kritzel-stencil 0.0.112 → 0.0.113

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.
Files changed (25) hide show
  1. package/dist/cjs/kritzel-brush-style_18.cjs.entry.js +12 -10
  2. package/dist/cjs/kritzel-brush-style_18.cjs.entry.js.map +1 -1
  3. package/dist/collection/classes/handlers/key.handler.js +4 -1
  4. package/dist/collection/classes/handlers/key.handler.js.map +1 -1
  5. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +4 -4
  6. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js.map +1 -1
  7. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +4 -5
  8. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js.map +1 -1
  9. package/dist/components/kritzel-controls.js +1 -1
  10. package/dist/components/kritzel-editor.js +6 -6
  11. package/dist/components/kritzel-editor.js.map +1 -1
  12. package/dist/components/kritzel-engine.js +1 -1
  13. package/dist/components/{p-BnsTGnvc.js → p-CFwf2KYj.js} +6 -7
  14. package/dist/components/p-CFwf2KYj.js.map +1 -0
  15. package/dist/components/{p--2WHhuBI.js → p-DieKGjdj.js} +6 -3
  16. package/dist/components/{p--2WHhuBI.js.map → p-DieKGjdj.js.map} +1 -1
  17. package/dist/esm/kritzel-brush-style_18.entry.js +12 -10
  18. package/dist/esm/kritzel-brush-style_18.entry.js.map +1 -1
  19. package/dist/stencil/{p-65e86254.entry.js → p-dc26eb80.entry.js} +2 -2
  20. package/dist/stencil/p-dc26eb80.entry.js.map +1 -0
  21. package/dist/stencil/stencil.esm.js +1 -1
  22. package/dist/types/components/core/kritzel-editor/kritzel-editor.d.ts +1 -1
  23. package/package.json +1 -1
  24. package/dist/components/p-BnsTGnvc.js.map +0 -1
  25. package/dist/stencil/p-65e86254.entry.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import{r as t,c as i,h as e,H as s,a as n}from"./p-BOJOOWaP.js";const o=":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 r=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:"d7af382fe6f613aa16a5146785990ad2faa17f60"},e("kritzel-dropdown",{key:"6d6d330d415c210058834b2968774b3db2ab7fc4",options:t,value:this.type,onValueChanged:t=>this.handleDropdownValueChange(t)},e("button",{key:"c9fb33795b8e25f68c1d2ae248dc82a6de29e199",class:"brush-style-button",slot:"prefix"},e("kritzel-icon",{key:"975c95b545a1c27ae2984405ac298592eec9743d",name:this.type,size:16}))))}};r.style=o;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 l=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 o=.299*i+.587*e+.114*s;return o>220}render(){const t=this.isLightColor(this.value);return e(s,{key:"19ad3872a132c885c612dc3b96698a0c8dc7214d"},e("div",{key:"f67108e82396cbaa3d070c8dfc83da2b080ddf47",class:"checkerboard-bg",style:{width:`${this.size}px`,height:`${this.size}px`,borderRadius:"50%",display:"inline-block",position:"relative"}},e("div",{key:"1af0cc3e9f6eebc04cae2367510ef3b98420a818",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"}})))}};l.style=h;const c=":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 a=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}))))))}};a.style=c;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 d=class{constructor(e){t(this,e);this.actionSelected=i(this,"actionSelected")}handleItemClick(t){const i=typeof t.disabled==="function"?t.disabled():t.disabled;if(!i){this.actionSelected.emit(t)}}render(){return e(s,{key:"92cf80d71faae3e33bc29d9e9b3a81b4b6ee6c87"},e("div",{key:"838734ed3f1e3af86a5db7312c2206e90835a8f0",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)}};d.style=f;const u=":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:"8e7930fcc093f7277ed088d8ec5e54e4cd051b86"},e("div",{key:"08bd37b90decc9054c05d646aabbba0a4985d04c",style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-start",width:"100%",gap:"8px"}},e("kritzel-brush-style",{key:"f79744fb6523d0b4fa67c324cbf8ff3eb8a0308d",type:this.tool.type,onTypeChange:t=>this.handleTypeChange(t)}),e("button",{key:"dc3bdd90cebb29f2357e13dbc8d2dcaf02ae056e",class:"expand-toggle",onClick:()=>this.handleToggleExpand(),title:this.isExpanded?"Collapse":"Expand",style:this.palette.length>6?{visibillity:"visible"}:{visibility:"hidden"}},e("kritzel-icon",{key:"6e9e6de7fc7c708aad700498e030d2ad7364a9f3",name:this.isExpanded?"chevron-up":"chevron-down"}))),e("kritzel-color-palette",{key:"c1ffd48a475754bb1447e9d866b494fd3476f050",colors:this.palette,selectedColor:this.tool.color,isExpanded:this.isExpanded,isOpaque:true,onColorChange:t=>this.handleColorChange(t)}),e("kritzel-stroke-size",{key:"38e265b42fe09d0105e0385d7ec8e7d8d318abb0",selectedSize:this.tool.size,onSizeChange:t=>this.handleSizeChange(t)}))}static get watchers(){return{tool:["handleToolChange"]}}};v.style=u;const p=":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 b=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)}))}};b.style=p;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 isPointerEventOnContextMenu(t){const i=t.composedPath();const e=i.find((t=>t.classList&&t.classList.contains("context-menu")));return!!e}static onLongTouchPress(t,i,e){if(t.pointerType!=="touch"){e===null||e===void 0?void 0:e();return()=>{}}const s=400;const n=10;const o=t.clientX;const r=t.clientY;const h=t.target;const l=setTimeout((()=>{u();i(t)}),s);const c=()=>{clearTimeout(l);u();e===null||e===void 0?void 0:e()};const a=t=>{if(Math.abs(t.clientX-o)>n||Math.abs(t.clientY-r)>n){c()}};const f=()=>{c()};const d=()=>{c()};const u=()=>{h.removeEventListener("pointermove",a);h.removeEventListener("pointerup",f);h.removeEventListener("pointercancel",d)};h.addEventListener("pointermove",a,{passive:true});h.addEventListener("pointerup",f,{once:true});h.addEventListener("pointercancel",d,{once:true});return c}}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 z(){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:()=>E,getStroke:()=>T,getStrokeOutlinePoints:()=>M,getStrokePoints:()=>C});function n(t,i,e,s=t=>t){return t*s(.5-i*(.5-e))}function o(t){return[-t[0],-t[1]]}function r(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 l(t,i){return[t[0]*i,t[1]*i]}function c(t,i){return[t[0]/i,t[1]/i]}function a(t){return[t[1],-t[0]]}function f(t,i){return t[0]*i[0]+t[1]*i[1]}function d(t,i){return t[0]===i[0]&&t[1]===i[1]}function u(t){return Math.hypot(t[0],t[1])}function v(t){return t[0]*t[0]+t[1]*t[1]}function p(t,i){return v(h(t,i))}function b(t){return c(t,u(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),o=t[0]-i[0],r=t[1]-i[1],h=o*n-r*s,l=o*s+r*n;return[h+i[0],l+i[1]]}function y(t,i,e){return r(t,l(h(i,t),e))}function k(t,i,e){return r(t,l(i,e))}var{min:x,PI:m}=Math,z=.275,A=m+1e-4;function M(t,i={}){let{size:e=16,smoothing:s=.5,thinning:c=.5,simulatePressure:d=true,easing:u=t=>t,start:v={},end:g={},last:m=false}=i,{cap:M=true,easing:C=t=>t*(2-t)}=v,{cap:T=true,easing:E=t=>--t*t*t+1}=g;if(t.length===0||e<=0)return[];let S=t[t.length-1].runningLength,j=v.taper===false?0:v.taper===true?Math.max(e,S):v.taper,I=g.taper===false?0:g.taper===true?Math.max(e,S):g.taper,F=Math.pow(e*s,2),B=[],U=[],P=t.slice(0,10).reduce(((t,i)=>{let s=i.pressure;if(d){let n=x(1,i.distance/e),o=x(1,1-n);s=x(1,t+(o-t)*(n*z))}return(t+s)/2}),t[0].pressure),O=n(e,c,t[t.length-1].pressure,u),$,D=t[0].vector,R=t[0].point,Q=R,_=R,L=Q,W=false;for(let i=0;i<t.length;i++){let{pressure:s}=t[i],{point:o,vector:v,distance:b,runningLength:g}=t[i];if(i<t.length-1&&S-g<3)continue;if(c){if(d){let t=x(1,b/e),i=x(1,1-t);s=x(1,P+(i-P)*(t*z))}O=n(e,c,s,u)}else O=e/2;$===void 0&&($=O);let k=g<j?C(g/j):1,m=S-g<I?E((S-g)/I):1;O=Math.max(.01,O*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,D)<0&&!W,K=T!==null&&T<0;if(H||K){let t=l(a(D),O);for(let i=1/13,e=0;e<=1;e+=i)_=w(h(o,t),o,A*e),B.push(_),L=w(r(o,t),o,A*-e),U.push(L);R=_,Q=L,K&&(W=true);continue}if(W=false,i===t.length-1){let t=l(a(v),O);B.push(h(o,t)),U.push(r(o,t));continue}let V=l(a(y(M,v,T)),O);_=h(o,V),(i<=1||p(R,_)>F)&&(B.push(_),R=_),L=r(o,V),(i<=1||p(Q,L)>F)&&(U.push(L),Q=L),P=s,D=v}let H=t[0].point.slice(0,2),K=t.length>1?t[t.length-1].point.slice(0,2):r(t[0].point,[1,1]),V=[],X=[];if(t.length===1){if(!(j||I)||m){let t=k(H,b(a(h(H,K))),-($||O)),i=[];for(let e=1/13,s=e;s<=1;s+=e)i.push(w(t,H,A*2*s));return i}}else{if(!(j||I&&t.length===1))if(M)for(let t=1/13,i=t;i<=1;i+=t){let t=w(U[0],H,A*i);V.push(t)}else{let t=h(B[0],U[0]),i=l(t,.5),e=l(t,.51);V.push(h(H,i),h(H,e),r(H,e),r(H,i))}let i=a(o(t[t.length-1].vector));if(I||j&&t.length===1)X.push(K);else if(T){let t=k(K,i,O);for(let i=1/29,e=i;e<1;e+=i)X.push(w(t,K,A*3*e))}else X.push(r(K,l(i,O)),r(K,l(i,O*.99)),h(K,l(i,O*.99)),h(K,l(i,O)))}return B.concat(X,U.reverse(),V)}function C(t,i={}){var e;let{streamline:s=.5,size:n=16,last:o=false}=i;if(t.length===0)return[];let l=.15+(1-s)*.85,c=Array.isArray(t[0])?t:t.map((({x:t,y:i,pressure:e=.5})=>[t,i,e]));if(c.length===2){let t=c[1];c=c.slice(0,-1);for(let i=1;i<5;i++)c.push(y(c[0],t,i/4))}c.length===1&&(c=[...c,[...r(c[0],[1,1]),...c[0].slice(2)]]);let a=[{point:[c[0][0],c[0][1]],pressure:c[0][2]>=0?c[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],f=false,u=0,v=a[0],p=c.length-1;for(let t=1;t<c.length;t++){let i=o&&t===p?c[t].slice(0,2):y(v.point,c[t],l);if(d(v.point,i))continue;let e=g(i,v.point);if(u+=e,t<p&&!f){if(u<n)continue;f=true}v={point:i,pressure:c[t][2]>=0?c[t][2]:.5,vector:b(h(v.point,i)),distance:e,runningLength:u},a.push(v)}return a[0].vector=((e=a[1])==null?void 0:e.vector)||[0,0],a}function T(t,i={}){return M(C(t,i),i)}var E=T})(x);return x}var A=z();class M{static average(t,i){return(t+i)/2}}var C=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 T{static generateUUID(){return Math.random().toString(36).substr(2,9)}static clone(t){const i=t=>{const i=C(t,["_store","_elementRef","totalWidth","totalHeight"]);return structuredClone(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 E{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 o={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 r=Object.keys(o).reduce(((s,n)=>{const r=o[n];const h=Math.cos(e)*(r.x-t)-Math.sin(e)*(r.y-i)+t;const l=Math.sin(e)*(r.x-t)+Math.cos(e)*(r.y-i)+i;s[n]={x:h,y:l};return s}),{});return r}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(){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.id=this.generateId()}static create(t){const i=new E;i._store=t;i.zIndex=t.currentZIndex;return i}mount(t){if(this.isMounted){return}this.elementRef=t;this.isMounted=true}generateId(){return T.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 o=(i-s)/this._store.state.scale;this.translateX+=n;this.translateY+=o}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}onSelectedClick(){}revive(t){Object.assign(this,t);return this}}class S extends E{constructor(){super(...arguments);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}get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}static create(t,i){var e,s,n,o,r,h;const l=new S;l._store=t;l.id=l.generateId();l.options=i;l.points=(e=i===null||i===void 0?void 0:i.points)!==null&&e!==void 0?e:[];l.translateX=(s=i===null||i===void 0?void 0:i.translateX)!==null&&s!==void 0?s:0;l.translateY=(n=i===null||i===void 0?void 0:i.translateY)!==null&&n!==void 0?n:0;l.scale=(o=i===null||i===void 0?void 0:i.scale)!==null&&o!==void 0?o:1;l.strokeWidth=(r=i===null||i===void 0?void 0:i.strokeWidth)!==null&&r!==void 0?r:8;l.fill=(h=i===null||i===void 0?void 0:i.fill)!==null&&h!==void 0?h:"#000000";l.zIndex=t.currentZIndex;l.d=l.generateSvgPath();l.updateDimensions();return l}resize(t,i,e,s){if(e<=1||s<=1){return}const n=e/this.width;const o=s/this.height;this.width=e;this.height=s;this.points=this.points.map((([t,i])=>[t*n,i*o]));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 A.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 o=t[2];let r=`M${s[0].toFixed(2)},${s[1].toFixed(2)} Q${n[0].toFixed(2)},${n[1].toFixed(2)} ${M.average(n[0],o[0]).toFixed(2)},${M.average(n[1],o[1]).toFixed(2)} T`;for(let i=2,o=e-1;i<o;i++){s=t[i];n=t[i+1];r+=`${M.average(s[0],n[0]).toFixed(2)},${M.average(s[1],n[1]).toFixed(2)} `}if(i){r+="Z"}return r}}class j{constructor(t){this.__class__=this.constructor.name;this.name="base-tool";this._store=t}onActivate(){}onDeactivate(){}handlePointerDown(t){}handlePointerMove(t){}handlePointerUp(t){}handleWheel(t){}revive(t){Object.assign(this,t);return this}}class I extends j{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"]}}handlePointerDown(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){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=S.create(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})}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());if(t.length===1){const i=Math.round(t[0].clientX-this._store.offsetX);const e=Math.round(t[0].clientY-this._store.offsetY);this._store.state.isDrawing=true;this._store.state.currentPath=S.create(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()}}}handlePointerMove(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){if(this._store.state.isDrawing){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.currentPath=S.create(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()}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());if(t.length===1){const i=Math.round(t[0].clientX-this._store.offsetX);const e=Math.round(t[0].clientY-this._store.offsetY);this._store.state.currentPath=S.create(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()}}}handlePointerUp(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){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}}if(t.pointerType==="touch"){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 F{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}}F.registry={};class B extends E{get isReadonly(){return!(this._store.state.activeTool instanceof P)}constructor(t){super();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;if(t){this.value=t.value||" ";this.translateX=t.translateX||0;this.translateY=t.translateY||0;this.fontSize=t.fontSize||8;this.fontFamily=t.fontFamily||"Arial";this.fontColor=t.fontColor||"#000000";this.height=t.height||this.fontSize*1.2;this.width=t.width||0;this.scale=t.scale||1}}static create(t,i,e){const s=new B;s._store=t;s.fontSize=i;s.fontFamily=e;s.translateX=0;s.translateY=0;s.width=s.initialWidth/(s._store.state.scale<0?s._store.state.scale:1);s.height=s.fontSize*1.2/(s._store.state.scale<0?s._store.state.scale:1);s.padding=5;s.backgroundColor="transparent";s.scale=s._store.state.scale;s.value=" ";s.zIndex=t.currentZIndex;return s}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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").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)}}}onSelectedClick(){this._store.setState("activeTool",F.getTool("text"));this._store.state.selectionGroup=null;this._store.state.selectionBox=null;this._store.state.activeText=this;setTimeout((()=>{this.focus()}),300)}}class U{static forceHideKeyboard(){if(document.activeElement instanceof HTMLElement){document.activeElement.blur()}}static enableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let i=t.getAttribute("content");if(!i.includes("interactive-widget=resizes-content")){i+=", interactive-widget=resizes-content"}t.setAttribute("content",i)}}static disableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let i=t.getAttribute("content");let e=i.replace(/\s*interactive-widget=resizes-content\s*[,;]?/g,"");e=e.replace(/,(\s*,)+/g,",").replace(/^,/,"").replace(/,$/,"").trim();t.setAttribute("content",e)}}}class P extends j{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"]}handlePointerDown(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){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 B){this._store.state.activeText=s;s.focus();return}if(this._store.state.activeText!==null&&s instanceof B){s.focus();return}if(this._store.state.activeText!==null){this._store.resetActiveText();this._store.setState("activeTool",F.getTool("selection"));return}if(w.isLeftClick(t)===false){return}const n=t.clientX-this._store.offsetX;const o=t.clientY-this._store.offsetY;const r=B.create(this._store,this.fontSize,this.fontFamily);r.fontColor=this.fontColor;r.translateX=(n-this._store.state.translateX)/this._store.state.scale;r.translateY=(o-this._store.state.translateY)/this._store.state.scale;r.zIndex=this._store.currentZIndex;this._store.state.activeText=r;this._store.history.executeCommand(new k(this._store,this,r))}if(t.pointerType==="touch"){const i=Array.from(this._store.state.pointers.values());const e=t.composedPath().slice(1);const s=e.find((t=>t.classList&&t.classList.contains("object")));const n=this._store.findObjectById(s===null||s===void 0?void 0:s.id);if(this._store.state.activeText===null&&n&&n instanceof B){this._store.state.activeText=n;n.focus();return}if(this._store.state.activeText!==null&&n instanceof B){n.focus();return}if(this._store.state.activeText!==null){this._store.resetActiveText();this._store.setState("activeTool",F.getTool("selection"));return}if(i.length>1){return}U.disableInteractiveWidget();const o=Math.round(i[0].clientX-this._store.offsetX);const r=Math.round(i[0].clientY-this._store.offsetY);const h=B.create(this._store,this.fontSize,this.fontFamily);h.fontColor=this.fontColor;h.translateX=(o-this._store.state.translateX)/this._store.state.scale;h.translateY=(r-this._store.state.translateY)/this._store.state.scale;h.zIndex=this._store.currentZIndex;this._store.state.activeText=h;this._store.history.executeCommand(new k(this._store,this,h))}}handlePointerUp(t){var i,e,s,n;if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){(i=this._store.state.activeText)===null||i===void 0?void 0:i.adjustTextareaSize();(e=this._store.state.activeText)===null||e===void 0?void 0:e.focus()}if(t.pointerType==="touch"){(s=this._store.state.activeText)===null||s===void 0?void 0:s.adjustTextareaSize();(n=this._store.state.activeText)===null||n===void 0?void 0:n.focus();U.enableInteractiveWidget()}}}class O{static isTouchDevice(){return window.matchMedia("(any-pointer: coarse)").matches}}const $=":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%))}:host(.mobile) .kritzel-control:hover{background-color:unset}.kritzel-control:active{background-color:var(--kritzel-controls-control-active-background-color, hsl(0, 0%, 0%, 8.6%))}:host(.mobile) .kritzel-control:active{background-color:unset}.kritzel-control.selected,.kritzel-control.selected:hover,.kritzel-control.selected:active{background-color:var(--kritzel-controls-control-selected-background-color, #0E1111) !important;color:var(--kritzel-controls-control-selected-color, #ffffff) !important}.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 D=class{constructor(e){t(this,e);this.controlsReady=i(this,"controlsReady");this.controls=[];this.activeControl=null;this.firstConfig=null;this.tooltipVisible=false;this.isTouchDevice=O.isTouchDevice();this.kritzelEngine=null}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()}async closeTooltip(){var t,i;this.tooltipVisible=false;(t=this.kritzelEngine)===null||t===void 0?void 0:t.enable();(i=this.kritzelEngine)===null||i===void 0?void 0:i.setFocus()}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 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:"b0ed601253a0f6187e601afd2fb56bdbc7d5a9cd",class:{mobile:this.isTouchDevice}},e("kritzel-utility-panel",{key:"a8621ccdc3186a3f6ac6d9b5aa9ee6d92401e5d9",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:"ade9f5ee7b854eac1d4497c4f3e5e3cd6a2f1f7f",class:"kritzel-controls"},this.controls.map((t=>{var i,s,o,r,h,l,c,a;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:(o=this.host.shadowRoot)===null||o===void 0?void 0:o.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 I&&e("div",{class:"color-container"},e("kritzel-color",{value:(r=this.activeToolAsBrushTool)===null||r===void 0?void 0:r.color,size:(h=this.activeToolAsBrushTool)===null||h===void 0?void 0:h.size,style:{borderRadius:"50%",border:"none"}})),this.activeControl.tool instanceof P&&e("div",{class:"font-container"},e("kritzel-font",{fontFamily:(l=this.activeToolAsTextTool)===null||l===void 0?void 0:l.fontFamily,size:(c=this.activeToolAsTextTool)===null||c===void 0?void 0:c.fontSize,color:(a=this.activeToolAsTextTool)===null||a===void 0?void 0:a.fontColor})),n&&e("div",{class:"no-config"})))}}))))}static get assetsDirs(){return["../assets"]}get host(){return n(this)}};D.style=$;const R=":host{display:block;position:fixed;top:0;left:0;width:100vw;height:100vh;pointer-events:none;z-index:9000}";const Q=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.pointerType==="mouse"){if(t.button===g.Left){this.isLeftButtonDown=true;this.cursorTrailPoints=[]}}if(t.pointerType==="touch"){if(this.store.state.pointers.size===1){this.isLeftButtonDown=true;this.cursorTrailPoints=[]}}}handlePointerMove(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}}handlePointerUp(t){if(t.pointerType==="mouse"){if(t.button===g.Left){this.isLeftButtonDown=false;this.cursorTrailPoints=[]}}if(t.pointerType==="touch"){if(this.store.state.pointers.size===0){this.isLeftButtonDown=false;this.cursorTrailPoints=[]}}}render(){return e(s,{key:"2e6ee739a4c25cee00470ee95ca22e55712c8d7b"},this.cursorTrailPoints.length>1&&e("svg",{key:"483aa687ccd290980ca9c588a84547df2bfdb659",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 o=n-t.timestamp;const r=Math.max(0,Math.min(1,o/this.TRAIL_DURATION_MS));if(r>=1)return null;const h=Math.max(2,15*(1-r));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"})}))))}};Q.style=R;const _=':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 L=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:"32c5f5a4f807c1e316c91b795c005b8d30ce6189"},e("div",{key:"b1cbeff18e688da4a2f7472be290b9527a619f07",class:"dropdown-wrapper"},e("slot",{key:"b3bbb7e21c6f5620cab41aa4b1c7206b6c75fd86",name:"prefix",ref:t=>this.prefixSlotElement=t,onSlotchange:this.evaluatePrefixContent}),e("select",{key:"8b2dcdc125bee59cf29fce7c980b755e78d5816e",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:"8d83f0dea41ac959bf2392948efef33bb70d0154",name:"suffix",ref:t=>this.suffixSlotElement=t,onSlotchange:this.evaluateSuffixContent})))}static get watchers(){return{value:["externalValueChanged"],options:["optionsChanged"]}}};L.style=_;class W{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)}}W.registry=new Map;W.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 H 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 K 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 V extends j{constructor(t){super(t);this.touchStartTimeout=null}handlePointerDown(t){if(t.pointerType==="mouse"){if(w.isLeftClick(t)){this._store.state.isErasing=true}}if(t.pointerType==="touch"){this.touchStartTimeout=setTimeout((()=>{if(this._store.state.pointers.size===1&&!this._store.state.isScaling){this._store.state.isErasing=true}}),80)}}handlePointerMove(t){var i,e;if(t.pointerType==="mouse"){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()}}if(t.pointerType==="touch"){if(this._store.state.pointers.size===1&&this._store.state.isErasing){const i=(e=this._store.state.host)===null||e===void 0?void 0:e.shadowRoot;if(!i)return;const s=this._store.getObjectFromPointerEvent(t,".object");if(!s)return;s.markedForRemoval=true;this._store.rerender()}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._store.state.isErasing){const t=this._store.allObjects.filter((t=>t.markedForRemoval)).map((t=>{t.markedForRemoval=false;return new K(this._store,this,t)}));if(t.length>0){this._store.history.executeCommand(new H(this._store,this,t))}this._store.state.isErasing=false}}if(t.pointerType==="touch"){clearTimeout(this.touchStartTimeout);if(this._store.state.isErasing){const t=this._store.allObjects.filter((t=>t.markedForRemoval)).map((t=>{t.markedForRemoval=false;return new K(this._store,this,t)}));if(t.length>0){this._store.history.executeCommand(new H(this._store,this,t))}this._store.state.isErasing=false}}}}class X extends E{constructor(){super(...arguments);this.__class__="KritzelImage";this.src="";this.debugInfoVisible=true}static create(t){const i=new X;i._store=t;i.id=i.generateId();i.x=0;i.y=0;i.translateX=0;i.translateY=0;i.scale=i._store.state.scale;i.zIndex=t.currentZIndex;return i}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 Y extends y{constructor(t,i){super(t,i);this.previousSelectionGroup=this._store.state.selectionGroup}execute(){this._store.state.objectsOctree.remove((t=>{var i;return t.id===((i=this.previousSelectionGroup)===null||i===void 0?void 0:i.id)}));this._store.state.selectionGroup=null}undo(){if(this.previousSelectionGroup){this._store.state.objectsOctree.insert(this.previousSelectionGroup);this._store.state.selectionGroup=this.previousSelectionGroup}}}class N extends y{constructor(t,i,e,s,n,o,r=false){super(t,i);this.startX=e;this.startY=s;this.endX=n;this.endY=o;this.skipExecution=r;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 G{constructor(t){this._store=t}}class q extends G{constructor(t){super(t)}handlePointerDown(t){var i,e;if(t.pointerType==="mouse"){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}}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());if(this._store.state.pointers.size===1){if(((e=this._store.state.selectionGroup)===null||e===void 0?void 0:e.selected)&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){const i=Math.round(t[0].clientX-this._store.offsetX);const e=Math.round(t[0].clientY-this._store.offsetY);this.dragStartX=i;this.dragStartY=e;this.startX=i;this.startY=e}}}}handlePointerMove(t){if(t.pointerType==="mouse"){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}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());if(this._store.state.pointers.size===1&&this._store.state.selectionGroup&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){const i=Math.round(t[0].clientX-this._store.offsetX);const e=Math.round(t[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 o=5;if(s>o||n>o){clearTimeout(this._store.state.longTouchTimeout);this._store.state.selectionGroup.move(i,e,this.dragStartX,this.dragStartY);this.dragStartX=i;this.dragStartY=e}}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._store.state.isDragging){this._store.state.isDragging=false;this._store.history.executeCommand(new N(this._store,this,this.endX,this.endY,this.startX,this.startY,true))}}if(t.pointerType==="touch"){if(this._store.state.isDragging){this._store.state.isDragging=false;this._store.history.executeCommand(new N(this._store,this,this.endX,this.endY,this.startX,this.startY,true))}}}}var Z;(function(t){t["TopLeft"]="top-left";t["TopRight"]="top-right";t["BottomLeft"]="bottom-left";t["BottomRight"]="bottom-right"})(Z||(Z={}));class J 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 tt extends G{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}}handlePointerDown(t){if(t.pointerType==="mouse"){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}}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());const i=t[0];if(!i){return}if(t.length===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)}}}}handlePointerMove(t){if(t.pointerType==="mouse"){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 Z.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 Z.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 Z.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 Z.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()}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());const i=t[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 Z.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 Z.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 Z.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 Z.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)}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._store.state.isResizing){const t=new J(this._store,this,structuredClone(this.initialSize),structuredClone(this.newSize));this._store.history.executeCommand(t);this._store.state.isResizing=false;this._store.rerender()}}if(t.pointerType==="touch"){if(this._store.state.isResizing){const t=new J(this._store,this,structuredClone(this.initialSize),structuredClone(this.newSize));this._store.history.executeCommand(t);this._store.state.isResizing=false;this._store.rerender();clearTimeout(this._store.state.longTouchTimeout)}}}}class it 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 et extends G{constructor(t){super(t);this.initialRotation=0;this.rotation=0}handlePointerDown(t){if(t.pointerType==="mouse"){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 o=(i-this._store.state.translateX)/this._store.state.scale;const r=(e-this._store.state.translateY)/this._store.state.scale;this.initialRotation=Math.atan2(n-r,s-o)-this._store.state.selectionGroup.rotation}}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());const i=t[0];if(!i){return}if(t.length===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 o=(t-this._store.state.translateX)/this._store.state.scale;const r=(e-this._store.state.translateY)/this._store.state.scale;this.initialRotation=Math.atan2(n-r,s-o)-this._store.state.selectionGroup.rotation;clearTimeout(this._store.state.longTouchTimeout)}}}}handlePointerMove(t){if(t.pointerType==="mouse"){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 o=(i-this._store.state.translateX)/this._store.state.scale;const r=(e-this._store.state.translateY)/this._store.state.scale;const h=Math.atan2(n-r,s-o);this.rotation=h-this.initialRotation;this._store.state.selectionGroup.rotate(this.rotation);this._store.rerender()}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());const i=t[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 o=(t-this._store.state.translateX)/this._store.state.scale;const r=(e-this._store.state.translateY)/this._store.state.scale;const h=Math.atan2(n-r,s-o);this.rotation=h-this.initialRotation;this._store.state.selectionGroup.rotate(this.rotation);this._store.rerender();clearTimeout(this._store.state.longTouchTimeout)}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._store.state.isRotating){this._store.history.executeCommand(new it(this._store,this,this.rotation));this._store.state.isRotating=false;this.initialRotation=0;this.rotation=0}}if(t.pointerType==="touch"){if(this._store.state.isRotating){this._store.history.executeCommand(new it(this._store,this,this.rotation));this._store.state.isRotating=false;this.initialRotation=0;this.rotation=0;clearTimeout(this._store.state.longTouchTimeout)}}}}class st{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 o=s[(t+1)%s.length];if(this.intersectLines(i,n,e,o)){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 o=i[s].x,r=i[s].y;const h=i[n].x,l=i[n].y;const c=r>t.y!==l>t.y&&t.x<(h-o)*(t.y-r)/(l-r)+o;if(c)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 o=((e.x-t.x)*(s.y-e.y)-(e.y-t.y)*(s.x-e.x))/n;const r=-((t.x-e.x)*(i.y-t.y)-(t.y-e.y)*(i.x-t.x))/n;return o>=0&&o<=1&&r>=0&&r<=1}}class nt extends E{constructor(){super(...arguments);this.__class__="KrtizelSelectionBox";this.objects=[]}static create(t){const i=new nt;i._store=t;i.id=i.generateId();i.scale=t.state.scale;i.zIndex=99999;i.backgroundColor="var(--kritzel-selection-box-background-color, rgba(14, 17, 17, 0.2))";i.borderColor="var(--kritzel-selection-box-border-color, rgba(14, 17, 17, 0.5))";i.borderWidth=2;i.height=0;i.width=0;return i}}class ot extends y{constructor(t,i,e){super(t,i);this.selectionGroup=e}execute(){this._store.state.objectsOctree.remove((t=>t instanceof nt));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 rt extends G{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}handlePointerDown(t){if(t.pointerType==="mouse"){if(w.isLeftClick(t)&&!this._store.state.selectionGroup){this.startMouseSelection(t)}}if(t.pointerType==="touch"){this.touchStartTimeout=setTimeout((()=>{if(this._store.state.pointers.size===1&&!this._store.state.isScaling&&!this._store.state.selectionGroup){this.startTouchSelection();this.updateTouchSelection()}}),80)}}handlePointerMove(t){if(t.pointerType==="mouse"){if(this._store.state.isSelecting){this.updateMouseSelection(t)}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());const i=Math.round(t[0].clientX-this._store.offsetX);const e=Math.round(t[0].clientY-this._store.offsetY);const s=Math.abs(i-this.touchStartX);const n=Math.abs(e-this.touchStartY);const o=5;if((s>o||n>o)&&this._store.state.isSelecting){this.updateTouchSelection();clearTimeout(this._store.state.longTouchTimeout)}}}handlePointerUp(t){if(t.pointerType==="mouse"){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()}}}if(t.pointerType==="touch"){clearTimeout(this.touchStartTimeout);if(this._store.state.isSelecting){if(this.isSelectionClick){this.updateTouchSelection();this.addSelectedObjectAtIndexToSelectionGroup(0);this.removeSelectionBox()}if(this.isSelectionDrag){this.updateTouchSelection();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 nt));this._store.rerender()}startMouseSelection(t){let i,e;i=t.clientX-this._store.offsetX;e=t.clientY-this._store.offsetY;const s=nt.create(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 nt||t instanceof ct));this._store.state.objectsOctree.insert(s)}startTouchSelection(){const t=Array.from(this._store.state.pointers.values());const i=t[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=nt.create(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 nt||t instanceof ct));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(){const t=Array.from(this._store.state.pointers.values());const i=t[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 nt))).forEach((t=>{const i=t.rotatedPolygon;const e=this._store.state.selectionBox.rotatedPolygon;t.selected=st.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=ct.create(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 ot(this._store,this,this._store.state.selectionGroup))}addSelectedObjectsToSelectionGroup(){const t=this._store.selectedObjects;if(t.length===0){return}this._store.state.selectionGroup=ct.create(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 ot(this._store,this,this._store.state.selectionGroup))}}class ht extends j{constructor(t){super(t);this.selectionHandler=new rt(this._store);this.moveHandler=new q(this._store);this.resizeHandler=new tt(this._store);this.rotationHandler=new et(this._store)}handlePointerDown(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){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 Y(this._store,this._store.state.selectionGroup))}if(i&&i.selected&&i.objects.length===1){setTimeout((()=>{if(this._store.state.isDragging===false&&this._store.state.isResizing===false&&this._store.state.isRotating===false){i.objects[0].onSelectedClick()}}),100)}}this.moveHandler.handlePointerDown(t);this.selectionHandler.handlePointerDown(t);this.resizeHandler.handlePointerDown(t);this.rotationHandler.handlePointerDown(t);this._store.rerender()}if(t.pointerType==="touch"){if(this._store.state.isScaling===true){return}if(this._store.state.pointers.size===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 Y(this._store,this._store.state.selectionGroup))}if(i&&i.selected&&i.objects.length===1){setTimeout((()=>{if(this._store.state.isDragging===false&&this._store.state.isResizing===false&&this._store.state.isRotating===false){i.objects[0].onSelectedClick()}}),100)}}this.rotationHandler.handlePointerDown(t);this.resizeHandler.handlePointerDown(t);this.moveHandler.handlePointerDown(t);this.selectionHandler.handlePointerDown(t)}}handlePointerMove(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){this.moveHandler.handlePointerMove(t);this.selectionHandler.handlePointerMove(t);this.resizeHandler.handlePointerMove(t);this.rotationHandler.handlePointerMove(t);this._store.rerender()}if(t.pointerType==="touch"){if(this._store.state.isScaling===true){return}this.rotationHandler.handlePointerMove(t);this.resizeHandler.handlePointerMove(t);this.moveHandler.handlePointerMove(t);this.selectionHandler.handlePointerMove(t);this._store.rerender()}}handlePointerUp(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){this.moveHandler.handlePointerUp(t);this.selectionHandler.handlePointerUp(t);this.resizeHandler.handlePointerUp(t);this.rotationHandler.handlePointerUp(t);this._store.rerender()}if(t.pointerType==="touch"){if(this._store.state.isScaling===true){return}this.rotationHandler.handlePointerUp(t);this.resizeHandler.handlePointerUp(t);this.moveHandler.handlePointerUp(t);this.selectionHandler.handlePointerUp(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 ct){return s}else{const t=ct.create(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 o=n.closest(".resize-handle-overlay");return o===null||o===void 0?void 0:o.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 lt{constructor(t){this._store=t}revive(t){if(t&&typeof t==="object"){if(t.__class__){let i;switch(t.__class__){case"KritzelPath":i=S.create(this._store).revive(t);break;case"KritzelText":i=B.create(this._store,t.fontSize,t.fontFamily).revive(t);break;case"KritzelImage":i=X.create(this._store).revive(t);break;case"KritzelSelectionGroup":i=ct.create(this._store).revive(t);break;case"KritzelBrushTool":i=new I(this._store);break;case"KritzelEraserTool":i=new V(this._store);break;case"KritzelImageTool":i=new Kt(this._store);break;case"KritzelSelectionTool":i=new ht(this._store);break;case"KritzelTextTool":i=new P(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 ct extends E{constructor(){super(...arguments);this.__class__="KritzelSelectionGroup";this.objects=[];this.unchangedObjects=[]}get length(){return this.objects.length}static create(t){const i=new ct;i._store=t;i.id=i.generateId();i.scale=t.state.scale;i.zIndex=99999;return i}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=T.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 o=(i-s)/this._store.state.scale;this.translateX+=n;this.translateY+=o;this._store.state.objectsOctree.update(this);this.objects.forEach((t=>{t.translateX+=n;t.translateY+=o;this._store.state.objectsOctree.update(t)}));this.unchangedObjects.forEach((t=>{t.translateX+=n;t.translateY+=o}))}resize(t,i,e,s){const n=e/this.width;const o=s/this.height;const r=t-this.translateX;const h=i-this.translateY;this.objects.forEach((t=>{const i=t.width*n;const e=t.height*o;const s=t.translateX+r+(t.translateX-this.translateX)*(n-1);const l=t.translateY+h+(t.translateY-this.translateY)*(o-1);t.resize(s,l,i,e);this._store.state.objectsOctree.update(t)}));this.refreshObjectDimensions();this.unchangedObjects=T.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 o=Math.sin(s);this.objects.forEach((s=>{const r=this.getUnchangedObject(s.id);const h=this.getOffsetXToCenter(r);const l=this.getOffsetYToCenter(r);const c=n*h-o*l;const a=o*h+n*l;s.translateX=i+c-s.totalWidth/2/s.scale;s.translateY=e+a-s.totalHeight/2/s.scale;s.rotation=this.objects.length===1?t:t+r.rotation;this._store.state.objectsOctree.update(s)}))}copy(){const t=ct.create(this._store);let i=this._store.currentZIndex;this.objects.forEach((e=>{const s=e.copy();s.zIndex=i;t.addOrRemove(s);i++}));t.unchangedObjects=T.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 lt(this._store);return e.revive(i)}}function at(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 ft(t,i){return new Promise((function(e,s){let n;return dt(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 dt=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 o=s.getUint16(n);if(65498===o)break;const r=s.getUint16(n+2);if(65505===o&&1165519206===s.getUint32(n+4)){const o=n+10;let h;switch(s.getUint16(o)){case 18761:h=true;break;case 19789:h=false;break;default:return e("TIFF header contains invalid endian")}if(42!==s.getUint16(o+2,h))return e("TIFF header contains invalid version");const l=s.getUint32(o+4,h),c=o+l+2+12*s.getUint16(o+l,h);for(let t=o+l+2;t<c;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+r))}n+=2+r}return i(new Blob)})),s.readAsArrayBuffer(t)}));var ut={},vt={get exports(){return ut},set exports(t){ut=t}};!function(t){var i,e,s={};vt.exports=s,s.parse=function(t,i){for(var e=s.bin.readUshort,n=s.bin.readUint,o=0,r={},h=new Uint8Array(t),l=h.length-4;101010256!=n(h,l);)l--;o=l;o+=4;var c=e(h,o+=4);e(h,o+=2);var a=n(h,o+=2),f=n(h,o+=4);o+=4,o=f;for(var d=0;d<c;d++){n(h,o),o+=4,o+=4,o+=4,n(h,o+=4);a=n(h,o+=4);var u=n(h,o+=4),v=e(h,o+=4),p=e(h,o+2),b=e(h,o+4);o+=6;var g=n(h,o+=8);o+=4,o+=v+p+b,s._readLocal(h,g,r,a,u,i)}return r},s._readLocal=function(t,i,e,n,o,r){var h=s.bin.readUshort,l=s.bin.readUint;l(t,i),h(t,i+=4),h(t,i+=2);var c=h(t,i+=2);l(t,i+=2),l(t,i+=4),i+=4;var a=h(t,i+=8),f=h(t,i+=2);i+=2;var d=s.bin.readUTF8(t,i,a);if(i+=a,i+=f,r)e[d]={size:o,csize:n};else{var u=new Uint8Array(t.buffer,i);if(0==c)e[d]=new Uint8Array(u.buffer.slice(i,i+n));else{if(8!=c)throw"unknown compression method: "+c;var v=new Uint8Array(o);s.inflateRaw(u,v),e[d]=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 o=s.adler(t,0,t.length);return n[e+0]=o>>>24&255,n[e+1]=o>>>16&255,n[e+2]=o>>>8&255,n[e+3]=o>>>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,o=s.bin.writeUshort,r={};for(var h in t){var l=!s._noNeed(h)&&!i,c=t[h],a=s.crc.crc(c,0,c.length);r[h]={cpr:l,usize:c.length,crc:a,file:l?s.deflateRaw(c):c}}for(var h in r)e+=r[h].file.length+30+46+2*s.bin.sizeUTF8(h);e+=22;var f=new Uint8Array(e),d=0,u=[];for(var h in r){var v=r[h];u.push(d),d=s._writeHeader(f,d,h,v,0)}var p=0,b=d;for(var h in r){v=r[h];u.push(d),d=s._writeHeader(f,d,h,v,1,u[p++])}var g=d-b;return n(f,d,101010256),d+=4,o(f,d+=4,p),o(f,d+=2,p),n(f,d+=2,g),n(f,d+=4,b),d+=4,d+=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,o,r){var h=s.bin.writeUint,l=s.bin.writeUshort,c=n.file;return h(t,i,0==o?67324752:33639248),i+=4,1==o&&(i+=2),l(t,i,20),l(t,i+=2,0),l(t,i+=2,n.cpr?8:0),h(t,i+=2,0),h(t,i+=4,n.crc),h(t,i+=4,c.length),h(t,i+=4,n.usize),l(t,i+=4,s.bin.sizeUTF8(e)),l(t,i+=2,0),i+=2,1==o&&(i+=2,i+=2,h(t,i+=6,r),i+=4),i+=s.bin.writeUTF8(t,i,e),0==o&&(t.set(c,i),i+=c.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 o=0;o<n;o++)t=s.crc.table[255&(t^i[e+o])]^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,o=i,r=i+e;o<r;){for(var h=Math.min(o+5552,r);o<h;)n+=s+=t[o++];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,o="",r=0;r<e;r++)o+="%"+s.bin.pad(t[i+r].toString(16));try{n=decodeURIComponent(o)}catch(n){return s.bin.readASCII(t,i,e)}return n},writeUTF8:function(t,i,e){for(var s=e.length,n=0,o=0;o<s;o++){var r=e.charCodeAt(o);if(0==(4294967168&r))t[i+n]=r,n++;else if(0==(4294965248&r))t[i+n]=192|r>>6,t[i+n+1]=128|r>>0&63,n+=2;else if(0==(4294901760&r))t[i+n]=224|r>>12,t[i+n+1]=128|r>>6&63,t[i+n+2]=128|r>>0&63,n+=3;else{if(0!=(4292870144&r))throw"e";t[i+n]=240|r>>18,t[i+n+1]=128|r>>12&63,t[i+n+2]=128|r>>6&63,t[i+n+3]=128|r>>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 o=[[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],r=s.F.U,h=s.F._goodIndex;var l=s.F._putsE,c=0,a=e<<3,f=0,d=t.length;if(0==n){for(;c<d;){l(i,a,c+(A=Math.min(65535,d-c))==d?1:0),a=s.F._copyExact(t,c,A,i,a+8),c+=A}return a>>>3}var u=r.lits,v=r.strt,p=r.prev,b=0,g=0,w=0,y=0,k=0,x=0;for(d>2&&(v[x=s.F._hash(t,0)]=0),c=0;c<d;c++){if(k=x,c+1<d-2){x=s.F._hash(t,c+1);var m=c+1&32767;p[m]=v[x],v[x]=m}if(f<=c){(b>14e3||g>26697)&&d-c>100&&(f<c&&(u[b]=c-f,b+=2,f=c),a=s.F._writeBlock(c==d-1||f==d?1:0,u,b,y,t,w,c-w,i,a),b=g=y=0,w=c);var z=0;c<d-2&&(z=s.F._bestMatch(t,c,p,k,Math.min(o[2],d-c),o[3]));var A=z>>>16,M=65535&z;if(0!=z){M=65535&z;var C=h(A=z>>>16,r.of0);r.lhst[257+C]++;var T=h(M,r.df0);r.dhst[T]++,y+=r.exb[C]+r.dxb[T],u[b]=A<<23|c-f,u[b+1]=M<<16|C<<8|T,b+=2,f=c+A}else r.lhst[t[c]]++;g++}}for(w==c&&0!=t.length||(f<c&&(u[b]=c-f,b+=2,f=c),a=s.F._writeBlock(1,u,b,y,t,w,c-w,i,a),b=0,g=0,b=g=y=0,w=c);0!=(7&a);)a++;return a>>>3},s.F._bestMatch=function(t,i,e,n,o,r){var h=32767&i,l=e[h],c=h-l+32768&32767;if(l==h||n!=s.F._hash(t,i-c))return 0;for(var a=0,f=0,d=Math.min(32767,i);c<=d&&0!=--r&&l!=h;){if(0==a||t[i+a]==t[i+a-c]){var u=s.F._howLong(t,i,c);if(u>a){if(f=c,(a=u)>=o)break;c+2<u&&(u=c+2);for(var v=0,p=0;p<u-2;p++){var b=i-c+p+32768&32767,g=b-e[b]+32768&32767;g>v&&(v=g,l=b)}}}c+=(h=l)-(l=e[h])+32768&32767}return a<<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,o,r,h,l,c){var a,f,d,u,v,p,b,g,w,y=s.F.U,k=s.F._putsF,x=s.F._putsE;y.lhst[256]++,f=(a=s.F.getTrees())[0],d=a[1],u=a[2],v=a[3],p=a[4],b=a[5],g=a[6],w=a[7];var m=32+(0==(c+3&7)?0:8-(c+3&7))+(h<<3),z=n+s.F.contSize(y.fltree,y.lhst)+s.F.contSize(y.fdtree,y.dhst),A=n+s.F.contSize(y.ltree,y.lhst)+s.F.contSize(y.dtree,y.dhst);A+=14+3*b+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 C=m<z&&m<A?0:z<A?1:2;if(k(l,c,t),k(l,c+1,C),c+=3,0==C){for(;0!=(7&c);)c++;c=s.F._copyExact(o,r,h,l,c)}else{var T,E;if(1==C&&(T=y.fltree,E=y.fdtree),2==C){s.F.makeCodes(y.ltree,f),s.F.revCodes(y.ltree,f),s.F.makeCodes(y.dtree,d),s.F.revCodes(y.dtree,d),s.F.makeCodes(y.itree,u),s.F.revCodes(y.itree,u),T=y.ltree,E=y.dtree,x(l,c,v-257),x(l,c+=5,p-1),x(l,c+=5,b-4),c+=4;for(var S=0;S<b;S++)x(l,c+3*S,y.itree[1+(y.ordr[S]<<1)]);c+=3*b,c=s.F._codeTiny(g,y.itree,l,c),c=s.F._codeTiny(w,y.itree,l,c)}for(var j=r,I=0;I<e;I+=2){for(var F=i[I],B=F>>>23,U=j+(8388607&F);j<U;)c=s.F._writeLit(o[j++],T,l,c);if(0!=B){var P=i[I+1],O=P>>16,$=P>>8&255,D=255&P;x(l,c=s.F._writeLit(257+$,T,l,c),B-y.of0[$]),c+=y.exb[$],k(l,c=s.F._writeLit(D,E,l,c),O-y.df0[D]),c+=y.dxb[D],j+=B}}c=s.F._writeLit(256,T,l,c)}return c},s.F._copyExact=function(t,i,e,s,n){var o=n>>>3;return s[o]=e,s[o+1]=e>>>8,s[o+2]=255-s[o],s[o+3]=255-s[o+1],o+=4,s.set(new Uint8Array(t.buffer,i,e),o),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=[],o=s.F._lenCodes(t.ltree,n),r=[],h=s.F._lenCodes(t.dtree,r),l=0;l<n.length;l+=2)t.ihst[n[l]]++;for(l=0;l<r.length;l+=2)t.ihst[r[l]]++;for(var c=s.F._hufTree(t.ihst,t.itree,7),a=19;a>4&&0==t.itree[1+(t.ordr[a-1]<<1)];)a--;return[i,e,c,o,h,a,n,r]},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 o=0;o<t.length;o+=2){var r=t[o],h=t[o+1];n=s.F._writeLit(r,i,e,n);var l=16==r?2:17==r?3:7;r>15&&(s.F._putsE(e,n,h,l),n+=l)}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],o=s+3<e?t[s+3]:-1,r=s+5<e?t[s+5]:-1,h=0==s?-1:t[s-1];if(0==n&&o==n&&r==n){for(var l=s+5;l+2<e&&t[l+2]==n;)l+=2;(c=Math.min(l+1-s>>>1,138))<11?i.push(17,c-3):i.push(18,c-11),s+=2*c-2}else if(n==h&&o==n&&r==n){for(l=s+5;l+2<e&&t[l+2]==n;)l+=2;var c=Math.min(l+1-s>>>1,6);i.push(16,c-3),s+=2*c-2}else i.push(n,0)}return e>>>1},s.F._hufTree=function(t,i,e){var n=[],o=t.length,r=i.length,h=0;for(h=0;h<r;h+=2)i[h]=0,i[h+1]=0;for(h=0;h<o;h++)0!=t[h]&&n.push({lit:h,f:t[h]});var l=n.length,c=n.slice(0);if(0==l)return 0;if(1==l){var a=n[0].lit;c=0==a?1:0;return i[1+(a<<1)]=1,i[1+(c<<1)]=1,1}n.sort((function(t,i){return t.f-i.f}));var f=n[0],d=n[1],u=0,v=1,p=2;for(n[0]={lit:-1,f:f.f+d.f,l:f,r:d,d:0};v!=l-1;)f=u!=v&&(p==l||n[u].f<n[p].f)?n[u++]:n[p++],d=u!=v&&(p==l||n[u].f<n[p].f)?n[u++]:n[p++],n[v++]={lit:-1,f:f.f+d.f,l:f,r:d};var b=s.F.setDepth(n[v-1],0);for(b>e&&(s.F.restrictDepth(c,e,b),b=e),h=0;h<l;h++)i[1+(c[h].lit<<1)]=c[h].d;return b},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,o=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 r=t[s].d;t[s].d=i,o+=n-(1<<e-r)}for(o>>>=e-i;o>0;){(r=t[s].d)<i?(t[s].d++,o-=1<<i-r-1):s++}for(;s>=0;s--)t[s].d==i&&o<0&&(t[s].d--,o++);0!=o&&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,o=n._bitsF,r=n._bitsE,h=n._decodeTiny,l=n.makeCodes,c=n.codes2map,a=n._get17,f=n.U,d=null==i;d&&(i=new e(t.length>>>2<<3));for(var u,v,p=0,b=0,g=0,w=0,y=0,k=0,x=0,m=0,z=0;0==p;)if(p=o(t,z,1),b=o(t,z+1,2),z+=3,0!=b){if(d&&(i=s.F._check(i,m+(1<<17))),1==b&&(u=f.flmap,v=f.fdmap,k=511,x=31),2==b){g=r(t,z,5)+257,w=r(t,z+5,5)+1,y=r(t,z+10,4)+4,z+=14;for(var A=0;A<38;A+=2)f.itree[A]=0,f.itree[A+1]=0;var M=1;for(A=0;A<y;A++){var C=r(t,z+3*A,3);f.itree[1+(f.ordr[A]<<1)]=C,C>M&&(M=C)}z+=3*y,l(f.itree,M),c(f.itree,M,f.imap),u=f.lmap,v=f.dmap,z=h(f.imap,(1<<M)-1,g+w,t,z,f.ttree);var T=n._copyOut(f.ttree,0,g,f.ltree);k=(1<<T)-1;var E=n._copyOut(f.ttree,g,w,f.dtree);x=(1<<E)-1,l(f.ltree,T),c(f.ltree,T,u),l(f.dtree,E),c(f.dtree,E,v)}for(;;){var S=u[a(t,z)&k];z+=15&S;var j=S>>>4;if(j>>>8==0)i[m++]=j;else{if(256==j)break;var I=m+j-254;if(j>264){var F=f.ldef[j-257];I=m+(F>>>3)+r(t,z,7&F),z+=7&F}var B=v[a(t,z)&x];z+=15&B;var U=B>>>4,P=f.ddef[U],O=(P>>>4)+o(t,z,15&P);for(z+=15&P,d&&(i=s.F._check(i,m+(1<<17)));m<I;)i[m]=i[m++-O],i[m]=i[m++-O],i[m]=i[m++-O],i[m]=i[m++-O];m=I}}}else{0!=(7&z)&&(z+=8-(7&z));var $=4+(z>>>3),D=t[$-4]|t[$-3]<<8;d&&(i=s.F._check(i,m+D)),i.set(new e(t.buffer,t.byteOffset+$,D),m),z=$+D<<3,m+=D}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,o,r){for(var h=s.F._bitsE,l=s.F._get17,c=0;c<e;){var a=t[l(n,o)&i];o+=15&a;var f=a>>>4;if(f<=15)r[c]=f,c++;else{var d=0,u=0;16==f?(u=3+h(n,o,2),o+=2,d=r[c-1]):17==f?(u=3+h(n,o,3),o+=3):18==f&&(u=11+h(n,o,7),o+=7);for(var v=c+u;c<v;)r[c]=d,c++}}return o},s.F._copyOut=function(t,i,e,s){for(var n=0,o=0,r=s.length>>>1;o<e;){var h=t[o+i];s[o<<1]=0,s[1+(o<<1)]=h,h>n&&(n=h),o++}for(;o<r;)s[o<<1]=0,s[1+(o<<1)]=0,o++;return n},s.F.makeCodes=function(t,i){for(var e,n,o,r,h=s.F.U,l=t.length,c=h.bl_count,a=0;a<=i;a++)c[a]=0;for(a=1;a<l;a+=2)c[t[a]]++;var f=h.next_code;for(e=0,c[0]=0,n=1;n<=i;n++)e=e+c[n-1]<<1,f[n]=e;for(o=0;o<l;o+=2)0!=(r=t[o+1])&&(t[o]=f[r],f[r]++)},s.F.codes2map=function(t,i,e){for(var n=t.length,o=s.F.U.rev15,r=0;r<n;r+=2)if(0!=t[r+1])for(var h=r>>1,l=t[r+1],c=h<<4|l,a=i-l,f=t[r]<<a,d=f+(1<<a);f!=d;){e[o[f]>>>15-i]=c,f++}},s.F.revCodes=function(t,i){for(var e=s.F.U.rev15,n=15-i,o=0;o<t.length;o+=2){var r=t[o]<<i-t[o+1];t[o]=e[r]>>>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 pt=at({__proto__:null,default:ut},[ut]);const bt=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,o="";for(let n=0;n<s;n++)o+=`%${t.pad(i[e+n].toString(16))}`;try{n=decodeURIComponent(o)}catch(n){return t.readASCII(i,e,s)}return n}};function i(i,e,s,n){const r=e*s,h=o(n),l=Math.ceil(e*h/8),c=new Uint8Array(4*r),a=new Uint32Array(c.buffer),{ctype:f}=n,{depth:d}=n,u=t.readUshort;if(6==f){const t=r<<2;if(8==d)for(var v=0;v<t;v+=4)c[v]=i[v],c[v+1]=i[v+1],c[v+2]=i[v+2],c[v+3]=i[v+3];if(16==d)for(v=0;v<t;v++)c[v]=i[v<<1]}else if(2==f){const t=n.tabs.tRNS;if(null==t){if(8==d)for(v=0;v<r;v++){var p=3*v;a[v]=255<<24|i[p+2]<<16|i[p+1]<<8|i[p]}if(16==d)for(v=0;v<r;v++){p=6*v;a[v]=255<<24|i[p+4]<<16|i[p+2]<<8|i[p]}}else{var b=t[0];const e=t[1],s=t[2];if(8==d)for(v=0;v<r;v++){var g=v<<2;p=3*v;a[v]=255<<24|i[p+2]<<16|i[p+1]<<8|i[p],i[p]==b&&i[p+1]==e&&i[p+2]==s&&(c[g+3]=0)}if(16==d)for(v=0;v<r;v++){g=v<<2,p=6*v;a[v]=255<<24|i[p+4]<<16|i[p+2]<<8|i[p],u(i,p)==b&&u(i,p+2)==e&&u(i,p+4)==s&&(c[g+3]=0)}}}else if(3==f){const t=n.tabs.PLTE,o=n.tabs.tRNS,h=o?o.length:0;if(1==d)for(var w=0;w<s;w++){var y=w*l,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);c[g]=t[x],c[g+1]=t[x+1],c[g+2]=t[x+2],c[g+3]=m<h?o[m]:255}}if(2==d)for(w=0;w<s;w++)for(y=w*l,k=w*e,v=0;v<e;v++){g=k+v<<2,x=3*(m=i[y+(v>>2)]>>6-((3&v)<<1)&3);c[g]=t[x],c[g+1]=t[x+1],c[g+2]=t[x+2],c[g+3]=m<h?o[m]:255}if(4==d)for(w=0;w<s;w++)for(y=w*l,k=w*e,v=0;v<e;v++){g=k+v<<2,x=3*(m=i[y+(v>>1)]>>4-((1&v)<<2)&15);c[g]=t[x],c[g+1]=t[x+1],c[g+2]=t[x+2],c[g+3]=m<h?o[m]:255}if(8==d)for(v=0;v<r;v++){var m;g=v<<2,x=3*(m=i[v]);c[g]=t[x],c[g+1]=t[x+1],c[g+2]=t[x+2],c[g+3]=m<h?o[m]:255}}else if(4==f){if(8==d)for(v=0;v<r;v++){g=v<<2;var z=i[A=v<<1];c[g]=z,c[g+1]=z,c[g+2]=z,c[g+3]=i[A+1]}if(16==d)for(v=0;v<r;v++){var A;g=v<<2,z=i[A=v<<2];c[g]=z,c[g+1]=z,c[g+2]=z,c[g+3]=i[A+2]}}else if(0==f)for(b=n.tabs.tRNS?n.tabs.tRNS:-1,w=0;w<s;w++){const t=w*l,s=w*e;if(1==d)for(var M=0;M<e;M++){var C=(z=255*(i[t+(M>>>3)]>>>7-(7&M)&1))==255*b?0:255;a[s+M]=C<<24|z<<16|z<<8|z}else if(2==d)for(M=0;M<e;M++){C=(z=85*(i[t+(M>>>2)]>>>6-((3&M)<<1)&3))==85*b?0:255;a[s+M]=C<<24|z<<16|z<<8|z}else if(4==d)for(M=0;M<e;M++){C=(z=17*(i[t+(M>>>1)]>>>4-((1&M)<<2)&15))==17*b?0:255;a[s+M]=C<<24|z<<16|z<<8|z}else if(8==d)for(M=0;M<e;M++){C=(z=i[t+M])==b?0:255;a[s+M]=C<<24|z<<16|z<<8|z}else if(16==d)for(M=0;M<e;M++){z=i[t+(M<<1)],C=u(i,t+(M<<1))==b?0:255;a[s+M]=C<<24|z<<16|z<<8|z}}return c}function e(t,i,e,h){const l=o(t),c=Math.ceil(e*l/8),a=new Uint8Array((c+1+t.interlace)*h);return i=t.tabs.CgBI?n(i,a):s(i,a),0==t.interlace?i=r(i,t,0,e,h):1==t.interlace&&(i=function t(i,e){const s=e.width,n=e.height,h=o(e),l=h>>3,c=Math.ceil(s*h/8),a=new Uint8Array(n*c);let f=0;const d=[0,0,4,0,2,0,1],u=[0,4,0,2,0,1,0],v=[8,8,8,4,4,2,2],p=[8,8,4,4,2,2,1];let b=0;for(;b<7;){const t=v[b],o=p[b];let w=0,y=0,k=d[b];for(;k<n;)k+=t,y++;let x=u[b];for(;x<s;)x+=o,w++;const m=Math.ceil(w*h/8);r(i,e,f,w,y);let z=0,A=d[b];for(;A<n;){let e=u[b],n=f+z*m<<3;for(;e<s;){var g;if(1==h)g=(g=i[n>>3])>>7-(7&n)&1,a[A*c+(e>>3)]|=g<<7-((7&e)<<0);if(2==h)g=(g=i[n>>3])>>6-(7&n)&3,a[A*c+(e>>2)]|=g<<6-((3&e)<<1);if(4==h)g=(g=i[n>>3])>>4-(7&n)&15,a[A*c+(e>>1)]|=g<<4-((1&e)<<2);if(h>=8){const t=A*c+e*l;for(let e=0;e<l;e++)a[t+e]=i[(n>>3)+e]}n+=h,e+=o}z++,A+=t}w*y!=0&&(f+=y*(1+m)),b+=1}return a}(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,o,r=0,h=0,l=0,c=0,a=0,f=0,d=0,u=0,v=0;if(3==i[0]&&0==i[1])return e||new s(0);const p=t.H,b=p.b,g=p.e,w=p.R,y=p.n,k=p.A,x=p.Z,m=p.m,z=null==e;for(z&&(e=new s(i.length>>>2<<5));0==r;)if(r=b(i,v,1),h=b(i,v+1,2),v+=3,0!=h){if(z&&(e=t.H.W(e,u+(1<<17))),1==h&&(n=m.J,o=m.h,f=511,d=31),2==h){l=g(i,v,5)+257,c=g(i,v+5,5)+1,a=g(i,v+10,4)+4,v+=14;let t=1;for(var A=0;A<38;A+=2)m.Q[A]=0,m.Q[A+1]=0;for(A=0;A<a;A++){const e=g(i,v+3*A,3);m.Q[1+(m.X[A]<<1)]=e,e>t&&(t=e)}v+=3*a,y(m.Q,t),k(m.Q,t,m.u),n=m.w,o=m.d,v=w(m.u,(1<<t)-1,l+c,i,v,m.v);const e=p.V(m.v,0,l,m.C);f=(1<<e)-1;const s=p.V(m.v,l,c,m.D);d=(1<<s)-1,y(m.C,e),k(m.C,e,n),y(m.D,s),k(m.D,s,o)}for(;;){const t=n[x(i,v)&f];v+=15&t;const s=t>>>4;if(s>>>8==0)e[u++]=s;else{if(256==s)break;{let t=u+s-254;if(s>264){const e=m.q[s-257];t=u+(e>>>3)+g(i,v,7&e),v+=7&e}const n=o[x(i,v)&d];v+=15&n;const r=n>>>4,h=m.c[r],l=(h>>>4)+b(i,v,15&h);for(v+=15&h;u<t;)e[u]=e[u++-l],e[u]=e[u++-l],e[u]=e[u++-l],e[u]=e[u++-l];u=t}}}}else{0!=(7&v)&&(v+=8-(7&v));const n=4+(v>>>3),o=i[n-4]|i[n-3]<<8;z&&(e=t.H.W(e,u+o)),e.set(new s(i.buffer,i.byteOffset+n,o),u),v=n+o<<3,u+=o}return e.length==u?e:e.slice(0,u)},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,o,r){const h=t.H.e,l=t.H.Z;let c=0;for(;c<s;){const t=i[l(n,o)&e];o+=15&t;const s=t>>>4;if(s<=15)r[c]=s,c++;else{let t=0,i=0;16==s?(i=3+h(n,o,2),o+=2,t=r[c-1]):17==s?(i=3+h(n,o,3),o+=3):18==s&&(i=11+h(n,o,7),o+=7);const e=c+i;for(;c<e;)r[c]=t,c++}}return o},t.H.V=function(t,i,e,s){let n=0,o=0;const r=s.length>>>1;for(;o<e;){const e=t[o+i];s[o<<1]=0,s[1+(o<<1)]=e,e>n&&(n=e),o++}for(;o<r;)s[o<<1]=0,s[1+(o<<1)]=0,o++;return n},t.H.n=function(i,e){const s=t.H.m,n=i.length;let o,r,h;let l;const c=s.j;for(var a=0;a<=e;a++)c[a]=0;for(a=1;a<n;a+=2)c[i[a]]++;const f=s.K;for(o=0,c[0]=0,r=1;r<=e;r++)o=o+c[r-1]<<1,f[r]=o;for(h=0;h<n;h+=2)l=i[h+1],0!=l&&(i[h]=f[l],f[l]++)},t.H.A=function(i,e,s){const n=i.length,o=t.H.m.r;for(let t=0;t<n;t+=2)if(0!=i[t+1]){const n=t>>1,r=i[t+1],h=n<<4|r,l=e-r;let c=i[t]<<l;const a=c+(1<<l);for(;c!=a;){s[o[c]>>>15-e]=h,c++}}},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 o=i[t]<<e-i[t+1];i[t]=s[o]>>>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 o(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function r(t,i,e,s,n){let r=o(i);const l=Math.ceil(s*r/8);let c,a;r=Math.ceil(r/8);let f=t[e],d=0;if(f>1&&(t[e]=[0,0,1][f-2]),3==f)for(d=r;d<l;d++)t[d+1]=t[d+1]+(t[d+1-r]>>>1)&255;for(let i=0;i<n;i++)if(c=e+i*l,a=c+i+1,f=t[a-1],d=0,0==f)for(;d<l;d++)t[c+d]=t[a+d];else if(1==f){for(;d<r;d++)t[c+d]=t[a+d];for(;d<l;d++)t[c+d]=t[a+d]+t[c+d-r]}else if(2==f)for(;d<l;d++)t[c+d]=t[a+d]+t[c+d-l];else if(3==f){for(;d<r;d++)t[c+d]=t[a+d]+(t[c+d-l]>>>1);for(;d<l;d++)t[c+d]=t[a+d]+(t[c+d-l]+t[c+d-r]>>>1)}else{for(;d<r;d++)t[c+d]=t[a+d]+h(0,t[c+d-l],0);for(;d<l;d++)t[c+d]=t[a+d]+h(t[c+d-r],t[c+d-l],t[c+d-r-l])}return t}function h(t,i,e){const s=t+i-e,n=s-t,o=s-i,r=s-e;return n*n<=o*o&&n*n<=r*r?t:o*o<=r*r?i:e}function l(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 c(t,i,e,s,n,o,r,h,l){const c=Math.min(i,n),a=Math.min(e,o);let f=0,d=0;for(let e=0;e<a;e++)for(let o=0;o<c;o++)if(r>=0&&h>=0?(f=e*i+o<<2,d=(h+e)*n+r+o<<2):(f=(-h+e)*i-r+o<<2,d=e*n+o<<2),0==l)s[d]=t[f],s[d+1]=t[f+1],s[d+2]=t[f+2],s[d+3]=t[f+3];else if(1==l){var u=t[f+3]*(1/255),v=t[f]*u,p=t[f+1]*u,b=t[f+2]*u,g=s[d+3]*(1/255),w=s[d]*g,y=s[d+1]*g,k=s[d+2]*g;const i=1-u,e=u+g*i,n=0==e?0:1/e;s[d+3]=255*e,s[d+0]=(v+w*i)*n,s[d+1]=(p+y*i)*n,s[d+2]=(b+k*i)*n}else if(2==l){u=t[f+3],v=t[f],p=t[f+1],b=t[f+2],g=s[d+3],w=s[d],y=s[d+1],k=s[d+2];u==g&&v==w&&p==y&&b==k?(s[d]=0,s[d+1]=0,s[d+2]=0,s[d+3]=0):(s[d]=v,s[d+1]=p,s[d+2]=b,s[d+3]=u)}else if(3==l){u=t[f+3],v=t[f],p=t[f+1],b=t[f+2],g=s[d+3],w=s[d],y=s[d+1],k=s[d+2];if(u==g&&v==w&&p==y&&b==k)continue;if(u<220&&g>20)return false}return true}return{decode:function i(o){const r=new Uint8Array(o);let h=8;const c=t,a=c.readUshort,f=c.readUint,d={tabs:{},frames:[]},u=new Uint8Array(r.length);let v,p=0,b=0;const g=[137,80,78,71,13,10,26,10];for(var w=0;w<8;w++)if(r[w]!=g[w])throw"The input is not a PNG file!";for(;h<r.length;){const t=c.readUint(r,h);h+=4;const i=c.readASCII(r,h,4);if(h+=4,"IHDR"==i)l(r,h,d);else if("iCCP"==i){for(var y=h;0!=r[y];)y++;c.readASCII(r,h,y-h);const e=r.slice(y+2,h+t);let o=null;try{o=s(e)}catch(t){o=n(e)}d.tabs[i]=o}else if("CgBI"==i)d.tabs[i]=r.slice(h,h+4);else if("IDAT"==i){for(w=0;w<t;w++)u[p+w]=r[h+w];p+=t}else if("acTL"==i)d.tabs[i]={num_frames:f(r,h),num_plays:f(r,h+4)},v=new Uint8Array(r.length);else if("fcTL"==i){if(0!=b)(M=d.frames[d.frames.length-1]).data=e(d,v.slice(0,b),M.rect.width,M.rect.height),b=0;const t={x:f(r,h+12),y:f(r,h+16),width:f(r,h+4),height:f(r,h+8)};let i=a(r,h+22);i=a(r,h+20)/(0==i?100:i);const s={rect:t,delay:Math.round(1e3*i),dispose:r[h+24],blend:r[h+25]};d.frames.push(s)}else if("fdAT"==i){for(w=0;w<t-4;w++)v[b+w]=r[h+w+4];b+=t-4}else if("pHYs"==i)d.tabs[i]=[c.readUint(r,h),c.readUint(r,h+4),r[h+8]];else if("cHRM"==i){d.tabs[i]=[];for(w=0;w<8;w++)d.tabs[i].push(c.readUint(r,h+4*w))}else if("tEXt"==i||"zTXt"==i){null==d.tabs[i]&&(d.tabs[i]={});var k=c.nextZero(r,h),x=c.readASCII(r,h,k-h),m=h+t-k-1;if("tEXt"==i)A=c.readASCII(r,k+1,m);else{var z=s(r.slice(k+2,k+2+m));A=c.readUTF8(z,0,z.length)}d.tabs[i][x]=A}else if("iTXt"==i){null==d.tabs[i]&&(d.tabs[i]={});k=0,y=h;k=c.nextZero(r,y);x=c.readASCII(r,y,k-y);const e=r[y=k+1];var A;y+=2,k=c.nextZero(r,y),c.readASCII(r,y,k-y),y=k+1,k=c.nextZero(r,y),c.readUTF8(r,y,k-y);m=t-((y=k+1)-h);if(0==e)A=c.readUTF8(r,y,m);else{z=s(r.slice(y,y+m));A=c.readUTF8(z,0,z.length)}d.tabs[i][x]=A}else if("PLTE"==i)d.tabs[i]=c.readBytes(r,h,t);else if("hIST"==i){const t=d.tabs.PLTE.length/3;d.tabs[i]=[];for(w=0;w<t;w++)d.tabs[i].push(a(r,h+2*w))}else if("tRNS"==i)3==d.ctype?d.tabs[i]=c.readBytes(r,h,t):0==d.ctype?d.tabs[i]=a(r,h):2==d.ctype&&(d.tabs[i]=[a(r,h),a(r,h+2),a(r,h+4)]);else if("gAMA"==i)d.tabs[i]=c.readUint(r,h)/1e5;else if("sRGB"==i)d.tabs[i]=r[h];else if("bKGD"==i)0==d.ctype||4==d.ctype?d.tabs[i]=[a(r,h)]:2==d.ctype||6==d.ctype?d.tabs[i]=[a(r,h),a(r,h+2),a(r,h+4)]:3==d.ctype&&(d.tabs[i]=r[h]);else if("IEND"==i)break;h+=t,c.readUint(r,h),h+=4}var M;return 0!=b&&((M=d.frames[d.frames.length-1]).data=e(d,v.slice(0,b),M.rect.width,M.rect.height)),d.data=e(d,u,d.width,d.height),delete d.compress,delete d.interlace,delete d.filter,d},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 o=[];null==e.frames[0].data&&(e.frames[0].data=e.data);const r=s*n*4,h=new Uint8Array(r),l=new Uint8Array(r),a=new Uint8Array(r);for(let t=0;t<e.frames.length;t++){const d=e.frames[t],u=d.rect.x,v=d.rect.y,p=d.rect.width,b=d.rect.height,g=i(d.data,p,b,e);if(0!=t)for(var f=0;f<r;f++)a[f]=h[f];if(0==d.blend?c(g,p,b,h,s,n,u,v,0):1==d.blend&&c(g,p,b,h,s,n,u,v,1),o.push(h.buffer.slice(0)),0==d.dispose);else if(1==d.dispose)c(l,p,b,h,s,n,u,v,0);else if(2==d.dispose)for(f=0;f<r;f++)h[f]=a[f]}return o},_paeth:h,_copyTile:c,_bin:t}}();!function(){const{_copyTile:t}=bt,{_bin:i}=bt,e=bt._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 o=0;o<n;o++)t=s.table[255&(t^i[e+o])]^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 o(t){return Math.max(0,Math.min(255,t))}function r(t,i){const e=t[0]-i[0],s=t[1]-i[1],n=t[2]-i[2],o=t[3]-i[3];return e*e+s*s+n*n+o*o}function h(t,i,e,s,h,l,c){null==c&&(c=1);const a=s.length,f=[];for(var d=0;d<a;d++){const t=s[d];f.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(d=0;d<a;d++){let t=4294967295;for(var u=0,v=0;v<a;v++){var p=r(f[d],f[v]);v!=d&&p<t&&(t=p,u=v)}}const b=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(d=0;d<w.length;d++)w[d]=255*((w[d]+.5)/16-.5);for(let h=0;h<e;h++)for(let k=0;k<i;k++){var y;d=4*(h*i+k);if(2!=c)y=[o(t[d]+g[d]),o(t[d+1]+g[d+1]),o(t[d+2]+g[d+2]),o(t[d+3]+g[d+3])];else{p=w[4*(3&h)+(3&k)];y=[o(t[d]+p),o(t[d+1]+p),o(t[d+2]+p),o(t[d+3]+p)]}u=0;let x=16777215;for(v=0;v<a;v++){const t=r(y,f[v]);t<x&&(x=t,u=v)}const m=f[u],z=[y[0]-m[0],y[1]-m[1],y[2]-m[2],y[3]-m[3]];1==c&&(k!=i-1&&n(z,g,d+4,7),h!=e-1&&(0!=k&&n(z,g,d+4*i-4,3),n(z,g,d+4*i,5),k!=i-1&&n(z,g,d+4*i+4,1))),l[d>>2]=u,b[d>>2]=s[u]}}function l(t,e,n,o,r){null==r&&(r={});const{crc:h}=s,l=i.writeUint,c=i.writeUshort,a=i.writeASCII;let f=8;const d=t.frames.length>1;let u,v=false,p=33+(d?20:0);if(null!=r.sRGB&&(p+=13),null!=r.pHYs&&(p+=21),null!=r.iCCP&&(u=pako.deflate(r.iCCP),p+=21+u.length+4),3==t.ctype){for(var b=t.plte.length,g=0;g<b;g++)t.plte[g]>>>24!=255&&(v=true);p+=8+3*b+4+(v?8+1*b+4:0)}for(var w=0;w<t.frames.length;w++){d&&(p+=38),p+=(m=t.frames[w]).cimg.length+12,0!=w&&(p+=4)}p+=12;const y=new Uint8Array(p),k=[137,80,78,71,13,10,26,10];for(g=0;g<8;g++)y[g]=k[g];if(l(y,f,13),f+=4,a(y,f,"IHDR"),f+=4,l(y,f,e),f+=4,l(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++,l(y,f,h(y,f-17,17)),f+=4,null!=r.sRGB&&(l(y,f,1),f+=4,a(y,f,"sRGB"),f+=4,y[f]=r.sRGB,f++,l(y,f,h(y,f-5,5)),f+=4),null!=r.iCCP){const t=13+u.length;l(y,f,t),f+=4,a(y,f,"iCCP"),f+=4,a(y,f,"ICC profile"),f+=11,f+=2,y.set(u,f),f+=u.length,l(y,f,h(y,f-(t+4),t+4)),f+=4}if(null!=r.pHYs&&(l(y,f,9),f+=4,a(y,f,"pHYs"),f+=4,l(y,f,r.pHYs[0]),f+=4,l(y,f,r.pHYs[1]),f+=4,y[f]=r.pHYs[2],f++,l(y,f,h(y,f-13,13)),f+=4),d&&(l(y,f,8),f+=4,a(y,f,"acTL"),f+=4,l(y,f,t.frames.length),f+=4,l(y,f,null!=r.loop?r.loop:0),f+=4,l(y,f,h(y,f-12,12)),f+=4),3==t.ctype){l(y,f,3*(b=t.plte.length)),f+=4,a(y,f,"PLTE"),f+=4;for(g=0;g<b;g++){const i=3*g,e=t.plte[g],s=255&e,n=e>>>8&255,o=e>>>16&255;y[f+i+0]=s,y[f+i+1]=n,y[f+i+2]=o}if(f+=3*b,l(y,f,h(y,f-3*b-4,3*b+4)),f+=4,v){l(y,f,b),f+=4,a(y,f,"tRNS"),f+=4;for(g=0;g<b;g++)y[f+g]=t.plte[g]>>>24&255;f+=b,l(y,f,h(y,f-b-4,b+4)),f+=4}}let x=0;for(w=0;w<t.frames.length;w++){var m=t.frames[w];d&&(l(y,f,26),f+=4,a(y,f,"fcTL"),f+=4,l(y,f,x++),f+=4,l(y,f,m.rect.width),f+=4,l(y,f,m.rect.height),f+=4,l(y,f,m.rect.x),f+=4,l(y,f,m.rect.y),f+=4,c(y,f,o[w]),f+=2,c(y,f,1e3),f+=2,y[f]=m.dispose,f++,y[f]=m.blend,f++,l(y,f,h(y,f-30,30)),f+=4);const i=m.cimg;l(y,f,(b=i.length)+(0==w?0:4)),f+=4;const e=f;a(y,f,0==w?"IDAT":"fdAT"),f+=4,0!=w&&(l(y,f,x++),f+=4),y.set(i,f),f+=b,l(y,f,h(y,e,f-e)),f+=4}return l(y,f,0),f+=4,a(y,f,"IEND"),f+=4,l(y,f,h(y,f-4,4)),f+=4,y.buffer}function c(t,i,e){for(let s=0;s<t.frames.length;s++){const n=t.frames[s];const o=n.rect.height,r=new Uint8Array(o*n.bpl+o);n.cimg=u(n.img,o,n.bpp,n.bpl,r,i,e)}}function a(i,e,s,n,o){const r=o[0],l=o[1],c=o[2],a=o[3],u=o[4],v=o[5];let b=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,z=function i(e,s,n,o,r,h){const l=[];for(var c=0;c<e.length;c++){const i=new Uint8Array(e[c]),f=new Uint32Array(i.buffer);var a;let v=0,b=0,g=s,w=n,y=o?1:0;if(0!=c){const k=h||o||1==c||0!=l[c-2].dispose?1:2;let x=0,m=1e9;for(let t=0;t<k;t++){var u=new Uint8Array(e[c-1-t]);const i=new Uint32Array(e[c-1-t]);let o=s,h=n,l=-1,a=-1;for(let t=0;t<n;t++)for(let e=0;e<s;e++){f[p=t*s+e]!=i[p]&&(e<o&&(o=e),e>l&&(l=e),t<h&&(h=t),t>a&&(a=t))}-1==l&&(o=h=l=a=0),r&&(1==(1&o)&&o--,1==(1&h)&&h--);const d=(l-o+1)*(a-h+1);d<m&&(m=d,x=t,v=o,b=h,g=l-o+1,w=a-h+1)}u=new Uint8Array(e[c-1-x]);1==x&&(l[c-1].dispose=2),a=new Uint8Array(g*w*4),t(u,s,n,a,g,w,-v,-b,0),y=t(i,s,n,a,g,w,-v,-b,3)?1:0,1==y?d(i,s,n,a,{x:v,y:b,width:g,height:w}):t(i,s,n,a,g,w,-v,-b,0)}else a=i.slice(0);l.push({rect:{x:v,y:b,width:g,height:w},img:a,blend:y,dispose:0})}if(o)for(c=0;c<l.length;c++){if(1==(b=l[c]).blend)continue;const t=b.rect,i=l[c-1].rect,o=Math.min(t.x,i.x),h=Math.min(t.y,i.y),a={x:o,y:h,width:Math.max(t.x+t.width,i.x+i.width)-o,height:Math.max(t.y+t.height,i.y+i.height)-h};l[c-1].dispose=1,c-1!=0&&f(e,s,n,l,c-1,a,r),f(e,s,n,l,c,a,r)}let v=0;if(1!=e.length)for(var p=0;p<l.length;p++){var b;v+=(b=l[p]).rect.width*b.rect.height}return l}(i,e,s,r,l,c),A={},M=[],C=[];if(0!=n){const t=[];for(x=0;x<z.length;x++)t.push(z[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 o=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],r=t[i+2];const h=t[i+3];0==h&&(e=s=r=0),n[o+i]=e,n[o+i+1]=s,n[o+i+2]=r,n[o+i+3]=h}o+=e}return n.buffer}(t),e=p(i,n);for(x=0;x<e.plte.length;x++)M.push(e.plte[x].est.rgba);let s=0;for(x=0;x<z.length;x++){const t=(E=z[x]).img.length;var T=new Uint8Array(e.inds.buffer,s>>2,t>>2);C.push(T);const i=new Uint8Array(e.abuf,s,t);v&&h(E.img,E.rect.width,E.rect.height,M,i,T),E.img.set(i),s+=t}}else for(y=0;y<z.length;y++){var E=z[y];const t=new Uint32Array(E.img.buffer);var S=E.rect.width;k=t.length,T=new Uint8Array(k);C.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=A[i];if(null==t&&(A[i]=t=M.length,M.push(i),M.length>=300))break;T[x]=t}}}const j=M.length;j<=256&&0==u&&(g=j<=2?1:j<=4?2:j<=16?4:8,g=Math.max(g,a));for(y=0;y<z.length;y++){(E=z[y]).rect.x;S=E.rect.width;const t=E.rect.height;let i=E.img;let e=4*S,s=4;if(j<=256&&0==u){e=Math.ceil(g*S/8);var I=new Uint8Array(e*t);const n=C[y];for(let i=0;i<t;i++){x=i*e;const t=i*S;if(8==g)for(var F=0;F<S;F++)I[x+F]=n[t+F];else if(4==g)for(F=0;F<S;F++)I[x+(F>>1)]|=n[t+F]<<4-4*(1&F);else if(2==g)for(F=0;F<S;F++)I[x+(F>>2)]|=n[t+F]<<6-2*(3&F);else if(1==g)for(F=0;F<S;F++)I[x+(F>>3)]|=n[t+F]<<7-1*(7&F)}i=I,b=3,s=1}else if(0==m&&1==z.length){I=new Uint8Array(S*t*3);const n=S*t;for(x=0;x<n;x++){const t=3*x,e=4*x;I[t]=i[e],I[t+1]=i[e+1],I[t+2]=i[e+2]}i=I,b=2,s=3,e=3*S}E.img=i,E.bpl=e,E.bpp=s}return{ctype:b,depth:g,plte:M,frames:z}}function f(i,e,s,n,o,r,h){const l=Uint8Array,c=Uint32Array,a=new l(i[o-1]),f=new c(i[o-1]),u=o+1<i.length?new l(i[o+1]):null,v=new l(i[o]),p=new c(v.buffer);let b=e,g=s,w=-1,y=-1;for(let t=0;t<r.height;t++)for(let i=0;i<r.width;i++){const s=r.x+i,h=r.y+t,l=h*e+s,c=p[l];0==c||0==n[o-1].dispose&&f[l]==c&&(null==u||0!=u[4*l+3])||(s<b&&(b=s),s>w&&(w=s),h<g&&(g=h),h>y&&(y=h))}-1==w&&(b=g=w=y=0),h&&(1==(1&b)&&b--,1==(1&g)&&g--),r={x:b,y:g,width:w-b+1,height:y-g+1};const k=n[o];k.rect=r,k.blend=1,k.img=new Uint8Array(r.width*r.height*4),0==n[o-1].dispose?(t(a,e,s,k.img,r.width,r.height,-r.x,-r.y,0),d(v,e,s,k.img,r)):t(v,e,s,k.img,r.width,r.height,-r.x,-r.y,0)}function d(i,e,s,n,o){t(i,e,s,n,o.width,o.height,-o.x,-o.y,2)}function u(t,i,e,s,n,o,r){const h=[];let l,c=[0,1,2,3,4];-1!=o?c=[o]:(i*s>5e5||1==e)&&(c=[0]),r&&(l={level:0});const a=pt;for(var f=0;f<c.length;f++){for(let o=0;o<i;o++)v(n,t,o,s,e,c[f]);h.push(a.deflate(n,l))}let d,u=1e9;for(f=0;f<h.length;f++)h[f].length<u&&(d=f,u=h[f].length);return h[d]}function v(t,i,s,n,o,r){const h=s*n;let l=h+s;if(t[l]=r,l++,0==r)if(n<500)for(var c=0;c<n;c++)t[l+c]=i[h+c];else t.set(new Uint8Array(i.buffer,h,n),l);else if(1==r){for(c=0;c<o;c++)t[l+c]=i[h+c];for(c=o;c<n;c++)t[l+c]=i[h+c]-i[h+c-o]+256&255}else if(0==s){for(c=0;c<o;c++)t[l+c]=i[h+c];if(2==r)for(c=o;c<n;c++)t[l+c]=i[h+c];if(3==r)for(c=o;c<n;c++)t[l+c]=i[h+c]-(i[h+c-o]>>1)+256&255;if(4==r)for(c=o;c<n;c++)t[l+c]=i[h+c]-e(i[h+c-o],0,0)+256&255}else{if(2==r)for(c=0;c<n;c++)t[l+c]=i[h+c]+256-i[h+c-n]&255;if(3==r){for(c=0;c<o;c++)t[l+c]=i[h+c]+256-(i[h+c-n]>>1)&255;for(c=o;c<n;c++)t[l+c]=i[h+c]+256-(i[h+c-n]+i[h+c-o]>>1)&255}if(4==r){for(c=0;c<o;c++)t[l+c]=i[h+c]+256-e(0,i[h+c-n],0)&255;for(c=o;c<n;c++)t[l+c]=i[h+c]+256-e(i[h+c-o],i[h+c-n],i[h+c-o-n])&255}}}function p(t,i){const e=new Uint8Array(t),s=e.slice(0),n=new Uint32Array(s.buffer),o=b(s,i),r=o[0],h=o[1],l=e.length,c=new Uint8Array(l>>2);let a;if(e.length<2e7)for(var f=0;f<l;f+=4){a=g(r,d=e[f]*(1/255),u=e[f+1]*(1/255),v=e[f+2]*(1/255),p=e[f+3]*(1/255)),c[f>>2]=a.ind,n[f>>2]=a.est.rgba}else for(f=0;f<l;f+=4){var d=e[f]*(1/255),u=e[f+1]*(1/255),v=e[f+2]*(1/255),p=e[f+3]*(1/255);for(a=r;a.left;)a=w(a.est,d,u,v,p)<=0?a.left:a.right;c[f>>2]=a.ind,n[f>>2]=a.est.rgba}return{abuf:s.buffer,inds:c,plte:h}}function b(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 o=[n];for(;o.length<i;){let i=0,n=0;for(var r=0;r<o.length;r++)o[r].est.L>i&&(i=o[r].est.L,n=r);if(i<e)break;const h=o[n],l=y(t,s,h.i0,h.i1,h.est.e,h.est.eMq255);if(h.i0>=l||h.i1<=l){h.est.L=0;continue}const c={i0:h.i0,i1:l,bst:null,est:null,tdst:0,left:null,right:null};c.bst=x(t,c.i0,c.i1),c.est=m(c.bst);const a={i0:l,i1:h.i1,bst:null,est:null,tdst:0,left:null,right:null};a.bst={R:[],m:[],N:h.bst.N-c.bst.N};for(r=0;r<16;r++)a.bst.R[r]=h.bst.R[r]-c.bst.R[r];for(r=0;r<4;r++)a.bst.m[r]=h.bst.m[r]-c.bst.m[r];a.est=m(a.bst),h.left=c,h.right=a,o[n]=c,o.push(a)}o.sort(((t,i)=>i.bst.N-t.bst.N));for(r=0;r<o.length;r++)o[r].ind=r;return[n,o]}function g(t,i,e,s,n){if(null==t.left)return t.tdst=function t(i,e,s,n,o){const r=e-i[0],h=s-i[1],l=n-i[2],c=o-i[3];return r*r+h*h+l*l+c*c}(t.est.q,i,e,s,n),t;const o=w(t.est,i,e,s,n);let r=t.left,h=t.right;o>0&&(r=t.right,h=t.left);const l=g(r,i,e,s,n);if(l.tdst<=o*o)return l;const c=g(h,i,e,s,n);return c.tdst<l.tdst?c:l}function w(t,i,e,s,n){const{e:o}=t;return o[0]*i+o[1]*e+o[2]*s+o[3]*n-t.eMq}function y(t,i,e,s,n,o){for(s-=4;e<s;){for(;k(t,e,n)<=o;)e+=4;for(;k(t,s,n)>o;)s-=4;if(e>=s)break;const r=i[e>>2];i[e>>2]=i[s>>2],i[s>>2]=r,e+=4,s-=4}for(;k(t,e,n)>o;)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],o=e-i>>2;for(let o=i;o<e;o+=4){const i=t[o]*(1/255),e=t[o+1]*(1/255),r=t[o+2]*(1/255),h=t[o+3]*(1/255);n[0]+=i,n[1]+=e,n[2]+=r,n[3]+=h,s[0]+=i*i,s[1]+=i*e,s[2]+=i*r,s[3]+=i*h,s[5]+=e*e,s[6]+=e*r,s[7]+=e*h,s[10]+=r*r,s[11]+=r*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:o}}function m(t){const{R:i}=t,{m:e}=t,{N:s}=t,n=e[0],o=e[1],r=e[2],h=e[3],l=0==s?0:1/s,c=[i[0]-n*n*l,i[1]-n*o*l,i[2]-n*r*l,i[3]-n*h*l,i[4]-o*n*l,i[5]-o*o*l,i[6]-o*r*l,i[7]-o*h*l,i[8]-r*n*l,i[9]-r*o*l,i[10]-r*r*l,i[11]-r*h*l,i[12]-h*n*l,i[13]-h*o*l,i[14]-h*r*l,i[15]-h*h*l],a=c,f=z;let d=[Math.random(),Math.random(),Math.random(),Math.random()],u=0,v=0;if(0!=s)for(let t=0;t<16&&(d=f.multVec(a,d),v=Math.sqrt(f.dot(d,d)),d=f.sml(1/v,d),!(0!=t&&Math.abs(v-u)<1e-9));t++)u=v;const p=[n*l,o*l,r*l,h*l];return{Cov:c,q:p,e:d,L:u,eMq255:f.dot(f.sml(255,p),d),eMq:f.dot(d,p),rgba:(Math.round(255*p[3])<<24|Math.round(255*p[2])<<16|Math.round(255*p[1])<<8|Math.round(255*p[0])<<0)>>>0}}var z={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]]};bt.encode=function t(i,e,s,n,o,r,h){null==n&&(n=0),null==h&&(h=false);const f=a(i,e,s,n,[false,false,false,0,h,false]);return c(f,-1),l(f,e,s,o,r)},bt.encodeLL=function t(i,e,s,n,o,r,h,a){const f={ctype:0+(1==n?0:2)+(0==o?0:4),depth:r,frames:[]},d=(n+o)*r,u=d*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(d/8),bpl:Math.ceil(u/8)});return c(f,0,true),l(f,e,s,h,a)},bt.encode.compress=a,bt.encode.dither=h,bt.quantize=p,bt.quantize.getKDtree=b,bt.quantize.getNearest=g}();const gt={toArrayBuffer(t,i){const e=t.width,s=t.height,n=e<<2,o=t.getContext("2d").getImageData(0,0,e,s),r=new Uint32Array(o.data.buffer),h=(32*e+31)/32<<2,l=h*s,c=122+l,a=new ArrayBuffer(c),f=new DataView(a),d=1<<20;let u,v,p,b,g=d,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 z(t){y+=t}x(19778),m(c),z(4),m(122),m(108),m(e),m(-s>>>0),x(1),x(32),m(3),m(l),m(2835),m(2835),z(8),m(16711680),m(65280),m(255),m(4278190080),m(1466527264),function t(){for(;w<s&&g>0;){for(b=122+w*h,u=0;u<n;)g--,v=r[k++],p=v>>>24,f.setUint32(b+u,v<<8|p),u+=4;w++}k<r.length?(g=d,setTimeout(t,gt._dly)):i(a)}()},toBlob(t,i){this.toArrayBuffer(t,(t=>{i(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var wt={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},yt={[wt.CHROME]:16384,[wt.FIREFOX]:11180,[wt.DESKTOP_SAFARI]:16384,[wt.IE]:8192,[wt.IOS]:4096,[wt.ETC]:8192};const kt="undefined"!=typeof window,xt="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,mt=kt&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),zt=(kt||xt)&&(mt&&mt.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),At=(kt||xt)&&(mt&&mt.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function Mt(t,i,e=Date.now()){return new Promise((s=>{const n=t.split(","),o=n[0].match(/:(.*?);/)[1],r=globalThis.atob(n[1]);let h=r.length;const l=new Uint8Array(h);for(;h--;)l[h]=r.charCodeAt(h);const c=new Blob([l],{type:o});c.name=i,c.lastModified=e,s(c)}))}function Ct(t){return new Promise(((i,e)=>{const s=new At;s.onload=()=>i(s.result),s.onerror=t=>e(t),s.readAsDataURL(t)}))}function Tt(t){return new Promise(((i,e)=>{const s=new Image;s.onload=()=>i(s),s.onerror=t=>e(t),s.src=t}))}function Et(){if(void 0!==Et.cachedResult)return Et.cachedResult;let t=wt.ETC;const{userAgent:i}=navigator;return/Chrom(e|ium)/i.test(i)?t=wt.CHROME:/iP(ad|od|hone)/i.test(i)&&/WebKit/i.test(i)?t=wt.IOS:/Safari/i.test(i)?t=wt.DESKTOP_SAFARI:/Firefox/i.test(i)?t=wt.FIREFOX:(/MSIE/i.test(i)||true==!!document.documentMode)&&(t=wt.IE),Et.cachedResult=t,Et.cachedResult}function St(t,i){const e=Et(),s=yt[e];let n=t,o=i,r=n*o;const h=n>o?o/n:n/o;for(;r>s*s;){const t=(s+n)/2,i=(s+o)/2;t<i?(o=i,n=i*h):(o=t*h,n=t),r=n*o}return{width:n,height:o}}function jt(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 It(t,i){const{width:e,height:s}=St(t.width,t.height),[n,o]=jt(e,s);return i&&/jpe?g/.test(i)&&(o.fillStyle="white",o.fillRect(0,0,n.width,n.height)),o.drawImage(t,0,0,n.width,n.height),n}function Ft(){return void 0!==Ft.cachedResult||(Ft.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),Ft.cachedResult}function Bt(t,i={}){return new Promise((function(e,s){let n,o;var r=function(){try{return o=It(n,i.fileType||t.type),e([n,o])}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 Ct(t).then((function(t){try{return i=t,Tt(i).then((function(t){try{return n=t,function(){try{return r()}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(Ft()||[wt.DESKTOP_SAFARI,wt.MOBILE_SAFARI].includes(Et()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return n=t,r()}catch(t){return h()}}),h)}catch(t){h()}}))}function Ut(t,i,e,s,n=1){return new Promise((function(o,r){let h;if("image/png"===i){let c,a,f;return c=t.getContext("2d"),({data:a}=c.getImageData(0,0,t.width,t.height)),f=bt.encode([a.buffer],t.width,t.height,4096*n),h=new Blob([f],{type:i}),h.name=e,h.lastModified=s,l.call(this)}{if("image/bmp"===i)return new Promise((i=>gt.toBlob(t,i))).then(function(t){try{return h=t,h.name=e,h.lastModified=s,d.call(this)}catch(t){return r(t)}}.bind(this),r);{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,u.call(this)}catch(t){return r(t)}}.bind(this),r);{let v;return v=t.toDataURL(i,n),Mt(v,e,s).then(function(t){try{return h=t,u.call(this)}catch(t){return r(t)}}.bind(this),r)}function u(){return d.call(this)}}function d(){return l.call(this)}}function l(){return o(h)}}))}function Pt(t){t.width=0,t.height=0}function Ot(){return new Promise((function(t,i){let e,s,n,o;return void 0!==Ot.cachedResult?t(Ot.cachedResult):Mt("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(r){try{return e=r,Bt(e).then((function(r){try{return s=r[1],Ut(s,e.type,e.name,e.lastModified).then((function(e){try{return n=e,Pt(s),Bt(n).then((function(e){try{return o=e[0],Ot.cachedResult=1===o.width&&2===o.height,t(Ot.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 $t(t){return new Promise(((i,e)=>{const s=new At;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 o=0;o<s;o++)if(274==e.getUint16(n+12*o,t))return i(e.getUint16(n+12*o+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 Dt(t,i){const{width:e}=t,{height:s}=t,{maxWidthOrHeight:n}=i;let o,r=t;return isFinite(n)&&(e>n||s>n)&&([r,o]=jt(e,s),e>s?(r.width=n,r.height=s/e*n):(r.width=e/s*n,r.height=n),o.drawImage(t,0,0,r.width,r.height),Pt(t)),r}function Rt(t,i){const{width:e}=t,{height:s}=t,[n,o]=jt(e,s);switch(i>4&&i<9?(n.width=s,n.height=e):(n.width=e,n.height=s),i){case 2:o.transform(-1,0,0,1,e,0);break;case 3:o.transform(-1,0,0,-1,e,s);break;case 4:o.transform(1,0,0,-1,0,s);break;case 5:o.transform(0,1,1,0,0,0);break;case 6:o.transform(0,1,-1,0,s,0);break;case 7:o.transform(0,-1,-1,0,s,e);break;case 8:o.transform(0,-1,1,0,0,e)}return o.drawImage(t,0,0,e,s),Pt(t),n}function Qt(t,i,e=0){return new Promise((function(s,n){let o,r,h,l,c,a,f,d,u,v,p,b,g,w,y,k,x,m,z,A;function M(t=5){if(i.signal&&i.signal.aborted)throw i.signal.reason;o+=t,i.onProgress(Math.min(o,100))}function C(t){if(i.signal&&i.signal.aborted)throw i.signal.reason;o=Math.min(Math.max(t,o),100),i.onProgress(o)}return o=e,r=i.maxIteration||10,h=1024*i.maxSizeMB*1024,M(),Bt(t,i).then(function(e){try{return[,l]=e,M(),c=Dt(l,i),M(),new Promise((function(e,s){var n;if(!(n=i.exifOrientation))return $t(t).then(function(t){try{return n=t,o.call(this)}catch(t){return s(t)}}.bind(this),s);function o(){return e(n)}return o.call(this)})).then(function(e){try{return a=e,M(),Ot().then(function(e){try{return f=e?c:Rt(c,a),M(),d=i.initialQuality||1,u=i.fileType||t.type,Ut(f,u,t.name,t.lastModified,d).then(function(e){try{{if(v=e,M(),p=v.size>h,b=v.size>t.size,!p&&!b)return C(100),s(v);var o;function a(){if(r--&&(y>h||y>g)){let i,e;return i=A?.95*z.width:z.width,e=A?.95*z.height:z.height,[x,m]=jt(i,e),m.drawImage(z,0,0,i,e),d*="image/png"===u?.85:.95,Ut(x,u,t.name,t.lastModified,d).then((function(t){try{return k=t,Pt(z),z=x,y=k.size,C(Math.min(99,Math.floor((w-y)/(w-h)*100))),a}catch(t){return n(t)}}),n)}return[1]}return g=t.size,w=v.size,y=w,z=f,A=!i.alwaysKeepResolution&&p,(o=function(t){for(;t;){if(t.then)return void t.then(o,n);try{if(t.pop){if(t.length)return t.pop()?T.call(this):t;t=a}else t=t.call(this)}catch(t){return n(t)}}}.bind(this))(a);function T(){return Pt(z),Pt(x),Pt(c),Pt(f),Pt(l),C(100),s(k)}}}catch(E){return n(E)}}.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 _t="\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 Lt;function Wt(t,i){return new Promise(((e,s)=>{Lt||(Lt=function t(i){const e=[];return e.push(i),URL.createObjectURL(new Blob(e))}(_t));const n=new Worker(Lt);n.addEventListener("message",(function t(o){if(i.signal&&i.signal.aborted)n.terminate();else if(void 0===o.data.progress){if(o.data.error)return s(new Error(o.data.error)),void n.terminate();e(o.data.file),n.terminate()}else i.onProgress(o.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 Ht(t,i){return new Promise((function(e,s){let n,o,r,h,l,c;if(n={...i},r=0,({onProgress:h}=n),n.maxSizeMB=n.maxSizeMB||Number.POSITIVE_INFINITY,l="boolean"!=typeof n.useWebWorker||n.useWebWorker,delete n.useWebWorker,n.onProgress=t=>{r=t,"function"==typeof h&&h(r)},!(t instanceof Blob||t instanceof zt))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(c="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!l||"function"!=typeof Worker||c)return Qt(t,n).then(function(t){try{return o=t,d.call(this)}catch(t){return s(t)}}.bind(this),s);var a=function(){try{return d.call(this)}catch(t){return s(t)}}.bind(this),f=function(i){try{return Qt(t,n).then((function(t){try{return o=t,a()}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",Wt(t,n).then((function(t){try{return o=t,a()}catch(t){return f()}}),f)}catch(t){f()}function d(){try{o.name=t.name,o.lastModified=t.lastModified}catch(t){}try{n.preserveExif&&"image/jpeg"===t.type&&(!n.fileType||n.fileType&&n.fileType===t.type)&&(o=ft(t,o))}catch(t){}return e(o)}}))}Ht.getDataUrlFromFile=Ct,Ht.getFilefromDataUrl=Mt,Ht.loadImage=Tt,Ht.drawImageInCanvas=It,Ht.drawFileInCanvas=Bt,Ht.canvasToFile=Ut,Ht.getExifOrientation=$t,Ht.handleMaxWidthOrHeight=Dt,Ht.followExifOrientation=Rt,Ht.cleanupCanvasMemory=Pt,Ht.isAutoOrientationInBrowser=Ot,Ht.approximateBelowMaximumCanvasSizeOfBrowser=St,Ht.copyExifWithoutOrientation=ft,Ht.getBrowserName=Et,Ht.version="2.0.2";class Kt extends j{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];Ht(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 o=Math.min(s,n);i=t.width*o;e=t.height*o}return{scaledWidth:i,scaledHeight:e}}createKritzelImage(t,i,e){const s=X.create(this._store);s.src=t.src;s.width=i;s.height=e;s.zIndex=this._store.currentZIndex;s.centerInViewport();return s}addImageToStore(t){const i=ct.create(this._store);i.addOrRemove(t);i.selected=true;const e=new k(this._store,this,t);const s=new ot(this._store,this,i);this._store.history.executeCommand(new H(this._store,this,[e,s]));this._store.setState("activeTool",F.getTool("selection"))}handleCancel(){this._store.setState("activeTool",F.getTool("selection"))}}const Vt={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 Xt={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 Yt=[{name:"selection",type:"tool",tool:ht,icon:"cursor"},{name:"brush",type:"tool",tool:I,isDefault:true,icon:"pen",config:Vt},{name:"eraser",type:"tool",tool:V,icon:"eraser"},{name:"text",type:"tool",tool:P,icon:"type",config:Xt},{name:"image",type:"tool",tool:Kt,icon:"image"},{name:"divider",type:"divider"},{name:"config",type:"config"}];const Nt="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;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}kritzel-controls{position:absolute;bottom:28px}";const Gt=class{constructor(i){t(this,i);this.controls=Yt;this.customSvgIcons={};this.hideControls=false}handleTouchStart(t){if(t.cancelable){t.preventDefault()}}handleKeyDown(t){var i;t.preventDefault();if(t.key==="Escape"){(i=this.controlsRef)===null||i===void 0?void 0:i.closeTooltip()}}componentWillLoad(){this.registerCustomSvgIcons()}registerCustomSvgIcons(){for(const[t,i]of Object.entries(this.customSvgIcons)){W.register(t,i)}}render(){return e(s,{key:"b861ac259f78cf3a4a7070ce2e54a731414a8c08"},e("kritzel-engine",{key:"026f2caba18bce0b0453b904616d9baa455592d9",ref:t=>this.engineRef=t}),e("kritzel-controls",{key:"afc78be61bfddeafd3650f7a383ad4a1847fa3b5",ref:t=>this.controlsRef=t,controls:this.controls,style:this.hideControls?{display:"none"}:{display:"flex"}}))}get host(){return n(this)}};Gt.style=Nt;class qt{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()}handlePointerDown(t){if(t.pointerType==="mouse"){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;if(t.button===g.Right){this._store.state.isPanning=true;this._store.state.startX=i;this._store.state.startY=e}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());if(t.length===2){this._store.state.currentPath=null;this._store.state.isScaling=true;const i=t[0].clientX-this._store.offsetX;const e=t[0].clientY-this._store.offsetY;const s=t[1].clientX-this._store.offsetX;const n=t[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()}}}handlePointerMove(t){if(t.pointerType==="mouse"){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()}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());if(t.length===2){const i=t[0].clientX-this._store.offsetX;const e=t[0].clientY-this._store.offsetY;const s=t[1].clientX-this._store.offsetX;const n=t[1].clientY-this._store.offsetY;const o=Math.sqrt(Math.pow(i-s,2)+Math.pow(e-n,2));const r=(i+s)/2;const h=(e+n)/2;const l=o/this.initialTouchDistance;const c=this._store.state.scale*l;if(c>this._store.state.scaleMax||c<this._store.state.scaleMin){this._store.state.translateX+=r-this.startX;this._store.state.translateY+=h-this.startY}else{const t=(r-this._store.state.translateX)*(l-1);const i=(h-this._store.state.translateY)*(l-1);this._store.state.translateX+=r-this.startX-t;this._store.state.translateY+=h-this.startY-i;this._store.state.scale=c;this.initialTouchDistance=o}this.startX=r;this.startY=h;this._store.state.hasViewportChanged=true;this._store.rerender()}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._store.state.isPanning){this._store.state.isPanning=false;this._store.rerender()}}if(t.pointerType==="touch"){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 o=(this._store.state.cursorX-this._store.state.translateX)*(n-1);const r=(this._store.state.cursorY-this._store.state.translateY)*(n-1);this._store.state.scale=s;this._store.state.translateX-=o;this._store.state.translateY-=r;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 Zt 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 Jt{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 ti{constructor(t){this._store=t;this.undoStack=new Jt(this._store.state.historyBufferSize);this.redoStack=new Jt(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 Zt(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 Zt(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 ii{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:o}=this.bounds;const r=s/2;const h=n/2;const l=o/2;this.children=[new ii({x:t,y:i,z:e,width:r,height:h,depth:l},this.capacity),new ii({x:t+r,y:i,z:e,width:r,height:h,depth:l},this.capacity),new ii({x:t,y:i+h,z:e,width:r,height:h,depth:l},this.capacity),new ii({x:t+r,y:i+h,z:e,width:r,height:h,depth:l},this.capacity),new ii({x:t,y:i,z:e+l,width:r,height:h,depth:l},this.capacity),new ii({x:t+r,y:i,z:e+l,width:r,height:h,depth:l},this.capacity),new ii({x:t,y:i+h,z:e+l,width:r,height:h,depth:l},this.capacity),new ii({x:t+r,y:i+h,z:e+l,width:r,height:h,depth:l},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 ei 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 si={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,longTouchTimeout:null,longTouchDelay:300,pointers:new Map};class ni{get history(){return this._history}get state(){return this._state}get currentZIndex(){return this._state.objectsOctree.filter((t=>!(t instanceof ct)&&!(t instanceof nt))).length}get allObjects(){return this._state.objectsOctree.allObjects()}get selectedObjects(){return this.allObjects.filter((t=>!(t instanceof ct))).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=si;this._kritzelEngine=t;this._history=new ti(this);this._state.objectsOctree=new ii({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 Y(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))))}}}delete(){if(!this.state.selectionGroup){return}const t=this.state.selectionGroup.objects.map((t=>new K(this,this.state.selectionGroup,t)));const i=new Y(this,this.state.selectionGroup);const e=[...t,i];this.history.executeCommand(new H(this,this.state.selectionGroup,e))}deleteObject(t,i=true){const e=this.findObjectById(t);if(e){if(i){const t=new K(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 Y(this,this.state.selectionGroup))}const o=this.state.copiedObjects.objects.map((t=>new k(this,this,t)));const r=new ot(this,this,this.state.copiedObjects);n.push(...o,r);this.history.executeCommand(new H(this,this,n));this.state.isSelecting=false;this.state.copiedObjects=this.state.selectionGroup.copy();this.setState("activeTool",F.getTool("selection"))}moveUp(){const t=this.allObjects.length+1;const i=this.state.selectionGroup.objects.map((i=>{if(i.zIndex===t){return}return new ei(this,this,i,{zIndex:i.zIndex+1})}));this.history.executeCommand(new H(this,this,i))}moveDown(){const t=0;const i=this.state.selectionGroup.objects.map((i=>{if(i.zIndex===t){return}return new ei(this,this,i,{zIndex:i.zIndex-1})}));this.history.executeCommand(new H(this,this,i))}moveToTop(){const t=this.allObjects.length+1;const i=this.state.selectionGroup.objects.map((i=>new ei(this,this,i,{zIndex:t})));this.history.executeCommand(new H(this,this,i))}moveToBottom(){const t=-1;const i=this.state.selectionGroup.objects.map((i=>new ei(this,this,i,{zIndex:t})));this.history.executeCommand(new H(this,this,i))}selectObjects(t){if(t.length===0){return}const i=ct.create(this);t.forEach((t=>{t.selected=false;i.addOrRemove(t)}));i.selected=true;this.state.selectionGroup=i;if(t.length===1){i.rotation=i.objects[0].rotation}this.history.executeCommand(new ot(this,this,i))}selectAllObjectsInViewport(){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 ct)&&!(t instanceof nt)&&!(t instanceof d)));if(t.length>0){const i=ct.create(this);t.forEach((t=>{t.selected=false;i.addOrRemove(t)}));i.selected=true;this.state.isSelecting=false;if(t.length===1){i.rotation=i.objects[0].rotation}this.history.executeCommand(new ot(this,this,i));this.setState("activeTool",F.getTool("selection"))}}clearSelection(){const t=new Y(this,this.state.selectionGroup);this.history.executeCommand(t);this.state.selectionGroup=null;this.state.selectionBox=null;this.state.isSelecting=false;this.state.isResizeHandleSelected=false;this.state.isRotationHandleSelected=false}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 o;if("touches"in t){const i=t.touches[0];if(!i)return null;n=i.clientX;o=i.clientY}else{n=t.clientX;o=t.clientY}const r=s.elementFromPoint(n,o);if(!r)return null;const h=r.closest(i);if(h){return this.allObjects.find((t=>h.id===t.id))}return null}}class oi extends G{constructor(t){super(t)}handleKeyDown(t){if(this._store.state.isFocused===false){return}t.preventDefault();this._store.state.isCtrlKeyPressed=t.ctrlKey;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",F.getTool("selection"));this._store.deselectAllObjects()}if(t.key==="b"&&t.ctrlKey){this._store.setState("activeTool",F.getTool("brush"));this._store.deselectAllObjects()}if(t.key==="e"&&t.ctrlKey){this._store.setState("activeTool",F.getTool("eraser"));this._store.deselectAllObjects()}if(t.key==="i"&&t.ctrlKey){this._store.setState("activeTool",F.getTool("image"));this._store.deselectAllObjects()}if(t.key==="x"&&t.ctrlKey){this._store.setState("activeTool",F.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 ri extends G{constructor(t,i,e){super(t);this.globalContextMenuItems=[];this.objectContextMenuItems=[];this.globalContextMenuItems=i;this.objectContextMenuItems=e}handleContextMenu(t){if(this._store.state.skipContextMenu){this._store.state.skipContextMenu=false;return}const i=this._store.getObjectFromPointerEvent(t,".object");if(i&&!(i instanceof ct)){this._store.state.selectionGroup=ct.create(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 ot(this._store,this,this._store.state.selectionGroup))}this._store.state.contextMenuItems=this._store.state.selectionGroup?this.objectContextMenuItems:this.globalContextMenuItems;let e=t.clientX-this._store.offsetX;let s=t.clientY-this._store.offsetY;const n=150;const o=200;const r=10;if(e+n>window.innerWidth-r){e=window.innerWidth-n-r}if(s+o>window.innerHeight-r){s=window.innerHeight-o-r}e=Math.max(r,e);s=Math.max(r,s);this._store.state.contextMenuX=e;this._store.state.contextMenuY=s;this._store.state.isContextMenuVisible=true;this._store.state.isEnabled=false;this._store.rerender()}}const hi=":host{display:block;position:relative;height:100%;width:100%;overflow:hidden;background-color:var(--kritzel-engine-background-color, #ffffff)}:host,:host *{touch-action:none;user-select:none}.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 li=class{get isSelecting(){return this.store.state.activeTool instanceof ht&&this.store.state.isSelecting}get isSelectionActive(){return this.store.state.activeTool instanceof ht&&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.selectAllObjectsInViewport()}];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 ni(this);this.contextMenuHandler=new ri(this.store,this.globalContextMenuItems,this.objectContextMenuItems);this.keyHandler=new oi(this.store);this.store.onStateChange("activeTool",(t=>{if(!(t instanceof ht)){this.store.clearSelection()}this.store.state.skipContextMenu=false;this.activeToolChange.emit(t);U.forceHideKeyboard()}));this.store.onStateChange("isFocused",(t=>{if(!t){this.store.resetActiveText()}}))}componentDidLoad(){this.viewport=new qt(this.store,this.host);this.engineReady.emit()}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)}handlePointerDown(t){var i,e;if(w.isPointerEventOnContextMenu(t)===false&&this.store.state.isContextMenuVisible){this.hideContextMenu();return}if(this.store.state.isEnabled===false){return}w.onLongTouchPress(t,(t=>{if(!(this.store.state.activeTool instanceof ht)){return}this.contextMenuHandler.handleContextMenu(t)}));this.host.setPointerCapture(t.pointerId);this.store.state.pointers.set(t.pointerId,t);this.viewport.handlePointerDown(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handlePointerDown(t)}handlePointerMove(t){var i,e;if(this.store.state.isEnabled===false){return}this.store.state.pointers.set(t.pointerId,t);this.viewport.handlePointerMove(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handlePointerMove(t)}handlePointerUp(t){var i,e;if(this.store.state.isEnabled===false){return}this.store.state.pointers.delete(t.pointerId);this.host.releasePointerCapture(t.pointerId);this.viewport.handlePointerUp(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handlePointerUp(t)}handlePointerCancel(t){var i,e;if(this.store.state.isEnabled===false){return}this.host.releasePointerCapture(t.pointerId);this.store.state.pointers.delete(t.pointerId);this.viewport.handlePointerUp(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handlePointerUp(t)}handleContextMenu(t){t.preventDefault();if(this.store.state.isEnabled===false){return}if(t.pointerType==="touch"){return}this.contextMenuHandler.handleContextMenu(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 o=s.includes(n||this.host);this.store.setState("isFocused",e&&o)}handleContextMenuAction(t){t.detail.action();this.hideContextMenu()}async registerTool(t,i,e){if(typeof i!=="function"||!(i.prototype instanceof j)){console.error(`Failed to register tool "${t}": Tool class must be a constructor function`);return null}const s=F.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 undo(){this.store.history.undo()}async redo(){this.store.history.redo()}async hideContextMenu(){this.store.state.pointers.clear();this.store.state.isContextMenuVisible=false;this.store.state.selectionBox=null;this.store.state.isSelecting=false}async getObjectById(t){const i=this.store.objects.find((i=>i.id===t));return i||null}async addObject(t){this.store.deselectAllObjects();t.id=t.generateId();t._store=this.store;t.zIndex=this.store.currentZIndex;const i=new k(this.store,this,t);this.store.history.executeCommand(i);return t}async updateObject(t,i){this.store.deselectAllObjects();const e=new ei(this.store,this,t,i);this.store.history.executeCommand(e);return t}async removeObject(t){this.store.deselectAllObjects();const i=new K(this.store,this,t);this.store.history.executeCommand(i);return t}async selectObjects(t){var i;(i=this.store.state.activeTool)===null||i===void 0?void 0:i.onDeactivate();this.store.setState("activeTool",F.getTool("selection"));this.store.deselectAllObjects();this.store.selectObjects(t)}async selectAllObjectsInViewport(){var t;(t=this.store.state.activeTool)===null||t===void 0?void 0:t.onDeactivate();this.store.setState("activeTool",F.getTool("selection"));this.store.deselectAllObjects();this.store.selectAllObjectsInViewport()}async clearSelection(){this.store.clearSelection()}render(){var t,i,n,o,r,h,l,c,a,f,d,u,v,p,b,g,w,y,k,x,m,z,A,M,C,T,E;const j=window.getComputedStyle(this.host);const I=j.getPropertyValue("--kritzel-selection-handle-size").trim()||"6px";const F=parseFloat(I);const U=F*2<14?14:F;return e(s,{key:"632d8633bd27520dedda2e6eb84862d280fa6714"},e("div",{key:"fda3cdc033d97e1f17ae8fcede94933ae73458b3",class:"debug-panel",style:{display:this.store.state.debugInfo.showViewportInfo?"block":"none"}},e("div",{key:"823aac3e9b58615e7c499163bd9101675a62ff70"},"TranslateX: ",(t=this.store.state)===null||t===void 0?void 0:t.translateX),e("div",{key:"5d138212f0fefcaea7dc839f6d5f3e9c68c19681"},"TranslateY: ",(i=this.store.state)===null||i===void 0?void 0:i.translateY),e("div",{key:"8342eabd22ba71b58fe8346a182904cf5f4ccbb9"},"ViewportWidth: ",(n=this.store.state)===null||n===void 0?void 0:n.viewportWidth),e("div",{key:"325546fc07c2cfec7808e661d82f21db06d53aea"},"ViewportHeight: ",(o=this.store.state)===null||o===void 0?void 0:o.viewportHeight),e("div",{key:"2b1826604f561c58ad573d5545a0913498345b1f"},"ObjectsInViewport. ",this.store.objects.length),e("div",{key:"749b56a6bfd63c838c89c55595bedd6749ee89ad"},"Scale: ",(r=this.store.state)===null||r===void 0?void 0:r.scale),e("div",{key:"0ee63c810198cb583c4e419f14503f5fb8d71d32"},"ActiveTool: ",(l=(h=this.store.state)===null||h===void 0?void 0:h.activeTool)===null||l===void 0?void 0:l.name),e("div",{key:"5facf47db6f093db24b12fa4b4453d20af1b1f57"},"HasViewportChanged: ",((c=this.store.state)===null||c===void 0?void 0:c.hasViewportChanged)?"true":"false"),e("div",{key:"948069683ac1568257dab4dbd5d1b3e9926ac501"},"IsEnabled: ",((a=this.store.state)===null||a===void 0?void 0:a.isEnabled)?"true":"false"),e("div",{key:"a3e5bf4522b9d515bc7d346dbc9803af12eb60f5"},"IsScaling: ",((f=this.store.state)===null||f===void 0?void 0:f.isScaling)?"true":"false"),e("div",{key:"ce8fc21cd938e7a58fef489b086b5111b1612353"},"IsPanning: ",((d=this.store.state)===null||d===void 0?void 0:d.isPanning)?"true":"false"),e("div",{key:"5725282e17bbe0766ebe010377070df81c1542d2"},"IsFocused: ",this.store.state.isFocused?"true":"false"),e("div",{key:"8805bbfac86078d2a0541d60a53a3c6a9585a1db"},"IsSelecting: ",this.isSelecting?"true":"false"),e("div",{key:"1801d4d8297e36f4c14022c411ce5a1889042398"},"IsSelectionActive: ",this.isSelectionActive?"true":"false"),e("div",{key:"d269982265e35a511eeb892969b3e47eb21b023f"},"IsResizeHandleSelected: ",this.store.state.isResizeHandleSelected?"true":"false"),e("div",{key:"1362e4c3d93a8452705e5fb1a1ba6a0ffdb3c557"},"IsRotationHandleSelected: ",this.store.state.isRotationHandleSelected?"true":"false"),e("div",{key:"2181e07738e56e10c57c4d6a06acdd667a14da83"},"IsDrawing: ",this.store.state.isDrawing?"true":"false"),e("div",{key:"57b96821b4fb1cbc97ec7083fc523c0bdba7539b"},"IsWriting: ",this.store.state.isWriting?"true":"false"),e("div",{key:"c7302e6ce4635e04aa92a24878dd3cbce8724228"},"CursorX: ",(u=this.store.state)===null||u===void 0?void 0:u.cursorX),e("div",{key:"93b01e5d147ca445e6645749043bb7fb46852f39"},"CursorY: ",(v=this.store.state)===null||v===void 0?void 0:v.cursorY)),e("div",{key:"7b535830bbd75ca61e09d6984120e17168911d7d",class:"origin",style:{transform:`matrix(${(p=this.store.state)===null||p===void 0?void 0:p.scale}, 0, 0, ${(b=this.store.state)===null||b===void 0?void 0:b.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,o,r,h,l,c,a,f,d,u,v,p,b,g,w,y,k;return e("div",{style:{transform:t===null||t===void 0?void 0:t.transformationMatrix,transformOrigin:"top left",zIndex:t.zIndex.toString(),position:"absolute"}},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"}},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 S&&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 X&&e("img",{ref:i=>t.mount(i),src:t.src,style:{width:"100%",height:"100%",userSelect:"none",pointerEvents:"none"},draggable:false,onDragStart:t=>t.preventDefault()}),t instanceof B&&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",pointerEvents:t.isReadonly?"none":"auto",cursor:t.isReadonly?"default":"text",caretColor:t.isReadonly?"transparent":"auto"}}),t instanceof ct&&e("div",{ref:i=>t.mount(i),style:{width:"100%",height:"100%"}}),t instanceof nt&&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} / ${(o=this.store.state)===null||o===void 0?void 0:o.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} / ${(r=this.store.state)===null||r===void 0?void 0:r.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:`${U*t.scale/((l=this.store.state)===null||l===void 0?void 0:l.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/((c=this.store.state)===null||c===void 0?void 0:c.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:`${U*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 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:`${U*t.scale/((d=this.store.state)===null||d===void 0?void 0:d.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/((u=this.store.state)===null||u===void 0?void 0:u.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:`${U*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/((p=this.store.state)===null||p===void 0?void 0:p.scale)),style:{stroke:"var(--kritzel-selection-border-color, #0e1111)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${(b=this.store.state)===null||b===void 0?void 0:b.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:`${U*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:"cce82d436a044879bfbb900a836978c392f232ae",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:(z=this.store.state.currentPath)===null||z===void 0?void 0:z.transformationMatrix,transformOrigin:"top left",overflow:"visible"},viewBox:(A=this.store.state.currentPath)===null||A===void 0?void 0:A.viewBox},e("path",{key:"1c0366598a805faffc965824c30c05fe1f1e0f74",d:(M=this.store.state.currentPath)===null||M===void 0?void 0:M.d,fill:(C=this.store.state.currentPath)===null||C===void 0?void 0:C.fill,stroke:(T=this.store.state.currentPath)===null||T===void 0?void 0:T.stroke}))),this.store.state.isContextMenuVisible&&e("kritzel-context-menu",{key:"624855529efbe7a5de784e3e1ce2b82282fac63a",class:"context-menu",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)}),((E=this.store.state)===null||E===void 0?void 0:E.activeTool)instanceof V&&!this.store.state.isScaling&&e("kritzel-cursor-trail",{key:"d09a4701c43b8acec4e9daa09b69f545eebe95b7",store:this.store}))}get host(){return n(this)}};li.style=hi;const ci=":host{display:block}.font-preview{color:var(--kritzel-font-size-text-color, #333333);line-height:1;text-align:center;font-weight:bold}";const ai=class{constructor(i){t(this,i);this.fontFamily="Arial, sans-serif";this.size=24;this.color="#000000"}render(){return e(s,{key:"d0378237899c5641ae4354f3bffb14e3f8bafb59"},e("div",{key:"1475a6ae39ffc97eb780b30c85015c22cecafa6e",class:"font-preview",style:{fontFamily:this.fontFamily,fontSize:`${this.size}px`,color:this.color}},"A"))}};ai.style=ci;const fi=":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 di=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:"f420ff18156d54bfc475148a7d9aae0f1441408c"},e("kritzel-dropdown",{key:"6b54fb8265a0eb59a6a681c6a2b7a95fb222671c",options:t,value:this.selectedFontFamily,onValueChanged:this.handleDropdownValueChange,selectStyles:{fontFamily:this.selectedFontFamily}},e("button",{key:"b853c75a425c7baafa7a8e749c90c0b08884375c",class:"font-style-button",slot:"suffix"},"B"),e("button",{key:"68dea850dd1d1f38db727d8be0eec3481890c571",class:"font-style-button italic-text",slot:"suffix"},"I")))}};di.style=fi;const ui=":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 vi=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:"1c09a403f1e8278d30b2675c3a6e17e12ec79afa"},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})))))}};vi.style=ui;const pi=":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 bi=class{constructor(i){t(this,i);this.size=24}render(){const t=W.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}))}};bi.style=pi;const gi=":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 wi=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})))))}};wi.style=gi;const yi=":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 ki=768;const xi=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<ki}handleWindowResize(){this.isMobileView=window.innerWidth<ki;this.calculateAdjustedPosition()}componentWillLoad(){this.isMobileView=window.innerWidth<ki;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:"3161826337f6957d2e568f52cfe3f57d705af0ed",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:"12fc4bc05b7be756102ce3779c9be1d51f3fe13b",class:"tooltip-content",onClick:t=>t.stopPropagation()},e("slot",{key:"90f645f8f7cec371aaeda7207a9fb420b02b2ae4"}),e("div",{key:"73380e2c6df22bc4a97479a52315e7b34d069fa1",class:"tooltip-arrow-wrapper",style:{position:"fixed",left:this.arrowOffset,bottom:`-${this.arrowSize*2}px`}},e("div",{key:"2e13cb01a3282e161d3212f4970a93b20ca1a0fe",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:"30ddbd00b928c0c734656d6309eaefbae5baf264",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)}};xi.style=yi;const mi=":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 zi=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()})))}};zi.style=mi;export{r as kritzel_brush_style,l as kritzel_color,a as kritzel_color_palette,d as kritzel_context_menu,v as kritzel_control_brush_config,b as kritzel_control_text_config,D as kritzel_controls,Q as kritzel_cursor_trail,L as kritzel_dropdown,Gt as kritzel_editor,li as kritzel_engine,ai as kritzel_font,di as kritzel_font_family,vi as kritzel_font_size,bi as kritzel_icon,wi as kritzel_stroke_size,xi as kritzel_tooltip,zi as kritzel_utility_panel};
2
- //# sourceMappingURL=p-65e86254.entry.js.map
1
+ import{r as t,c as i,h as e,H as s,a as n}from"./p-BOJOOWaP.js";const o=":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 r=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:"d7af382fe6f613aa16a5146785990ad2faa17f60"},e("kritzel-dropdown",{key:"6d6d330d415c210058834b2968774b3db2ab7fc4",options:t,value:this.type,onValueChanged:t=>this.handleDropdownValueChange(t)},e("button",{key:"c9fb33795b8e25f68c1d2ae248dc82a6de29e199",class:"brush-style-button",slot:"prefix"},e("kritzel-icon",{key:"975c95b545a1c27ae2984405ac298592eec9743d",name:this.type,size:16}))))}};r.style=o;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 l=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 o=.299*i+.587*e+.114*s;return o>220}render(){const t=this.isLightColor(this.value);return e(s,{key:"19ad3872a132c885c612dc3b96698a0c8dc7214d"},e("div",{key:"f67108e82396cbaa3d070c8dfc83da2b080ddf47",class:"checkerboard-bg",style:{width:`${this.size}px`,height:`${this.size}px`,borderRadius:"50%",display:"inline-block",position:"relative"}},e("div",{key:"1af0cc3e9f6eebc04cae2367510ef3b98420a818",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"}})))}};l.style=h;const c=":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 a=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}))))))}};a.style=c;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 d=class{constructor(e){t(this,e);this.actionSelected=i(this,"actionSelected")}handleItemClick(t){const i=typeof t.disabled==="function"?t.disabled():t.disabled;if(!i){this.actionSelected.emit(t)}}render(){return e(s,{key:"92cf80d71faae3e33bc29d9e9b3a81b4b6ee6c87"},e("div",{key:"838734ed3f1e3af86a5db7312c2206e90835a8f0",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)}};d.style=f;const u=":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:"8e7930fcc093f7277ed088d8ec5e54e4cd051b86"},e("div",{key:"08bd37b90decc9054c05d646aabbba0a4985d04c",style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-start",width:"100%",gap:"8px"}},e("kritzel-brush-style",{key:"f79744fb6523d0b4fa67c324cbf8ff3eb8a0308d",type:this.tool.type,onTypeChange:t=>this.handleTypeChange(t)}),e("button",{key:"dc3bdd90cebb29f2357e13dbc8d2dcaf02ae056e",class:"expand-toggle",onClick:()=>this.handleToggleExpand(),title:this.isExpanded?"Collapse":"Expand",style:this.palette.length>6?{visibillity:"visible"}:{visibility:"hidden"}},e("kritzel-icon",{key:"6e9e6de7fc7c708aad700498e030d2ad7364a9f3",name:this.isExpanded?"chevron-up":"chevron-down"}))),e("kritzel-color-palette",{key:"c1ffd48a475754bb1447e9d866b494fd3476f050",colors:this.palette,selectedColor:this.tool.color,isExpanded:this.isExpanded,isOpaque:true,onColorChange:t=>this.handleColorChange(t)}),e("kritzel-stroke-size",{key:"38e265b42fe09d0105e0385d7ec8e7d8d318abb0",selectedSize:this.tool.size,onSizeChange:t=>this.handleSizeChange(t)}))}static get watchers(){return{tool:["handleToolChange"]}}};v.style=u;const p=":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 b=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)}))}};b.style=p;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 isPointerEventOnContextMenu(t){const i=t.composedPath();const e=i.find((t=>t.classList&&t.classList.contains("context-menu")));return!!e}static onLongTouchPress(t,i,e){if(t.pointerType!=="touch"){e===null||e===void 0?void 0:e();return()=>{}}const s=400;const n=10;const o=t.clientX;const r=t.clientY;const h=t.target;const l=setTimeout((()=>{u();i(t)}),s);const c=()=>{clearTimeout(l);u();e===null||e===void 0?void 0:e()};const a=t=>{if(Math.abs(t.clientX-o)>n||Math.abs(t.clientY-r)>n){c()}};const f=()=>{c()};const d=()=>{c()};const u=()=>{h.removeEventListener("pointermove",a);h.removeEventListener("pointerup",f);h.removeEventListener("pointercancel",d)};h.addEventListener("pointermove",a,{passive:true});h.addEventListener("pointerup",f,{once:true});h.addEventListener("pointercancel",d,{once:true});return c}}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 z(){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:()=>E,getStroke:()=>T,getStrokeOutlinePoints:()=>M,getStrokePoints:()=>C});function n(t,i,e,s=t=>t){return t*s(.5-i*(.5-e))}function o(t){return[-t[0],-t[1]]}function r(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 l(t,i){return[t[0]*i,t[1]*i]}function c(t,i){return[t[0]/i,t[1]/i]}function a(t){return[t[1],-t[0]]}function f(t,i){return t[0]*i[0]+t[1]*i[1]}function d(t,i){return t[0]===i[0]&&t[1]===i[1]}function u(t){return Math.hypot(t[0],t[1])}function v(t){return t[0]*t[0]+t[1]*t[1]}function p(t,i){return v(h(t,i))}function b(t){return c(t,u(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),o=t[0]-i[0],r=t[1]-i[1],h=o*n-r*s,l=o*s+r*n;return[h+i[0],l+i[1]]}function y(t,i,e){return r(t,l(h(i,t),e))}function k(t,i,e){return r(t,l(i,e))}var{min:x,PI:m}=Math,z=.275,A=m+1e-4;function M(t,i={}){let{size:e=16,smoothing:s=.5,thinning:c=.5,simulatePressure:d=true,easing:u=t=>t,start:v={},end:g={},last:m=false}=i,{cap:M=true,easing:C=t=>t*(2-t)}=v,{cap:T=true,easing:E=t=>--t*t*t+1}=g;if(t.length===0||e<=0)return[];let S=t[t.length-1].runningLength,j=v.taper===false?0:v.taper===true?Math.max(e,S):v.taper,I=g.taper===false?0:g.taper===true?Math.max(e,S):g.taper,F=Math.pow(e*s,2),B=[],U=[],P=t.slice(0,10).reduce(((t,i)=>{let s=i.pressure;if(d){let n=x(1,i.distance/e),o=x(1,1-n);s=x(1,t+(o-t)*(n*z))}return(t+s)/2}),t[0].pressure),O=n(e,c,t[t.length-1].pressure,u),$,D=t[0].vector,R=t[0].point,Q=R,_=R,L=Q,W=false;for(let i=0;i<t.length;i++){let{pressure:s}=t[i],{point:o,vector:v,distance:b,runningLength:g}=t[i];if(i<t.length-1&&S-g<3)continue;if(c){if(d){let t=x(1,b/e),i=x(1,1-t);s=x(1,P+(i-P)*(t*z))}O=n(e,c,s,u)}else O=e/2;$===void 0&&($=O);let k=g<j?C(g/j):1,m=S-g<I?E((S-g)/I):1;O=Math.max(.01,O*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,D)<0&&!W,K=T!==null&&T<0;if(H||K){let t=l(a(D),O);for(let i=1/13,e=0;e<=1;e+=i)_=w(h(o,t),o,A*e),B.push(_),L=w(r(o,t),o,A*-e),U.push(L);R=_,Q=L,K&&(W=true);continue}if(W=false,i===t.length-1){let t=l(a(v),O);B.push(h(o,t)),U.push(r(o,t));continue}let V=l(a(y(M,v,T)),O);_=h(o,V),(i<=1||p(R,_)>F)&&(B.push(_),R=_),L=r(o,V),(i<=1||p(Q,L)>F)&&(U.push(L),Q=L),P=s,D=v}let H=t[0].point.slice(0,2),K=t.length>1?t[t.length-1].point.slice(0,2):r(t[0].point,[1,1]),V=[],X=[];if(t.length===1){if(!(j||I)||m){let t=k(H,b(a(h(H,K))),-($||O)),i=[];for(let e=1/13,s=e;s<=1;s+=e)i.push(w(t,H,A*2*s));return i}}else{if(!(j||I&&t.length===1))if(M)for(let t=1/13,i=t;i<=1;i+=t){let t=w(U[0],H,A*i);V.push(t)}else{let t=h(B[0],U[0]),i=l(t,.5),e=l(t,.51);V.push(h(H,i),h(H,e),r(H,e),r(H,i))}let i=a(o(t[t.length-1].vector));if(I||j&&t.length===1)X.push(K);else if(T){let t=k(K,i,O);for(let i=1/29,e=i;e<1;e+=i)X.push(w(t,K,A*3*e))}else X.push(r(K,l(i,O)),r(K,l(i,O*.99)),h(K,l(i,O*.99)),h(K,l(i,O)))}return B.concat(X,U.reverse(),V)}function C(t,i={}){var e;let{streamline:s=.5,size:n=16,last:o=false}=i;if(t.length===0)return[];let l=.15+(1-s)*.85,c=Array.isArray(t[0])?t:t.map((({x:t,y:i,pressure:e=.5})=>[t,i,e]));if(c.length===2){let t=c[1];c=c.slice(0,-1);for(let i=1;i<5;i++)c.push(y(c[0],t,i/4))}c.length===1&&(c=[...c,[...r(c[0],[1,1]),...c[0].slice(2)]]);let a=[{point:[c[0][0],c[0][1]],pressure:c[0][2]>=0?c[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],f=false,u=0,v=a[0],p=c.length-1;for(let t=1;t<c.length;t++){let i=o&&t===p?c[t].slice(0,2):y(v.point,c[t],l);if(d(v.point,i))continue;let e=g(i,v.point);if(u+=e,t<p&&!f){if(u<n)continue;f=true}v={point:i,pressure:c[t][2]>=0?c[t][2]:.5,vector:b(h(v.point,i)),distance:e,runningLength:u},a.push(v)}return a[0].vector=((e=a[1])==null?void 0:e.vector)||[0,0],a}function T(t,i={}){return M(C(t,i),i)}var E=T})(x);return x}var A=z();class M{static average(t,i){return(t+i)/2}}var C=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 T{static generateUUID(){return Math.random().toString(36).substr(2,9)}static clone(t){const i=t=>{const i=C(t,["_store","_elementRef","totalWidth","totalHeight"]);return structuredClone(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 E{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 o={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 r=Object.keys(o).reduce(((s,n)=>{const r=o[n];const h=Math.cos(e)*(r.x-t)-Math.sin(e)*(r.y-i)+t;const l=Math.sin(e)*(r.x-t)+Math.cos(e)*(r.y-i)+i;s[n]={x:h,y:l};return s}),{});return r}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(){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.id=this.generateId()}static create(t){const i=new E;i._store=t;i.zIndex=t.currentZIndex;return i}mount(t){if(this.isMounted){return}this.elementRef=t;this.isMounted=true}generateId(){return T.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 o=(i-s)/this._store.state.scale;this.translateX+=n;this.translateY+=o}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}onSelectedClick(){}revive(t){Object.assign(this,t);return this}}class S extends E{constructor(){super(...arguments);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}get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}static create(t,i){var e,s,n,o,r,h;const l=new S;l._store=t;l.id=l.generateId();l.options=i;l.points=(e=i===null||i===void 0?void 0:i.points)!==null&&e!==void 0?e:[];l.translateX=(s=i===null||i===void 0?void 0:i.translateX)!==null&&s!==void 0?s:0;l.translateY=(n=i===null||i===void 0?void 0:i.translateY)!==null&&n!==void 0?n:0;l.scale=(o=i===null||i===void 0?void 0:i.scale)!==null&&o!==void 0?o:1;l.strokeWidth=(r=i===null||i===void 0?void 0:i.strokeWidth)!==null&&r!==void 0?r:8;l.fill=(h=i===null||i===void 0?void 0:i.fill)!==null&&h!==void 0?h:"#000000";l.zIndex=t.currentZIndex;l.d=l.generateSvgPath();l.updateDimensions();return l}resize(t,i,e,s){if(e<=1||s<=1){return}const n=e/this.width;const o=s/this.height;this.width=e;this.height=s;this.points=this.points.map((([t,i])=>[t*n,i*o]));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 A.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 o=t[2];let r=`M${s[0].toFixed(2)},${s[1].toFixed(2)} Q${n[0].toFixed(2)},${n[1].toFixed(2)} ${M.average(n[0],o[0]).toFixed(2)},${M.average(n[1],o[1]).toFixed(2)} T`;for(let i=2,o=e-1;i<o;i++){s=t[i];n=t[i+1];r+=`${M.average(s[0],n[0]).toFixed(2)},${M.average(s[1],n[1]).toFixed(2)} `}if(i){r+="Z"}return r}}class j{constructor(t){this.__class__=this.constructor.name;this.name="base-tool";this._store=t}onActivate(){}onDeactivate(){}handlePointerDown(t){}handlePointerMove(t){}handlePointerUp(t){}handleWheel(t){}revive(t){Object.assign(this,t);return this}}class I extends j{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"]}}handlePointerDown(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){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=S.create(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})}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());if(t.length===1){const i=Math.round(t[0].clientX-this._store.offsetX);const e=Math.round(t[0].clientY-this._store.offsetY);this._store.state.isDrawing=true;this._store.state.currentPath=S.create(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()}}}handlePointerMove(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){if(this._store.state.isDrawing){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.currentPath=S.create(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()}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());if(t.length===1){const i=Math.round(t[0].clientX-this._store.offsetX);const e=Math.round(t[0].clientY-this._store.offsetY);this._store.state.currentPath=S.create(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()}}}handlePointerUp(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){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}}if(t.pointerType==="touch"){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 F{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}}F.registry={};class B extends E{get isReadonly(){return!(this._store.state.activeTool instanceof P)}constructor(t){super();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;if(t){this.value=t.value||" ";this.translateX=t.translateX||0;this.translateY=t.translateY||0;this.fontSize=t.fontSize||8;this.fontFamily=t.fontFamily||"Arial";this.fontColor=t.fontColor||"#000000";this.height=t.height||this.fontSize*1.2;this.width=t.width||0;this.scale=t.scale||1}}static create(t,i,e){const s=new B;s._store=t;s.fontSize=i;s.fontFamily=e;s.translateX=0;s.translateY=0;s.width=s.initialWidth/(s._store.state.scale<0?s._store.state.scale:1);s.height=s.fontSize*1.2/(s._store.state.scale<0?s._store.state.scale:1);s.padding=5;s.backgroundColor="transparent";s.scale=s._store.state.scale;s.value=" ";s.zIndex=t.currentZIndex;return s}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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").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)}}}onSelectedClick(){this._store.setState("activeTool",F.getTool("text"));this._store.state.selectionGroup=null;this._store.state.selectionBox=null;this._store.state.activeText=this;setTimeout((()=>{this.focus()}),300)}}class U{static forceHideKeyboard(){if(document.activeElement instanceof HTMLElement){document.activeElement.blur()}}static enableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let i=t.getAttribute("content");if(!i.includes("interactive-widget=resizes-content")){i+=", interactive-widget=resizes-content"}t.setAttribute("content",i)}}static disableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let i=t.getAttribute("content");let e=i.replace(/\s*interactive-widget=resizes-content\s*[,;]?/g,"");e=e.replace(/,(\s*,)+/g,",").replace(/^,/,"").replace(/,$/,"").trim();t.setAttribute("content",e)}}}class P extends j{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"]}handlePointerDown(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){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 B){this._store.state.activeText=s;s.focus();return}if(this._store.state.activeText!==null&&s instanceof B){s.focus();return}if(this._store.state.activeText!==null){this._store.resetActiveText();this._store.setState("activeTool",F.getTool("selection"));return}if(w.isLeftClick(t)===false){return}const n=t.clientX-this._store.offsetX;const o=t.clientY-this._store.offsetY;const r=B.create(this._store,this.fontSize,this.fontFamily);r.fontColor=this.fontColor;r.translateX=(n-this._store.state.translateX)/this._store.state.scale;r.translateY=(o-this._store.state.translateY)/this._store.state.scale;r.zIndex=this._store.currentZIndex;this._store.state.activeText=r;this._store.history.executeCommand(new k(this._store,this,r))}if(t.pointerType==="touch"){const i=Array.from(this._store.state.pointers.values());const e=t.composedPath().slice(1);const s=e.find((t=>t.classList&&t.classList.contains("object")));const n=this._store.findObjectById(s===null||s===void 0?void 0:s.id);if(this._store.state.activeText===null&&n&&n instanceof B){this._store.state.activeText=n;n.focus();return}if(this._store.state.activeText!==null&&n instanceof B){n.focus();return}if(this._store.state.activeText!==null){this._store.resetActiveText();this._store.setState("activeTool",F.getTool("selection"));return}if(i.length>1){return}U.disableInteractiveWidget();const o=Math.round(i[0].clientX-this._store.offsetX);const r=Math.round(i[0].clientY-this._store.offsetY);const h=B.create(this._store,this.fontSize,this.fontFamily);h.fontColor=this.fontColor;h.translateX=(o-this._store.state.translateX)/this._store.state.scale;h.translateY=(r-this._store.state.translateY)/this._store.state.scale;h.zIndex=this._store.currentZIndex;this._store.state.activeText=h;this._store.history.executeCommand(new k(this._store,this,h))}}handlePointerUp(t){var i,e,s,n;if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){(i=this._store.state.activeText)===null||i===void 0?void 0:i.adjustTextareaSize();(e=this._store.state.activeText)===null||e===void 0?void 0:e.focus()}if(t.pointerType==="touch"){(s=this._store.state.activeText)===null||s===void 0?void 0:s.adjustTextareaSize();(n=this._store.state.activeText)===null||n===void 0?void 0:n.focus();U.enableInteractiveWidget()}}}class O{static isTouchDevice(){return window.matchMedia("(any-pointer: coarse)").matches}}const $=":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%))}:host(.mobile) .kritzel-control:hover{background-color:unset}.kritzel-control:active{background-color:var(--kritzel-controls-control-active-background-color, hsl(0, 0%, 0%, 8.6%))}:host(.mobile) .kritzel-control:active{background-color:unset}.kritzel-control.selected,.kritzel-control.selected:hover,.kritzel-control.selected:active{background-color:var(--kritzel-controls-control-selected-background-color, #0E1111) !important;color:var(--kritzel-controls-control-selected-color, #ffffff) !important}.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 D=class{constructor(e){t(this,e);this.controlsReady=i(this,"controlsReady");this.controls=[];this.activeControl=null;this.firstConfig=null;this.tooltipVisible=false;this.isTouchDevice=O.isTouchDevice();this.kritzelEngine=null}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()}async closeTooltip(){var t;this.tooltipVisible=false;(t=this.kritzelEngine)===null||t===void 0?void 0:t.enable()}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 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:"c20b7cbc7228f1b13a7e17f7ea94c96151e11608",class:{mobile:this.isTouchDevice}},e("kritzel-utility-panel",{key:"0e56c27c57d5cd7302ec80f6809fe4673afddae5",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:"6454509e3c524a42345e383270e3c1220f87dab6",class:"kritzel-controls"},this.controls.map((t=>{var i,s,o,r,h,l,c,a;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:(o=this.host.shadowRoot)===null||o===void 0?void 0:o.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 I&&e("div",{class:"color-container"},e("kritzel-color",{value:(r=this.activeToolAsBrushTool)===null||r===void 0?void 0:r.color,size:(h=this.activeToolAsBrushTool)===null||h===void 0?void 0:h.size,style:{borderRadius:"50%",border:"none"}})),this.activeControl.tool instanceof P&&e("div",{class:"font-container"},e("kritzel-font",{fontFamily:(l=this.activeToolAsTextTool)===null||l===void 0?void 0:l.fontFamily,size:(c=this.activeToolAsTextTool)===null||c===void 0?void 0:c.fontSize,color:(a=this.activeToolAsTextTool)===null||a===void 0?void 0:a.fontColor})),n&&e("div",{class:"no-config"})))}}))))}static get assetsDirs(){return["../assets"]}get host(){return n(this)}};D.style=$;const R=":host{display:block;position:fixed;top:0;left:0;width:100vw;height:100vh;pointer-events:none;z-index:9000}";const Q=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.pointerType==="mouse"){if(t.button===g.Left){this.isLeftButtonDown=true;this.cursorTrailPoints=[]}}if(t.pointerType==="touch"){if(this.store.state.pointers.size===1){this.isLeftButtonDown=true;this.cursorTrailPoints=[]}}}handlePointerMove(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}}handlePointerUp(t){if(t.pointerType==="mouse"){if(t.button===g.Left){this.isLeftButtonDown=false;this.cursorTrailPoints=[]}}if(t.pointerType==="touch"){if(this.store.state.pointers.size===0){this.isLeftButtonDown=false;this.cursorTrailPoints=[]}}}render(){return e(s,{key:"2e6ee739a4c25cee00470ee95ca22e55712c8d7b"},this.cursorTrailPoints.length>1&&e("svg",{key:"483aa687ccd290980ca9c588a84547df2bfdb659",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 o=n-t.timestamp;const r=Math.max(0,Math.min(1,o/this.TRAIL_DURATION_MS));if(r>=1)return null;const h=Math.max(2,15*(1-r));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"})}))))}};Q.style=R;const _=':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 L=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:"32c5f5a4f807c1e316c91b795c005b8d30ce6189"},e("div",{key:"b1cbeff18e688da4a2f7472be290b9527a619f07",class:"dropdown-wrapper"},e("slot",{key:"b3bbb7e21c6f5620cab41aa4b1c7206b6c75fd86",name:"prefix",ref:t=>this.prefixSlotElement=t,onSlotchange:this.evaluatePrefixContent}),e("select",{key:"8b2dcdc125bee59cf29fce7c980b755e78d5816e",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:"8d83f0dea41ac959bf2392948efef33bb70d0154",name:"suffix",ref:t=>this.suffixSlotElement=t,onSlotchange:this.evaluateSuffixContent})))}static get watchers(){return{value:["externalValueChanged"],options:["optionsChanged"]}}};L.style=_;class W{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)}}W.registry=new Map;W.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 H 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 K 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 V extends j{constructor(t){super(t);this.touchStartTimeout=null}handlePointerDown(t){if(t.pointerType==="mouse"){if(w.isLeftClick(t)){this._store.state.isErasing=true}}if(t.pointerType==="touch"){this.touchStartTimeout=setTimeout((()=>{if(this._store.state.pointers.size===1&&!this._store.state.isScaling){this._store.state.isErasing=true}}),80)}}handlePointerMove(t){var i,e;if(t.pointerType==="mouse"){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()}}if(t.pointerType==="touch"){if(this._store.state.pointers.size===1&&this._store.state.isErasing){const i=(e=this._store.state.host)===null||e===void 0?void 0:e.shadowRoot;if(!i)return;const s=this._store.getObjectFromPointerEvent(t,".object");if(!s)return;s.markedForRemoval=true;this._store.rerender()}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._store.state.isErasing){const t=this._store.allObjects.filter((t=>t.markedForRemoval)).map((t=>{t.markedForRemoval=false;return new K(this._store,this,t)}));if(t.length>0){this._store.history.executeCommand(new H(this._store,this,t))}this._store.state.isErasing=false}}if(t.pointerType==="touch"){clearTimeout(this.touchStartTimeout);if(this._store.state.isErasing){const t=this._store.allObjects.filter((t=>t.markedForRemoval)).map((t=>{t.markedForRemoval=false;return new K(this._store,this,t)}));if(t.length>0){this._store.history.executeCommand(new H(this._store,this,t))}this._store.state.isErasing=false}}}}class X extends E{constructor(){super(...arguments);this.__class__="KritzelImage";this.src="";this.debugInfoVisible=true}static create(t){const i=new X;i._store=t;i.id=i.generateId();i.x=0;i.y=0;i.translateX=0;i.translateY=0;i.scale=i._store.state.scale;i.zIndex=t.currentZIndex;return i}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 Y extends y{constructor(t,i){super(t,i);this.previousSelectionGroup=this._store.state.selectionGroup}execute(){this._store.state.objectsOctree.remove((t=>{var i;return t.id===((i=this.previousSelectionGroup)===null||i===void 0?void 0:i.id)}));this._store.state.selectionGroup=null}undo(){if(this.previousSelectionGroup){this._store.state.objectsOctree.insert(this.previousSelectionGroup);this._store.state.selectionGroup=this.previousSelectionGroup}}}class N extends y{constructor(t,i,e,s,n,o,r=false){super(t,i);this.startX=e;this.startY=s;this.endX=n;this.endY=o;this.skipExecution=r;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 G{constructor(t){this._store=t}}class q extends G{constructor(t){super(t)}handlePointerDown(t){var i,e;if(t.pointerType==="mouse"){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}}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());if(this._store.state.pointers.size===1){if(((e=this._store.state.selectionGroup)===null||e===void 0?void 0:e.selected)&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){const i=Math.round(t[0].clientX-this._store.offsetX);const e=Math.round(t[0].clientY-this._store.offsetY);this.dragStartX=i;this.dragStartY=e;this.startX=i;this.startY=e}}}}handlePointerMove(t){if(t.pointerType==="mouse"){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}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());if(this._store.state.pointers.size===1&&this._store.state.selectionGroup&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){const i=Math.round(t[0].clientX-this._store.offsetX);const e=Math.round(t[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 o=5;if(s>o||n>o){clearTimeout(this._store.state.longTouchTimeout);this._store.state.selectionGroup.move(i,e,this.dragStartX,this.dragStartY);this.dragStartX=i;this.dragStartY=e}}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._store.state.isDragging){this._store.state.isDragging=false;this._store.history.executeCommand(new N(this._store,this,this.endX,this.endY,this.startX,this.startY,true))}}if(t.pointerType==="touch"){if(this._store.state.isDragging){this._store.state.isDragging=false;this._store.history.executeCommand(new N(this._store,this,this.endX,this.endY,this.startX,this.startY,true))}}}}var Z;(function(t){t["TopLeft"]="top-left";t["TopRight"]="top-right";t["BottomLeft"]="bottom-left";t["BottomRight"]="bottom-right"})(Z||(Z={}));class J 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 tt extends G{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}}handlePointerDown(t){if(t.pointerType==="mouse"){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}}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());const i=t[0];if(!i){return}if(t.length===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)}}}}handlePointerMove(t){if(t.pointerType==="mouse"){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 Z.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 Z.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 Z.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 Z.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()}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());const i=t[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 Z.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 Z.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 Z.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 Z.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)}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._store.state.isResizing){const t=new J(this._store,this,structuredClone(this.initialSize),structuredClone(this.newSize));this._store.history.executeCommand(t);this._store.state.isResizing=false;this._store.rerender()}}if(t.pointerType==="touch"){if(this._store.state.isResizing){const t=new J(this._store,this,structuredClone(this.initialSize),structuredClone(this.newSize));this._store.history.executeCommand(t);this._store.state.isResizing=false;this._store.rerender();clearTimeout(this._store.state.longTouchTimeout)}}}}class it 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 et extends G{constructor(t){super(t);this.initialRotation=0;this.rotation=0}handlePointerDown(t){if(t.pointerType==="mouse"){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 o=(i-this._store.state.translateX)/this._store.state.scale;const r=(e-this._store.state.translateY)/this._store.state.scale;this.initialRotation=Math.atan2(n-r,s-o)-this._store.state.selectionGroup.rotation}}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());const i=t[0];if(!i){return}if(t.length===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 o=(t-this._store.state.translateX)/this._store.state.scale;const r=(e-this._store.state.translateY)/this._store.state.scale;this.initialRotation=Math.atan2(n-r,s-o)-this._store.state.selectionGroup.rotation;clearTimeout(this._store.state.longTouchTimeout)}}}}handlePointerMove(t){if(t.pointerType==="mouse"){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 o=(i-this._store.state.translateX)/this._store.state.scale;const r=(e-this._store.state.translateY)/this._store.state.scale;const h=Math.atan2(n-r,s-o);this.rotation=h-this.initialRotation;this._store.state.selectionGroup.rotate(this.rotation);this._store.rerender()}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());const i=t[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 o=(t-this._store.state.translateX)/this._store.state.scale;const r=(e-this._store.state.translateY)/this._store.state.scale;const h=Math.atan2(n-r,s-o);this.rotation=h-this.initialRotation;this._store.state.selectionGroup.rotate(this.rotation);this._store.rerender();clearTimeout(this._store.state.longTouchTimeout)}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._store.state.isRotating){this._store.history.executeCommand(new it(this._store,this,this.rotation));this._store.state.isRotating=false;this.initialRotation=0;this.rotation=0}}if(t.pointerType==="touch"){if(this._store.state.isRotating){this._store.history.executeCommand(new it(this._store,this,this.rotation));this._store.state.isRotating=false;this.initialRotation=0;this.rotation=0;clearTimeout(this._store.state.longTouchTimeout)}}}}class st{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 o=s[(t+1)%s.length];if(this.intersectLines(i,n,e,o)){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 o=i[s].x,r=i[s].y;const h=i[n].x,l=i[n].y;const c=r>t.y!==l>t.y&&t.x<(h-o)*(t.y-r)/(l-r)+o;if(c)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 o=((e.x-t.x)*(s.y-e.y)-(e.y-t.y)*(s.x-e.x))/n;const r=-((t.x-e.x)*(i.y-t.y)-(t.y-e.y)*(i.x-t.x))/n;return o>=0&&o<=1&&r>=0&&r<=1}}class nt extends E{constructor(){super(...arguments);this.__class__="KrtizelSelectionBox";this.objects=[]}static create(t){const i=new nt;i._store=t;i.id=i.generateId();i.scale=t.state.scale;i.zIndex=99999;i.backgroundColor="var(--kritzel-selection-box-background-color, rgba(14, 17, 17, 0.2))";i.borderColor="var(--kritzel-selection-box-border-color, rgba(14, 17, 17, 0.5))";i.borderWidth=2;i.height=0;i.width=0;return i}}class ot extends y{constructor(t,i,e){super(t,i);this.selectionGroup=e}execute(){this._store.state.objectsOctree.remove((t=>t instanceof nt));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 rt extends G{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}handlePointerDown(t){if(t.pointerType==="mouse"){if(w.isLeftClick(t)&&!this._store.state.selectionGroup){this.startMouseSelection(t)}}if(t.pointerType==="touch"){this.touchStartTimeout=setTimeout((()=>{if(this._store.state.pointers.size===1&&!this._store.state.isScaling&&!this._store.state.selectionGroup){this.startTouchSelection();this.updateTouchSelection()}}),80)}}handlePointerMove(t){if(t.pointerType==="mouse"){if(this._store.state.isSelecting){this.updateMouseSelection(t)}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());const i=Math.round(t[0].clientX-this._store.offsetX);const e=Math.round(t[0].clientY-this._store.offsetY);const s=Math.abs(i-this.touchStartX);const n=Math.abs(e-this.touchStartY);const o=5;if((s>o||n>o)&&this._store.state.isSelecting){this.updateTouchSelection();clearTimeout(this._store.state.longTouchTimeout)}}}handlePointerUp(t){if(t.pointerType==="mouse"){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()}}}if(t.pointerType==="touch"){clearTimeout(this.touchStartTimeout);if(this._store.state.isSelecting){if(this.isSelectionClick){this.updateTouchSelection();this.addSelectedObjectAtIndexToSelectionGroup(0);this.removeSelectionBox()}if(this.isSelectionDrag){this.updateTouchSelection();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 nt));this._store.rerender()}startMouseSelection(t){let i,e;i=t.clientX-this._store.offsetX;e=t.clientY-this._store.offsetY;const s=nt.create(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 nt||t instanceof ct));this._store.state.objectsOctree.insert(s)}startTouchSelection(){const t=Array.from(this._store.state.pointers.values());const i=t[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=nt.create(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 nt||t instanceof ct));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(){const t=Array.from(this._store.state.pointers.values());const i=t[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 nt))).forEach((t=>{const i=t.rotatedPolygon;const e=this._store.state.selectionBox.rotatedPolygon;t.selected=st.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=ct.create(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 ot(this._store,this,this._store.state.selectionGroup))}addSelectedObjectsToSelectionGroup(){const t=this._store.selectedObjects;if(t.length===0){return}this._store.state.selectionGroup=ct.create(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 ot(this._store,this,this._store.state.selectionGroup))}}class ht extends j{constructor(t){super(t);this.selectionHandler=new rt(this._store);this.moveHandler=new q(this._store);this.resizeHandler=new tt(this._store);this.rotationHandler=new et(this._store)}handlePointerDown(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){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 Y(this._store,this._store.state.selectionGroup))}if(i&&i.selected&&i.objects.length===1){setTimeout((()=>{if(this._store.state.isDragging===false&&this._store.state.isResizing===false&&this._store.state.isRotating===false){i.objects[0].onSelectedClick()}}),100)}}this.moveHandler.handlePointerDown(t);this.selectionHandler.handlePointerDown(t);this.resizeHandler.handlePointerDown(t);this.rotationHandler.handlePointerDown(t);this._store.rerender()}if(t.pointerType==="touch"){if(this._store.state.isScaling===true){return}if(this._store.state.pointers.size===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 Y(this._store,this._store.state.selectionGroup))}if(i&&i.selected&&i.objects.length===1){setTimeout((()=>{if(this._store.state.isDragging===false&&this._store.state.isResizing===false&&this._store.state.isRotating===false){i.objects[0].onSelectedClick()}}),100)}}this.rotationHandler.handlePointerDown(t);this.resizeHandler.handlePointerDown(t);this.moveHandler.handlePointerDown(t);this.selectionHandler.handlePointerDown(t)}}handlePointerMove(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){this.moveHandler.handlePointerMove(t);this.selectionHandler.handlePointerMove(t);this.resizeHandler.handlePointerMove(t);this.rotationHandler.handlePointerMove(t);this._store.rerender()}if(t.pointerType==="touch"){if(this._store.state.isScaling===true){return}this.rotationHandler.handlePointerMove(t);this.resizeHandler.handlePointerMove(t);this.moveHandler.handlePointerMove(t);this.selectionHandler.handlePointerMove(t);this._store.rerender()}}handlePointerUp(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){this.moveHandler.handlePointerUp(t);this.selectionHandler.handlePointerUp(t);this.resizeHandler.handlePointerUp(t);this.rotationHandler.handlePointerUp(t);this._store.rerender()}if(t.pointerType==="touch"){if(this._store.state.isScaling===true){return}this.rotationHandler.handlePointerUp(t);this.resizeHandler.handlePointerUp(t);this.moveHandler.handlePointerUp(t);this.selectionHandler.handlePointerUp(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 ct){return s}else{const t=ct.create(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 o=n.closest(".resize-handle-overlay");return o===null||o===void 0?void 0:o.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 lt{constructor(t){this._store=t}revive(t){if(t&&typeof t==="object"){if(t.__class__){let i;switch(t.__class__){case"KritzelPath":i=S.create(this._store).revive(t);break;case"KritzelText":i=B.create(this._store,t.fontSize,t.fontFamily).revive(t);break;case"KritzelImage":i=X.create(this._store).revive(t);break;case"KritzelSelectionGroup":i=ct.create(this._store).revive(t);break;case"KritzelBrushTool":i=new I(this._store);break;case"KritzelEraserTool":i=new V(this._store);break;case"KritzelImageTool":i=new Kt(this._store);break;case"KritzelSelectionTool":i=new ht(this._store);break;case"KritzelTextTool":i=new P(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 ct extends E{constructor(){super(...arguments);this.__class__="KritzelSelectionGroup";this.objects=[];this.unchangedObjects=[]}get length(){return this.objects.length}static create(t){const i=new ct;i._store=t;i.id=i.generateId();i.scale=t.state.scale;i.zIndex=99999;return i}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=T.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 o=(i-s)/this._store.state.scale;this.translateX+=n;this.translateY+=o;this._store.state.objectsOctree.update(this);this.objects.forEach((t=>{t.translateX+=n;t.translateY+=o;this._store.state.objectsOctree.update(t)}));this.unchangedObjects.forEach((t=>{t.translateX+=n;t.translateY+=o}))}resize(t,i,e,s){const n=e/this.width;const o=s/this.height;const r=t-this.translateX;const h=i-this.translateY;this.objects.forEach((t=>{const i=t.width*n;const e=t.height*o;const s=t.translateX+r+(t.translateX-this.translateX)*(n-1);const l=t.translateY+h+(t.translateY-this.translateY)*(o-1);t.resize(s,l,i,e);this._store.state.objectsOctree.update(t)}));this.refreshObjectDimensions();this.unchangedObjects=T.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 o=Math.sin(s);this.objects.forEach((s=>{const r=this.getUnchangedObject(s.id);const h=this.getOffsetXToCenter(r);const l=this.getOffsetYToCenter(r);const c=n*h-o*l;const a=o*h+n*l;s.translateX=i+c-s.totalWidth/2/s.scale;s.translateY=e+a-s.totalHeight/2/s.scale;s.rotation=this.objects.length===1?t:t+r.rotation;this._store.state.objectsOctree.update(s)}))}copy(){const t=ct.create(this._store);let i=this._store.currentZIndex;this.objects.forEach((e=>{const s=e.copy();s.zIndex=i;t.addOrRemove(s);i++}));t.unchangedObjects=T.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 lt(this._store);return e.revive(i)}}function at(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 ft(t,i){return new Promise((function(e,s){let n;return dt(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 dt=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 o=s.getUint16(n);if(65498===o)break;const r=s.getUint16(n+2);if(65505===o&&1165519206===s.getUint32(n+4)){const o=n+10;let h;switch(s.getUint16(o)){case 18761:h=true;break;case 19789:h=false;break;default:return e("TIFF header contains invalid endian")}if(42!==s.getUint16(o+2,h))return e("TIFF header contains invalid version");const l=s.getUint32(o+4,h),c=o+l+2+12*s.getUint16(o+l,h);for(let t=o+l+2;t<c;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+r))}n+=2+r}return i(new Blob)})),s.readAsArrayBuffer(t)}));var ut={},vt={get exports(){return ut},set exports(t){ut=t}};!function(t){var i,e,s={};vt.exports=s,s.parse=function(t,i){for(var e=s.bin.readUshort,n=s.bin.readUint,o=0,r={},h=new Uint8Array(t),l=h.length-4;101010256!=n(h,l);)l--;o=l;o+=4;var c=e(h,o+=4);e(h,o+=2);var a=n(h,o+=2),f=n(h,o+=4);o+=4,o=f;for(var d=0;d<c;d++){n(h,o),o+=4,o+=4,o+=4,n(h,o+=4);a=n(h,o+=4);var u=n(h,o+=4),v=e(h,o+=4),p=e(h,o+2),b=e(h,o+4);o+=6;var g=n(h,o+=8);o+=4,o+=v+p+b,s._readLocal(h,g,r,a,u,i)}return r},s._readLocal=function(t,i,e,n,o,r){var h=s.bin.readUshort,l=s.bin.readUint;l(t,i),h(t,i+=4),h(t,i+=2);var c=h(t,i+=2);l(t,i+=2),l(t,i+=4),i+=4;var a=h(t,i+=8),f=h(t,i+=2);i+=2;var d=s.bin.readUTF8(t,i,a);if(i+=a,i+=f,r)e[d]={size:o,csize:n};else{var u=new Uint8Array(t.buffer,i);if(0==c)e[d]=new Uint8Array(u.buffer.slice(i,i+n));else{if(8!=c)throw"unknown compression method: "+c;var v=new Uint8Array(o);s.inflateRaw(u,v),e[d]=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 o=s.adler(t,0,t.length);return n[e+0]=o>>>24&255,n[e+1]=o>>>16&255,n[e+2]=o>>>8&255,n[e+3]=o>>>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,o=s.bin.writeUshort,r={};for(var h in t){var l=!s._noNeed(h)&&!i,c=t[h],a=s.crc.crc(c,0,c.length);r[h]={cpr:l,usize:c.length,crc:a,file:l?s.deflateRaw(c):c}}for(var h in r)e+=r[h].file.length+30+46+2*s.bin.sizeUTF8(h);e+=22;var f=new Uint8Array(e),d=0,u=[];for(var h in r){var v=r[h];u.push(d),d=s._writeHeader(f,d,h,v,0)}var p=0,b=d;for(var h in r){v=r[h];u.push(d),d=s._writeHeader(f,d,h,v,1,u[p++])}var g=d-b;return n(f,d,101010256),d+=4,o(f,d+=4,p),o(f,d+=2,p),n(f,d+=2,g),n(f,d+=4,b),d+=4,d+=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,o,r){var h=s.bin.writeUint,l=s.bin.writeUshort,c=n.file;return h(t,i,0==o?67324752:33639248),i+=4,1==o&&(i+=2),l(t,i,20),l(t,i+=2,0),l(t,i+=2,n.cpr?8:0),h(t,i+=2,0),h(t,i+=4,n.crc),h(t,i+=4,c.length),h(t,i+=4,n.usize),l(t,i+=4,s.bin.sizeUTF8(e)),l(t,i+=2,0),i+=2,1==o&&(i+=2,i+=2,h(t,i+=6,r),i+=4),i+=s.bin.writeUTF8(t,i,e),0==o&&(t.set(c,i),i+=c.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 o=0;o<n;o++)t=s.crc.table[255&(t^i[e+o])]^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,o=i,r=i+e;o<r;){for(var h=Math.min(o+5552,r);o<h;)n+=s+=t[o++];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,o="",r=0;r<e;r++)o+="%"+s.bin.pad(t[i+r].toString(16));try{n=decodeURIComponent(o)}catch(n){return s.bin.readASCII(t,i,e)}return n},writeUTF8:function(t,i,e){for(var s=e.length,n=0,o=0;o<s;o++){var r=e.charCodeAt(o);if(0==(4294967168&r))t[i+n]=r,n++;else if(0==(4294965248&r))t[i+n]=192|r>>6,t[i+n+1]=128|r>>0&63,n+=2;else if(0==(4294901760&r))t[i+n]=224|r>>12,t[i+n+1]=128|r>>6&63,t[i+n+2]=128|r>>0&63,n+=3;else{if(0!=(4292870144&r))throw"e";t[i+n]=240|r>>18,t[i+n+1]=128|r>>12&63,t[i+n+2]=128|r>>6&63,t[i+n+3]=128|r>>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 o=[[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],r=s.F.U,h=s.F._goodIndex;var l=s.F._putsE,c=0,a=e<<3,f=0,d=t.length;if(0==n){for(;c<d;){l(i,a,c+(A=Math.min(65535,d-c))==d?1:0),a=s.F._copyExact(t,c,A,i,a+8),c+=A}return a>>>3}var u=r.lits,v=r.strt,p=r.prev,b=0,g=0,w=0,y=0,k=0,x=0;for(d>2&&(v[x=s.F._hash(t,0)]=0),c=0;c<d;c++){if(k=x,c+1<d-2){x=s.F._hash(t,c+1);var m=c+1&32767;p[m]=v[x],v[x]=m}if(f<=c){(b>14e3||g>26697)&&d-c>100&&(f<c&&(u[b]=c-f,b+=2,f=c),a=s.F._writeBlock(c==d-1||f==d?1:0,u,b,y,t,w,c-w,i,a),b=g=y=0,w=c);var z=0;c<d-2&&(z=s.F._bestMatch(t,c,p,k,Math.min(o[2],d-c),o[3]));var A=z>>>16,M=65535&z;if(0!=z){M=65535&z;var C=h(A=z>>>16,r.of0);r.lhst[257+C]++;var T=h(M,r.df0);r.dhst[T]++,y+=r.exb[C]+r.dxb[T],u[b]=A<<23|c-f,u[b+1]=M<<16|C<<8|T,b+=2,f=c+A}else r.lhst[t[c]]++;g++}}for(w==c&&0!=t.length||(f<c&&(u[b]=c-f,b+=2,f=c),a=s.F._writeBlock(1,u,b,y,t,w,c-w,i,a),b=0,g=0,b=g=y=0,w=c);0!=(7&a);)a++;return a>>>3},s.F._bestMatch=function(t,i,e,n,o,r){var h=32767&i,l=e[h],c=h-l+32768&32767;if(l==h||n!=s.F._hash(t,i-c))return 0;for(var a=0,f=0,d=Math.min(32767,i);c<=d&&0!=--r&&l!=h;){if(0==a||t[i+a]==t[i+a-c]){var u=s.F._howLong(t,i,c);if(u>a){if(f=c,(a=u)>=o)break;c+2<u&&(u=c+2);for(var v=0,p=0;p<u-2;p++){var b=i-c+p+32768&32767,g=b-e[b]+32768&32767;g>v&&(v=g,l=b)}}}c+=(h=l)-(l=e[h])+32768&32767}return a<<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,o,r,h,l,c){var a,f,d,u,v,p,b,g,w,y=s.F.U,k=s.F._putsF,x=s.F._putsE;y.lhst[256]++,f=(a=s.F.getTrees())[0],d=a[1],u=a[2],v=a[3],p=a[4],b=a[5],g=a[6],w=a[7];var m=32+(0==(c+3&7)?0:8-(c+3&7))+(h<<3),z=n+s.F.contSize(y.fltree,y.lhst)+s.F.contSize(y.fdtree,y.dhst),A=n+s.F.contSize(y.ltree,y.lhst)+s.F.contSize(y.dtree,y.dhst);A+=14+3*b+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 C=m<z&&m<A?0:z<A?1:2;if(k(l,c,t),k(l,c+1,C),c+=3,0==C){for(;0!=(7&c);)c++;c=s.F._copyExact(o,r,h,l,c)}else{var T,E;if(1==C&&(T=y.fltree,E=y.fdtree),2==C){s.F.makeCodes(y.ltree,f),s.F.revCodes(y.ltree,f),s.F.makeCodes(y.dtree,d),s.F.revCodes(y.dtree,d),s.F.makeCodes(y.itree,u),s.F.revCodes(y.itree,u),T=y.ltree,E=y.dtree,x(l,c,v-257),x(l,c+=5,p-1),x(l,c+=5,b-4),c+=4;for(var S=0;S<b;S++)x(l,c+3*S,y.itree[1+(y.ordr[S]<<1)]);c+=3*b,c=s.F._codeTiny(g,y.itree,l,c),c=s.F._codeTiny(w,y.itree,l,c)}for(var j=r,I=0;I<e;I+=2){for(var F=i[I],B=F>>>23,U=j+(8388607&F);j<U;)c=s.F._writeLit(o[j++],T,l,c);if(0!=B){var P=i[I+1],O=P>>16,$=P>>8&255,D=255&P;x(l,c=s.F._writeLit(257+$,T,l,c),B-y.of0[$]),c+=y.exb[$],k(l,c=s.F._writeLit(D,E,l,c),O-y.df0[D]),c+=y.dxb[D],j+=B}}c=s.F._writeLit(256,T,l,c)}return c},s.F._copyExact=function(t,i,e,s,n){var o=n>>>3;return s[o]=e,s[o+1]=e>>>8,s[o+2]=255-s[o],s[o+3]=255-s[o+1],o+=4,s.set(new Uint8Array(t.buffer,i,e),o),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=[],o=s.F._lenCodes(t.ltree,n),r=[],h=s.F._lenCodes(t.dtree,r),l=0;l<n.length;l+=2)t.ihst[n[l]]++;for(l=0;l<r.length;l+=2)t.ihst[r[l]]++;for(var c=s.F._hufTree(t.ihst,t.itree,7),a=19;a>4&&0==t.itree[1+(t.ordr[a-1]<<1)];)a--;return[i,e,c,o,h,a,n,r]},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 o=0;o<t.length;o+=2){var r=t[o],h=t[o+1];n=s.F._writeLit(r,i,e,n);var l=16==r?2:17==r?3:7;r>15&&(s.F._putsE(e,n,h,l),n+=l)}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],o=s+3<e?t[s+3]:-1,r=s+5<e?t[s+5]:-1,h=0==s?-1:t[s-1];if(0==n&&o==n&&r==n){for(var l=s+5;l+2<e&&t[l+2]==n;)l+=2;(c=Math.min(l+1-s>>>1,138))<11?i.push(17,c-3):i.push(18,c-11),s+=2*c-2}else if(n==h&&o==n&&r==n){for(l=s+5;l+2<e&&t[l+2]==n;)l+=2;var c=Math.min(l+1-s>>>1,6);i.push(16,c-3),s+=2*c-2}else i.push(n,0)}return e>>>1},s.F._hufTree=function(t,i,e){var n=[],o=t.length,r=i.length,h=0;for(h=0;h<r;h+=2)i[h]=0,i[h+1]=0;for(h=0;h<o;h++)0!=t[h]&&n.push({lit:h,f:t[h]});var l=n.length,c=n.slice(0);if(0==l)return 0;if(1==l){var a=n[0].lit;c=0==a?1:0;return i[1+(a<<1)]=1,i[1+(c<<1)]=1,1}n.sort((function(t,i){return t.f-i.f}));var f=n[0],d=n[1],u=0,v=1,p=2;for(n[0]={lit:-1,f:f.f+d.f,l:f,r:d,d:0};v!=l-1;)f=u!=v&&(p==l||n[u].f<n[p].f)?n[u++]:n[p++],d=u!=v&&(p==l||n[u].f<n[p].f)?n[u++]:n[p++],n[v++]={lit:-1,f:f.f+d.f,l:f,r:d};var b=s.F.setDepth(n[v-1],0);for(b>e&&(s.F.restrictDepth(c,e,b),b=e),h=0;h<l;h++)i[1+(c[h].lit<<1)]=c[h].d;return b},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,o=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 r=t[s].d;t[s].d=i,o+=n-(1<<e-r)}for(o>>>=e-i;o>0;){(r=t[s].d)<i?(t[s].d++,o-=1<<i-r-1):s++}for(;s>=0;s--)t[s].d==i&&o<0&&(t[s].d--,o++);0!=o&&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,o=n._bitsF,r=n._bitsE,h=n._decodeTiny,l=n.makeCodes,c=n.codes2map,a=n._get17,f=n.U,d=null==i;d&&(i=new e(t.length>>>2<<3));for(var u,v,p=0,b=0,g=0,w=0,y=0,k=0,x=0,m=0,z=0;0==p;)if(p=o(t,z,1),b=o(t,z+1,2),z+=3,0!=b){if(d&&(i=s.F._check(i,m+(1<<17))),1==b&&(u=f.flmap,v=f.fdmap,k=511,x=31),2==b){g=r(t,z,5)+257,w=r(t,z+5,5)+1,y=r(t,z+10,4)+4,z+=14;for(var A=0;A<38;A+=2)f.itree[A]=0,f.itree[A+1]=0;var M=1;for(A=0;A<y;A++){var C=r(t,z+3*A,3);f.itree[1+(f.ordr[A]<<1)]=C,C>M&&(M=C)}z+=3*y,l(f.itree,M),c(f.itree,M,f.imap),u=f.lmap,v=f.dmap,z=h(f.imap,(1<<M)-1,g+w,t,z,f.ttree);var T=n._copyOut(f.ttree,0,g,f.ltree);k=(1<<T)-1;var E=n._copyOut(f.ttree,g,w,f.dtree);x=(1<<E)-1,l(f.ltree,T),c(f.ltree,T,u),l(f.dtree,E),c(f.dtree,E,v)}for(;;){var S=u[a(t,z)&k];z+=15&S;var j=S>>>4;if(j>>>8==0)i[m++]=j;else{if(256==j)break;var I=m+j-254;if(j>264){var F=f.ldef[j-257];I=m+(F>>>3)+r(t,z,7&F),z+=7&F}var B=v[a(t,z)&x];z+=15&B;var U=B>>>4,P=f.ddef[U],O=(P>>>4)+o(t,z,15&P);for(z+=15&P,d&&(i=s.F._check(i,m+(1<<17)));m<I;)i[m]=i[m++-O],i[m]=i[m++-O],i[m]=i[m++-O],i[m]=i[m++-O];m=I}}}else{0!=(7&z)&&(z+=8-(7&z));var $=4+(z>>>3),D=t[$-4]|t[$-3]<<8;d&&(i=s.F._check(i,m+D)),i.set(new e(t.buffer,t.byteOffset+$,D),m),z=$+D<<3,m+=D}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,o,r){for(var h=s.F._bitsE,l=s.F._get17,c=0;c<e;){var a=t[l(n,o)&i];o+=15&a;var f=a>>>4;if(f<=15)r[c]=f,c++;else{var d=0,u=0;16==f?(u=3+h(n,o,2),o+=2,d=r[c-1]):17==f?(u=3+h(n,o,3),o+=3):18==f&&(u=11+h(n,o,7),o+=7);for(var v=c+u;c<v;)r[c]=d,c++}}return o},s.F._copyOut=function(t,i,e,s){for(var n=0,o=0,r=s.length>>>1;o<e;){var h=t[o+i];s[o<<1]=0,s[1+(o<<1)]=h,h>n&&(n=h),o++}for(;o<r;)s[o<<1]=0,s[1+(o<<1)]=0,o++;return n},s.F.makeCodes=function(t,i){for(var e,n,o,r,h=s.F.U,l=t.length,c=h.bl_count,a=0;a<=i;a++)c[a]=0;for(a=1;a<l;a+=2)c[t[a]]++;var f=h.next_code;for(e=0,c[0]=0,n=1;n<=i;n++)e=e+c[n-1]<<1,f[n]=e;for(o=0;o<l;o+=2)0!=(r=t[o+1])&&(t[o]=f[r],f[r]++)},s.F.codes2map=function(t,i,e){for(var n=t.length,o=s.F.U.rev15,r=0;r<n;r+=2)if(0!=t[r+1])for(var h=r>>1,l=t[r+1],c=h<<4|l,a=i-l,f=t[r]<<a,d=f+(1<<a);f!=d;){e[o[f]>>>15-i]=c,f++}},s.F.revCodes=function(t,i){for(var e=s.F.U.rev15,n=15-i,o=0;o<t.length;o+=2){var r=t[o]<<i-t[o+1];t[o]=e[r]>>>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 pt=at({__proto__:null,default:ut},[ut]);const bt=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,o="";for(let n=0;n<s;n++)o+=`%${t.pad(i[e+n].toString(16))}`;try{n=decodeURIComponent(o)}catch(n){return t.readASCII(i,e,s)}return n}};function i(i,e,s,n){const r=e*s,h=o(n),l=Math.ceil(e*h/8),c=new Uint8Array(4*r),a=new Uint32Array(c.buffer),{ctype:f}=n,{depth:d}=n,u=t.readUshort;if(6==f){const t=r<<2;if(8==d)for(var v=0;v<t;v+=4)c[v]=i[v],c[v+1]=i[v+1],c[v+2]=i[v+2],c[v+3]=i[v+3];if(16==d)for(v=0;v<t;v++)c[v]=i[v<<1]}else if(2==f){const t=n.tabs.tRNS;if(null==t){if(8==d)for(v=0;v<r;v++){var p=3*v;a[v]=255<<24|i[p+2]<<16|i[p+1]<<8|i[p]}if(16==d)for(v=0;v<r;v++){p=6*v;a[v]=255<<24|i[p+4]<<16|i[p+2]<<8|i[p]}}else{var b=t[0];const e=t[1],s=t[2];if(8==d)for(v=0;v<r;v++){var g=v<<2;p=3*v;a[v]=255<<24|i[p+2]<<16|i[p+1]<<8|i[p],i[p]==b&&i[p+1]==e&&i[p+2]==s&&(c[g+3]=0)}if(16==d)for(v=0;v<r;v++){g=v<<2,p=6*v;a[v]=255<<24|i[p+4]<<16|i[p+2]<<8|i[p],u(i,p)==b&&u(i,p+2)==e&&u(i,p+4)==s&&(c[g+3]=0)}}}else if(3==f){const t=n.tabs.PLTE,o=n.tabs.tRNS,h=o?o.length:0;if(1==d)for(var w=0;w<s;w++){var y=w*l,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);c[g]=t[x],c[g+1]=t[x+1],c[g+2]=t[x+2],c[g+3]=m<h?o[m]:255}}if(2==d)for(w=0;w<s;w++)for(y=w*l,k=w*e,v=0;v<e;v++){g=k+v<<2,x=3*(m=i[y+(v>>2)]>>6-((3&v)<<1)&3);c[g]=t[x],c[g+1]=t[x+1],c[g+2]=t[x+2],c[g+3]=m<h?o[m]:255}if(4==d)for(w=0;w<s;w++)for(y=w*l,k=w*e,v=0;v<e;v++){g=k+v<<2,x=3*(m=i[y+(v>>1)]>>4-((1&v)<<2)&15);c[g]=t[x],c[g+1]=t[x+1],c[g+2]=t[x+2],c[g+3]=m<h?o[m]:255}if(8==d)for(v=0;v<r;v++){var m;g=v<<2,x=3*(m=i[v]);c[g]=t[x],c[g+1]=t[x+1],c[g+2]=t[x+2],c[g+3]=m<h?o[m]:255}}else if(4==f){if(8==d)for(v=0;v<r;v++){g=v<<2;var z=i[A=v<<1];c[g]=z,c[g+1]=z,c[g+2]=z,c[g+3]=i[A+1]}if(16==d)for(v=0;v<r;v++){var A;g=v<<2,z=i[A=v<<2];c[g]=z,c[g+1]=z,c[g+2]=z,c[g+3]=i[A+2]}}else if(0==f)for(b=n.tabs.tRNS?n.tabs.tRNS:-1,w=0;w<s;w++){const t=w*l,s=w*e;if(1==d)for(var M=0;M<e;M++){var C=(z=255*(i[t+(M>>>3)]>>>7-(7&M)&1))==255*b?0:255;a[s+M]=C<<24|z<<16|z<<8|z}else if(2==d)for(M=0;M<e;M++){C=(z=85*(i[t+(M>>>2)]>>>6-((3&M)<<1)&3))==85*b?0:255;a[s+M]=C<<24|z<<16|z<<8|z}else if(4==d)for(M=0;M<e;M++){C=(z=17*(i[t+(M>>>1)]>>>4-((1&M)<<2)&15))==17*b?0:255;a[s+M]=C<<24|z<<16|z<<8|z}else if(8==d)for(M=0;M<e;M++){C=(z=i[t+M])==b?0:255;a[s+M]=C<<24|z<<16|z<<8|z}else if(16==d)for(M=0;M<e;M++){z=i[t+(M<<1)],C=u(i,t+(M<<1))==b?0:255;a[s+M]=C<<24|z<<16|z<<8|z}}return c}function e(t,i,e,h){const l=o(t),c=Math.ceil(e*l/8),a=new Uint8Array((c+1+t.interlace)*h);return i=t.tabs.CgBI?n(i,a):s(i,a),0==t.interlace?i=r(i,t,0,e,h):1==t.interlace&&(i=function t(i,e){const s=e.width,n=e.height,h=o(e),l=h>>3,c=Math.ceil(s*h/8),a=new Uint8Array(n*c);let f=0;const d=[0,0,4,0,2,0,1],u=[0,4,0,2,0,1,0],v=[8,8,8,4,4,2,2],p=[8,8,4,4,2,2,1];let b=0;for(;b<7;){const t=v[b],o=p[b];let w=0,y=0,k=d[b];for(;k<n;)k+=t,y++;let x=u[b];for(;x<s;)x+=o,w++;const m=Math.ceil(w*h/8);r(i,e,f,w,y);let z=0,A=d[b];for(;A<n;){let e=u[b],n=f+z*m<<3;for(;e<s;){var g;if(1==h)g=(g=i[n>>3])>>7-(7&n)&1,a[A*c+(e>>3)]|=g<<7-((7&e)<<0);if(2==h)g=(g=i[n>>3])>>6-(7&n)&3,a[A*c+(e>>2)]|=g<<6-((3&e)<<1);if(4==h)g=(g=i[n>>3])>>4-(7&n)&15,a[A*c+(e>>1)]|=g<<4-((1&e)<<2);if(h>=8){const t=A*c+e*l;for(let e=0;e<l;e++)a[t+e]=i[(n>>3)+e]}n+=h,e+=o}z++,A+=t}w*y!=0&&(f+=y*(1+m)),b+=1}return a}(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,o,r=0,h=0,l=0,c=0,a=0,f=0,d=0,u=0,v=0;if(3==i[0]&&0==i[1])return e||new s(0);const p=t.H,b=p.b,g=p.e,w=p.R,y=p.n,k=p.A,x=p.Z,m=p.m,z=null==e;for(z&&(e=new s(i.length>>>2<<5));0==r;)if(r=b(i,v,1),h=b(i,v+1,2),v+=3,0!=h){if(z&&(e=t.H.W(e,u+(1<<17))),1==h&&(n=m.J,o=m.h,f=511,d=31),2==h){l=g(i,v,5)+257,c=g(i,v+5,5)+1,a=g(i,v+10,4)+4,v+=14;let t=1;for(var A=0;A<38;A+=2)m.Q[A]=0,m.Q[A+1]=0;for(A=0;A<a;A++){const e=g(i,v+3*A,3);m.Q[1+(m.X[A]<<1)]=e,e>t&&(t=e)}v+=3*a,y(m.Q,t),k(m.Q,t,m.u),n=m.w,o=m.d,v=w(m.u,(1<<t)-1,l+c,i,v,m.v);const e=p.V(m.v,0,l,m.C);f=(1<<e)-1;const s=p.V(m.v,l,c,m.D);d=(1<<s)-1,y(m.C,e),k(m.C,e,n),y(m.D,s),k(m.D,s,o)}for(;;){const t=n[x(i,v)&f];v+=15&t;const s=t>>>4;if(s>>>8==0)e[u++]=s;else{if(256==s)break;{let t=u+s-254;if(s>264){const e=m.q[s-257];t=u+(e>>>3)+g(i,v,7&e),v+=7&e}const n=o[x(i,v)&d];v+=15&n;const r=n>>>4,h=m.c[r],l=(h>>>4)+b(i,v,15&h);for(v+=15&h;u<t;)e[u]=e[u++-l],e[u]=e[u++-l],e[u]=e[u++-l],e[u]=e[u++-l];u=t}}}}else{0!=(7&v)&&(v+=8-(7&v));const n=4+(v>>>3),o=i[n-4]|i[n-3]<<8;z&&(e=t.H.W(e,u+o)),e.set(new s(i.buffer,i.byteOffset+n,o),u),v=n+o<<3,u+=o}return e.length==u?e:e.slice(0,u)},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,o,r){const h=t.H.e,l=t.H.Z;let c=0;for(;c<s;){const t=i[l(n,o)&e];o+=15&t;const s=t>>>4;if(s<=15)r[c]=s,c++;else{let t=0,i=0;16==s?(i=3+h(n,o,2),o+=2,t=r[c-1]):17==s?(i=3+h(n,o,3),o+=3):18==s&&(i=11+h(n,o,7),o+=7);const e=c+i;for(;c<e;)r[c]=t,c++}}return o},t.H.V=function(t,i,e,s){let n=0,o=0;const r=s.length>>>1;for(;o<e;){const e=t[o+i];s[o<<1]=0,s[1+(o<<1)]=e,e>n&&(n=e),o++}for(;o<r;)s[o<<1]=0,s[1+(o<<1)]=0,o++;return n},t.H.n=function(i,e){const s=t.H.m,n=i.length;let o,r,h;let l;const c=s.j;for(var a=0;a<=e;a++)c[a]=0;for(a=1;a<n;a+=2)c[i[a]]++;const f=s.K;for(o=0,c[0]=0,r=1;r<=e;r++)o=o+c[r-1]<<1,f[r]=o;for(h=0;h<n;h+=2)l=i[h+1],0!=l&&(i[h]=f[l],f[l]++)},t.H.A=function(i,e,s){const n=i.length,o=t.H.m.r;for(let t=0;t<n;t+=2)if(0!=i[t+1]){const n=t>>1,r=i[t+1],h=n<<4|r,l=e-r;let c=i[t]<<l;const a=c+(1<<l);for(;c!=a;){s[o[c]>>>15-e]=h,c++}}},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 o=i[t]<<e-i[t+1];i[t]=s[o]>>>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 o(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function r(t,i,e,s,n){let r=o(i);const l=Math.ceil(s*r/8);let c,a;r=Math.ceil(r/8);let f=t[e],d=0;if(f>1&&(t[e]=[0,0,1][f-2]),3==f)for(d=r;d<l;d++)t[d+1]=t[d+1]+(t[d+1-r]>>>1)&255;for(let i=0;i<n;i++)if(c=e+i*l,a=c+i+1,f=t[a-1],d=0,0==f)for(;d<l;d++)t[c+d]=t[a+d];else if(1==f){for(;d<r;d++)t[c+d]=t[a+d];for(;d<l;d++)t[c+d]=t[a+d]+t[c+d-r]}else if(2==f)for(;d<l;d++)t[c+d]=t[a+d]+t[c+d-l];else if(3==f){for(;d<r;d++)t[c+d]=t[a+d]+(t[c+d-l]>>>1);for(;d<l;d++)t[c+d]=t[a+d]+(t[c+d-l]+t[c+d-r]>>>1)}else{for(;d<r;d++)t[c+d]=t[a+d]+h(0,t[c+d-l],0);for(;d<l;d++)t[c+d]=t[a+d]+h(t[c+d-r],t[c+d-l],t[c+d-r-l])}return t}function h(t,i,e){const s=t+i-e,n=s-t,o=s-i,r=s-e;return n*n<=o*o&&n*n<=r*r?t:o*o<=r*r?i:e}function l(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 c(t,i,e,s,n,o,r,h,l){const c=Math.min(i,n),a=Math.min(e,o);let f=0,d=0;for(let e=0;e<a;e++)for(let o=0;o<c;o++)if(r>=0&&h>=0?(f=e*i+o<<2,d=(h+e)*n+r+o<<2):(f=(-h+e)*i-r+o<<2,d=e*n+o<<2),0==l)s[d]=t[f],s[d+1]=t[f+1],s[d+2]=t[f+2],s[d+3]=t[f+3];else if(1==l){var u=t[f+3]*(1/255),v=t[f]*u,p=t[f+1]*u,b=t[f+2]*u,g=s[d+3]*(1/255),w=s[d]*g,y=s[d+1]*g,k=s[d+2]*g;const i=1-u,e=u+g*i,n=0==e?0:1/e;s[d+3]=255*e,s[d+0]=(v+w*i)*n,s[d+1]=(p+y*i)*n,s[d+2]=(b+k*i)*n}else if(2==l){u=t[f+3],v=t[f],p=t[f+1],b=t[f+2],g=s[d+3],w=s[d],y=s[d+1],k=s[d+2];u==g&&v==w&&p==y&&b==k?(s[d]=0,s[d+1]=0,s[d+2]=0,s[d+3]=0):(s[d]=v,s[d+1]=p,s[d+2]=b,s[d+3]=u)}else if(3==l){u=t[f+3],v=t[f],p=t[f+1],b=t[f+2],g=s[d+3],w=s[d],y=s[d+1],k=s[d+2];if(u==g&&v==w&&p==y&&b==k)continue;if(u<220&&g>20)return false}return true}return{decode:function i(o){const r=new Uint8Array(o);let h=8;const c=t,a=c.readUshort,f=c.readUint,d={tabs:{},frames:[]},u=new Uint8Array(r.length);let v,p=0,b=0;const g=[137,80,78,71,13,10,26,10];for(var w=0;w<8;w++)if(r[w]!=g[w])throw"The input is not a PNG file!";for(;h<r.length;){const t=c.readUint(r,h);h+=4;const i=c.readASCII(r,h,4);if(h+=4,"IHDR"==i)l(r,h,d);else if("iCCP"==i){for(var y=h;0!=r[y];)y++;c.readASCII(r,h,y-h);const e=r.slice(y+2,h+t);let o=null;try{o=s(e)}catch(t){o=n(e)}d.tabs[i]=o}else if("CgBI"==i)d.tabs[i]=r.slice(h,h+4);else if("IDAT"==i){for(w=0;w<t;w++)u[p+w]=r[h+w];p+=t}else if("acTL"==i)d.tabs[i]={num_frames:f(r,h),num_plays:f(r,h+4)},v=new Uint8Array(r.length);else if("fcTL"==i){if(0!=b)(M=d.frames[d.frames.length-1]).data=e(d,v.slice(0,b),M.rect.width,M.rect.height),b=0;const t={x:f(r,h+12),y:f(r,h+16),width:f(r,h+4),height:f(r,h+8)};let i=a(r,h+22);i=a(r,h+20)/(0==i?100:i);const s={rect:t,delay:Math.round(1e3*i),dispose:r[h+24],blend:r[h+25]};d.frames.push(s)}else if("fdAT"==i){for(w=0;w<t-4;w++)v[b+w]=r[h+w+4];b+=t-4}else if("pHYs"==i)d.tabs[i]=[c.readUint(r,h),c.readUint(r,h+4),r[h+8]];else if("cHRM"==i){d.tabs[i]=[];for(w=0;w<8;w++)d.tabs[i].push(c.readUint(r,h+4*w))}else if("tEXt"==i||"zTXt"==i){null==d.tabs[i]&&(d.tabs[i]={});var k=c.nextZero(r,h),x=c.readASCII(r,h,k-h),m=h+t-k-1;if("tEXt"==i)A=c.readASCII(r,k+1,m);else{var z=s(r.slice(k+2,k+2+m));A=c.readUTF8(z,0,z.length)}d.tabs[i][x]=A}else if("iTXt"==i){null==d.tabs[i]&&(d.tabs[i]={});k=0,y=h;k=c.nextZero(r,y);x=c.readASCII(r,y,k-y);const e=r[y=k+1];var A;y+=2,k=c.nextZero(r,y),c.readASCII(r,y,k-y),y=k+1,k=c.nextZero(r,y),c.readUTF8(r,y,k-y);m=t-((y=k+1)-h);if(0==e)A=c.readUTF8(r,y,m);else{z=s(r.slice(y,y+m));A=c.readUTF8(z,0,z.length)}d.tabs[i][x]=A}else if("PLTE"==i)d.tabs[i]=c.readBytes(r,h,t);else if("hIST"==i){const t=d.tabs.PLTE.length/3;d.tabs[i]=[];for(w=0;w<t;w++)d.tabs[i].push(a(r,h+2*w))}else if("tRNS"==i)3==d.ctype?d.tabs[i]=c.readBytes(r,h,t):0==d.ctype?d.tabs[i]=a(r,h):2==d.ctype&&(d.tabs[i]=[a(r,h),a(r,h+2),a(r,h+4)]);else if("gAMA"==i)d.tabs[i]=c.readUint(r,h)/1e5;else if("sRGB"==i)d.tabs[i]=r[h];else if("bKGD"==i)0==d.ctype||4==d.ctype?d.tabs[i]=[a(r,h)]:2==d.ctype||6==d.ctype?d.tabs[i]=[a(r,h),a(r,h+2),a(r,h+4)]:3==d.ctype&&(d.tabs[i]=r[h]);else if("IEND"==i)break;h+=t,c.readUint(r,h),h+=4}var M;return 0!=b&&((M=d.frames[d.frames.length-1]).data=e(d,v.slice(0,b),M.rect.width,M.rect.height)),d.data=e(d,u,d.width,d.height),delete d.compress,delete d.interlace,delete d.filter,d},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 o=[];null==e.frames[0].data&&(e.frames[0].data=e.data);const r=s*n*4,h=new Uint8Array(r),l=new Uint8Array(r),a=new Uint8Array(r);for(let t=0;t<e.frames.length;t++){const d=e.frames[t],u=d.rect.x,v=d.rect.y,p=d.rect.width,b=d.rect.height,g=i(d.data,p,b,e);if(0!=t)for(var f=0;f<r;f++)a[f]=h[f];if(0==d.blend?c(g,p,b,h,s,n,u,v,0):1==d.blend&&c(g,p,b,h,s,n,u,v,1),o.push(h.buffer.slice(0)),0==d.dispose);else if(1==d.dispose)c(l,p,b,h,s,n,u,v,0);else if(2==d.dispose)for(f=0;f<r;f++)h[f]=a[f]}return o},_paeth:h,_copyTile:c,_bin:t}}();!function(){const{_copyTile:t}=bt,{_bin:i}=bt,e=bt._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 o=0;o<n;o++)t=s.table[255&(t^i[e+o])]^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 o(t){return Math.max(0,Math.min(255,t))}function r(t,i){const e=t[0]-i[0],s=t[1]-i[1],n=t[2]-i[2],o=t[3]-i[3];return e*e+s*s+n*n+o*o}function h(t,i,e,s,h,l,c){null==c&&(c=1);const a=s.length,f=[];for(var d=0;d<a;d++){const t=s[d];f.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(d=0;d<a;d++){let t=4294967295;for(var u=0,v=0;v<a;v++){var p=r(f[d],f[v]);v!=d&&p<t&&(t=p,u=v)}}const b=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(d=0;d<w.length;d++)w[d]=255*((w[d]+.5)/16-.5);for(let h=0;h<e;h++)for(let k=0;k<i;k++){var y;d=4*(h*i+k);if(2!=c)y=[o(t[d]+g[d]),o(t[d+1]+g[d+1]),o(t[d+2]+g[d+2]),o(t[d+3]+g[d+3])];else{p=w[4*(3&h)+(3&k)];y=[o(t[d]+p),o(t[d+1]+p),o(t[d+2]+p),o(t[d+3]+p)]}u=0;let x=16777215;for(v=0;v<a;v++){const t=r(y,f[v]);t<x&&(x=t,u=v)}const m=f[u],z=[y[0]-m[0],y[1]-m[1],y[2]-m[2],y[3]-m[3]];1==c&&(k!=i-1&&n(z,g,d+4,7),h!=e-1&&(0!=k&&n(z,g,d+4*i-4,3),n(z,g,d+4*i,5),k!=i-1&&n(z,g,d+4*i+4,1))),l[d>>2]=u,b[d>>2]=s[u]}}function l(t,e,n,o,r){null==r&&(r={});const{crc:h}=s,l=i.writeUint,c=i.writeUshort,a=i.writeASCII;let f=8;const d=t.frames.length>1;let u,v=false,p=33+(d?20:0);if(null!=r.sRGB&&(p+=13),null!=r.pHYs&&(p+=21),null!=r.iCCP&&(u=pako.deflate(r.iCCP),p+=21+u.length+4),3==t.ctype){for(var b=t.plte.length,g=0;g<b;g++)t.plte[g]>>>24!=255&&(v=true);p+=8+3*b+4+(v?8+1*b+4:0)}for(var w=0;w<t.frames.length;w++){d&&(p+=38),p+=(m=t.frames[w]).cimg.length+12,0!=w&&(p+=4)}p+=12;const y=new Uint8Array(p),k=[137,80,78,71,13,10,26,10];for(g=0;g<8;g++)y[g]=k[g];if(l(y,f,13),f+=4,a(y,f,"IHDR"),f+=4,l(y,f,e),f+=4,l(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++,l(y,f,h(y,f-17,17)),f+=4,null!=r.sRGB&&(l(y,f,1),f+=4,a(y,f,"sRGB"),f+=4,y[f]=r.sRGB,f++,l(y,f,h(y,f-5,5)),f+=4),null!=r.iCCP){const t=13+u.length;l(y,f,t),f+=4,a(y,f,"iCCP"),f+=4,a(y,f,"ICC profile"),f+=11,f+=2,y.set(u,f),f+=u.length,l(y,f,h(y,f-(t+4),t+4)),f+=4}if(null!=r.pHYs&&(l(y,f,9),f+=4,a(y,f,"pHYs"),f+=4,l(y,f,r.pHYs[0]),f+=4,l(y,f,r.pHYs[1]),f+=4,y[f]=r.pHYs[2],f++,l(y,f,h(y,f-13,13)),f+=4),d&&(l(y,f,8),f+=4,a(y,f,"acTL"),f+=4,l(y,f,t.frames.length),f+=4,l(y,f,null!=r.loop?r.loop:0),f+=4,l(y,f,h(y,f-12,12)),f+=4),3==t.ctype){l(y,f,3*(b=t.plte.length)),f+=4,a(y,f,"PLTE"),f+=4;for(g=0;g<b;g++){const i=3*g,e=t.plte[g],s=255&e,n=e>>>8&255,o=e>>>16&255;y[f+i+0]=s,y[f+i+1]=n,y[f+i+2]=o}if(f+=3*b,l(y,f,h(y,f-3*b-4,3*b+4)),f+=4,v){l(y,f,b),f+=4,a(y,f,"tRNS"),f+=4;for(g=0;g<b;g++)y[f+g]=t.plte[g]>>>24&255;f+=b,l(y,f,h(y,f-b-4,b+4)),f+=4}}let x=0;for(w=0;w<t.frames.length;w++){var m=t.frames[w];d&&(l(y,f,26),f+=4,a(y,f,"fcTL"),f+=4,l(y,f,x++),f+=4,l(y,f,m.rect.width),f+=4,l(y,f,m.rect.height),f+=4,l(y,f,m.rect.x),f+=4,l(y,f,m.rect.y),f+=4,c(y,f,o[w]),f+=2,c(y,f,1e3),f+=2,y[f]=m.dispose,f++,y[f]=m.blend,f++,l(y,f,h(y,f-30,30)),f+=4);const i=m.cimg;l(y,f,(b=i.length)+(0==w?0:4)),f+=4;const e=f;a(y,f,0==w?"IDAT":"fdAT"),f+=4,0!=w&&(l(y,f,x++),f+=4),y.set(i,f),f+=b,l(y,f,h(y,e,f-e)),f+=4}return l(y,f,0),f+=4,a(y,f,"IEND"),f+=4,l(y,f,h(y,f-4,4)),f+=4,y.buffer}function c(t,i,e){for(let s=0;s<t.frames.length;s++){const n=t.frames[s];const o=n.rect.height,r=new Uint8Array(o*n.bpl+o);n.cimg=u(n.img,o,n.bpp,n.bpl,r,i,e)}}function a(i,e,s,n,o){const r=o[0],l=o[1],c=o[2],a=o[3],u=o[4],v=o[5];let b=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,z=function i(e,s,n,o,r,h){const l=[];for(var c=0;c<e.length;c++){const i=new Uint8Array(e[c]),f=new Uint32Array(i.buffer);var a;let v=0,b=0,g=s,w=n,y=o?1:0;if(0!=c){const k=h||o||1==c||0!=l[c-2].dispose?1:2;let x=0,m=1e9;for(let t=0;t<k;t++){var u=new Uint8Array(e[c-1-t]);const i=new Uint32Array(e[c-1-t]);let o=s,h=n,l=-1,a=-1;for(let t=0;t<n;t++)for(let e=0;e<s;e++){f[p=t*s+e]!=i[p]&&(e<o&&(o=e),e>l&&(l=e),t<h&&(h=t),t>a&&(a=t))}-1==l&&(o=h=l=a=0),r&&(1==(1&o)&&o--,1==(1&h)&&h--);const d=(l-o+1)*(a-h+1);d<m&&(m=d,x=t,v=o,b=h,g=l-o+1,w=a-h+1)}u=new Uint8Array(e[c-1-x]);1==x&&(l[c-1].dispose=2),a=new Uint8Array(g*w*4),t(u,s,n,a,g,w,-v,-b,0),y=t(i,s,n,a,g,w,-v,-b,3)?1:0,1==y?d(i,s,n,a,{x:v,y:b,width:g,height:w}):t(i,s,n,a,g,w,-v,-b,0)}else a=i.slice(0);l.push({rect:{x:v,y:b,width:g,height:w},img:a,blend:y,dispose:0})}if(o)for(c=0;c<l.length;c++){if(1==(b=l[c]).blend)continue;const t=b.rect,i=l[c-1].rect,o=Math.min(t.x,i.x),h=Math.min(t.y,i.y),a={x:o,y:h,width:Math.max(t.x+t.width,i.x+i.width)-o,height:Math.max(t.y+t.height,i.y+i.height)-h};l[c-1].dispose=1,c-1!=0&&f(e,s,n,l,c-1,a,r),f(e,s,n,l,c,a,r)}let v=0;if(1!=e.length)for(var p=0;p<l.length;p++){var b;v+=(b=l[p]).rect.width*b.rect.height}return l}(i,e,s,r,l,c),A={},M=[],C=[];if(0!=n){const t=[];for(x=0;x<z.length;x++)t.push(z[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 o=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],r=t[i+2];const h=t[i+3];0==h&&(e=s=r=0),n[o+i]=e,n[o+i+1]=s,n[o+i+2]=r,n[o+i+3]=h}o+=e}return n.buffer}(t),e=p(i,n);for(x=0;x<e.plte.length;x++)M.push(e.plte[x].est.rgba);let s=0;for(x=0;x<z.length;x++){const t=(E=z[x]).img.length;var T=new Uint8Array(e.inds.buffer,s>>2,t>>2);C.push(T);const i=new Uint8Array(e.abuf,s,t);v&&h(E.img,E.rect.width,E.rect.height,M,i,T),E.img.set(i),s+=t}}else for(y=0;y<z.length;y++){var E=z[y];const t=new Uint32Array(E.img.buffer);var S=E.rect.width;k=t.length,T=new Uint8Array(k);C.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=A[i];if(null==t&&(A[i]=t=M.length,M.push(i),M.length>=300))break;T[x]=t}}}const j=M.length;j<=256&&0==u&&(g=j<=2?1:j<=4?2:j<=16?4:8,g=Math.max(g,a));for(y=0;y<z.length;y++){(E=z[y]).rect.x;S=E.rect.width;const t=E.rect.height;let i=E.img;let e=4*S,s=4;if(j<=256&&0==u){e=Math.ceil(g*S/8);var I=new Uint8Array(e*t);const n=C[y];for(let i=0;i<t;i++){x=i*e;const t=i*S;if(8==g)for(var F=0;F<S;F++)I[x+F]=n[t+F];else if(4==g)for(F=0;F<S;F++)I[x+(F>>1)]|=n[t+F]<<4-4*(1&F);else if(2==g)for(F=0;F<S;F++)I[x+(F>>2)]|=n[t+F]<<6-2*(3&F);else if(1==g)for(F=0;F<S;F++)I[x+(F>>3)]|=n[t+F]<<7-1*(7&F)}i=I,b=3,s=1}else if(0==m&&1==z.length){I=new Uint8Array(S*t*3);const n=S*t;for(x=0;x<n;x++){const t=3*x,e=4*x;I[t]=i[e],I[t+1]=i[e+1],I[t+2]=i[e+2]}i=I,b=2,s=3,e=3*S}E.img=i,E.bpl=e,E.bpp=s}return{ctype:b,depth:g,plte:M,frames:z}}function f(i,e,s,n,o,r,h){const l=Uint8Array,c=Uint32Array,a=new l(i[o-1]),f=new c(i[o-1]),u=o+1<i.length?new l(i[o+1]):null,v=new l(i[o]),p=new c(v.buffer);let b=e,g=s,w=-1,y=-1;for(let t=0;t<r.height;t++)for(let i=0;i<r.width;i++){const s=r.x+i,h=r.y+t,l=h*e+s,c=p[l];0==c||0==n[o-1].dispose&&f[l]==c&&(null==u||0!=u[4*l+3])||(s<b&&(b=s),s>w&&(w=s),h<g&&(g=h),h>y&&(y=h))}-1==w&&(b=g=w=y=0),h&&(1==(1&b)&&b--,1==(1&g)&&g--),r={x:b,y:g,width:w-b+1,height:y-g+1};const k=n[o];k.rect=r,k.blend=1,k.img=new Uint8Array(r.width*r.height*4),0==n[o-1].dispose?(t(a,e,s,k.img,r.width,r.height,-r.x,-r.y,0),d(v,e,s,k.img,r)):t(v,e,s,k.img,r.width,r.height,-r.x,-r.y,0)}function d(i,e,s,n,o){t(i,e,s,n,o.width,o.height,-o.x,-o.y,2)}function u(t,i,e,s,n,o,r){const h=[];let l,c=[0,1,2,3,4];-1!=o?c=[o]:(i*s>5e5||1==e)&&(c=[0]),r&&(l={level:0});const a=pt;for(var f=0;f<c.length;f++){for(let o=0;o<i;o++)v(n,t,o,s,e,c[f]);h.push(a.deflate(n,l))}let d,u=1e9;for(f=0;f<h.length;f++)h[f].length<u&&(d=f,u=h[f].length);return h[d]}function v(t,i,s,n,o,r){const h=s*n;let l=h+s;if(t[l]=r,l++,0==r)if(n<500)for(var c=0;c<n;c++)t[l+c]=i[h+c];else t.set(new Uint8Array(i.buffer,h,n),l);else if(1==r){for(c=0;c<o;c++)t[l+c]=i[h+c];for(c=o;c<n;c++)t[l+c]=i[h+c]-i[h+c-o]+256&255}else if(0==s){for(c=0;c<o;c++)t[l+c]=i[h+c];if(2==r)for(c=o;c<n;c++)t[l+c]=i[h+c];if(3==r)for(c=o;c<n;c++)t[l+c]=i[h+c]-(i[h+c-o]>>1)+256&255;if(4==r)for(c=o;c<n;c++)t[l+c]=i[h+c]-e(i[h+c-o],0,0)+256&255}else{if(2==r)for(c=0;c<n;c++)t[l+c]=i[h+c]+256-i[h+c-n]&255;if(3==r){for(c=0;c<o;c++)t[l+c]=i[h+c]+256-(i[h+c-n]>>1)&255;for(c=o;c<n;c++)t[l+c]=i[h+c]+256-(i[h+c-n]+i[h+c-o]>>1)&255}if(4==r){for(c=0;c<o;c++)t[l+c]=i[h+c]+256-e(0,i[h+c-n],0)&255;for(c=o;c<n;c++)t[l+c]=i[h+c]+256-e(i[h+c-o],i[h+c-n],i[h+c-o-n])&255}}}function p(t,i){const e=new Uint8Array(t),s=e.slice(0),n=new Uint32Array(s.buffer),o=b(s,i),r=o[0],h=o[1],l=e.length,c=new Uint8Array(l>>2);let a;if(e.length<2e7)for(var f=0;f<l;f+=4){a=g(r,d=e[f]*(1/255),u=e[f+1]*(1/255),v=e[f+2]*(1/255),p=e[f+3]*(1/255)),c[f>>2]=a.ind,n[f>>2]=a.est.rgba}else for(f=0;f<l;f+=4){var d=e[f]*(1/255),u=e[f+1]*(1/255),v=e[f+2]*(1/255),p=e[f+3]*(1/255);for(a=r;a.left;)a=w(a.est,d,u,v,p)<=0?a.left:a.right;c[f>>2]=a.ind,n[f>>2]=a.est.rgba}return{abuf:s.buffer,inds:c,plte:h}}function b(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 o=[n];for(;o.length<i;){let i=0,n=0;for(var r=0;r<o.length;r++)o[r].est.L>i&&(i=o[r].est.L,n=r);if(i<e)break;const h=o[n],l=y(t,s,h.i0,h.i1,h.est.e,h.est.eMq255);if(h.i0>=l||h.i1<=l){h.est.L=0;continue}const c={i0:h.i0,i1:l,bst:null,est:null,tdst:0,left:null,right:null};c.bst=x(t,c.i0,c.i1),c.est=m(c.bst);const a={i0:l,i1:h.i1,bst:null,est:null,tdst:0,left:null,right:null};a.bst={R:[],m:[],N:h.bst.N-c.bst.N};for(r=0;r<16;r++)a.bst.R[r]=h.bst.R[r]-c.bst.R[r];for(r=0;r<4;r++)a.bst.m[r]=h.bst.m[r]-c.bst.m[r];a.est=m(a.bst),h.left=c,h.right=a,o[n]=c,o.push(a)}o.sort(((t,i)=>i.bst.N-t.bst.N));for(r=0;r<o.length;r++)o[r].ind=r;return[n,o]}function g(t,i,e,s,n){if(null==t.left)return t.tdst=function t(i,e,s,n,o){const r=e-i[0],h=s-i[1],l=n-i[2],c=o-i[3];return r*r+h*h+l*l+c*c}(t.est.q,i,e,s,n),t;const o=w(t.est,i,e,s,n);let r=t.left,h=t.right;o>0&&(r=t.right,h=t.left);const l=g(r,i,e,s,n);if(l.tdst<=o*o)return l;const c=g(h,i,e,s,n);return c.tdst<l.tdst?c:l}function w(t,i,e,s,n){const{e:o}=t;return o[0]*i+o[1]*e+o[2]*s+o[3]*n-t.eMq}function y(t,i,e,s,n,o){for(s-=4;e<s;){for(;k(t,e,n)<=o;)e+=4;for(;k(t,s,n)>o;)s-=4;if(e>=s)break;const r=i[e>>2];i[e>>2]=i[s>>2],i[s>>2]=r,e+=4,s-=4}for(;k(t,e,n)>o;)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],o=e-i>>2;for(let o=i;o<e;o+=4){const i=t[o]*(1/255),e=t[o+1]*(1/255),r=t[o+2]*(1/255),h=t[o+3]*(1/255);n[0]+=i,n[1]+=e,n[2]+=r,n[3]+=h,s[0]+=i*i,s[1]+=i*e,s[2]+=i*r,s[3]+=i*h,s[5]+=e*e,s[6]+=e*r,s[7]+=e*h,s[10]+=r*r,s[11]+=r*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:o}}function m(t){const{R:i}=t,{m:e}=t,{N:s}=t,n=e[0],o=e[1],r=e[2],h=e[3],l=0==s?0:1/s,c=[i[0]-n*n*l,i[1]-n*o*l,i[2]-n*r*l,i[3]-n*h*l,i[4]-o*n*l,i[5]-o*o*l,i[6]-o*r*l,i[7]-o*h*l,i[8]-r*n*l,i[9]-r*o*l,i[10]-r*r*l,i[11]-r*h*l,i[12]-h*n*l,i[13]-h*o*l,i[14]-h*r*l,i[15]-h*h*l],a=c,f=z;let d=[Math.random(),Math.random(),Math.random(),Math.random()],u=0,v=0;if(0!=s)for(let t=0;t<16&&(d=f.multVec(a,d),v=Math.sqrt(f.dot(d,d)),d=f.sml(1/v,d),!(0!=t&&Math.abs(v-u)<1e-9));t++)u=v;const p=[n*l,o*l,r*l,h*l];return{Cov:c,q:p,e:d,L:u,eMq255:f.dot(f.sml(255,p),d),eMq:f.dot(d,p),rgba:(Math.round(255*p[3])<<24|Math.round(255*p[2])<<16|Math.round(255*p[1])<<8|Math.round(255*p[0])<<0)>>>0}}var z={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]]};bt.encode=function t(i,e,s,n,o,r,h){null==n&&(n=0),null==h&&(h=false);const f=a(i,e,s,n,[false,false,false,0,h,false]);return c(f,-1),l(f,e,s,o,r)},bt.encodeLL=function t(i,e,s,n,o,r,h,a){const f={ctype:0+(1==n?0:2)+(0==o?0:4),depth:r,frames:[]},d=(n+o)*r,u=d*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(d/8),bpl:Math.ceil(u/8)});return c(f,0,true),l(f,e,s,h,a)},bt.encode.compress=a,bt.encode.dither=h,bt.quantize=p,bt.quantize.getKDtree=b,bt.quantize.getNearest=g}();const gt={toArrayBuffer(t,i){const e=t.width,s=t.height,n=e<<2,o=t.getContext("2d").getImageData(0,0,e,s),r=new Uint32Array(o.data.buffer),h=(32*e+31)/32<<2,l=h*s,c=122+l,a=new ArrayBuffer(c),f=new DataView(a),d=1<<20;let u,v,p,b,g=d,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 z(t){y+=t}x(19778),m(c),z(4),m(122),m(108),m(e),m(-s>>>0),x(1),x(32),m(3),m(l),m(2835),m(2835),z(8),m(16711680),m(65280),m(255),m(4278190080),m(1466527264),function t(){for(;w<s&&g>0;){for(b=122+w*h,u=0;u<n;)g--,v=r[k++],p=v>>>24,f.setUint32(b+u,v<<8|p),u+=4;w++}k<r.length?(g=d,setTimeout(t,gt._dly)):i(a)}()},toBlob(t,i){this.toArrayBuffer(t,(t=>{i(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var wt={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},yt={[wt.CHROME]:16384,[wt.FIREFOX]:11180,[wt.DESKTOP_SAFARI]:16384,[wt.IE]:8192,[wt.IOS]:4096,[wt.ETC]:8192};const kt="undefined"!=typeof window,xt="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,mt=kt&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),zt=(kt||xt)&&(mt&&mt.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),At=(kt||xt)&&(mt&&mt.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function Mt(t,i,e=Date.now()){return new Promise((s=>{const n=t.split(","),o=n[0].match(/:(.*?);/)[1],r=globalThis.atob(n[1]);let h=r.length;const l=new Uint8Array(h);for(;h--;)l[h]=r.charCodeAt(h);const c=new Blob([l],{type:o});c.name=i,c.lastModified=e,s(c)}))}function Ct(t){return new Promise(((i,e)=>{const s=new At;s.onload=()=>i(s.result),s.onerror=t=>e(t),s.readAsDataURL(t)}))}function Tt(t){return new Promise(((i,e)=>{const s=new Image;s.onload=()=>i(s),s.onerror=t=>e(t),s.src=t}))}function Et(){if(void 0!==Et.cachedResult)return Et.cachedResult;let t=wt.ETC;const{userAgent:i}=navigator;return/Chrom(e|ium)/i.test(i)?t=wt.CHROME:/iP(ad|od|hone)/i.test(i)&&/WebKit/i.test(i)?t=wt.IOS:/Safari/i.test(i)?t=wt.DESKTOP_SAFARI:/Firefox/i.test(i)?t=wt.FIREFOX:(/MSIE/i.test(i)||true==!!document.documentMode)&&(t=wt.IE),Et.cachedResult=t,Et.cachedResult}function St(t,i){const e=Et(),s=yt[e];let n=t,o=i,r=n*o;const h=n>o?o/n:n/o;for(;r>s*s;){const t=(s+n)/2,i=(s+o)/2;t<i?(o=i,n=i*h):(o=t*h,n=t),r=n*o}return{width:n,height:o}}function jt(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 It(t,i){const{width:e,height:s}=St(t.width,t.height),[n,o]=jt(e,s);return i&&/jpe?g/.test(i)&&(o.fillStyle="white",o.fillRect(0,0,n.width,n.height)),o.drawImage(t,0,0,n.width,n.height),n}function Ft(){return void 0!==Ft.cachedResult||(Ft.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),Ft.cachedResult}function Bt(t,i={}){return new Promise((function(e,s){let n,o;var r=function(){try{return o=It(n,i.fileType||t.type),e([n,o])}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 Ct(t).then((function(t){try{return i=t,Tt(i).then((function(t){try{return n=t,function(){try{return r()}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(Ft()||[wt.DESKTOP_SAFARI,wt.MOBILE_SAFARI].includes(Et()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return n=t,r()}catch(t){return h()}}),h)}catch(t){h()}}))}function Ut(t,i,e,s,n=1){return new Promise((function(o,r){let h;if("image/png"===i){let c,a,f;return c=t.getContext("2d"),({data:a}=c.getImageData(0,0,t.width,t.height)),f=bt.encode([a.buffer],t.width,t.height,4096*n),h=new Blob([f],{type:i}),h.name=e,h.lastModified=s,l.call(this)}{if("image/bmp"===i)return new Promise((i=>gt.toBlob(t,i))).then(function(t){try{return h=t,h.name=e,h.lastModified=s,d.call(this)}catch(t){return r(t)}}.bind(this),r);{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,u.call(this)}catch(t){return r(t)}}.bind(this),r);{let v;return v=t.toDataURL(i,n),Mt(v,e,s).then(function(t){try{return h=t,u.call(this)}catch(t){return r(t)}}.bind(this),r)}function u(){return d.call(this)}}function d(){return l.call(this)}}function l(){return o(h)}}))}function Pt(t){t.width=0,t.height=0}function Ot(){return new Promise((function(t,i){let e,s,n,o;return void 0!==Ot.cachedResult?t(Ot.cachedResult):Mt("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(r){try{return e=r,Bt(e).then((function(r){try{return s=r[1],Ut(s,e.type,e.name,e.lastModified).then((function(e){try{return n=e,Pt(s),Bt(n).then((function(e){try{return o=e[0],Ot.cachedResult=1===o.width&&2===o.height,t(Ot.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 $t(t){return new Promise(((i,e)=>{const s=new At;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 o=0;o<s;o++)if(274==e.getUint16(n+12*o,t))return i(e.getUint16(n+12*o+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 Dt(t,i){const{width:e}=t,{height:s}=t,{maxWidthOrHeight:n}=i;let o,r=t;return isFinite(n)&&(e>n||s>n)&&([r,o]=jt(e,s),e>s?(r.width=n,r.height=s/e*n):(r.width=e/s*n,r.height=n),o.drawImage(t,0,0,r.width,r.height),Pt(t)),r}function Rt(t,i){const{width:e}=t,{height:s}=t,[n,o]=jt(e,s);switch(i>4&&i<9?(n.width=s,n.height=e):(n.width=e,n.height=s),i){case 2:o.transform(-1,0,0,1,e,0);break;case 3:o.transform(-1,0,0,-1,e,s);break;case 4:o.transform(1,0,0,-1,0,s);break;case 5:o.transform(0,1,1,0,0,0);break;case 6:o.transform(0,1,-1,0,s,0);break;case 7:o.transform(0,-1,-1,0,s,e);break;case 8:o.transform(0,-1,1,0,0,e)}return o.drawImage(t,0,0,e,s),Pt(t),n}function Qt(t,i,e=0){return new Promise((function(s,n){let o,r,h,l,c,a,f,d,u,v,p,b,g,w,y,k,x,m,z,A;function M(t=5){if(i.signal&&i.signal.aborted)throw i.signal.reason;o+=t,i.onProgress(Math.min(o,100))}function C(t){if(i.signal&&i.signal.aborted)throw i.signal.reason;o=Math.min(Math.max(t,o),100),i.onProgress(o)}return o=e,r=i.maxIteration||10,h=1024*i.maxSizeMB*1024,M(),Bt(t,i).then(function(e){try{return[,l]=e,M(),c=Dt(l,i),M(),new Promise((function(e,s){var n;if(!(n=i.exifOrientation))return $t(t).then(function(t){try{return n=t,o.call(this)}catch(t){return s(t)}}.bind(this),s);function o(){return e(n)}return o.call(this)})).then(function(e){try{return a=e,M(),Ot().then(function(e){try{return f=e?c:Rt(c,a),M(),d=i.initialQuality||1,u=i.fileType||t.type,Ut(f,u,t.name,t.lastModified,d).then(function(e){try{{if(v=e,M(),p=v.size>h,b=v.size>t.size,!p&&!b)return C(100),s(v);var o;function a(){if(r--&&(y>h||y>g)){let i,e;return i=A?.95*z.width:z.width,e=A?.95*z.height:z.height,[x,m]=jt(i,e),m.drawImage(z,0,0,i,e),d*="image/png"===u?.85:.95,Ut(x,u,t.name,t.lastModified,d).then((function(t){try{return k=t,Pt(z),z=x,y=k.size,C(Math.min(99,Math.floor((w-y)/(w-h)*100))),a}catch(t){return n(t)}}),n)}return[1]}return g=t.size,w=v.size,y=w,z=f,A=!i.alwaysKeepResolution&&p,(o=function(t){for(;t;){if(t.then)return void t.then(o,n);try{if(t.pop){if(t.length)return t.pop()?T.call(this):t;t=a}else t=t.call(this)}catch(t){return n(t)}}}.bind(this))(a);function T(){return Pt(z),Pt(x),Pt(c),Pt(f),Pt(l),C(100),s(k)}}}catch(E){return n(E)}}.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 _t="\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 Lt;function Wt(t,i){return new Promise(((e,s)=>{Lt||(Lt=function t(i){const e=[];return e.push(i),URL.createObjectURL(new Blob(e))}(_t));const n=new Worker(Lt);n.addEventListener("message",(function t(o){if(i.signal&&i.signal.aborted)n.terminate();else if(void 0===o.data.progress){if(o.data.error)return s(new Error(o.data.error)),void n.terminate();e(o.data.file),n.terminate()}else i.onProgress(o.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 Ht(t,i){return new Promise((function(e,s){let n,o,r,h,l,c;if(n={...i},r=0,({onProgress:h}=n),n.maxSizeMB=n.maxSizeMB||Number.POSITIVE_INFINITY,l="boolean"!=typeof n.useWebWorker||n.useWebWorker,delete n.useWebWorker,n.onProgress=t=>{r=t,"function"==typeof h&&h(r)},!(t instanceof Blob||t instanceof zt))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(c="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!l||"function"!=typeof Worker||c)return Qt(t,n).then(function(t){try{return o=t,d.call(this)}catch(t){return s(t)}}.bind(this),s);var a=function(){try{return d.call(this)}catch(t){return s(t)}}.bind(this),f=function(i){try{return Qt(t,n).then((function(t){try{return o=t,a()}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",Wt(t,n).then((function(t){try{return o=t,a()}catch(t){return f()}}),f)}catch(t){f()}function d(){try{o.name=t.name,o.lastModified=t.lastModified}catch(t){}try{n.preserveExif&&"image/jpeg"===t.type&&(!n.fileType||n.fileType&&n.fileType===t.type)&&(o=ft(t,o))}catch(t){}return e(o)}}))}Ht.getDataUrlFromFile=Ct,Ht.getFilefromDataUrl=Mt,Ht.loadImage=Tt,Ht.drawImageInCanvas=It,Ht.drawFileInCanvas=Bt,Ht.canvasToFile=Ut,Ht.getExifOrientation=$t,Ht.handleMaxWidthOrHeight=Dt,Ht.followExifOrientation=Rt,Ht.cleanupCanvasMemory=Pt,Ht.isAutoOrientationInBrowser=Ot,Ht.approximateBelowMaximumCanvasSizeOfBrowser=St,Ht.copyExifWithoutOrientation=ft,Ht.getBrowserName=Et,Ht.version="2.0.2";class Kt extends j{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];Ht(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 o=Math.min(s,n);i=t.width*o;e=t.height*o}return{scaledWidth:i,scaledHeight:e}}createKritzelImage(t,i,e){const s=X.create(this._store);s.src=t.src;s.width=i;s.height=e;s.zIndex=this._store.currentZIndex;s.centerInViewport();return s}addImageToStore(t){const i=ct.create(this._store);i.addOrRemove(t);i.selected=true;const e=new k(this._store,this,t);const s=new ot(this._store,this,i);this._store.history.executeCommand(new H(this._store,this,[e,s]));this._store.setState("activeTool",F.getTool("selection"))}handleCancel(){this._store.setState("activeTool",F.getTool("selection"))}}const Vt={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 Xt={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 Yt=[{name:"selection",type:"tool",tool:ht,icon:"cursor"},{name:"brush",type:"tool",tool:I,isDefault:true,icon:"pen",config:Vt},{name:"eraser",type:"tool",tool:V,icon:"eraser"},{name:"text",type:"tool",tool:P,icon:"type",config:Xt},{name:"image",type:"tool",tool:Kt,icon:"image"},{name:"divider",type:"divider"},{name:"config",type:"config"}];const Nt="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;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}kritzel-controls{position:absolute;bottom:28px}";const Gt=class{constructor(i){t(this,i);this.controls=Yt;this.customSvgIcons={};this.hideControls=false}handleTouchStart(t){if(t.cancelable){t.preventDefault()}}handleKeyDown(t){var i;if(t.key==="Escape"){t.preventDefault();(i=this.controlsRef)===null||i===void 0?void 0:i.closeTooltip()}}componentWillLoad(){this.registerCustomSvgIcons()}registerCustomSvgIcons(){for(const[t,i]of Object.entries(this.customSvgIcons)){W.register(t,i)}}render(){return e(s,{key:"009fe43f85f368b2f60b31947596e1423f60e28d"},e("kritzel-engine",{key:"76fa90e8c283723d546d02ab4eacc111047d6b9d",ref:t=>this.engineRef=t}),e("kritzel-controls",{key:"a7381534ab01236d12135f7a9f1a486c9b4be05a",ref:t=>this.controlsRef=t,controls:this.controls,style:this.hideControls?{display:"none"}:{display:"flex"}}))}get host(){return n(this)}};Gt.style=Nt;class qt{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()}handlePointerDown(t){if(t.pointerType==="mouse"){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;if(t.button===g.Right){this._store.state.isPanning=true;this._store.state.startX=i;this._store.state.startY=e}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());if(t.length===2){this._store.state.currentPath=null;this._store.state.isScaling=true;const i=t[0].clientX-this._store.offsetX;const e=t[0].clientY-this._store.offsetY;const s=t[1].clientX-this._store.offsetX;const n=t[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()}}}handlePointerMove(t){if(t.pointerType==="mouse"){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()}}if(t.pointerType==="touch"){const t=Array.from(this._store.state.pointers.values());if(t.length===2){const i=t[0].clientX-this._store.offsetX;const e=t[0].clientY-this._store.offsetY;const s=t[1].clientX-this._store.offsetX;const n=t[1].clientY-this._store.offsetY;const o=Math.sqrt(Math.pow(i-s,2)+Math.pow(e-n,2));const r=(i+s)/2;const h=(e+n)/2;const l=o/this.initialTouchDistance;const c=this._store.state.scale*l;if(c>this._store.state.scaleMax||c<this._store.state.scaleMin){this._store.state.translateX+=r-this.startX;this._store.state.translateY+=h-this.startY}else{const t=(r-this._store.state.translateX)*(l-1);const i=(h-this._store.state.translateY)*(l-1);this._store.state.translateX+=r-this.startX-t;this._store.state.translateY+=h-this.startY-i;this._store.state.scale=c;this.initialTouchDistance=o}this.startX=r;this.startY=h;this._store.state.hasViewportChanged=true;this._store.rerender()}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._store.state.isPanning){this._store.state.isPanning=false;this._store.rerender()}}if(t.pointerType==="touch"){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 o=(this._store.state.cursorX-this._store.state.translateX)*(n-1);const r=(this._store.state.cursorY-this._store.state.translateY)*(n-1);this._store.state.scale=s;this._store.state.translateX-=o;this._store.state.translateY-=r;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 Zt 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 Jt{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 ti{constructor(t){this._store=t;this.undoStack=new Jt(this._store.state.historyBufferSize);this.redoStack=new Jt(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 Zt(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 Zt(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 ii{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:o}=this.bounds;const r=s/2;const h=n/2;const l=o/2;this.children=[new ii({x:t,y:i,z:e,width:r,height:h,depth:l},this.capacity),new ii({x:t+r,y:i,z:e,width:r,height:h,depth:l},this.capacity),new ii({x:t,y:i+h,z:e,width:r,height:h,depth:l},this.capacity),new ii({x:t+r,y:i+h,z:e,width:r,height:h,depth:l},this.capacity),new ii({x:t,y:i,z:e+l,width:r,height:h,depth:l},this.capacity),new ii({x:t+r,y:i,z:e+l,width:r,height:h,depth:l},this.capacity),new ii({x:t,y:i+h,z:e+l,width:r,height:h,depth:l},this.capacity),new ii({x:t+r,y:i+h,z:e+l,width:r,height:h,depth:l},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 ei 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 si={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,longTouchTimeout:null,longTouchDelay:300,pointers:new Map};class ni{get history(){return this._history}get state(){return this._state}get currentZIndex(){return this._state.objectsOctree.filter((t=>!(t instanceof ct)&&!(t instanceof nt))).length}get allObjects(){return this._state.objectsOctree.allObjects()}get selectedObjects(){return this.allObjects.filter((t=>!(t instanceof ct))).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=si;this._kritzelEngine=t;this._history=new ti(this);this._state.objectsOctree=new ii({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 Y(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))))}}}delete(){if(!this.state.selectionGroup){return}const t=this.state.selectionGroup.objects.map((t=>new K(this,this.state.selectionGroup,t)));const i=new Y(this,this.state.selectionGroup);const e=[...t,i];this.history.executeCommand(new H(this,this.state.selectionGroup,e))}deleteObject(t,i=true){const e=this.findObjectById(t);if(e){if(i){const t=new K(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 Y(this,this.state.selectionGroup))}const o=this.state.copiedObjects.objects.map((t=>new k(this,this,t)));const r=new ot(this,this,this.state.copiedObjects);n.push(...o,r);this.history.executeCommand(new H(this,this,n));this.state.isSelecting=false;this.state.copiedObjects=this.state.selectionGroup.copy();this.setState("activeTool",F.getTool("selection"))}moveUp(){const t=this.allObjects.length+1;const i=this.state.selectionGroup.objects.map((i=>{if(i.zIndex===t){return}return new ei(this,this,i,{zIndex:i.zIndex+1})}));this.history.executeCommand(new H(this,this,i))}moveDown(){const t=0;const i=this.state.selectionGroup.objects.map((i=>{if(i.zIndex===t){return}return new ei(this,this,i,{zIndex:i.zIndex-1})}));this.history.executeCommand(new H(this,this,i))}moveToTop(){const t=this.allObjects.length+1;const i=this.state.selectionGroup.objects.map((i=>new ei(this,this,i,{zIndex:t})));this.history.executeCommand(new H(this,this,i))}moveToBottom(){const t=-1;const i=this.state.selectionGroup.objects.map((i=>new ei(this,this,i,{zIndex:t})));this.history.executeCommand(new H(this,this,i))}selectObjects(t){if(t.length===0){return}const i=ct.create(this);t.forEach((t=>{t.selected=false;i.addOrRemove(t)}));i.selected=true;this.state.selectionGroup=i;if(t.length===1){i.rotation=i.objects[0].rotation}this.history.executeCommand(new ot(this,this,i))}selectAllObjectsInViewport(){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 ct)&&!(t instanceof nt)&&!(t instanceof d)));if(t.length>0){const i=ct.create(this);t.forEach((t=>{t.selected=false;i.addOrRemove(t)}));i.selected=true;this.state.isSelecting=false;if(t.length===1){i.rotation=i.objects[0].rotation}this.history.executeCommand(new ot(this,this,i));this.setState("activeTool",F.getTool("selection"))}}clearSelection(){const t=new Y(this,this.state.selectionGroup);this.history.executeCommand(t);this.state.selectionGroup=null;this.state.selectionBox=null;this.state.isSelecting=false;this.state.isResizeHandleSelected=false;this.state.isRotationHandleSelected=false}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 o;if("touches"in t){const i=t.touches[0];if(!i)return null;n=i.clientX;o=i.clientY}else{n=t.clientX;o=t.clientY}const r=s.elementFromPoint(n,o);if(!r)return null;const h=r.closest(i);if(h){return this.allObjects.find((t=>h.id===t.id))}return null}}class oi extends G{constructor(t){super(t)}handleKeyDown(t){if(this._store.state.isFocused===false){t.preventDefault();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",F.getTool("selection"));this._store.deselectAllObjects()}if(t.key==="b"&&t.ctrlKey){this._store.setState("activeTool",F.getTool("brush"));this._store.deselectAllObjects()}if(t.key==="e"&&t.ctrlKey){this._store.setState("activeTool",F.getTool("eraser"));this._store.deselectAllObjects()}if(t.key==="i"&&t.ctrlKey){this._store.setState("activeTool",F.getTool("image"));this._store.deselectAllObjects()}if(t.key==="x"&&t.ctrlKey){this._store.setState("activeTool",F.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 ri extends G{constructor(t,i,e){super(t);this.globalContextMenuItems=[];this.objectContextMenuItems=[];this.globalContextMenuItems=i;this.objectContextMenuItems=e}handleContextMenu(t){if(this._store.state.skipContextMenu){this._store.state.skipContextMenu=false;return}const i=this._store.getObjectFromPointerEvent(t,".object");if(i&&!(i instanceof ct)){this._store.state.selectionGroup=ct.create(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 ot(this._store,this,this._store.state.selectionGroup))}this._store.state.contextMenuItems=this._store.state.selectionGroup?this.objectContextMenuItems:this.globalContextMenuItems;let e=t.clientX-this._store.offsetX;let s=t.clientY-this._store.offsetY;const n=150;const o=200;const r=10;if(e+n>window.innerWidth-r){e=window.innerWidth-n-r}if(s+o>window.innerHeight-r){s=window.innerHeight-o-r}e=Math.max(r,e);s=Math.max(r,s);this._store.state.contextMenuX=e;this._store.state.contextMenuY=s;this._store.state.isContextMenuVisible=true;this._store.state.isEnabled=false;this._store.rerender()}}const hi=":host{display:block;position:relative;height:100%;width:100%;overflow:hidden;background-color:var(--kritzel-engine-background-color, #ffffff)}:host,:host *{touch-action:none;user-select:none}.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 li=class{get isSelecting(){return this.store.state.activeTool instanceof ht&&this.store.state.isSelecting}get isSelectionActive(){return this.store.state.activeTool instanceof ht&&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.selectAllObjectsInViewport()}];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 ni(this);this.contextMenuHandler=new ri(this.store,this.globalContextMenuItems,this.objectContextMenuItems);this.keyHandler=new oi(this.store);this.store.onStateChange("activeTool",(t=>{if(!(t instanceof ht)){this.store.clearSelection()}this.store.state.skipContextMenu=false;this.activeToolChange.emit(t);U.forceHideKeyboard()}));this.store.onStateChange("isFocused",(t=>{if(!t){this.store.resetActiveText()}}))}componentDidLoad(){this.viewport=new qt(this.store,this.host);this.engineReady.emit()}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)}handlePointerDown(t){var i,e;if(w.isPointerEventOnContextMenu(t)===false&&this.store.state.isContextMenuVisible){this.hideContextMenu();return}if(this.store.state.isEnabled===false){return}w.onLongTouchPress(t,(t=>{if(!(this.store.state.activeTool instanceof ht)){return}this.contextMenuHandler.handleContextMenu(t)}));this.host.setPointerCapture(t.pointerId);this.store.state.pointers.set(t.pointerId,t);this.viewport.handlePointerDown(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handlePointerDown(t)}handlePointerMove(t){var i,e;if(this.store.state.isEnabled===false){return}this.store.state.pointers.set(t.pointerId,t);this.viewport.handlePointerMove(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handlePointerMove(t)}handlePointerUp(t){var i,e;if(this.store.state.isEnabled===false){return}this.store.state.pointers.delete(t.pointerId);this.host.releasePointerCapture(t.pointerId);this.viewport.handlePointerUp(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handlePointerUp(t)}handlePointerCancel(t){var i,e;if(this.store.state.isEnabled===false){return}this.host.releasePointerCapture(t.pointerId);this.store.state.pointers.delete(t.pointerId);this.viewport.handlePointerUp(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handlePointerUp(t)}handleContextMenu(t){t.preventDefault();if(this.store.state.isEnabled===false){return}if(t.pointerType==="touch"){return}this.contextMenuHandler.handleContextMenu(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 o=s.includes(n||this.host);this.store.setState("isFocused",e&&o)}handleContextMenuAction(t){t.detail.action();this.hideContextMenu()}async registerTool(t,i,e){if(typeof i!=="function"||!(i.prototype instanceof j)){console.error(`Failed to register tool "${t}": Tool class must be a constructor function`);return null}const s=F.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 undo(){this.store.history.undo()}async redo(){this.store.history.redo()}async hideContextMenu(){this.store.state.pointers.clear();this.store.state.isContextMenuVisible=false;this.store.state.selectionBox=null;this.store.state.isSelecting=false}async getObjectById(t){const i=this.store.objects.find((i=>i.id===t));return i||null}async addObject(t){this.store.deselectAllObjects();t.id=t.generateId();t._store=this.store;t.zIndex=this.store.currentZIndex;const i=new k(this.store,this,t);this.store.history.executeCommand(i);return t}async updateObject(t,i){this.store.deselectAllObjects();const e=new ei(this.store,this,t,i);this.store.history.executeCommand(e);return t}async removeObject(t){this.store.deselectAllObjects();const i=new K(this.store,this,t);this.store.history.executeCommand(i);return t}async selectObjects(t){var i;(i=this.store.state.activeTool)===null||i===void 0?void 0:i.onDeactivate();this.store.setState("activeTool",F.getTool("selection"));this.store.deselectAllObjects();this.store.selectObjects(t)}async selectAllObjectsInViewport(){var t;(t=this.store.state.activeTool)===null||t===void 0?void 0:t.onDeactivate();this.store.setState("activeTool",F.getTool("selection"));this.store.deselectAllObjects();this.store.selectAllObjectsInViewport()}async clearSelection(){this.store.clearSelection()}render(){var t,i,n,o,r,h,l,c,a,f,d,u,v,p,b,g,w,y,k,x,m,z,A,M,C,T,E;const j=window.getComputedStyle(this.host);const I=j.getPropertyValue("--kritzel-selection-handle-size").trim()||"6px";const F=parseFloat(I);const U=F*2<14?14:F;return e(s,{key:"632d8633bd27520dedda2e6eb84862d280fa6714"},e("div",{key:"fda3cdc033d97e1f17ae8fcede94933ae73458b3",class:"debug-panel",style:{display:this.store.state.debugInfo.showViewportInfo?"block":"none"}},e("div",{key:"823aac3e9b58615e7c499163bd9101675a62ff70"},"TranslateX: ",(t=this.store.state)===null||t===void 0?void 0:t.translateX),e("div",{key:"5d138212f0fefcaea7dc839f6d5f3e9c68c19681"},"TranslateY: ",(i=this.store.state)===null||i===void 0?void 0:i.translateY),e("div",{key:"8342eabd22ba71b58fe8346a182904cf5f4ccbb9"},"ViewportWidth: ",(n=this.store.state)===null||n===void 0?void 0:n.viewportWidth),e("div",{key:"325546fc07c2cfec7808e661d82f21db06d53aea"},"ViewportHeight: ",(o=this.store.state)===null||o===void 0?void 0:o.viewportHeight),e("div",{key:"2b1826604f561c58ad573d5545a0913498345b1f"},"ObjectsInViewport. ",this.store.objects.length),e("div",{key:"749b56a6bfd63c838c89c55595bedd6749ee89ad"},"Scale: ",(r=this.store.state)===null||r===void 0?void 0:r.scale),e("div",{key:"0ee63c810198cb583c4e419f14503f5fb8d71d32"},"ActiveTool: ",(l=(h=this.store.state)===null||h===void 0?void 0:h.activeTool)===null||l===void 0?void 0:l.name),e("div",{key:"5facf47db6f093db24b12fa4b4453d20af1b1f57"},"HasViewportChanged: ",((c=this.store.state)===null||c===void 0?void 0:c.hasViewportChanged)?"true":"false"),e("div",{key:"948069683ac1568257dab4dbd5d1b3e9926ac501"},"IsEnabled: ",((a=this.store.state)===null||a===void 0?void 0:a.isEnabled)?"true":"false"),e("div",{key:"a3e5bf4522b9d515bc7d346dbc9803af12eb60f5"},"IsScaling: ",((f=this.store.state)===null||f===void 0?void 0:f.isScaling)?"true":"false"),e("div",{key:"ce8fc21cd938e7a58fef489b086b5111b1612353"},"IsPanning: ",((d=this.store.state)===null||d===void 0?void 0:d.isPanning)?"true":"false"),e("div",{key:"5725282e17bbe0766ebe010377070df81c1542d2"},"IsFocused: ",this.store.state.isFocused?"true":"false"),e("div",{key:"8805bbfac86078d2a0541d60a53a3c6a9585a1db"},"IsSelecting: ",this.isSelecting?"true":"false"),e("div",{key:"1801d4d8297e36f4c14022c411ce5a1889042398"},"IsSelectionActive: ",this.isSelectionActive?"true":"false"),e("div",{key:"d269982265e35a511eeb892969b3e47eb21b023f"},"IsResizeHandleSelected: ",this.store.state.isResizeHandleSelected?"true":"false"),e("div",{key:"1362e4c3d93a8452705e5fb1a1ba6a0ffdb3c557"},"IsRotationHandleSelected: ",this.store.state.isRotationHandleSelected?"true":"false"),e("div",{key:"2181e07738e56e10c57c4d6a06acdd667a14da83"},"IsDrawing: ",this.store.state.isDrawing?"true":"false"),e("div",{key:"57b96821b4fb1cbc97ec7083fc523c0bdba7539b"},"IsWriting: ",this.store.state.isWriting?"true":"false"),e("div",{key:"c7302e6ce4635e04aa92a24878dd3cbce8724228"},"CursorX: ",(u=this.store.state)===null||u===void 0?void 0:u.cursorX),e("div",{key:"93b01e5d147ca445e6645749043bb7fb46852f39"},"CursorY: ",(v=this.store.state)===null||v===void 0?void 0:v.cursorY)),e("div",{key:"7b535830bbd75ca61e09d6984120e17168911d7d",class:"origin",style:{transform:`matrix(${(p=this.store.state)===null||p===void 0?void 0:p.scale}, 0, 0, ${(b=this.store.state)===null||b===void 0?void 0:b.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,o,r,h,l,c,a,f,d,u,v,p,b,g,w,y,k;return e("div",{style:{transform:t===null||t===void 0?void 0:t.transformationMatrix,transformOrigin:"top left",zIndex:t.zIndex.toString(),position:"absolute"}},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"}},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 S&&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 X&&e("img",{ref:i=>t.mount(i),src:t.src,style:{width:"100%",height:"100%",userSelect:"none",pointerEvents:"none"},draggable:false,onDragStart:t=>t.preventDefault()}),t instanceof B&&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",pointerEvents:t.isReadonly?"none":"auto",cursor:t.isReadonly?"default":"text",caretColor:t.isReadonly?"transparent":"auto"}}),t instanceof ct&&e("div",{ref:i=>t.mount(i),style:{width:"100%",height:"100%"}}),t instanceof nt&&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} / ${(o=this.store.state)===null||o===void 0?void 0:o.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} / ${(r=this.store.state)===null||r===void 0?void 0:r.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:`${U*t.scale/((l=this.store.state)===null||l===void 0?void 0:l.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/((c=this.store.state)===null||c===void 0?void 0:c.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:`${U*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 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:`${U*t.scale/((d=this.store.state)===null||d===void 0?void 0:d.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/((u=this.store.state)===null||u===void 0?void 0:u.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:`${U*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/((p=this.store.state)===null||p===void 0?void 0:p.scale)),style:{stroke:"var(--kritzel-selection-border-color, #0e1111)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${(b=this.store.state)===null||b===void 0?void 0:b.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:`${U*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:"cce82d436a044879bfbb900a836978c392f232ae",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:(z=this.store.state.currentPath)===null||z===void 0?void 0:z.transformationMatrix,transformOrigin:"top left",overflow:"visible"},viewBox:(A=this.store.state.currentPath)===null||A===void 0?void 0:A.viewBox},e("path",{key:"1c0366598a805faffc965824c30c05fe1f1e0f74",d:(M=this.store.state.currentPath)===null||M===void 0?void 0:M.d,fill:(C=this.store.state.currentPath)===null||C===void 0?void 0:C.fill,stroke:(T=this.store.state.currentPath)===null||T===void 0?void 0:T.stroke}))),this.store.state.isContextMenuVisible&&e("kritzel-context-menu",{key:"624855529efbe7a5de784e3e1ce2b82282fac63a",class:"context-menu",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)}),((E=this.store.state)===null||E===void 0?void 0:E.activeTool)instanceof V&&!this.store.state.isScaling&&e("kritzel-cursor-trail",{key:"d09a4701c43b8acec4e9daa09b69f545eebe95b7",store:this.store}))}get host(){return n(this)}};li.style=hi;const ci=":host{display:block}.font-preview{color:var(--kritzel-font-size-text-color, #333333);line-height:1;text-align:center;font-weight:bold}";const ai=class{constructor(i){t(this,i);this.fontFamily="Arial, sans-serif";this.size=24;this.color="#000000"}render(){return e(s,{key:"d0378237899c5641ae4354f3bffb14e3f8bafb59"},e("div",{key:"1475a6ae39ffc97eb780b30c85015c22cecafa6e",class:"font-preview",style:{fontFamily:this.fontFamily,fontSize:`${this.size}px`,color:this.color}},"A"))}};ai.style=ci;const fi=":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 di=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:"f420ff18156d54bfc475148a7d9aae0f1441408c"},e("kritzel-dropdown",{key:"6b54fb8265a0eb59a6a681c6a2b7a95fb222671c",options:t,value:this.selectedFontFamily,onValueChanged:this.handleDropdownValueChange,selectStyles:{fontFamily:this.selectedFontFamily}},e("button",{key:"b853c75a425c7baafa7a8e749c90c0b08884375c",class:"font-style-button",slot:"suffix"},"B"),e("button",{key:"68dea850dd1d1f38db727d8be0eec3481890c571",class:"font-style-button italic-text",slot:"suffix"},"I")))}};di.style=fi;const ui=":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 vi=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:"1c09a403f1e8278d30b2675c3a6e17e12ec79afa"},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})))))}};vi.style=ui;const pi=":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 bi=class{constructor(i){t(this,i);this.size=24}render(){const t=W.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}))}};bi.style=pi;const gi=":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 wi=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})))))}};wi.style=gi;const yi=":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 ki=768;const xi=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<ki}handleWindowResize(){this.isMobileView=window.innerWidth<ki;this.calculateAdjustedPosition()}componentWillLoad(){this.isMobileView=window.innerWidth<ki;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:"3161826337f6957d2e568f52cfe3f57d705af0ed",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:"12fc4bc05b7be756102ce3779c9be1d51f3fe13b",class:"tooltip-content",onClick:t=>t.stopPropagation()},e("slot",{key:"90f645f8f7cec371aaeda7207a9fb420b02b2ae4"}),e("div",{key:"73380e2c6df22bc4a97479a52315e7b34d069fa1",class:"tooltip-arrow-wrapper",style:{position:"fixed",left:this.arrowOffset,bottom:`-${this.arrowSize*2}px`}},e("div",{key:"2e13cb01a3282e161d3212f4970a93b20ca1a0fe",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:"30ddbd00b928c0c734656d6309eaefbae5baf264",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)}};xi.style=yi;const mi=":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 zi=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()})))}};zi.style=mi;export{r as kritzel_brush_style,l as kritzel_color,a as kritzel_color_palette,d as kritzel_context_menu,v as kritzel_control_brush_config,b as kritzel_control_text_config,D as kritzel_controls,Q as kritzel_cursor_trail,L as kritzel_dropdown,Gt as kritzel_editor,li as kritzel_engine,ai as kritzel_font,di as kritzel_font_family,vi as kritzel_font_size,bi as kritzel_icon,wi as kritzel_stroke_size,xi as kritzel_tooltip,zi as kritzel_utility_panel};
2
+ //# sourceMappingURL=p-dc26eb80.entry.js.map