kritzel-stencil 0.0.102 → 0.0.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/kritzel-brush-style_18.cjs.entry.js +16 -19
- package/dist/cjs/kritzel-brush-style_18.cjs.entry.js.map +1 -1
- package/dist/collection/classes/handlers/rotation.handler.js +0 -1
- package/dist/collection/classes/handlers/rotation.handler.js.map +1 -1
- package/dist/collection/classes/objects/selection-group.class.js +7 -8
- package/dist/collection/classes/objects/selection-group.class.js.map +1 -1
- package/dist/collection/classes/reviver.class.js +0 -2
- package/dist/collection/classes/reviver.class.js.map +1 -1
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.css +2 -3
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +8 -7
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
- package/dist/components/kritzel-editor.js +1 -1
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/{p-CF-8joQn.js → p-DMSOfO6k.js} +18 -21
- package/dist/components/p-DMSOfO6k.js.map +1 -0
- package/dist/esm/kritzel-brush-style_18.entry.js +16 -19
- package/dist/esm/kritzel-brush-style_18.entry.js.map +1 -1
- package/dist/stencil/p-f059fbff.entry.js +2 -0
- package/dist/stencil/p-f059fbff.entry.js.map +1 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/package.json +1 -1
- package/dist/components/p-CF-8joQn.js.map +0 -1
- package/dist/stencil/p-73d454f3.entry.js +0 -2
- package/dist/stencil/p-73d454f3.entry.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as t,c as i,h as e,H as s,a as n}from"./p-BOJOOWaP.js";const r=":host{display:flex;align-items:flex-start;gap:8px;padding:8px;box-sizing:border-box;width:100%}.brush-style-button{display:flex;justify-content:center;align-items:center;width:42px;height:32px;padding:0;border:none;outline:none;background:none;cursor:default;border-radius:0;color:var(--control-text-color);font-weight:bold;-webkit-tap-highlight-color:transparent}.font-style-button:not(:last-child){border-right:1px solid #333333}.font-style-button:hover{background-color:var(--control-hover-bg)}.font-style-button:active{background-color:var(--control-active-bg)}.font-style-button.selected,.font-style-button.selected:hover,.font-style-button.selected:active{background-color:var(--control-selected-bg);color:var(--control-selected-color)}";const o=class{constructor(e){t(this,e);this.typeChange=i(this,"typeChange");this.type="pen";this.brushOptions=[{value:"pen",label:"Pen"},{value:"highlighter",label:"Highlighter"}]}handleDropdownValueChange(t){this.typeChange.emit(t.detail)}render(){const t=this.brushOptions.map((t=>({value:t.value,label:t.label})));return e(s,{key:"cb9a9485596d25280c6d96e30296ed8c6b3de0e1"},e("kritzel-dropdown",{key:"b2f22f627e91228ca42bcd2898b468fcb994d5f8",options:t,value:this.type,onValueChanged:t=>this.handleDropdownValueChange(t)},e("button",{key:"1a8ab8cc0917bcdcbbbd485354853b80dd2f9a7f",class:"brush-style-button",slot:"prefix"},e("kritzel-icon",{key:"62238f43f6a88a0a01d47e56d48179834edc4fc1",name:this.type,size:16}))))}};o.style=r;const h=":host{display:flex}.checkerboard-bg{background:repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 50% / 8px 8px;position:relative;overflow:hidden}.color-circle{width:24px;height:24px;border-radius:50%;box-sizing:border-box;display:block}.color-circle.white{border:1px solid var(--kritzel-color-palette-circle-border-color, #dddcdc)}";const a=class{constructor(i){t(this,i);this.size=24}isLightColor(t){if(!t)return false;let i=0,e=0,s=0;let n=t.startsWith("#")?t.slice(1):t;if(n.length===3){i=parseInt(n[0]+n[0],16);e=parseInt(n[1]+n[1],16);s=parseInt(n[2]+n[2],16)}else if(n.length===6){i=parseInt(n.substring(0,2),16);e=parseInt(n.substring(2,4),16);s=parseInt(n.substring(4,6),16)}else{return false}if(isNaN(i)||isNaN(e)||isNaN(s)){return false}const r=.299*i+.587*e+.114*s;return r>220}render(){const t=this.isLightColor(this.value);return e(s,{key:"e913815994a30d97f92781e742c4a13de19e59fe"},e("div",{key:"e0cc40b10dcb298f5b86be7d4283d6bffbd08c2c",class:"checkerboard-bg",style:{width:`${this.size}px`,height:`${this.size}px`,borderRadius:"50%",display:"inline-block",position:"relative"}},e("div",{key:"5e0a092a6d3463d852a1760d125fba04494e0d90",class:{"color-circle":true,white:t},style:{backgroundColor:this.value,width:`${this.size}px`,height:`${this.size}px`,borderRadius:"50%",position:"absolute",top:"0",left:"0",display:"inline-block"}})))}};a.style=h;const l=":host{display:flex;align-items:flex-start;gap:8px;padding:8px;width:100%;box-sizing:border-box}.color-grid{width:100%;display:grid;grid-template-columns:repeat(6, 32px);gap:8px;justify-items:center;overflow:hidden;height:40px;transition:height 0.1s ease-in-out}.color-grid.expanded{height:500px}.color-container{display:flex;justify-content:center;align-items:center;width:32px;height:32px;border-radius:50%;cursor:pointer;border:2px solid transparent;box-sizing:border-box}.color-container:hover{background-color:var(--kritzel-color-palette-hover-background-color, #f0f0f0)}.color-container.selected{border-color:var(--kritzel-selection-border-color, #0E1111);background-color:var(--kritzel-color-palette-selected-background-color)}";const c=class{constructor(e){t(this,e);this.colorChange=i(this,"colorChange");this.colors=[];this.selectedColor=null;this.isExpanded=false;this.isOpaque=false}handleColorClick(t){this.selectedColor=t;this.colorChange.emit(t)}calculateHeight(){const t=6;const i=32;const e=8;const s=Math.ceil(this.colors.length/t);return`${s*i+(s-1)*e}px`}render(){const t=this.isExpanded?this.colors:this.colors.slice(0,6);const i=this.isExpanded?this.calculateHeight():"32px";return e(s,{key:"0f0d176e1c8b199a973dbdb23b84e4a8d4d57f59"},e("div",{key:"1d4707cdb30752d21a5058dbbef5fb32934bd3bd",class:{"color-grid":true,expanded:this.isExpanded},style:{height:i}},t.map((t=>e("div",{class:{"color-container":true,selected:this.selectedColor===t},onClick:()=>this.handleColorClick(t)},e("kritzel-color",{value:t}))))))}};c.style=l;const f=":host{display:block}.menu-container{display:flex;flex-direction:column;background-color:var(--kritzel-context-menu-background-color, #ffffff);border-radius:var(--kritzel-context-menu-border-radius, 8px);box-shadow:var(--kritzel-context-menu-box-shadow, 0 1px 6px rgba(0, 0, 0, 0.12));border:var(--kritzel-context-menu-border, 1px solid hsl(0, 0%, 0%, 4.3%));padding:var(--kritzel-context-menu-padding,4px)}.menu-item{display:flex;align-items:center;gap:var(--kritzel-context-menu-item-gap, 8px);background:none;border:none;text-align:left;padding:var(--kritzel-context-menu-item-padding, 8px);border-radius:var(--kritzel-context-menu-item-border-radius, 8px);cursor:pointer;font-size:var(--kritzel-context-menu-item-font-size, 14px);color:var(--kritzel-context-menu-item-color, #333333);white-space:nowrap;-webkit-tap-highlight-color:transparent}.menu-item:not(.disabled):hover{background-color:var(--kritzel-context-menu-item-hover-background-color, hsl(0, 0%, 0%, 4.3%))}.menu-item:not(.disabled):active{background-color:var(--kritzel-context-menu-item-active-background-color, hsl(0, 0%, 0%, 8.6%))}.menu-item.disabled{color:var(--kritzel-context-menu-item-disabled-color, #aaaaaa);cursor:default}.menu-item kritzel-icon{opacity:0.8;flex-shrink:0}.menu-item.disabled kritzel-icon{opacity:0.4}.label{flex-grow:1}";const u=class{constructor(e){t(this,e);this.actionSelected=i(this,"actionSelected");this.close=i(this,"close")}handleItemClick(t){const i=typeof t.disabled==="function"?t.disabled():t.disabled;if(!i){this.actionSelected.emit(t)}}render(){return e(s,{key:"dfbafed8ab0ab62e8124763431e00283ddfc9aaa"},e("div",{key:"d0d7cf6241d24bd85ca2f4d2aa3e23aeb4283d82",class:"menu-container"},this.items.map((t=>e("button",{key:`${t.label}-${this.items.indexOf(t)}`,class:{"menu-item":true,disabled:typeof t.disabled==="function"?t.disabled():t.disabled},onClick:()=>this.handleItemClick(t),onTouchStart:()=>this.handleItemClick(t),disabled:typeof t.disabled==="function"?t.disabled():t.disabled},t.icon&&e("kritzel-icon",{name:t.icon,size:16}),e("span",{class:"label"},t.label))))))}get hostElement(){return n(this)}};u.style=f;const d=":host{display:flex;flex-direction:column;width:100%}.expand-toggle{background:none;border:none;cursor:pointer;font-size:14px;line-height:1;padding:8px;color:var(--kritzel-color-palette-expand-toggle-color, #666666)}.expand-toggle:hover{color:var(--kritzel-color-palette-expand-toggle-hover-color, #333333)}";const v=class{constructor(e){t(this,e);this.toolChange=i(this,"toolChange");this.isExpanded=false;this.palette=[]}handleToolChange(t){this.palette=t.palettes[t.type]}componentWillLoad(){this.palette=this.tool.palettes[this.tool.type]}handleToggleExpand(){this.isExpanded=!this.isExpanded}handleTypeChange(t){this.palette=this.tool.palettes[t.detail];this.tool.type=t.detail;this.tool.color=this.palette[0];this.toolChange.emit(this.tool)}handleColorChange(t){this.tool.color=t.detail;this.toolChange.emit(this.tool)}handleSizeChange(t){this.tool.size=t.detail;this.toolChange.emit(this.tool)}render(){return e(s,{key:"1658cc6062f9a62c11a7011e36bd5f892653f691"},e("div",{key:"bfafd20ebc6f7541e6a0952b555e3aefd0524086",style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-start",width:"100%",gap:"8px"}},e("kritzel-brush-style",{key:"6530b0fbee10db66f6dfd0e482e2a95279f303eb",type:this.tool.type,onTypeChange:t=>this.handleTypeChange(t)}),e("button",{key:"f16a4c5aefb298228d29576d6bf8a0632301169d",class:"expand-toggle",onClick:()=>this.handleToggleExpand(),title:this.isExpanded?"Collapse":"Expand",style:this.palette.length>6?{visibillity:"visible"}:{visibility:"hidden"}},e("kritzel-icon",{key:"138726189ee12b0d15dedfdbd07019701712ea3b",name:this.isExpanded?"chevron-up":"chevron-down"}))),e("kritzel-color-palette",{key:"ca15a07a28ad955d49289299265e1b62da508cfd",colors:this.palette,selectedColor:this.tool.color,isExpanded:this.isExpanded,isOpaque:true,onColorChange:t=>this.handleColorChange(t)}),e("kritzel-stroke-size",{key:"1017df7a36bad69af055fe08e685a1be3ff48b4b",selectedSize:this.tool.size,onSizeChange:t=>this.handleSizeChange(t)}))}static get watchers(){return{tool:["handleToolChange"]}}};v.style=d;const b=":host{display:block;flex-direction:column;width:100%}.expand-toggle{background:none;border:none;cursor:pointer;font-size:14px;line-height:1;padding:8px;color:var(--kritzel-color-palette-expand-toggle-color, #666666)}.expand-toggle:hover{color:var(--kritzel-color-palette-expand-toggle-hover-color, #333333)}";const p=class{constructor(e){t(this,e);this.toolChange=i(this,"toolChange");this.isExpanded=false}handleToggleExpand(){this.isExpanded=!this.isExpanded}handleFamilyChange(t){this.tool.fontFamily=t.detail;this.toolChange.emit(this.tool)}handleColorChange(t){this.tool.fontColor=t.detail;this.toolChange.emit(this.tool)}handleSizeChange(t){this.tool.fontSize=t.detail;this.toolChange.emit(this.tool)}render(){return e(s,{key:"27d47c47987fb7644313a4face4a7023dfbe454d"},e("div",{key:"835b8072267da18b39a5c02a6c989e1f7b81e9a5",style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-start",width:"100%",gap:"8px"}},e("kritzel-font-family",{key:"b7a0bde2e9cf53c9ae7c3a32b424825ca9f757c4",selectedFontFamily:this.tool.fontFamily,onFontFamilyChange:t=>this.handleFamilyChange(t)}),e("button",{key:"41aba583656195c4825a15ddc12c5e1efed0d8d2",class:"expand-toggle",onClick:()=>this.handleToggleExpand(),title:this.isExpanded?"Collapse":"Expand"},e("kritzel-icon",{key:"5ff979420066703b5d5e886d12f89687392006e3",name:this.isExpanded?"chevron-up":"chevron-down"}))),e("kritzel-color-palette",{key:"30fbcc05f80b15fba7f1f5ac6413732d0149ee9b",colors:this.tool.palette,selectedColor:this.tool.fontColor,isExpanded:this.isExpanded,onColorChange:t=>this.handleColorChange(t)}),e("kritzel-font-size",{key:"2a0d3c4578316b37bc1a25b6e065ecf565eca2b3",selectedSize:this.tool.fontSize,fontFamily:this.tool.fontFamily,onSizeChange:t=>this.handleSizeChange(t)}))}};p.style=b;var g;(function(t){t[t["Left"]=0]="Left";t[t["Middle"]=1]="Middle";t[t["Right"]=2]="Right"})(g||(g={}));class w{static isRightClick(t){return t.button===g.Right}static isLeftClick(t){return t.button===g.Left}static isMainMouseWheel(t){return Math.abs(t.deltaY)>0&&Math.abs(t.deltaX)===0&&Number.isInteger(t.deltaY)}static detectDoubleTap(){const t=Date.now();const i=t-w.lastTapTimestamp;if(w.tapTimeoutId){clearTimeout(w.tapTimeoutId);w.tapTimeoutId=null}if(i<w.doubleTapTimeout&&i>0){w.lastTapTimestamp=0;return true}else{w.lastTapTimestamp=t;w.tapTimeoutId=setTimeout((()=>{w.tapTimeoutId=null}),w.doubleTapTimeout);return false}}}w.lastTapTimestamp=0;w.tapTimeoutId=null;w.doubleTapTimeout=300;class y{constructor(t,i){var e,s;this._store=t;this.initiator=(s=(e=i===null||i===void 0?void 0:i.constructor)===null||e===void 0?void 0:e.name)!==null&&s!==void 0?s:"Unknown";this.isUndoable=true}execute(){throw new Error("Method not implemented.")}undo(){throw new Error("Method not implemented.")}}class k extends y{constructor(t,i,e){super(t,i);this.object=e}execute(){this._store.state.objectsOctree.insert(this.object)}undo(){this._store.state.objectsOctree.remove((t=>t.id===this.object.id))}}var x={};var m;function A(){if(m)return x;m=1;(function(t){var i=Object.defineProperty;var e=t=>i(t,"__esModule",{value:true});var s=(t,s)=>{e(t);for(var n in s)i(t,n,{get:s[n],enumerable:true})};s(t,{default:()=>C,getStroke:()=>T,getStrokeOutlinePoints:()=>M,getStrokePoints:()=>j});function n(t,i,e,s=t=>t){return t*s(.5-i*(.5-e))}function r(t){return[-t[0],-t[1]]}function o(t,i){return[t[0]+i[0],t[1]+i[1]]}function h(t,i){return[t[0]-i[0],t[1]-i[1]]}function a(t,i){return[t[0]*i,t[1]*i]}function l(t,i){return[t[0]/i,t[1]/i]}function c(t){return[t[1],-t[0]]}function f(t,i){return t[0]*i[0]+t[1]*i[1]}function u(t,i){return t[0]===i[0]&&t[1]===i[1]}function d(t){return Math.hypot(t[0],t[1])}function v(t){return t[0]*t[0]+t[1]*t[1]}function b(t,i){return v(h(t,i))}function p(t){return l(t,d(t))}function g(t,i){return Math.hypot(t[1]-i[1],t[0]-i[0])}function w(t,i,e){let s=Math.sin(e),n=Math.cos(e),r=t[0]-i[0],o=t[1]-i[1],h=r*n-o*s,a=r*s+o*n;return[h+i[0],a+i[1]]}function y(t,i,e){return o(t,a(h(i,t),e))}function k(t,i,e){return o(t,a(i,e))}var{min:x,PI:m}=Math,A=.275,z=m+1e-4;function M(t,i={}){let{size:e=16,smoothing:s=.5,thinning:l=.5,simulatePressure:u=true,easing:d=t=>t,start:v={},end:g={},last:m=false}=i,{cap:M=true,easing:j=t=>t*(2-t)}=v,{cap:T=true,easing:C=t=>--t*t*t+1}=g;if(t.length===0||e<=0)return[];let S=t[t.length-1].runningLength,E=v.taper===false?0:v.taper===true?Math.max(e,S):v.taper,F=g.taper===false?0:g.taper===true?Math.max(e,S):g.taper,I=Math.pow(e*s,2),U=[],B=[],O=t.slice(0,10).reduce(((t,i)=>{let s=i.pressure;if(u){let n=x(1,i.distance/e),r=x(1,1-n);s=x(1,t+(r-t)*(n*A))}return(t+s)/2}),t[0].pressure),$=n(e,l,t[t.length-1].pressure,d),D,_=t[0].vector,P=t[0].point,R=P,Q=P,W=R,L=false;for(let i=0;i<t.length;i++){let{pressure:s}=t[i],{point:r,vector:v,distance:p,runningLength:g}=t[i];if(i<t.length-1&&S-g<3)continue;if(l){if(u){let t=x(1,p/e),i=x(1,1-t);s=x(1,O+(i-O)*(t*A))}$=n(e,l,s,d)}else $=e/2;D===void 0&&(D=$);let k=g<E?j(g/E):1,m=S-g<F?C((S-g)/F):1;$=Math.max(.01,$*Math.min(k,m));let M=(i<t.length-1?t[i+1]:t[i]).vector,T=i<t.length-1?f(v,M):1,H=f(v,_)<0&&!L,V=T!==null&&T<0;if(H||V){let t=a(c(_),$);for(let i=1/13,e=0;e<=1;e+=i)Q=w(h(r,t),r,z*e),U.push(Q),W=w(o(r,t),r,z*-e),B.push(W);P=Q,R=W,V&&(L=true);continue}if(L=false,i===t.length-1){let t=a(c(v),$);U.push(h(r,t)),B.push(o(r,t));continue}let K=a(c(y(M,v,T)),$);Q=h(r,K),(i<=1||b(P,Q)>I)&&(U.push(Q),P=Q),W=o(r,K),(i<=1||b(R,W)>I)&&(B.push(W),R=W),O=s,_=v}let H=t[0].point.slice(0,2),V=t.length>1?t[t.length-1].point.slice(0,2):o(t[0].point,[1,1]),K=[],X=[];if(t.length===1){if(!(E||F)||m){let t=k(H,p(c(h(H,V))),-(D||$)),i=[];for(let e=1/13,s=e;s<=1;s+=e)i.push(w(t,H,z*2*s));return i}}else{if(!(E||F&&t.length===1))if(M)for(let t=1/13,i=t;i<=1;i+=t){let t=w(B[0],H,z*i);K.push(t)}else{let t=h(U[0],B[0]),i=a(t,.5),e=a(t,.51);K.push(h(H,i),h(H,e),o(H,e),o(H,i))}let i=c(r(t[t.length-1].vector));if(F||E&&t.length===1)X.push(V);else if(T){let t=k(V,i,$);for(let i=1/29,e=i;e<1;e+=i)X.push(w(t,V,z*3*e))}else X.push(o(V,a(i,$)),o(V,a(i,$*.99)),h(V,a(i,$*.99)),h(V,a(i,$)))}return U.concat(X,B.reverse(),K)}function j(t,i={}){var e;let{streamline:s=.5,size:n=16,last:r=false}=i;if(t.length===0)return[];let a=.15+(1-s)*.85,l=Array.isArray(t[0])?t:t.map((({x:t,y:i,pressure:e=.5})=>[t,i,e]));if(l.length===2){let t=l[1];l=l.slice(0,-1);for(let i=1;i<5;i++)l.push(y(l[0],t,i/4))}l.length===1&&(l=[...l,[...o(l[0],[1,1]),...l[0].slice(2)]]);let c=[{point:[l[0][0],l[0][1]],pressure:l[0][2]>=0?l[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],f=false,d=0,v=c[0],b=l.length-1;for(let t=1;t<l.length;t++){let i=r&&t===b?l[t].slice(0,2):y(v.point,l[t],a);if(u(v.point,i))continue;let e=g(i,v.point);if(d+=e,t<b&&!f){if(d<n)continue;f=true}v={point:i,pressure:l[t][2]>=0?l[t][2]:.5,vector:p(h(v.point,i)),distance:e,runningLength:d},c.push(v)}return c[0].vector=((e=c[1])==null?void 0:e.vector)||[0,0],c}function T(t,i={}){return M(j(t,i),i)}var C=T})(x);return x}var z=A();class M{static average(t,i){return(t+i)/2}}var j=typeof global=="object"&&global&&global.Object===Object&&global;var T=typeof self=="object"&&self&&self.Object===Object&&self;var C=j||T||Function("return this")();var S=C.Symbol;var E=Object.prototype;var F=E.hasOwnProperty;var I=E.toString;var U=S?S.toStringTag:undefined;function B(t){var i=F.call(t,U),e=t[U];try{t[U]=undefined;var s=true}catch(t){}var n=I.call(t);if(s){if(i){t[U]=e}else{delete t[U]}}return n}var O=Object.prototype;var $=O.toString;function D(t){return $.call(t)}var _="[object Null]",P="[object Undefined]";var R=S?S.toStringTag:undefined;function Q(t){if(t==null){return t===undefined?P:_}return R&&R in Object(t)?B(t):D(t)}function W(t){return t!=null&&typeof t=="object"}var L=Array.isArray;function H(t){var i=typeof t;return t!=null&&(i=="object"||i=="function")}var V="[object AsyncFunction]",K="[object Function]",X="[object GeneratorFunction]",N="[object Proxy]";function Y(t){if(!H(t)){return false}var i=Q(t);return i==K||i==X||i==V||i==N}var G=C["__core-js_shared__"];var q=function(){var t=/[^.]+$/.exec(G&&G.keys&&G.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function Z(t){return!!q&&q in t}var J=Function.prototype;var tt=J.toString;function it(t){if(t!=null){try{return tt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var et=/[\\^$.*+?()[\]{}|]/g;var st=/^\[object .+?Constructor\]$/;var nt=Function.prototype,rt=Object.prototype;var ot=nt.toString;var ht=rt.hasOwnProperty;var at=RegExp("^"+ot.call(ht).replace(et,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function lt(t){if(!H(t)||Z(t)){return false}var i=Y(t)?at:st;return i.test(it(t))}function ct(t,i){return t==null?undefined:t[i]}function ft(t,i){var e=ct(t,i);return lt(e)?e:undefined}var ut=ft(C,"WeakMap");var dt=Object.create;var vt=function(){function t(){}return function(i){if(!H(i)){return{}}if(dt){return dt(i)}t.prototype=i;var e=new t;t.prototype=undefined;return e}}();var bt=function(){try{var t=ft(Object,"defineProperty");t({},"",{});return t}catch(t){}}();function pt(t,i){var e=-1,s=t==null?0:t.length;while(++e<s){if(i(t[e],e,t)===false){break}}return t}var gt=9007199254740991;var wt=/^(?:0|[1-9]\d*)$/;function yt(t,i){var e=typeof t;i=i==null?gt:i;return!!i&&(e=="number"||e!="symbol"&&wt.test(t))&&(t>-1&&t%1==0&&t<i)}function kt(t,i,e){if(i=="__proto__"&&bt){bt(t,i,{configurable:true,enumerable:true,value:e,writable:true})}else{t[i]=e}}function xt(t,i){return t===i||t!==t&&i!==i}var mt=Object.prototype;var At=mt.hasOwnProperty;function zt(t,i,e){var s=t[i];if(!(At.call(t,i)&&xt(s,e))||e===undefined&&!(i in t)){kt(t,i,e)}}var Mt=9007199254740991;function jt(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=Mt}function Tt(t){return t!=null&&jt(t.length)&&!Y(t)}var Ct=Object.prototype;function St(t){var i=t&&t.constructor,e=typeof i=="function"&&i.prototype||Ct;return t===e}function Et(t,i){var e=-1,s=Array(t);while(++e<t){s[e]=i(e)}return s}var Ft="[object Arguments]";function It(t){return W(t)&&Q(t)==Ft}var Ut=Object.prototype;var Bt=Ut.hasOwnProperty;var Ot=Ut.propertyIsEnumerable;var $t=It(function(){return arguments}())?It:function(t){return W(t)&&Bt.call(t,"callee")&&!Ot.call(t,"callee")};function Dt(){return false}var _t=typeof exports=="object"&&exports&&!exports.nodeType&&exports;var Pt=_t&&typeof module=="object"&&module&&!module.nodeType&&module;var Rt=Pt&&Pt.exports===_t;var Qt=Rt?C.Buffer:undefined;var Wt=Qt?Qt.isBuffer:undefined;var Lt=Wt||Dt;var Ht="[object Arguments]",Vt="[object Array]",Kt="[object Boolean]",Xt="[object Date]",Nt="[object Error]",Yt="[object Function]",Gt="[object Map]",qt="[object Number]",Zt="[object Object]",Jt="[object RegExp]",ti="[object Set]",ii="[object String]",ei="[object WeakMap]";var si="[object ArrayBuffer]",ni="[object DataView]",ri="[object Float32Array]",oi="[object Float64Array]",hi="[object Int8Array]",ai="[object Int16Array]",li="[object Int32Array]",ci="[object Uint8Array]",fi="[object Uint8ClampedArray]",ui="[object Uint16Array]",di="[object Uint32Array]";var vi={};vi[ri]=vi[oi]=vi[hi]=vi[ai]=vi[li]=vi[ci]=vi[fi]=vi[ui]=vi[di]=true;vi[Ht]=vi[Vt]=vi[si]=vi[Kt]=vi[ni]=vi[Xt]=vi[Nt]=vi[Yt]=vi[Gt]=vi[qt]=vi[Zt]=vi[Jt]=vi[ti]=vi[ii]=vi[ei]=false;function bi(t){return W(t)&&jt(t.length)&&!!vi[Q(t)]}function pi(t){return function(i){return t(i)}}var gi=typeof exports=="object"&&exports&&!exports.nodeType&&exports;var wi=gi&&typeof module=="object"&&module&&!module.nodeType&&module;var yi=wi&&wi.exports===gi;var ki=yi&&j.process;var xi=function(){try{var t=wi&&wi.require&&wi.require("util").types;if(t){return t}return ki&&ki.binding&&ki.binding("util")}catch(t){}}();var mi=xi&&xi.isTypedArray;var Ai=mi?pi(mi):bi;var zi=Object.prototype;var Mi=zi.hasOwnProperty;function ji(t,i){var e=L(t),s=!e&&$t(t),n=!e&&!s&&Lt(t),r=!e&&!s&&!n&&Ai(t),o=e||s||n||r,h=o?Et(t.length,String):[],a=h.length;for(var l in t){if(Mi.call(t,l)&&!(o&&(l=="length"||n&&(l=="offset"||l=="parent")||r&&(l=="buffer"||l=="byteLength"||l=="byteOffset")||yt(l,a)))){h.push(l)}}return h}function Ti(t,i){return function(e){return t(i(e))}}var Ci=Ti(Object.keys,Object);var Si=Object.prototype;var Ei=Si.hasOwnProperty;function Fi(t){if(!St(t)){return Ci(t)}var i=[];for(var e in Object(t)){if(Ei.call(t,e)&&e!="constructor"){i.push(e)}}return i}function Ii(t){return Tt(t)?ji(t):Fi(t)}var Ui=ft(Object,"create");function Bi(){this.__data__=Ui?Ui(null):{};this.size=0}function Oi(t){var i=this.has(t)&&delete this.__data__[t];this.size-=i?1:0;return i}var $i="__lodash_hash_undefined__";var Di=Object.prototype;var _i=Di.hasOwnProperty;function Pi(t){var i=this.__data__;if(Ui){var e=i[t];return e===$i?undefined:e}return _i.call(i,t)?i[t]:undefined}var Ri=Object.prototype;var Qi=Ri.hasOwnProperty;function Wi(t){var i=this.__data__;return Ui?i[t]!==undefined:Qi.call(i,t)}var Li="__lodash_hash_undefined__";function Hi(t,i){var e=this.__data__;this.size+=this.has(t)?0:1;e[t]=Ui&&i===undefined?Li:i;return this}function Vi(t){var i=-1,e=t==null?0:t.length;this.clear();while(++i<e){var s=t[i];this.set(s[0],s[1])}}Vi.prototype.clear=Bi;Vi.prototype["delete"]=Oi;Vi.prototype.get=Pi;Vi.prototype.has=Wi;Vi.prototype.set=Hi;function Ki(){this.__data__=[];this.size=0}function Xi(t,i){var e=t.length;while(e--){if(xt(t[e][0],i)){return e}}return-1}var Ni=Array.prototype;var Yi=Ni.splice;function Gi(t){var i=this.__data__,e=Xi(i,t);if(e<0){return false}var s=i.length-1;if(e==s){i.pop()}else{Yi.call(i,e,1)}--this.size;return true}function qi(t){var i=this.__data__,e=Xi(i,t);return e<0?undefined:i[e][1]}function Zi(t){return Xi(this.__data__,t)>-1}function Ji(t,i){var e=this.__data__,s=Xi(e,t);if(s<0){++this.size;e.push([t,i])}else{e[s][1]=i}return this}function te(t){var i=-1,e=t==null?0:t.length;this.clear();while(++i<e){var s=t[i];this.set(s[0],s[1])}}te.prototype.clear=Ki;te.prototype["delete"]=Gi;te.prototype.get=qi;te.prototype.has=Zi;te.prototype.set=Ji;var ie=ft(C,"Map");function ee(){this.size=0;this.__data__={hash:new Vi,map:new(ie||te),string:new Vi}}function se(t){var i=typeof t;return i=="string"||i=="number"||i=="symbol"||i=="boolean"?t!=="__proto__":t===null}function ne(t,i){var e=t.__data__;return se(i)?e[typeof i=="string"?"string":"hash"]:e.map}function re(t){var i=ne(this,t)["delete"](t);this.size-=i?1:0;return i}function oe(t){return ne(this,t).get(t)}function he(t){return ne(this,t).has(t)}function ae(t,i){var e=ne(this,t),s=e.size;e.set(t,i);this.size+=e.size==s?0:1;return this}function le(t){var i=-1,e=t==null?0:t.length;this.clear();while(++i<e){var s=t[i];this.set(s[0],s[1])}}le.prototype.clear=ee;le.prototype["delete"]=re;le.prototype.get=oe;le.prototype.has=he;le.prototype.set=ae;function ce(t,i){var e=-1,s=i.length,n=t.length;while(++e<s){t[n+e]=i[e]}return t}var fe=Ti(Object.getPrototypeOf,Object);function ue(){this.__data__=new te;this.size=0}function de(t){var i=this.__data__,e=i["delete"](t);this.size=i.size;return e}function ve(t){return this.__data__.get(t)}function be(t){return this.__data__.has(t)}var pe=200;function ge(t,i){var e=this.__data__;if(e instanceof te){var s=e.__data__;if(!ie||s.length<pe-1){s.push([t,i]);this.size=++e.size;return this}e=this.__data__=new le(s)}e.set(t,i);this.size=e.size;return this}function we(t){var i=this.__data__=new te(t);this.size=i.size}we.prototype.clear=ue;we.prototype["delete"]=de;we.prototype.get=ve;we.prototype.has=be;we.prototype.set=ge;var ye=typeof exports=="object"&&exports&&!exports.nodeType&&exports;ye&&typeof module=="object"&&module&&!module.nodeType&&module;function ke(t,i){{return t.slice()}}function xe(t,i){var e=-1,s=t==null?0:t.length,n=0,r=[];while(++e<s){var o=t[e];if(i(o,e,t)){r[n++]=o}}return r}function me(){return[]}var Ae=Object.prototype;var ze=Ae.propertyIsEnumerable;var Me=Object.getOwnPropertySymbols;var je=!Me?me:function(t){if(t==null){return[]}t=Object(t);return xe(Me(t),(function(i){return ze.call(t,i)}))};function Te(t,i,e){var s=i(t);return L(t)?s:ce(s,e(t))}function Ce(t){return Te(t,Ii,je)}var Se=ft(C,"DataView");var Ee=ft(C,"Promise");var Fe=ft(C,"Set");var Ie="[object Map]",Ue="[object Object]",Be="[object Promise]",Oe="[object Set]",$e="[object WeakMap]";var De="[object DataView]";var _e=it(Se),Pe=it(ie),Re=it(Ee),Qe=it(Fe),We=it(ut);var Le=Q;if(Se&&Le(new Se(new ArrayBuffer(1)))!=De||ie&&Le(new ie)!=Ie||Ee&&Le(Ee.resolve())!=Be||Fe&&Le(new Fe)!=Oe||ut&&Le(new ut)!=$e){Le=function(t){var i=Q(t),e=i==Ue?t.constructor:undefined,s=e?it(e):"";if(s){switch(s){case _e:return De;case Pe:return Ie;case Re:return Be;case Qe:return Oe;case We:return $e}}return i}}var He=Object.prototype;var Ve=He.hasOwnProperty;function Ke(t){var i=t.length,e=new t.constructor(i);if(i&&typeof t[0]=="string"&&Ve.call(t,"index")){e.index=t.index;e.input=t.input}return e}var Xe=C.Uint8Array;function Ne(t){var i=new t.constructor(t.byteLength);new Xe(i).set(new Xe(t));return i}function Ye(t,i){var e=Ne(t.buffer);return new t.constructor(e,t.byteOffset,t.byteLength)}var Ge=/\w*$/;function qe(t){var i=new t.constructor(t.source,Ge.exec(t));i.lastIndex=t.lastIndex;return i}var Ze=S?S.prototype:undefined,Je=Ze?Ze.valueOf:undefined;function ts(t){return Je?Object(Je.call(t)):{}}function is(t,i){var e=Ne(t.buffer);return new t.constructor(e,t.byteOffset,t.length)}var es="[object Boolean]",ss="[object Date]",ns="[object Map]",rs="[object Number]",os="[object RegExp]",hs="[object Set]",as="[object String]",ls="[object Symbol]";var cs="[object ArrayBuffer]",fs="[object DataView]",us="[object Float32Array]",ds="[object Float64Array]",vs="[object Int8Array]",bs="[object Int16Array]",ps="[object Int32Array]",gs="[object Uint8Array]",ws="[object Uint8ClampedArray]",ys="[object Uint16Array]",ks="[object Uint32Array]";function xs(t,i,e){var s=t.constructor;switch(i){case cs:return Ne(t);case es:case ss:return new s(+t);case fs:return Ye(t);case us:case ds:case vs:case bs:case ps:case gs:case ws:case ys:case ks:return is(t);case ns:return new s;case rs:case as:return new s(t);case os:return qe(t);case hs:return new s;case ls:return ts(t)}}function ms(t){return typeof t.constructor=="function"&&!St(t)?vt(fe(t)):{}}var As="[object Map]";function zs(t){return W(t)&&Le(t)==As}var Ms=xi&&xi.isMap;var js=Ms?pi(Ms):zs;var Ts="[object Set]";function Cs(t){return W(t)&&Le(t)==Ts}var Ss=xi&&xi.isSet;var Es=Ss?pi(Ss):Cs;var Fs="[object Arguments]",Is="[object Array]",Us="[object Boolean]",Bs="[object Date]",Os="[object Error]",$s="[object Function]",Ds="[object GeneratorFunction]",_s="[object Map]",Ps="[object Number]",Rs="[object Object]",Qs="[object RegExp]",Ws="[object Set]",Ls="[object String]",Hs="[object Symbol]",Vs="[object WeakMap]";var Ks="[object ArrayBuffer]",Xs="[object DataView]",Ns="[object Float32Array]",Ys="[object Float64Array]",Gs="[object Int8Array]",qs="[object Int16Array]",Zs="[object Int32Array]",Js="[object Uint8Array]",tn="[object Uint8ClampedArray]",en="[object Uint16Array]",sn="[object Uint32Array]";var nn={};nn[Fs]=nn[Is]=nn[Ks]=nn[Xs]=nn[Us]=nn[Bs]=nn[Ns]=nn[Ys]=nn[Gs]=nn[qs]=nn[Zs]=nn[_s]=nn[Ps]=nn[Rs]=nn[Qs]=nn[Ws]=nn[Ls]=nn[Hs]=nn[Js]=nn[tn]=nn[en]=nn[sn]=true;nn[Os]=nn[$s]=nn[Vs]=false;function rn(t,i,e,s,n,r){var o;if(o!==undefined){return o}if(!H(t)){return t}var h=L(t);if(h){o=Ke(t)}else{var a=Le(t),l=a==$s||a==Ds;if(Lt(t)){return ke(t)}if(a==Rs||a==Fs||l&&!n){o=l?{}:ms(t)}else{if(!nn[a]){return n?t:{}}o=xs(t,a)}}r||(r=new we);var c=r.get(t);if(c){return c}r.set(t,o);if(Es(t)){t.forEach((function(s){o.add(rn(s,i,e,s,t,r))}))}else if(js(t)){t.forEach((function(s,n){o.set(n,rn(s,i,e,n,t,r))}))}var f=Ce;var u=h?undefined:f(t);pt(u||t,(function(s,n){if(u){n=s;s=t[n]}zt(o,n,rn(s,i,e,n,t,r))}));return o}var on=1,hn=4;function an(t){return rn(t,on|hn)}var ln=undefined&&undefined.__rest||function(t,i){var e={};for(var s in t)if(Object.prototype.hasOwnProperty.call(t,s)&&i.indexOf(s)<0)e[s]=t[s];if(t!=null&&typeof Object.getOwnPropertySymbols==="function")for(var n=0,s=Object.getOwnPropertySymbols(t);n<s.length;n++){if(i.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n]))e[s[n]]=t[s[n]]}return e};class cn{static safeStringify(t,i=2){const e=new WeakSet;return JSON.stringify(t,((t,i)=>{if(typeof i==="object"&&i!==null){if(e.has(i)){return undefined}e.add(i)}return i}),i)}static generateUUID(){return Math.random().toString(36).substr(2,9)}static clone(t){const i=t=>{const i=ln(t,["_store","_elementRef","totalWidth","totalHeight"]);return an(i)};if(Array.isArray(t)){return t.map(i)}return i(t)}static isEmpty(t){if(t===null||t===undefined){return true}return(Object===null||Object===void 0?void 0:Object.keys(t).length)===0&&(t===null||t===void 0?void 0:t.constructor)===Object}}class fn{get totalWidth(){return this.width+this.padding*2}get totalHeight(){return this.height+this.padding*2}set elementRef(t){this._elementRef=t}get elementRef(){return this._elementRef}get boundingBox(){return{x:this.translateX,y:this.translateY,z:this.scale,width:this.totalWidth/this.scale,height:this.totalHeight/this.scale,depth:0}}get rotatedBoundingBox(){return{x:this.minXRotated,y:this.minYRotated,z:this.scale,width:this.maxXRotated-this.minXRotated,height:this.maxYRotated-this.minYRotated,depth:0}}get rotatedPolygon(){const t=this.translateX+this.totalWidth/2/this.scale;const i=this.translateY+this.totalHeight/2/this.scale;const e=this.rotation;const s=this.totalWidth/this.scale;const n=this.totalHeight/this.scale;const r={topLeft:{x:this.translateX,y:this.translateY},topRight:{x:this.translateX+s,y:this.translateY},bottomRight:{x:this.translateX+s,y:this.translateY+n},bottomLeft:{x:this.translateX,y:this.translateY+n}};const o=Object.keys(r).reduce(((s,n)=>{const o=r[n];const h=Math.cos(e)*(o.x-t)-Math.sin(e)*(o.y-i)+t;const a=Math.sin(e)*(o.x-t)+Math.cos(e)*(o.y-i)+i;s[n]={x:h,y:a};return s}),{});return o}get minXRotated(){const t=[this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x];return Math.min(...t)}get minYRotated(){const t=[this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y];return Math.min(...t)}get maxXRotated(){const t=[this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x];return Math.max(...t)}get maxYRotated(){const t=[this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y];return Math.max(...t)}get transformationMatrix(){const t=1/this.scale;const i=this.translateX;const e=this.translateY;return`matrix(${t}, 0, 0, ${t}, ${i}, ${e})`}get rotationDegrees(){return this.rotation*(180/Math.PI)}get centerX(){return this.translateX+this.totalWidth/2}get centerY(){return this.translateY+this.totalHeight/2}constructor(t){this.__class__="KritzelBaseObject";this.visible=true;this.borderWidth=0;this.opacity=1;this.padding=0;this.selected=false;this.resizing=false;this.rotation=0;this.markedForRemoval=false;this.isMounted=false;this.zIndex=0;this.debugInfoVisible=false;this._store=t;this.id=this.generateId()}mount(t){if(this.isMounted){return}this.elementRef=t;this.isMounted=true}generateId(){return cn.generateUUID()}isInViewport(){const t={x:-this._store.state.translateX/this._store.state.scale,y:-this._store.state.translateY/this._store.state.scale,width:this._store.state.viewportWidth/this._store.state.scale,height:this._store.state.viewportHeight/this._store.state.scale};return this.boundingBox.x<t.x+t.width&&this.boundingBox.x+this.boundingBox.width>t.x&&this.boundingBox.y<t.y+t.height&&this.boundingBox.y+this.boundingBox.height>t.y}centerInViewport(){const t=this._store.state.scale;this.translateX=(this._store.state.viewportWidth/2-this.totalWidth/2-this._store.state.translateX)/t;this.translateY=(this._store.state.viewportHeight/2-this.totalHeight/2-this._store.state.translateY)/t}move(t,i,e,s){const n=(t-e)/this._store.state.scale;const r=(i-s)/this._store.state.scale;this.translateX+=n;this.translateY+=r}resize(t,i,e,s){if(e<=1||s<=1){return}this.width=e;this.height=s;this.translateX=t;this.translateY=i}rotate(t){this.rotation=t}copy(){const t=Object.create(Object.getPrototypeOf(this));Object.assign(t,this);t.id=this.generateId();t.isMounted=false;return t}revive(t){Object.assign(this,t);return this}}class un extends fn{get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t,i){var e,s,n,r,o,h;super(t);this.__class__="KritzelPath";this.stroke="none";this.lineSlack=.5;this.x=0;this.y=0;this.height=0;this.width=0;this.scale=1;this.visible=true;this.debugInfoVisible=true;this.options=i;this.points=(e=i===null||i===void 0?void 0:i.points)!==null&&e!==void 0?e:[];this.translateX=(s=i===null||i===void 0?void 0:i.translateX)!==null&&s!==void 0?s:0;this.translateY=(n=i===null||i===void 0?void 0:i.translateY)!==null&&n!==void 0?n:0;this.scale=(r=i===null||i===void 0?void 0:i.scale)!==null&&r!==void 0?r:1;this.strokeWidth=(o=i===null||i===void 0?void 0:i.strokeWidth)!==null&&o!==void 0?o:8;this.fill=(h=i===null||i===void 0?void 0:i.fill)!==null&&h!==void 0?h:"#000000";this.zIndex=9999;this.d=this.generateSvgPath();this.updateDimensions()}resize(t,i,e,s){if(e<=1||s<=1){return}const n=e/this.width;const r=s/this.height;this.width=e;this.height=s;this.points=this.points.map((([t,i])=>[t*n,i*r]));this.d=this.generateSvgPath();this.width=Math.max(...this.points.map((t=>t[0])))-Math.min(...this.points.map((t=>t[0])))+this.strokeWidth;this.height=Math.max(...this.points.map((t=>t[1])))-Math.min(...this.points.map((t=>t[1])))+this.strokeWidth;this.x=Math.min(...this.points.map((t=>t[0])))-this.strokeWidth/2;this.y=Math.min(...this.points.map((t=>t[1])))-this.strokeWidth/2;this.translateX=t;this.translateY=i}rotate(t){super.rotate(t);this.updateDimensions()}updateDimensions(){const t=this.points.map((([t,i])=>{const e=t*Math.cos(this.rotation)-i*Math.sin(this.rotation);const s=t*Math.sin(this.rotation)+i*Math.cos(this.rotation);return[e,s]}));const i=Math.min(...t.map((t=>t[0]-this.strokeWidth/2)));const e=Math.min(...t.map((t=>t[1]-this.strokeWidth/2)));const s=Math.max(...t.map((t=>t[0]+this.strokeWidth/2)));const n=Math.max(...t.map((t=>t[1]+this.strokeWidth/2)));this.width=s-i+this.lineSlack;this.height=n-e+this.lineSlack;this.x=i;this.y=e;this.translateX=(this.x+this.translateX)/this.scale;this.translateY=(this.y+this.translateY)/this.scale}generateSvgPath(){const t=this.getStrokeFromPoints(this.points,this.strokeWidth);return this.getSvgPathFromStroke(t)}getStrokeFromPoints(t,i){return z.getStroke(t,{size:i,thinning:.5,smoothing:.5,streamline:.5,easing:t=>t,simulatePressure:true,last:true,start:{cap:true,taper:0,easing:t=>t},end:{cap:true,taper:0,easing:t=>t}})}getSvgPathFromStroke(t,i=true){const e=t.length;if(e<4){return``}let s=t[0];let n=t[1];const r=t[2];let o=`M${s[0].toFixed(2)},${s[1].toFixed(2)} Q${n[0].toFixed(2)},${n[1].toFixed(2)} ${M.average(n[0],r[0]).toFixed(2)},${M.average(n[1],r[1]).toFixed(2)} T`;for(let i=2,r=e-1;i<r;i++){s=t[i];n=t[i+1];o+=`${M.average(s[0],n[0]).toFixed(2)},${M.average(s[1],n[1]).toFixed(2)} `}if(i){o+="Z"}return o}}class dn{constructor(t){this.__class__=this.constructor.name;this.name="base-tool";this._store=t}onActivate(){}onDeactivate(){}handleMouseDown(t){}handleMouseMove(t){}handleMouseUp(t){}handleDoubleClick(t){}handleDoubleTap(t){}handleTouchStart(t){}handleTouchMove(t){}handleTouchEnd(t){}handleWheel(t){}revive(t){Object.assign(this,t);return this}}class vn extends dn{constructor(t){super(t);this.type="pen";this.color="#000000";this.size=6;this.palettes={pen:["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#808080","#C0C0C0","#800000","#008000","#000080","#808000","#800080"],highlighter:["#ffff00","#ffb347","#b4ffb4"]}}handleMouseDown(t){if(w.isLeftClick(t)){this._store.state.isDrawing=true;const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.currentPath=new un(this._store,{points:[[i,e]],translateX:-this._store.state.translateX,translateY:-this._store.state.translateY,scale:this._store.state.scale,fill:this.color,strokeWidth:this.size})}}handleMouseMove(t){if(this._store.state.isDrawing){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.currentPath=new un(this._store,{points:[...this._store.state.currentPath.points,[i,e]],translateX:-this._store.state.translateX,translateY:-this._store.state.translateY,scale:this._store.state.scale,fill:this.color,strokeWidth:this.size});this._store.rerender()}}handleMouseUp(t){if(this._store.state.isDrawing){this._store.state.isDrawing=false;if(this._store.state.currentPath){this._store.state.currentPath.zIndex=this._store.currentZIndex;this._store.history.executeCommand(new k(this._store,this,this._store.state.currentPath))}this._store.state.currentPath=undefined}}handleTouchStart(t){if(this._store.state.touchCount===1){const i=Math.round(t.touches[0].clientX-this._store.offsetX);const e=Math.round(t.touches[0].clientY-this._store.offsetY);this._store.state.isDrawing=true;this._store.state.currentPath=new un(this._store,{points:[[i,e]],translateX:-this._store.state.translateX,translateY:-this._store.state.translateY,scale:this._store.state.scale,fill:this.color,strokeWidth:this.size});this._store.rerender()}}handleTouchMove(t){if(this._store.state.touchCount===1){const i=Math.round(t.touches[0].clientX-this._store.offsetX);const e=Math.round(t.touches[0].clientY-this._store.offsetY);this._store.state.currentPath=new un(this._store,{points:[...this._store.state.currentPath.points,[i,e]],translateX:-this._store.state.translateX,translateY:-this._store.state.translateY,scale:this._store.state.scale,fill:this.color,strokeWidth:this.size});this._store.rerender()}}handleTouchEnd(t){if(this._store.state.isDrawing){this._store.state.isDrawing=false;if(this._store.state.currentPath){this._store.state.currentPath.zIndex=this._store.currentZIndex;this._store.history.executeCommand(new k(this._store,this,this._store.state.currentPath))}this._store.state.currentPath=undefined;this._store.rerender()}}}class bn extends fn{get isReadonly(){return!(this._store.state.activeTool instanceof gn)}constructor(t,i,e){super(t);this.__class__="KritzelText";this.value="";this.fontFamily="Arial";this.fontSize=8;this.fontColor="#000000";this.initialWidth=3;this.isNew=true;this.debugInfoVisible=true;this.rows=1;this.fontSize=i;this.fontFamily=e;this.translateX=0;this.translateY=0;this.width=this.initialWidth/(this._store.state.scale<0?this._store.state.scale:1);this.height=this.fontSize*1.2/(this._store.state.scale<0?this._store.state.scale:1);this.padding=5;this.backgroundColor="transparent";this.scale=this._store.state.scale;this.value=" "}mount(t){if(this.isMounted&&this.elementRef===t||this.isInViewport()===false){return}this.elementRef=t;this.isMounted=true}resize(t,i,e,s){if(e<=1||s<=1){return}const n=s/this.height;this.fontSize=this.fontSize*n;this.width=this.width*n;this.height=s;this.translateX=t;this.translateY=i}handleKeyDown(t){if(this.isReadonly){t.preventDefault();t.stopPropagation()}}handleInput(t){const i=t.target;if(i.value===""){this.value=" ";i.value=" ";i.selectionStart=i.selectionEnd=i.value.length}else{this.value=i.value.trim()}this.adjustTextareaSize()}adjustTextareaSize(){if(this.elementRef){const t=document.createElement("span");t.style.position="absolute";t.style.whiteSpace="pre-wrap";t.style.visibility="hidden";t.style.fontSize=window.getComputedStyle(this.elementRef).fontSize;t.style.fontFamily=window.getComputedStyle(this.elementRef).fontFamily;t.innerHTML=this.elementRef.value.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br>")+"<br>";document.body.appendChild(t);const i=t.offsetWidth;const e=t.offsetHeight;document.body.removeChild(t);this.width=i;this.height=e;this._store.rerender()}}focus(){if(this.elementRef){this.elementRef.focus()}}selectAll(){if(this.elementRef){this.elementRef.select()}}insertFromClipboard(){if(this.elementRef){this.elementRef.focus();try{navigator.clipboard.readText().then((t=>{const i=this.elementRef.selectionStart;const e=this.elementRef.selectionEnd;const s=this.elementRef.value;this.elementRef.value=s.substring(0,i)+t+s.substring(e);this.elementRef.selectionStart=this.elementRef.selectionEnd=i+t.length;this.value=this.elementRef.value;this.adjustTextareaSize()}))}catch(t){console.error("Failed to read clipboard contents:",t)}}}}class pn{static registerTool(t,i,e){const s=new i(e);s.name=t;this.registry[t]=s;return s}static getTool(t){const i=this.registry[t];if(!i){console.warn(`Unknown tool: ${t}`);return null}return i}}pn.registry={};class gn extends dn{constructor(t){super(t);this.fontFamily="Arial";this.fontSize=16;this.fontColor="#000000";this.palette=["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#808080","#C0C0C0","#800000","#008000","#000080","#808000","#800080"]}handleMouseDown(t){const i=t.composedPath().slice(1);const e=i.find((t=>t.classList&&t.classList.contains("object")));const s=this._store.findObjectById(e===null||e===void 0?void 0:e.id);if(this._store.state.activeText===null&&s&&s instanceof bn){this._store.state.activeText=s;s.focus();return}if(this._store.state.activeText!==null&&s instanceof bn){s.focus();return}if(this._store.state.activeText!==null){this._store.resetActiveText();this._store.setState("activeTool",pn.getTool("selection"));return}if(w.isLeftClick(t)===false){return}const n=t.clientX-this._store.offsetX;const r=t.clientY-this._store.offsetY;const o=new bn(this._store,this.fontSize,this.fontFamily);o.fontColor=this.fontColor;o.translateX=(n-this._store.state.translateX)/this._store.state.scale;o.translateY=(r-this._store.state.translateY)/this._store.state.scale;o.zIndex=this._store.currentZIndex;o.adjustTextareaSize();this._store.state.activeText=o;this._store.history.executeCommand(new k(this._store,this,o))}handleMouseUp(t){var i,e;(i=this._store.state.activeText)===null||i===void 0?void 0:i.focus();(e=this._store.state.activeText)===null||e===void 0?void 0:e.adjustTextareaSize()}handleTouchStart(t){const i=t.composedPath().slice(1);const e=i.find((t=>t.classList&&t.classList.contains("object")));const s=this._store.findObjectById(e===null||e===void 0?void 0:e.id);if(this._store.state.activeText===null&&s&&s instanceof bn){this._store.state.activeText=s;s.focus();return}if(this._store.state.activeText!==null&&s instanceof bn){s.focus();return}if(this._store.state.activeText!==null){this._store.resetActiveText();this._store.setState("activeTool",pn.getTool("selection"));return}if(this._store.state.touchCount>1){return}const n=Math.round(t.touches[0].clientX-this._store.offsetX);const r=Math.round(t.touches[0].clientY-this._store.offsetY);const o=new bn(this._store,this.fontSize,this.fontFamily);o.fontColor=this.fontColor;o.translateX=(n-this._store.state.translateX)/this._store.state.scale;o.translateY=(r-this._store.state.translateY)/this._store.state.scale;o.zIndex=this._store.currentZIndex;this._store.state.activeText=o;this._store.history.executeCommand(new k(this._store,this,o))}handleTouchEnd(t){var i,e;(i=this._store.state.activeText)===null||i===void 0?void 0:i.focus();(e=this._store.state.activeText)===null||e===void 0?void 0:e.adjustTextareaSize()}}const wn=":host{display:flex;flex-direction:column;user-select:none}.kritzel-controls{display:flex;flex-direction:row;align-items:center;justify-content:flex-start;gap:var(--kritzel-controls-gap, 8px);height:100%;padding:var(--kritzel-controls-padding, 8px);background-color:var(--kritzel-controls-background-color, #ffffff);border-radius:var(--kritzel-controls-border-radius, 8px);box-shadow:var(--kritzel-controls-box-shadow, 0 0 3px rgba(0, 0, 0, 0.08));border:var(--kritzel-controls-border, 1px solid hsl(0, 0%, 0%, 4.3%));border-radius:var(--kritzel-controls-border-radius, 8px);z-index:10000;position:relative}.kritzel-control{display:flex;justify-content:center;align-items:center;color:var(--kritzel-controls-control-color, #000000);border-radius:var(--kritzel-controls-control-border-radius, 8px);padding:var(--kritzel-controls-control-padding, 8px);border:none;outline:none;background:none;cursor:pointer;-webkit-tap-highlight-color:transparent;font-weight:bold}.kritzel-control:hover{background-color:var(--kritzel-controls-control-hover-background-color, hsl(0, 0%, 0%, 4.3%))}.kritzel-control:active{background-color:var(--kritzel-controls-control-active-background-color, hsl(0, 0%, 0%, 8.6%))}.kritzel-control.selected,.kritzel-control.selected:hover,.kritzel-control.selected:active{background-color:var(--kritzel-controls-control-selected-background-color, #0E1111);color:var(--kritzel-controls-control-selected-color, #ffffff)}.kritzel-divider{width:var(--kritzel-controls-divider-width, 1px);height:var(--kritzel-controls-divider-height, 24px);background-color:var(--kritzel-controls-divider-background-color, hsl(0, 0%, 0%, 4.3%))}.kritzel-config-container{position:relative;display:flex;justify-content:center;align-items:center;width:40px;height:40px;box-sizing:border-box;-webkit-tap-highlight-color:transparent}.kritzel-config{display:flex;justify-content:center;align-items:center;cursor:pointer}.color-container{display:flex;justify-content:center;align-items:center;width:32px;height:32px;border-radius:50%;cursor:pointer;border:2px solid transparent;box-sizing:border-box;background-color:var(--kritzel-color-palette-hover-background-color, #f0f0f0)}.font-container{display:flex;justify-content:center;align-items:center;width:32px;height:32px;border-radius:50%;cursor:pointer;border:2px solid transparent;box-sizing:border-box;background-color:var(--kritzel-color-palette-hover-background-color, #f0f0f0)}.no-config{height:24px;width:24px;border-radius:50%;border:1px dashed gray}kritzel-tooltip{position:fixed;bottom:66px;left:50%;transform:translateX(-50%);z-index:10001}";const yn=class{constructor(e){t(this,e);this.controlsReady=i(this,"controlsReady");this.controls=[];this.activeControl=null;this.firstConfig=null;this.tooltipVisible=false;this.kritzelEngine=null}get activeToolAsTextTool(){var t;return(t=this.activeControl)===null||t===void 0?void 0:t.tool}get activeToolAsBrushTool(){var t;return(t=this.activeControl)===null||t===void 0?void 0:t.tool}async componentWillLoad(){await this.initializeEngine();await this.initializeTools()}componentDidLoad(){this.controlsReady.emit()}async initializeEngine(){await customElements.whenDefined("kritzel-engine");this.kritzelEngine=this.host.parentElement.querySelector("kritzel-engine");if(!this.kritzelEngine){throw new Error("kritzel-engine not found in parent element.")}}async initializeTools(){for(const t of this.controls){if(t.type==="tool"&&t.tool){t.tool=await this.kritzelEngine.registerTool(t.name,t.tool,t.config)}if(t.type==="tool"&&t.isDefault&&t.tool){await this.kritzelEngine.changeActiveTool(t.tool);this.activeControl=t}if(t.type==="config"){if(this.firstConfig===null){this.firstConfig=t}else{console.warn("Only one config control is allowed. The first one will be used.")}}}}async handleActiveToolChange(t){var i;this.activeControl=this.controls.find((i=>i.tool===t.detail))||null;await((i=this.kritzelEngine)===null||i===void 0?void 0:i.setFocus())}handleClick(t){const i=t.target;if(!this.kritzelEngine||i.closest(".kritzel-tooltip")){return}this.tooltipVisible=false;this.kritzelEngine.enable()}preventDefault(t){if(t.cancelable){t.preventDefault();t.stopPropagation()}}async handleControlClick(t){this.activeControl=t;if(this.activeControl.type==="tool"){await this.kritzelEngine.changeActiveTool(this.activeControl.tool)}}handleConfigClick(t){t.stopPropagation();this.tooltipVisible=!this.tooltipVisible;this.kritzelEngine.disable()}async handleToolChange(t){this.activeControl=Object.assign(Object.assign({},this.activeControl),{tool:t.detail});await this.kritzelEngine.changeActiveTool(this.activeControl.tool)}render(){var t,i;const n=((t=this.activeControl)===null||t===void 0?void 0:t.config)===undefined||((i=this.activeControl)===null||i===void 0?void 0:i.config)===null;return e(s,{key:"2b13783ef0f1638ad76bfcef22c17c3eeb849d67"},e("kritzel-utility-panel",{key:"1babeb88133cebc9057c85723b812b99152316c6",style:{position:"absolute",bottom:"56px",left:"12px"},onUndo:()=>{var t;return(t=this.kritzelEngine)===null||t===void 0?void 0:t.undo()},onRedo:()=>{var t;return(t=this.kritzelEngine)===null||t===void 0?void 0:t.redo()},onDelete:()=>{var t;return(t=this.kritzelEngine)===null||t===void 0?void 0:t.delete()}}),e("div",{key:"8fafebdf6726dd2bffe85cb2b3ada5f4885a2bf8",class:"kritzel-controls"},this.controls.map((t=>{var i,s,r,o,h,a,l,c;if(t.type==="tool"){return e("button",{class:{"kritzel-control":true,selected:((i=this.activeControl)===null||i===void 0?void 0:i.name)===(t===null||t===void 0?void 0:t.name)},key:t.name,onClick:i=>{var e;return(e=this.handleControlClick)===null||e===void 0?void 0:e.call(this,t)}},e("kritzel-icon",{name:t.icon}))}if(t.type==="divider"){return e("div",{class:"kritzel-divider",key:t.name})}if(t.type==="config"&&t.name===((s=this.firstConfig)===null||s===void 0?void 0:s.name)&&this.activeControl){return e("div",{class:"kritzel-config-container",key:t.name},e("kritzel-tooltip",{isVisible:this.tooltipVisible,anchorElement:(r=this.host.shadowRoot)===null||r===void 0?void 0:r.querySelector(".kritzel-config-container")},e("div",{style:{width:"294px",height:"100%"}},this.activeControl.name==="brush"&&e("kritzel-control-brush-config",{tool:this.activeToolAsBrushTool,onToolChange:t=>{var i;return(i=this.handleToolChange)===null||i===void 0?void 0:i.call(this,t)}}),this.activeControl.name==="text"&&e("kritzel-control-text-config",{tool:this.activeToolAsTextTool,onToolChange:t=>{var i;return(i=this.handleToolChange)===null||i===void 0?void 0:i.call(this,t)}}))),e("div",{class:"kritzel-config",onClick:t=>{var i;return(i=this.handleConfigClick)===null||i===void 0?void 0:i.call(this,t)},style:{cursor:this.activeControl.config?"pointer":"default",pointerEvents:n?"none":"auto"}},this.activeControl.tool instanceof vn&&e("div",{class:"color-container"},e("kritzel-color",{value:(o=this.activeToolAsBrushTool)===null||o===void 0?void 0:o.color,size:(h=this.activeToolAsBrushTool)===null||h===void 0?void 0:h.size,style:{borderRadius:"50%",border:"none"}})),this.activeControl.tool instanceof gn&&e("div",{class:"font-container"},e("kritzel-font",{fontFamily:(a=this.activeToolAsTextTool)===null||a===void 0?void 0:a.fontFamily,size:(l=this.activeToolAsTextTool)===null||l===void 0?void 0:l.fontSize,color:(c=this.activeToolAsTextTool)===null||c===void 0?void 0:c.fontColor})),n&&e("div",{class:"no-config"})))}}))))}static get assetsDirs(){return["../assets"]}get host(){return n(this)}};yn.style=wn;const kn=":host{display:block;position:fixed;top:0;left:0;width:100vw;height:100vh;pointer-events:none;z-index:9000}";const xn=class{constructor(i){t(this,i);this.cursorTrailPoints=[];this.isLeftButtonDown=false;this.TRAIL_DURATION_MS=100;this.MAX_TRAIL_POINTS=50}componentDidLoad(){this.trailCleanupIntervalId=window.setInterval((()=>{const t=Date.now();const i=this.cursorTrailPoints.filter((i=>t-i.timestamp<this.TRAIL_DURATION_MS));if(i.length!==this.cursorTrailPoints.length){this.cursorTrailPoints=i}}),50)}disconnectedCallback(){if(this.trailCleanupIntervalId){window.clearInterval(this.trailCleanupIntervalId)}}handleMouseDown(t){if(t.button===0){this.isLeftButtonDown=true;this.cursorTrailPoints=[]}}handleMouseMove(t){if(!this.isLeftButtonDown){return}const i={x:t.clientX,y:t.clientY,timestamp:Date.now()};const e=[i,...this.cursorTrailPoints];if(e.length>this.MAX_TRAIL_POINTS){this.cursorTrailPoints=e.slice(0,this.MAX_TRAIL_POINTS)}else{this.cursorTrailPoints=e}}handleMouseUp(t){if(t.button===0){this.isLeftButtonDown=false;this.cursorTrailPoints=[]}}handleTouchStart(t){if(t.touches.length===1){this.isLeftButtonDown=true;this.cursorTrailPoints=[]}}handleTouchMove(t){if(!this.isLeftButtonDown){return}const i=t.touches[0];const e={x:i.clientX,y:i.clientY,timestamp:Date.now()};const s=[e,...this.cursorTrailPoints];if(s.length>this.MAX_TRAIL_POINTS){this.cursorTrailPoints=s.slice(0,this.MAX_TRAIL_POINTS)}else{this.cursorTrailPoints=s}}handleTouchEnd(t){if(t.touches.length===0){this.isLeftButtonDown=false;this.cursorTrailPoints=[]}}render(){return e(s,{key:"604f5c39a01f3aea870861de0a93cd162302d7b2"},this.cursorTrailPoints.length>1&&e("svg",{key:"6f69f0b5a871010581b73bff51b2ef7341389f5a",class:"cursor-trail-svg",xmlns:"http://www.w3.org/2000/svg",style:{position:"absolute",left:"0",top:"0",width:"100%",height:"100%",pointerEvents:"none",opacity:"var(--kritzel-cursor-trail-opacity, 0.6)",zIndex:"9000"}},this.cursorTrailPoints.slice(1).map(((t,i)=>{const s=this.cursorTrailPoints[i];const n=Date.now();const r=n-t.timestamp;const o=Math.max(0,Math.min(1,r/this.TRAIL_DURATION_MS));if(o>=1)return null;const h=Math.max(2,15*(1-o));return e("line",{key:`trail-segment-${t.timestamp}`,x1:s.x.toString(),y1:s.y.toString(),x2:t.x.toString(),y2:t.y.toString(),stroke:"var(--kritzel-cursor-trail-color, rgb(228, 228, 228))","stroke-width":h.toString(),"stroke-linecap":"round"})}))))}};xn.style=kn;const mn=':host{display:inline-flex;vertical-align:middle;width:100%;}.dropdown-wrapper{display:flex;align-items:center;border:1px solid #333333;border-radius:var(--kritzel-controls-control-border-radius, 8px);overflow:hidden;height:32px;width:100%}.custom-select{padding:0 8px;padding-right:30px;height:100%;width:100%;box-sizing:border-box;border-radius:0;border:none;background-color:#fff;cursor:pointer;outline:none;font-size:inherit;color:var(--kritzel-controls-text-color, #333333);-webkit-tap-highlight-color:transparent;-webkit-appearance:none;-moz-appearance:none;appearance:none;background-image:url(\'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23333333" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>\');background-size:16px 16px;background-repeat:no-repeat;background-position:right 8px center}.custom-select.has-suffix-border{border-right:1px solid #333333}.custom-select.has-prefix-border{border-left:1px solid #333333}::slotted(*){height:100%;box-sizing:border-box}';const An=class{constructor(e){t(this,e);this.valueChanged=i(this,"valueChanged");this.options=[];this.selectStyles={};this.hasSuffixContent=false;this.hasPrefixContent=false;this.handleSelectChange=t=>{const i=t.target.value;if(this.internalValue!==i){this.internalValue=i;this.valueChanged.emit(this.internalValue)}};this.evaluateSuffixContent=()=>{if(this.suffixSlotElement){const t=this.suffixSlotElement.assignedNodes({flatten:true}).length>0;if(this.hasSuffixContent!==t){this.hasSuffixContent=t}}else{if(this.hasSuffixContent!==false){this.hasSuffixContent=false}}};this.evaluatePrefixContent=()=>{if(this.prefixSlotElement){const t=this.prefixSlotElement.assignedNodes({flatten:true}).length>0;if(this.hasPrefixContent!==t){this.hasPrefixContent=t}}else{if(this.hasPrefixContent!==false){this.hasPrefixContent=false}}}}componentWillLoad(){this.updateInternalValue(this.value,false);this.evaluateSuffixContent();this.evaluatePrefixContent()}externalValueChanged(t){if(t!==this.internalValue){this.updateInternalValue(t,false)}}optionsChanged(){this.updateInternalValue(this.internalValue,true)}updateInternalValue(t,i){let e=t;if(this.options&&this.options.length>0){const t=this.options.some((t=>t.value===e));if(!e||!t){e=this.options[0].value}}else{e=undefined}if(this.internalValue!==e){this.internalValue=e;if(i||t!==e&&t!==undefined){this.valueChanged.emit(this.internalValue)}}}render(){const t={"custom-select":true,"has-suffix-border":this.hasSuffixContent,"has-prefix-border":this.hasPrefixContent};return e(s,{key:"1e4df5425e205d3709d93d71f2e7a47844a5b0f2"},e("div",{key:"6e0d6fa7b35d1d9d61cf2174828d0d0f0d242683",class:"dropdown-wrapper"},e("slot",{key:"07565dc0982498a9b026bc36f285eb728b5c771b",name:"prefix",ref:t=>this.prefixSlotElement=t,onSlotchange:this.evaluatePrefixContent}),e("select",{key:"ba618a1166681f36aae554242192e375286ba7e8",class:t,style:Object.assign(Object.assign({},this.selectStyles),{width:this.width}),onInput:this.handleSelectChange},this.options.map((t=>e("option",{value:t.value,style:t.style,selected:t.value===this.internalValue},t.label)))),e("slot",{key:"2731003fa214cb3aa968b48db36ab1816d563425",name:"suffix",ref:t=>this.suffixSlotElement=t,onSlotchange:this.evaluateSuffixContent})))}static get watchers(){return{value:["externalValueChanged"],options:["optionsChanged"]}}};An.style=mn;class zn{static register(t,i){if(this.registry.has(t)){console.warn(`[IconRegistry] Icon "${t}" is already registered. It will be overwritten.`)}this.registry.set(t,i)}static get(t){return this.registry.get(t)}static registerIcons(t){for(const i in t){if(Object.prototype.hasOwnProperty.call(t,i)){this.register(i,t[i])}}}static has(t){return this.registry.has(t)}}zn.registry=new Map;zn.registerIcons({cursor:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z"/></svg>',pen:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/></svg>',highlighter:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-highlighter-icon lucide-highlighter"><path d="m9 11-6 6v3h9l3-3"/><path d="m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"/></svg>',eraser:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21"/><path d="M22 21H7"/><path d="m5 11 9 9"/></svg>',type:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 7 4 4 20 4 20 7"/><line x1="9" x2="15" y1="20" y2="20"/><line x1="12" x2="12" y1="4" y2="20"/></svg>',image:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>',"chevron-down":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>',"chevron-up":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m18 15-6-6-6 6"/></svg>',copy:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy-icon lucide-copy"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>',paste:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-clipboard-paste-icon lucide-clipboard-paste"><path d="M11 14h10"/><path d="M16 4h2a2 2 0 0 1 2 2v1.344"/><path d="m17 18 4-4-4-4"/><path d="M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113"/><rect x="8" y="2" width="8" height="4" rx="1"/></svg>',cut:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-scissors-icon lucide-scissors"><circle cx="6" cy="6" r="3"/><path d="M8.12 8.12 12 12"/><path d="M20 4 8.12 15.88"/><circle cx="6" cy="18" r="3"/><path d="M14.8 14.8 20 20"/></svg>',delete:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trash2-icon lucide-trash-2"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg>',"bring-to-front":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-up-to-line-icon lucide-arrow-up-to-line"><path d="M5 3h14"/><path d="m18 13-6-6-6 6"/><path d="M12 7v14"/></svg>',"send-to-back":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-down-to-line-icon lucide-arrow-down-to-line"><path d="M12 17V3"/><path d="m6 11 6 6 6-6"/><path d="M19 21H5"/></svg>',"select-all":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-square-mouse-pointer-icon lucide-square-mouse-pointer"><path d="M12.034 12.681a.498.498 0 0 1 .647-.647l9 3.5a.5.5 0 0 1-.033.943l-3.444 1.068a1 1 0 0 0-.66.66l-1.067 3.443a.5.5 0 0 1-.943.033z"/><path d="M21 11V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h6"/></svg>',download:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-download-icon lucide-download"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" x2="12" y1="15" y2="3"/></svg>',undo:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-undo-icon lucide-undo"><path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/></svg>',redo:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-redo-icon lucide-redo"><path d="M21 7v6h-6"/><path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7"/></svg>'});class Mn extends y{constructor(t,i,e){super(t,i);this.commands=e}execute(){this.commands.forEach((t=>t.execute()))}undo(){this.commands.forEach((t=>t.undo()))}}class jn extends y{constructor(t,i,e){super(t,i);this.object=e}execute(){this._store.state.objectsOctree.remove((t=>t.id===this.object.id))}undo(){this._store.state.objectsOctree.insert(this.object)}}class Tn extends dn{constructor(t){super(t);this.touchStartTimeout=null}handleMouseDown(t){if(w.isLeftClick(t)){this._store.state.isErasing=true}}handleMouseMove(t){var i;if(this._store.state.isErasing){const e=(i=this._store.state.host)===null||i===void 0?void 0:i.shadowRoot;if(!e)return;const s=this._store.getObjectFromPointerEvent(t,".object");if(!s)return;s.markedForRemoval=true;this._store.rerender()}}handleMouseUp(t){if(this._store.state.isErasing){const t=this._store.allObjects.filter((t=>t.markedForRemoval)).map((t=>{t.markedForRemoval=false;return new jn(this._store,this,t)}));if(t.length>0){this._store.history.executeCommand(new Mn(this._store,this,t))}this._store.state.isErasing=false}}handleTouchStart(t){this.touchStartTimeout=setTimeout((()=>{if(this._store.state.touchCount===1&&!this._store.state.isScaling){this._store.state.isErasing=true}}),80)}handleTouchMove(t){var i;if(this._store.state.touchCount===1&&this._store.state.isErasing){const e=(i=this._store.state.host)===null||i===void 0?void 0:i.shadowRoot;if(!e)return;const s=this._store.getObjectFromPointerEvent(t,".object");if(!s)return;s.markedForRemoval=true;this._store.rerender()}}handleTouchEnd(t){clearTimeout(this.touchStartTimeout);if(this._store.state.isErasing){const t=this._store.allObjects.filter((t=>t.markedForRemoval)).map((t=>{t.markedForRemoval=false;return new jn(this._store,this,t)}));if(t.length>0){this._store.history.executeCommand(new Mn(this._store,this,t))}this._store.state.isErasing=false}}}class Cn extends fn{constructor(t,i){super(t);this.__class__="KritzelImage";this.debugInfoVisible=true;this.img=i;this.x=0;this.y=0;this.translateX=0;this.translateY=0;this.width=i.width;this.height=i.height;this.scale=this._store.state.scale}resize(t,i,e,s){if(e<=1||s<=1){return}const n=s/this.height;this.width=this.width*n;this.height=this.height*n;this.translateX=t;this.translateY=i}}class Sn extends y{constructor(t,i){super(t,i);this.previousSelectionGroup=this._store.state.selectionGroup}execute(){this._store.state.objectsOctree.remove((t=>t.id===this.previousSelectionGroup.id));this._store.state.selectionGroup=null}undo(){if(this.previousSelectionGroup){this._store.state.objectsOctree.insert(this.previousSelectionGroup);this._store.state.selectionGroup=this.previousSelectionGroup}}}class En extends y{constructor(t,i,e,s,n,r,o=false){super(t,i);this.startX=e;this.startY=s;this.endX=n;this.endY=r;this.skipExecution=o;this.selectionGroup=this._store.state.selectionGroup}execute(){if(this.skipExecution){this.skipExecution=false;return}this._store.state.selectionGroup=this.selectionGroup;this._store.state.selectionGroup.move(this.startX,this.startY,this.endX,this.endY)}undo(){this._store.state.selectionGroup=this.selectionGroup;this._store.state.selectionGroup.move(this.endX,this.endY,this.startX,this.startY)}}class Fn{constructor(t){this._store=t}}class In extends Fn{constructor(t){super(t)}handleMouseDown(t){var i;if(w.isLeftClick(t)){if(((i=this._store.state.selectionGroup)===null||i===void 0?void 0:i.selected)&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.isDragging=true;this.dragStartX=i;this.dragStartY=e;this.startX=this.dragStartX;this.startY=this.dragStartY}}}handleMouseMove(t){if(this._store.state.isDragging&&this._store.state.selectionGroup){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this.endX=i;this.endY=e;this._store.state.selectionGroup.move(i,e,this.dragStartX,this.dragStartY);this.dragStartX=i;this.dragStartY=e}}handleMouseUp(t){if(this._store.state.isDragging){this._store.state.isDragging=false;this._store.history.executeCommand(new En(this._store,this,this.endX,this.endY,this.startX,this.startY,true))}}handleTouchStart(t){var i;if(this._store.state.touchCount===1){if(((i=this._store.state.selectionGroup)===null||i===void 0?void 0:i.selected)&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){const i=Math.round(t.touches[0].clientX-this._store.offsetX);const e=Math.round(t.touches[0].clientY-this._store.offsetY);this.dragStartX=i;this.dragStartY=e;this.startX=i;this.startY=e}}}handleTouchMove(t){if(this._store.state.touchCount===1&&this._store.state.selectionGroup&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){const i=Math.round(t.touches[0].clientX-this._store.offsetX);const e=Math.round(t.touches[0].clientY-this._store.offsetY);this._store.state.isDragging=true;this.endX=i;this.endY=e;const s=Math.abs(i-this.startX);const n=Math.abs(e-this.startY);const r=5;if(s>r||n>r){clearTimeout(this._store.state.longTouchTimeout);this._store.state.selectionGroup.move(i,e,this.dragStartX,this.dragStartY);this.dragStartX=i;this.dragStartY=e}}}handleTouchEnd(t){if(this._store.state.isDragging){this._store.state.isDragging=false;this._store.history.executeCommand(new En(this._store,this,this.endX,this.endY,this.startX,this.startY,true))}}}var Un;(function(t){t["TopLeft"]="top-left";t["TopRight"]="top-right";t["BottomLeft"]="bottom-left";t["BottomRight"]="bottom-right"})(Un||(Un={}));class Bn extends y{constructor(t,i,e,s){super(t,i);this.previousSize=e;this.newSize=s;this.selectionGroup=this._store.state.selectionGroup}execute(){this._store.state.selectionGroup=this.selectionGroup;this._store.state.selectionGroup.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}undo(){this._store.state.selectionGroup=this.selectionGroup;this._store.state.selectionGroup.resize(this.previousSize.x,this.previousSize.y,this.previousSize.width,this.previousSize.height)}}class On extends Fn{constructor(t){super(t);this.initialMouseX=0;this.initialMouseY=0;this.initialSize={x:0,y:0,width:0,height:0};this.newSize={x:0,y:0,width:0,height:0}}handleMouseDown(t){if(w.isLeftClick(t)){if(this._store.state.selectionGroup&&this._store.state.isResizeHandleSelected){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.isResizing=true;this.initialMouseX=i;this.initialMouseY=e;this.initialSize.width=this._store.state.selectionGroup.width;this.initialSize.height=this._store.state.selectionGroup.height;this.initialSize.x=this._store.state.selectionGroup.translateX;this.initialSize.y=this._store.state.selectionGroup.translateY}}}handleMouseMove(t){if(this._store.state.isResizing&&this._store.state.selectionGroup){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;const s=i-this.initialMouseX;const n=e-this.initialMouseY;switch(this._store.state.resizeHandleType){case Un.TopLeft:this.newSize.width=this.initialSize.width-s;this.newSize.height=this.initialSize.height-n;this.newSize.x=s/this._store.state.scale+this.initialSize.x;this.newSize.y=n/this._store.state.scale+this.initialSize.y;break;case Un.TopRight:this.newSize.width=this.initialSize.width+s;this.newSize.height=this.initialSize.height-n;this.newSize.x=this.initialSize.x;this.newSize.y=n/this._store.state.scale+this.initialSize.y;break;case Un.BottomLeft:this.newSize.width=this.initialSize.width-s;this.newSize.height=this.initialSize.height+n;this.newSize.x=s/this._store.state.scale+this.initialSize.x;this.newSize.y=this.initialSize.y;break;case Un.BottomRight:this.newSize.width=this.initialSize.width+s;this.newSize.height=this.initialSize.height+n;this.newSize.x=this.initialSize.x;this.newSize.y=this.initialSize.y;break}this._store.state.selectionGroup.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height);this._store.rerender()}}handleMouseUp(t){if(this._store.state.isResizing){const t=new Bn(this._store,this,structuredClone(this.initialSize),structuredClone(this.newSize));this._store.history.executeCommand(t);this._store.state.isResizing=false;this._store.rerender()}}handleTouchStart(t){const i=t.touches[0];if(!i){return}if(this._store.state.touchCount===1){if(this._store.state.selectionGroup&&this._store.state.isResizeHandleSelected){const t=Math.round(i.clientX-this._store.offsetX);const e=Math.round(i.clientY-this._store.offsetY);this._store.state.isResizing=true;this.initialMouseX=t;this.initialMouseY=e;this.initialSize.width=this._store.state.selectionGroup.width;this.initialSize.height=this._store.state.selectionGroup.height;this.initialSize.x=this._store.state.selectionGroup.translateX;this.initialSize.y=this._store.state.selectionGroup.translateY;clearTimeout(this._store.state.longTouchTimeout)}}}handleTouchMove(t){const i=t.touches[0];if(!i){return}if(this._store.state.isResizing&&this._store.state.selectionGroup){const t=Math.round(i.clientX-this._store.offsetX);const e=Math.round(i.clientY-this._store.offsetY);const s=t-this.initialMouseX;const n=e-this.initialMouseY;switch(this._store.state.resizeHandleType){case Un.TopLeft:this.newSize.width=this.initialSize.width-s;this.newSize.height=this.initialSize.height-n;this.newSize.x=s/this._store.state.scale+this.initialSize.x;this.newSize.y=n/this._store.state.scale+this.initialSize.y;break;case Un.TopRight:this.newSize.width=this.initialSize.width+s;this.newSize.height=this.initialSize.height-n;this.newSize.x=this.initialSize.x;this.newSize.y=n/this._store.state.scale+this.initialSize.y;break;case Un.BottomLeft:this.newSize.width=this.initialSize.width-s;this.newSize.height=this.initialSize.height+n;this.newSize.x=s/this._store.state.scale+this.initialSize.x;this.newSize.y=this.initialSize.y;break;case Un.BottomRight:this.newSize.width=this.initialSize.width+s;this.newSize.height=this.initialSize.height+n;this.newSize.x=this.initialSize.x;this.newSize.y=this.initialSize.y;break}this._store.state.selectionGroup.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height);clearTimeout(this._store.state.longTouchTimeout)}}handleTouchEnd(t){if(this._store.state.isResizing){const t=new Bn(this._store,this,structuredClone(this.initialSize),structuredClone(this.newSize));this._store.history.executeCommand(t);this._store.state.isResizing=false;clearTimeout(this._store.state.longTouchTimeout)}}}class $n extends y{constructor(t,i,e){super(t,i);this.rotation=e;this.initialRotation=this._store.state.selectionGroup.rotation;this.selectionGroup=this._store.state.selectionGroup}execute(){this._store.state.selectionGroup=this.selectionGroup;this._store.state.selectionGroup.rotate(this.rotation);this._store.state.selectionGroup.objects.forEach((t=>{this._store.state.objectsOctree.update(t)}))}undo(){this._store.state.selectionGroup=this.selectionGroup;this._store.state.selectionGroup.rotate(this.rotation-this.initialRotation);this._store.state.selectionGroup.objects.forEach((t=>{this._store.state.objectsOctree.update(t)}))}}class Dn extends Fn{constructor(t){super(t);this.initialRotation=0;this.rotation=0}handleMouseDown(t){if(w.isLeftClick(t)){if(this._store.state.selectionGroup&&this._store.state.isRotationHandleSelected){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.isRotating=true;const s=this._store.state.selectionGroup.translateX+this._store.state.selectionGroup.width/2/this._store.state.scale;const n=this._store.state.selectionGroup.translateY+this._store.state.selectionGroup.height/2/this._store.state.scale;const r=(i-this._store.state.translateX)/this._store.state.scale;const o=(e-this._store.state.translateY)/this._store.state.scale;this.initialRotation=Math.atan2(n-o,s-r)-this._store.state.selectionGroup.rotation}}}handleMouseMove(t){if(this._store.state.isRotating&&this._store.state.selectionGroup){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;const s=this._store.state.selectionGroup.translateX+this._store.state.selectionGroup.width/2/this._store.state.scale;const n=this._store.state.selectionGroup.translateY+this._store.state.selectionGroup.height/2/this._store.state.scale;const r=(i-this._store.state.translateX)/this._store.state.scale;const o=(e-this._store.state.translateY)/this._store.state.scale;const h=Math.atan2(n-o,s-r);this.rotation=h-this.initialRotation;this._store.state.selectionGroup.rotate(this.rotation);this._store.rerender()}}handleMouseUp(t){if(this._store.state.isRotating){this._store.history.executeCommand(new $n(this._store,this,this.rotation));this._store.state.isRotating=false;this.initialRotation=0;this.rotation=0}}handleTouchStart(t){const i=t.touches[0];if(!i){return}if(this._store.state.touchCount===1){if(this._store.state.selectionGroup&&this._store.state.isRotationHandleSelected){const t=Math.round(i.clientX-this._store.offsetX);const e=Math.round(i.clientY-this._store.offsetY);this._store.state.isRotating=true;const s=this._store.state.selectionGroup.translateX+this._store.state.selectionGroup.width/2/this._store.state.scale;const n=this._store.state.selectionGroup.translateY+this._store.state.selectionGroup.height/2/this._store.state.scale;const r=(t-this._store.state.translateX)/this._store.state.scale;const o=(e-this._store.state.translateY)/this._store.state.scale;this.initialRotation=Math.atan2(n-o,s-r)-this._store.state.selectionGroup.rotation;clearTimeout(this._store.state.longTouchTimeout)}}}handleTouchMove(t){const i=t.touches[0];if(!i){return}if(this._store.state.isRotating&&this._store.state.selectionGroup){const t=Math.round(i.clientX-this._store.offsetX);const e=Math.round(i.clientY-this._store.offsetY);const s=this._store.state.selectionGroup.translateX+this._store.state.selectionGroup.width/2/this._store.state.scale;const n=this._store.state.selectionGroup.translateY+this._store.state.selectionGroup.height/2/this._store.state.scale;const r=(t-this._store.state.translateX)/this._store.state.scale;const o=(e-this._store.state.translateY)/this._store.state.scale;const h=Math.atan2(n-o,s-r);this.rotation=h-this.initialRotation;this._store.state.selectionGroup.rotate(this.rotation);clearTimeout(this._store.state.longTouchTimeout)}}handleTouchEnd(t){if(this._store.state.isRotating){this._store.history.executeCommand(new $n(this._store,this,this.rotation));this._store.state.isRotating=false;this.initialRotation=0;this.rotation=0;clearTimeout(this._store.state.longTouchTimeout)}}}class _n{static doPolygonsIntersect(t,i){const e=[t.bottomLeft,t.bottomRight,t.topRight,t.topLeft];const s=[i.bottomLeft,i.bottomRight,i.topRight,i.topLeft];for(const t of e){if(this.isPointInPolygon(t,s)){return true}}for(const t of s){if(this.isPointInPolygon(t,e)){return true}}for(let t=0;t<e.length;t++){const i=e[t];const n=e[(t+1)%e.length];for(let t=0;t<s.length;t++){const e=s[t];const r=s[(t+1)%s.length];if(this.intersectLines(i,n,e,r)){return true}}}return false}static isPointInPolygon(t,i){let e=false;for(let s=0,n=i.length-1;s<i.length;n=s++){const r=i[s].x,o=i[s].y;const h=i[n].x,a=i[n].y;const l=o>t.y!==a>t.y&&t.x<(h-r)*(t.y-o)/(a-o)+r;if(l)e=!e}return e}static intersectLines(t,i,e,s){const n=(i.x-t.x)*(s.y-e.y)-(i.y-t.y)*(s.x-e.x);if(n===0){return false}const r=((e.x-t.x)*(s.y-e.y)-(e.y-t.y)*(s.x-e.x))/n;const o=-((t.x-e.x)*(i.y-t.y)-(t.y-e.y)*(i.x-t.x))/n;return r>=0&&r<=1&&o>=0&&o<=1}}class Pn extends fn{constructor(t){super(t);this.__class__="KrtizelSelectionBox";this.objects=[];this.backgroundColor="var(--kritzel-selection-box-background-color, rgba(14, 17, 17, 0.2))";this.borderColor="var(--kritzel-selection-box-border-color, rgba(14, 17, 17, 0.5))";this.borderWidth=2;this.scale=this._store.state.scale;this.height=0;this.width=0;this.zIndex=9999}}class Rn extends y{constructor(t,i,e){super(t,i);this.selectionGroup=e}execute(){this._store.state.objectsOctree.remove((t=>t instanceof Pn));this._store.state.objectsOctree.insert(this.selectionGroup);this._store.state.selectionGroup=this.selectionGroup}undo(){this._store.state.objectsOctree.remove((t=>t.id===this.selectionGroup.id));this._store.state.selectionGroup=null}}class Qn extends Fn{get isSelectionClick(){return this._store.state.selectionBox&&this._store.state.selectionBox.width===0&&this._store.state.selectionBox.height===0}get isSelectionDrag(){return this._store.state.selectionBox&&(this._store.state.selectionBox.width>0||this._store.state.selectionBox.height>0)}constructor(t){super(t);this.touchStartX=0;this.touchStartY=0;this.touchStartTimeout=null}handleMouseDown(t){if(w.isLeftClick(t)&&!this._store.state.selectionGroup){this.startMouseSelection(t)}}handleMouseMove(t){if(this._store.state.isSelecting){this.updateMouseSelection(t)}}handleMouseUp(t){if(w.isLeftClick(t)&&this._store.state.isSelecting){if(this.isSelectionClick){this.updateMouseSelection(t);this.addSelectedObjectAtIndexToSelectionGroup(0);this.removeSelectionBox()}if(this.isSelectionDrag){this.updateMouseSelection(t);this.addSelectedObjectsToSelectionGroup();this.removeSelectionBox()}}}handleTouchStart(t){this.touchStartTimeout=setTimeout((()=>{if(this._store.state.touchCount===1&&!this._store.state.isScaling&&!this._store.state.selectionGroup){this.startTouchSelection(t);this.updateTouchSelection(t)}}),80)}handleTouchMove(t){const i=Math.round(t.touches[0].clientX-this._store.offsetX);const e=Math.round(t.touches[0].clientY-this._store.offsetY);const s=Math.abs(i-this.touchStartX);const n=Math.abs(e-this.touchStartY);const r=5;if((s>r||n>r)&&this._store.state.isSelecting){this.updateTouchSelection(t);clearTimeout(this._store.state.longTouchTimeout)}}handleTouchEnd(t){clearTimeout(this.touchStartTimeout);if(this._store.state.isSelecting){if(this.isSelectionClick){this.updateTouchSelection(t);this.addSelectedObjectAtIndexToSelectionGroup(0);this.removeSelectionBox()}if(this.isSelectionDrag){this.updateTouchSelection(t);this.addSelectedObjectsToSelectionGroup();this.removeSelectionBox()}this._store.state.skipContextMenu=false}}removeSelectionBox(){this._store.state.selectionBox=null;this._store.state.isSelecting=false;this._store.state.objectsOctree.remove((t=>t instanceof Pn));this._store.rerender()}startMouseSelection(t){let i,e;i=t.clientX-this._store.offsetX;e=t.clientY-this._store.offsetY;const s=new Pn(this._store);this.startX=(i-this._store.state.translateX)/this._store.state.scale;this.startY=(e-this._store.state.translateY)/this._store.state.scale;s.translateX=this.startX;s.translateY=this.startY;this._store.state.selectionGroup=null;this._store.state.selectionBox=s;this._store.state.isSelecting=true;this._store.state.objectsOctree.remove((t=>t instanceof Pn||t instanceof Hn));this._store.state.objectsOctree.insert(s)}startTouchSelection(t){const i=t.touches[0];if(!i){return}let e,s;e=Math.round(i.clientX-this._store.offsetX);s=Math.round(i.clientY-this._store.offsetY);this.touchStartX=e;this.touchStartY=s;const n=new Pn(this._store);this.startX=(e-this._store.state.translateX)/this._store.state.scale;this.startY=(s-this._store.state.translateY)/this._store.state.scale;n.translateX=this.startX;n.translateY=this.startY;this._store.state.selectionGroup=null;this._store.state.selectionBox=n;this._store.state.isSelecting=true;this._store.state.objectsOctree.remove((t=>t instanceof Pn||t instanceof Hn));this._store.state.objectsOctree.insert(n)}updateMouseSelection(t){let i,e;i=t.clientX-this._store.offsetX;e=t.clientY-this._store.offsetY;const s=this._store.state.selectionBox;if(s){const t=(i-this._store.state.translateX)/s.scale;const n=(e-this._store.state.translateY)/s.scale;s.width=Math.abs(t-this.startX)*s.scale;s.height=Math.abs(n-this.startY)*s.scale;s.translateX=Math.min(t,this.startX);s.translateY=Math.min(n,this.startY);this.updateSelectedObjects();this._store.rerender()}}updateTouchSelection(t){const i=t.touches[0];if(!i){return}let e,s;e=Math.round(i.clientX-this._store.offsetX);s=Math.round(i.clientY-this._store.offsetY);const n=this._store.state.selectionBox;if(n){const t=(e-this._store.state.translateX)/n.scale;const i=(s-this._store.state.translateY)/n.scale;n.width=Math.abs(t-this.startX)*n.scale;n.height=Math.abs(i-this.startY)*n.scale;n.translateX=Math.min(t,this.startX);n.translateY=Math.min(i,this.startY);this.updateSelectedObjects()}}updateSelectedObjects(){this._store.allObjects.filter((t=>!(t instanceof Pn))).forEach((t=>{const i=t.rotatedPolygon;const e=this._store.state.selectionBox.rotatedPolygon;t.selected=_n.doPolygonsIntersect(i,e)}))}addSelectedObjectAtIndexToSelectionGroup(t){const i=this._store.selectedObjects.sort(((t,i)=>i.zIndex-t.zIndex));const e=i[t];if(!e){return}i.forEach((t=>t.selected=false));this._store.state.selectionGroup=new Hn(this._store);this._store.state.selectionGroup.addOrRemove(e);this._store.state.selectionGroup.selected=true;this._store.state.selectionGroup.rotation=this._store.state.selectionGroup.objects[0].rotation;this._store.history.executeCommand(new Rn(this._store,this,this._store.state.selectionGroup))}addSelectedObjectsToSelectionGroup(){const t=this._store.selectedObjects;if(t.length===0){return}this._store.state.selectionGroup=new Hn(this._store);t.forEach((t=>{t.selected=false;this._store.state.selectionGroup.addOrRemove(t)}));this._store.state.selectionGroup.selected=true;if(this._store.state.selectionGroup.length===1){this._store.state.selectionGroup.rotation=this._store.state.selectionGroup.objects[0].rotation}this._store.history.executeCommand(new Rn(this._store,this,this._store.state.selectionGroup))}}class Wn extends dn{constructor(t){super(t);this.selectionHandler=new Qn(this._store);this.moveHandler=new In(this._store);this.resizeHandler=new On(this._store);this.rotationHandler=new Dn(this._store)}handleMouseDown(t){if(w.isLeftClick(t)){this._store.state.isResizeHandleSelected=this.isHandleSelected(t);this._store.state.isRotationHandleSelected=this.isRotationHandleSelected(t);this._store.state.resizeHandleType=this.getHandleType(t);const i=this.getSelectedObject(t);const e=i&&this._store.state.selectionGroup&&i.id!==this._store.state.selectionGroup.id;if((i===null||e)&&this._store.state.selectionGroup&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){this._store.history.executeCommand(new Sn(this._store,this._store.state.selectionGroup))}}this.moveHandler.handleMouseDown(t);this.selectionHandler.handleMouseDown(t);this.resizeHandler.handleMouseDown(t);this.rotationHandler.handleMouseDown(t);this._store.rerender()}handleMouseMove(t){this.moveHandler.handleMouseMove(t);this.selectionHandler.handleMouseMove(t);this.resizeHandler.handleMouseMove(t);this.rotationHandler.handleMouseMove(t);this._store.rerender()}handleMouseUp(t){this.moveHandler.handleMouseUp(t);this.selectionHandler.handleMouseUp(t);this.resizeHandler.handleMouseUp(t);this.rotationHandler.handleMouseUp(t);this._store.rerender()}handleDoubleClick(t){var i;if(w.isLeftClick(t)){if(this._store.state.selectionGroup&&((i=this._store.state.selectionGroup)===null||i===void 0?void 0:i.objects.length)===1){const t=this._store.state.selectionGroup.objects[0];if(t instanceof bn){this._store.history.executeCommand(new Sn(this._store,this._store.state.selectionGroup));this._store.setState("activeTool",pn.getTool("text"));this._store.state.activeText=t;setTimeout((()=>{t.focus()}),300)}}}}handleDoubleTap(t){const i=this.getSelectedObject(t);if(!i||i.objects.length!==1){return}const e=i.objects[0];if(e instanceof bn){this._store.setState("activeTool",pn.getTool("text"));this._store.state.activeText=e;setTimeout((()=>{e.focus()}),300)}}handleTouchStart(t){if(this._store.state.isScaling===true){return}if(this._store.state.touchCount===1){this._store.state.isResizeHandleSelected=this.isHandleSelected(t);this._store.state.isRotationHandleSelected=this.isRotationHandleSelected(t);this._store.state.resizeHandleType=this.getHandleType(t);const i=this.getSelectedObject(t);const e=i&&this._store.state.selectionGroup&&i.id!==this._store.state.selectionGroup.id;if(!this._store.state.selectionGroup&&i){this._store.state.skipContextMenu=true}if((i===null||e)&&this._store.state.selectionGroup&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){this._store.history.executeCommand(new Sn(this._store,this._store.state.selectionGroup))}}this.rotationHandler.handleTouchStart(t);this.resizeHandler.handleTouchStart(t);this.moveHandler.handleTouchStart(t);this.selectionHandler.handleTouchStart(t)}handleTouchMove(t){if(this._store.state.isScaling===true){return}this.rotationHandler.handleTouchMove(t);this.resizeHandler.handleTouchMove(t);this.moveHandler.handleTouchMove(t);this.selectionHandler.handleTouchMove(t);this._store.rerender()}handleTouchEnd(t){if(this._store.state.isScaling===true){return}this.rotationHandler.handleTouchEnd(t);this.resizeHandler.handleTouchEnd(t);this.moveHandler.handleTouchEnd(t);this.selectionHandler.handleTouchEnd(t)}getSelectedObject(t){const i=t.composedPath().slice(1);const e=i.find((t=>t.classList&&t.classList.contains("object")));const s=this._store.findObjectById(e===null||e===void 0?void 0:e.id);if(!s){return null}if(s instanceof Hn){return s}else{const t=new Hn(this._store);t.translateX=0;t.translateY=0;t.addOrRemove(s);return t}}getHandleType(t){var i;const e=(i=this._store.state.host)===null||i===void 0?void 0:i.shadowRoot;if(!e)return;const s=t instanceof TouchEvent?t.touches[0]:t;const n=e.elementFromPoint(s.clientX,s.clientY);const r=n.closest(".resize-handle-overlay");return r===null||r===void 0?void 0:r.classList[1]}isHandleSelected(t){var i;const e=(i=this._store.state.host)===null||i===void 0?void 0:i.shadowRoot;if(!e)return false;const s=t instanceof TouchEvent?t.touches[0]:t;const n=e.elementFromPoint(s.clientX,s.clientY);return n===null||n===void 0?void 0:n.classList.contains("resize-handle-overlay")}isRotationHandleSelected(t){const i=t.composedPath();return!!i.find((t=>t.classList&&t.classList.contains("rotation-handle-overlay")))}}class Ln{constructor(t){this._store=t}revive(t){if(t&&typeof t==="object"){if(t.__class__){let i;switch(t.__class__){case"KritzelPath":i=new un(this._store).revive(t);break;case"KritzelText":i=new bn(this._store,t.fontSize,t.fontFamily).revive(t);break;case"KritzelImage":i=new Cn(this._store,t.img).revive(t);break;case"KritzelSelectionGroup":i=new Hn(this._store).revive(t);break;case"KritzelBrushTool":i=new vn(this._store);break;case"KritzelEraserTool":i=new Tn(this._store);break;case"KritzelImageTool":i=new jr(this._store);break;case"KritzelSelectionTool":i=new Wn(this._store);break;case"KritzelTextTool":i=new gn(this._store);break;default:i=t}return i}const i=Array.isArray(t)?[]:{};for(const e in t){if(Object.prototype.hasOwnProperty.call(t,e)){i[e]=this.revive(t[e])}}return i}return t}}class Hn extends fn{constructor(t){super(t);this.__class__="KritzelSelectionGroup";this.objects=[];this.unchangedObjects=[];this.scale=this._store.state.scale;this.zIndex=99999}get length(){return this.objects.length}addOrRemove(t){const i=this.objects.findIndex((i=>i.id===t.id));if(i===-1){this.objects.push(t)}else{this.objects.splice(i,1)}this.unchangedObjects=cn.clone(this.objects);this.refreshObjectDimensions()}deselectAllChildren(){this.objects.forEach((t=>t.selected=false))}updatePosition(t,i){this.objects.forEach((e=>{const s=e.translateX-this.translateX;const n=e.translateY-this.translateY;e.translateX=t+s;e.translateY=i+n;this._store.state.objectsOctree.update(e)}));this.unchangedObjects.forEach((e=>{const s=e.translateX-this.translateX;const n=e.translateY-this.translateY;e.translateX=t+s;e.translateY=i+n}));this.translateX=t;this.translateY=i;this._store.state.objectsOctree.update(this)}move(t,i,e,s){const n=(t-e)/this._store.state.scale;const r=(i-s)/this._store.state.scale;this.translateX+=n;this.translateY+=r;this._store.state.objectsOctree.update(this);this.objects.forEach((t=>{t.translateX+=n;t.translateY+=r;this._store.state.objectsOctree.update(t)}));this.unchangedObjects.forEach((t=>{t.translateX+=n;t.translateY+=r}))}resize(t,i,e,s){const n=e/this.width;const r=s/this.height;const o=t-this.translateX;const h=i-this.translateY;this.objects.forEach((t=>{const i=t.width*n;const e=t.height*r;const s=t.translateX+o+(t.translateX-this.translateX)*(n-1);const a=t.translateY+h+(t.translateY-this.translateY)*(r-1);t.resize(s,a,i,e);this._store.state.objectsOctree.update(t)}));this.refreshObjectDimensions();this.unchangedObjects=cn.clone(this.objects)}rotate(t){this.rotation=t;const i=this.translateX+this.totalWidth/2/this.scale;const e=this.translateY+this.totalHeight/2/this.scale;const s=t;const n=Math.cos(s);const r=Math.sin(s);this.objects.forEach((s=>{const o=this.getUnchangedObject(s.id);const h=this.getOffsetXToCenter(o);const a=this.getOffsetYToCenter(o);const l=n*h-r*a;const c=r*h+n*a;s.translateX=i+l-s.totalWidth/2/s.scale;s.translateY=e+c-s.totalHeight/2/s.scale;s.rotation=this.objects.length===1?t:t+o.rotation}))}copy(){const t=new Hn(this._store);let i=this._store.currentZIndex;this.objects.forEach((e=>{const s=e.copy();s.zIndex=i;t.addOrRemove(s);i++}));t.unchangedObjects=cn.clone(t.objects);if(this.objects.length===1){t.rotation=this.objects[0].rotation}return t}refreshObjectDimensions(){if(this.objects.length===1){const t=this.objects[0];this.minX=t.boundingBox.x/this.scale;this.maxX=t.boundingBox.x/this.scale+t.boundingBox.width;this.minY=t.boundingBox.y/this.scale;this.maxY=t.boundingBox.y/this.scale+t.boundingBox.height;this.translateX=(this.minX-this.padding)*this.scale;this.translateY=(this.minY-this.padding)*this.scale;this.width=(this.maxX-this.minX-this.padding)*this.scale;this.height=(this.maxY-this.minY-this.padding)*this.scale}else{this.minX=Math.min(...this.objects.map((t=>t.minXRotated)));this.maxX=Math.max(...this.objects.map((t=>t.maxXRotated)));this.minY=Math.min(...this.objects.map((t=>t.minYRotated)));this.maxY=Math.max(...this.objects.map((t=>t.maxYRotated)));this.translateX=this.minX-this.padding;this.translateY=this.minY-this.padding;this.width=(this.maxX-this.minX-this.padding)*this.scale;this.height=(this.maxY-this.minY-this.padding)*this.scale}this._store.state.objectsOctree.update(this)}getOffsetXToCenter(t){const i=t.translateX+t.totalWidth/t.scale/2;const e=this.translateX+this.totalWidth/this.scale/2;return i-e}getOffsetYToCenter(t){const i=t.translateY+t.totalHeight/t.scale/2;const e=this.translateY+this.totalHeight/this.scale/2;return i-e}getUnchangedObject(t){const i=this.unchangedObjects.find((i=>i.id===t));const e=new Ln(this._store);return e.revive(i)}}function Vn(t,i){return i.forEach((function(i){i&&"string"!=typeof i&&!Array.isArray(i)&&Object.keys(i).forEach((function(e){if("default"!==e&&!(e in t)){var s=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(t,e,s.get?s:{enumerable:true,get:function(){return i[e]}})}}))})),Object.freeze(t)}function Kn(t,i){return new Promise((function(e,s){let n;return Xn(t).then((function(t){try{return n=t,e(new Blob([i.slice(0,2),n,i.slice(2)],{type:"image/jpeg"}))}catch(t){return s(t)}}),s)}))}const Xn=t=>new Promise(((i,e)=>{const s=new FileReader;s.addEventListener("load",(({target:{result:t}})=>{const s=new DataView(t);let n=0;if(65496!==s.getUint16(n))return e("not a valid JPEG");for(n+=2;;){const r=s.getUint16(n);if(65498===r)break;const o=s.getUint16(n+2);if(65505===r&&1165519206===s.getUint32(n+4)){const r=n+10;let h;switch(s.getUint16(r)){case 18761:h=true;break;case 19789:h=false;break;default:return e("TIFF header contains invalid endian")}if(42!==s.getUint16(r+2,h))return e("TIFF header contains invalid version");const a=s.getUint32(r+4,h),l=r+a+2+12*s.getUint16(r+a,h);for(let t=r+a+2;t<l;t+=12){if(274==s.getUint16(t,h)){if(3!==s.getUint16(t+2,h))return e("Orientation data type is invalid");if(1!==s.getUint32(t+4,h))return e("Orientation data count is invalid");s.setUint16(t+8,1,h);break}}return i(t.slice(n,n+2+o))}n+=2+o}return i(new Blob)})),s.readAsArrayBuffer(t)}));var Nn={},Yn={get exports(){return Nn},set exports(t){Nn=t}};!function(t){var i,e,s={};Yn.exports=s,s.parse=function(t,i){for(var e=s.bin.readUshort,n=s.bin.readUint,r=0,o={},h=new Uint8Array(t),a=h.length-4;101010256!=n(h,a);)a--;r=a;r+=4;var l=e(h,r+=4);e(h,r+=2);var c=n(h,r+=2),f=n(h,r+=4);r+=4,r=f;for(var u=0;u<l;u++){n(h,r),r+=4,r+=4,r+=4,n(h,r+=4);c=n(h,r+=4);var d=n(h,r+=4),v=e(h,r+=4),b=e(h,r+2),p=e(h,r+4);r+=6;var g=n(h,r+=8);r+=4,r+=v+b+p,s._readLocal(h,g,o,c,d,i)}return o},s._readLocal=function(t,i,e,n,r,o){var h=s.bin.readUshort,a=s.bin.readUint;a(t,i),h(t,i+=4),h(t,i+=2);var l=h(t,i+=2);a(t,i+=2),a(t,i+=4),i+=4;var c=h(t,i+=8),f=h(t,i+=2);i+=2;var u=s.bin.readUTF8(t,i,c);if(i+=c,i+=f,o)e[u]={size:r,csize:n};else{var d=new Uint8Array(t.buffer,i);if(0==l)e[u]=new Uint8Array(d.buffer.slice(i,i+n));else{if(8!=l)throw"unknown compression method: "+l;var v=new Uint8Array(r);s.inflateRaw(d,v),e[u]=v}}},s.inflateRaw=function(t,i){return s.F.inflate(t,i)},s.inflate=function(t,i){return s.inflateRaw(new Uint8Array(t.buffer,t.byteOffset+2,t.length-6),i)},s.deflate=function(t,i){null==i&&(i={level:6});var e=0,n=new Uint8Array(50+Math.floor(1.1*t.length));n[e]=120,n[e+1]=156,e+=2,e=s.F.deflateRaw(t,n,e,i.level);var r=s.adler(t,0,t.length);return n[e+0]=r>>>24&255,n[e+1]=r>>>16&255,n[e+2]=r>>>8&255,n[e+3]=r>>>0&255,new Uint8Array(n.buffer,0,e+4)},s.deflateRaw=function(t,i){null==i&&(i={level:6});var e=new Uint8Array(50+Math.floor(1.1*t.length)),n=s.F.deflateRaw(t,e,n,i.level);return new Uint8Array(e.buffer,0,n)},s.encode=function(t,i){null==i&&(i=false);var e=0,n=s.bin.writeUint,r=s.bin.writeUshort,o={};for(var h in t){var a=!s._noNeed(h)&&!i,l=t[h],c=s.crc.crc(l,0,l.length);o[h]={cpr:a,usize:l.length,crc:c,file:a?s.deflateRaw(l):l}}for(var h in o)e+=o[h].file.length+30+46+2*s.bin.sizeUTF8(h);e+=22;var f=new Uint8Array(e),u=0,d=[];for(var h in o){var v=o[h];d.push(u),u=s._writeHeader(f,u,h,v,0)}var b=0,p=u;for(var h in o){v=o[h];d.push(u),u=s._writeHeader(f,u,h,v,1,d[b++])}var g=u-p;return n(f,u,101010256),u+=4,r(f,u+=4,b),r(f,u+=2,b),n(f,u+=2,g),n(f,u+=4,p),u+=4,u+=2,f.buffer},s._noNeed=function(t){var i=t.split(".").pop().toLowerCase();return-1!="png,jpg,jpeg,zip".indexOf(i)},s._writeHeader=function(t,i,e,n,r,o){var h=s.bin.writeUint,a=s.bin.writeUshort,l=n.file;return h(t,i,0==r?67324752:33639248),i+=4,1==r&&(i+=2),a(t,i,20),a(t,i+=2,0),a(t,i+=2,n.cpr?8:0),h(t,i+=2,0),h(t,i+=4,n.crc),h(t,i+=4,l.length),h(t,i+=4,n.usize),a(t,i+=4,s.bin.sizeUTF8(e)),a(t,i+=2,0),i+=2,1==r&&(i+=2,i+=2,h(t,i+=6,o),i+=4),i+=s.bin.writeUTF8(t,i,e),0==r&&(t.set(l,i),i+=l.length),i},s.crc={table:function(){for(var t=new Uint32Array(256),i=0;i<256;i++){for(var e=i,s=0;s<8;s++)1&e?e=3988292384^e>>>1:e>>>=1;t[i]=e}return t}(),update:function(t,i,e,n){for(var r=0;r<n;r++)t=s.crc.table[255&(t^i[e+r])]^t>>>8;return t},crc:function(t,i,e){return 4294967295^s.crc.update(4294967295,t,i,e)}},s.adler=function(t,i,e){for(var s=1,n=0,r=i,o=i+e;r<o;){for(var h=Math.min(r+5552,o);r<h;)n+=s+=t[r++];s%=65521,n%=65521}return n<<16|s},s.bin={readUshort:function(t,i){return t[i]|t[i+1]<<8},writeUshort:function(t,i,e){t[i]=255&e,t[i+1]=e>>8&255},readUint:function(t,i){return 16777216*t[i+3]+(t[i+2]<<16|t[i+1]<<8|t[i])},writeUint:function(t,i,e){t[i]=255&e,t[i+1]=e>>8&255,t[i+2]=e>>16&255,t[i+3]=e>>24&255},readASCII:function(t,i,e){for(var s="",n=0;n<e;n++)s+=String.fromCharCode(t[i+n]);return s},writeASCII:function(t,i,e){for(var s=0;s<e.length;s++)t[i+s]=e.charCodeAt(s)},pad:function(t){return t.length<2?"0"+t:t},readUTF8:function(t,i,e){for(var n,r="",o=0;o<e;o++)r+="%"+s.bin.pad(t[i+o].toString(16));try{n=decodeURIComponent(r)}catch(n){return s.bin.readASCII(t,i,e)}return n},writeUTF8:function(t,i,e){for(var s=e.length,n=0,r=0;r<s;r++){var o=e.charCodeAt(r);if(0==(4294967168&o))t[i+n]=o,n++;else if(0==(4294965248&o))t[i+n]=192|o>>6,t[i+n+1]=128|o>>0&63,n+=2;else if(0==(4294901760&o))t[i+n]=224|o>>12,t[i+n+1]=128|o>>6&63,t[i+n+2]=128|o>>0&63,n+=3;else{if(0!=(4292870144&o))throw"e";t[i+n]=240|o>>18,t[i+n+1]=128|o>>12&63,t[i+n+2]=128|o>>6&63,t[i+n+3]=128|o>>0&63,n+=4}}return n},sizeUTF8:function(t){for(var i=t.length,e=0,s=0;s<i;s++){var n=t.charCodeAt(s);if(0==(4294967168&n))e++;else if(0==(4294965248&n))e+=2;else if(0==(4294901760&n))e+=3;else{if(0!=(4292870144&n))throw"e";e+=4}}return e}},s.F={},s.F.deflateRaw=function(t,i,e,n){var r=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]][n],o=s.F.U,h=s.F._goodIndex;var a=s.F._putsE,l=0,c=e<<3,f=0,u=t.length;if(0==n){for(;l<u;){a(i,c,l+(z=Math.min(65535,u-l))==u?1:0),c=s.F._copyExact(t,l,z,i,c+8),l+=z}return c>>>3}var d=o.lits,v=o.strt,b=o.prev,p=0,g=0,w=0,y=0,k=0,x=0;for(u>2&&(v[x=s.F._hash(t,0)]=0),l=0;l<u;l++){if(k=x,l+1<u-2){x=s.F._hash(t,l+1);var m=l+1&32767;b[m]=v[x],v[x]=m}if(f<=l){(p>14e3||g>26697)&&u-l>100&&(f<l&&(d[p]=l-f,p+=2,f=l),c=s.F._writeBlock(l==u-1||f==u?1:0,d,p,y,t,w,l-w,i,c),p=g=y=0,w=l);var A=0;l<u-2&&(A=s.F._bestMatch(t,l,b,k,Math.min(r[2],u-l),r[3]));var z=A>>>16,M=65535&A;if(0!=A){M=65535&A;var j=h(z=A>>>16,o.of0);o.lhst[257+j]++;var T=h(M,o.df0);o.dhst[T]++,y+=o.exb[j]+o.dxb[T],d[p]=z<<23|l-f,d[p+1]=M<<16|j<<8|T,p+=2,f=l+z}else o.lhst[t[l]]++;g++}}for(w==l&&0!=t.length||(f<l&&(d[p]=l-f,p+=2,f=l),c=s.F._writeBlock(1,d,p,y,t,w,l-w,i,c),p=0,g=0,p=g=y=0,w=l);0!=(7&c);)c++;return c>>>3},s.F._bestMatch=function(t,i,e,n,r,o){var h=32767&i,a=e[h],l=h-a+32768&32767;if(a==h||n!=s.F._hash(t,i-l))return 0;for(var c=0,f=0,u=Math.min(32767,i);l<=u&&0!=--o&&a!=h;){if(0==c||t[i+c]==t[i+c-l]){var d=s.F._howLong(t,i,l);if(d>c){if(f=l,(c=d)>=r)break;l+2<d&&(d=l+2);for(var v=0,b=0;b<d-2;b++){var p=i-l+b+32768&32767,g=p-e[p]+32768&32767;g>v&&(v=g,a=p)}}}l+=(h=a)-(a=e[h])+32768&32767}return c<<16|f},s.F._howLong=function(t,i,e){if(t[i]!=t[i-e]||t[i+1]!=t[i+1-e]||t[i+2]!=t[i+2-e])return 0;var s=i,n=Math.min(t.length,i+258);for(i+=3;i<n&&t[i]==t[i-e];)i++;return i-s},s.F._hash=function(t,i){return(t[i]<<8|t[i+1])+(t[i+2]<<4)&65535},s.saved=0,s.F._writeBlock=function(t,i,e,n,r,o,h,a,l){var c,f,u,d,v,b,p,g,w,y=s.F.U,k=s.F._putsF,x=s.F._putsE;y.lhst[256]++,f=(c=s.F.getTrees())[0],u=c[1],d=c[2],v=c[3],b=c[4],p=c[5],g=c[6],w=c[7];var m=32+(0==(l+3&7)?0:8-(l+3&7))+(h<<3),A=n+s.F.contSize(y.fltree,y.lhst)+s.F.contSize(y.fdtree,y.dhst),z=n+s.F.contSize(y.ltree,y.lhst)+s.F.contSize(y.dtree,y.dhst);z+=14+3*p+s.F.contSize(y.itree,y.ihst)+(2*y.ihst[16]+3*y.ihst[17]+7*y.ihst[18]);for(var M=0;M<286;M++)y.lhst[M]=0;for(M=0;M<30;M++)y.dhst[M]=0;for(M=0;M<19;M++)y.ihst[M]=0;var j=m<A&&m<z?0:A<z?1:2;if(k(a,l,t),k(a,l+1,j),l+=3,0==j){for(;0!=(7&l);)l++;l=s.F._copyExact(r,o,h,a,l)}else{var T,C;if(1==j&&(T=y.fltree,C=y.fdtree),2==j){s.F.makeCodes(y.ltree,f),s.F.revCodes(y.ltree,f),s.F.makeCodes(y.dtree,u),s.F.revCodes(y.dtree,u),s.F.makeCodes(y.itree,d),s.F.revCodes(y.itree,d),T=y.ltree,C=y.dtree,x(a,l,v-257),x(a,l+=5,b-1),x(a,l+=5,p-4),l+=4;for(var S=0;S<p;S++)x(a,l+3*S,y.itree[1+(y.ordr[S]<<1)]);l+=3*p,l=s.F._codeTiny(g,y.itree,a,l),l=s.F._codeTiny(w,y.itree,a,l)}for(var E=o,F=0;F<e;F+=2){for(var I=i[F],U=I>>>23,B=E+(8388607&I);E<B;)l=s.F._writeLit(r[E++],T,a,l);if(0!=U){var O=i[F+1],$=O>>16,D=O>>8&255,_=255&O;x(a,l=s.F._writeLit(257+D,T,a,l),U-y.of0[D]),l+=y.exb[D],k(a,l=s.F._writeLit(_,C,a,l),$-y.df0[_]),l+=y.dxb[_],E+=U}}l=s.F._writeLit(256,T,a,l)}return l},s.F._copyExact=function(t,i,e,s,n){var r=n>>>3;return s[r]=e,s[r+1]=e>>>8,s[r+2]=255-s[r],s[r+3]=255-s[r+1],r+=4,s.set(new Uint8Array(t.buffer,i,e),r),n+(e+4<<3)},s.F.getTrees=function(){for(var t=s.F.U,i=s.F._hufTree(t.lhst,t.ltree,15),e=s.F._hufTree(t.dhst,t.dtree,15),n=[],r=s.F._lenCodes(t.ltree,n),o=[],h=s.F._lenCodes(t.dtree,o),a=0;a<n.length;a+=2)t.ihst[n[a]]++;for(a=0;a<o.length;a+=2)t.ihst[o[a]]++;for(var l=s.F._hufTree(t.ihst,t.itree,7),c=19;c>4&&0==t.itree[1+(t.ordr[c-1]<<1)];)c--;return[i,e,l,r,h,c,n,o]},s.F.getSecond=function(t){for(var i=[],e=0;e<t.length;e+=2)i.push(t[e+1]);return i},s.F.nonZero=function(t){for(var i="",e=0;e<t.length;e+=2)0!=t[e+1]&&(i+=(e>>1)+",");return i},s.F.contSize=function(t,i){for(var e=0,s=0;s<i.length;s++)e+=i[s]*t[1+(s<<1)];return e},s.F._codeTiny=function(t,i,e,n){for(var r=0;r<t.length;r+=2){var o=t[r],h=t[r+1];n=s.F._writeLit(o,i,e,n);var a=16==o?2:17==o?3:7;o>15&&(s.F._putsE(e,n,h,a),n+=a)}return n},s.F._lenCodes=function(t,i){for(var e=t.length;2!=e&&0==t[e-1];)e-=2;for(var s=0;s<e;s+=2){var n=t[s+1],r=s+3<e?t[s+3]:-1,o=s+5<e?t[s+5]:-1,h=0==s?-1:t[s-1];if(0==n&&r==n&&o==n){for(var a=s+5;a+2<e&&t[a+2]==n;)a+=2;(l=Math.min(a+1-s>>>1,138))<11?i.push(17,l-3):i.push(18,l-11),s+=2*l-2}else if(n==h&&r==n&&o==n){for(a=s+5;a+2<e&&t[a+2]==n;)a+=2;var l=Math.min(a+1-s>>>1,6);i.push(16,l-3),s+=2*l-2}else i.push(n,0)}return e>>>1},s.F._hufTree=function(t,i,e){var n=[],r=t.length,o=i.length,h=0;for(h=0;h<o;h+=2)i[h]=0,i[h+1]=0;for(h=0;h<r;h++)0!=t[h]&&n.push({lit:h,f:t[h]});var a=n.length,l=n.slice(0);if(0==a)return 0;if(1==a){var c=n[0].lit;l=0==c?1:0;return i[1+(c<<1)]=1,i[1+(l<<1)]=1,1}n.sort((function(t,i){return t.f-i.f}));var f=n[0],u=n[1],d=0,v=1,b=2;for(n[0]={lit:-1,f:f.f+u.f,l:f,r:u,d:0};v!=a-1;)f=d!=v&&(b==a||n[d].f<n[b].f)?n[d++]:n[b++],u=d!=v&&(b==a||n[d].f<n[b].f)?n[d++]:n[b++],n[v++]={lit:-1,f:f.f+u.f,l:f,r:u};var p=s.F.setDepth(n[v-1],0);for(p>e&&(s.F.restrictDepth(l,e,p),p=e),h=0;h<a;h++)i[1+(l[h].lit<<1)]=l[h].d;return p},s.F.setDepth=function(t,i){return-1!=t.lit?(t.d=i,i):Math.max(s.F.setDepth(t.l,i+1),s.F.setDepth(t.r,i+1))},s.F.restrictDepth=function(t,i,e){var s=0,n=1<<e-i,r=0;for(t.sort((function(t,i){return i.d==t.d?t.f-i.f:i.d-t.d})),s=0;s<t.length&&t[s].d>i;s++){var o=t[s].d;t[s].d=i,r+=n-(1<<e-o)}for(r>>>=e-i;r>0;){(o=t[s].d)<i?(t[s].d++,r-=1<<i-o-1):s++}for(;s>=0;s--)t[s].d==i&&r<0&&(t[s].d--,r++);0!=r&&console.log("debt left")},s.F._goodIndex=function(t,i){var e=0;return i[16|e]<=t&&(e|=16),i[8|e]<=t&&(e|=8),i[4|e]<=t&&(e|=4),i[2|e]<=t&&(e|=2),i[1|e]<=t&&(e|=1),e},s.F._writeLit=function(t,i,e,n){return s.F._putsF(e,n,i[t<<1]),n+i[1+(t<<1)]},s.F.inflate=function(t,i){var e=Uint8Array;if(3==t[0]&&0==t[1])return i||new e(0);var n=s.F,r=n._bitsF,o=n._bitsE,h=n._decodeTiny,a=n.makeCodes,l=n.codes2map,c=n._get17,f=n.U,u=null==i;u&&(i=new e(t.length>>>2<<3));for(var d,v,b=0,p=0,g=0,w=0,y=0,k=0,x=0,m=0,A=0;0==b;)if(b=r(t,A,1),p=r(t,A+1,2),A+=3,0!=p){if(u&&(i=s.F._check(i,m+(1<<17))),1==p&&(d=f.flmap,v=f.fdmap,k=511,x=31),2==p){g=o(t,A,5)+257,w=o(t,A+5,5)+1,y=o(t,A+10,4)+4,A+=14;for(var z=0;z<38;z+=2)f.itree[z]=0,f.itree[z+1]=0;var M=1;for(z=0;z<y;z++){var j=o(t,A+3*z,3);f.itree[1+(f.ordr[z]<<1)]=j,j>M&&(M=j)}A+=3*y,a(f.itree,M),l(f.itree,M,f.imap),d=f.lmap,v=f.dmap,A=h(f.imap,(1<<M)-1,g+w,t,A,f.ttree);var T=n._copyOut(f.ttree,0,g,f.ltree);k=(1<<T)-1;var C=n._copyOut(f.ttree,g,w,f.dtree);x=(1<<C)-1,a(f.ltree,T),l(f.ltree,T,d),a(f.dtree,C),l(f.dtree,C,v)}for(;;){var S=d[c(t,A)&k];A+=15&S;var E=S>>>4;if(E>>>8==0)i[m++]=E;else{if(256==E)break;var F=m+E-254;if(E>264){var I=f.ldef[E-257];F=m+(I>>>3)+o(t,A,7&I),A+=7&I}var U=v[c(t,A)&x];A+=15&U;var B=U>>>4,O=f.ddef[B],$=(O>>>4)+r(t,A,15&O);for(A+=15&O,u&&(i=s.F._check(i,m+(1<<17)));m<F;)i[m]=i[m++-$],i[m]=i[m++-$],i[m]=i[m++-$],i[m]=i[m++-$];m=F}}}else{0!=(7&A)&&(A+=8-(7&A));var D=4+(A>>>3),_=t[D-4]|t[D-3]<<8;u&&(i=s.F._check(i,m+_)),i.set(new e(t.buffer,t.byteOffset+D,_),m),A=D+_<<3,m+=_}return i.length==m?i:i.slice(0,m)},s.F._check=function(t,i){var e=t.length;if(i<=e)return t;var s=new Uint8Array(Math.max(e<<1,i));return s.set(t,0),s},s.F._decodeTiny=function(t,i,e,n,r,o){for(var h=s.F._bitsE,a=s.F._get17,l=0;l<e;){var c=t[a(n,r)&i];r+=15&c;var f=c>>>4;if(f<=15)o[l]=f,l++;else{var u=0,d=0;16==f?(d=3+h(n,r,2),r+=2,u=o[l-1]):17==f?(d=3+h(n,r,3),r+=3):18==f&&(d=11+h(n,r,7),r+=7);for(var v=l+d;l<v;)o[l]=u,l++}}return r},s.F._copyOut=function(t,i,e,s){for(var n=0,r=0,o=s.length>>>1;r<e;){var h=t[r+i];s[r<<1]=0,s[1+(r<<1)]=h,h>n&&(n=h),r++}for(;r<o;)s[r<<1]=0,s[1+(r<<1)]=0,r++;return n},s.F.makeCodes=function(t,i){for(var e,n,r,o,h=s.F.U,a=t.length,l=h.bl_count,c=0;c<=i;c++)l[c]=0;for(c=1;c<a;c+=2)l[t[c]]++;var f=h.next_code;for(e=0,l[0]=0,n=1;n<=i;n++)e=e+l[n-1]<<1,f[n]=e;for(r=0;r<a;r+=2)0!=(o=t[r+1])&&(t[r]=f[o],f[o]++)},s.F.codes2map=function(t,i,e){for(var n=t.length,r=s.F.U.rev15,o=0;o<n;o+=2)if(0!=t[o+1])for(var h=o>>1,a=t[o+1],l=h<<4|a,c=i-a,f=t[o]<<c,u=f+(1<<c);f!=u;){e[r[f]>>>15-i]=l,f++}},s.F.revCodes=function(t,i){for(var e=s.F.U.rev15,n=15-i,r=0;r<t.length;r+=2){var o=t[r]<<i-t[r+1];t[r]=e[o]>>>n}},s.F._putsE=function(t,i,e){e<<=7&i;var s=i>>>3;t[s]|=e,t[s+1]|=e>>>8},s.F._putsF=function(t,i,e){e<<=7&i;var s=i>>>3;t[s]|=e,t[s+1]|=e>>>8,t[s+2]|=e>>>16},s.F._bitsE=function(t,i,e){return(t[i>>>3]|t[1+(i>>>3)]<<8)>>>(7&i)&(1<<e)-1},s.F._bitsF=function(t,i,e){return(t[i>>>3]|t[1+(i>>>3)]<<8|t[2+(i>>>3)]<<16)>>>(7&i)&(1<<e)-1},s.F._get17=function(t,i){return(t[i>>>3]|t[1+(i>>>3)]<<8|t[2+(i>>>3)]<<16)>>>(7&i)},s.F._get25=function(t,i){return(t[i>>>3]|t[1+(i>>>3)]<<8|t[2+(i>>>3)]<<16|t[3+(i>>>3)]<<24)>>>(7&i)},s.F.U=(i=Uint16Array,e=Uint32Array,{next_code:new i(16),bl_count:new i(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],ldef:new i(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],ddef:new e(32),flmap:new i(512),fltree:[],fdmap:new i(32),fdtree:[],lmap:new i(32768),ltree:[],ttree:[],dmap:new i(32768),dtree:[],imap:new i(512),itree:[],rev15:new i(32768),lhst:new e(286),dhst:new e(30),ihst:new e(19),lits:new e(15e3),strt:new i(65536),prev:new i(32768)}),function(){for(var t=s.F.U,i=0;i<32768;i++){var e=i;e=(4278255360&(e=(4042322160&(e=(3435973836&(e=(2863311530&e)>>>1|(1431655765&e)<<1))>>>2|(858993459&e)<<2))>>>4|(252645135&e)<<4))>>>8|(16711935&e)<<8,t.rev15[i]=(e>>>16|e<<16)>>>17}function n(t,i,e){for(;0!=i--;)t.push(0,e)}for(i=0;i<32;i++)t.ldef[i]=t.of0[i]<<3|t.exb[i],t.ddef[i]=t.df0[i]<<4|t.dxb[i];n(t.fltree,144,8),n(t.fltree,112,9),n(t.fltree,24,7),n(t.fltree,8,8),s.F.makeCodes(t.fltree,9),s.F.codes2map(t.fltree,9,t.flmap),s.F.revCodes(t.fltree,9),n(t.fdtree,32,5),s.F.makeCodes(t.fdtree,5),s.F.codes2map(t.fdtree,5,t.fdmap),s.F.revCodes(t.fdtree,5),n(t.itree,19,0),n(t.ltree,286,0),n(t.dtree,30,0),n(t.ttree,320,0)}()}();var Gn=Vn({__proto__:null,default:Nn},[Nn]);const qn=function(){var t={nextZero(t,i){for(;0!=t[i];)i++;return i},readUshort:(t,i)=>t[i]<<8|t[i+1],writeUshort(t,i,e){t[i]=e>>8&255,t[i+1]=255&e},readUint:(t,i)=>16777216*t[i]+(t[i+1]<<16|t[i+2]<<8|t[i+3]),writeUint(t,i,e){t[i]=e>>24&255,t[i+1]=e>>16&255,t[i+2]=e>>8&255,t[i+3]=255&e},readASCII(t,i,e){let s="";for(let n=0;n<e;n++)s+=String.fromCharCode(t[i+n]);return s},writeASCII(t,i,e){for(let s=0;s<e.length;s++)t[i+s]=e.charCodeAt(s)},readBytes(t,i,e){const s=[];for(let n=0;n<e;n++)s.push(t[i+n]);return s},pad:t=>t.length<2?`0${t}`:t,readUTF8(i,e,s){let n,r="";for(let n=0;n<s;n++)r+=`%${t.pad(i[e+n].toString(16))}`;try{n=decodeURIComponent(r)}catch(n){return t.readASCII(i,e,s)}return n}};function i(i,e,s,n){const o=e*s,h=r(n),a=Math.ceil(e*h/8),l=new Uint8Array(4*o),c=new Uint32Array(l.buffer),{ctype:f}=n,{depth:u}=n,d=t.readUshort;if(6==f){const t=o<<2;if(8==u)for(var v=0;v<t;v+=4)l[v]=i[v],l[v+1]=i[v+1],l[v+2]=i[v+2],l[v+3]=i[v+3];if(16==u)for(v=0;v<t;v++)l[v]=i[v<<1]}else if(2==f){const t=n.tabs.tRNS;if(null==t){if(8==u)for(v=0;v<o;v++){var b=3*v;c[v]=255<<24|i[b+2]<<16|i[b+1]<<8|i[b]}if(16==u)for(v=0;v<o;v++){b=6*v;c[v]=255<<24|i[b+4]<<16|i[b+2]<<8|i[b]}}else{var p=t[0];const e=t[1],s=t[2];if(8==u)for(v=0;v<o;v++){var g=v<<2;b=3*v;c[v]=255<<24|i[b+2]<<16|i[b+1]<<8|i[b],i[b]==p&&i[b+1]==e&&i[b+2]==s&&(l[g+3]=0)}if(16==u)for(v=0;v<o;v++){g=v<<2,b=6*v;c[v]=255<<24|i[b+4]<<16|i[b+2]<<8|i[b],d(i,b)==p&&d(i,b+2)==e&&d(i,b+4)==s&&(l[g+3]=0)}}}else if(3==f){const t=n.tabs.PLTE,r=n.tabs.tRNS,h=r?r.length:0;if(1==u)for(var w=0;w<s;w++){var y=w*a,k=w*e;for(v=0;v<e;v++){g=k+v<<2;var x=3*(m=i[y+(v>>3)]>>7-((7&v)<<0)&1);l[g]=t[x],l[g+1]=t[x+1],l[g+2]=t[x+2],l[g+3]=m<h?r[m]:255}}if(2==u)for(w=0;w<s;w++)for(y=w*a,k=w*e,v=0;v<e;v++){g=k+v<<2,x=3*(m=i[y+(v>>2)]>>6-((3&v)<<1)&3);l[g]=t[x],l[g+1]=t[x+1],l[g+2]=t[x+2],l[g+3]=m<h?r[m]:255}if(4==u)for(w=0;w<s;w++)for(y=w*a,k=w*e,v=0;v<e;v++){g=k+v<<2,x=3*(m=i[y+(v>>1)]>>4-((1&v)<<2)&15);l[g]=t[x],l[g+1]=t[x+1],l[g+2]=t[x+2],l[g+3]=m<h?r[m]:255}if(8==u)for(v=0;v<o;v++){var m;g=v<<2,x=3*(m=i[v]);l[g]=t[x],l[g+1]=t[x+1],l[g+2]=t[x+2],l[g+3]=m<h?r[m]:255}}else if(4==f){if(8==u)for(v=0;v<o;v++){g=v<<2;var A=i[z=v<<1];l[g]=A,l[g+1]=A,l[g+2]=A,l[g+3]=i[z+1]}if(16==u)for(v=0;v<o;v++){var z;g=v<<2,A=i[z=v<<2];l[g]=A,l[g+1]=A,l[g+2]=A,l[g+3]=i[z+2]}}else if(0==f)for(p=n.tabs.tRNS?n.tabs.tRNS:-1,w=0;w<s;w++){const t=w*a,s=w*e;if(1==u)for(var M=0;M<e;M++){var j=(A=255*(i[t+(M>>>3)]>>>7-(7&M)&1))==255*p?0:255;c[s+M]=j<<24|A<<16|A<<8|A}else if(2==u)for(M=0;M<e;M++){j=(A=85*(i[t+(M>>>2)]>>>6-((3&M)<<1)&3))==85*p?0:255;c[s+M]=j<<24|A<<16|A<<8|A}else if(4==u)for(M=0;M<e;M++){j=(A=17*(i[t+(M>>>1)]>>>4-((1&M)<<2)&15))==17*p?0:255;c[s+M]=j<<24|A<<16|A<<8|A}else if(8==u)for(M=0;M<e;M++){j=(A=i[t+M])==p?0:255;c[s+M]=j<<24|A<<16|A<<8|A}else if(16==u)for(M=0;M<e;M++){A=i[t+(M<<1)],j=d(i,t+(M<<1))==p?0:255;c[s+M]=j<<24|A<<16|A<<8|A}}return l}function e(t,i,e,h){const a=r(t),l=Math.ceil(e*a/8),c=new Uint8Array((l+1+t.interlace)*h);return i=t.tabs.CgBI?n(i,c):s(i,c),0==t.interlace?i=o(i,t,0,e,h):1==t.interlace&&(i=function t(i,e){const s=e.width,n=e.height,h=r(e),a=h>>3,l=Math.ceil(s*h/8),c=new Uint8Array(n*l);let f=0;const u=[0,0,4,0,2,0,1],d=[0,4,0,2,0,1,0],v=[8,8,8,4,4,2,2],b=[8,8,4,4,2,2,1];let p=0;for(;p<7;){const t=v[p],r=b[p];let w=0,y=0,k=u[p];for(;k<n;)k+=t,y++;let x=d[p];for(;x<s;)x+=r,w++;const m=Math.ceil(w*h/8);o(i,e,f,w,y);let A=0,z=u[p];for(;z<n;){let e=d[p],n=f+A*m<<3;for(;e<s;){var g;if(1==h)g=(g=i[n>>3])>>7-(7&n)&1,c[z*l+(e>>3)]|=g<<7-((7&e)<<0);if(2==h)g=(g=i[n>>3])>>6-(7&n)&3,c[z*l+(e>>2)]|=g<<6-((3&e)<<1);if(4==h)g=(g=i[n>>3])>>4-(7&n)&15,c[z*l+(e>>1)]|=g<<4-((1&e)<<2);if(h>=8){const t=z*l+e*a;for(let e=0;e<a;e++)c[t+e]=i[(n>>3)+e]}n+=h,e+=r}A++,z+=t}w*y!=0&&(f+=y*(1+m)),p+=1}return c}(i,t)),i}function s(t,i){return n(new Uint8Array(t.buffer,2,t.length-6),i)}var n=function(){const t={H:{}};return t.H.N=function(i,e){const s=Uint8Array;let n,r,o=0,h=0,a=0,l=0,c=0,f=0,u=0,d=0,v=0;if(3==i[0]&&0==i[1])return e||new s(0);const b=t.H,p=b.b,g=b.e,w=b.R,y=b.n,k=b.A,x=b.Z,m=b.m,A=null==e;for(A&&(e=new s(i.length>>>2<<5));0==o;)if(o=p(i,v,1),h=p(i,v+1,2),v+=3,0!=h){if(A&&(e=t.H.W(e,d+(1<<17))),1==h&&(n=m.J,r=m.h,f=511,u=31),2==h){a=g(i,v,5)+257,l=g(i,v+5,5)+1,c=g(i,v+10,4)+4,v+=14;let t=1;for(var z=0;z<38;z+=2)m.Q[z]=0,m.Q[z+1]=0;for(z=0;z<c;z++){const e=g(i,v+3*z,3);m.Q[1+(m.X[z]<<1)]=e,e>t&&(t=e)}v+=3*c,y(m.Q,t),k(m.Q,t,m.u),n=m.w,r=m.d,v=w(m.u,(1<<t)-1,a+l,i,v,m.v);const e=b.V(m.v,0,a,m.C);f=(1<<e)-1;const s=b.V(m.v,a,l,m.D);u=(1<<s)-1,y(m.C,e),k(m.C,e,n),y(m.D,s),k(m.D,s,r)}for(;;){const t=n[x(i,v)&f];v+=15&t;const s=t>>>4;if(s>>>8==0)e[d++]=s;else{if(256==s)break;{let t=d+s-254;if(s>264){const e=m.q[s-257];t=d+(e>>>3)+g(i,v,7&e),v+=7&e}const n=r[x(i,v)&u];v+=15&n;const o=n>>>4,h=m.c[o],a=(h>>>4)+p(i,v,15&h);for(v+=15&h;d<t;)e[d]=e[d++-a],e[d]=e[d++-a],e[d]=e[d++-a],e[d]=e[d++-a];d=t}}}}else{0!=(7&v)&&(v+=8-(7&v));const n=4+(v>>>3),r=i[n-4]|i[n-3]<<8;A&&(e=t.H.W(e,d+r)),e.set(new s(i.buffer,i.byteOffset+n,r),d),v=n+r<<3,d+=r}return e.length==d?e:e.slice(0,d)},t.H.W=function(t,i){const e=t.length;if(i<=e)return t;const s=new Uint8Array(e<<1);return s.set(t,0),s},t.H.R=function(i,e,s,n,r,o){const h=t.H.e,a=t.H.Z;let l=0;for(;l<s;){const t=i[a(n,r)&e];r+=15&t;const s=t>>>4;if(s<=15)o[l]=s,l++;else{let t=0,i=0;16==s?(i=3+h(n,r,2),r+=2,t=o[l-1]):17==s?(i=3+h(n,r,3),r+=3):18==s&&(i=11+h(n,r,7),r+=7);const e=l+i;for(;l<e;)o[l]=t,l++}}return r},t.H.V=function(t,i,e,s){let n=0,r=0;const o=s.length>>>1;for(;r<e;){const e=t[r+i];s[r<<1]=0,s[1+(r<<1)]=e,e>n&&(n=e),r++}for(;r<o;)s[r<<1]=0,s[1+(r<<1)]=0,r++;return n},t.H.n=function(i,e){const s=t.H.m,n=i.length;let r,o,h;let a;const l=s.j;for(var c=0;c<=e;c++)l[c]=0;for(c=1;c<n;c+=2)l[i[c]]++;const f=s.K;for(r=0,l[0]=0,o=1;o<=e;o++)r=r+l[o-1]<<1,f[o]=r;for(h=0;h<n;h+=2)a=i[h+1],0!=a&&(i[h]=f[a],f[a]++)},t.H.A=function(i,e,s){const n=i.length,r=t.H.m.r;for(let t=0;t<n;t+=2)if(0!=i[t+1]){const n=t>>1,o=i[t+1],h=n<<4|o,a=e-o;let l=i[t]<<a;const c=l+(1<<a);for(;l!=c;){s[r[l]>>>15-e]=h,l++}}},t.H.l=function(i,e){const s=t.H.m.r,n=15-e;for(let t=0;t<i.length;t+=2){const r=i[t]<<e-i[t+1];i[t]=s[r]>>>n}},t.H.M=function(t,i,e){e<<=7&i;const s=i>>>3;t[s]|=e,t[s+1]|=e>>>8},t.H.I=function(t,i,e){e<<=7&i;const s=i>>>3;t[s]|=e,t[s+1]|=e>>>8,t[s+2]|=e>>>16},t.H.e=function(t,i,e){return(t[i>>>3]|t[1+(i>>>3)]<<8)>>>(7&i)&(1<<e)-1},t.H.b=function(t,i,e){return(t[i>>>3]|t[1+(i>>>3)]<<8|t[2+(i>>>3)]<<16)>>>(7&i)&(1<<e)-1},t.H.Z=function(t,i){return(t[i>>>3]|t[1+(i>>>3)]<<8|t[2+(i>>>3)]<<16)>>>(7&i)},t.H.i=function(t,i){return(t[i>>>3]|t[1+(i>>>3)]<<8|t[2+(i>>>3)]<<16|t[3+(i>>>3)]<<24)>>>(7&i)},t.H.m=function(){const t=Uint16Array,i=Uint32Array;return{K:new t(16),j:new t(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new t(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new i(32),J:new t(512),_:[],h:new t(32),$:[],w:new t(32768),C:[],v:[],d:new t(32768),D:[],u:new t(512),Q:[],r:new t(32768),s:new i(286),Y:new i(30),a:new i(19),t:new i(15e3),k:new t(65536),g:new t(32768)}}(),function(){const i=t.H.m;for(var e=0;e<32768;e++){let t=e;t=(2863311530&t)>>>1|(1431655765&t)<<1,t=(3435973836&t)>>>2|(858993459&t)<<2,t=(4042322160&t)>>>4|(252645135&t)<<4,t=(4278255360&t)>>>8|(16711935&t)<<8,i.r[e]=(t>>>16|t<<16)>>>17}function s(t,i,e){for(;0!=i--;)t.push(0,e)}for(e=0;e<32;e++)i.q[e]=i.S[e]<<3|i.T[e],i.c[e]=i.p[e]<<4|i.z[e];s(i._,144,8),s(i._,112,9),s(i._,24,7),s(i._,8,8),t.H.n(i._,9),t.H.A(i._,9,i.J),t.H.l(i._,9),s(i.$,32,5),t.H.n(i.$,5),t.H.A(i.$,5,i.h),t.H.l(i.$,5),s(i.Q,19,0),s(i.C,286,0),s(i.D,30,0),s(i.v,320,0)}(),t.H.N}();function r(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function o(t,i,e,s,n){let o=r(i);const a=Math.ceil(s*o/8);let l,c;o=Math.ceil(o/8);let f=t[e],u=0;if(f>1&&(t[e]=[0,0,1][f-2]),3==f)for(u=o;u<a;u++)t[u+1]=t[u+1]+(t[u+1-o]>>>1)&255;for(let i=0;i<n;i++)if(l=e+i*a,c=l+i+1,f=t[c-1],u=0,0==f)for(;u<a;u++)t[l+u]=t[c+u];else if(1==f){for(;u<o;u++)t[l+u]=t[c+u];for(;u<a;u++)t[l+u]=t[c+u]+t[l+u-o]}else if(2==f)for(;u<a;u++)t[l+u]=t[c+u]+t[l+u-a];else if(3==f){for(;u<o;u++)t[l+u]=t[c+u]+(t[l+u-a]>>>1);for(;u<a;u++)t[l+u]=t[c+u]+(t[l+u-a]+t[l+u-o]>>>1)}else{for(;u<o;u++)t[l+u]=t[c+u]+h(0,t[l+u-a],0);for(;u<a;u++)t[l+u]=t[c+u]+h(t[l+u-o],t[l+u-a],t[l+u-o-a])}return t}function h(t,i,e){const s=t+i-e,n=s-t,r=s-i,o=s-e;return n*n<=r*r&&n*n<=o*o?t:r*r<=o*o?i:e}function a(i,e,s){s.width=t.readUint(i,e),e+=4,s.height=t.readUint(i,e),e+=4,s.depth=i[e],e++,s.ctype=i[e],e++,s.compress=i[e],e++,s.filter=i[e],e++,s.interlace=i[e],e++}function l(t,i,e,s,n,r,o,h,a){const l=Math.min(i,n),c=Math.min(e,r);let f=0,u=0;for(let e=0;e<c;e++)for(let r=0;r<l;r++)if(o>=0&&h>=0?(f=e*i+r<<2,u=(h+e)*n+o+r<<2):(f=(-h+e)*i-o+r<<2,u=e*n+r<<2),0==a)s[u]=t[f],s[u+1]=t[f+1],s[u+2]=t[f+2],s[u+3]=t[f+3];else if(1==a){var d=t[f+3]*(1/255),v=t[f]*d,b=t[f+1]*d,p=t[f+2]*d,g=s[u+3]*(1/255),w=s[u]*g,y=s[u+1]*g,k=s[u+2]*g;const i=1-d,e=d+g*i,n=0==e?0:1/e;s[u+3]=255*e,s[u+0]=(v+w*i)*n,s[u+1]=(b+y*i)*n,s[u+2]=(p+k*i)*n}else if(2==a){d=t[f+3],v=t[f],b=t[f+1],p=t[f+2],g=s[u+3],w=s[u],y=s[u+1],k=s[u+2];d==g&&v==w&&b==y&&p==k?(s[u]=0,s[u+1]=0,s[u+2]=0,s[u+3]=0):(s[u]=v,s[u+1]=b,s[u+2]=p,s[u+3]=d)}else if(3==a){d=t[f+3],v=t[f],b=t[f+1],p=t[f+2],g=s[u+3],w=s[u],y=s[u+1],k=s[u+2];if(d==g&&v==w&&b==y&&p==k)continue;if(d<220&&g>20)return false}return true}return{decode:function i(r){const o=new Uint8Array(r);let h=8;const l=t,c=l.readUshort,f=l.readUint,u={tabs:{},frames:[]},d=new Uint8Array(o.length);let v,b=0,p=0;const g=[137,80,78,71,13,10,26,10];for(var w=0;w<8;w++)if(o[w]!=g[w])throw"The input is not a PNG file!";for(;h<o.length;){const t=l.readUint(o,h);h+=4;const i=l.readASCII(o,h,4);if(h+=4,"IHDR"==i)a(o,h,u);else if("iCCP"==i){for(var y=h;0!=o[y];)y++;l.readASCII(o,h,y-h);const e=o.slice(y+2,h+t);let r=null;try{r=s(e)}catch(t){r=n(e)}u.tabs[i]=r}else if("CgBI"==i)u.tabs[i]=o.slice(h,h+4);else if("IDAT"==i){for(w=0;w<t;w++)d[b+w]=o[h+w];b+=t}else if("acTL"==i)u.tabs[i]={num_frames:f(o,h),num_plays:f(o,h+4)},v=new Uint8Array(o.length);else if("fcTL"==i){if(0!=p)(M=u.frames[u.frames.length-1]).data=e(u,v.slice(0,p),M.rect.width,M.rect.height),p=0;const t={x:f(o,h+12),y:f(o,h+16),width:f(o,h+4),height:f(o,h+8)};let i=c(o,h+22);i=c(o,h+20)/(0==i?100:i);const s={rect:t,delay:Math.round(1e3*i),dispose:o[h+24],blend:o[h+25]};u.frames.push(s)}else if("fdAT"==i){for(w=0;w<t-4;w++)v[p+w]=o[h+w+4];p+=t-4}else if("pHYs"==i)u.tabs[i]=[l.readUint(o,h),l.readUint(o,h+4),o[h+8]];else if("cHRM"==i){u.tabs[i]=[];for(w=0;w<8;w++)u.tabs[i].push(l.readUint(o,h+4*w))}else if("tEXt"==i||"zTXt"==i){null==u.tabs[i]&&(u.tabs[i]={});var k=l.nextZero(o,h),x=l.readASCII(o,h,k-h),m=h+t-k-1;if("tEXt"==i)z=l.readASCII(o,k+1,m);else{var A=s(o.slice(k+2,k+2+m));z=l.readUTF8(A,0,A.length)}u.tabs[i][x]=z}else if("iTXt"==i){null==u.tabs[i]&&(u.tabs[i]={});k=0,y=h;k=l.nextZero(o,y);x=l.readASCII(o,y,k-y);const e=o[y=k+1];var z;y+=2,k=l.nextZero(o,y),l.readASCII(o,y,k-y),y=k+1,k=l.nextZero(o,y),l.readUTF8(o,y,k-y);m=t-((y=k+1)-h);if(0==e)z=l.readUTF8(o,y,m);else{A=s(o.slice(y,y+m));z=l.readUTF8(A,0,A.length)}u.tabs[i][x]=z}else if("PLTE"==i)u.tabs[i]=l.readBytes(o,h,t);else if("hIST"==i){const t=u.tabs.PLTE.length/3;u.tabs[i]=[];for(w=0;w<t;w++)u.tabs[i].push(c(o,h+2*w))}else if("tRNS"==i)3==u.ctype?u.tabs[i]=l.readBytes(o,h,t):0==u.ctype?u.tabs[i]=c(o,h):2==u.ctype&&(u.tabs[i]=[c(o,h),c(o,h+2),c(o,h+4)]);else if("gAMA"==i)u.tabs[i]=l.readUint(o,h)/1e5;else if("sRGB"==i)u.tabs[i]=o[h];else if("bKGD"==i)0==u.ctype||4==u.ctype?u.tabs[i]=[c(o,h)]:2==u.ctype||6==u.ctype?u.tabs[i]=[c(o,h),c(o,h+2),c(o,h+4)]:3==u.ctype&&(u.tabs[i]=o[h]);else if("IEND"==i)break;h+=t,l.readUint(o,h),h+=4}var M;return 0!=p&&((M=u.frames[u.frames.length-1]).data=e(u,v.slice(0,p),M.rect.width,M.rect.height)),u.data=e(u,d,u.width,u.height),delete u.compress,delete u.interlace,delete u.filter,u},toRGBA8:function t(e){const s=e.width,n=e.height;if(null==e.tabs.acTL)return[i(e.data,s,n,e).buffer];const r=[];null==e.frames[0].data&&(e.frames[0].data=e.data);const o=s*n*4,h=new Uint8Array(o),a=new Uint8Array(o),c=new Uint8Array(o);for(let t=0;t<e.frames.length;t++){const u=e.frames[t],d=u.rect.x,v=u.rect.y,b=u.rect.width,p=u.rect.height,g=i(u.data,b,p,e);if(0!=t)for(var f=0;f<o;f++)c[f]=h[f];if(0==u.blend?l(g,b,p,h,s,n,d,v,0):1==u.blend&&l(g,b,p,h,s,n,d,v,1),r.push(h.buffer.slice(0)),0==u.dispose);else if(1==u.dispose)l(a,b,p,h,s,n,d,v,0);else if(2==u.dispose)for(f=0;f<o;f++)h[f]=c[f]}return r},_paeth:h,_copyTile:l,_bin:t}}();!function(){const{_copyTile:t}=qn,{_bin:i}=qn,e=qn._paeth;var s={table:function(){const t=new Uint32Array(256);for(let i=0;i<256;i++){let e=i;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;t[i]=e}return t}(),update(t,i,e,n){for(let r=0;r<n;r++)t=s.table[255&(t^i[e+r])]^t>>>8;return t},crc:(t,i,e)=>4294967295^s.update(4294967295,t,i,e)};function n(t,i,e,s){i[e]+=t[0]*s>>4,i[e+1]+=t[1]*s>>4,i[e+2]+=t[2]*s>>4,i[e+3]+=t[3]*s>>4}function r(t){return Math.max(0,Math.min(255,t))}function o(t,i){const e=t[0]-i[0],s=t[1]-i[1],n=t[2]-i[2],r=t[3]-i[3];return e*e+s*s+n*n+r*r}function h(t,i,e,s,h,a,l){null==l&&(l=1);const c=s.length,f=[];for(var u=0;u<c;u++){const t=s[u];f.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(u=0;u<c;u++){let t=4294967295;for(var d=0,v=0;v<c;v++){var b=o(f[u],f[v]);v!=u&&b<t&&(t=b,d=v)}}const p=new Uint32Array(h.buffer),g=new Int16Array(i*e*4),w=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(u=0;u<w.length;u++)w[u]=255*((w[u]+.5)/16-.5);for(let h=0;h<e;h++)for(let k=0;k<i;k++){var y;u=4*(h*i+k);if(2!=l)y=[r(t[u]+g[u]),r(t[u+1]+g[u+1]),r(t[u+2]+g[u+2]),r(t[u+3]+g[u+3])];else{b=w[4*(3&h)+(3&k)];y=[r(t[u]+b),r(t[u+1]+b),r(t[u+2]+b),r(t[u+3]+b)]}d=0;let x=16777215;for(v=0;v<c;v++){const t=o(y,f[v]);t<x&&(x=t,d=v)}const m=f[d],A=[y[0]-m[0],y[1]-m[1],y[2]-m[2],y[3]-m[3]];1==l&&(k!=i-1&&n(A,g,u+4,7),h!=e-1&&(0!=k&&n(A,g,u+4*i-4,3),n(A,g,u+4*i,5),k!=i-1&&n(A,g,u+4*i+4,1))),a[u>>2]=d,p[u>>2]=s[d]}}function a(t,e,n,r,o){null==o&&(o={});const{crc:h}=s,a=i.writeUint,l=i.writeUshort,c=i.writeASCII;let f=8;const u=t.frames.length>1;let d,v=false,b=33+(u?20:0);if(null!=o.sRGB&&(b+=13),null!=o.pHYs&&(b+=21),null!=o.iCCP&&(d=pako.deflate(o.iCCP),b+=21+d.length+4),3==t.ctype){for(var p=t.plte.length,g=0;g<p;g++)t.plte[g]>>>24!=255&&(v=true);b+=8+3*p+4+(v?8+1*p+4:0)}for(var w=0;w<t.frames.length;w++){u&&(b+=38),b+=(m=t.frames[w]).cimg.length+12,0!=w&&(b+=4)}b+=12;const y=new Uint8Array(b),k=[137,80,78,71,13,10,26,10];for(g=0;g<8;g++)y[g]=k[g];if(a(y,f,13),f+=4,c(y,f,"IHDR"),f+=4,a(y,f,e),f+=4,a(y,f,n),f+=4,y[f]=t.depth,f++,y[f]=t.ctype,f++,y[f]=0,f++,y[f]=0,f++,y[f]=0,f++,a(y,f,h(y,f-17,17)),f+=4,null!=o.sRGB&&(a(y,f,1),f+=4,c(y,f,"sRGB"),f+=4,y[f]=o.sRGB,f++,a(y,f,h(y,f-5,5)),f+=4),null!=o.iCCP){const t=13+d.length;a(y,f,t),f+=4,c(y,f,"iCCP"),f+=4,c(y,f,"ICC profile"),f+=11,f+=2,y.set(d,f),f+=d.length,a(y,f,h(y,f-(t+4),t+4)),f+=4}if(null!=o.pHYs&&(a(y,f,9),f+=4,c(y,f,"pHYs"),f+=4,a(y,f,o.pHYs[0]),f+=4,a(y,f,o.pHYs[1]),f+=4,y[f]=o.pHYs[2],f++,a(y,f,h(y,f-13,13)),f+=4),u&&(a(y,f,8),f+=4,c(y,f,"acTL"),f+=4,a(y,f,t.frames.length),f+=4,a(y,f,null!=o.loop?o.loop:0),f+=4,a(y,f,h(y,f-12,12)),f+=4),3==t.ctype){a(y,f,3*(p=t.plte.length)),f+=4,c(y,f,"PLTE"),f+=4;for(g=0;g<p;g++){const i=3*g,e=t.plte[g],s=255&e,n=e>>>8&255,r=e>>>16&255;y[f+i+0]=s,y[f+i+1]=n,y[f+i+2]=r}if(f+=3*p,a(y,f,h(y,f-3*p-4,3*p+4)),f+=4,v){a(y,f,p),f+=4,c(y,f,"tRNS"),f+=4;for(g=0;g<p;g++)y[f+g]=t.plte[g]>>>24&255;f+=p,a(y,f,h(y,f-p-4,p+4)),f+=4}}let x=0;for(w=0;w<t.frames.length;w++){var m=t.frames[w];u&&(a(y,f,26),f+=4,c(y,f,"fcTL"),f+=4,a(y,f,x++),f+=4,a(y,f,m.rect.width),f+=4,a(y,f,m.rect.height),f+=4,a(y,f,m.rect.x),f+=4,a(y,f,m.rect.y),f+=4,l(y,f,r[w]),f+=2,l(y,f,1e3),f+=2,y[f]=m.dispose,f++,y[f]=m.blend,f++,a(y,f,h(y,f-30,30)),f+=4);const i=m.cimg;a(y,f,(p=i.length)+(0==w?0:4)),f+=4;const e=f;c(y,f,0==w?"IDAT":"fdAT"),f+=4,0!=w&&(a(y,f,x++),f+=4),y.set(i,f),f+=p,a(y,f,h(y,e,f-e)),f+=4}return a(y,f,0),f+=4,c(y,f,"IEND"),f+=4,a(y,f,h(y,f-4,4)),f+=4,y.buffer}function l(t,i,e){for(let s=0;s<t.frames.length;s++){const n=t.frames[s];const r=n.rect.height,o=new Uint8Array(r*n.bpl+r);n.cimg=d(n.img,r,n.bpp,n.bpl,o,i,e)}}function c(i,e,s,n,r){const o=r[0],a=r[1],l=r[2],c=r[3],d=r[4],v=r[5];let p=6,g=8,w=255;for(var y=0;y<i.length;y++){const t=new Uint8Array(i[y]);for(var k=t.length,x=0;x<k;x+=4)w&=t[x+3]}const m=255!=w,A=function i(e,s,n,r,o,h){const a=[];for(var l=0;l<e.length;l++){const i=new Uint8Array(e[l]),f=new Uint32Array(i.buffer);var c;let v=0,p=0,g=s,w=n,y=r?1:0;if(0!=l){const k=h||r||1==l||0!=a[l-2].dispose?1:2;let x=0,m=1e9;for(let t=0;t<k;t++){var d=new Uint8Array(e[l-1-t]);const i=new Uint32Array(e[l-1-t]);let r=s,h=n,a=-1,c=-1;for(let t=0;t<n;t++)for(let e=0;e<s;e++){f[b=t*s+e]!=i[b]&&(e<r&&(r=e),e>a&&(a=e),t<h&&(h=t),t>c&&(c=t))}-1==a&&(r=h=a=c=0),o&&(1==(1&r)&&r--,1==(1&h)&&h--);const u=(a-r+1)*(c-h+1);u<m&&(m=u,x=t,v=r,p=h,g=a-r+1,w=c-h+1)}d=new Uint8Array(e[l-1-x]);1==x&&(a[l-1].dispose=2),c=new Uint8Array(g*w*4),t(d,s,n,c,g,w,-v,-p,0),y=t(i,s,n,c,g,w,-v,-p,3)?1:0,1==y?u(i,s,n,c,{x:v,y:p,width:g,height:w}):t(i,s,n,c,g,w,-v,-p,0)}else c=i.slice(0);a.push({rect:{x:v,y:p,width:g,height:w},img:c,blend:y,dispose:0})}if(r)for(l=0;l<a.length;l++){if(1==(p=a[l]).blend)continue;const t=p.rect,i=a[l-1].rect,r=Math.min(t.x,i.x),h=Math.min(t.y,i.y),c={x:r,y:h,width:Math.max(t.x+t.width,i.x+i.width)-r,height:Math.max(t.y+t.height,i.y+i.height)-h};a[l-1].dispose=1,l-1!=0&&f(e,s,n,a,l-1,c,o),f(e,s,n,a,l,c,o)}let v=0;if(1!=e.length)for(var b=0;b<a.length;b++){var p;v+=(p=a[b]).rect.width*p.rect.height}return a}(i,e,s,o,a,l),z={},M=[],j=[];if(0!=n){const t=[];for(x=0;x<A.length;x++)t.push(A[x].img.buffer);const i=function t(i){let e=0;for(var s=0;s<i.length;s++)e+=i[s].byteLength;const n=new Uint8Array(e);let r=0;for(s=0;s<i.length;s++){const t=new Uint8Array(i[s]),e=t.length;for(let i=0;i<e;i+=4){let e=t[i],s=t[i+1],o=t[i+2];const h=t[i+3];0==h&&(e=s=o=0),n[r+i]=e,n[r+i+1]=s,n[r+i+2]=o,n[r+i+3]=h}r+=e}return n.buffer}(t),e=b(i,n);for(x=0;x<e.plte.length;x++)M.push(e.plte[x].est.rgba);let s=0;for(x=0;x<A.length;x++){const t=(C=A[x]).img.length;var T=new Uint8Array(e.inds.buffer,s>>2,t>>2);j.push(T);const i=new Uint8Array(e.abuf,s,t);v&&h(C.img,C.rect.width,C.rect.height,M,i,T),C.img.set(i),s+=t}}else for(y=0;y<A.length;y++){var C=A[y];const t=new Uint32Array(C.img.buffer);var S=C.rect.width;k=t.length,T=new Uint8Array(k);j.push(T);for(x=0;x<k;x++){const i=t[x];if(0!=x&&i==t[x-1])T[x]=T[x-1];else if(x>S&&i==t[x-S])T[x]=T[x-S];else{let t=z[i];if(null==t&&(z[i]=t=M.length,M.push(i),M.length>=300))break;T[x]=t}}}const E=M.length;E<=256&&0==d&&(g=E<=2?1:E<=4?2:E<=16?4:8,g=Math.max(g,c));for(y=0;y<A.length;y++){(C=A[y]).rect.x;S=C.rect.width;const t=C.rect.height;let i=C.img;let e=4*S,s=4;if(E<=256&&0==d){e=Math.ceil(g*S/8);var F=new Uint8Array(e*t);const n=j[y];for(let i=0;i<t;i++){x=i*e;const t=i*S;if(8==g)for(var I=0;I<S;I++)F[x+I]=n[t+I];else if(4==g)for(I=0;I<S;I++)F[x+(I>>1)]|=n[t+I]<<4-4*(1&I);else if(2==g)for(I=0;I<S;I++)F[x+(I>>2)]|=n[t+I]<<6-2*(3&I);else if(1==g)for(I=0;I<S;I++)F[x+(I>>3)]|=n[t+I]<<7-1*(7&I)}i=F,p=3,s=1}else if(0==m&&1==A.length){F=new Uint8Array(S*t*3);const n=S*t;for(x=0;x<n;x++){const t=3*x,e=4*x;F[t]=i[e],F[t+1]=i[e+1],F[t+2]=i[e+2]}i=F,p=2,s=3,e=3*S}C.img=i,C.bpl=e,C.bpp=s}return{ctype:p,depth:g,plte:M,frames:A}}function f(i,e,s,n,r,o,h){const a=Uint8Array,l=Uint32Array,c=new a(i[r-1]),f=new l(i[r-1]),d=r+1<i.length?new a(i[r+1]):null,v=new a(i[r]),b=new l(v.buffer);let p=e,g=s,w=-1,y=-1;for(let t=0;t<o.height;t++)for(let i=0;i<o.width;i++){const s=o.x+i,h=o.y+t,a=h*e+s,l=b[a];0==l||0==n[r-1].dispose&&f[a]==l&&(null==d||0!=d[4*a+3])||(s<p&&(p=s),s>w&&(w=s),h<g&&(g=h),h>y&&(y=h))}-1==w&&(p=g=w=y=0),h&&(1==(1&p)&&p--,1==(1&g)&&g--),o={x:p,y:g,width:w-p+1,height:y-g+1};const k=n[r];k.rect=o,k.blend=1,k.img=new Uint8Array(o.width*o.height*4),0==n[r-1].dispose?(t(c,e,s,k.img,o.width,o.height,-o.x,-o.y,0),u(v,e,s,k.img,o)):t(v,e,s,k.img,o.width,o.height,-o.x,-o.y,0)}function u(i,e,s,n,r){t(i,e,s,n,r.width,r.height,-r.x,-r.y,2)}function d(t,i,e,s,n,r,o){const h=[];let a,l=[0,1,2,3,4];-1!=r?l=[r]:(i*s>5e5||1==e)&&(l=[0]),o&&(a={level:0});const c=Gn;for(var f=0;f<l.length;f++){for(let r=0;r<i;r++)v(n,t,r,s,e,l[f]);h.push(c.deflate(n,a))}let u,d=1e9;for(f=0;f<h.length;f++)h[f].length<d&&(u=f,d=h[f].length);return h[u]}function v(t,i,s,n,r,o){const h=s*n;let a=h+s;if(t[a]=o,a++,0==o)if(n<500)for(var l=0;l<n;l++)t[a+l]=i[h+l];else t.set(new Uint8Array(i.buffer,h,n),a);else if(1==o){for(l=0;l<r;l++)t[a+l]=i[h+l];for(l=r;l<n;l++)t[a+l]=i[h+l]-i[h+l-r]+256&255}else if(0==s){for(l=0;l<r;l++)t[a+l]=i[h+l];if(2==o)for(l=r;l<n;l++)t[a+l]=i[h+l];if(3==o)for(l=r;l<n;l++)t[a+l]=i[h+l]-(i[h+l-r]>>1)+256&255;if(4==o)for(l=r;l<n;l++)t[a+l]=i[h+l]-e(i[h+l-r],0,0)+256&255}else{if(2==o)for(l=0;l<n;l++)t[a+l]=i[h+l]+256-i[h+l-n]&255;if(3==o){for(l=0;l<r;l++)t[a+l]=i[h+l]+256-(i[h+l-n]>>1)&255;for(l=r;l<n;l++)t[a+l]=i[h+l]+256-(i[h+l-n]+i[h+l-r]>>1)&255}if(4==o){for(l=0;l<r;l++)t[a+l]=i[h+l]+256-e(0,i[h+l-n],0)&255;for(l=r;l<n;l++)t[a+l]=i[h+l]+256-e(i[h+l-r],i[h+l-n],i[h+l-r-n])&255}}}function b(t,i){const e=new Uint8Array(t),s=e.slice(0),n=new Uint32Array(s.buffer),r=p(s,i),o=r[0],h=r[1],a=e.length,l=new Uint8Array(a>>2);let c;if(e.length<2e7)for(var f=0;f<a;f+=4){c=g(o,u=e[f]*(1/255),d=e[f+1]*(1/255),v=e[f+2]*(1/255),b=e[f+3]*(1/255)),l[f>>2]=c.ind,n[f>>2]=c.est.rgba}else for(f=0;f<a;f+=4){var u=e[f]*(1/255),d=e[f+1]*(1/255),v=e[f+2]*(1/255),b=e[f+3]*(1/255);for(c=o;c.left;)c=w(c.est,u,d,v,b)<=0?c.left:c.right;l[f>>2]=c.ind,n[f>>2]=c.est.rgba}return{abuf:s.buffer,inds:l,plte:h}}function p(t,i,e){null==e&&(e=1e-4);const s=new Uint32Array(t.buffer),n={i0:0,i1:t.length,bst:null,est:null,tdst:0,left:null,right:null};n.bst=x(t,n.i0,n.i1),n.est=m(n.bst);const r=[n];for(;r.length<i;){let i=0,n=0;for(var o=0;o<r.length;o++)r[o].est.L>i&&(i=r[o].est.L,n=o);if(i<e)break;const h=r[n],a=y(t,s,h.i0,h.i1,h.est.e,h.est.eMq255);if(h.i0>=a||h.i1<=a){h.est.L=0;continue}const l={i0:h.i0,i1:a,bst:null,est:null,tdst:0,left:null,right:null};l.bst=x(t,l.i0,l.i1),l.est=m(l.bst);const c={i0:a,i1:h.i1,bst:null,est:null,tdst:0,left:null,right:null};c.bst={R:[],m:[],N:h.bst.N-l.bst.N};for(o=0;o<16;o++)c.bst.R[o]=h.bst.R[o]-l.bst.R[o];for(o=0;o<4;o++)c.bst.m[o]=h.bst.m[o]-l.bst.m[o];c.est=m(c.bst),h.left=l,h.right=c,r[n]=l,r.push(c)}r.sort(((t,i)=>i.bst.N-t.bst.N));for(o=0;o<r.length;o++)r[o].ind=o;return[n,r]}function g(t,i,e,s,n){if(null==t.left)return t.tdst=function t(i,e,s,n,r){const o=e-i[0],h=s-i[1],a=n-i[2],l=r-i[3];return o*o+h*h+a*a+l*l}(t.est.q,i,e,s,n),t;const r=w(t.est,i,e,s,n);let o=t.left,h=t.right;r>0&&(o=t.right,h=t.left);const a=g(o,i,e,s,n);if(a.tdst<=r*r)return a;const l=g(h,i,e,s,n);return l.tdst<a.tdst?l:a}function w(t,i,e,s,n){const{e:r}=t;return r[0]*i+r[1]*e+r[2]*s+r[3]*n-t.eMq}function y(t,i,e,s,n,r){for(s-=4;e<s;){for(;k(t,e,n)<=r;)e+=4;for(;k(t,s,n)>r;)s-=4;if(e>=s)break;const o=i[e>>2];i[e>>2]=i[s>>2],i[s>>2]=o,e+=4,s-=4}for(;k(t,e,n)>r;)e-=4;return e+4}function k(t,i,e){return t[i]*e[0]+t[i+1]*e[1]+t[i+2]*e[2]+t[i+3]*e[3]}function x(t,i,e){const s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=[0,0,0,0],r=e-i>>2;for(let r=i;r<e;r+=4){const i=t[r]*(1/255),e=t[r+1]*(1/255),o=t[r+2]*(1/255),h=t[r+3]*(1/255);n[0]+=i,n[1]+=e,n[2]+=o,n[3]+=h,s[0]+=i*i,s[1]+=i*e,s[2]+=i*o,s[3]+=i*h,s[5]+=e*e,s[6]+=e*o,s[7]+=e*h,s[10]+=o*o,s[11]+=o*h,s[15]+=h*h}return s[4]=s[1],s[8]=s[2],s[9]=s[6],s[12]=s[3],s[13]=s[7],s[14]=s[11],{R:s,m:n,N:r}}function m(t){const{R:i}=t,{m:e}=t,{N:s}=t,n=e[0],r=e[1],o=e[2],h=e[3],a=0==s?0:1/s,l=[i[0]-n*n*a,i[1]-n*r*a,i[2]-n*o*a,i[3]-n*h*a,i[4]-r*n*a,i[5]-r*r*a,i[6]-r*o*a,i[7]-r*h*a,i[8]-o*n*a,i[9]-o*r*a,i[10]-o*o*a,i[11]-o*h*a,i[12]-h*n*a,i[13]-h*r*a,i[14]-h*o*a,i[15]-h*h*a],c=l,f=A;let u=[Math.random(),Math.random(),Math.random(),Math.random()],d=0,v=0;if(0!=s)for(let t=0;t<16&&(u=f.multVec(c,u),v=Math.sqrt(f.dot(u,u)),u=f.sml(1/v,u),!(0!=t&&Math.abs(v-d)<1e-9));t++)d=v;const b=[n*a,r*a,o*a,h*a];return{Cov:l,q:b,e:u,L:d,eMq255:f.dot(f.sml(255,b),u),eMq:f.dot(u,b),rgba:(Math.round(255*b[3])<<24|Math.round(255*b[2])<<16|Math.round(255*b[1])<<8|Math.round(255*b[0])<<0)>>>0}}var A={multVec:(t,i)=>[t[0]*i[0]+t[1]*i[1]+t[2]*i[2]+t[3]*i[3],t[4]*i[0]+t[5]*i[1]+t[6]*i[2]+t[7]*i[3],t[8]*i[0]+t[9]*i[1]+t[10]*i[2]+t[11]*i[3],t[12]*i[0]+t[13]*i[1]+t[14]*i[2]+t[15]*i[3]],dot:(t,i)=>t[0]*i[0]+t[1]*i[1]+t[2]*i[2]+t[3]*i[3],sml:(t,i)=>[t*i[0],t*i[1],t*i[2],t*i[3]]};qn.encode=function t(i,e,s,n,r,o,h){null==n&&(n=0),null==h&&(h=false);const f=c(i,e,s,n,[false,false,false,0,h,false]);return l(f,-1),a(f,e,s,r,o)},qn.encodeLL=function t(i,e,s,n,r,o,h,c){const f={ctype:0+(1==n?0:2)+(0==r?0:4),depth:o,frames:[]},u=(n+r)*o,d=u*e;for(let t=0;t<i.length;t++)f.frames.push({rect:{x:0,y:0,width:e,height:s},img:new Uint8Array(i[t]),blend:0,dispose:1,bpp:Math.ceil(u/8),bpl:Math.ceil(d/8)});return l(f,0,true),a(f,e,s,h,c)},qn.encode.compress=c,qn.encode.dither=h,qn.quantize=b,qn.quantize.getKDtree=p,qn.quantize.getNearest=g}();const Zn={toArrayBuffer(t,i){const e=t.width,s=t.height,n=e<<2,r=t.getContext("2d").getImageData(0,0,e,s),o=new Uint32Array(r.data.buffer),h=(32*e+31)/32<<2,a=h*s,l=122+a,c=new ArrayBuffer(l),f=new DataView(c),u=1<<20;let d,v,b,p,g=u,w=0,y=0,k=0;function x(t){f.setUint16(y,t,true),y+=2}function m(t){f.setUint32(y,t,true),y+=4}function A(t){y+=t}x(19778),m(l),A(4),m(122),m(108),m(e),m(-s>>>0),x(1),x(32),m(3),m(a),m(2835),m(2835),A(8),m(16711680),m(65280),m(255),m(4278190080),m(1466527264),function t(){for(;w<s&&g>0;){for(p=122+w*h,d=0;d<n;)g--,v=o[k++],b=v>>>24,f.setUint32(p+d,v<<8|b),d+=4;w++}k<o.length?(g=u,setTimeout(t,Zn._dly)):i(c)}()},toBlob(t,i){this.toArrayBuffer(t,(t=>{i(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var Jn={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},tr={[Jn.CHROME]:16384,[Jn.FIREFOX]:11180,[Jn.DESKTOP_SAFARI]:16384,[Jn.IE]:8192,[Jn.IOS]:4096,[Jn.ETC]:8192};const ir="undefined"!=typeof window,er="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,sr=ir&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),nr=(ir||er)&&(sr&&sr.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),rr=(ir||er)&&(sr&&sr.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function or(t,i,e=Date.now()){return new Promise((s=>{const n=t.split(","),r=n[0].match(/:(.*?);/)[1],o=globalThis.atob(n[1]);let h=o.length;const a=new Uint8Array(h);for(;h--;)a[h]=o.charCodeAt(h);const l=new Blob([a],{type:r});l.name=i,l.lastModified=e,s(l)}))}function hr(t){return new Promise(((i,e)=>{const s=new rr;s.onload=()=>i(s.result),s.onerror=t=>e(t),s.readAsDataURL(t)}))}function ar(t){return new Promise(((i,e)=>{const s=new Image;s.onload=()=>i(s),s.onerror=t=>e(t),s.src=t}))}function lr(){if(void 0!==lr.cachedResult)return lr.cachedResult;let t=Jn.ETC;const{userAgent:i}=navigator;return/Chrom(e|ium)/i.test(i)?t=Jn.CHROME:/iP(ad|od|hone)/i.test(i)&&/WebKit/i.test(i)?t=Jn.IOS:/Safari/i.test(i)?t=Jn.DESKTOP_SAFARI:/Firefox/i.test(i)?t=Jn.FIREFOX:(/MSIE/i.test(i)||true==!!document.documentMode)&&(t=Jn.IE),lr.cachedResult=t,lr.cachedResult}function cr(t,i){const e=lr(),s=tr[e];let n=t,r=i,o=n*r;const h=n>r?r/n:n/r;for(;o>s*s;){const t=(s+n)/2,i=(s+r)/2;t<i?(r=i,n=i*h):(r=t*h,n=t),o=n*r}return{width:n,height:r}}function fr(t,i){let e,s;try{if(e=new OffscreenCanvas(t,i),s=e.getContext("2d"),null===s)throw new Error("getContext of OffscreenCanvas returns null")}catch(t){e=document.createElement("canvas"),s=e.getContext("2d")}return e.width=t,e.height=i,[e,s]}function ur(t,i){const{width:e,height:s}=cr(t.width,t.height),[n,r]=fr(e,s);return i&&/jpe?g/.test(i)&&(r.fillStyle="white",r.fillRect(0,0,n.width,n.height)),r.drawImage(t,0,0,n.width,n.height),n}function dr(){return void 0!==dr.cachedResult||(dr.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),dr.cachedResult}function vr(t,i={}){return new Promise((function(e,s){let n,r;var o=function(){try{return r=ur(n,i.fileType||t.type),e([n,r])}catch(t){return s(t)}},h=function(i){try{var e=function(t){try{throw t}catch(t){return s(t)}};try{let i;return hr(t).then((function(t){try{return i=t,ar(i).then((function(t){try{return n=t,function(){try{return o()}catch(t){return s(t)}}()}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){e(t)}}catch(t){return s(t)}};try{if(dr()||[Jn.DESKTOP_SAFARI,Jn.MOBILE_SAFARI].includes(lr()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return n=t,o()}catch(t){return h()}}),h)}catch(t){h()}}))}function br(t,i,e,s,n=1){return new Promise((function(r,o){let h;if("image/png"===i){let l,c,f;return l=t.getContext("2d"),({data:c}=l.getImageData(0,0,t.width,t.height)),f=qn.encode([c.buffer],t.width,t.height,4096*n),h=new Blob([f],{type:i}),h.name=e,h.lastModified=s,a.call(this)}{if("image/bmp"===i)return new Promise((i=>Zn.toBlob(t,i))).then(function(t){try{return h=t,h.name=e,h.lastModified=s,u.call(this)}catch(t){return o(t)}}.bind(this),o);{if("function"==typeof OffscreenCanvas&&t instanceof OffscreenCanvas)return t.convertToBlob({type:i,quality:n}).then(function(t){try{return h=t,h.name=e,h.lastModified=s,d.call(this)}catch(t){return o(t)}}.bind(this),o);{let v;return v=t.toDataURL(i,n),or(v,e,s).then(function(t){try{return h=t,d.call(this)}catch(t){return o(t)}}.bind(this),o)}function d(){return u.call(this)}}function u(){return a.call(this)}}function a(){return r(h)}}))}function pr(t){t.width=0,t.height=0}function gr(){return new Promise((function(t,i){let e,s,n,r;return void 0!==gr.cachedResult?t(gr.cachedResult):or("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return e=o,vr(e).then((function(o){try{return s=o[1],br(s,e.type,e.name,e.lastModified).then((function(e){try{return n=e,pr(s),vr(n).then((function(e){try{return r=e[0],gr.cachedResult=1===r.width&&2===r.height,t(gr.cachedResult)}catch(t){return i(t)}}),i)}catch(t){return i(t)}}),i)}catch(t){return i(t)}}),i)}catch(t){return i(t)}}),i)}))}function wr(t){return new Promise(((i,e)=>{const s=new rr;s.onload=t=>{const e=new DataView(t.target.result);if(65496!=e.getUint16(0,false))return i(-2);const s=e.byteLength;let n=2;for(;n<s;){if(e.getUint16(n+2,false)<=8)return i(-1);const t=e.getUint16(n,false);if(n+=2,65505==t){if(1165519206!=e.getUint32(n+=2,false))return i(-1);const t=18761==e.getUint16(n+=6,false);n+=e.getUint32(n+4,t);const s=e.getUint16(n,t);n+=2;for(let r=0;r<s;r++)if(274==e.getUint16(n+12*r,t))return i(e.getUint16(n+12*r+8,t))}else{if(65280!=(65280&t))break;n+=e.getUint16(n,false)}}return i(-1)},s.onerror=t=>e(t),s.readAsArrayBuffer(t)}))}function yr(t,i){const{width:e}=t,{height:s}=t,{maxWidthOrHeight:n}=i;let r,o=t;return isFinite(n)&&(e>n||s>n)&&([o,r]=fr(e,s),e>s?(o.width=n,o.height=s/e*n):(o.width=e/s*n,o.height=n),r.drawImage(t,0,0,o.width,o.height),pr(t)),o}function kr(t,i){const{width:e}=t,{height:s}=t,[n,r]=fr(e,s);switch(i>4&&i<9?(n.width=s,n.height=e):(n.width=e,n.height=s),i){case 2:r.transform(-1,0,0,1,e,0);break;case 3:r.transform(-1,0,0,-1,e,s);break;case 4:r.transform(1,0,0,-1,0,s);break;case 5:r.transform(0,1,1,0,0,0);break;case 6:r.transform(0,1,-1,0,s,0);break;case 7:r.transform(0,-1,-1,0,s,e);break;case 8:r.transform(0,-1,1,0,0,e)}return r.drawImage(t,0,0,e,s),pr(t),n}function xr(t,i,e=0){return new Promise((function(s,n){let r,o,h,a,l,c,f,u,d,v,b,p,g,w,y,k,x,m,A,z;function M(t=5){if(i.signal&&i.signal.aborted)throw i.signal.reason;r+=t,i.onProgress(Math.min(r,100))}function j(t){if(i.signal&&i.signal.aborted)throw i.signal.reason;r=Math.min(Math.max(t,r),100),i.onProgress(r)}return r=e,o=i.maxIteration||10,h=1024*i.maxSizeMB*1024,M(),vr(t,i).then(function(e){try{return[,a]=e,M(),l=yr(a,i),M(),new Promise((function(e,s){var n;if(!(n=i.exifOrientation))return wr(t).then(function(t){try{return n=t,r.call(this)}catch(t){return s(t)}}.bind(this),s);function r(){return e(n)}return r.call(this)})).then(function(e){try{return c=e,M(),gr().then(function(e){try{return f=e?l:kr(l,c),M(),u=i.initialQuality||1,d=i.fileType||t.type,br(f,d,t.name,t.lastModified,u).then(function(e){try{{if(v=e,M(),b=v.size>h,p=v.size>t.size,!b&&!p)return j(100),s(v);var r;function c(){if(o--&&(y>h||y>g)){let i,e;return i=z?.95*A.width:A.width,e=z?.95*A.height:A.height,[x,m]=fr(i,e),m.drawImage(A,0,0,i,e),u*="image/png"===d?.85:.95,br(x,d,t.name,t.lastModified,u).then((function(t){try{return k=t,pr(A),A=x,y=k.size,j(Math.min(99,Math.floor((w-y)/(w-h)*100))),c}catch(t){return n(t)}}),n)}return[1]}return g=t.size,w=v.size,y=w,A=f,z=!i.alwaysKeepResolution&&b,(r=function(t){for(;t;){if(t.then)return void t.then(r,n);try{if(t.pop){if(t.length)return t.pop()?T.call(this):t;t=c}else t=t.call(this)}catch(t){return n(t)}}}.bind(this))(c);function T(){return pr(A),pr(x),pr(l),pr(f),pr(a),j(100),s(k)}}}catch(C){return n(C)}}.bind(this),n)}catch(t){return n(t)}}.bind(this),n)}catch(t){return n(t)}}.bind(this),n)}catch(t){return n(t)}}.bind(this),n)}))}const mr="\nlet scriptImported = false\nself.addEventListener('message', async (e) => {\n const { file, id, imageCompressionLibUrl, options } = e.data\n options.onProgress = (progress) => self.postMessage({ progress, id })\n try {\n if (!scriptImported) {\n // console.log('[worker] importScripts', imageCompressionLibUrl)\n self.importScripts(imageCompressionLibUrl)\n scriptImported = true\n }\n // console.log('[worker] self', self)\n const compressedFile = await imageCompression(file, options)\n self.postMessage({ file: compressedFile, id })\n } catch (e) {\n // console.error('[worker] error', e)\n self.postMessage({ error: e.message + '\\n' + e.stack, id })\n }\n})\n";let Ar;function zr(t,i){return new Promise(((e,s)=>{Ar||(Ar=function t(i){const e=[];return e.push(i),URL.createObjectURL(new Blob(e))}(mr));const n=new Worker(Ar);n.addEventListener("message",(function t(r){if(i.signal&&i.signal.aborted)n.terminate();else if(void 0===r.data.progress){if(r.data.error)return s(new Error(r.data.error)),void n.terminate();e(r.data.file),n.terminate()}else i.onProgress(r.data.progress)})),n.addEventListener("error",s),i.signal&&i.signal.addEventListener("abort",(()=>{s(i.signal.reason),n.terminate()})),n.postMessage({file:t,imageCompressionLibUrl:i.libURL,options:{...i,onProgress:void 0,signal:void 0}})}))}function Mr(t,i){return new Promise((function(e,s){let n,r,o,h,a,l;if(n={...i},o=0,({onProgress:h}=n),n.maxSizeMB=n.maxSizeMB||Number.POSITIVE_INFINITY,a="boolean"!=typeof n.useWebWorker||n.useWebWorker,delete n.useWebWorker,n.onProgress=t=>{o=t,"function"==typeof h&&h(o)},!(t instanceof Blob||t instanceof nr))return s(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(t.type))return s(new Error("The file given is not an image"));if(l="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!a||"function"!=typeof Worker||l)return xr(t,n).then(function(t){try{return r=t,u.call(this)}catch(t){return s(t)}}.bind(this),s);var c=function(){try{return u.call(this)}catch(t){return s(t)}}.bind(this),f=function(i){try{return xr(t,n).then((function(t){try{return r=t,c()}catch(t){return s(t)}}),s)}catch(t){return s(t)}};try{return n.libURL=n.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",zr(t,n).then((function(t){try{return r=t,c()}catch(t){return f()}}),f)}catch(t){f()}function u(){try{r.name=t.name,r.lastModified=t.lastModified}catch(t){}try{n.preserveExif&&"image/jpeg"===t.type&&(!n.fileType||n.fileType&&n.fileType===t.type)&&(r=Kn(t,r))}catch(t){}return e(r)}}))}Mr.getDataUrlFromFile=hr,Mr.getFilefromDataUrl=or,Mr.loadImage=ar,Mr.drawImageInCanvas=ur,Mr.drawFileInCanvas=vr,Mr.canvasToFile=br,Mr.getExifOrientation=wr,Mr.handleMaxWidthOrHeight=yr,Mr.followExifOrientation=kr,Mr.cleanupCanvasMemory=pr,Mr.isAutoOrientationInBrowser=gr,Mr.approximateBelowMaximumCanvasSizeOfBrowser=cr,Mr.copyExifWithoutOrientation=Kn,Mr.getBrowserName=lr,Mr.version="2.0.2";class jr extends dn{constructor(t){super(t);this.fileInput=null;this.maxWidth=300;this.maxHeight=300;this.maxCompressionSize=300;this.setupFileInput()}onActivate(){this.openFilePicker()}openFilePicker(){this.fileInput.click()}setupFileInput(){this.fileInput=document.createElement("input");this.fileInput.type="file";this.fileInput.accept="image/*";this.fileInput.style.display="none";this.fileInput.addEventListener("change",this.handleFileSelect.bind(this));this.fileInput.addEventListener("cancel",this.handleCancel.bind(this));document.body.appendChild(this.fileInput)}handleFileSelect(t){const i=t.target;if(i.files&&i.files[0]){const t=i.files[0];Mr(t,{maxWidthOrHeight:this.maxCompressionSize}).then((t=>{this.readFile(t)})).catch((t=>{console.error("Error during image compression or processing:",t);this.handleCancel()}))}else{console.info("File selection cancelled by user.");this.handleCancel()}if(i){i.value=""}}readFile(t){const i=new FileReader;i.onload=t=>{var i;const e=new Image;e.src=(i=t.target)===null||i===void 0?void 0:i.result;e.onload=()=>this.processImage(e)};i.readAsDataURL(t)}processImage(t){const{scaledWidth:i,scaledHeight:e}=this.calculateScaledDimensions(t);const s=this.createKritzelImage(t,i,e);this.addImageToStore(s)}calculateScaledDimensions(t){let i=t.width;let e=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const s=this.maxWidth/t.width;const n=this.maxHeight/t.height;const r=Math.min(s,n);i=t.width*r;e=t.height*r}return{scaledWidth:i,scaledHeight:e}}createKritzelImage(t,i,e){const s=new Cn(this._store,t);s.width=i;s.height=e;s.zIndex=this._store.currentZIndex;s.centerInViewport();return s}addImageToStore(t){const i=new Hn(this._store);i.addOrRemove(t);i.selected=true;const e=new k(this._store,this,t);const s=new Rn(this._store,this,i);this._store.history.executeCommand(new Mn(this._store,this,[e,s]));this._store.setState("activeTool",pn.getTool("selection"))}handleCancel(){this._store.setState("activeTool",pn.getTool("selection"))}}const Tr={type:"pen",color:"#000000",size:16,palettes:{pen:["#000000","#ff5252","#ffbc00","#00c853","#0000FF","#d500f9","#fafafa","#a52714","#ee8100","#558b2f","#01579b","#8e24aa","#90a4ae","#ff4081","#ff6e40","#aeea00","#304ffe","#7c4dff","#cfd8dc","#f8bbd0","#ffccbc","#f0f4c3","#9fa8da","#d1c4e9"],highlighter:["#0000006e","#ff52526e","#ffbb006e","#00c8536e","#0000FF6e","#d500f96e","#fafafa6e","#a527146e","#ee81006e","#558b2f6e","#01579b6e","#8e24aa6e","#90a4ae6e","#ff40816e","#ff6e406e","#aeea006e","#304ffe6e","#7c4dff6e","#cfd8dc6e","#f8bbd06e","#ffccbc6e","#f0f4c36e","#9fa8da6e","#d1c4e96e"]}};const Cr={color:"#000000",size:8,fontFamily:"Arial",palette:["#000000","#ff5252","#ffbc00","#00c853","#0000FF","#d500f9","#fafafa","#a52714","#ee8100","#558b2f","#01579b","#8e24aa","#90a4ae","#ff4081","#ff6e40","#aeea00","#304ffe","#7c4dff","#cfd8dc","#f8bbd0","#ffccbc","#f0f4c3","#9fa8da","#d1c4e9"]};const Sr=[{name:"selection",type:"tool",tool:Wn,icon:"cursor"},{name:"brush",type:"tool",tool:vn,isDefault:true,icon:"pen",config:Tr},{name:"eraser",type:"tool",tool:Tn,icon:"eraser"},{name:"text",type:"tool",tool:gn,icon:"type",config:Cr},{name:"image",type:"tool",tool:jr,icon:"image"},{name:"divider",type:"divider"},{name:"config",type:"config"}];const Er="kritzel-editor{display:flex;margin:0;position:relative;overflow:hidden;width:100%;height:100%;align-items:center;justify-content:center;touch-action:manipulation;user-select:none}kritzel-controls{position:absolute;bottom:28px}";const Fr=class{constructor(i){t(this,i);this.controls=Sr;this.customSvgIcons={};this.hideControls=false}handleTouchStart(t){if(t.cancelable){t.preventDefault()}}componentWillLoad(){this.registerCustomSvgIcons()}registerCustomSvgIcons(){for(const[t,i]of Object.entries(this.customSvgIcons)){zn.register(t,i)}}render(){return e(s,{key:"3a2846ec3573702162d669a130420f5b0dca97bd"},e("kritzel-engine",{key:"853d5558e2886c62a3a07109be23145978a0a88f"}),e("kritzel-controls",{key:"eb4d48e6768b4808d3efc43ceb104de72475a4f2",controls:this.controls,style:this.hideControls?{display:"none"}:{display:"flex"}}))}get host(){return n(this)}};Fr.style=Er;class Ir{constructor(t,i){this.initialTouchDistance=0;this.startX=0;this.startY=0;this._store=t;this._store.state.host=i;this._store.state.viewportWidth=i.clientWidth;this._store.state.viewportHeight=i.clientHeight;this._store.state.startX=0;this._store.state.startY=0;this._store.state.translateX=0;this._store.state.translateY=0}handleResize(){this._store.state.viewportWidth=this._store.state.host.clientWidth;this._store.state.viewportHeight=this._store.state.host.clientHeight;this._store.state.hasViewportChanged=true;this._store.rerender()}handleMouseDown(t){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;if(w.isRightClick(t)){this._store.state.isPanning=true;this._store.state.startX=i;this._store.state.startY=e}}handleMouseMove(t){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.cursorX=i;this._store.state.cursorY=e;if(this._store.state.isPanning){this._store.state.translateX-=this._store.state.startX-i;this._store.state.translateY-=this._store.state.startY-e;this._store.state.startX=i;this._store.state.startY=e;this._store.state.hasViewportChanged=true;this._store.state.skipContextMenu=true;this._store.rerender()}}handleMouseUp(t){if(this._store.state.isPanning){this._store.state.isPanning=false;this._store.rerender()}}handleTouchStart(t){this._store.state.touchCount=t.touches.length;if(this._store.state.touchCount===2){this._store.state.currentPath=null;this._store.state.isScaling=true;const i=t.touches[0].clientX-this._store.offsetX;const e=t.touches[0].clientY-this._store.offsetY;const s=t.touches[1].clientX-this._store.offsetX;const n=t.touches[1].clientY-this._store.offsetY;this.initialTouchDistance=Math.sqrt(Math.pow(i-s,2)+Math.pow(e-n,2));this.startX=(i+s)/2;this.startY=(e+n)/2;this._store.rerender()}}handleTouchMove(t){if(this._store.state.touchCount===2){const i=t.touches[0].clientX-this._store.offsetX;const e=t.touches[0].clientY-this._store.offsetY;const s=t.touches[1].clientX-this._store.offsetX;const n=t.touches[1].clientY-this._store.offsetY;const r=Math.sqrt(Math.pow(i-s,2)+Math.pow(e-n,2));const o=(i+s)/2;const h=(e+n)/2;const a=r/this.initialTouchDistance;const l=this._store.state.scale*a;if(l>this._store.state.scaleMax||l<this._store.state.scaleMin){this._store.state.translateX+=o-this.startX;this._store.state.translateY+=h-this.startY}else{const t=(o-this._store.state.translateX)*(a-1);const i=(h-this._store.state.translateY)*(a-1);this._store.state.translateX+=o-this.startX-t;this._store.state.translateY+=h-this.startY-i;this._store.state.scale=l;this.initialTouchDistance=r}this.startX=o;this.startY=h;this._store.state.hasViewportChanged=true;this._store.rerender()}}handleTouchEnd(t){this._store.state.touchCount=0;this._store.state.isScaling=false;this._store.rerender()}handleWheel(t){t.preventDefault();if(t.ctrlKey===true&&w.isMainMouseWheel(t)){this.handleZoom(t)}if(!t.ctrlKey){this.handlePan(t)}}handleZoom(t){const i=this._store.state.host.getBoundingClientRect();this._store.state.cursorX=t.clientX-i.left;this._store.state.cursorY=t.clientY-i.top;const e=t.deltaY>0?-this._store.state.scaleStep*this._store.state.scale:this._store.state.scaleStep*this._store.state.scale;const s=Math.min(this._store.state.scaleMax,Math.max(this._store.state.scaleMin,this._store.state.scale+e));const n=s/this._store.state.scale;const r=(this._store.state.cursorX-this._store.state.translateX)*(n-1);const o=(this._store.state.cursorY-this._store.state.translateY)*(n-1);this._store.state.scale=s;this._store.state.translateX-=r;this._store.state.translateY-=o;this._store.state.hasViewportChanged=true;this._store.rerender()}handlePan(t){const i=.8;this._store.state.translateX-=t.deltaX*i;this._store.state.translateY-=t.deltaY*i;this._store.state.hasViewportChanged=true;this._store.rerender()}}class Ur extends y{constructor(t,i,e){super(t,i);this.previousViewport=e;this.currentViewport={scale:this._store.state.scale,translateX:this._store.state.translateX,translateY:this._store.state.translateY}}execute(){this._store.state.scale=this.currentViewport.scale;this._store.state.translateX=this.currentViewport.translateX;this._store.state.translateY=this.currentViewport.translateY}undo(){this._store.state.scale=this.previousViewport.scale;this._store.state.translateX=this.previousViewport.translateX;this._store.state.translateY=this.previousViewport.translateY}}class Br{constructor(t){this.head=0;this.tail=0;this.size=0;this.capacity=t;this.buffer=new Array(t).fill(null)}add(t){this.buffer[this.head]=t;this.head=(this.head+1)%this.capacity;if(this.size<this.capacity){this.size++}else{this.tail=(this.tail+1)%this.capacity}}pop(){if(this.size===0){return null}this.head=(this.head-1+this.capacity)%this.capacity;const t=this.buffer[this.head];this.buffer[this.head]=null;this.size--;return t}peek(){if(this.size===0){return null}const t=(this.head-1+this.capacity)%this.capacity;return this.buffer[t]}isEmpty(){return this.size===0}clear(){this.buffer.fill(null);this.head=0;this.tail=0;this.size=0}}class Or{constructor(t){this._store=t;this.undoStack=new Br(this._store.state.historyBufferSize);this.redoStack=new Br(this._store.state.historyBufferSize);this.previousViewport={scale:this._store.state.scale,scaleStep:this._store.state.scaleStep,translateX:this._store.state.translateX,translateY:this._store.state.translateY}}executeCommand(t){if(this._store.state.hasViewportChanged){const t=new Ur(this._store,this,this.previousViewport);t.execute();this.undoStack.add(t);if(this.redoStack.isEmpty()===false){this.redoStack.clear()}this._store.state.hasViewportChanged=false;this.previousViewport={scale:this._store.state.scale,scaleStep:this._store.state.scaleStep,translateX:this._store.state.translateX,translateY:this._store.state.translateY}}t.execute();if(this._store.state.debugInfo.logCommands)console.info("add",t);this.undoStack.add(t);if(this.redoStack.isEmpty()===false){this.redoStack.clear()}this._store.rerender()}undo(){if(this._store.state.hasViewportChanged){const t=new Ur(this._store,this,this.previousViewport);t.undo();this._store.state.hasViewportChanged=false;this._store.rerender();return}const t=this.undoStack.pop();if(t){t.undo();if(this._store.state.debugInfo.logCommands)console.info("undo",t);this.redoStack.add(t)}this._store.rerender()}redo(){const t=this.redoStack.pop();if(t){t.execute();if(this._store.state.debugInfo.logCommands)console.info("redo",t);this.undoStack.add(t)}this._store.rerender()}}class $r{constructor(t,i=8){this.objects=[];this.children=null;this.bounds=t;this.capacity=i}insert(t){if(!this.intersects(t.rotatedBoundingBox,this.bounds)){return false}if(this.objects.length<this.capacity&&this.children===null){this.objects.push(t);return true}if(this.children===null){this.subdivide()}for(const i of this.children){if(i.insert(t)){return true}}return false}update(t){const i=this.objects.findIndex((i=>i.id===t.id));if(i!==-1){this.objects[i]=t;return true}if(this.children!==null){for(const i of this.children){if(i.update(t)){return true}}}return false}remove(t){const i=this.objects.findIndex((i=>t(i)));if(i!==-1){this.objects.splice(i,1)}if(this.children!==null){for(const i of this.children){i.remove(t)}}}query(t){const i=[];if(!this.intersects(t,this.bounds)){return i}for(const e of this.objects){if(this.intersects(e.rotatedBoundingBox,t)){i.push(e)}}if(this.children!==null){for(const e of this.children){i.push(...e.query(t))}}return i}filter(t){const i=this.objects.filter((i=>t(i)));if(this.children!==null){for(const e of this.children){i.push(...e.filter(t))}}return i}allObjects(){const t=[...this.objects];if(this.children!==null){for(const i of this.children){t.push(...i.allObjects())}}return t}subdivide(){const{x:t,y:i,z:e,width:s,height:n,depth:r}=this.bounds;const o=s/2;const h=n/2;const a=r/2;this.children=[new $r({x:t,y:i,z:e,width:o,height:h,depth:a},this.capacity),new $r({x:t+o,y:i,z:e,width:o,height:h,depth:a},this.capacity),new $r({x:t,y:i+h,z:e,width:o,height:h,depth:a},this.capacity),new $r({x:t+o,y:i+h,z:e,width:o,height:h,depth:a},this.capacity),new $r({x:t,y:i,z:e+a,width:o,height:h,depth:a},this.capacity),new $r({x:t+o,y:i,z:e+a,width:o,height:h,depth:a},this.capacity),new $r({x:t,y:i+h,z:e+a,width:o,height:h,depth:a},this.capacity),new $r({x:t+o,y:i+h,z:e+a,width:o,height:h,depth:a},this.capacity)]}intersects(t,i){return!(t.x>=i.x+i.width||t.x+t.width<=i.x||t.y>=i.y+i.height||t.y+t.height<=i.y)}}class Dr extends y{constructor(t,i,e,s){super(t,i);this.object=e;this.updatedProperties=s;this.previousProperties={};for(const t in s){if(s.hasOwnProperty(t)){this.previousProperties[t]=this.object[t]}}}execute(){for(const t in this.updatedProperties){if(this.updatedProperties.hasOwnProperty(t)){this.object[t]=this.updatedProperties[t]}}}undo(){for(const t in this.previousProperties){if(this.previousProperties.hasOwnProperty(t)){this.object[t]=this.previousProperties[t]}}}}const _r={activeTool:null,activeText:null,currentPath:null,copiedObjects:null,objectsOctree:null,selectionBox:null,selectionGroup:null,resizeHandleType:null,hasViewportChanged:false,isEnabled:true,isScaling:false,isPanning:false,isFocused:false,isSelecting:false,isResizing:false,isResizeHandleSelected:false,isRotating:false,isRotationHandleSelected:false,isDragging:false,isDrawing:false,isErasing:false,isWriting:false,isCtrlKeyPressed:false,isContextMenuVisible:false,contextMenuItems:[],contextMenuX:0,contextMenuY:0,skipContextMenu:false,debugInfo:{showObjectInfo:false,showViewportInfo:false,logCommands:false},host:null,cursorX:0,cursorY:0,scale:1,scaleMax:1e3,scaleMin:1e-4,scaleStep:.05,startX:0,startY:0,translateX:0,translateY:0,viewportWidth:0,viewportHeight:0,historyBufferSize:1e3,touchCount:0,longTouchTimeout:null,longTouchDelay:300};class Pr{get history(){return this._history}get state(){return this._state}get currentZIndex(){return this._state.objectsOctree.filter((t=>!(t instanceof Hn)&&!(t instanceof Pn))).length}get allObjects(){return this._state.objectsOctree.allObjects()}get selectedObjects(){return this.allObjects.filter((t=>!(t instanceof Hn))).filter((t=>t.selected))}get offsetX(){return this._state.host.getBoundingClientRect().left}get offsetY(){return this._state.host.getBoundingClientRect().top}constructor(t){this._listeners=new Map;this.objects=[];this._state=_r;this._kritzelEngine=t;this._history=new Or(this);this._state.objectsOctree=new $r({x:-Infinity,y:-Infinity,z:-Infinity,width:Infinity,height:Infinity,depth:Infinity})}rerender(){const t={x:-this._state.translateX/this._state.scale,y:-this._state.translateY/this._state.scale,z:this._state.scale,width:this._state.viewportWidth/this._state.scale,height:this._state.viewportHeight/this._state.scale,depth:100};this.objects=this._state.objectsOctree.query(t);if(this._kritzelEngine){this._kritzelEngine.forceUpdate++}}findObjectById(t){for(const i of this.allObjects){if(i.id===t){return i}}return null}deselectAllObjects(){if(this._state.selectionGroup){this._history.executeCommand(new Sn(this,this))}}onStateChange(t,i){if(!this._listeners.has(t)){this._listeners.set(t,new Set)}this._listeners.get(t).add(i)}setState(t,i){const e=this._state[t];if(e!==i){this._state[t]=i;if(this._listeners.has(t)){this._listeners.get(t).forEach((s=>s(i,e,String(t))))}}}clearSelection(){this.history.executeCommand(new Sn(this,this.state.selectionGroup))}delete(){if(!this.state.selectionGroup){return}const t=this.state.selectionGroup.objects.map((t=>new jn(this,this.state.selectionGroup,t)));const i=new Sn(this,this.state.selectionGroup);const e=[...t,i];this.history.executeCommand(new Mn(this,this.state.selectionGroup,e))}deleteObject(t,i=true){const e=this.findObjectById(t);if(e){if(i){const t=new jn(this,this,e);this.history.executeCommand(t)}else{this._state.objectsOctree.remove((i=>i.id===t));this.rerender()}}}copy(){this.state.copiedObjects=this.state.selectionGroup.copy()}paste(t,i){this.state.copiedObjects.selected=true;const e=t!==undefined?t:this.state.copiedObjects.translateX+25;const s=i!==undefined?i:this.state.copiedObjects.translateY+25;this.state.copiedObjects.updatePosition(e,s);const n=[];if(this.state.selectionGroup!==null){n.push(new Sn(this,this.state.selectionGroup))}const r=this.state.copiedObjects.objects.map((t=>new k(this,this,t)));const o=new Rn(this,this,this.state.copiedObjects);n.push(...r,o);this.history.executeCommand(new Mn(this,this,n));this.state.isSelecting=false;this.state.copiedObjects=this.state.selectionGroup.copy();this.setState("activeTool",pn.getTool("selection"))}moveUp(){const t=this.allObjects.length+1;const i=this.state.selectionGroup.objects.map((i=>{if(i.zIndex===t){return}return new Dr(this,this,i,{zIndex:i.zIndex+1})}));this.history.executeCommand(new Mn(this,this,i))}moveDown(){const t=0;const i=this.state.selectionGroup.objects.map((i=>{if(i.zIndex===t){return}return new Dr(this,this,i,{zIndex:i.zIndex-1})}));this.history.executeCommand(new Mn(this,this,i))}moveToTop(){const t=this.allObjects.length+1;const i=this.state.selectionGroup.objects.map((i=>new Dr(this,this,i,{zIndex:t})));this.history.executeCommand(new Mn(this,this,i))}moveToBottom(){const t=-1;const i=this.state.selectionGroup.objects.map((i=>new Dr(this,this,i,{zIndex:t})));this.history.executeCommand(new Mn(this,this,i))}selectAllInViewport(){const t=this._state.objectsOctree.query({x:-this._state.translateX/this._state.scale,y:-this._state.translateY/this._state.scale,z:this._state.scale,width:this._state.viewportWidth/this._state.scale,height:this._state.viewportHeight/this._state.scale,depth:100}).filter((t=>!(t instanceof Hn)&&!(t instanceof Pn)&&!(t instanceof u)));if(t.length>0){const i=new Hn(this);t.forEach((t=>{t.selected=false;i.addOrRemove(t)}));i.selected=true;this.state.isSelecting=false;this.history.executeCommand(new Rn(this,this,i));this.setState("activeTool",pn.getTool("selection"))}}resetActiveText(){if(this.state.activeText&&this.state.activeText.value===" "){this.deleteObject(this.state.activeText.id,false);this.history.undoStack.pop()}this.state.activeText=null}getObjectFromPointerEvent(t,i=".object"){var e;const s=(e=this.state.host)===null||e===void 0?void 0:e.shadowRoot;if(!s)return null;let n;let r;if("touches"in t){const i=t.touches[0];if(!i)return null;n=i.clientX;r=i.clientY}else{n=t.clientX;r=t.clientY}const o=s.elementFromPoint(n,r);if(!o)return null;const h=o.closest(i);if(h){return this.allObjects.find((t=>h.id===t.id))}return null}resetSelection(){this.state.selectionGroup=null;this.state.selectionBox=null;this.state.isSelecting=false;this.state.isResizeHandleSelected=false;this.state.isRotationHandleSelected=false;this._state.objectsOctree.remove((t=>t instanceof Hn));this.rerender()}}class Rr extends Fn{constructor(t){super(t)}handleKeyDown(t){if(this._store.state.isFocused===false){return}this._store.state.isCtrlKeyPressed=t.ctrlKey;if(this._store.state.isCtrlKeyPressed){t.preventDefault()}if(t.key==="Escape"&&this._store.state.selectionGroup){this._store.clearSelection()}if(t.key==="Delete"&&this._store.state.selectionGroup){this._store.delete()}if(t.key==="z"&&t.ctrlKey){this._store.history.undo()}if(t.key==="y"&&t.ctrlKey){this._store.history.redo()}if(t.key==="s"&&t.ctrlKey){this._store.setState("activeTool",pn.getTool("selection"));this._store.deselectAllObjects()}if(t.key==="b"&&t.ctrlKey){this._store.setState("activeTool",pn.getTool("brush"));this._store.deselectAllObjects()}if(t.key==="e"&&t.ctrlKey){this._store.setState("activeTool",pn.getTool("eraser"));this._store.deselectAllObjects()}if(t.key==="i"&&t.ctrlKey){this._store.setState("activeTool",pn.getTool("image"));this._store.deselectAllObjects()}if(t.key==="x"&&t.ctrlKey){this._store.setState("activeTool",pn.getTool("text"));this._store.deselectAllObjects()}if(t.key==="c"&&t.ctrlKey&&this._store.state.selectionGroup){this._store.copy();this._store.rerender()}if(t.key==="v"&&t.ctrlKey&&this._store.state.copiedObjects){this._store.paste()}if(t.key==="+"&&t.ctrlKey&&this._store.state.selectionGroup){this._store.moveUp()}if(t.key==="-"&&t.ctrlKey&&this._store.state.selectionGroup){this._store.moveDown()}if(t.key==="*"&&t.shiftKey&&this._store.state.selectionGroup){this._store.moveToTop()}if(t.key==="_"&&t.shiftKey&&this._store.state.selectionGroup){this._store.moveToBottom()}if(t.key==="a"&&t.ctrlKey&&this._store.state.activeText){this._store.state.activeText.selectAll()}if(t.key==="v"&&t.ctrlKey&&this._store.state.activeText){this._store.state.activeText.insertFromClipboard()}}handleKeyUp(t){if(this._store.state.isFocused===false){return}this._store.state.isCtrlKeyPressed=t.ctrlKey}}class Qr{static forceHideKeyboard(){if(document.activeElement instanceof HTMLElement){document.activeElement.blur()}}}class Wr extends Fn{constructor(t,i,e){super(t);this.globalContextMenuItems=[];this.objectContextMenuItems=[];this.globalContextMenuItems=i;this.objectContextMenuItems=e}handleContextMenu(t){if(t.cancelable){t.preventDefault()}if(!(this._store.state.activeTool instanceof Wn)){return}if(this._store.state.skipContextMenu){this._store.state.skipContextMenu=false;return}this._store.state.contextMenuItems=this._store.state.selectionGroup?this.objectContextMenuItems:this.globalContextMenuItems;let i=t.clientX-this._store.offsetX;let e=t.clientY-this._store.offsetY;const s=150;const n=200;const r=10;if(i+s>window.innerWidth-r){i=window.innerWidth-s-r}if(e+n>window.innerHeight-r){e=window.innerHeight-n-r}i=Math.max(r,i);e=Math.max(r,e);this._store.state.contextMenuX=i;this._store.state.contextMenuY=e;this._store.state.isContextMenuVisible=true;this._store.state.isEnabled=false;this._store.rerender()}handleContextMenuTouch(t){if(t.cancelable){t.preventDefault()}if(this._store.state.touchCount>1||!(this._store.state.activeTool instanceof Wn)){return}if("vibrate"in navigator){navigator.vibrate(25)}const i=this._store.getObjectFromPointerEvent(t,".object");if(i&&!(i instanceof Hn)){this._store.state.selectionGroup=new Hn(this._store);this._store.state.selectionGroup.addOrRemove(i);this._store.state.selectionGroup.selected=true;this._store.state.selectionGroup.rotation=i.rotation;this._store.state.isSelecting=false;this._store.history.executeCommand(new Rn(this._store,this,this._store.state.selectionGroup))}this._store.state.contextMenuItems=this._store.state.selectionGroup?this.objectContextMenuItems:this.globalContextMenuItems;const e=t.touches[0];if(!e){return}let s=Math.round(e.clientX-this._store.offsetX);let n=Math.round(e.clientY-this._store.offsetY);const r=150;const o=200;const h=10;if(s+r>window.innerWidth-h){s=window.innerWidth-r-h}if(n+o>window.innerHeight-h){n=window.innerHeight-o-h}s=Math.max(h,s);n=Math.max(h,n);this._store.state.contextMenuX=s;this._store.state.contextMenuY=n;this._store.state.isContextMenuVisible=true;this._store.state.isEnabled=false;this._store.rerender()}}const Lr=":host{display:block;position:relative;height:100%;width:100%;overflow:hidden;background-color:var(--kritzel-engine-background-color, #ffffff)}.debug-panel{position:absolute;pointer-events:none;top:0;right:0}.origin{position:relative;top:0;left:0;height:0;width:0;pointer-events:none;-webkit-transform-origin:top left;-moz-transform-origin:top left;transform-origin:top left;overflow:visible}.object{overflow:visible}textarea{all:unset;box-sizing:border-box;outline:none !important;border:none !important;overflow:visible}.resize-handle-overlay.top-left,.resize-handle-overlay.bottom-right{cursor:nwse-resize}.resize-handle-overlay.top-right,.resize-handle-overlay.bottom-left{cursor:nesw-resize}.rotation-handle-overlay{cursor:grab}";const Hr=class{get isSelecting(){return this.store.state.activeTool instanceof Wn&&this.store.state.isSelecting}get isSelectionActive(){return this.store.state.activeTool instanceof Wn&&this.store.state.selectionGroup!==null}constructor(e){t(this,e);this.engineReady=i(this,"engineReady");this.activeToolChange=i(this,"activeToolChange");this.globalContextMenuItems=[{label:"Paste",icon:"paste",disabled:()=>this.store.state.copiedObjects===null,action:()=>{const t=(-this.store.state.translateX+this.store.state.contextMenuX)/this.store.state.scale;const i=(-this.store.state.translateY+this.store.state.contextMenuY)/this.store.state.scale;this.paste(t,i)}},{label:"Select All",icon:"select-all",action:()=>this.selectAllInViewport()}];this.objectContextMenuItems=[{label:"Copy",icon:"copy",action:()=>this.copy()},{label:"Paste",icon:"paste",disabled:()=>this.store.state.copiedObjects===null,action:()=>{const t=(-this.store.state.translateX+this.store.state.contextMenuX)/this.store.state.scale;const i=(-this.store.state.translateY+this.store.state.contextMenuY)/this.store.state.scale;this.paste(t,i)}},{label:"Delete",icon:"delete",action:()=>this.delete()},{label:"Bring to Front",icon:"bring-to-front",action:()=>this.moveToTop()},{label:"Send to Back",icon:"send-to-back",action:()=>this.moveToBottom()}];this.forceUpdate=0;this.contextMenuElement=null;this.store=new Pr(this);this.contextMenuHandler=new Wr(this.store,this.globalContextMenuItems,this.objectContextMenuItems);this.keyHandler=new Rr(this.store);this.store.onStateChange("activeTool",(t=>{if(!(t instanceof Wn)){this.store.resetSelection()}this.store.state.skipContextMenu=false;this.activeToolChange.emit(t);Qr.forceHideKeyboard()}));this.store.onStateChange("isFocused",(t=>{if(!t){this.store.resetActiveText()}}))}componentDidLoad(){this.viewport=new Ir(this.store,this.host);this.engineReady.emit()}handleContextMenu(t){if(this.store.state.isEnabled===false){return}this.contextMenuHandler.handleContextMenu(t)}handleMouseDown(t){var i,e;if(this.store.state.isContextMenuVisible){this.hideContextMenu();return}if(this.store.state.isEnabled===false){return}this.viewport.handleMouseDown(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleMouseDown(t)}handleMouseMove(t){var i,e;if(this.store.state.isEnabled===false){return}this.viewport.handleMouseMove(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleMouseMove(t)}handleMouseUp(t){var i,e;if(this.store.state.isEnabled===false){return}this.viewport.handleMouseUp(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleMouseUp(t)}handleDoubleClick(t){var i,e;if(this.store.state.isEnabled===false){return}(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleDoubleClick(t)}handleDoubleTap(t){var i,e;if(this.store.state.isEnabled===false){return}const s=t instanceof CustomEvent&&t.detail?t.detail:t;(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleDoubleTap(s)}handleTouchStart(t){var i,e;if(this.store.state.isEnabled===false){return}if(w.detectDoubleTap()){const t=new CustomEvent("doubletap",{detail:event,bubbles:true,composed:true});this.host.dispatchEvent(t)}if(t.touches.length>1){clearTimeout(this.store.state.longTouchTimeout)}if(t.cancelable){t.preventDefault()}this.store.state.longTouchTimeout=setTimeout((()=>this.contextMenuHandler.handleContextMenuTouch(t)),this.store.state.longTouchDelay);this.viewport.handleTouchStart(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleTouchStart(t)}handleTouchMove(t){var i,e;if(this.store.state.isEnabled===false){return}if(t.cancelable){t.preventDefault()}this.viewport.handleTouchMove(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleTouchMove(t)}handleTouchEnd(t){var i,e;if(this.store.state.isEnabled===false){return}if(t.cancelable){t.preventDefault()}clearTimeout(this.store.state.longTouchTimeout);this.viewport.handleTouchEnd(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleTouchEnd(t)}handleTouchCancel(t){clearTimeout(this.store.state.longTouchTimeout)}handleWheel(t){var i,e;if(this.store.state.isContextMenuVisible){this.hideContextMenu()}this.viewport.handleWheel(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleWheel(t)}handleResize(){this.viewport.handleResize()}handleKeyDown(t){this.keyHandler.handleKeyDown(t)}handleKeyUp(t){this.keyHandler.handleKeyUp(t)}updateFocus(t){const i=this.store.state.host.getBoundingClientRect();const e=t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom;const s=t.composedPath();const n=this.host.closest("kritzel-engine");const r=s.includes(n||this.host);this.store.setState("isFocused",e&&r)}handleContextMenuAction(t){t.detail.action();this.hideContextMenu()}async registerTool(t,i,e){if(typeof i!=="function"||!(i.prototype instanceof dn)){console.error(`Failed to register tool "${t}": Tool class must be a constructor function`);return null}const s=pn.registerTool(t,i,this.store);if(e){Object.entries(e).forEach((([t,i])=>{s[t]=i}))}return Promise.resolve(s)}async changeActiveTool(t){var i;(i=this.store.state.activeTool)===null||i===void 0?void 0:i.onDeactivate();this.store.setState("activeTool",t);this.store.deselectAllObjects();t===null||t===void 0?void 0:t.onActivate()}async setFocus(){this.host.focus();this.store.state.isFocused=true}async disable(){this.store.state.isEnabled=false;this.forceUpdate++}async enable(){this.store.state.isEnabled=true;this.forceUpdate++}async delete(){this.store.delete()}async copy(){this.store.copy()}async paste(t,i){this.store.paste(t,i)}async moveToTop(){this.store.moveToTop()}async moveToBottom(){this.store.moveToBottom()}async selectAllInViewport(){this.store.selectAllInViewport()}async undo(){this.store.history.undo()}async redo(){this.store.history.redo()}async hideContextMenu(){this.store.state.isContextMenuVisible=false;this.store.state.selectionBox=null;this.store.state.isSelecting=false}render(){var t,i,n,r,o,h,a,l,c,f,u,d,v,b,p,g,w,y,k,x,m,A,z,M,j,T,C;const S=window.getComputedStyle(this.host);const E=S.getPropertyValue("--kritzel-selection-handle-size").trim()||"6px";const F=parseFloat(E);const I=F*2<14?14:F;return e(s,{key:"81d2f8efadded214fde44f3dbaea3b678d0b182b"},e("div",{key:"6657555d40bff3b5d44733e286c4076a82ca2e98",class:"debug-panel",style:{display:this.store.state.debugInfo.showViewportInfo?"block":"none"}},e("div",{key:"e0cf766f7e8c8e7856a6b55c9c24272fa865c86e"},"TranslateX: ",(t=this.store.state)===null||t===void 0?void 0:t.translateX),e("div",{key:"6c979eb953d01507fd29013d9186618f8f14588b"},"TranslateY: ",(i=this.store.state)===null||i===void 0?void 0:i.translateY),e("div",{key:"3be6ea4a5b5eef5d07ddc48aa8ac2e57edbe0887"},"ViewportWidth: ",(n=this.store.state)===null||n===void 0?void 0:n.viewportWidth),e("div",{key:"70aed9d3ee1227ba2a4f54a95eda27cb748f4b9f"},"ViewportHeight: ",(r=this.store.state)===null||r===void 0?void 0:r.viewportHeight),e("div",{key:"c2e79c4245e9f107e5512472030684e0ed617d1a"},"ObjectsInViewport. ",this.store.objects.length),e("div",{key:"66f4284c2d4fd5dae03ffa9b641a28b2528ea117"},"Scale: ",(o=this.store.state)===null||o===void 0?void 0:o.scale),e("div",{key:"e4518d18cf923b57dceb38c07f409471bc178e9d"},"ActiveTool: ",(a=(h=this.store.state)===null||h===void 0?void 0:h.activeTool)===null||a===void 0?void 0:a.name),e("div",{key:"47ea576f9c78f3bfb3e03649a88ec0f7b544f2d7"},"HasViewportChanged: ",((l=this.store.state)===null||l===void 0?void 0:l.hasViewportChanged)?"true":"false"),e("div",{key:"fe92910fd861170651688fedbdc2f15829c15a58"},"IsEnabled: ",((c=this.store.state)===null||c===void 0?void 0:c.isEnabled)?"true":"false"),e("div",{key:"cbe7e87d9a3be8acd47dd45f1b69314a8a9c536a"},"IsScaling: ",((f=this.store.state)===null||f===void 0?void 0:f.isScaling)?"true":"false"),e("div",{key:"722a58415ae67530dfe611e03a34f30e4c1db64e"},"IsPanning: ",((u=this.store.state)===null||u===void 0?void 0:u.isPanning)?"true":"false"),e("div",{key:"d9686a405ee05480c17358afb865a39bd64a2346"},"IsFocused: ",this.store.state.isFocused?"true":"false"),e("div",{key:"383f8e4a9e98b891507ff95416a20279e4d79431"},"IsSelecting: ",this.isSelecting?"true":"false"),e("div",{key:"fbda2b9f1ba4fe9daefb7f8b36d25d297b47a764"},"IsSelectionActive: ",this.isSelectionActive?"true":"false"),e("div",{key:"c1bb88c228cd6bbd2bdb0fe6bb3fd9b47d92bc2e"},"IsResizeHandleSelected: ",this.store.state.isResizeHandleSelected?"true":"false"),e("div",{key:"26c77aadc8cda5f27f746d0c38049d830127c81e"},"IsRotationHandleSelected: ",this.store.state.isRotationHandleSelected?"true":"false"),e("div",{key:"885725248c47714a49769b94ba48a3a0f59a7f97"},"IsDrawing: ",this.store.state.isDrawing?"true":"false"),e("div",{key:"035d1c72d476ea9f8110145a25084eca59cfbedc"},"IsWriting: ",this.store.state.isWriting?"true":"false"),e("div",{key:"d6ac0024bec7d64ca327e6a5760e427e88269b8d"},"CursorX: ",(d=this.store.state)===null||d===void 0?void 0:d.cursorX),e("div",{key:"b3bdd26eb7d5ac0fdfda0f13b7d4cde9f3712954"},"CursorY: ",(v=this.store.state)===null||v===void 0?void 0:v.cursorY)),e("div",{key:"186591f736514dcdb96f22d5ab3d14347a4c51ae",class:"origin",style:{transform:`matrix(${(b=this.store.state)===null||b===void 0?void 0:b.scale}, 0, 0, ${(p=this.store.state)===null||p===void 0?void 0:p.scale}, ${(g=this.store.state)===null||g===void 0?void 0:g.translateX}, ${(w=this.store.state)===null||w===void 0?void 0:w.translateY})`}},(y=this.store.objects)===null||y===void 0?void 0:y.map((t=>{var i,s,n,r,o,h,a,l,c,f,u,d,v,b,p,g,w,y,k;return e("div",{style:{transform:t===null||t===void 0?void 0:t.transformationMatrix,transformOrigin:"top left"}},e("svg",{xmlns:"http://www.w3.org/2000/svg",key:t.id,id:t.id,class:"object",style:{height:t===null||t===void 0?void 0:t.totalHeight.toString(),width:t===null||t===void 0?void 0:t.totalWidth.toString(),left:"0",top:"0",position:"absolute",transform:`rotate(${t.rotationDegrees}deg)`,transformOrigin:"center",opacity:t.markedForRemoval?"0.5":t.opacity.toString(),pointerEvents:t.markedForRemoval?"none":"auto",zIndex:t.zIndex.toString()}},e("foreignObject",{x:"0",y:"0",width:t.totalWidth.toString(),height:t.totalHeight.toString(),style:{minHeight:"0",minWidth:"0",backgroundColor:t.backgroundColor,borderColor:t.borderColor,borderWidth:t.borderWidth+"px",borderStyle:"solid",padding:t.padding+"px",overflow:"visible"}},t instanceof un&&e("svg",{ref:i=>t.mount(i),xmlns:"http://www.w3.org/2000/svg",style:{height:t===null||t===void 0?void 0:t.height.toString(),width:t===null||t===void 0?void 0:t.width.toString(),position:"absolute",overflow:"visible"},viewBox:t===null||t===void 0?void 0:t.viewBox},e("path",{d:t===null||t===void 0?void 0:t.d,fill:t.fill,stroke:t===null||t===void 0?void 0:t.stroke})),t instanceof Cn&&e("img",{ref:i=>t.mount(i),src:t.img.src,style:{width:"100%",height:"100%",userSelect:"none",pointerEvents:"none"},draggable:false,onDragStart:t=>t.preventDefault()}),t instanceof bn&&e("textarea",{ref:i=>t.mount(i),value:t.value,onKeyDown:i=>t.handleKeyDown(i),onInput:i=>t.handleInput(i),rows:t.rows,style:{width:"100%",height:"100%",color:t.fontColor,fontSize:((i=t.fontSize)===null||i===void 0?void 0:i.toString())+"px",fontFamily:t.fontFamily,border:"none",outline:"none",resize:"none",overflow:"hidden",display:"block",padding:"1px",whiteSpace:"nowrap",cursor:t.isReadonly?"default":"text",caretColor:t.isReadonly?"transparent":"auto"}}),t instanceof Hn&&e("div",{ref:i=>t.mount(i),style:{width:"100%",height:"100%"}}),t instanceof Pn&&e("div",{ref:i=>t.mount(i),style:{width:"100%",height:"100%"}})),e("line",{x1:"0",y1:"0",x2:t.totalWidth,y2:"0",style:{stroke:"var(--kritzel-selection-border-color, #0e1111)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${(s=this.store.state)===null||s===void 0?void 0:s.scale})`,strokeLinecap:"square"},visibility:t.selected?"visible":"hidden"}),e("line",{x1:"0",y1:"0",x2:"0",y2:t.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #0e1111)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${(n=this.store.state)===null||n===void 0?void 0:n.scale})`,strokeLinecap:"square"},visibility:t.selected?"visible":"hidden"}),e("line",{x1:"0",y1:t.totalHeight,x2:t.totalWidth,y2:t.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #0e1111)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${(r=this.store.state)===null||r===void 0?void 0:r.scale})`,strokeLinecap:"square"},visibility:t.selected?"visible":"hidden"}),e("line",{x1:t.totalWidth,y1:"0",x2:t.totalWidth,y2:t.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #0e1111)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${(o=this.store.state)===null||o===void 0?void 0:o.scale})`,strokeLinecap:"square"},visibility:t.selected?"visible":"hidden"}),e("circle",{class:"resize-handle top-left",cx:"0",cy:"0",r:`${F*t.scale/((h=this.store.state)===null||h===void 0?void 0:h.scale)}`,style:{fill:"var(--kritzel-selection-handle-color, #000000)"},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("circle",{class:"resize-handle-overlay top-left",cx:"0",cy:"0",r:`${I*t.scale/((a=this.store.state)===null||a===void 0?void 0:a.scale)}`,style:{fill:"transparent"},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("circle",{class:"resize-handle top-right",cx:t.totalWidth,cy:"0",r:`${F*t.scale/((l=this.store.state)===null||l===void 0?void 0:l.scale)}`,style:{fill:"var(--kritzel-selection-handle-color, #000000)"},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("circle",{class:"resize-handle-overlay top-right",cx:t.totalWidth,cy:"0",r:`${I*t.scale/((c=this.store.state)===null||c===void 0?void 0:c.scale)}`,style:{fill:"transparent"},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("circle",{class:"resize-handle bottom-left",cx:"0",cy:t.totalHeight,r:`${F*t.scale/((f=this.store.state)===null||f===void 0?void 0:f.scale)}`,style:{fill:"var(--kritzel-selection-handle-color, #000000)"},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("circle",{class:"resize-handle-overlay bottom-left",cx:"0",cy:t.totalHeight,r:`${I*t.scale/((u=this.store.state)===null||u===void 0?void 0:u.scale)}`,style:{fill:"transparent"},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("circle",{class:"resize-handle bottom-right",cx:t.totalWidth,cy:t.totalHeight,r:`${F*t.scale/((d=this.store.state)===null||d===void 0?void 0:d.scale)}`,style:{fill:"var(--kritzel-selection-handle-color, #000000)"},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("circle",{class:"resize-handle-overlay bottom-right",cx:t.totalWidth,cy:t.totalHeight,r:`${I*t.scale/((v=this.store.state)===null||v===void 0?void 0:v.scale)}`,style:{fill:"transparent"},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("line",{x1:t.totalWidth/2,y1:"0",x2:t.totalWidth/2,y2:-(15*t.scale/((b=this.store.state)===null||b===void 0?void 0:b.scale)),style:{stroke:"var(--kritzel-selection-border-color, #0e1111)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${(p=this.store.state)===null||p===void 0?void 0:p.scale})`},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("circle",{class:"rotation-handle",cx:t.totalWidth/2,cy:-(15*t.scale/((g=this.store.state)===null||g===void 0?void 0:g.scale)),r:`${F*t.scale/((w=this.store.state)===null||w===void 0?void 0:w.scale)}`,style:{fill:"var(--kritzel-selection-handle-color, #000000)"},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("circle",{class:"rotation-handle-overlay",cx:t.totalWidth/2,cy:-(15*t.scale/((y=this.store.state)===null||y===void 0?void 0:y.scale)),r:`${I*t.scale/((k=this.store.state)===null||k===void 0?void 0:k.scale)}`,style:{fill:"transparent",cursor:"grab"},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("g",{style:{display:this.store.state.debugInfo.showObjectInfo?"block":"none",pointerEvents:"none"}},e("foreignObject",{x:t.totalWidth.toString(),y:"0",width:"400px",height:"160px",style:{minHeight:"0",minWidth:"0",display:t.debugInfoVisible?"block":"none"}},e("div",{style:{width:"100%",height:"100%"}},e("div",{style:{whiteSpace:"nowrap"}},"zIndex: ",t.zIndex),e("div",{style:{whiteSpace:"nowrap"}},"translateX: ",t.translateX),e("div",{style:{whiteSpace:"nowrap"}},"translateY: ",t.translateY),e("div",{style:{whiteSpace:"nowrap"}},"width: ",t.width),e("div",{style:{whiteSpace:"nowrap"}},"height: ",t.height),e("div",{style:{whiteSpace:"nowrap"}},"scale: ",t.scale),e("div",{style:{whiteSpace:"nowrap"}},"rotation: ",t.rotation))))))})),e("svg",{key:"76788f88c63996a85778fac600f568e651f2604f",class:"object",xmlns:"http://www.w3.org/2000/svg",style:{height:(k=this.store.state.currentPath)===null||k===void 0?void 0:k.height.toString(),width:(x=this.store.state.currentPath)===null||x===void 0?void 0:x.width.toString(),left:"0",top:"0",zIndex:(m=this.store.state.currentPath)===null||m===void 0?void 0:m.zIndex.toString(),position:"absolute",transform:(A=this.store.state.currentPath)===null||A===void 0?void 0:A.transformationMatrix,transformOrigin:"top left",overflow:"visible"},viewBox:(z=this.store.state.currentPath)===null||z===void 0?void 0:z.viewBox},e("path",{key:"e0356205729f20a61f5bbac14393d4d607a7c865",d:(M=this.store.state.currentPath)===null||M===void 0?void 0:M.d,fill:(j=this.store.state.currentPath)===null||j===void 0?void 0:j.fill,stroke:(T=this.store.state.currentPath)===null||T===void 0?void 0:T.stroke}))),this.store.state.isContextMenuVisible&&e("kritzel-context-menu",{key:"23ab721c25518e6c6a6e6e163fa0753e054cb5e7",ref:t=>this.contextMenuElement=t,items:this.store.state.contextMenuItems,style:{position:"fixed",left:`${this.store.state.contextMenuX}px`,top:`${this.store.state.contextMenuY}px`,zIndex:"10000"},onActionSelected:t=>this.handleContextMenuAction(t)}),((C=this.store.state)===null||C===void 0?void 0:C.activeTool)instanceof Tn&&!this.store.state.isScaling&&e("kritzel-cursor-trail",{key:"01f90ff856d6a3b0812ce47796fd59dbbf0cd52d"}))}get host(){return n(this)}};Hr.style=Lr;const Vr=":host{display:block}.font-preview{color:var(--kritzel-font-size-text-color, #333333);line-height:1;text-align:center;font-weight:bold}";const Kr=class{constructor(i){t(this,i);this.fontFamily="Arial, sans-serif";this.size=24;this.color="#000000"}render(){return e(s,{key:"6f25832892d8042464751360cc9e2307193f5407"},e("div",{key:"3d2ec48a6a3b3e347c8cc1ab6f129bfacd984776",class:"font-preview",style:{fontFamily:this.fontFamily,fontSize:`${this.size}px`,color:this.color}},"A"))}};Kr.style=Vr;const Xr=":host{display:flex;align-items:flex-start;gap:8px;padding:8px;box-sizing:border-box;width:100%}.font-style-button{display:flex;justify-content:center;align-items:center;width:42px;height:32px;padding:0;border:none;outline:none;background:none;cursor:pointer;border-radius:0;color:var(--control-text-color);font-weight:bold;-webkit-tap-highlight-color:transparent}.font-style-button:not(:last-child){border-right:1px solid #333333}.font-style-button:hover{background-color:var(--control-hover-bg)}.font-style-button:active{background-color:var(--control-active-bg)}.font-style-button.selected,.font-style-button.selected:hover,.font-style-button.selected:active{background-color:var(--control-selected-bg);color:var(--control-selected-color)}.font-style-button.italic-text{font-style:italic}";const Nr=class{constructor(e){t(this,e);this.fontFamilyChange=i(this,"fontFamilyChange");this.fontOptions=[{value:"arial",label:"Arial"},{value:"verdana",label:"Verdana"},{value:"helvetica",label:"Helvetica"},{value:"tahoma",label:"Tahoma"},{value:"trebuchet ms",label:"Trebuchet MS"},{value:"times new roman",label:"Times New Roman"},{value:"georgia",label:"Georgia"},{value:"garamond",label:"Garamond"},{value:"courier new",label:"Courier New"},{value:"brush script mt",label:"Brush Script MT"}];this.handleDropdownValueChange=t=>{this.fontFamilyChange.emit(t.detail)}}componentWillLoad(){if(this.fontOptions&&this.fontOptions.length>0){const t=this.fontOptions.some((t=>t.value===this.selectedFontFamily));if(!this.selectedFontFamily||!t){this.selectedFontFamily=this.fontOptions[0].value}}}render(){const t=this.fontOptions.map((t=>({value:t.value,label:t.label,style:{fontFamily:t.value}})));return e(s,{key:"7ab677468a605e6b23466b73c1c93e258cf85c1a"},e("kritzel-dropdown",{key:"5c2528687d1e5068d958b9f663cb0ceb46a2794e",options:t,value:this.selectedFontFamily,onValueChanged:this.handleDropdownValueChange,selectStyles:{fontFamily:this.selectedFontFamily}},e("button",{key:"ab422c954569515f636031ddaaea2ec5f13a7bdc",class:"font-style-button",slot:"suffix"},"B"),e("button",{key:"884116c86f3d710df58f82c10294f66aae95829e",class:"font-style-button italic-text",slot:"suffix"},"I")))}};Nr.style=Xr;const Yr=":host{display:flex;align-items:flex-start;gap:8px;padding:8px;box-sizing:border-box}.size-container{display:flex;justify-content:center;align-items:center;width:32px;height:32px;border-radius:4px;cursor:pointer;border:2px solid transparent;box-sizing:border-box;border-radius:50%}.size-container:hover{background-color:var(--kritzel-font-size-hover-background-color, #f0f0f0)}.size-container.selected{border-color:var(--kritzel-selection-border-color, #0E1111);background-color:var(--kritzel-font-size-selected-background-color, #e0e0e0)}";const Gr=class{constructor(e){t(this,e);this.sizeChange=i(this,"sizeChange");this.sizes=[8,10,12,16,20,24];this.selectedSize=null;this.fontFamily="Arial"}handleSizeClick(t){this.selectedSize=t;this.sizeChange.emit(t)}render(){return e(s,{key:"20ad8f22858732c62838693c7b135dc92dbc5910"},this.sizes.map((t=>e("div",{class:{"size-container":true,selected:this.selectedSize===t},onClick:()=>this.handleSizeClick(t)},e("kritzel-font",{fontFamily:this.fontFamily,size:t})))))}};Gr.style=Yr;const qr=":host{display:inline-flex;justify-content:center;align-items:center;}span{display:flex;align-items:center;width:100%;height:100%;}span>svg{width:100%;height:100%}";const Zr=class{constructor(i){t(this,i);this.size=24}render(){const t=zn.get(this.name);if(!t){console.error(`[kritzel-icon] Icon "${this.name}" not found in registry.`);return e("span",{class:"error-icon","aria-label":`Error: Icon ${this.name} not found`},"?")}const i={width:`${this.size}px`,height:`${this.size}px`};return e(s,{style:i},e("span",{"aria-hidden":!this.label,role:this.label?"img":undefined,"aria-label":this.label,innerHTML:t}))}};Zr.style=qr;const Jr=":host{display:flex;align-items:flex-start;gap:8px;padding:8px;box-sizing:border-box}.size-container{display:flex;justify-content:center;align-items:center;width:32px;height:32px;border-radius:50%;cursor:pointer;border:2px solid transparent;box-sizing:border-box}.size-container:hover{background-color:var(--kritzel-stroke-size-hover-background-color, #f0f0f0)}.size-container.selected{border-color:var(--kritzel-selection-border-color, #0E1111);background-color:var(--kritzel-stroke-size-selected-background-color, #f0f0f0)}";const to=class{constructor(e){t(this,e);this.sizeChange=i(this,"sizeChange");this.sizes=[4,6,8,12,16,24];this.selectedSize=null}handleSizeClick(t){this.selectedSize=t;this.sizeChange.emit(t)}render(){return e(s,{key:"2e2a4d38920e25e1e60788deabe4912b510d0b10"},this.sizes.map((t=>e("div",{class:{"size-container":true,selected:this.selectedSize===t},onClick:()=>this.handleSizeClick(t)},e("kritzel-color",{value:"#000000",size:t})))))}};to.style=Jr;const io=":host{width:auto}.tooltip-content{position:relative;padding:8px 12px;border-radius:4px;width:fit-content;background-color:var(--kritzel-controls-tooltip-background-color, #ffffff);color:var(--kritzel-controls-tooltip-color, #000000);padding:var(--kritzel-controls-tooltip-padding, 8px);border-radius:var(--kritzel-controls-tooltip-border-radius, 8px);white-space:nowrap;box-shadow:var(--kritzel-controls-tooltip-box-shadow, 0 1px 6px rgba(0, 0, 0, 0.12))}";const eo=768;const so=class{constructor(i){t(this,i);this.isVisible=false;this.arrowSize=8;this.offsetY=24;this.positionX=0;this.arrowOffset="0px";this.isMobileView=window.innerWidth<eo}handleWindowResize(){this.isMobileView=window.innerWidth<eo;this.calculateAdjustedPosition()}componentWillLoad(){this.isMobileView=window.innerWidth<eo;this.calculateAdjustedPosition()}componentWillUpdate(){this.calculateAdjustedPosition()}calculateAdjustedPosition(){var t;if(this.isVisible&&this.anchorElement){const i=this.anchorElement.getBoundingClientRect();const e=(t=this.el.shadowRoot)===null||t===void 0?void 0:t.querySelector(".tooltip-content");if(!this.isMobileView){this.positionX=i.left+i.width/2;this.arrowOffset=`calc(${50}% - ${this.arrowSize}px)`}else{const t=e.getBoundingClientRect();this.positionX=i.left+i.width/2-t.width/2;this.arrowOffset=`${i.left+i.width/2-t.left-this.arrowSize}px`}}}render(){return e(s,{key:"30db4852719464fcb9c6964c34992e87a364caa3",style:{position:"fixed",zIndex:"9999",transition:"opacity 0.3s ease-in-out, transform 0.3s ease-in-out",visibility:this.isVisible?"visible":"hidden",left:!this.isMobileView?`${this.positionX}px`:"50%",marginBottom:`${this.offsetY+this.arrowSize}px`}},e("div",{key:"3f270c9bdb1a5282f67034618123a5d61f9f8b40",class:"tooltip-content",onClick:t=>t.stopPropagation()},e("slot",{key:"bd4a11782eb2e263f21a8ab57ad64eb4fd4fe7ec"}),e("div",{key:"4ede173979b8e0335fb3a012b662a694dc09ea28",class:"tooltip-arrow-wrapper",style:{position:"fixed",left:this.arrowOffset,bottom:`-${this.arrowSize*2}px`}},e("div",{key:"c96993f91dde76cc5feb0c42dd4e599837121bf7",class:"tooltip-arrow",style:{borderLeft:`${this.arrowSize}px solid transparent`,borderRight:`${this.arrowSize}px solid transparent`,borderTop:`${this.arrowSize}px solid var(--kritzel-controls-tooltip-background-color, #ffffff)`,filter:"drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2))"}}),e("div",{key:"888f9d44f58969b3f50db04f1cd3d49008872b55",class:"tooltip-arrow-rect",style:{position:"relative",width:`${this.arrowSize*2}px`,height:`${this.arrowSize}px`,backgroundColor:"var(--kritzel-controls-tooltip-background-color, #ffffff)",bottom:`${this.arrowSize*2}px`}}))))}get el(){return n(this)}};so.style=io;const no=":host{display:flex;flex-direction:row;align-items:center;padding:4px;gap:8px;border-top-left-radius:6px;border-top-right-radius:6px;background-color:rgb(226, 226, 226);width:fit-content;user-select:none}.utility-button{display:flex;justify-content:center;align-items:center;width:28px;height:28px;padding:8px 4px;border:none;outline:none;background:none;cursor:pointer;color:#333333;-webkit-tap-highlight-color:transparent}.utility-separator{width:1px;height:16px;background-color:hsl(0, 0%, 0%, 4.3%)}";const ro=class{constructor(e){t(this,e);this.undo=i(this,"undo");this.redo=i(this,"redo");this.delete=i(this,"delete")}handleUndo(t){if(t.cancelable){t.preventDefault();t.stopPropagation();this.undo.emit()}}handleRedo(t){t.preventDefault();t.stopPropagation();this.redo.emit()}render(){return e(s,{key:"496ed78323c9899ad363e7f7732a1464d99e1b3b"},e("button",{key:"7b6b9cd238a8d254f032d5752f184d567e9a3096",class:"utility-button",onClick:t=>this.handleUndo(t)},e("kritzel-icon",{key:"8ac19f36c6b82f7cc4a0249e60cf429f75c09218",name:"undo"})),e("button",{key:"1164727510a968356042507c1e302b85a135baf8",class:"utility-button",onClick:t=>this.handleRedo(t)},e("kritzel-icon",{key:"1c6cc414d5841a06853f99316eee7a0a609d5c92",name:"redo"})),e("div",{key:"e6f3342569b1c6b5a6b267cc215bc8e5d259e302",class:"utility-separator"}),e("button",{key:"0aa486a543df924c224f3637857cdcdb06f995ea",class:"utility-button"},e("kritzel-icon",{key:"9ee324e03f5df5297916549743539f7f19950768",name:"delete",onClick:()=>this.delete.emit()})))}};ro.style=no;export{o as kritzel_brush_style,a as kritzel_color,c as kritzel_color_palette,u as kritzel_context_menu,v as kritzel_control_brush_config,p as kritzel_control_text_config,yn as kritzel_controls,xn as kritzel_cursor_trail,An as kritzel_dropdown,Fr as kritzel_editor,Hr as kritzel_engine,Kr as kritzel_font,Nr as kritzel_font_family,Gr as kritzel_font_size,Zr as kritzel_icon,to as kritzel_stroke_size,so as kritzel_tooltip,ro as kritzel_utility_panel};
|
|
2
|
+
//# sourceMappingURL=p-f059fbff.entry.js.map
|