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Delivr using Terser v5.39.0.\n * Original file: /npm/vue-scan-code@1.1.5/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const eventSimple = require('event-simple');\r\n\r\nvar _Vue;\r\n\r\nfunction Scan () {\r\n  this.pointer = '';\r\n  this.pointerQueue = [];\r\n  this.code = '';\r\n  this.nextCode = '';\r\n  this.lastCode = '';\r\n  this.name = 'scan';\r\n  this.eventName = 'scancode';\r\n  this.codeMinLength = 5;\r\n  this.wait = 30;\r\n  this.timer = null;\r\n  this.handler = {};\r\n  this.initScanCode = function (callback, vueExp) {\r\n    if (typeof callback === 'function') {\r\n      if ((vueExp._uid || vueExp._uid === 0) && !this.handler[this.name + vueExp._uid]) {\r\n        var bool = this.pointerQueue.some(function (point) { return point == vueExp._uid });\r\n        !bool && this.pointerQueue.push([vueExp._uid]);\r\n        this.handler[this.name + vueExp._uid] = callback;\r\n      } else if (this.handler[this.name + vueExp._uid]) {\r\n        this.handler[this.name + vueExp._uid] = callback;\r\n      } else {\r\n        console.error('error: ~~~');\r\n      }\r\n    } else {\r\n      console.error('the callback is only function');\r\n    }\r\n    this.pointer = vueExp._uid;\r\n  };\r\n  this.offScanCode = function (that) {\r\n    if (that instanceof _Vue) {\r\n      const pointerIndex = this.pointerQueue.findIndex(function (p) { return p == this._uid });\r\n      if (pointerIndex > -1) {\r\n        this.pointerQueue.splice(pointerIndex, -1);\r\n        delete this.handler[this.name + this._uid];\r\n      }\r\n      this.pointer = '';\r\n    } else {\r\n      console.error('current Example not a vue example');\r\n    }\r\n  };\r\n  this.bindScanCode = function (that, callback) {\r\n    if (that instanceof _Vue) {\r\n      if (typeof callback == 'function') {\r\n        this.initScanCode(callback, that);\r\n      }\r\n    } else {\r\n      console.error('current Example not a vue example');\r\n    }\r\n  };\r\n  this.outputScanCode = function (code) {\r\n    if (this.pointer && this.handler[this.name + this.pointer]) {\r\n      this.handler[this.name + this.pointer](code);\r\n    }\r\n    this.clearCache();\r\n  };\r\n  this.getPrototypeName = function () {\r\n    return '$' + this.name\r\n  };\r\n  this.clearCache = function () {\r\n    this.nextCode = '';\r\n    this.lastCode = '';\r\n    this.code = '';\r\n  };\r\n}\r\n\r\nScan.prototype.init = function (options) {\r\n  options && options.scanName && (this.name = options.scanName);\r\n  options && options.scanWait && (this.wait = options.scanWait);\r\n  options && options.scanCodeMinLength && (this.codeMinLength = options.scanCodeMinLength);\r\n  var lastTime, nextTime, lastCode, nextCode;\r\n  var self = this;\r\n  window.addEventListener('keypress', function (e) {\r\n    nextCode = e.which;\r\n    nextTime = new Date().getTime();\r\n    if (lastCode && lastTime && nextTime - lastTime <= self.wait) {\r\n      if (lastCode) {\r\n        self.lastCode += String.fromCharCode(lastCode);\r\n      } else {\r\n        self.lastCode += '';\r\n      }\r\n      if (nextCode) {\r\n        self.nextCode += String.fromCharCode(nextCode);\r\n      } else {\r\n        self.nextCode += '';\r\n      }\r\n      eventSimple.emit(self.eventName, self.nextCode, self.lastCode);\r\n    } else if (lastCode && lastTime && nextTime - lastTime > 100) {\r\n      self.code = '';\r\n    }\r\n    lastCode = nextCode;\r\n    lastTime = nextTime;\r\n  });\r\n  eventSimple.on(self.eventName, function (nextCode, lastCode) {\r\n    clearTimeout(self.timer);\r\n    self.timer = setTimeout(function () {\r\n      if (nextCode.length >= self.codeMinLength && lastCode.length >= self.codeMinLength) {\r\n        self.code = lastCode + nextCode.slice(lastCode.length - 1);\r\n        self.outputScanCode(self.code);\r\n      } else {\r\n        console.error('current barcode length less than the options scanCodeMinLength');\r\n        self.clearCache();\r\n      }\r\n    }, self.wait);\r\n  });\r\n};\r\n\r\nvar index = {\r\n  install: function (Vue, options) {\r\n    // eslint-disable-next-line no-undef\r\n    if (_Vue === Vue) { return }\r\n    _Vue = Vue;\r\n\r\n    const sc = new Scan();\r\n    window.scan = sc;\r\n    sc.init(options || {});\r\n    Vue.prototype[sc.getPrototypeName()] = sc;\r\n  }\r\n};\n\nexport default index;\n"]}