ngx-opencv-16
Version:
Angular service for implementing the OpenCV library in angular based applications
2 lines • 2.32 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("rxjs")):"function"==typeof define&&define.amd?define("ngx-opencv",["exports","@angular/core","rxjs"],t):t((e=e||self)["ngx-opencv"]={},e.ng.core,e.rxjs)}(this,(function(e,t,n){"use strict";var o=new t.InjectionToken("OpenCV config object token"),r=function(){function e(e,t){this._ngZone=t,this.cvState=new n.BehaviorSubject({ready:!1,error:!1,loading:!0,state:"loading"}),e||(e={}),this.configModule=this.generateConfigModule(e),this.loadOpenCv()}return e.prototype.loadOpenCv=function(){var e=this;this.cvState.next(this.newState("loading")),window.Module=this.configModule;var t=document.createElement("script");t.setAttribute("async",""),t.setAttribute("type","text/javascript"),t.addEventListener("error",(function(){var t=new Error("Failed to load "+e.configModule.scriptUrl);e.cvState.next(e.newState("error")),e.cvState.error(t)}),{passive:!0}),t.src=this.configModule.scriptUrl;var n=document.getElementsByTagName("script")[0];n?n.parentNode.insertBefore(t,n):document.head.appendChild(t)},e.prototype.newState=function(e){var t={ready:!1,loading:!1,error:!1,state:""};return Object.keys(t).forEach((function(n){"state"!==n&&(n===e?(t[n]=!0,t.state=n):t[n]=!1)})),t},e.prototype.generateConfigModule=function(e){var t=this;return{scriptUrl:e.openCVDirPath?e.openCVDirPath+"/opencv.js":"/assets/opencv/opencv.js",wasmBinaryFile:"opencv_js.wasm",usingWasm:!0,onRuntimeInitialized:function(){t._ngZone.run((function(){console.log("openCV Ready"),t.cvState.next(t.newState("ready")),e.runOnOpenCVInit&&e.runOnOpenCVInit()}))}}},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Inject,args:[o]}]},{type:t.NgZone}]},e.ɵprov=t.ɵɵdefineInjectable({factory:function(){return new e(t.ɵɵinject(o),t.ɵɵinject(t.NgZone))},token:e,providedIn:"root"}),e}();var i=function(){function e(){}return e.forRoot=function(t){return{ngModule:e,providers:[{provide:o,useValue:t}]}},e.decorators=[{type:t.NgModule,args:[{declarations:[],exports:[],providers:[r]}]}],e}();e.NgxOpenCVModule=i,e.NgxOpenCVService=r,e.OpenCvConfigToken=o,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-opencv.umd.min.js.map