UNPKG

@sd-angular/core

Version:

Sd Angular Core Lib

16 lines (14 loc) • 7.89 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("uuid"),require("konva"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@sd-angular/core/konva",["exports","@angular/core","@angular/common","uuid","konva","rxjs","rxjs/operators"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self)["sd-angular"]=e["sd-angular"]||{},e["sd-angular"].core=e["sd-angular"].core||{},e["sd-angular"].core.konva={}),e.ng.core,e.ng.common,e.uuid,e.konva,e.rxjs,e.rxjs.operators)}(this,(function(e,t,n,r,o,a,i){"use strict";function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=s(o); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */function c(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}u((r=r.apply(e,t||[])).next())}))}function l(e,t){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}Object.create;function f(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function d(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,a=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=a.next()).done;)i.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(o)throw o.error}}return i}var p,h,g,y,v,m,w,b;Object.create;function x(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function k(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}var j=function(){function e(e){var n=this;this.ref=e,this.id="I"+r.v4(),this.kImages=[],p.set(this,void 0),h.set(this,void 0),g.set(this,void 0),y.set(this,void 0),v.set(this,void 0),this.save=new t.EventEmitter,m.set(this,void 0),w.set(this,new a.Subject),b.set(this,new a.Subscription),this.toImage=function(){return c(n,void 0,void 0,(function(){var e=this;return l(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t){var n;null===(n=x(e,y))||void 0===n||n.toImage({callback:function(e){t(e)}})}))];case 1:return[2,t.sent()]}}))}))},this.toDataUrl=function(){return x(n,y).toDataURL()}}return Object.defineProperty(e.prototype,"height",{set:function(e){k(this,p,+e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"width",{set:function(e){k(this,h,+e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"images",{set:function(e){var t=this;setTimeout((function(){k(t,g,e),x(t,w).next(x(t,g))}),2e3)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"container",{set:function(e){x(this,m)!==e&&(k(this,m,e),x(this,w).next(x(this,g)))},enumerable:!1,configurable:!0}),e.prototype.ngOnInit=function(){},e.prototype.ngAfterViewInit=function(){var e=this;x(this,b).add(x(this,w).pipe(i.startWith([])).subscribe((function(){var t,n,r;if(document.getElementById(e.id)&&(document.getElementById(e.id).innerHTML="",null===(r=x(e,g))||void 0===r?void 0:r.length)){var o=x(e,g);k(e,y,new u.default.Stage({container:e.id,width:x(e,h),height:x(e,p)})),k(e,v,new u.default.Layer),x(e,y).add(x(e,v));var a=function(t,n){var r=0,a=0,i=x(e,h)/2,s=x(e,p)/2;1===o.length?(r=x(e,h)/4,a=x(e,p)/4):2===o.length?0===t?(r=0,a=x(e,p)/4):1===t&&(r=x(e,h)/2,a=x(e,p)/4):3===o.length?0===t?(r=0,a=0):1===t?(r=x(e,h)/2,a=0):2===t&&(r=x(e,h)/4,a=x(e,p)/4):4===o.length&&(0===t?(r=0,a=0):1===t?(r=x(e,h)/2,a=0):2===t?(r=0,a=x(e,p)/2):3===t&&(r=x(e,h)/2,a=x(e,p)/2));var c=new Image,l=new u.default.Image({image:c,x:r,y:a,width:i,height:s,name:"image",draggable:!0});e.kImages.push(l),c.onload=function(){l.image(c),e.ref.detectChanges()},c.crossOrigin="Anonymous",c.src=n,x(e,v).add(l)};try{for(var i=f(o.entries()),s=i.next();!s.done;s=i.next()){var c=d(s.value,2);a(c[0],c[1])}}catch(e){t={error:e}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}var l=new u.default.Transformer;x(e,v).add(l),x(e,v).draw(),e.ref.detectChanges(),x(e,y).on("click tap",(function(t){if(t.target===x(e,y))return l.nodes([]),void x(e,v).draw();if(t.target.hasName("rect")||t.target.hasName("image")){var n=t.evt.shiftKey||t.evt.ctrlKey||t.evt.metaKey,r=l.nodes().indexOf(t.target)>=0;if(n||r){if(n&&r){(o=l.nodes().slice()).splice(o.indexOf(t.target),1),l.nodes(o)}else if(n&&!r){var o=l.nodes().concat([t.target]);l.nodes(o)}}else l.nodes([t.target]);x(e,v).draw()}}))}})))},e.prototype.ngOnDestroy=function(){x(this,b).unsubscribe()},e}();p=new WeakMap,h=new WeakMap,g=new WeakMap,y=new WeakMap,v=new WeakMap,m=new WeakMap,w=new WeakMap,b=new WeakMap,j.decorators=[{type:t.Component,args:[{selector:"sd-merge-images",template:'<div [id]="id" #container></div>',styles:[":host ::ng-deep .konvajs-content{border:2px solid #dadada}"]}]}],j.ctorParameters=function(){return[{type:t.ChangeDetectorRef}]},j.propDecorators={height:[{type:t.Input}],width:[{type:t.Input}],images:[{type:t.Input}],save:[{type:t.Output}],container:[{type:t.ViewChild,args:["container"]}]};var I=function(){};I.decorators=[{type:t.NgModule,args:[{declarations:[j],imports:[n.CommonModule],exports:[j]}]}],e.SdKonvaModule=I,e.SdMergeImages=j,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=sd-angular-core-konva.umd.min.js.map