kritzel-stencil 0.0.105 → 0.0.106

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 (157) hide show
  1. package/dist/cjs/kritzel-brush-style_18.cjs.entry.js +265 -123
  2. package/dist/cjs/kritzel-brush-style_18.cjs.entry.js.map +1 -1
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/stencil.cjs.js +1 -1
  5. package/dist/collection/classes/handlers/context-menu.handler.js +1 -1
  6. package/dist/collection/classes/handlers/context-menu.handler.js.map +1 -1
  7. package/dist/collection/classes/handlers/selection.handler.js +4 -4
  8. package/dist/collection/classes/handlers/selection.handler.js.map +1 -1
  9. package/dist/collection/classes/objects/base-object.class.js +7 -2
  10. package/dist/collection/classes/objects/base-object.class.js.map +1 -1
  11. package/dist/collection/classes/objects/image.class.js +14 -7
  12. package/dist/collection/classes/objects/image.class.js.map +1 -1
  13. package/dist/collection/classes/objects/path.class.js +22 -16
  14. package/dist/collection/classes/objects/path.class.js.map +1 -1
  15. package/dist/collection/classes/objects/selection-box.class.js +15 -9
  16. package/dist/collection/classes/objects/selection-box.class.js.map +1 -1
  17. package/dist/collection/classes/objects/selection-group.class.js +11 -5
  18. package/dist/collection/classes/objects/selection-group.class.js.map +1 -1
  19. package/dist/collection/classes/objects/text.class.js +29 -12
  20. package/dist/collection/classes/objects/text.class.js.map +1 -1
  21. package/dist/collection/classes/reviver.class.js +4 -4
  22. package/dist/collection/classes/reviver.class.js.map +1 -1
  23. package/dist/collection/classes/store.class.js +30 -14
  24. package/dist/collection/classes/store.class.js.map +1 -1
  25. package/dist/collection/classes/tools/brush-tool.class.js +4 -4
  26. package/dist/collection/classes/tools/brush-tool.class.js.map +1 -1
  27. package/dist/collection/classes/tools/image-tool.class.js +2 -2
  28. package/dist/collection/classes/tools/image-tool.class.js.map +1 -1
  29. package/dist/collection/classes/tools/selection-tool.class.js +1 -1
  30. package/dist/collection/classes/tools/selection-tool.class.js.map +1 -1
  31. package/dist/collection/classes/tools/text-tool.class.js +2 -2
  32. package/dist/collection/classes/tools/text-tool.class.js.map +1 -1
  33. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.css +10 -10
  34. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js +1 -1
  35. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js.map +1 -1
  36. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +42 -1
  37. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js.map +1 -1
  38. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +235 -22
  39. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
  40. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.css +43 -43
  41. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.js +2 -2
  42. package/dist/collection/components/shared/kritzel-brush-style/kritzel-brush-style.js.map +1 -1
  43. package/dist/collection/components/shared/kritzel-color/kritzel-color.css +20 -20
  44. package/dist/collection/components/shared/kritzel-color/kritzel-color.js +2 -2
  45. package/dist/collection/components/shared/kritzel-color/kritzel-color.js.map +1 -1
  46. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.js +1 -1
  47. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.css +53 -53
  48. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.js +1 -1
  49. package/dist/collection/components/shared/kritzel-dropdown/kritzel-dropdown.js.map +1 -1
  50. package/dist/collection/components/shared/kritzel-font/kritzel-font.css +10 -10
  51. package/dist/collection/components/shared/kritzel-font/kritzel-font.js +1 -1
  52. package/dist/collection/components/shared/kritzel-font/kritzel-font.js.map +1 -1
  53. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.css +48 -48
  54. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.js +2 -2
  55. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.js.map +1 -1
  56. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.css +30 -30
  57. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js +1 -1
  58. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js.map +1 -1
  59. package/dist/collection/components/shared/kritzel-icon/kritzel-icon.css +17 -17
  60. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.js +1 -1
  61. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.css +17 -17
  62. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js +4 -4
  63. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js.map +1 -1
  64. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js +1 -1
  65. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js.map +1 -1
  66. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.css +18 -18
  67. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js +2 -2
  68. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js.map +1 -1
  69. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.js +2 -2
  70. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +2 -2
  71. package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.js +1 -1
  72. package/dist/collection/interfaces/object.interface.js.map +1 -1
  73. package/dist/components/kritzel-brush-style.js +1 -1
  74. package/dist/components/kritzel-color-palette.js +1 -1
  75. package/dist/components/kritzel-color.js +1 -1
  76. package/dist/components/kritzel-context-menu.js +1 -1
  77. package/dist/components/kritzel-control-brush-config.js +1 -1
  78. package/dist/components/kritzel-control-text-config.js +1 -1
  79. package/dist/components/kritzel-controls.js +1 -1
  80. package/dist/components/kritzel-cursor-trail.js +1 -1
  81. package/dist/components/kritzel-dropdown.js +1 -1
  82. package/dist/components/kritzel-editor.js +58 -18
  83. package/dist/components/kritzel-editor.js.map +1 -1
  84. package/dist/components/kritzel-engine.js +1 -1
  85. package/dist/components/kritzel-font-family.js +1 -1
  86. package/dist/components/kritzel-font-size.js +1 -1
  87. package/dist/components/kritzel-font.js +1 -1
  88. package/dist/components/kritzel-stroke-size.js +1 -1
  89. package/dist/components/kritzel-tooltip.js +1 -1
  90. package/dist/components/kritzel-utility-panel.js +1 -1
  91. package/dist/components/{p-X3xYsp4r.js → p-9IX8ss5J.js} +6 -6
  92. package/dist/components/p-9IX8ss5J.js.map +1 -0
  93. package/dist/components/{p-Ddfewfv9.js → p-B1tJ3Woq.js} +3 -3
  94. package/dist/components/{p-Ddfewfv9.js.map → p-B1tJ3Woq.js.map} +1 -1
  95. package/dist/components/{p-D06w3u84.js → p-B7P9QBiE.js} +4 -4
  96. package/dist/components/p-B7P9QBiE.js.map +1 -0
  97. package/dist/components/{p-BjqfG-5H.js → p-BFlJumTk.js} +10 -10
  98. package/dist/components/{p-BjqfG-5H.js.map → p-BFlJumTk.js.map} +1 -1
  99. package/dist/components/{p-DT8_Rz-o.js → p-BcQCX1Z6.js} +67 -39
  100. package/dist/components/p-BcQCX1Z6.js.map +1 -0
  101. package/dist/components/{p-_wFpvzNp.js → p-Bhfk_puI.js} +4 -4
  102. package/dist/components/p-Bhfk_puI.js.map +1 -0
  103. package/dist/components/{p-BYH2jNAX.js → p-CF5pcRGS.js} +4 -4
  104. package/dist/components/{p-BYH2jNAX.js.map → p-CF5pcRGS.js.map} +1 -1
  105. package/dist/components/p-CZkSABuJ.js.map +1 -1
  106. package/dist/components/{p-BYt7-mGK.js → p-Cbu5RSmC.js} +3 -3
  107. package/dist/components/{p-BYt7-mGK.js.map → p-Cbu5RSmC.js.map} +1 -1
  108. package/dist/components/{p-DaeIjoQm.js → p-Ck2d5Wd1.js} +4 -4
  109. package/dist/components/p-Ck2d5Wd1.js.map +1 -0
  110. package/dist/components/{p-C3vo4rx8.js → p-CkPd1oL1.js} +151 -71
  111. package/dist/components/p-CkPd1oL1.js.map +1 -0
  112. package/dist/components/{p-C8KDwUb7.js → p-D9nf_Yw4.js} +3 -3
  113. package/dist/components/p-D9nf_Yw4.js.map +1 -0
  114. package/dist/components/{p-D31-QJwi.js → p-DIxwvThL.js} +17 -17
  115. package/dist/components/{p-D31-QJwi.js.map → p-DIxwvThL.js.map} +1 -1
  116. package/dist/components/{p-CDhTT8u8.js → p-Ds3FhuuO.js} +3 -3
  117. package/dist/components/p-Ds3FhuuO.js.map +1 -0
  118. package/dist/components/{p-BgUIonZF.js → p-I1jXruHK.js} +4 -4
  119. package/dist/components/p-I1jXruHK.js.map +1 -0
  120. package/dist/components/{p-BqUM5gV3.js → p-JvUh5Cky.js} +9 -9
  121. package/dist/components/p-JvUh5Cky.js.map +1 -0
  122. package/dist/components/{p-DQHNxDS7.js → p-c6tIpE_t.js} +3 -3
  123. package/dist/components/p-c6tIpE_t.js.map +1 -0
  124. package/dist/components/{p-BJ5xxphF.js → p-wUZba7Vi.js} +4 -4
  125. package/dist/components/{p-BJ5xxphF.js.map → p-wUZba7Vi.js.map} +1 -1
  126. package/dist/esm/kritzel-brush-style_18.entry.js +265 -123
  127. package/dist/esm/kritzel-brush-style_18.entry.js.map +1 -1
  128. package/dist/esm/loader.js +1 -1
  129. package/dist/esm/stencil.js +1 -1
  130. package/dist/stencil/p-7aaf3e49.entry.js +2 -0
  131. package/dist/stencil/p-7aaf3e49.entry.js.map +1 -0
  132. package/dist/stencil/stencil.esm.js +1 -1
  133. package/dist/types/classes/objects/base-object.class.d.ts +4 -3
  134. package/dist/types/classes/objects/image.class.d.ts +1 -1
  135. package/dist/types/classes/objects/path.class.d.ts +1 -1
  136. package/dist/types/classes/objects/selection-box.class.d.ts +1 -1
  137. package/dist/types/classes/objects/selection-group.class.d.ts +1 -1
  138. package/dist/types/classes/objects/text.class.d.ts +12 -1
  139. package/dist/types/classes/store.class.d.ts +3 -3
  140. package/dist/types/components/core/kritzel-editor/kritzel-editor.d.ts +7 -0
  141. package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +8 -1
  142. package/dist/types/components.d.ts +11 -3
  143. package/dist/types/interfaces/object.interface.d.ts +1 -1
  144. package/package.json +1 -1
  145. package/dist/components/p-BgUIonZF.js.map +0 -1
  146. package/dist/components/p-BqUM5gV3.js.map +0 -1
  147. package/dist/components/p-C3vo4rx8.js.map +0 -1
  148. package/dist/components/p-C8KDwUb7.js.map +0 -1
  149. package/dist/components/p-CDhTT8u8.js.map +0 -1
  150. package/dist/components/p-D06w3u84.js.map +0 -1
  151. package/dist/components/p-DQHNxDS7.js.map +0 -1
  152. package/dist/components/p-DT8_Rz-o.js.map +0 -1
  153. package/dist/components/p-DaeIjoQm.js.map +0 -1
  154. package/dist/components/p-X3xYsp4r.js.map +0 -1
  155. package/dist/components/p-_wFpvzNp.js.map +0 -1
  156. package/dist/stencil/p-d0394bb5.entry.js +0 -2
  157. package/dist/stencil/p-d0394bb5.entry.js.map +0 -1
