Houjie
2025-04-11 1bf977929dd324f3ac64b70debd8a79443c54392
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { BaseUiElementFactory, PublicUiElementIdAndClasses } from "./base";
import { Html5QrcodeScannerStrings } from "../../strings";
var CameraSelectionUi = (function () {
    function CameraSelectionUi(cameras) {
        this.selectElement = BaseUiElementFactory
            .createElement("select", PublicUiElementIdAndClasses.CAMERA_SELECTION_SELECT_ID);
        this.cameras = cameras;
        this.options = [];
    }
    CameraSelectionUi.prototype.render = function (parentElement) {
        var cameraSelectionContainer = document.createElement("span");
        cameraSelectionContainer.style.marginRight = "10px";
        var numCameras = this.cameras.length;
        if (numCameras === 0) {
            throw new Error("No cameras found");
        }
        if (numCameras === 1) {
            cameraSelectionContainer.style.display = "none";
        }
        else {
            var selectCameraString = Html5QrcodeScannerStrings.selectCamera();
            cameraSelectionContainer.innerText
                = "".concat(selectCameraString, " (").concat(this.cameras.length, ")  ");
        }
        var anonymousCameraId = 1;
        for (var _i = 0, _a = this.cameras; _i < _a.length; _i++) {
            var camera = _a[_i];
            var value = camera.id;
            var name_1 = camera.label == null ? value : camera.label;
            if (!name_1 || name_1 === "") {
                name_1 = [
                    Html5QrcodeScannerStrings.anonymousCameraPrefix(),
                    anonymousCameraId++
                ].join(" ");
            }
            var option = document.createElement("option");
            option.value = value;
            option.innerText = name_1;
            this.options.push(option);
            this.selectElement.appendChild(option);
        }
        cameraSelectionContainer.appendChild(this.selectElement);
        parentElement.appendChild(cameraSelectionContainer);
    };
    CameraSelectionUi.prototype.disable = function () {
        this.selectElement.disabled = true;
    };
    CameraSelectionUi.prototype.isDisabled = function () {
        return this.selectElement.disabled === true;
    };
    CameraSelectionUi.prototype.enable = function () {
        this.selectElement.disabled = false;
    };
    CameraSelectionUi.prototype.getValue = function () {
        return this.selectElement.value;
    };
    CameraSelectionUi.prototype.hasValue = function (value) {
        for (var _i = 0, _a = this.options; _i < _a.length; _i++) {
            var option = _a[_i];
            if (option.value === value) {
                return true;
            }
        }
        return false;
    };
    CameraSelectionUi.prototype.setValue = function (value) {
        if (!this.hasValue(value)) {
            throw new Error("".concat(value, " is not present in the camera list."));
        }
        this.selectElement.value = value;
    };
    CameraSelectionUi.prototype.hasSingleItem = function () {
        return this.cameras.length === 1;
    };
    CameraSelectionUi.prototype.numCameras = function () {
        return this.cameras.length;
    };
    CameraSelectionUi.create = function (parentElement, cameras) {
        var cameraSelectUi = new CameraSelectionUi(cameras);
        cameraSelectUi.render(parentElement);
        return cameraSelectUi;
    };
    return CameraSelectionUi;
}());
export { CameraSelectionUi };
//# sourceMappingURL=camera-selection-ui.js.map