/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/react-barcode-reader@0.0.2/lib/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _react=_interopRequireDefault(require("react")),_propTypes=_interopRequireDefault(require("prop-types"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),e}function _createSuper(e){return function(){var t,r=_getPrototypeOf(e);if(_isNativeReflectConstruct()){var n=_getPrototypeOf(this).constructor;t=Reflect.construct(r,arguments,n)}else t=r.apply(this,arguments);return _possibleConstructorReturn(this,t)}}function _possibleConstructorReturn(e,t){return!t||"object"!==_typeof(t)&&"function"!=typeof t?_assertThisInitialized(e):t}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},_getPrototypeOf(e)}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return _setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},_setPrototypeOf(e,t)}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function isContentEditable(e){return"function"==typeof e.getAttribute&&!!e.getAttribute("contenteditable")}function isInput(e){if(!e)return!1;var t=e.tagName,r=isContentEditable(e);return"INPUT"===t||"TEXTAREA"===t||r}function inIframe(){try{return window.self!==window.top}catch(e){return!0}}var BarcodeScanner=function(){_inherits(t,_react["default"].Component);var e=_createSuper(t);function t(r){var n;return _classCallCheck(this,t),_defineProperty(_assertThisInitialized(n=e.call(this,r)),"initScannerDetection",(function(){n.firstCharTime=0,n.stringWriting="",n.scanButtonCounter=0})),_defineProperty(_assertThisInitialized(n),"scannerDetectionTest",(function(e){var t=n.props,r=t.minLength,o=t.avgTimeByChar,i=t.onScanButtonLongPressed,a=t.scanButtonLongPressThreshold,s=t.onScan,u=t.onError;if(e&&(n.firstCharTime=0,n.lastCharTime=0,n.stringWriting=e),n.scanButtonCounter||(n.scanButtonCounter=1),n.stringWriting.length>=r&&n.lastCharTime-n.firstCharTime<n.stringWriting.length*o)return i&&n.scanButtonCounter>a?i(n.stringWriting,n.scanButtonCounter):s&&s(n.stringWriting,n.scanButtonCounter),n.initScannerDetection(),!0;var c="";return n.stringWriting.length<r?c="String length should be greater or equal ".concat(r):n.lastCharTime-n.firstCharTime>n.stringWriting.length*o&&(c="Average key character time should be less or equal ".concat(o,"ms")),u&&u(n.stringWriting,c),n.initScannerDetection(),!1})),_defineProperty(_assertThisInitialized(n),"handleKeyPress",(function(e){var t=n.props,r=t.onKeyDetect,o=t.onReceive,i=t.scanButtonKeyCode,a=t.stopPropagation,s=t.preventDefault,u=t.endChar,c=t.startChar,p=t.timeBeforeScanTest,f=e.target;f instanceof window.HTMLElement&&isInput(f)||(i&&e.which===i&&(n.scanButtonCounter+=1,e.preventDefault(),e.stopImmediatePropagation()),r&&r(e),a&&e.stopImmediatePropagation(),s&&e.preventDefault(),n.firstCharTime&&-1!==u.indexOf(e.which)?(e.preventDefault(),e.stopImmediatePropagation(),n.callIsScanner=!0):n.firstCharTime||-1===c.indexOf(e.which)?(void 0!==e.which&&(n.stringWriting+=String.fromCharCode(e.which)),n.callIsScanner=!1):(e.preventDefault(),e.stopImmediatePropagation(),n.callIsScanner=!1),n.firstCharTime||(n.firstCharTime=Date.now()),n.lastCharTime=Date.now(),n.testTimer&&clearTimeout(n.testTimer),n.callIsScanner?(n.scannerDetectionTest(),n.testTimer=!1):n.testTimer=setTimeout(n.scannerDetectionTest,p),o&&o(e))})),n.firstCharTime=0,n.lastCharTime=0,n.stringWriting="",n.callIsScanner=!1,n.testTimer=!1,n.scanButtonCounter=0,n}return _createClass(t,[{key:"componentDidMount",value:function(){inIframe&&window.parent.document.addEventListener("keypress",this.handleKeyPress),window.document.addEventListener("keypress",this.handleKeyPress)}},{key:"componentWillUnmount",value:function(){inIframe&&window.parent.document.removeEventListener("keypress",this.handleKeyPress),window.document.removeEventListener("keypress",this.handleKeyPress)}},{key:"render",value:function(){return this.props.testCode&&this.scannerDetectionTest(this.props.testCode),null}}]),t}();BarcodeScanner.propTypes={onScan:_propTypes.default.func,onError:_propTypes.default.func,onReceive:_propTypes.default.func,onKeyDetect:_propTypes.default.func,timeBeforeScanTest:_propTypes.default.number,avgTimeByChar:_propTypes.default.number,minLength:_propTypes.default.number,endChar:_propTypes.default.arrayOf(_propTypes.default.number),startChar:_propTypes.default.arrayOf(_propTypes.default.number),scanButtonKeyCode:_propTypes.default.number,scanButtonLongPressThreshold:_propTypes.default.number,onScanButtonLongPressed:_propTypes.default.func,stopPropagation:_propTypes.default.bool,preventDefault:_propTypes.default.bool,testCode:_propTypes.default.string},BarcodeScanner.defaultProps={timeBeforeScanTest:100,avgTimeByChar:30,minLength:6,endChar:[9,13],startChar:[],scanButtonLongPressThreshold:3,stopPropagation:!1,preventDefault:!1};var _default=BarcodeScanner;exports.default=_default;
//# sourceMappingURL=/sm/6b8a1fd82ed3733467a32a426c53a956f68da4c0fe6bd0e43c3572a1e491d8e8.map