@@ -1,2 +0,0 @@
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:"cb9a9485596d25280c6d96e30296ed8c6b3de0e1"},e("kritzel-dropdown",{key:"b2f22f627e91228ca42bcd2898b468fcb994d5f8",options:t,value:this.type,onValueChanged:t=>this.handleDropdownValueChange(t)},e("button",{key:"1a8ab8cc0917bcdcbbbd485354853b80dd2f9a7f",class:"brush-style-button",slot:"prefix"},e("kritzel-icon",{key:"62238f43f6a88a0a01d47e56d48179834edc4fc1",name:this.type,size:16}))))}};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:"e913815994a30d97f92781e742c4a13de19e59fe"},e("div",{key:"e0cc40b10dcb298f5b86be7d4283d6bffbd08c2c",class:"checkerboard-bg",style:{width:`${this.size}px`,height:`${this.size}px`,borderRadius:"50%",display:"inline-block",position:"relative"}},e("div",{key:"5e0a092a6d3463d852a1760d125fba04494e0d90",class:{"color-circle":true,white:t},style:{backgroundColor:this.value,width:`${this.size}px`,height:`${this.size}px`,borderRadius:"50%",position:"absolute",top:"0",left:"0",display:"inline-block"}})))}};l.style=h;const a=":host{display:flex;align-items:flex-start;gap:8px;padding:8px;width:100%;box-sizing:border-box}.color-grid{width:100%;display:grid;grid-template-columns:repeat(6, 32px);gap:8px;justify-items:center;overflow:hidden;height:40px;transition:height 0.1s ease-in-out}.color-grid.expanded{height:500px}.color-container{display:flex;justify-content:center;align-items:center;width:32px;height:32px;border-radius:50%;cursor:pointer;border:2px solid transparent;box-sizing:border-box}.color-container:hover{background-color:var(--kritzel-color-palette-hover-background-color, #f0f0f0)}.color-container.selected{border-color:var(--kritzel-selection-border-color, #0E1111);background-color:var(--kritzel-color-palette-selected-background-color)}";const c=class{constructor(e){t(this,e);this.colorChange=i(this,"colorChange");this.colors=[];this.selectedColor=null;this.isExpanded=false;this.isOpaque=false}handleColorClick(t){this.selectedColor=t;this.colorChange.emit(t)}calculateHeight(){const t=6;const i=32;const e=8;const s=Math.ceil(this.colors.length/t);return`${s*i+(s-1)*e}px`}render(){const t=this.isExpanded?this.colors:this.colors.slice(0,6);const i=this.isExpanded?this.calculateHeight():"32px";return e(s,{key:"0f0d176e1c8b199a973dbdb23b84e4a8d4d57f59"},e("div",{key:"1d4707cdb30752d21a5058dbbef5fb32934bd3bd",class:{"color-grid":true,expanded:this.isExpanded},style:{height:i}},t.map((t=>e("div",{class:{"color-container":true,selected:this.selectedColor===t},onClick:()=>this.handleColorClick(t)},e("kritzel-color",{value:t}))))))}};c.style=a;const d=":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 f=class{constructor(e){t(this,e);this.actionSelected=i(this,"actionSelected");this.close=i(this,"close")}handleItemClick(t){const i=typeof t.disabled==="function"?t.disabled():t.disabled;if(!i){this.actionSelected.emit(t)}}render(){return e(s,{key:"dfbafed8ab0ab62e8124763431e00283ddfc9aaa"},e("div",{key:"d0d7cf6241d24bd85ca2f4d2aa3e23aeb4283d82",class:"menu-container"},this.items.map((t=>e("button",{key:`${t.label}-${this.items.indexOf(t)}`,class:{"menu-item":true,disabled:typeof t.disabled==="function"?t.disabled():t.disabled},onClick:()=>this.handleItemClick(t),onTouchStart:()=>this.handleItemClick(t),disabled:typeof t.disabled==="function"?t.disabled():t.disabled},t.icon&&e("kritzel-icon",{name:t.icon,size:16}),e("span",{class:"label"},t.label))))))}get hostElement(){return n(this)}};f.style=d;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:"1658cc6062f9a62c11a7011e36bd5f892653f691"},e("div",{key:"bfafd20ebc6f7541e6a0952b555e3aefd0524086",style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-start",width:"100%",gap:"8px"}},e("kritzel-brush-style",{key:"6530b0fbee10db66f6dfd0e482e2a95279f303eb",type:this.tool.type,onTypeChange:t=>this.handleTypeChange(t)}),e("button",{key:"f16a4c5aefb298228d29576d6bf8a0632301169d",class:"expand-toggle",onClick:()=>this.handleToggleExpand(),title:this.isExpanded?"Collapse":"Expand",style:this.palette.length>6?{visibillity:"visible"}:{visibility:"hidden"}},e("kritzel-icon",{key:"138726189ee12b0d15dedfdbd07019701712ea3b",name:this.isExpanded?"chevron-up":"chevron-down"}))),e("kritzel-color-palette",{key:"ca15a07a28ad955d49289299265e1b62da508cfd",colors:this.palette,selectedColor:this.tool.color,isExpanded:this.isExpanded,isOpaque:true,onColorChange:t=>this.handleColorChange(t)}),e("kritzel-stroke-size",{key:"1017df7a36bad69af055fe08e685a1be3ff48b4b",selectedSize:this.tool.size,onSizeChange:t=>this.handleSizeChange(t)}))}static get watchers(){return{tool:["handleToolChange"]}}};v.style=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 detectDoubleTap(){const t=Date.now();const i=t-w.lastTapTimestamp;if(w.tapTimeoutId){clearTimeout(w.tapTimeoutId);w.tapTimeoutId=null}if(i<w.doubleTapTimeout&&i>0){w.lastTapTimestamp=0;return true}else{w.lastTapTimestamp=t;w.tapTimeoutId=setTimeout((()=>{w.tapTimeoutId=null}),w.doubleTapTimeout);return false}}}w.lastTapTimestamp=0;w.tapTimeoutId=null;w.doubleTapTimeout=300;class y{constructor(t,i){var e,s;this._store=t;this.initiator=(s=(e=i===null||i===void 0?void 0:i.constructor)===null||e===void 0?void 0:e.name)!==null&&s!==void 0?s:"Unknown";this.isUndoable=true}execute(){throw new Error("Method not implemented.")}undo(){throw new Error("Method not implemented.")}}class k extends y{constructor(t,i,e){super(t,i);this.object=e}execute(){this._store.state.objectsOctree.insert(this.object)}undo(){this._store.state.objectsOctree.remove((t=>t.id===this.object.id))}}var x={};var m;function 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:()=>C,getStrokeOutlinePoints:()=>M,getStrokePoints:()=>T});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 a(t,i){return[t[0]/i,t[1]/i]}function c(t){return[t[1],-t[0]]}function d(t,i){return t[0]*i[0]+t[1]*i[1]}function f(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 a(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:a=.5,simulatePressure:f=true,easing:u=t=>t,start:v={},end:g={},last:m=false}=i,{cap:M=true,easing:T=t=>t*(2-t)}=v,{cap:C=true,easing:E=t=>--t*t*t+1}=g;if(t.length===0||e<=0)return[];let S=t[t.length-1].runningLength,F=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,j=Math.pow(e*s,2),B=[],U=[],O=t.slice(0,10).reduce(((t,i)=>{let s=i.pressure;if(f){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),$=n(e,a,t[t.length-1].pressure,u),D,P=t[0].vector,R=t[0].point,Q=R,_=R,L=Q,H=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(a){if(f){let t=x(1,b/e),i=x(1,1-t);s=x(1,O+(i-O)*(t*z))}$=n(e,a,s,u)}else $=e/2;D===void 0&&(D=$);let k=g<F?T(g/F):1,m=S-g<I?E((S-g)/I):1;$=Math.max(.01,$*Math.min(k,m));let M=(i<t.length-1?t[i+1]:t[i]).vector,C=i<t.length-1?d(v,M):1,W=d(v,P)<0&&!H,K=C!==null&&C<0;if(W||K){let t=l(c(P),$);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&&(H=true);continue}if(H=false,i===t.length-1){let t=l(c(v),$);B.push(h(o,t)),U.push(r(o,t));continue}let V=l(c(y(M,v,C)),$);_=h(o,V),(i<=1||p(R,_)>j)&&(B.push(_),R=_),L=r(o,V),(i<=1||p(Q,L)>j)&&(U.push(L),Q=L),O=s,P=v}let W=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(!(F||I)||m){let t=k(W,b(c(h(W,K))),-(D||$)),i=[];for(let e=1/13,s=e;s<=1;s+=e)i.push(w(t,W,A*2*s));return i}}else{if(!(F||I&&t.length===1))if(M)for(let t=1/13,i=t;i<=1;i+=t){let t=w(U[0],W,A*i);V.push(t)}else{let t=h(B[0],U[0]),i=l(t,.5),e=l(t,.51);V.push(h(W,i),h(W,e),r(W,e),r(W,i))}let i=c(o(t[t.length-1].vector));if(I||F&&t.length===1)X.push(K);else if(C){let t=k(K,i,$);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,$)),r(K,l(i,$*.99)),h(K,l(i,$*.99)),h(K,l(i,$)))}return B.concat(X,U.reverse(),V)}function T(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,a=Array.isArray(t[0])?t:t.map((({x:t,y:i,pressure:e=.5})=>[t,i,e]));if(a.length===2){let t=a[1];a=a.slice(0,-1);for(let i=1;i<5;i++)a.push(y(a[0],t,i/4))}a.length===1&&(a=[...a,[...r(a[0],[1,1]),...a[0].slice(2)]]);let c=[{point:[a[0][0],a[0][1]],pressure:a[0][2]>=0?a[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],d=false,u=0,v=c[0],p=a.length-1;for(let t=1;t<a.length;t++){let i=o&&t===p?a[t].slice(0,2):y(v.point,a[t],l);if(f(v.point,i))continue;let e=g(i,v.point);if(u+=e,t<p&&!d){if(u<n)continue;d=true}v={point:i,pressure:a[t][2]>=0?a[t][2]:.5,vector:b(h(v.point,i)),distance:e,runningLength:u},c.push(v)}return c[0].vector=((e=c[1])==null?void 0:e.vector)||[0,0],c}function C(t,i={}){return M(T(t,i),i)}var E=C})(x);return x}var A=z();class M{static average(t,i){return(t+i)/2}}var T=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 C{static generateUUID(){return Math.random().toString(36).substr(2,9)}static clone(t){const i=t=>{const i=T(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(t){this.__class__="KritzelBaseObject";this.visible=true;this.borderWidth=0;this.opacity=1;this.padding=0;this.selected=false;this.resizing=false;this.rotation=0;this.markedForRemoval=false;this.isMounted=false;this.zIndex=0;this.debugInfoVisible=false;this._store=t;this.id=this.generateId()}mount(t){if(this.isMounted){return}this.elementRef=t;this.isMounted=true}generateId(){return C.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}revive(t){Object.assign(this,t);return this}}class S extends E{get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t,i){var e,s,n,o,r,h;super(t);this.__class__="KritzelPath";this.stroke="none";this.lineSlack=.5;this.x=0;this.y=0;this.height=0;this.width=0;this.scale=1;this.visible=true;this.debugInfoVisible=true;this.options=i;this.points=(e=i===null||i===void 0?void 0:i.points)!==null&&e!==void 0?e:[];this.translateX=(s=i===null||i===void 0?void 0:i.translateX)!==null&&s!==void 0?s:0;this.translateY=(n=i===null||i===void 0?void 0:i.translateY)!==null&&n!==void 0?n:0;this.scale=(o=i===null||i===void 0?void 0:i.scale)!==null&&o!==void 0?o:1;this.strokeWidth=(r=i===null||i===void 0?void 0:i.strokeWidth)!==null&&r!==void 0?r:8;this.fill=(h=i===null||i===void 0?void 0:i.fill)!==null&&h!==void 0?h:"#000000";this.zIndex=9999;this.d=this.generateSvgPath();this.updateDimensions()}resize(t,i,e,s){if(e<=1||s<=1){return}const n=e/this.width;const 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 F{constructor(t){this.__class__=this.constructor.name;this.name="base-tool";this._store=t}onActivate(){}onDeactivate(){}handleMouseDown(t){}handleMouseMove(t){}handleMouseUp(t){}handleDoubleClick(t){}handleDoubleTap(t){}handleTouchStart(t){}handleTouchMove(t){}handleTouchEnd(t){}handleWheel(t){}revive(t){Object.assign(this,t);return this}}class I extends F{constructor(t){super(t);this.type="pen";this.color="#000000";this.size=6;this.palettes={pen:["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#808080","#C0C0C0","#800000","#008000","#000080","#808000","#800080"],highlighter:["#ffff00","#ffb347","#b4ffb4"]}}handleMouseDown(t){if(w.isLeftClick(t)){this._store.state.isDrawing=true;const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.currentPath=new S(this._store,{points:[[i,e]],translateX:-this._store.state.translateX,translateY:-this._store.state.translateY,scale:this._store.state.scale,fill:this.color,strokeWidth:this.size})}}handleMouseMove(t){if(this._store.state.isDrawing){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.currentPath=new S(this._store,{points:[...this._store.state.currentPath.points,[i,e]],translateX:-this._store.state.translateX,translateY:-this._store.state.translateY,scale:this._store.state.scale,fill:this.color,strokeWidth:this.size});this._store.rerender()}}handleMouseUp(t){if(this._store.state.isDrawing){this._store.state.isDrawing=false;if(this._store.state.currentPath){this._store.state.currentPath.zIndex=this._store.currentZIndex;this._store.history.executeCommand(new k(this._store,this,this._store.state.currentPath))}this._store.state.currentPath=undefined}}handleTouchStart(t){if(this._store.state.touchCount===1){const i=Math.round(t.touches[0].clientX-this._store.offsetX);const e=Math.round(t.touches[0].clientY-this._store.offsetY);this._store.state.isDrawing=true;this._store.state.currentPath=new S(this._store,{points:[[i,e]],translateX:-this._store.state.translateX,translateY:-this._store.state.translateY,scale:this._store.state.scale,fill:this.color,strokeWidth:this.size});this._store.rerender()}}handleTouchMove(t){if(this._store.state.touchCount===1){const i=Math.round(t.touches[0].clientX-this._store.offsetX);const e=Math.round(t.touches[0].clientY-this._store.offsetY);this._store.state.currentPath=new S(this._store,{points:[...this._store.state.currentPath.points,[i,e]],translateX:-this._store.state.translateX,translateY:-this._store.state.translateY,scale:this._store.state.scale,fill:this.color,strokeWidth:this.size});this._store.rerender()}}handleTouchEnd(t){if(this._store.state.isDrawing){this._store.state.isDrawing=false;if(this._store.state.currentPath){this._store.state.currentPath.zIndex=this._store.currentZIndex;this._store.history.executeCommand(new k(this._store,this,this._store.state.currentPath))}this._store.state.currentPath=undefined;this._store.rerender()}}}class j extends E{get isReadonly(){return!(this._store.state.activeTool instanceof U)}constructor(t,i,e){super(t);this.__class__="KritzelText";this.value="";this.fontFamily="Arial";this.fontSize=8;this.fontColor="#000000";this.initialWidth=3;this.isNew=true;this.debugInfoVisible=true;this.rows=1;this.fontSize=i;this.fontFamily=e;this.translateX=0;this.translateY=0;this.width=this.initialWidth/(this._store.state.scale<0?this._store.state.scale:1);this.height=this.fontSize*1.2/(this._store.state.scale<0?this._store.state.scale:1);this.padding=5;this.backgroundColor="transparent";this.scale=this._store.state.scale;this.value=" "}mount(t){if(this.isMounted&&this.elementRef===t||this.isInViewport()===false){return}this.elementRef=t;this.isMounted=true}resize(t,i,e,s){if(e<=1||s<=1){return}const n=s/this.height;this.fontSize=this.fontSize*n;this.width=this.width*n;this.height=s;this.translateX=t;this.translateY=i}handleKeyDown(t){if(this.isReadonly){t.preventDefault();t.stopPropagation()}}handleInput(t){const i=t.target;if(i.value===""){this.value=" ";i.value=" ";i.selectionStart=i.selectionEnd=i.value.length}else{this.value=i.value.trim()}this.adjustTextareaSize()}adjustTextareaSize(){if(this.elementRef){const t=document.createElement("span");t.style.position="absolute";t.style.whiteSpace="pre-wrap";t.style.visibility="hidden";t.style.fontSize=window.getComputedStyle(this.elementRef).fontSize;t.style.fontFamily=window.getComputedStyle(this.elementRef).fontFamily;t.innerHTML=this.elementRef.value.replace(/&/g,"&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)}}}}class B{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}}B.registry={};class U extends F{constructor(t){super(t);this.fontFamily="Arial";this.fontSize=16;this.fontColor="#000000";this.palette=["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#808080","#C0C0C0","#800000","#008000","#000080","#808000","#800080"]}handleMouseDown(t){const i=t.composedPath().slice(1);const e=i.find((t=>t.classList&&t.classList.contains("object")));const s=this._store.findObjectById(e===null||e===void 0?void 0:e.id);if(this._store.state.activeText===null&&s&&s instanceof j){this._store.state.activeText=s;s.focus();return}if(this._store.state.activeText!==null&&s instanceof j){s.focus();return}if(this._store.state.activeText!==null){this._store.resetActiveText();this._store.setState("activeTool",B.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=new j(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;r.adjustTextareaSize();this._store.state.activeText=r;this._store.history.executeCommand(new k(this._store,this,r))}handleMouseUp(t){var i,e;(i=this._store.state.activeText)===null||i===void 0?void 0:i.focus();(e=this._store.state.activeText)===null||e===void 0?void 0:e.adjustTextareaSize()}handleTouchStart(t){const i=t.composedPath().slice(1);const e=i.find((t=>t.classList&&t.classList.contains("object")));const s=this._store.findObjectById(e===null||e===void 0?void 0:e.id);if(this._store.state.activeText===null&&s&&s instanceof j){this._store.state.activeText=s;s.focus();return}if(this._store.state.activeText!==null&&s instanceof j){s.focus();return}if(this._store.state.activeText!==null){this._store.resetActiveText();this._store.setState("activeTool",B.getTool("selection"));return}if(this._store.state.touchCount>1){return}const n=Math.round(t.touches[0].clientX-this._store.offsetX);const o=Math.round(t.touches[0].clientY-this._store.offsetY);const r=new j(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))}handleTouchEnd(t){var i,e;(i=this._store.state.activeText)===null||i===void 0?void 0:i.focus();(e=this._store.state.activeText)===null||e===void 0?void 0:e.adjustTextareaSize()}}const O=":host{display:flex;flex-direction:column;user-select:none}.kritzel-controls{display:flex;flex-direction:row;align-items:center;justify-content:flex-start;gap:var(--kritzel-controls-gap, 8px);height:100%;padding:var(--kritzel-controls-padding, 8px);background-color:var(--kritzel-controls-background-color, #ffffff);border-radius:var(--kritzel-controls-border-radius, 8px);box-shadow:var(--kritzel-controls-box-shadow, 0 0 3px rgba(0, 0, 0, 0.08));border:var(--kritzel-controls-border, 1px solid hsl(0, 0%, 0%, 4.3%));border-radius:var(--kritzel-controls-border-radius, 8px);z-index:10000;position:relative}.kritzel-control{display:flex;justify-content:center;align-items:center;color:var(--kritzel-controls-control-color, #000000);border-radius:var(--kritzel-controls-control-border-radius, 8px);padding:var(--kritzel-controls-control-padding, 8px);border:none;outline:none;background:none;cursor:pointer;-webkit-tap-highlight-color:transparent;font-weight:bold}.kritzel-control:hover{background-color:var(--kritzel-controls-control-hover-background-color, hsl(0, 0%, 0%, 4.3%))}.kritzel-control:active{background-color:var(--kritzel-controls-control-active-background-color, hsl(0, 0%, 0%, 8.6%))}.kritzel-control.selected,.kritzel-control.selected:hover,.kritzel-control.selected:active{background-color:var(--kritzel-controls-control-selected-background-color, #0E1111);color:var(--kritzel-controls-control-selected-color, #ffffff)}.kritzel-divider{width:var(--kritzel-controls-divider-width, 1px);height:var(--kritzel-controls-divider-height, 24px);background-color:var(--kritzel-controls-divider-background-color, hsl(0, 0%, 0%, 4.3%))}.kritzel-config-container{position:relative;display:flex;justify-content:center;align-items:center;width:40px;height:40px;box-sizing:border-box;-webkit-tap-highlight-color:transparent}.kritzel-config{display:flex;justify-content:center;align-items:center;cursor:pointer}.color-container{display:flex;justify-content:center;align-items:center;width:32px;height:32px;border-radius:50%;cursor:pointer;border:2px solid transparent;box-sizing:border-box;background-color:var(--kritzel-color-palette-hover-background-color, #f0f0f0)}.font-container{display:flex;justify-content:center;align-items:center;width:32px;height:32px;border-radius:50%;cursor:pointer;border:2px solid transparent;box-sizing:border-box;background-color:var(--kritzel-color-palette-hover-background-color, #f0f0f0)}.no-config{height:24px;width:24px;border-radius:50%;border:1px dashed gray}kritzel-tooltip{position:fixed;bottom:66px;left:50%;transform:translateX(-50%);z-index:10001}";const $=class{constructor(e){t(this,e);this.controlsReady=i(this,"controlsReady");this.controls=[];this.activeControl=null;this.firstConfig=null;this.tooltipVisible=false;this.kritzelEngine=null}get activeToolAsTextTool(){var t;return(t=this.activeControl)===null||t===void 0?void 0:t.tool}get activeToolAsBrushTool(){var t;return(t=this.activeControl)===null||t===void 0?void 0:t.tool}async componentWillLoad(){await this.initializeEngine();await this.initializeTools()}componentDidLoad(){this.controlsReady.emit()}async initializeEngine(){await customElements.whenDefined("kritzel-engine");this.kritzelEngine=this.host.parentElement.querySelector("kritzel-engine");if(!this.kritzelEngine){throw new Error("kritzel-engine not found in parent element.")}}async initializeTools(){for(const t of this.controls){if(t.type==="tool"&&t.tool){t.tool=await this.kritzelEngine.registerTool(t.name,t.tool,t.config)}if(t.type==="tool"&&t.isDefault&&t.tool){await this.kritzelEngine.changeActiveTool(t.tool);this.activeControl=t}if(t.type==="config"){if(this.firstConfig===null){this.firstConfig=t}else{console.warn("Only one config control is allowed. The first one will be used.")}}}}async handleActiveToolChange(t){var i;this.activeControl=this.controls.find((i=>i.tool===t.detail))||null;await((i=this.kritzelEngine)===null||i===void 0?void 0:i.setFocus())}handleClick(t){const i=t.target;if(!this.kritzelEngine||i.closest(".kritzel-tooltip")){return}this.tooltipVisible=false;this.kritzelEngine.enable()}preventDefault(t){if(t.cancelable){t.preventDefault();t.stopPropagation()}}async handleControlClick(t){this.activeControl=t;if(this.activeControl.type==="tool"){await this.kritzelEngine.changeActiveTool(this.activeControl.tool)}}handleConfigClick(t){t.stopPropagation();this.tooltipVisible=!this.tooltipVisible;this.kritzelEngine.disable()}async handleToolChange(t){this.activeControl=Object.assign(Object.assign({},this.activeControl),{tool:t.detail});await this.kritzelEngine.changeActiveTool(this.activeControl.tool)}render(){var t,i;const n=((t=this.activeControl)===null||t===void 0?void 0:t.config)===undefined||((i=this.activeControl)===null||i===void 0?void 0:i.config)===null;return e(s,{key:"2b13783ef0f1638ad76bfcef22c17c3eeb849d67"},e("kritzel-utility-panel",{key:"1babeb88133cebc9057c85723b812b99152316c6",style:{position:"absolute",bottom:"56px",left:"12px"},onUndo:()=>{var t;return(t=this.kritzelEngine)===null||t===void 0?void 0:t.undo()},onRedo:()=>{var t;return(t=this.kritzelEngine)===null||t===void 0?void 0:t.redo()},onDelete:()=>{var t;return(t=this.kritzelEngine)===null||t===void 0?void 0:t.delete()}}),e("div",{key:"8fafebdf6726dd2bffe85cb2b3ada5f4885a2bf8",class:"kritzel-controls"},this.controls.map((t=>{var i,s,o,r,h,l,a,c;if(t.type==="tool"){return e("button",{class:{"kritzel-control":true,selected:((i=this.activeControl)===null||i===void 0?void 0:i.name)===(t===null||t===void 0?void 0:t.name)},key:t.name,onClick:i=>{var e;return(e=this.handleControlClick)===null||e===void 0?void 0:e.call(this,t)}},e("kritzel-icon",{name:t.icon}))}if(t.type==="divider"){return e("div",{class:"kritzel-divider",key:t.name})}if(t.type==="config"&&t.name===((s=this.firstConfig)===null||s===void 0?void 0:s.name)&&this.activeControl){return e("div",{class:"kritzel-config-container",key:t.name},e("kritzel-tooltip",{isVisible:this.tooltipVisible,anchorElement:(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 U&&e("div",{class:"font-container"},e("kritzel-font",{fontFamily:(l=this.activeToolAsTextTool)===null||l===void 0?void 0:l.fontFamily,size:(a=this.activeToolAsTextTool)===null||a===void 0?void 0:a.fontSize,color:(c=this.activeToolAsTextTool)===null||c===void 0?void 0:c.fontColor})),n&&e("div",{class:"no-config"})))}}))))}static get assetsDirs(){return["../assets"]}get host(){return n(this)}};$.style=O;const D=":host{display:block;position:fixed;top:0;left:0;width:100vw;height:100vh;pointer-events:none;z-index:9000}";const P=class{constructor(i){t(this,i);this.cursorTrailPoints=[];this.isLeftButtonDown=false;this.TRAIL_DURATION_MS=100;this.MAX_TRAIL_POINTS=50}componentDidLoad(){this.trailCleanupIntervalId=window.setInterval((()=>{const t=Date.now();const i=this.cursorTrailPoints.filter((i=>t-i.timestamp<this.TRAIL_DURATION_MS));if(i.length!==this.cursorTrailPoints.length){this.cursorTrailPoints=i}}),50)}disconnectedCallback(){if(this.trailCleanupIntervalId){window.clearInterval(this.trailCleanupIntervalId)}}handleMouseDown(t){if(t.button===0){this.isLeftButtonDown=true;this.cursorTrailPoints=[]}}handleMouseMove(t){if(!this.isLeftButtonDown){return}const i={x:t.clientX,y:t.clientY,timestamp:Date.now()};const e=[i,...this.cursorTrailPoints];if(e.length>this.MAX_TRAIL_POINTS){this.cursorTrailPoints=e.slice(0,this.MAX_TRAIL_POINTS)}else{this.cursorTrailPoints=e}}handleMouseUp(t){if(t.button===0){this.isLeftButtonDown=false;this.cursorTrailPoints=[]}}handleTouchStart(t){if(t.touches.length===1){this.isLeftButtonDown=true;this.cursorTrailPoints=[]}}handleTouchMove(t){if(!this.isLeftButtonDown){return}const i=t.touches[0];const e={x:i.clientX,y:i.clientY,timestamp:Date.now()};const s=[e,...this.cursorTrailPoints];if(s.length>this.MAX_TRAIL_POINTS){this.cursorTrailPoints=s.slice(0,this.MAX_TRAIL_POINTS)}else{this.cursorTrailPoints=s}}handleTouchEnd(t){if(t.touches.length===0){this.isLeftButtonDown=false;this.cursorTrailPoints=[]}}render(){return e(s,{key:"604f5c39a01f3aea870861de0a93cd162302d7b2"},this.cursorTrailPoints.length>1&&e("svg",{key:"6f69f0b5a871010581b73bff51b2ef7341389f5a",class:"cursor-trail-svg",xmlns:"http://www.w3.org/2000/svg",style:{position:"absolute",left:"0",top:"0",width:"100%",height:"100%",pointerEvents:"none",opacity:"var(--kritzel-cursor-trail-opacity, 0.6)",zIndex:"9000"}},this.cursorTrailPoints.slice(1).map(((t,i)=>{const s=this.cursorTrailPoints[i];const n=Date.now();const 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"})}))))}};P.style=D;const R=':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 Q=class{constructor(e){t(this,e);this.valueChanged=i(this,"valueChanged");this.options=[];this.selectStyles={};this.hasSuffixContent=false;this.hasPrefixContent=false;this.handleSelectChange=t=>{const i=t.target.value;if(this.internalValue!==i){this.internalValue=i;this.valueChanged.emit(this.internalValue)}};this.evaluateSuffixContent=()=>{if(this.suffixSlotElement){const t=this.suffixSlotElement.assignedNodes({flatten:true}).length>0;if(this.hasSuffixContent!==t){this.hasSuffixContent=t}}else{if(this.hasSuffixContent!==false){this.hasSuffixContent=false}}};this.evaluatePrefixContent=()=>{if(this.prefixSlotElement){const t=this.prefixSlotElement.assignedNodes({flatten:true}).length>0;if(this.hasPrefixContent!==t){this.hasPrefixContent=t}}else{if(this.hasPrefixContent!==false){this.hasPrefixContent=false}}}}componentWillLoad(){this.updateInternalValue(this.value,false);this.evaluateSuffixContent();this.evaluatePrefixContent()}externalValueChanged(t){if(t!==this.internalValue){this.updateInternalValue(t,false)}}optionsChanged(){this.updateInternalValue(this.internalValue,true)}updateInternalValue(t,i){let e=t;if(this.options&&this.options.length>0){const t=this.options.some((t=>t.value===e));if(!e||!t){e=this.options[0].value}}else{e=undefined}if(this.internalValue!==e){this.internalValue=e;if(i||t!==e&&t!==undefined){this.valueChanged.emit(this.internalValue)}}}render(){const t={"custom-select":true,"has-suffix-border":this.hasSuffixContent,"has-prefix-border":this.hasPrefixContent};return e(s,{key:"1e4df5425e205d3709d93d71f2e7a47844a5b0f2"},e("div",{key:"6e0d6fa7b35d1d9d61cf2174828d0d0f0d242683",class:"dropdown-wrapper"},e("slot",{key:"07565dc0982498a9b026bc36f285eb728b5c771b",name:"prefix",ref:t=>this.prefixSlotElement=t,onSlotchange:this.evaluatePrefixContent}),e("select",{key:"ba618a1166681f36aae554242192e375286ba7e8",class:t,style:Object.assign(Object.assign({},this.selectStyles),{width:this.width}),onInput:this.handleSelectChange},this.options.map((t=>e("option",{value:t.value,style:t.style,selected:t.value===this.internalValue},t.label)))),e("slot",{key:"2731003fa214cb3aa968b48db36ab1816d563425",name:"suffix",ref:t=>this.suffixSlotElement=t,onSlotchange:this.evaluateSuffixContent})))}static get watchers(){return{value:["externalValueChanged"],options:["optionsChanged"]}}};Q.style=R;class _{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)}}_.registry=new Map;_.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 L 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 H 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 W extends F{constructor(t){super(t);this.touchStartTimeout=null}handleMouseDown(t){if(w.isLeftClick(t)){this._store.state.isErasing=true}}handleMouseMove(t){var i;if(this._store.state.isErasing){const e=(i=this._store.state.host)===null||i===void 0?void 0:i.shadowRoot;if(!e)return;const s=this._store.getObjectFromPointerEvent(t,".object");if(!s)return;s.markedForRemoval=true;this._store.rerender()}}handleMouseUp(t){if(this._store.state.isErasing){const t=this._store.allObjects.filter((t=>t.markedForRemoval)).map((t=>{t.markedForRemoval=false;return new H(this._store,this,t)}));if(t.length>0){this._store.history.executeCommand(new L(this._store,this,t))}this._store.state.isErasing=false}}handleTouchStart(t){this.touchStartTimeout=setTimeout((()=>{if(this._store.state.touchCount===1&&!this._store.state.isScaling){this._store.state.isErasing=true}}),80)}handleTouchMove(t){var i;if(this._store.state.touchCount===1&&this._store.state.isErasing){const e=(i=this._store.state.host)===null||i===void 0?void 0:i.shadowRoot;if(!e)return;const s=this._store.getObjectFromPointerEvent(t,".object");if(!s)return;s.markedForRemoval=true;this._store.rerender()}}handleTouchEnd(t){clearTimeout(this.touchStartTimeout);if(this._store.state.isErasing){const t=this._store.allObjects.filter((t=>t.markedForRemoval)).map((t=>{t.markedForRemoval=false;return new H(this._store,this,t)}));if(t.length>0){this._store.history.executeCommand(new L(this._store,this,t))}this._store.state.isErasing=false}}}class K extends E{constructor(t){super(t);this.__class__="KritzelImage";this.src="";this.debugInfoVisible=true;this.x=0;this.y=0;this.translateX=0;this.translateY=0;this.scale=this._store.state.scale}resize(t,i,e,s){if(e<=1||s<=1){return}const n=s/this.height;this.width=this.width*n;this.height=this.height*n;this.translateX=t;this.translateY=i}}class V extends y{constructor(t,i){super(t,i);this.previousSelectionGroup=this._store.state.selectionGroup}execute(){this._store.state.objectsOctree.remove((t=>t.id===this.previousSelectionGroup.id));this._store.state.selectionGroup=null}undo(){if(this.previousSelectionGroup){this._store.state.objectsOctree.insert(this.previousSelectionGroup);this._store.state.selectionGroup=this.previousSelectionGroup}}}class X 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 Y{constructor(t){this._store=t}}class N extends Y{constructor(t){super(t)}handleMouseDown(t){var i;if(w.isLeftClick(t)){if(((i=this._store.state.selectionGroup)===null||i===void 0?void 0:i.selected)&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.isDragging=true;this.dragStartX=i;this.dragStartY=e;this.startX=this.dragStartX;this.startY=this.dragStartY}}}handleMouseMove(t){if(this._store.state.isDragging&&this._store.state.selectionGroup){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this.endX=i;this.endY=e;this._store.state.selectionGroup.move(i,e,this.dragStartX,this.dragStartY);this.dragStartX=i;this.dragStartY=e}}handleMouseUp(t){if(this._store.state.isDragging){this._store.state.isDragging=false;this._store.history.executeCommand(new X(this._store,this,this.endX,this.endY,this.startX,this.startY,true))}}handleTouchStart(t){var i;if(this._store.state.touchCount===1){if(((i=this._store.state.selectionGroup)===null||i===void 0?void 0:i.selected)&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){const i=Math.round(t.touches[0].clientX-this._store.offsetX);const e=Math.round(t.touches[0].clientY-this._store.offsetY);this.dragStartX=i;this.dragStartY=e;this.startX=i;this.startY=e}}}handleTouchMove(t){if(this._store.state.touchCount===1&&this._store.state.selectionGroup&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){const i=Math.round(t.touches[0].clientX-this._store.offsetX);const e=Math.round(t.touches[0].clientY-this._store.offsetY);this._store.state.isDragging=true;this.endX=i;this.endY=e;const s=Math.abs(i-this.startX);const n=Math.abs(e-this.startY);const 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}}}handleTouchEnd(t){if(this._store.state.isDragging){this._store.state.isDragging=false;this._store.history.executeCommand(new X(this._store,this,this.endX,this.endY,this.startX,this.startY,true))}}}var G;(function(t){t["TopLeft"]="top-left";t["TopRight"]="top-right";t["BottomLeft"]="bottom-left";t["BottomRight"]="bottom-right"})(G||(G={}));class q 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 Z extends Y{constructor(t){super(t);this.initialMouseX=0;this.initialMouseY=0;this.initialSize={x:0,y:0,width:0,height:0};this.newSize={x:0,y:0,width:0,height:0}}handleMouseDown(t){if(w.isLeftClick(t)){if(this._store.state.selectionGroup&&this._store.state.isResizeHandleSelected){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.isResizing=true;this.initialMouseX=i;this.initialMouseY=e;this.initialSize.width=this._store.state.selectionGroup.width;this.initialSize.height=this._store.state.selectionGroup.height;this.initialSize.x=this._store.state.selectionGroup.translateX;this.initialSize.y=this._store.state.selectionGroup.translateY}}}handleMouseMove(t){if(this._store.state.isResizing&&this._store.state.selectionGroup){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;const s=i-this.initialMouseX;const n=e-this.initialMouseY;switch(this._store.state.resizeHandleType){case G.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 G.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 G.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 G.BottomRight:this.newSize.width=this.initialSize.width+s;this.newSize.height=this.initialSize.height+n;this.newSize.x=this.initialSize.x;this.newSize.y=this.initialSize.y;break}this._store.state.selectionGroup.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height);this._store.rerender()}}handleMouseUp(t){if(this._store.state.isResizing){const t=new q(this._store,this,structuredClone(this.initialSize),structuredClone(this.newSize));this._store.history.executeCommand(t);this._store.state.isResizing=false;this._store.rerender()}}handleTouchStart(t){const i=t.touches[0];if(!i){return}if(this._store.state.touchCount===1){if(this._store.state.selectionGroup&&this._store.state.isResizeHandleSelected){const t=Math.round(i.clientX-this._store.offsetX);const e=Math.round(i.clientY-this._store.offsetY);this._store.state.isResizing=true;this.initialMouseX=t;this.initialMouseY=e;this.initialSize.width=this._store.state.selectionGroup.width;this.initialSize.height=this._store.state.selectionGroup.height;this.initialSize.x=this._store.state.selectionGroup.translateX;this.initialSize.y=this._store.state.selectionGroup.translateY;clearTimeout(this._store.state.longTouchTimeout)}}}handleTouchMove(t){const i=t.touches[0];if(!i){return}if(this._store.state.isResizing&&this._store.state.selectionGroup){const t=Math.round(i.clientX-this._store.offsetX);const e=Math.round(i.clientY-this._store.offsetY);const s=t-this.initialMouseX;const n=e-this.initialMouseY;switch(this._store.state.resizeHandleType){case G.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 G.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 G.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 G.BottomRight:this.newSize.width=this.initialSize.width+s;this.newSize.height=this.initialSize.height+n;this.newSize.x=this.initialSize.x;this.newSize.y=this.initialSize.y;break}this._store.state.selectionGroup.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height);clearTimeout(this._store.state.longTouchTimeout)}}handleTouchEnd(t){if(this._store.state.isResizing){const t=new q(this._store,this,structuredClone(this.initialSize),structuredClone(this.newSize));this._store.history.executeCommand(t);this._store.state.isResizing=false;clearTimeout(this._store.state.longTouchTimeout)}}}class J 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 tt extends Y{constructor(t){super(t);this.initialRotation=0;this.rotation=0}handleMouseDown(t){if(w.isLeftClick(t)){if(this._store.state.selectionGroup&&this._store.state.isRotationHandleSelected){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.isRotating=true;const s=this._store.state.selectionGroup.translateX+this._store.state.selectionGroup.width/2/this._store.state.scale;const n=this._store.state.selectionGroup.translateY+this._store.state.selectionGroup.height/2/this._store.state.scale;const 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}}}handleMouseMove(t){if(this._store.state.isRotating&&this._store.state.selectionGroup){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;const s=this._store.state.selectionGroup.translateX+this._store.state.selectionGroup.width/2/this._store.state.scale;const n=this._store.state.selectionGroup.translateY+this._store.state.selectionGroup.height/2/this._store.state.scale;const 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()}}handleMouseUp(t){if(this._store.state.isRotating){this._store.history.executeCommand(new J(this._store,this,this.rotation));this._store.state.isRotating=false;this.initialRotation=0;this.rotation=0}}handleTouchStart(t){const i=t.touches[0];if(!i){return}if(this._store.state.touchCount===1){if(this._store.state.selectionGroup&&this._store.state.isRotationHandleSelected){const t=Math.round(i.clientX-this._store.offsetX);const e=Math.round(i.clientY-this._store.offsetY);this._store.state.isRotating=true;const s=this._store.state.selectionGroup.translateX+this._store.state.selectionGroup.width/2/this._store.state.scale;const n=this._store.state.selectionGroup.translateY+this._store.state.selectionGroup.height/2/this._store.state.scale;const 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)}}}handleTouchMove(t){const i=t.touches[0];if(!i){return}if(this._store.state.isRotating&&this._store.state.selectionGroup){const t=Math.round(i.clientX-this._store.offsetX);const e=Math.round(i.clientY-this._store.offsetY);const s=this._store.state.selectionGroup.translateX+this._store.state.selectionGroup.width/2/this._store.state.scale;const n=this._store.state.selectionGroup.translateY+this._store.state.selectionGroup.height/2/this._store.state.scale;const 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)}}handleTouchEnd(t){if(this._store.state.isRotating){this._store.history.executeCommand(new J(this._store,this,this.rotation));this._store.state.isRotating=false;this.initialRotation=0;this.rotation=0;clearTimeout(this._store.state.longTouchTimeout)}}}class it{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 a=r>t.y!==l>t.y&&t.x<(h-o)*(t.y-r)/(l-r)+o;if(a)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 et extends E{constructor(t){super(t);this.__class__="KrtizelSelectionBox";this.objects=[];this.backgroundColor="var(--kritzel-selection-box-background-color, rgba(14, 17, 17, 0.2))";this.borderColor="var(--kritzel-selection-box-border-color, rgba(14, 17, 17, 0.5))";this.borderWidth=2;this.scale=this._store.state.scale;this.height=0;this.width=0;this.zIndex=9999}}class st extends y{constructor(t,i,e){super(t,i);this.selectionGroup=e}execute(){this._store.state.objectsOctree.remove((t=>t instanceof et));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 nt extends Y{get isSelectionClick(){return this._store.state.selectionBox&&this._store.state.selectionBox.width===0&&this._store.state.selectionBox.height===0}get isSelectionDrag(){return this._store.state.selectionBox&&(this._store.state.selectionBox.width>0||this._store.state.selectionBox.height>0)}constructor(t){super(t);this.touchStartX=0;this.touchStartY=0;this.touchStartTimeout=null}handleMouseDown(t){if(w.isLeftClick(t)&&!this._store.state.selectionGroup){this.startMouseSelection(t)}}handleMouseMove(t){if(this._store.state.isSelecting){this.updateMouseSelection(t)}}handleMouseUp(t){if(w.isLeftClick(t)&&this._store.state.isSelecting){if(this.isSelectionClick){this.updateMouseSelection(t);this.addSelectedObjectAtIndexToSelectionGroup(0);this.removeSelectionBox()}if(this.isSelectionDrag){this.updateMouseSelection(t);this.addSelectedObjectsToSelectionGroup();this.removeSelectionBox()}}}handleTouchStart(t){this.touchStartTimeout=setTimeout((()=>{if(this._store.state.touchCount===1&&!this._store.state.isScaling&&!this._store.state.selectionGroup){this.startTouchSelection(t);this.updateTouchSelection(t)}}),80)}handleTouchMove(t){const i=Math.round(t.touches[0].clientX-this._store.offsetX);const e=Math.round(t.touches[0].clientY-this._store.offsetY);const s=Math.abs(i-this.touchStartX);const n=Math.abs(e-this.touchStartY);const o=5;if((s>o||n>o)&&this._store.state.isSelecting){this.updateTouchSelection(t);clearTimeout(this._store.state.longTouchTimeout)}}handleTouchEnd(t){clearTimeout(this.touchStartTimeout);if(this._store.state.isSelecting){if(this.isSelectionClick){this.updateTouchSelection(t);this.addSelectedObjectAtIndexToSelectionGroup(0);this.removeSelectionBox()}if(this.isSelectionDrag){this.updateTouchSelection(t);this.addSelectedObjectsToSelectionGroup();this.removeSelectionBox()}this._store.state.skipContextMenu=false}}removeSelectionBox(){this._store.state.selectionBox=null;this._store.state.isSelecting=false;this._store.state.objectsOctree.remove((t=>t instanceof et));this._store.rerender()}startMouseSelection(t){let i,e;i=t.clientX-this._store.offsetX;e=t.clientY-this._store.offsetY;const s=new et(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 et||t instanceof ht));this._store.state.objectsOctree.insert(s)}startTouchSelection(t){const i=t.touches[0];if(!i){return}let e,s;e=Math.round(i.clientX-this._store.offsetX);s=Math.round(i.clientY-this._store.offsetY);this.touchStartX=e;this.touchStartY=s;const n=new et(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 et||t instanceof ht));this._store.state.objectsOctree.insert(n)}updateMouseSelection(t){let i,e;i=t.clientX-this._store.offsetX;e=t.clientY-this._store.offsetY;const s=this._store.state.selectionBox;if(s){const t=(i-this._store.state.translateX)/s.scale;const n=(e-this._store.state.translateY)/s.scale;s.width=Math.abs(t-this.startX)*s.scale;s.height=Math.abs(n-this.startY)*s.scale;s.translateX=Math.min(t,this.startX);s.translateY=Math.min(n,this.startY);this.updateSelectedObjects();this._store.rerender()}}updateTouchSelection(t){const i=t.touches[0];if(!i){return}let e,s;e=Math.round(i.clientX-this._store.offsetX);s=Math.round(i.clientY-this._store.offsetY);const n=this._store.state.selectionBox;if(n){const t=(e-this._store.state.translateX)/n.scale;const i=(s-this._store.state.translateY)/n.scale;n.width=Math.abs(t-this.startX)*n.scale;n.height=Math.abs(i-this.startY)*n.scale;n.translateX=Math.min(t,this.startX);n.translateY=Math.min(i,this.startY);this.updateSelectedObjects()}}updateSelectedObjects(){this._store.allObjects.filter((t=>!(t instanceof et))).forEach((t=>{const i=t.rotatedPolygon;const e=this._store.state.selectionBox.rotatedPolygon;t.selected=it.doPolygonsIntersect(i,e)}))}addSelectedObjectAtIndexToSelectionGroup(t){const i=this._store.selectedObjects.sort(((t,i)=>i.zIndex-t.zIndex));const e=i[t];if(!e){return}i.forEach((t=>t.selected=false));this._store.state.selectionGroup=new ht(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 st(this._store,this,this._store.state.selectionGroup))}addSelectedObjectsToSelectionGroup(){const t=this._store.selectedObjects;if(t.length===0){return}this._store.state.selectionGroup=new ht(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 st(this._store,this,this._store.state.selectionGroup))}}class ot extends F{constructor(t){super(t);this.selectionHandler=new nt(this._store);this.moveHandler=new N(this._store);this.resizeHandler=new Z(this._store);this.rotationHandler=new tt(this._store)}handleMouseDown(t){if(w.isLeftClick(t)){this._store.state.isResizeHandleSelected=this.isHandleSelected(t);this._store.state.isRotationHandleSelected=this.isRotationHandleSelected(t);this._store.state.resizeHandleType=this.getHandleType(t);const i=this.getSelectedObject(t);const e=i&&this._store.state.selectionGroup&&i.id!==this._store.state.selectionGroup.id;if((i===null||e)&&this._store.state.selectionGroup&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){this._store.history.executeCommand(new V(this._store,this._store.state.selectionGroup))}}this.moveHandler.handleMouseDown(t);this.selectionHandler.handleMouseDown(t);this.resizeHandler.handleMouseDown(t);this.rotationHandler.handleMouseDown(t);this._store.rerender()}handleMouseMove(t){this.moveHandler.handleMouseMove(t);this.selectionHandler.handleMouseMove(t);this.resizeHandler.handleMouseMove(t);this.rotationHandler.handleMouseMove(t);this._store.rerender()}handleMouseUp(t){this.moveHandler.handleMouseUp(t);this.selectionHandler.handleMouseUp(t);this.resizeHandler.handleMouseUp(t);this.rotationHandler.handleMouseUp(t);this._store.rerender()}handleDoubleClick(t){var i;if(w.isLeftClick(t)){if(this._store.state.selectionGroup&&((i=this._store.state.selectionGroup)===null||i===void 0?void 0:i.objects.length)===1){const t=this._store.state.selectionGroup.objects[0];if(t instanceof j){this._store.history.executeCommand(new V(this._store,this._store.state.selectionGroup));this._store.setState("activeTool",B.getTool("text"));this._store.state.activeText=t;setTimeout((()=>{t.focus()}),300)}}}}handleDoubleTap(t){const i=this.getSelectedObject(t);if(!i||i.objects.length!==1){return}const e=i.objects[0];if(e instanceof j){this._store.setState("activeTool",B.getTool("text"));this._store.state.activeText=e;setTimeout((()=>{e.focus()}),300)}}handleTouchStart(t){if(this._store.state.isScaling===true){return}if(this._store.state.touchCount===1){this._store.state.isResizeHandleSelected=this.isHandleSelected(t);this._store.state.isRotationHandleSelected=this.isRotationHandleSelected(t);this._store.state.resizeHandleType=this.getHandleType(t);const i=this.getSelectedObject(t);const e=i&&this._store.state.selectionGroup&&i.id!==this._store.state.selectionGroup.id;if(!this._store.state.selectionGroup&&i){this._store.state.skipContextMenu=true}if((i===null||e)&&this._store.state.selectionGroup&&!this._store.state.isResizeHandleSelected&&!this._store.state.isRotationHandleSelected){this._store.history.executeCommand(new V(this._store,this._store.state.selectionGroup))}}this.rotationHandler.handleTouchStart(t);this.resizeHandler.handleTouchStart(t);this.moveHandler.handleTouchStart(t);this.selectionHandler.handleTouchStart(t)}handleTouchMove(t){if(this._store.state.isScaling===true){return}this.rotationHandler.handleTouchMove(t);this.resizeHandler.handleTouchMove(t);this.moveHandler.handleTouchMove(t);this.selectionHandler.handleTouchMove(t);this._store.rerender()}handleTouchEnd(t){if(this._store.state.isScaling===true){return}this.rotationHandler.handleTouchEnd(t);this.resizeHandler.handleTouchEnd(t);this.moveHandler.handleTouchEnd(t);this.selectionHandler.handleTouchEnd(t)}getSelectedObject(t){const i=t.composedPath().slice(1);const e=i.find((t=>t.classList&&t.classList.contains("object")));const s=this._store.findObjectById(e===null||e===void 0?void 0:e.id);if(!s){return null}if(s instanceof ht){return s}else{const t=new ht(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 rt{constructor(t){this._store=t}revive(t){if(t&&typeof t==="object"){if(t.__class__){let i;switch(t.__class__){case"KritzelPath":i=new S(this._store).revive(t);break;case"KritzelText":i=new j(this._store,t.fontSize,t.fontFamily).revive(t);break;case"KritzelImage":i=new K(this._store).revive(t);break;case"KritzelSelectionGroup":i=new ht(this._store).revive(t);break;case"KritzelBrushTool":i=new I(this._store);break;case"KritzelEraserTool":i=new W(this._store);break;case"KritzelImageTool":i=new Ht(this._store);break;case"KritzelSelectionTool":i=new ot(this._store);break;case"KritzelTextTool":i=new U(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 ht extends E{constructor(t){super(t);this.__class__="KritzelSelectionGroup";this.objects=[];this.unchangedObjects=[];this.scale=this._store.state.scale;this.zIndex=99999}get length(){return this.objects.length}addOrRemove(t){const i=this.objects.findIndex((i=>i.id===t.id));if(i===-1){this.objects.push(t)}else{this.objects.splice(i,1)}this.unchangedObjects=C.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=C.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 a=n*h-o*l;const c=o*h+n*l;s.translateX=i+a-s.totalWidth/2/s.scale;s.translateY=e+c-s.totalHeight/2/s.scale;s.rotation=this.objects.length===1?t:t+r.rotation;this._store.state.objectsOctree.update(s)}))}copy(){const t=new ht(this._store);let i=this._store.currentZIndex;this.objects.forEach((e=>{const s=e.copy();s.zIndex=i;t.addOrRemove(s);i++}));t.unchangedObjects=C.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 rt(this._store);return e.revive(i)}}function lt(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 at(t,i){return new Promise((function(e,s){let n;return ct(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 ct=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),a=o+l+2+12*s.getUint16(o+l,h);for(let t=o+l+2;t<a;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 dt={},ft={get exports(){return dt},set exports(t){dt=t}};!function(t){var i,e,s={};ft.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 a=e(h,o+=4);e(h,o+=2);var c=n(h,o+=2),d=n(h,o+=4);o+=4,o=d;for(var f=0;f<a;f++){n(h,o),o+=4,o+=4,o+=4,n(h,o+=4);c=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,c,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 a=h(t,i+=2);l(t,i+=2),l(t,i+=4),i+=4;var c=h(t,i+=8),d=h(t,i+=2);i+=2;var f=s.bin.readUTF8(t,i,c);if(i+=c,i+=d,r)e[f]={size:o,csize:n};else{var u=new Uint8Array(t.buffer,i);if(0==a)e[f]=new Uint8Array(u.buffer.slice(i,i+n));else{if(8!=a)throw"unknown compression method: "+a;var v=new Uint8Array(o);s.inflateRaw(u,v),e[f]=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,a=t[h],c=s.crc.crc(a,0,a.length);r[h]={cpr:l,usize:a.length,crc:c,file:l?s.deflateRaw(a):a}}for(var h in r)e+=r[h].file.length+30+46+2*s.bin.sizeUTF8(h);e+=22;var d=new Uint8Array(e),f=0,u=[];for(var h in r){var v=r[h];u.push(f),f=s._writeHeader(d,f,h,v,0)}var p=0,b=f;for(var h in r){v=r[h];u.push(f),f=s._writeHeader(d,f,h,v,1,u[p++])}var g=f-b;return n(d,f,101010256),f+=4,o(d,f+=4,p),o(d,f+=2,p),n(d,f+=2,g),n(d,f+=4,b),f+=4,f+=2,d.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,a=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,a.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(a,i),i+=a.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,a=0,c=e<<3,d=0,f=t.length;if(0==n){for(;a<f;){l(i,c,a+(A=Math.min(65535,f-a))==f?1:0),c=s.F._copyExact(t,a,A,i,c+8),a+=A}return c>>>3}var u=r.lits,v=r.strt,p=r.prev,b=0,g=0,w=0,y=0,k=0,x=0;for(f>2&&(v[x=s.F._hash(t,0)]=0),a=0;a<f;a++){if(k=x,a+1<f-2){x=s.F._hash(t,a+1);var m=a+1&32767;p[m]=v[x],v[x]=m}if(d<=a){(b>14e3||g>26697)&&f-a>100&&(d<a&&(u[b]=a-d,b+=2,d=a),c=s.F._writeBlock(a==f-1||d==f?1:0,u,b,y,t,w,a-w,i,c),b=g=y=0,w=a);var z=0;a<f-2&&(z=s.F._bestMatch(t,a,p,k,Math.min(o[2],f-a),o[3]));var A=z>>>16,M=65535&z;if(0!=z){M=65535&z;var T=h(A=z>>>16,r.of0);r.lhst[257+T]++;var C=h(M,r.df0);r.dhst[C]++,y+=r.exb[T]+r.dxb[C],u[b]=A<<23|a-d,u[b+1]=M<<16|T<<8|C,b+=2,d=a+A}else r.lhst[t[a]]++;g++}}for(w==a&&0!=t.length||(d<a&&(u[b]=a-d,b+=2,d=a),c=s.F._writeBlock(1,u,b,y,t,w,a-w,i,c),b=0,g=0,b=g=y=0,w=a);0!=(7&c);)c++;return c>>>3},s.F._bestMatch=function(t,i,e,n,o,r){var h=32767&i,l=e[h],a=h-l+32768&32767;if(l==h||n!=s.F._hash(t,i-a))return 0;for(var c=0,d=0,f=Math.min(32767,i);a<=f&&0!=--r&&l!=h;){if(0==c||t[i+c]==t[i+c-a]){var u=s.F._howLong(t,i,a);if(u>c){if(d=a,(c=u)>=o)break;a+2<u&&(u=a+2);for(var v=0,p=0;p<u-2;p++){var b=i-a+p+32768&32767,g=b-e[b]+32768&32767;g>v&&(v=g,l=b)}}}a+=(h=l)-(l=e[h])+32768&32767}return c<<16|d},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,a){var c,d,f,u,v,p,b,g,w,y=s.F.U,k=s.F._putsF,x=s.F._putsE;y.lhst[256]++,d=(c=s.F.getTrees())[0],f=c[1],u=c[2],v=c[3],p=c[4],b=c[5],g=c[6],w=c[7];var m=32+(0==(a+3&7)?0:8-(a+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 T=m<z&&m<A?0:z<A?1:2;if(k(l,a,t),k(l,a+1,T),a+=3,0==T){for(;0!=(7&a);)a++;a=s.F._copyExact(o,r,h,l,a)}else{var C,E;if(1==T&&(C=y.fltree,E=y.fdtree),2==T){s.F.makeCodes(y.ltree,d),s.F.revCodes(y.ltree,d),s.F.makeCodes(y.dtree,f),s.F.revCodes(y.dtree,f),s.F.makeCodes(y.itree,u),s.F.revCodes(y.itree,u),C=y.ltree,E=y.dtree,x(l,a,v-257),x(l,a+=5,p-1),x(l,a+=5,b-4),a+=4;for(var S=0;S<b;S++)x(l,a+3*S,y.itree[1+(y.ordr[S]<<1)]);a+=3*b,a=s.F._codeTiny(g,y.itree,l,a),a=s.F._codeTiny(w,y.itree,l,a)}for(var F=r,I=0;I<e;I+=2){for(var j=i[I],B=j>>>23,U=F+(8388607&j);F<U;)a=s.F._writeLit(o[F++],C,l,a);if(0!=B){var O=i[I+1],$=O>>16,D=O>>8&255,P=255&O;x(l,a=s.F._writeLit(257+D,C,l,a),B-y.of0[D]),a+=y.exb[D],k(l,a=s.F._writeLit(P,E,l,a),$-y.df0[P]),a+=y.dxb[P],F+=B}}a=s.F._writeLit(256,C,l,a)}return a},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 a=s.F._hufTree(t.ihst,t.itree,7),c=19;c>4&&0==t.itree[1+(t.ordr[c-1]<<1)];)c--;return[i,e,a,o,h,c,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;(a=Math.min(l+1-s>>>1,138))<11?i.push(17,a-3):i.push(18,a-11),s+=2*a-2}else if(n==h&&o==n&&r==n){for(l=s+5;l+2<e&&t[l+2]==n;)l+=2;var a=Math.min(l+1-s>>>1,6);i.push(16,a-3),s+=2*a-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,a=n.slice(0);if(0==l)return 0;if(1==l){var c=n[0].lit;a=0==c?1:0;return i[1+(c<<1)]=1,i[1+(a<<1)]=1,1}n.sort((function(t,i){return t.f-i.f}));var d=n[0],f=n[1],u=0,v=1,p=2;for(n[0]={lit:-1,f:d.f+f.f,l:d,r:f,d:0};v!=l-1;)d=u!=v&&(p==l||n[u].f<n[p].f)?n[u++]:n[p++],f=u!=v&&(p==l||n[u].f<n[p].f)?n[u++]:n[p++],n[v++]={lit:-1,f:d.f+f.f,l:d,r:f};var b=s.F.setDepth(n[v-1],0);for(b>e&&(s.F.restrictDepth(a,e,b),b=e),h=0;h<l;h++)i[1+(a[h].lit<<1)]=a[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,a=n.codes2map,c=n._get17,d=n.U,f=null==i;f&&(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(f&&(i=s.F._check(i,m+(1<<17))),1==b&&(u=d.flmap,v=d.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)d.itree[A]=0,d.itree[A+1]=0;var M=1;for(A=0;A<y;A++){var T=r(t,z+3*A,3);d.itree[1+(d.ordr[A]<<1)]=T,T>M&&(M=T)}z+=3*y,l(d.itree,M),a(d.itree,M,d.imap),u=d.lmap,v=d.dmap,z=h(d.imap,(1<<M)-1,g+w,t,z,d.ttree);var C=n._copyOut(d.ttree,0,g,d.ltree);k=(1<<C)-1;var E=n._copyOut(d.ttree,g,w,d.dtree);x=(1<<E)-1,l(d.ltree,C),a(d.ltree,C,u),l(d.dtree,E),a(d.dtree,E,v)}for(;;){var S=u[c(t,z)&k];z+=15&S;var F=S>>>4;if(F>>>8==0)i[m++]=F;else{if(256==F)break;var I=m+F-254;if(F>264){var j=d.ldef[F-257];I=m+(j>>>3)+r(t,z,7&j),z+=7&j}var B=v[c(t,z)&x];z+=15&B;var U=B>>>4,O=d.ddef[U],$=(O>>>4)+o(t,z,15&O);for(z+=15&O,f&&(i=s.F._check(i,m+(1<<17)));m<I;)i[m]=i[m++-$],i[m]=i[m++-$],i[m]=i[m++-$],i[m]=i[m++-$];m=I}}}else{0!=(7&z)&&(z+=8-(7&z));var D=4+(z>>>3),P=t[D-4]|t[D-3]<<8;f&&(i=s.F._check(i,m+P)),i.set(new e(t.buffer,t.byteOffset+D,P),m),z=D+P<<3,m+=P}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,a=0;a<e;){var c=t[l(n,o)&i];o+=15&c;var d=c>>>4;if(d<=15)r[a]=d,a++;else{var f=0,u=0;16==d?(u=3+h(n,o,2),o+=2,f=r[a-1]):17==d?(u=3+h(n,o,3),o+=3):18==d&&(u=11+h(n,o,7),o+=7);for(var v=a+u;a<v;)r[a]=f,a++}}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,a=h.bl_count,c=0;c<=i;c++)a[c]=0;for(c=1;c<l;c+=2)a[t[c]]++;var d=h.next_code;for(e=0,a[0]=0,n=1;n<=i;n++)e=e+a[n-1]<<1,d[n]=e;for(o=0;o<l;o+=2)0!=(r=t[o+1])&&(t[o]=d[r],d[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],a=h<<4|l,c=i-l,d=t[r]<<c,f=d+(1<<c);d!=f;){e[o[d]>>>15-i]=a,d++}},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 ut=lt({__proto__:null,default:dt},[dt]);const vt=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),a=new Uint8Array(4*r),c=new Uint32Array(a.buffer),{ctype:d}=n,{depth:f}=n,u=t.readUshort;if(6==d){const t=r<<2;if(8==f)for(var v=0;v<t;v+=4)a[v]=i[v],a[v+1]=i[v+1],a[v+2]=i[v+2],a[v+3]=i[v+3];if(16==f)for(v=0;v<t;v++)a[v]=i[v<<1]}else if(2==d){const t=n.tabs.tRNS;if(null==t){if(8==f)for(v=0;v<r;v++){var p=3*v;c[v]=255<<24|i[p+2]<<16|i[p+1]<<8|i[p]}if(16==f)for(v=0;v<r;v++){p=6*v;c[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==f)for(v=0;v<r;v++){var g=v<<2;p=3*v;c[v]=255<<24|i[p+2]<<16|i[p+1]<<8|i[p],i[p]==b&&i[p+1]==e&&i[p+2]==s&&(a[g+3]=0)}if(16==f)for(v=0;v<r;v++){g=v<<2,p=6*v;c[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&&(a[g+3]=0)}}}else if(3==d){const t=n.tabs.PLTE,o=n.tabs.tRNS,h=o?o.length:0;if(1==f)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);a[g]=t[x],a[g+1]=t[x+1],a[g+2]=t[x+2],a[g+3]=m<h?o[m]:255}}if(2==f)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);a[g]=t[x],a[g+1]=t[x+1],a[g+2]=t[x+2],a[g+3]=m<h?o[m]:255}if(4==f)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);a[g]=t[x],a[g+1]=t[x+1],a[g+2]=t[x+2],a[g+3]=m<h?o[m]:255}if(8==f)for(v=0;v<r;v++){var m;g=v<<2,x=3*(m=i[v]);a[g]=t[x],a[g+1]=t[x+1],a[g+2]=t[x+2],a[g+3]=m<h?o[m]:255}}else if(4==d){if(8==f)for(v=0;v<r;v++){g=v<<2;var z=i[A=v<<1];a[g]=z,a[g+1]=z,a[g+2]=z,a[g+3]=i[A+1]}if(16==f)for(v=0;v<r;v++){var A;g=v<<2,z=i[A=v<<2];a[g]=z,a[g+1]=z,a[g+2]=z,a[g+3]=i[A+2]}}else if(0==d)for(b=n.tabs.tRNS?n.tabs.tRNS:-1,w=0;w<s;w++){const t=w*l,s=w*e;if(1==f)for(var M=0;M<e;M++){var T=(z=255*(i[t+(M>>>3)]>>>7-(7&M)&1))==255*b?0:255;c[s+M]=T<<24|z<<16|z<<8|z}else if(2==f)for(M=0;M<e;M++){T=(z=85*(i[t+(M>>>2)]>>>6-((3&M)<<1)&3))==85*b?0:255;c[s+M]=T<<24|z<<16|z<<8|z}else if(4==f)for(M=0;M<e;M++){T=(z=17*(i[t+(M>>>1)]>>>4-((1&M)<<2)&15))==17*b?0:255;c[s+M]=T<<24|z<<16|z<<8|z}else if(8==f)for(M=0;M<e;M++){T=(z=i[t+M])==b?0:255;c[s+M]=T<<24|z<<16|z<<8|z}else if(16==f)for(M=0;M<e;M++){z=i[t+(M<<1)],T=u(i,t+(M<<1))==b?0:255;c[s+M]=T<<24|z<<16|z<<8|z}}return a}function e(t,i,e,h){const l=o(t),a=Math.ceil(e*l/8),c=new Uint8Array((a+1+t.interlace)*h);return i=t.tabs.CgBI?n(i,c):s(i,c),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,a=Math.ceil(s*h/8),c=new Uint8Array(n*a);let d=0;const f=[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=f[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,d,w,y);let z=0,A=f[b];for(;A<n;){let e=u[b],n=d+z*m<<3;for(;e<s;){var g;if(1==h)g=(g=i[n>>3])>>7-(7&n)&1,c[A*a+(e>>3)]|=g<<7-((7&e)<<0);if(2==h)g=(g=i[n>>3])>>6-(7&n)&3,c[A*a+(e>>2)]|=g<<6-((3&e)<<1);if(4==h)g=(g=i[n>>3])>>4-(7&n)&15,c[A*a+(e>>1)]|=g<<4-((1&e)<<2);if(h>=8){const t=A*a+e*l;for(let e=0;e<l;e++)c[t+e]=i[(n>>3)+e]}n+=h,e+=o}z++,A+=t}w*y!=0&&(d+=y*(1+m)),b+=1}return c}(i,t)),i}function s(t,i){return n(new Uint8Array(t.buffer,2,t.length-6),i)}var n=function(){const t={H:{}};return t.H.N=function(i,e){const s=Uint8Array;let n,o,r=0,h=0,l=0,a=0,c=0,d=0,f=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,d=511,f=31),2==h){l=g(i,v,5)+257,a=g(i,v+5,5)+1,c=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<c;A++){const e=g(i,v+3*A,3);m.Q[1+(m.X[A]<<1)]=e,e>t&&(t=e)}v+=3*c,y(m.Q,t),k(m.Q,t,m.u),n=m.w,o=m.d,v=w(m.u,(1<<t)-1,l+a,i,v,m.v);const e=p.V(m.v,0,l,m.C);d=(1<<e)-1;const s=p.V(m.v,l,a,m.D);f=(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)&d];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)&f];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 a=0;for(;a<s;){const t=i[l(n,o)&e];o+=15&t;const s=t>>>4;if(s<=15)r[a]=s,a++;else{let t=0,i=0;16==s?(i=3+h(n,o,2),o+=2,t=r[a-1]):17==s?(i=3+h(n,o,3),o+=3):18==s&&(i=11+h(n,o,7),o+=7);const e=a+i;for(;a<e;)r[a]=t,a++}}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 a=s.j;for(var c=0;c<=e;c++)a[c]=0;for(c=1;c<n;c+=2)a[i[c]]++;const d=s.K;for(o=0,a[0]=0,r=1;r<=e;r++)o=o+a[r-1]<<1,d[r]=o;for(h=0;h<n;h+=2)l=i[h+1],0!=l&&(i[h]=d[l],d[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 a=i[t]<<l;const c=a+(1<<l);for(;a!=c;){s[o[a]>>>15-e]=h,a++}}},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 a,c;r=Math.ceil(r/8);let d=t[e],f=0;if(d>1&&(t[e]=[0,0,1][d-2]),3==d)for(f=r;f<l;f++)t[f+1]=t[f+1]+(t[f+1-r]>>>1)&255;for(let i=0;i<n;i++)if(a=e+i*l,c=a+i+1,d=t[c-1],f=0,0==d)for(;f<l;f++)t[a+f]=t[c+f];else if(1==d){for(;f<r;f++)t[a+f]=t[c+f];for(;f<l;f++)t[a+f]=t[c+f]+t[a+f-r]}else if(2==d)for(;f<l;f++)t[a+f]=t[c+f]+t[a+f-l];else if(3==d){for(;f<r;f++)t[a+f]=t[c+f]+(t[a+f-l]>>>1);for(;f<l;f++)t[a+f]=t[c+f]+(t[a+f-l]+t[a+f-r]>>>1)}else{for(;f<r;f++)t[a+f]=t[c+f]+h(0,t[a+f-l],0);for(;f<l;f++)t[a+f]=t[c+f]+h(t[a+f-r],t[a+f-l],t[a+f-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 a(t,i,e,s,n,o,r,h,l){const a=Math.min(i,n),c=Math.min(e,o);let d=0,f=0;for(let e=0;e<c;e++)for(let o=0;o<a;o++)if(r>=0&&h>=0?(d=e*i+o<<2,f=(h+e)*n+r+o<<2):(d=(-h+e)*i-r+o<<2,f=e*n+o<<2),0==l)s[f]=t[d],s[f+1]=t[d+1],s[f+2]=t[d+2],s[f+3]=t[d+3];else if(1==l){var u=t[d+3]*(1/255),v=t[d]*u,p=t[d+1]*u,b=t[d+2]*u,g=s[f+3]*(1/255),w=s[f]*g,y=s[f+1]*g,k=s[f+2]*g;const i=1-u,e=u+g*i,n=0==e?0:1/e;s[f+3]=255*e,s[f+0]=(v+w*i)*n,s[f+1]=(p+y*i)*n,s[f+2]=(b+k*i)*n}else if(2==l){u=t[d+3],v=t[d],p=t[d+1],b=t[d+2],g=s[f+3],w=s[f],y=s[f+1],k=s[f+2];u==g&&v==w&&p==y&&b==k?(s[f]=0,s[f+1]=0,s[f+2]=0,s[f+3]=0):(s[f]=v,s[f+1]=p,s[f+2]=b,s[f+3]=u)}else if(3==l){u=t[d+3],v=t[d],p=t[d+1],b=t[d+2],g=s[f+3],w=s[f],y=s[f+1],k=s[f+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 a=t,c=a.readUshort,d=a.readUint,f={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=a.readUint(r,h);h+=4;const i=a.readASCII(r,h,4);if(h+=4,"IHDR"==i)l(r,h,f);else if("iCCP"==i){for(var y=h;0!=r[y];)y++;a.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)}f.tabs[i]=o}else if("CgBI"==i)f.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)f.tabs[i]={num_frames:d(r,h),num_plays:d(r,h+4)},v=new Uint8Array(r.length);else if("fcTL"==i){if(0!=b)(M=f.frames[f.frames.length-1]).data=e(f,v.slice(0,b),M.rect.width,M.rect.height),b=0;const t={x:d(r,h+12),y:d(r,h+16),width:d(r,h+4),height:d(r,h+8)};let i=c(r,h+22);i=c(r,h+20)/(0==i?100:i);const s={rect:t,delay:Math.round(1e3*i),dispose:r[h+24],blend:r[h+25]};f.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)f.tabs[i]=[a.readUint(r,h),a.readUint(r,h+4),r[h+8]];else if("cHRM"==i){f.tabs[i]=[];for(w=0;w<8;w++)f.tabs[i].push(a.readUint(r,h+4*w))}else if("tEXt"==i||"zTXt"==i){null==f.tabs[i]&&(f.tabs[i]={});var k=a.nextZero(r,h),x=a.readASCII(r,h,k-h),m=h+t-k-1;if("tEXt"==i)A=a.readASCII(r,k+1,m);else{var z=s(r.slice(k+2,k+2+m));A=a.readUTF8(z,0,z.length)}f.tabs[i][x]=A}else if("iTXt"==i){null==f.tabs[i]&&(f.tabs[i]={});k=0,y=h;k=a.nextZero(r,y);x=a.readASCII(r,y,k-y);const e=r[y=k+1];var A;y+=2,k=a.nextZero(r,y),a.readASCII(r,y,k-y),y=k+1,k=a.nextZero(r,y),a.readUTF8(r,y,k-y);m=t-((y=k+1)-h);if(0==e)A=a.readUTF8(r,y,m);else{z=s(r.slice(y,y+m));A=a.readUTF8(z,0,z.length)}f.tabs[i][x]=A}else if("PLTE"==i)f.tabs[i]=a.readBytes(r,h,t);else if("hIST"==i){const t=f.tabs.PLTE.length/3;f.tabs[i]=[];for(w=0;w<t;w++)f.tabs[i].push(c(r,h+2*w))}else if("tRNS"==i)3==f.ctype?f.tabs[i]=a.readBytes(r,h,t):0==f.ctype?f.tabs[i]=c(r,h):2==f.ctype&&(f.tabs[i]=[c(r,h),c(r,h+2),c(r,h+4)]);else if("gAMA"==i)f.tabs[i]=a.readUint(r,h)/1e5;else if("sRGB"==i)f.tabs[i]=r[h];else if("bKGD"==i)0==f.ctype||4==f.ctype?f.tabs[i]=[c(r,h)]:2==f.ctype||6==f.ctype?f.tabs[i]=[c(r,h),c(r,h+2),c(r,h+4)]:3==f.ctype&&(f.tabs[i]=r[h]);else if("IEND"==i)break;h+=t,a.readUint(r,h),h+=4}var M;return 0!=b&&((M=f.frames[f.frames.length-1]).data=e(f,v.slice(0,b),M.rect.width,M.rect.height)),f.data=e(f,u,f.width,f.height),delete f.compress,delete f.interlace,delete f.filter,f},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),c=new Uint8Array(r);for(let t=0;t<e.frames.length;t++){const f=e.frames[t],u=f.rect.x,v=f.rect.y,p=f.rect.width,b=f.rect.height,g=i(f.data,p,b,e);if(0!=t)for(var d=0;d<r;d++)c[d]=h[d];if(0==f.blend?a(g,p,b,h,s,n,u,v,0):1==f.blend&&a(g,p,b,h,s,n,u,v,1),o.push(h.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)a(l,p,b,h,s,n,u,v,0);else if(2==f.dispose)for(d=0;d<r;d++)h[d]=c[d]}return o},_paeth:h,_copyTile:a,_bin:t}}();!function(){const{_copyTile:t}=vt,{_bin:i}=vt,e=vt._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,a){null==a&&(a=1);const c=s.length,d=[];for(var f=0;f<c;f++){const t=s[f];d.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(f=0;f<c;f++){let t=4294967295;for(var u=0,v=0;v<c;v++){var p=r(d[f],d[v]);v!=f&&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(f=0;f<w.length;f++)w[f]=255*((w[f]+.5)/16-.5);for(let h=0;h<e;h++)for(let k=0;k<i;k++){var y;f=4*(h*i+k);if(2!=a)y=[o(t[f]+g[f]),o(t[f+1]+g[f+1]),o(t[f+2]+g[f+2]),o(t[f+3]+g[f+3])];else{p=w[4*(3&h)+(3&k)];y=[o(t[f]+p),o(t[f+1]+p),o(t[f+2]+p),o(t[f+3]+p)]}u=0;let x=16777215;for(v=0;v<c;v++){const t=r(y,d[v]);t<x&&(x=t,u=v)}const m=d[u],z=[y[0]-m[0],y[1]-m[1],y[2]-m[2],y[3]-m[3]];1==a&&(k!=i-1&&n(z,g,f+4,7),h!=e-1&&(0!=k&&n(z,g,f+4*i-4,3),n(z,g,f+4*i,5),k!=i-1&&n(z,g,f+4*i+4,1))),l[f>>2]=u,b[f>>2]=s[u]}}function l(t,e,n,o,r){null==r&&(r={});const{crc:h}=s,l=i.writeUint,a=i.writeUshort,c=i.writeASCII;let d=8;const f=t.frames.length>1;let u,v=false,p=33+(f?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++){f&&(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,d,13),d+=4,c(y,d,"IHDR"),d+=4,l(y,d,e),d+=4,l(y,d,n),d+=4,y[d]=t.depth,d++,y[d]=t.ctype,d++,y[d]=0,d++,y[d]=0,d++,y[d]=0,d++,l(y,d,h(y,d-17,17)),d+=4,null!=r.sRGB&&(l(y,d,1),d+=4,c(y,d,"sRGB"),d+=4,y[d]=r.sRGB,d++,l(y,d,h(y,d-5,5)),d+=4),null!=r.iCCP){const t=13+u.length;l(y,d,t),d+=4,c(y,d,"iCCP"),d+=4,c(y,d,"ICC profile"),d+=11,d+=2,y.set(u,d),d+=u.length,l(y,d,h(y,d-(t+4),t+4)),d+=4}if(null!=r.pHYs&&(l(y,d,9),d+=4,c(y,d,"pHYs"),d+=4,l(y,d,r.pHYs[0]),d+=4,l(y,d,r.pHYs[1]),d+=4,y[d]=r.pHYs[2],d++,l(y,d,h(y,d-13,13)),d+=4),f&&(l(y,d,8),d+=4,c(y,d,"acTL"),d+=4,l(y,d,t.frames.length),d+=4,l(y,d,null!=r.loop?r.loop:0),d+=4,l(y,d,h(y,d-12,12)),d+=4),3==t.ctype){l(y,d,3*(b=t.plte.length)),d+=4,c(y,d,"PLTE"),d+=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[d+i+0]=s,y[d+i+1]=n,y[d+i+2]=o}if(d+=3*b,l(y,d,h(y,d-3*b-4,3*b+4)),d+=4,v){l(y,d,b),d+=4,c(y,d,"tRNS"),d+=4;for(g=0;g<b;g++)y[d+g]=t.plte[g]>>>24&255;d+=b,l(y,d,h(y,d-b-4,b+4)),d+=4}}let x=0;for(w=0;w<t.frames.length;w++){var m=t.frames[w];f&&(l(y,d,26),d+=4,c(y,d,"fcTL"),d+=4,l(y,d,x++),d+=4,l(y,d,m.rect.width),d+=4,l(y,d,m.rect.height),d+=4,l(y,d,m.rect.x),d+=4,l(y,d,m.rect.y),d+=4,a(y,d,o[w]),d+=2,a(y,d,1e3),d+=2,y[d]=m.dispose,d++,y[d]=m.blend,d++,l(y,d,h(y,d-30,30)),d+=4);const i=m.cimg;l(y,d,(b=i.length)+(0==w?0:4)),d+=4;const e=d;c(y,d,0==w?"IDAT":"fdAT"),d+=4,0!=w&&(l(y,d,x++),d+=4),y.set(i,d),d+=b,l(y,d,h(y,e,d-e)),d+=4}return l(y,d,0),d+=4,c(y,d,"IEND"),d+=4,l(y,d,h(y,d-4,4)),d+=4,y.buffer}function a(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 c(i,e,s,n,o){const r=o[0],l=o[1],a=o[2],c=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 a=0;a<e.length;a++){const i=new Uint8Array(e[a]),d=new Uint32Array(i.buffer);var c;let v=0,b=0,g=s,w=n,y=o?1:0;if(0!=a){const k=h||o||1==a||0!=l[a-2].dispose?1:2;let x=0,m=1e9;for(let t=0;t<k;t++){var u=new Uint8Array(e[a-1-t]);const i=new Uint32Array(e[a-1-t]);let o=s,h=n,l=-1,c=-1;for(let t=0;t<n;t++)for(let e=0;e<s;e++){d[p=t*s+e]!=i[p]&&(e<o&&(o=e),e>l&&(l=e),t<h&&(h=t),t>c&&(c=t))}-1==l&&(o=h=l=c=0),r&&(1==(1&o)&&o--,1==(1&h)&&h--);const f=(l-o+1)*(c-h+1);f<m&&(m=f,x=t,v=o,b=h,g=l-o+1,w=c-h+1)}u=new Uint8Array(e[a-1-x]);1==x&&(l[a-1].dispose=2),c=new Uint8Array(g*w*4),t(u,s,n,c,g,w,-v,-b,0),y=t(i,s,n,c,g,w,-v,-b,3)?1:0,1==y?f(i,s,n,c,{x:v,y:b,width:g,height:w}):t(i,s,n,c,g,w,-v,-b,0)}else c=i.slice(0);l.push({rect:{x:v,y:b,width:g,height:w},img:c,blend:y,dispose:0})}if(o)for(a=0;a<l.length;a++){if(1==(b=l[a]).blend)continue;const t=b.rect,i=l[a-1].rect,o=Math.min(t.x,i.x),h=Math.min(t.y,i.y),c={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[a-1].dispose=1,a-1!=0&&d(e,s,n,l,a-1,c,r),d(e,s,n,l,a,c,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,a),A={},M=[],T=[];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 C=new Uint8Array(e.inds.buffer,s>>2,t>>2);T.push(C);const i=new Uint8Array(e.abuf,s,t);v&&h(E.img,E.rect.width,E.rect.height,M,i,C),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,C=new Uint8Array(k);T.push(C);for(x=0;x<k;x++){const i=t[x];if(0!=x&&i==t[x-1])C[x]=C[x-1];else if(x>S&&i==t[x-S])C[x]=C[x-S];else{let t=A[i];if(null==t&&(A[i]=t=M.length,M.push(i),M.length>=300))break;C[x]=t}}}const F=M.length;F<=256&&0==u&&(g=F<=2?1:F<=4?2:F<=16?4:8,g=Math.max(g,c));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(F<=256&&0==u){e=Math.ceil(g*S/8);var I=new Uint8Array(e*t);const n=T[y];for(let i=0;i<t;i++){x=i*e;const t=i*S;if(8==g)for(var j=0;j<S;j++)I[x+j]=n[t+j];else if(4==g)for(j=0;j<S;j++)I[x+(j>>1)]|=n[t+j]<<4-4*(1&j);else if(2==g)for(j=0;j<S;j++)I[x+(j>>2)]|=n[t+j]<<6-2*(3&j);else if(1==g)for(j=0;j<S;j++)I[x+(j>>3)]|=n[t+j]<<7-1*(7&j)}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 d(i,e,s,n,o,r,h){const l=Uint8Array,a=Uint32Array,c=new l(i[o-1]),d=new a(i[o-1]),u=o+1<i.length?new l(i[o+1]):null,v=new l(i[o]),p=new a(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,a=p[l];0==a||0==n[o-1].dispose&&d[l]==a&&(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(c,e,s,k.img,r.width,r.height,-r.x,-r.y,0),f(v,e,s,k.img,r)):t(v,e,s,k.img,r.width,r.height,-r.x,-r.y,0)}function f(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,a=[0,1,2,3,4];-1!=o?a=[o]:(i*s>5e5||1==e)&&(a=[0]),r&&(l={level:0});const c=ut;for(var d=0;d<a.length;d++){for(let o=0;o<i;o++)v(n,t,o,s,e,a[d]);h.push(c.deflate(n,l))}let f,u=1e9;for(d=0;d<h.length;d++)h[d].length<u&&(f=d,u=h[d].length);return h[f]}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 a=0;a<n;a++)t[l+a]=i[h+a];else t.set(new Uint8Array(i.buffer,h,n),l);else if(1==r){for(a=0;a<o;a++)t[l+a]=i[h+a];for(a=o;a<n;a++)t[l+a]=i[h+a]-i[h+a-o]+256&255}else if(0==s){for(a=0;a<o;a++)t[l+a]=i[h+a];if(2==r)for(a=o;a<n;a++)t[l+a]=i[h+a];if(3==r)for(a=o;a<n;a++)t[l+a]=i[h+a]-(i[h+a-o]>>1)+256&255;if(4==r)for(a=o;a<n;a++)t[l+a]=i[h+a]-e(i[h+a-o],0,0)+256&255}else{if(2==r)for(a=0;a<n;a++)t[l+a]=i[h+a]+256-i[h+a-n]&255;if(3==r){for(a=0;a<o;a++)t[l+a]=i[h+a]+256-(i[h+a-n]>>1)&255;for(a=o;a<n;a++)t[l+a]=i[h+a]+256-(i[h+a-n]+i[h+a-o]>>1)&255}if(4==r){for(a=0;a<o;a++)t[l+a]=i[h+a]+256-e(0,i[h+a-n],0)&255;for(a=o;a<n;a++)t[l+a]=i[h+a]+256-e(i[h+a-o],i[h+a-n],i[h+a-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,a=new Uint8Array(l>>2);let c;if(e.length<2e7)for(var d=0;d<l;d+=4){c=g(r,f=e[d]*(1/255),u=e[d+1]*(1/255),v=e[d+2]*(1/255),p=e[d+3]*(1/255)),a[d>>2]=c.ind,n[d>>2]=c.est.rgba}else for(d=0;d<l;d+=4){var f=e[d]*(1/255),u=e[d+1]*(1/255),v=e[d+2]*(1/255),p=e[d+3]*(1/255);for(c=r;c.left;)c=w(c.est,f,u,v,p)<=0?c.left:c.right;a[d>>2]=c.ind,n[d>>2]=c.est.rgba}return{abuf:s.buffer,inds:a,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 a={i0:h.i0,i1:l,bst:null,est:null,tdst:0,left:null,right:null};a.bst=x(t,a.i0,a.i1),a.est=m(a.bst);const c={i0:l,i1:h.i1,bst:null,est:null,tdst:0,left:null,right:null};c.bst={R:[],m:[],N:h.bst.N-a.bst.N};for(r=0;r<16;r++)c.bst.R[r]=h.bst.R[r]-a.bst.R[r];for(r=0;r<4;r++)c.bst.m[r]=h.bst.m[r]-a.bst.m[r];c.est=m(c.bst),h.left=a,h.right=c,o[n]=a,o.push(c)}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],a=o-i[3];return r*r+h*h+l*l+a*a}(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 a=g(h,i,e,s,n);return a.tdst<l.tdst?a: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,a=[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],c=a,d=z;let f=[Math.random(),Math.random(),Math.random(),Math.random()],u=0,v=0;if(0!=s)for(let t=0;t<16&&(f=d.multVec(c,f),v=Math.sqrt(d.dot(f,f)),f=d.sml(1/v,f),!(0!=t&&Math.abs(v-u)<1e-9));t++)u=v;const p=[n*l,o*l,r*l,h*l];return{Cov:a,q:p,e:f,L:u,eMq255:d.dot(d.sml(255,p),f),eMq:d.dot(f,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]]};vt.encode=function t(i,e,s,n,o,r,h){null==n&&(n=0),null==h&&(h=false);const d=c(i,e,s,n,[false,false,false,0,h,false]);return a(d,-1),l(d,e,s,o,r)},vt.encodeLL=function t(i,e,s,n,o,r,h,c){const d={ctype:0+(1==n?0:2)+(0==o?0:4),depth:r,frames:[]},f=(n+o)*r,u=f*e;for(let t=0;t<i.length;t++)d.frames.push({rect:{x:0,y:0,width:e,height:s},img:new Uint8Array(i[t]),blend:0,dispose:1,bpp:Math.ceil(f/8),bpl:Math.ceil(u/8)});return a(d,0,true),l(d,e,s,h,c)},vt.encode.compress=c,vt.encode.dither=h,vt.quantize=p,vt.quantize.getKDtree=b,vt.quantize.getNearest=g}();const pt={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,a=122+l,c=new ArrayBuffer(a),d=new DataView(c),f=1<<20;let u,v,p,b,g=f,w=0,y=0,k=0;function x(t){d.setUint16(y,t,true),y+=2}function m(t){d.setUint32(y,t,true),y+=4}function z(t){y+=t}x(19778),m(a),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,d.setUint32(b+u,v<<8|p),u+=4;w++}k<r.length?(g=f,setTimeout(t,pt._dly)):i(c)}()},toBlob(t,i){this.toArrayBuffer(t,(t=>{i(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var bt={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},gt={[bt.CHROME]:16384,[bt.FIREFOX]:11180,[bt.DESKTOP_SAFARI]:16384,[bt.IE]:8192,[bt.IOS]:4096,[bt.ETC]:8192};const wt="undefined"!=typeof window,yt="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,kt=wt&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),xt=(wt||yt)&&(kt&&kt.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),mt=(wt||yt)&&(kt&&kt.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function zt(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 a=new Blob([l],{type:o});a.name=i,a.lastModified=e,s(a)}))}function At(t){return new Promise(((i,e)=>{const s=new mt;s.onload=()=>i(s.result),s.onerror=t=>e(t),s.readAsDataURL(t)}))}function Mt(t){return new Promise(((i,e)=>{const s=new Image;s.onload=()=>i(s),s.onerror=t=>e(t),s.src=t}))}function Tt(){if(void 0!==Tt.cachedResult)return Tt.cachedResult;let t=bt.ETC;const{userAgent:i}=navigator;return/Chrom(e|ium)/i.test(i)?t=bt.CHROME:/iP(ad|od|hone)/i.test(i)&&/WebKit/i.test(i)?t=bt.IOS:/Safari/i.test(i)?t=bt.DESKTOP_SAFARI:/Firefox/i.test(i)?t=bt.FIREFOX:(/MSIE/i.test(i)||true==!!document.documentMode)&&(t=bt.IE),Tt.cachedResult=t,Tt.cachedResult}function Ct(t,i){const e=Tt(),s=gt[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 Et(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 St(t,i){const{width:e,height:s}=Ct(t.width,t.height),[n,o]=Et(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 It(t,i={}){return new Promise((function(e,s){let n,o;var r=function(){try{return o=St(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 At(t).then((function(t){try{return i=t,Mt(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()||[bt.DESKTOP_SAFARI,bt.MOBILE_SAFARI].includes(Tt()))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 jt(t,i,e,s,n=1){return new Promise((function(o,r){let h;if("image/png"===i){let a,c,d;return a=t.getContext("2d"),({data:c}=a.getImageData(0,0,t.width,t.height)),d=vt.encode([c.buffer],t.width,t.height,4096*n),h=new Blob([d],{type:i}),h.name=e,h.lastModified=s,l.call(this)}{if("image/bmp"===i)return new Promise((i=>pt.toBlob(t,i))).then(function(t){try{return h=t,h.name=e,h.lastModified=s,f.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),zt(v,e,s).then(function(t){try{return h=t,u.call(this)}catch(t){return r(t)}}.bind(this),r)}function u(){return f.call(this)}}function f(){return l.call(this)}}function l(){return o(h)}}))}function Bt(t){t.width=0,t.height=0}function Ut(){return new Promise((function(t,i){let e,s,n,o;return void 0!==Ut.cachedResult?t(Ut.cachedResult):zt("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(r){try{return e=r,It(e).then((function(r){try{return s=r[1],jt(s,e.type,e.name,e.lastModified).then((function(e){try{return n=e,Bt(s),It(n).then((function(e){try{return o=e[0],Ut.cachedResult=1===o.width&&2===o.height,t(Ut.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 Ot(t){return new Promise(((i,e)=>{const s=new mt;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 $t(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]=Et(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),Bt(t)),r}function Dt(t,i){const{width:e}=t,{height:s}=t,[n,o]=Et(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),Bt(t),n}function Pt(t,i,e=0){return new Promise((function(s,n){let o,r,h,l,a,c,d,f,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 T(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(),It(t,i).then(function(e){try{return[,l]=e,M(),a=$t(l,i),M(),new Promise((function(e,s){var n;if(!(n=i.exifOrientation))return Ot(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 c=e,M(),Ut().then(function(e){try{return d=e?a:Dt(a,c),M(),f=i.initialQuality||1,u=i.fileType||t.type,jt(d,u,t.name,t.lastModified,f).then(function(e){try{{if(v=e,M(),p=v.size>h,b=v.size>t.size,!p&&!b)return T(100),s(v);var o;function c(){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]=Et(i,e),m.drawImage(z,0,0,i,e),f*="image/png"===u?.85:.95,jt(x,u,t.name,t.lastModified,f).then((function(t){try{return k=t,Bt(z),z=x,y=k.size,T(Math.min(99,Math.floor((w-y)/(w-h)*100))),c}catch(t){return n(t)}}),n)}return[1]}return g=t.size,w=v.size,y=w,z=d,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()?C.call(this):t;t=c}else t=t.call(this)}catch(t){return n(t)}}}.bind(this))(c);function C(){return Bt(z),Bt(x),Bt(a),Bt(d),Bt(l),T(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 Rt="\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 Qt;function _t(t,i){return new Promise(((e,s)=>{Qt||(Qt=function t(i){const e=[];return e.push(i),URL.createObjectURL(new Blob(e))}(Rt));const n=new Worker(Qt);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 Lt(t,i){return new Promise((function(e,s){let n,o,r,h,l,a;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 xt))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(a="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!l||"function"!=typeof Worker||a)return Pt(t,n).then(function(t){try{return o=t,f.call(this)}catch(t){return s(t)}}.bind(this),s);var c=function(){try{return f.call(this)}catch(t){return s(t)}}.bind(this),d=function(i){try{return Pt(t,n).then((function(t){try{return o=t,c()}catch(t){return s(t)}}),s)}catch(t){return s(t)}};try{return n.libURL=n.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",_t(t,n).then((function(t){try{return o=t,c()}catch(t){return d()}}),d)}catch(t){d()}function f(){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=at(t,o))}catch(t){}return e(o)}}))}Lt.getDataUrlFromFile=At,Lt.getFilefromDataUrl=zt,Lt.loadImage=Mt,Lt.drawImageInCanvas=St,Lt.drawFileInCanvas=It,Lt.canvasToFile=jt,Lt.getExifOrientation=Ot,Lt.handleMaxWidthOrHeight=$t,Lt.followExifOrientation=Dt,Lt.cleanupCanvasMemory=Bt,Lt.isAutoOrientationInBrowser=Ut,Lt.approximateBelowMaximumCanvasSizeOfBrowser=Ct,Lt.copyExifWithoutOrientation=at,Lt.getBrowserName=Tt,Lt.version="2.0.2";class Ht extends F{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];Lt(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=new K(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=new ht(this._store);i.addOrRemove(t);i.selected=true;const e=new k(this._store,this,t);const s=new st(this._store,this,i);this._store.history.executeCommand(new L(this._store,this,[e,s]));this._store.setState("activeTool",B.getTool("selection"))}handleCancel(){this._store.setState("activeTool",B.getTool("selection"))}}const Wt={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 Kt={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 Vt=[{name:"selection",type:"tool",tool:ot,icon:"cursor"},{name:"brush",type:"tool",tool:I,isDefault:true,icon:"pen",config:Wt},{name:"eraser",type:"tool",tool:W,icon:"eraser"},{name:"text",type:"tool",tool:U,icon:"type",config:Kt},{name:"image",type:"tool",tool:Ht,icon:"image"},{name:"divider",type:"divider"},{name:"config",type:"config"}];const Xt="kritzel-editor{display:flex;margin:0;position:relative;overflow:hidden;width:100%;height:100%;align-items:center;justify-content:center;touch-action:manipulation;user-select:none}kritzel-controls{position:absolute;bottom:28px}";const Yt=class{constructor(i){t(this,i);this.controls=Vt;this.customSvgIcons={};this.hideControls=false}handleTouchStart(t){if(t.cancelable){t.preventDefault()}}componentWillLoad(){this.registerCustomSvgIcons()}registerCustomSvgIcons(){for(const[t,i]of Object.entries(this.customSvgIcons)){_.register(t,i)}}render(){return e(s,{key:"3a2846ec3573702162d669a130420f5b0dca97bd"},e("kritzel-engine",{key:"853d5558e2886c62a3a07109be23145978a0a88f"}),e("kritzel-controls",{key:"eb4d48e6768b4808d3efc43ceb104de72475a4f2",controls:this.controls,style:this.hideControls?{display:"none"}:{display:"flex"}}))}get host(){return n(this)}};Yt.style=Xt;class Nt{constructor(t,i){this.initialTouchDistance=0;this.startX=0;this.startY=0;this._store=t;this._store.state.host=i;this._store.state.viewportWidth=i.clientWidth;this._store.state.viewportHeight=i.clientHeight;this._store.state.startX=0;this._store.state.startY=0;this._store.state.translateX=0;this._store.state.translateY=0}handleResize(){this._store.state.viewportWidth=this._store.state.host.clientWidth;this._store.state.viewportHeight=this._store.state.host.clientHeight;this._store.state.hasViewportChanged=true;this._store.rerender()}handleMouseDown(t){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;if(w.isRightClick(t)){this._store.state.isPanning=true;this._store.state.startX=i;this._store.state.startY=e}}handleMouseMove(t){const i=t.clientX-this._store.offsetX;const e=t.clientY-this._store.offsetY;this._store.state.cursorX=i;this._store.state.cursorY=e;if(this._store.state.isPanning){this._store.state.translateX-=this._store.state.startX-i;this._store.state.translateY-=this._store.state.startY-e;this._store.state.startX=i;this._store.state.startY=e;this._store.state.hasViewportChanged=true;this._store.state.skipContextMenu=true;this._store.rerender()}}handleMouseUp(t){if(this._store.state.isPanning){this._store.state.isPanning=false;this._store.rerender()}}handleTouchStart(t){this._store.state.touchCount=t.touches.length;if(this._store.state.touchCount===2){this._store.state.currentPath=null;this._store.state.isScaling=true;const i=t.touches[0].clientX-this._store.offsetX;const e=t.touches[0].clientY-this._store.offsetY;const s=t.touches[1].clientX-this._store.offsetX;const n=t.touches[1].clientY-this._store.offsetY;this.initialTouchDistance=Math.sqrt(Math.pow(i-s,2)+Math.pow(e-n,2));this.startX=(i+s)/2;this.startY=(e+n)/2;this._store.rerender()}}handleTouchMove(t){if(this._store.state.touchCount===2){const i=t.touches[0].clientX-this._store.offsetX;const e=t.touches[0].clientY-this._store.offsetY;const s=t.touches[1].clientX-this._store.offsetX;const n=t.touches[1].clientY-this._store.offsetY;const 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 a=this._store.state.scale*l;if(a>this._store.state.scaleMax||a<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=a;this.initialTouchDistance=o}this.startX=r;this.startY=h;this._store.state.hasViewportChanged=true;this._store.rerender()}}handleTouchEnd(t){this._store.state.touchCount=0;this._store.state.isScaling=false;this._store.rerender()}handleWheel(t){t.preventDefault();if(t.ctrlKey===true&&w.isMainMouseWheel(t)){this.handleZoom(t)}if(!t.ctrlKey){this.handlePan(t)}}handleZoom(t){const i=this._store.state.host.getBoundingClientRect();this._store.state.cursorX=t.clientX-i.left;this._store.state.cursorY=t.clientY-i.top;const e=t.deltaY>0?-this._store.state.scaleStep*this._store.state.scale:this._store.state.scaleStep*this._store.state.scale;const s=Math.min(this._store.state.scaleMax,Math.max(this._store.state.scaleMin,this._store.state.scale+e));const n=s/this._store.state.scale;const 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 Gt 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 qt{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 Zt{constructor(t){this._store=t;this.undoStack=new qt(this._store.state.historyBufferSize);this.redoStack=new qt(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 Gt(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 Gt(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 Jt{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 Jt({x:t,y:i,z:e,width:r,height:h,depth:l},this.capacity),new Jt({x:t+r,y:i,z:e,width:r,height:h,depth:l},this.capacity),new Jt({x:t,y:i+h,z:e,width:r,height:h,depth:l},this.capacity),new Jt({x:t+r,y:i+h,z:e,width:r,height:h,depth:l},this.capacity),new Jt({x:t,y:i,z:e+l,width:r,height:h,depth:l},this.capacity),new Jt({x:t+r,y:i,z:e+l,width:r,height:h,depth:l},this.capacity),new Jt({x:t,y:i+h,z:e+l,width:r,height:h,depth:l},this.capacity),new Jt({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 ti 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 ii={activeTool:null,activeText:null,currentPath:null,copiedObjects:null,objectsOctree:null,selectionBox:null,selectionGroup:null,resizeHandleType:null,hasViewportChanged:false,isEnabled:true,isScaling:false,isPanning:false,isFocused:false,isSelecting:false,isResizing:false,isResizeHandleSelected:false,isRotating:false,isRotationHandleSelected:false,isDragging:false,isDrawing:false,isErasing:false,isWriting:false,isCtrlKeyPressed:false,isContextMenuVisible:false,contextMenuItems:[],contextMenuX:0,contextMenuY:0,skipContextMenu:false,debugInfo:{showObjectInfo:false,showViewportInfo:false,logCommands:false},host:null,cursorX:0,cursorY:0,scale:1,scaleMax:1e3,scaleMin:1e-4,scaleStep:.05,startX:0,startY:0,translateX:0,translateY:0,viewportWidth:0,viewportHeight:0,historyBufferSize:1e3,touchCount:0,longTouchTimeout:null,longTouchDelay:300};class ei{get history(){return this._history}get state(){return this._state}get currentZIndex(){return this._state.objectsOctree.filter((t=>!(t instanceof ht)&&!(t instanceof et))).length}get allObjects(){return this._state.objectsOctree.allObjects()}get selectedObjects(){return this.allObjects.filter((t=>!(t instanceof ht))).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=ii;this._kritzelEngine=t;this._history=new Zt(this);this._state.objectsOctree=new Jt({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 V(this,this))}}onStateChange(t,i){if(!this._listeners.has(t)){this._listeners.set(t,new Set)}this._listeners.get(t).add(i)}setState(t,i){const e=this._state[t];if(e!==i){this._state[t]=i;if(this._listeners.has(t)){this._listeners.get(t).forEach((s=>s(i,e,String(t))))}}}clearSelection(){this.history.executeCommand(new V(this,this.state.selectionGroup))}delete(){if(!this.state.selectionGroup){return}const t=this.state.selectionGroup.objects.map((t=>new H(this,this.state.selectionGroup,t)));const i=new V(this,this.state.selectionGroup);const e=[...t,i];this.history.executeCommand(new L(this,this.state.selectionGroup,e))}deleteObject(t,i=true){const e=this.findObjectById(t);if(e){if(i){const t=new H(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 V(this,this.state.selectionGroup))}const o=this.state.copiedObjects.objects.map((t=>new k(this,this,t)));const r=new st(this,this,this.state.copiedObjects);n.push(...o,r);this.history.executeCommand(new L(this,this,n));this.state.isSelecting=false;this.state.copiedObjects=this.state.selectionGroup.copy();this.setState("activeTool",B.getTool("selection"))}moveUp(){const t=this.allObjects.length+1;const i=this.state.selectionGroup.objects.map((i=>{if(i.zIndex===t){return}return new ti(this,this,i,{zIndex:i.zIndex+1})}));this.history.executeCommand(new L(this,this,i))}moveDown(){const t=0;const i=this.state.selectionGroup.objects.map((i=>{if(i.zIndex===t){return}return new ti(this,this,i,{zIndex:i.zIndex-1})}));this.history.executeCommand(new L(this,this,i))}moveToTop(){const t=this.allObjects.length+1;const i=this.state.selectionGroup.objects.map((i=>new ti(this,this,i,{zIndex:t})));this.history.executeCommand(new L(this,this,i))}moveToBottom(){const t=-1;const i=this.state.selectionGroup.objects.map((i=>new ti(this,this,i,{zIndex:t})));this.history.executeCommand(new L(this,this,i))}selectAllInViewport(){const t=this._state.objectsOctree.query({x:-this._state.translateX/this._state.scale,y:-this._state.translateY/this._state.scale,z:this._state.scale,width:this._state.viewportWidth/this._state.scale,height:this._state.viewportHeight/this._state.scale,depth:100}).filter((t=>!(t instanceof ht)&&!(t instanceof et)&&!(t instanceof f)));if(t.length>0){const i=new ht(this);t.forEach((t=>{t.selected=false;i.addOrRemove(t)}));i.selected=true;this.state.isSelecting=false;this.history.executeCommand(new st(this,this,i));this.setState("activeTool",B.getTool("selection"))}}resetActiveText(){if(this.state.activeText&&this.state.activeText.value===" "){this.deleteObject(this.state.activeText.id,false);this.history.undoStack.pop()}this.state.activeText=null}getObjectFromPointerEvent(t,i=".object"){var e;const s=(e=this.state.host)===null||e===void 0?void 0:e.shadowRoot;if(!s)return null;let n;let 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}resetSelection(){this.state.selectionGroup=null;this.state.selectionBox=null;this.state.isSelecting=false;this.state.isResizeHandleSelected=false;this.state.isRotationHandleSelected=false;this._state.objectsOctree.remove((t=>t instanceof ht));this.rerender()}}class si extends Y{constructor(t){super(t)}handleKeyDown(t){if(this._store.state.isFocused===false){return}this._store.state.isCtrlKeyPressed=t.ctrlKey;if(this._store.state.isCtrlKeyPressed){t.preventDefault()}if(t.key==="Escape"&&this._store.state.selectionGroup){this._store.clearSelection()}if(t.key==="Delete"&&this._store.state.selectionGroup){this._store.delete()}if(t.key==="z"&&t.ctrlKey){this._store.history.undo()}if(t.key==="y"&&t.ctrlKey){this._store.history.redo()}if(t.key==="s"&&t.ctrlKey){this._store.setState("activeTool",B.getTool("selection"));this._store.deselectAllObjects()}if(t.key==="b"&&t.ctrlKey){this._store.setState("activeTool",B.getTool("brush"));this._store.deselectAllObjects()}if(t.key==="e"&&t.ctrlKey){this._store.setState("activeTool",B.getTool("eraser"));this._store.deselectAllObjects()}if(t.key==="i"&&t.ctrlKey){this._store.setState("activeTool",B.getTool("image"));this._store.deselectAllObjects()}if(t.key==="x"&&t.ctrlKey){this._store.setState("activeTool",B.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 ni{static forceHideKeyboard(){if(document.activeElement instanceof HTMLElement){document.activeElement.blur()}}}class oi extends Y{constructor(t,i,e){super(t);this.globalContextMenuItems=[];this.objectContextMenuItems=[];this.globalContextMenuItems=i;this.objectContextMenuItems=e}handleContextMenu(t){if(t.cancelable){t.preventDefault()}if(!(this._store.state.activeTool instanceof ot)){return}if(this._store.state.skipContextMenu){this._store.state.skipContextMenu=false;return}this._store.state.contextMenuItems=this._store.state.selectionGroup?this.objectContextMenuItems:this.globalContextMenuItems;let i=t.clientX-this._store.offsetX;let e=t.clientY-this._store.offsetY;const s=150;const n=200;const o=10;if(i+s>window.innerWidth-o){i=window.innerWidth-s-o}if(e+n>window.innerHeight-o){e=window.innerHeight-n-o}i=Math.max(o,i);e=Math.max(o,e);this._store.state.contextMenuX=i;this._store.state.contextMenuY=e;this._store.state.isContextMenuVisible=true;this._store.state.isEnabled=false;this._store.rerender()}handleContextMenuTouch(t){if(t.cancelable){t.preventDefault()}if(this._store.state.touchCount>1||!(this._store.state.activeTool instanceof ot)){return}if("vibrate"in navigator){navigator.vibrate(25)}const i=this._store.getObjectFromPointerEvent(t,".object");if(i&&!(i instanceof ht)){this._store.state.selectionGroup=new ht(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 st(this._store,this,this._store.state.selectionGroup))}this._store.state.contextMenuItems=this._store.state.selectionGroup?this.objectContextMenuItems:this.globalContextMenuItems;const e=t.touches[0];if(!e){return}let s=Math.round(e.clientX-this._store.offsetX);let n=Math.round(e.clientY-this._store.offsetY);const o=150;const r=200;const h=10;if(s+o>window.innerWidth-h){s=window.innerWidth-o-h}if(n+r>window.innerHeight-h){n=window.innerHeight-r-h}s=Math.max(h,s);n=Math.max(h,n);this._store.state.contextMenuX=s;this._store.state.contextMenuY=n;this._store.state.isContextMenuVisible=true;this._store.state.isEnabled=false;this._store.rerender()}}const ri=":host{display:block;position:relative;height:100%;width:100%;overflow:hidden;background-color:var(--kritzel-engine-background-color, #ffffff)}.debug-panel{position:absolute;pointer-events:none;top:0;right:0}.origin{position:relative;top:0;left:0;height:0;width:0;pointer-events:none;-webkit-transform-origin:top left;-moz-transform-origin:top left;transform-origin:top left;overflow:visible}.object{overflow:visible}textarea{all:unset;box-sizing:border-box;outline:none !important;border:none !important;overflow:visible}.resize-handle-overlay.top-left,.resize-handle-overlay.bottom-right{cursor:nwse-resize}.resize-handle-overlay.top-right,.resize-handle-overlay.bottom-left{cursor:nesw-resize}.rotation-handle-overlay{cursor:grab}";const hi=class{get isSelecting(){return this.store.state.activeTool instanceof ot&&this.store.state.isSelecting}get isSelectionActive(){return this.store.state.activeTool instanceof ot&&this.store.state.selectionGroup!==null}constructor(e){t(this,e);this.engineReady=i(this,"engineReady");this.activeToolChange=i(this,"activeToolChange");this.globalContextMenuItems=[{label:"Paste",icon:"paste",disabled:()=>this.store.state.copiedObjects===null,action:()=>{const t=(-this.store.state.translateX+this.store.state.contextMenuX)/this.store.state.scale;const i=(-this.store.state.translateY+this.store.state.contextMenuY)/this.store.state.scale;this.paste(t,i)}},{label:"Select All",icon:"select-all",action:()=>this.selectAllInViewport()}];this.objectContextMenuItems=[{label:"Copy",icon:"copy",action:()=>this.copy()},{label:"Paste",icon:"paste",disabled:()=>this.store.state.copiedObjects===null,action:()=>{const t=(-this.store.state.translateX+this.store.state.contextMenuX)/this.store.state.scale;const i=(-this.store.state.translateY+this.store.state.contextMenuY)/this.store.state.scale;this.paste(t,i)}},{label:"Delete",icon:"delete",action:()=>this.delete()},{label:"Bring to Front",icon:"bring-to-front",action:()=>this.moveToTop()},{label:"Send to Back",icon:"send-to-back",action:()=>this.moveToBottom()}];this.forceUpdate=0;this.contextMenuElement=null;this.store=new ei(this);this.contextMenuHandler=new oi(this.store,this.globalContextMenuItems,this.objectContextMenuItems);this.keyHandler=new si(this.store);this.store.onStateChange("activeTool",(t=>{if(!(t instanceof ot)){this.store.resetSelection()}this.store.state.skipContextMenu=false;this.activeToolChange.emit(t);ni.forceHideKeyboard()}));this.store.onStateChange("isFocused",(t=>{if(!t){this.store.resetActiveText()}}))}componentDidLoad(){this.viewport=new Nt(this.store,this.host);this.engineReady.emit()}handleContextMenu(t){if(this.store.state.isEnabled===false){return}this.contextMenuHandler.handleContextMenu(t)}handleMouseDown(t){var i,e;if(this.store.state.isContextMenuVisible){this.hideContextMenu();return}if(this.store.state.isEnabled===false){return}this.viewport.handleMouseDown(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleMouseDown(t)}handleMouseMove(t){var i,e;if(this.store.state.isEnabled===false){return}this.viewport.handleMouseMove(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleMouseMove(t)}handleMouseUp(t){var i,e;if(this.store.state.isEnabled===false){return}this.viewport.handleMouseUp(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleMouseUp(t)}handleDoubleClick(t){var i,e;if(this.store.state.isEnabled===false){return}(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleDoubleClick(t)}handleDoubleTap(t){var i,e;if(this.store.state.isEnabled===false){return}const s=t instanceof CustomEvent&&t.detail?t.detail:t;(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleDoubleTap(s)}handleTouchStart(t){var i,e;if(this.store.state.isEnabled===false){return}if(w.detectDoubleTap()){const t=new CustomEvent("doubletap",{detail:event,bubbles:true,composed:true});this.host.dispatchEvent(t)}if(t.touches.length>1){clearTimeout(this.store.state.longTouchTimeout)}if(t.cancelable){t.preventDefault()}this.store.state.longTouchTimeout=setTimeout((()=>this.contextMenuHandler.handleContextMenuTouch(t)),this.store.state.longTouchDelay);this.viewport.handleTouchStart(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleTouchStart(t)}handleTouchMove(t){var i,e;if(this.store.state.isEnabled===false){return}if(t.cancelable){t.preventDefault()}this.viewport.handleTouchMove(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleTouchMove(t)}handleTouchEnd(t){var i,e;if(this.store.state.isEnabled===false){return}if(t.cancelable){t.preventDefault()}clearTimeout(this.store.state.longTouchTimeout);this.viewport.handleTouchEnd(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleTouchEnd(t)}handleTouchCancel(t){clearTimeout(this.store.state.longTouchTimeout)}handleWheel(t){var i,e;if(this.store.state.isContextMenuVisible){this.hideContextMenu()}this.viewport.handleWheel(t);(e=(i=this.store.state)===null||i===void 0?void 0:i.activeTool)===null||e===void 0?void 0:e.handleWheel(t)}handleResize(){this.viewport.handleResize()}handleKeyDown(t){this.keyHandler.handleKeyDown(t)}handleKeyUp(t){this.keyHandler.handleKeyUp(t)}updateFocus(t){const i=this.store.state.host.getBoundingClientRect();const e=t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom;const s=t.composedPath();const n=this.host.closest("kritzel-engine");const 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 F)){console.error(`Failed to register tool "${t}": Tool class must be a constructor function`);return null}const s=B.registerTool(t,i,this.store);if(e){Object.entries(e).forEach((([t,i])=>{s[t]=i}))}return Promise.resolve(s)}async changeActiveTool(t){var i;(i=this.store.state.activeTool)===null||i===void 0?void 0:i.onDeactivate();this.store.setState("activeTool",t);this.store.deselectAllObjects();t===null||t===void 0?void 0:t.onActivate()}async setFocus(){this.host.focus();this.store.state.isFocused=true}async disable(){this.store.state.isEnabled=false;this.forceUpdate++}async enable(){this.store.state.isEnabled=true;this.forceUpdate++}async delete(){this.store.delete()}async copy(){this.store.copy()}async paste(t,i){this.store.paste(t,i)}async moveToTop(){this.store.moveToTop()}async moveToBottom(){this.store.moveToBottom()}async selectAllInViewport(){this.store.selectAllInViewport()}async undo(){this.store.history.undo()}async redo(){this.store.history.redo()}async hideContextMenu(){this.store.state.isContextMenuVisible=false;this.store.state.selectionBox=null;this.store.state.isSelecting=false}render(){var t,i,n,o,r,h,l,a,c,d,f,u,v,p,b,g,w,y,k,x,m,z,A,M,T,C,E;const F=window.getComputedStyle(this.host);const I=F.getPropertyValue("--kritzel-selection-handle-size").trim()||"6px";const B=parseFloat(I);const U=B*2<14?14:B;return e(s,{key:"81d2f8efadded214fde44f3dbaea3b678d0b182b"},e("div",{key:"6657555d40bff3b5d44733e286c4076a82ca2e98",class:"debug-panel",style:{display:this.store.state.debugInfo.showViewportInfo?"block":"none"}},e("div",{key:"e0cf766f7e8c8e7856a6b55c9c24272fa865c86e"},"TranslateX: ",(t=this.store.state)===null||t===void 0?void 0:t.translateX),e("div",{key:"6c979eb953d01507fd29013d9186618f8f14588b"},"TranslateY: ",(i=this.store.state)===null||i===void 0?void 0:i.translateY),e("div",{key:"3be6ea4a5b5eef5d07ddc48aa8ac2e57edbe0887"},"ViewportWidth: ",(n=this.store.state)===null||n===void 0?void 0:n.viewportWidth),e("div",{key:"70aed9d3ee1227ba2a4f54a95eda27cb748f4b9f"},"ViewportHeight: ",(o=this.store.state)===null||o===void 0?void 0:o.viewportHeight),e("div",{key:"c2e79c4245e9f107e5512472030684e0ed617d1a"},"ObjectsInViewport. ",this.store.objects.length),e("div",{key:"66f4284c2d4fd5dae03ffa9b641a28b2528ea117"},"Scale: ",(r=this.store.state)===null||r===void 0?void 0:r.scale),e("div",{key:"e4518d18cf923b57dceb38c07f409471bc178e9d"},"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:"47ea576f9c78f3bfb3e03649a88ec0f7b544f2d7"},"HasViewportChanged: ",((a=this.store.state)===null||a===void 0?void 0:a.hasViewportChanged)?"true":"false"),e("div",{key:"fe92910fd861170651688fedbdc2f15829c15a58"},"IsEnabled: ",((c=this.store.state)===null||c===void 0?void 0:c.isEnabled)?"true":"false"),e("div",{key:"cbe7e87d9a3be8acd47dd45f1b69314a8a9c536a"},"IsScaling: ",((d=this.store.state)===null||d===void 0?void 0:d.isScaling)?"true":"false"),e("div",{key:"722a58415ae67530dfe611e03a34f30e4c1db64e"},"IsPanning: ",((f=this.store.state)===null||f===void 0?void 0:f.isPanning)?"true":"false"),e("div",{key:"d9686a405ee05480c17358afb865a39bd64a2346"},"IsFocused: ",this.store.state.isFocused?"true":"false"),e("div",{key:"383f8e4a9e98b891507ff95416a20279e4d79431"},"IsSelecting: ",this.isSelecting?"true":"false"),e("div",{key:"fbda2b9f1ba4fe9daefb7f8b36d25d297b47a764"},"IsSelectionActive: ",this.isSelectionActive?"true":"false"),e("div",{key:"c1bb88c228cd6bbd2bdb0fe6bb3fd9b47d92bc2e"},"IsResizeHandleSelected: ",this.store.state.isResizeHandleSelected?"true":"false"),e("div",{key:"26c77aadc8cda5f27f746d0c38049d830127c81e"},"IsRotationHandleSelected: ",this.store.state.isRotationHandleSelected?"true":"false"),e("div",{key:"885725248c47714a49769b94ba48a3a0f59a7f97"},"IsDrawing: ",this.store.state.isDrawing?"true":"false"),e("div",{key:"035d1c72d476ea9f8110145a25084eca59cfbedc"},"IsWriting: ",this.store.state.isWriting?"true":"false"),e("div",{key:"d6ac0024bec7d64ca327e6a5760e427e88269b8d"},"CursorX: ",(u=this.store.state)===null||u===void 0?void 0:u.cursorX),e("div",{key:"b3bdd26eb7d5ac0fdfda0f13b7d4cde9f3712954"},"CursorY: ",(v=this.store.state)===null||v===void 0?void 0:v.cursorY)),e("div",{key:"186591f736514dcdb96f22d5ab3d14347a4c51ae",class:"origin",style:{transform:`matrix(${(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,a,c,d,f,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"}},e("svg",{xmlns:"http://www.w3.org/2000/svg",key:t.id,id:t.id,class:"object",style:{height:t===null||t===void 0?void 0:t.totalHeight.toString(),width:t===null||t===void 0?void 0:t.totalWidth.toString(),left:"0",top:"0",position:"absolute",transform:`rotate(${t.rotationDegrees}deg)`,transformOrigin:"center",opacity:t.markedForRemoval?"0.5":t.opacity.toString(),pointerEvents:t.markedForRemoval?"none":"auto",zIndex:t.zIndex.toString()}},e("foreignObject",{x:"0",y:"0",width:t.totalWidth.toString(),height:t.totalHeight.toString(),style:{minHeight:"0",minWidth:"0",backgroundColor:t.backgroundColor,borderColor:t.borderColor,borderWidth:t.borderWidth+"px",borderStyle:"solid",padding:t.padding+"px",overflow:"visible"}},t instanceof 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 K&&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 j&&e("textarea",{ref:i=>t.mount(i),value:t.value,onKeyDown:i=>t.handleKeyDown(i),onInput:i=>t.handleInput(i),rows:t.rows,style:{width:"100%",height:"100%",color:t.fontColor,fontSize:((i=t.fontSize)===null||i===void 0?void 0:i.toString())+"px",fontFamily:t.fontFamily,border:"none",outline:"none",resize:"none",overflow:"hidden",display:"block",padding:"1px",whiteSpace:"nowrap",cursor:t.isReadonly?"default":"text",caretColor:t.isReadonly?"transparent":"auto"}}),t instanceof ht&&e("div",{ref:i=>t.mount(i),style:{width:"100%",height:"100%"}}),t instanceof et&&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:`${B*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:`${B*t.scale/((a=this.store.state)===null||a===void 0?void 0:a.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/((c=this.store.state)===null||c===void 0?void 0:c.scale)}`,style:{fill:"transparent"},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("circle",{class:"resize-handle bottom-left",cx:"0",cy:t.totalHeight,r:`${B*t.scale/((d=this.store.state)===null||d===void 0?void 0:d.scale)}`,style:{fill:"var(--kritzel-selection-handle-color, #000000)"},visibility:t.selected&&!this.isSelecting?"visible":"hidden"}),e("circle",{class:"resize-handle-overlay bottom-left",cx:"0",cy:t.totalHeight,r:`${U*t.scale/((f=this.store.state)===null||f===void 0?void 0:f.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:`${B*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:`${B*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:"9f862215ce2de4cc0745942bc946897f5f5e24b7",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:"e1f0ea5ee56c8fb753438c978750151c688e9330",d:(M=this.store.state.currentPath)===null||M===void 0?void 0:M.d,fill:(T=this.store.state.currentPath)===null||T===void 0?void 0:T.fill,stroke:(C=this.store.state.currentPath)===null||C===void 0?void 0:C.stroke}))),this.store.state.isContextMenuVisible&&e("kritzel-context-menu",{key:"89184b62326fcfde61ee4922ec5d640b16a191a7",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 W&&!this.store.state.isScaling&&e("kritzel-cursor-trail",{key:"8797da3afce7d97e0f94ec9f90522b9ad35bb71b"}))}get host(){return n(this)}};hi.style=ri;const li=":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:"6f25832892d8042464751360cc9e2307193f5407"},e("div",{key:"3d2ec48a6a3b3e347c8cc1ab6f129bfacd984776",class:"font-preview",style:{fontFamily:this.fontFamily,fontSize:`${this.size}px`,color:this.color}},"A"))}};ai.style=li;const ci=":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:"7ab677468a605e6b23466b73c1c93e258cf85c1a"},e("kritzel-dropdown",{key:"5c2528687d1e5068d958b9f663cb0ceb46a2794e",options:t,value:this.selectedFontFamily,onValueChanged:this.handleDropdownValueChange,selectStyles:{fontFamily:this.selectedFontFamily}},e("button",{key:"ab422c954569515f636031ddaaea2ec5f13a7bdc",class:"font-style-button",slot:"suffix"},"B"),e("button",{key:"884116c86f3d710df58f82c10294f66aae95829e",class:"font-style-button italic-text",slot:"suffix"},"I")))}};di.style=ci;const fi=":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 ui=class{constructor(e){t(this,e);this.sizeChange=i(this,"sizeChange");this.sizes=[8,10,12,16,20,24];this.selectedSize=null;this.fontFamily="Arial"}handleSizeClick(t){this.selectedSize=t;this.sizeChange.emit(t)}render(){return e(s,{key:"20ad8f22858732c62838693c7b135dc92dbc5910"},this.sizes.map((t=>e("div",{class:{"size-container":true,selected:this.selectedSize===t},onClick:()=>this.handleSizeClick(t)},e("kritzel-font",{fontFamily:this.fontFamily,size:t})))))}};ui.style=fi;const vi=":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 pi=class{constructor(i){t(this,i);this.size=24}render(){const t=_.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}))}};pi.style=vi;const bi=":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 gi=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})))))}};gi.style=bi;const wi=":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 yi=768;const ki=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<yi}handleWindowResize(){this.isMobileView=window.innerWidth<yi;this.calculateAdjustedPosition()}componentWillLoad(){this.isMobileView=window.innerWidth<yi;this.calculateAdjustedPosition()}componentWillUpdate(){this.calculateAdjustedPosition()}calculateAdjustedPosition(){var t;if(this.isVisible&&this.anchorElement){const i=this.anchorElement.getBoundingClientRect();const e=(t=this.el.shadowRoot)===null||t===void 0?void 0:t.querySelector(".tooltip-content");if(!this.isMobileView){this.positionX=i.left+i.width/2;this.arrowOffset=`calc(${50}% - ${this.arrowSize}px)`}else{const t=e.getBoundingClientRect();this.positionX=i.left+i.width/2-t.width/2;this.arrowOffset=`${i.left+i.width/2-t.left-this.arrowSize}px`}}}render(){return e(s,{key:"30db4852719464fcb9c6964c34992e87a364caa3",style:{position:"fixed",zIndex:"9999",transition:"opacity 0.3s ease-in-out, transform 0.3s ease-in-out",visibility:this.isVisible?"visible":"hidden",left:!this.isMobileView?`${this.positionX}px`:"50%",marginBottom:`${this.offsetY+this.arrowSize}px`}},e("div",{key:"3f270c9bdb1a5282f67034618123a5d61f9f8b40",class:"tooltip-content",onClick:t=>t.stopPropagation()},e("slot",{key:"bd4a11782eb2e263f21a8ab57ad64eb4fd4fe7ec"}),e("div",{key:"4ede173979b8e0335fb3a012b662a694dc09ea28",class:"tooltip-arrow-wrapper",style:{position:"fixed",left:this.arrowOffset,bottom:`-${this.arrowSize*2}px`}},e("div",{key:"c96993f91dde76cc5feb0c42dd4e599837121bf7",class:"tooltip-arrow",style:{borderLeft:`${this.arrowSize}px solid transparent`,borderRight:`${this.arrowSize}px solid transparent`,borderTop:`${this.arrowSize}px solid var(--kritzel-controls-tooltip-background-color, #ffffff)`,filter:"drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2))"}}),e("div",{key:"888f9d44f58969b3f50db04f1cd3d49008872b55",class:"tooltip-arrow-rect",style:{position:"relative",width:`${this.arrowSize*2}px`,height:`${this.arrowSize}px`,backgroundColor:"var(--kritzel-controls-tooltip-background-color, #ffffff)",bottom:`${this.arrowSize*2}px`}}))))}get el(){return n(this)}};ki.style=wi;const xi=":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 mi=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()})))}};mi.style=xi;export{r as kritzel_brush_style,l as kritzel_color,c as kritzel_color_palette,f as kritzel_context_menu,v as kritzel_control_brush_config,b as kritzel_control_text_config,$ as kritzel_controls,P as kritzel_cursor_trail,Q as kritzel_dropdown,Yt as kritzel_editor,hi as kritzel_engine,ai as kritzel_font,di as kritzel_font_family,ui as kritzel_font_size,pi as kritzel_icon,gi as kritzel_stroke_size,ki as kritzel_tooltip,mi as kritzel_utility_panel};
2
- //# sourceMappingURL=p-d0394bb5.entry.js.map