{"version":3,"sources":["jsdelivr-header.js","/npm/@itexperts/barcode-scanner@1.0.1/BarcodeScanner.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OCNO,MAAM,uBAAuB,YAChC,WAAA,CAAY,EAAU,CAAC,GACnB,QAEA,EAAU,OAAO,OAAO,CACpB,QAAS,IACT,eAAgB,IACjB,GAEH,KAAK,QAAU,EAAQ,QACvB,KAAK,eAAiB,EAAQ,eAC9B,KAAK,MAAQ,KAAK,MAClB,KAAK,QAAU,GACf,KAAK,OAAS,IAAI,YAClB,SAAS,iBAAiB,WAAY,KAAK,SAAS,KAAK,MAC7D,CAEA,QAAA,CAAS,GAEL,IAAI,EAAM,KAAK,MAGX,EAAM,KAAK,MAAQ,KAAK,SACxB,KAAK,QAIQ,EAAM,KAAK,MACX,KAAK,UAClB,KAAK,SAAW,EAAE,IAGd,KAAK,QAAQ,SAAW,KAAK,gBAC7B,KAAK,oBAGjB,CAEA,iBAAA,GACI,IAAI,EAAQ,IAAI,YAAY,OAAQ,CAAC,OAAQ,KAAK,UAClD,KAAK,cAAc,GACnB,KAAK,OACT,CAEA,KAAA,GACI,KAAK,MAAQ,KAAK,MAClB,KAAK,QAAU,EACnB","file":"/npm/@itexperts/barcode-scanner@1.0.1/BarcodeScanner.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@itexperts/barcode-scanner@1.0.1/BarcodeScanner.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","export class BarcodeScanner extends EventTarget {\n    constructor(options = {}) {\n        super();\n\n        options = Object.assign({\n            timeOut: 130,\n            characterCount: 13\n        }, options);\n\n        this.timeOut = options.timeOut;\n        this.characterCount = options.characterCount;\n        this.timer = Date.now();\n        this.capture = '';\n        this.target = new EventTarget();\n        document.addEventListener('keypress', this.keypress.bind(this));\n    }\n\n    keypress(e) {\n        // Set current time\n        let now = Date.now();\n\n        // If out timer is out, we need to reset because it was not a barcode\n        if (now - this.timer > this.timeOut) {\n            this.reset();\n        }\n\n        // It seems we are still fast enough to be a barcode, so add to capture\n        let sinceFirst = now - this.timer;\n        if (sinceFirst < this.timeOut) {\n            this.capture += e.key\n\n            // It seems we managed to get enough characters within the time out, send scan!\n            if (this.capture.length === this.characterCount) {\n                this.dispatchScanEvent();\n            }\n        }\n    }\n\n    dispatchScanEvent(){\n        let event = new CustomEvent('scan', {detail: this.capture});\n        this.dispatchEvent(event);\n        this.reset();\n    }\n\n    reset() {\n        this.timer = Date.now();\n        this.capture = '';\n    }\n}\n"]}