text: define(["exports", "meta", "../../lit/index.js", "../es-global-bridge/es-global-bridge.js", "../simple-icon/lib/simple-icon-button.js"], function (_exports, meta, _index, _esGlobalBridge, _simpleIconButton) {
    "use strict";
  
    Object.defineProperty(_exports, "__esModule", {
      value: true
    });
    _exports.BarcodeReader = void 0;
    meta = _interopRequireWildcard(meta);
  
    var _templateObject_13bf2760942811ecb1937969798b231a, _templateObject2_13bf2760942811ecb1937969798b231a;
  
    function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  
    function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || babelHelpers.typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  
    function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = babelHelpers.getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = babelHelpers.getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return babelHelpers.possibleConstructorReturn(this, result); }; }
  
    function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  
    var vid;
    /**
     * `barcode-reader`
     * `Element to read barcodes and QR codes through a video stream`
     * @demo demo/index.html
     * @element barcode-reader
     * Amalgamation of https://github.com/justinribeiro/barcode-reader/blob/master/barcode-reader.js for LitElement & render
     * & https://github.com/zxing-js for img processing.
     */
  
    var BarcodeReader = /*#__PURE__*/function (_LitElement) {
      babelHelpers.inherits(BarcodeReader, _LitElement);
  
      var _super = _createSuper(BarcodeReader);
  
      function BarcodeReader() {
        var _this;
  
        babelHelpers.classCallCheck(this, BarcodeReader);
        _this = _super.call(this);
        _this.value = "";
        _this.hideinput = false;
        window.ESGlobalBridge.requestAvailability().load("ZXing", decodeURIComponent(meta.url) + "/../lib/zxing.js");
        window.addEventListener("es-bridge-zxing-loaded", _this._control.bind(babelHelpers.assertThisInitialized(_this)));
        return _this;
      }
  
      babelHelpers.createClass(BarcodeReader, [{
        key: "render",
        value:
        /**
         * LitElement render callback
         */
        function render() {
          return (0, _index.html)(_templateObject_13bf2760942811ecb1937969798b231a || (_templateObject_13bf2760942811ecb1937969798b231a = babelHelpers.taggedTemplateLiteral(["\n      <div class=\"hidden\" hidden>\n        <div>\n          <video\n            muted\n            autoplay\n            playsinline\n            width=\"", "%\"\n            height=\"", "%\"\n          ></video>\n          <canvas style=\"display: none; float: bottom;\"></canvas>\n        </div>\n      </div>\n      <div class=\"input\" ?hidden=\"", "\">\n        Result: <span><input type=\"text\" .value=\"", "\" /> </span>\n      </div>\n      <span>\n        <div class=\"hidden2\" hidden>\n          <div class=\"select\">\n            <label for=\"videoSource\">Video source: </label>\n            <select></select>\n          </div>\n          <button class=\"go\">Scan</button>\n        </div>\n        <simple-icon-button\n          aria-labelledby=\"label\"\n          icon=\"image:camera-alt\"\n          class=\"render\"\n        ></simple-icon-button>\n        <label id=\"label\">Initialize</label>\n      </span>\n    "])), this.scale, this.scale, this.hideinput, this.value);
        }
      }, {
        key: "_control",
        value: function _control() {
          var _this2 = this;
  
          var videoElement = this.shadowRoot.querySelector("video");
          var canvas = this.shadowRoot.querySelector("canvas");
          var ctx = canvas.getContext("2d");
          var buttonGo = this.shadowRoot.querySelector(".go");
          var isPaused = false;
          var videoWidth = 640,
              videoHeight = 480;
          var mobileVideoWidth = 240,
              mobileVideoHeight = 320;
          var isPC = true;
          var ZXing = null;
          var decodePtr = null;
  
          var tick = function tick() {
            if (window.ZXing) {
              setTimeout(function () {
                console.log("loaded zxing instance");
                ZXing = new window.ZXing();
                decodePtr = ZXing.Runtime.addFunction(decodeCallback);
              }, 100); //Slow down execution. Error when loaded before getting devices
            } else {
              setTimeout(tick, 100);
            }
          };
  
          tick(); // we got a match!
  
          var decodeCallback = /*#__PURE__*/function () {
            var _ref = babelHelpers.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(ptr, len, resultIndex, resultCount) {
              var result;
              return regeneratorRuntime.wrap(function _callee$(_context) {
                while (1) {
                  switch (_context.prev = _context.next) {
                    case 0:
                      result = new Uint8Array(ZXing.HEAPU8.buffer, ptr, len);
                      console.log(String.fromCharCode.apply(null, result));
                      _this2.value = String.fromCharCode.apply(null, result);
                      buttonGo.removeAttribute("disabled");
  
                    case 4:
                    case "end":
                      return _context.stop();
                  }
                }
              }, _callee);
            }));
  
            return function decodeCallback(_x, _x2, _x3, _x4) {
              return _ref.apply(this, arguments);
            };
          }(); // check devices
  
  
          function browserRedirect() {
            var deviceType;
            var sUserAgent = navigator.userAgent.toLowerCase();
            var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
            var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
            var bIsMidp = sUserAgent.match(/midp/i) == "midp";
            var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
            var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
            var bIsAndroid = sUserAgent.match(/android/i) == "android";
            var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
            var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
  
            if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
              deviceType = "phone";
            } else {
              deviceType = "pc";
            }
  
            return deviceType;
          }
  
          if (browserRedirect() == "pc") {
            isPC = true;
          } else {
            isPC = false;
          }
  
          buttonGo.onclick = function () {
            console.log("click");
            _this2.value = "";
            canvas.style.display = "none";
            isPaused = false;
            buttonGo.setAttribute("disabled", "");
            scanBarcode();
          }; // scan barcode
  
  
          function scanBarcode() {
            if (ZXing == null) {
              buttonGo.removeAttribute("disabled");
              alert("Barcode Reader is not ready!");
              return;
            }
  
            var data = null,
                context = null,
                width = 0,
                height = 0,
                dbrCanvas = null;
  
            if (isPC) {
              context = ctx;
              width = videoWidth;
              height = videoHeight;
              dbrCanvas = canvas;
            } else {
              context = mobileCtx;
              width = mobileVideoWidth;
              height = mobileVideoHeight;
            }
  
            context.drawImage(videoElement, 0, 0, width, height);
            var barcodeCanvas = document.createElement("canvas");
            barcodeCanvas.width = vid.videoWidth;
            barcodeCanvas.height = vid.videoHeight;
            var barcodeContext = barcodeCanvas.getContext("2d");
            var imageWidth = vid.videoWidth,
                imageHeight = vid.videoHeight;
            barcodeContext.drawImage(videoElement, 0, 0, imageWidth, imageHeight);
            var imageData = barcodeContext.getImageData(0, 0, imageWidth, imageHeight);
            var idd = imageData.data;
  
            var image = ZXing._resize(imageWidth, imageHeight);
  
            console.time("decode barcode");
  
            for (var i = 0, j = 0; i < idd.length; i += 4, j++) {
              ZXing.HEAPU8[image + j] = idd[i];
            }
  
            var err = ZXing._decode_any(decodePtr);
  
            console.timeEnd("decode barcode");
            console.log(err);
  
            if (err == -2) {
              setTimeout(scanBarcode, 30);
            } else if (err == -3) {
              console.error("error code: ", err);
              buttonGo.removeAttribute("disabled");
            } else if (err === 0) {
              buttonGo.removeAttribute("disabled");
            }
          }
  
          var videoSelect = this.shadowRoot.querySelector("select");
          navigator.mediaDevices.enumerateDevices().then(gotDevices).then(getStream).catch(handleError);
          videoSelect.onchange = getStream;
  
          function gotDevices(deviceInfos) {
            for (var i = deviceInfos.length - 1; i >= 0; --i) {
              var deviceInfo = deviceInfos[i];
              var option = document.createElement("option");
              option.value = deviceInfo.deviceId;
  
              if (deviceInfo.kind === "videoinput") {
                option.text = deviceInfo.label || "camera " + (videoSelect.length + 1);
                videoSelect.appendChild(option);
              } else {
                console.log("Found one other kind of source/device: ", deviceInfo);
              }
            }
          }
  
          function getStream() {
            buttonGo.removeAttribute("disabled");
  
            if (window.stream) {
              window.stream.getTracks().forEach(function (track) {
                track.stop();
              });
            }
  
            var constraints = {
              video: {
                deviceId: {
                  exact: videoSelect.value
                }
              }
            };
            navigator.mediaDevices.getUserMedia(constraints).then(gotStream).catch(handleError);
          }
  
          function gotStream(stream) {
            window.stream = stream; // make stream available to console
  
            videoElement.srcObject = stream;
          }
  
          this.shadowRoot.querySelector(".render").addEventListener("click", function () {
            if (_this2.shadowRoot.querySelector(".render").innerHTML === "Show") {
              if (window.stream) {
                window.stream.getTracks().forEach(function (track) {});
                var constraints = {
                  video: {
                    deviceId: {
                      exact: videoSelect.value
                    }
                  }
                };
                navigator.mediaDevices.getUserMedia(constraints).then(gotStream).catch(handleError);
              }
            }
          });
  
          function handleError(error) {
            console.error("Error: ", error);
          }
        }
        /**
         * Convention we use
         */
  
      }, {
        key: "updated",
        value: function updated(changedProperties) {
          var _this3 = this;
  
          changedProperties.forEach(function (oldValue, propName) {
            if (propName === "value") {
              _this3.dispatchEvent(new CustomEvent("value-changed", {
                detail: _this3
              }));
            }
          });
        }
        /**
         * LitElement ready
         */
  
      }, {
        key: "firstUpdated",
        value: function firstUpdated() {
          this.start().then(function (r) {});
          this.__context = this.shadowRoot.querySelector("canvas").getContext("2d");
          this.__video = this.shadowRoot.querySelector("video");
          this.__videoInputSelector = this.shadowRoot.querySelector("#videoInput");
          vid = this.shadowRoot.querySelector("video");
  
          this._renderVideo().then(function (r) {});
  
          if (!this.hideinput) {
            this.shadowRoot.querySelector(".input").removeAttribute("hidden");
          }
        }
      }, {
        key: "_onFrame",
        value: function () {
          var _onFrame2 = babelHelpers.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
            return regeneratorRuntime.wrap(function _callee2$(_context2) {
              while (1) {
                switch (_context2.prev = _context2.next) {
                  case 0:
                    if (this.__video.videoWidth > 0) {
                      this._drawFrame(this.__video);
                    }
  
                    this.__animationFrameId = requestAnimationFrame(this._onFrame.bind(this));
  
                  case 2:
                  case "end":
                    return _context2.stop();
                }
              }
            }, _callee2, this);
          }));
  
          function _onFrame() {
            return _onFrame2.apply(this, arguments);
          }
  
          return _onFrame;
        }()
      }, {
        key: "_drawFrame",
        value: function _drawFrame(frameData) {
          this.__context.drawImage(frameData, 0, 0, this.width, this.height, 0, 0, this.width, this.height);
        }
      }, {
        key: "start",
        value: function () {
          var _start = babelHelpers.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
            var _this4 = this;
  
            return regeneratorRuntime.wrap(function _callee3$(_context3) {
              while (1) {
                switch (_context3.prev = _context3.next) {
                  case 0:
                    this.shadowRoot.querySelector("simple-icon-button").addEventListener("click", function () {
                      if (_this4.shadowRoot.querySelector(".render").innerHTML === "Initialize") {
                        _this4._control();
                      }
                    });
  
                  case 1:
                  case "end":
                    return _context3.stop();
                }
              }
            }, _callee3, this);
          }));
  
          function start() {
            return _start.apply(this, arguments);
          }
  
          return start;
        }()
      }, {
        key: "_renderVideo",
        value: function () {
          var _renderVideo2 = babelHelpers.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
            var video, button, extraButtons;
            return regeneratorRuntime.wrap(function _callee4$(_context4) {
              while (1) {
                switch (_context4.prev = _context4.next) {
                  case 0:
                    video = this.shadowRoot.querySelector(".hidden");
                    button = this.shadowRoot.querySelector("simple-icon-button");
                    extraButtons = this.shadowRoot.querySelector(".hidden2");
                    video.style.display = "none";
                    this.shadowRoot.querySelector("simple-icon-button").addEventListener("click", function () {
                      setTimeout(function () {
                        if (video.style.display === "none") {
                          video.style.display = "inline";
                          button.innerHTML = "Hide";
                          extraButtons.style.display = "inline";
                        } else {
                          video.style.display = "none";
                          button.innerHTML = "Show";
                          extraButtons.style.display = "none";
                          window.stream.getTracks().forEach(function (track) {
                            track.stop();
                          });
                        }
                      }, 100);
                    });
  
                  case 5:
                  case "end":
                    return _context4.stop();
                }
              }
            }, _callee4, this);
          }));
  
          function _renderVideo() {
            return _renderVideo2.apply(this, arguments);
          }
  
          return _renderVideo;
        }()
      }], [{
        key: "styles",
        get:
        /**
         * LitElement style callback
         */
        function get() {
          return (0, _index.css)(_templateObject2_13bf2760942811ecb1937969798b231a || (_templateObject2_13bf2760942811ecb1937969798b231a = babelHelpers.taggedTemplateLiteral(["\n      :host([hidden]) {\n        display: none;\n      }\n      canvas {\n        display: none;\n      }\n      video {\n        border-style: solid;\n        border-color: rgba(0, 0, 0, 0.5);\n        border-width: 5px;\n      }\n    "])));
        }
        /**      .hidden {
              display: none;
            }
         .hidden2 {
              display: none;
            }*/
  
      }, {
        key: "properties",
        get: function get() {
          return {
            value: {
              type: String,
              reflect: true
            },
            scale: {
              type: Number,
              reflect: true
            },
            hideinput: {
              type: Boolean
            }
          };
        }
      }, {
        key: "tag",
        get: function get() {
          return "barcode-reader";
        }
      }]);
      return BarcodeReader;
    }(_index.LitElement);
  
    _exports.BarcodeReader = BarcodeReader;
    customElements.define(BarcodeReader.tag, BarcodeReader);
  });