!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common"),require("@angular/core"),require("@angular/forms"),require("@zxing/library"),require("rxjs")):"function"==typeof define&&define.amd?define("@zxing/ngx-scanner",["exports","@angular/common","@angular/core","@angular/forms","@zxing/library","rxjs"],t):t(((e=e||self).zxing=e.zxing||{},e.zxing["ngx-scanner"]={}),e.ng.common,e.ng.core,e.ng.forms,e.library,e.rxjs)}(this,(function(e,t,n,r,i,o){"use strict";
/*! *****************************************************************************
    Copyright (c) Microsoft Corporation. All rights reserved.
    Licensed under the Apache License, Version 2.0 (the "License"); you may not use
    this file except in compliance with the License. You may obtain a copy of the
    License at http://www.apache.org/licenses/LICENSE-2.0

    THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
    WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
    MERCHANTABLITY OR NON-INFRINGEMENT.

    See the Apache Version 2.0 License for specific language governing permissions
    and limitations under the License.
    ***************************************************************************** */var s=function(e,t){return(s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function a(e,t,n,r){var i,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(s=(o<3?i(s):o>3?i(t,n,s):i(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s}function c(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function u(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){e.done?i(e.value):new n((function(t){t(e.value)})).then(s,a)}c((r=r.apply(e,t||[])).next())}))}function p(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function d(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}function l(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function h(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(l(arguments[t]));return e}var f=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._isTorchAvailable=new o.BehaviorSubject(void 0),t}return function(e,t){function n(){this.constructor=e}s(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),Object.defineProperty(t.prototype,"isTorchAvailable",{get:function(){return this._isTorchAvailable.asObservable()},enumerable:!0,configurable:!0}),t.prototype.continuousDecodeFromInputVideoDevice=function(e,t){var n=this;if(this.reset(),void 0!==e&&(this.deviceId=e),"undefined"!=typeof navigator){var r=new o.BehaviorSubject({});try{this.getStreamForDevice({deviceId:e}).then((function(e){return n.attachStreamToVideoAndCheckTorch(e,t)})).then((function(e){return n.decodeOnSubject(r,e,n.timeBetweenScansMillis)}))}catch(e){r.error(e)}return this._setScanStream(r),r.asObservable()}},t.prototype.getStreamForDevice=function(e){var t=e.deviceId;return u(this,void 0,void 0,(function(){var e;return p(this,(function(n){switch(n.label){case 0:return e=this.getUserMediaConstraints(t),[4,navigator.mediaDevices.getUserMedia(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.getUserMediaConstraints=function(e){return{video:void 0===e?{facingMode:{exact:"environment"}}:{deviceId:{exact:e}}}},t.prototype.setTorch=function(e){if(this._isTorchAvailable.value){var t=this.getVideoTracks(this.stream);e?this.applyTorchOnTracks(t,!0):(this.applyTorchOnTracks(t,!1),this.restart())}},t.prototype.attachStreamToVideoAndCheckTorch=function(e,t){return this.updateTorchCompatibility(e),this.attachStreamToVideo(e,t)},t.prototype.updateTorchCompatibility=function(e){return u(this,void 0,void 0,(function(){var t,n,r,i,o,s,a;return p(this,(function(c){switch(c.label){case 0:r=this.getVideoTracks(e),c.label=1;case 1:c.trys.push([1,6,7,8]),i=d(r),o=i.next(),c.label=2;case 2:return o.done?[3,5]:(s=o.value,[4,this.isTorchCompatible(s)]);case 3:if(c.sent())return this._isTorchAvailable.next(!0),[3,5];c.label=4;case 4:return o=i.next(),[3,2];case 5:return[3,8];case 6:return a=c.sent(),t={error:a},[3,8];case 7:try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}return[7];case 8:return[2]}}))}))},t.prototype.getVideoTracks=function(e){var t=[];try{t=e.getVideoTracks()}finally{return t||[]}},t.prototype.isTorchCompatible=function(e){return u(this,void 0,void 0,(function(){var t,n;return p(this,(function(r){switch(r.label){case 0:t=!1,r.label=1;case 1:return r.trys.push([1,,3,4]),[4,new ImageCapture(e).getPhotoCapabilities()];case 2:return n=r.sent(),t=!!n.torch||"fillLightMode"in n&&0!==n.fillLightMode.length,[3,4];case 3:return[2,t];case 4:return[2]}}))}))},t.prototype.applyTorchOnTracks=function(e,t){e.forEach((function(e){return e.applyConstraints({advanced:[{torch:t,fillLightMode:t?"torch":"none"}]})}))},t.prototype._setScanStream=function(e){this._cleanScanStream(),this.scanStream=e},t.prototype._cleanScanStream=function(){this.scanStream&&!this.scanStream.isStopped&&this.scanStream.complete(),this.scanStream=null},t.prototype.decodeOnSubject=function(e,t,n){var r,o=this;if(!e.isStopped)try{r=this.decode(t),e.next({result:r})}catch(t){!t||t instanceof i.NotFoundException||t instanceof i.ChecksumException||t instanceof i.FormatException?e.next({error:t}):e.error(t)}finally{setTimeout((function(){return o.decodeOnSubject(e,t,n)}),r?n:0)}},t.prototype.restart=function(){return this.continuousDecodeFromInputVideoDevice(this.deviceId,this.videoElement)},t}(i.BrowserMultiFormatReader),v=function(){function e(){this.previewFitMode="cover",this.autostarted=new n.EventEmitter,this.autostarting=new n.EventEmitter,this.torchCompatible=new n.EventEmitter,this.scanSuccess=new n.EventEmitter,this.scanFailure=new n.EventEmitter,this.scanError=new n.EventEmitter,this.scanComplete=new n.EventEmitter,this.camerasFound=new n.EventEmitter,this.camerasNotFound=new n.EventEmitter,this.permissionResponse=new n.EventEmitter(!0),this.hasDevices=new n.EventEmitter,this.deviceChange=new n.EventEmitter,this._device=null,this._enabled=!0,this._hints=new Map,this.autofocusEnabled=!0,this.autostart=!0,this.formats=[i.BarcodeFormat.QR_CODE],this.hasNavigator="undefined"!=typeof navigator,this.isMediaDevicesSuported=this.hasNavigator&&!!navigator.mediaDevices}return Object.defineProperty(e.prototype,"codeReader",{get:function(){return this._codeReader},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"device",{get:function(){return this._device},set:function(e){if(!e&&null!==e)throw new i.ArgumentException("The `device` must be a valid MediaDeviceInfo or null.");this.isCurrentDevice(e)?console.warn("Setting the same device is not allowed."):this.isAutostarting?console.warn("Avoid setting a device during auto-start."):(this.hasPermission||console.warn("Permissions not set yet, waiting for them to be set to apply device change."),this._reset(),this._device=e,this._enabled&&null!==e&&this.scanFromDevice(e.deviceId))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"formats",{get:function(){return this.hints.get(i.DecodeHintType.POSSIBLE_FORMATS)},set:function(e){var t=this;if("string"==typeof e)throw new Error("Invalid formats, make sure the [formats] input is a binding.");var n=e.map((function(e){return t.getBarcodeFormatOrFail(e)})),r=this.hints;r.set(i.DecodeHintType.POSSIBLE_FORMATS,n),this.hints=r},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hints",{get:function(){return this._hints},set:function(e){this._hints=e,this.restart()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isAutostarting",{set:function(e){this._isAutostarting=e,this.autostarting.next(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isAutstarting",{get:function(){return this._isAutostarting},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"torch",{set:function(e){this.getCodeReader().setTorch(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enable",{set:function(e){this._enabled=Boolean(e),this._enabled?this.device&&this.scanFromDevice(this.device.deviceId):this.reset()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tryHarder",{get:function(){return this.hints.get(i.DecodeHintType.TRY_HARDER)},set:function(e){var t=this.hints;e?t.set(i.DecodeHintType.TRY_HARDER,!0):t.delete(i.DecodeHintType.TRY_HARDER),this.hints=t},enumerable:!0,configurable:!0}),e.prototype.askForPermission=function(){return u(this,void 0,void 0,(function(){var e,t,n;return p(this,(function(r){switch(r.label){case 0:if(!this.hasNavigator)return console.error("@zxing/ngx-scanner","Can't ask permission, navigator is not present."),this.setPermission(null),[2,this.hasPermission];if(!this.isMediaDevicesSuported)return console.error("@zxing/ngx-scanner","Can't get user media, this is not supported."),this.setPermission(null),[2,this.hasPermission];r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,this.getAnyVideoDevice()];case 2:return e=r.sent(),t=!!e,[3,5];case 3:return n=r.sent(),[2,this.handlePermissionException(n)];case 4:return this.terminateStream(e),[7];case 5:return this.setPermission(t),[2,t]}}))}))},e.prototype.getAnyVideoDevice=function(){return navigator.mediaDevices.getUserMedia({video:!0})},e.prototype.terminateStream=function(e){e&&e.getTracks().forEach((function(e){return e.stop()})),e=void 0},e.prototype.initAutostartOff=function(){this.isAutostarting=null,this.updateVideoInputDevices()},e.prototype.initAutostartOn=function(){return u(this,void 0,void 0,(function(){var e,t,n;return p(this,(function(r){switch(r.label){case 0:this.isAutostarting=!0,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.askForPermission()];case 2:return e=r.sent(),[3,4];case 3:return t=r.sent(),console.error("Exception occurred while asking for permission:",t),[2];case 4:return e?[4,this.updateVideoInputDevices()]:[3,6];case 5:n=r.sent(),this.autostartScanner(h(n)),r.label=6;case 6:return[2]}}))}))},e.prototype.isCurrentDevice=function(e){return this.device&&e&&e.deviceId===this.device.deviceId},e.prototype.ngAfterViewInit=function(){var e=this;if(this.getCodeReader().isTorchAvailable.subscribe((function(t){return e.torchCompatible.emit(t)})),!this.autostart)return console.warn("New feature 'autostart' disabled, be careful. Permissions and devices recovery has to be run manually."),void this.initAutostartOff();this.initAutostartOn()},e.prototype.ngOnDestroy=function(){this.reset()},e.prototype.restart=function(){var e=this._reset();e&&(this._codeReader=void 0,this.device=e)},e.prototype.updateVideoInputDevices=function(){return u(this,void 0,void 0,(function(){var e,t;return p(this,(function(n){switch(n.label){case 0:return[4,this.getCodeReader().listVideoInputDevices()];case 1:return e=n.sent()||[],t=e&&e.length>0,this.hasDevices.next(t),this.camerasFound.next(h(e)),t||this.camerasNotFound.next(),[2,e]}}))}))},e.prototype.autostartScanner=function(e){var t=e.find((function(e){var t=e.label;return/back|trás|rear|traseira|environment|ambiente/gi.test(t)}))||e.pop();if(!t)throw new Error("Impossible to autostart, no input devices available.");this.device=t,this.deviceChange.emit(t),this.isAutostarting=!1,this.autostarted.next()},e.prototype.dispatchScanSuccess=function(e){this.scanSuccess.next(e.getText())},e.prototype.dispatchScanFailure=function(e){this.scanFailure.next(e)},e.prototype.dispatchScanError=function(e){this.scanError.next(e)},e.prototype.dispatchScanComplete=function(e){this.scanComplete.next(e)},e.prototype.handlePermissionException=function(e){var t;switch(console.error("@zxing/ngx-scanner","Error when asking for permission.",e),e.name){case"NotSupportedError":console.warn("@zxing/ngx-scanner",e.message),t=null,this.hasDevices.next(null);break;case"NotAllowedError":console.warn("@zxing/ngx-scanner",e.message),t=!1,this.hasDevices.next(!0);break;case"NotFoundError":console.warn("@zxing/ngx-scanner",e.message),t=null,this.hasDevices.next(!1),this.camerasNotFound.next(e);break;case"NotReadableError":console.warn("@zxing/ngx-scanner","Couldn't read the device(s)'s stream, it's probably in use by another app."),t=null,this.hasDevices.next(!1),this.camerasNotFound.next(e);break;default:console.warn("@zxing/ngx-scanner","I was not able to define if I have permissions for camera or not.",e),t=null}return this.setPermission(t),this.permissionResponse.error(e),t},e.prototype.getBarcodeFormatOrFail=function(e){return"string"==typeof e?i.BarcodeFormat[e.trim().toUpperCase()]:e},e.prototype.getCodeReader=function(){return this._codeReader||(this._codeReader=new f(this.hints)),this._codeReader},e.prototype.scanFromDevice=function(e){var t=this,n=this.previewElemRef.nativeElement,r=this.getCodeReader().continuousDecodeFromInputVideoDevice(e,n);if(!r)throw new Error("Undefined decoding stream, aborting.");r.subscribe((function(e){return t._onDecodeResult(e.result,e.error)}),(function(e){return t._onDecodeError(e)}),(function(){t.reset(),console.log("completed")}))},e.prototype._onDecodeError=function(e){this.dispatchScanError(e),this.reset()},e.prototype._onDecodeResult=function(e,t){e?this.dispatchScanSuccess(e):this.dispatchScanFailure(t),this.dispatchScanComplete(e)},e.prototype._reset=function(){if(this._codeReader){var e=this.device;return this._device=null,this._codeReader.reset(),e}},e.prototype.reset=function(){this._reset(),this.deviceChange.emit(null)},e.prototype.setPermission=function(e){this.hasPermission=e,this.permissionResponse.next(e)},a([n.ViewChild("preview",{static:!0}),c("design:type",n.ElementRef)],e.prototype,"previewElemRef",void 0),a([n.Input(),c("design:type",Boolean)],e.prototype,"autofocusEnabled",void 0),a([n.Output(),c("design:type",n.EventEmitter)],e.prototype,"autostarted",void 0),a([n.Output(),c("design:type",n.EventEmitter)],e.prototype,"autostarting",void 0),a([n.Input(),c("design:type",Boolean)],e.prototype,"autostart",void 0),a([n.Input(),c("design:type",String)],e.prototype,"previewFitMode",void 0),a([n.Output(),c("design:type",n.EventEmitter)],e.prototype,"torchCompatible",void 0),a([n.Output(),c("design:type",n.EventEmitter)],e.prototype,"scanSuccess",void 0),a([n.Output(),c("design:type",n.EventEmitter)],e.prototype,"scanFailure",void 0),a([n.Output(),c("design:type",n.EventEmitter)],e.prototype,"scanError",void 0),a([n.Output(),c("design:type",n.EventEmitter)],e.prototype,"scanComplete",void 0),a([n.Output(),c("design:type",n.EventEmitter)],e.prototype,"camerasFound",void 0),a([n.Output(),c("design:type",n.EventEmitter)],e.prototype,"camerasNotFound",void 0),a([n.Output(),c("design:type",n.EventEmitter)],e.prototype,"permissionResponse",void 0),a([n.Output(),c("design:type",n.EventEmitter)],e.prototype,"hasDevices",void 0),a([n.Input(),c("design:type",MediaDeviceInfo),c("design:paramtypes",[MediaDeviceInfo])],e.prototype,"device",null),a([n.Output(),c("design:type",n.EventEmitter)],e.prototype,"deviceChange",void 0),a([n.Input(),c("design:type",Array),c("design:paramtypes",[Array])],e.prototype,"formats",null),a([n.Input(),c("design:type",Boolean),c("design:paramtypes",[Boolean])],e.prototype,"torch",null),a([n.Input(),c("design:type",Boolean),c("design:paramtypes",[Boolean])],e.prototype,"enable",null),a([n.Input(),c("design:type",Boolean),c("design:paramtypes",[Boolean])],e.prototype,"tryHarder",null),e=a([n.Component({selector:"zxing-scanner",template:'<video #preview [style.object-fit]="previewFitMode">\n  <p>\n    Your browser does not support this feature, please try to upgrade it.\n  </p>\n  <p>\n    Seu navegador não suporta este recurso, por favor tente atualizá-lo.\n  </p>\n</video>\n',changeDetection:n.ChangeDetectionStrategy.OnPush,styles:[":host{display:block}video{width:100%;height:auto;-o-object-fit:contain;object-fit:contain}"]}),c("design:paramtypes",[])],e)}(),y=function(){function e(){}return e=a([n.NgModule({imports:[t.CommonModule,r.FormsModule],declarations:[v],exports:[v]})],e)}();e.ZXingScannerComponent=v,e.ZXingScannerModule=y,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=zxing-ngx-scanner.umd.min.js.map