kritzel-stencil 0.1.0 → 0.1.2

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 (176) hide show
  1. package/dist/cjs/{default-line-tool.config-7eJND6Jb.js → default-line-tool.config-MA02HCrH.js} +703 -133
  2. package/dist/cjs/{index-BeKMS-Zt.js → index-Bj0n7fQQ.js} +84 -7
  3. package/dist/cjs/index.cjs.js +1 -1
  4. package/dist/cjs/kritzel-brush-style.cjs.entry.js +1 -1
  5. package/dist/cjs/{kritzel-color_22.cjs.entry.js → kritzel-color_24.cjs.entry.js} +1018 -897
  6. package/dist/cjs/loader.cjs.js +2 -2
  7. package/dist/cjs/stencil.cjs.js +3 -3
  8. package/dist/collection/classes/core/core.class.js +2 -0
  9. package/dist/collection/classes/core/viewport.class.js +43 -3
  10. package/dist/collection/classes/handlers/move.handler.js +6 -0
  11. package/dist/collection/classes/objects/line.class.js +63 -15
  12. package/dist/collection/classes/objects/path.class.js +1 -0
  13. package/dist/collection/classes/objects/shape.class.js +1 -0
  14. package/dist/collection/classes/objects/text.class.js +4 -3
  15. package/dist/collection/classes/providers/indexeddb-sync-provider.class.js +0 -1
  16. package/dist/collection/classes/tools/brush-tool.class.js +5 -0
  17. package/dist/collection/classes/tools/line-tool.class.js +31 -1
  18. package/dist/collection/classes/tools/selection-tool.class.js +193 -0
  19. package/dist/collection/classes/tools/shape-tool.class.js +2 -0
  20. package/dist/collection/classes/tools/text-tool.class.js +3 -0
  21. package/dist/collection/collection-manifest.json +5 -3
  22. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js +3 -2
  23. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +37 -19
  24. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +108 -36
  25. package/dist/collection/components/shared/kritzel-color/kritzel-color.js +2 -2
  26. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.css +1 -1
  27. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.js +24 -2
  28. package/dist/collection/components/shared/kritzel-font/kritzel-font.js +1 -1
  29. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.css +1 -1
  30. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.css +1 -1
  31. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js +1 -1
  32. package/dist/collection/components/shared/kritzel-line-endings/kritzel-line-endings.css +60 -0
  33. package/dist/collection/components/shared/kritzel-line-endings/kritzel-line-endings.js +187 -0
  34. package/dist/collection/components/shared/kritzel-menu/kritzel-menu.js +15 -8
  35. package/dist/collection/components/shared/kritzel-menu-item/kritzel-menu-item.js +16 -9
  36. package/dist/collection/components/shared/kritzel-opacity-slider/kritzel-opacity-slider.css +85 -0
  37. package/dist/collection/components/shared/kritzel-opacity-slider/kritzel-opacity-slider.js +163 -0
  38. package/dist/collection/components/shared/kritzel-portal/kritzel-portal.js +1 -1
  39. package/dist/collection/components/shared/kritzel-shape-fill/kritzel-shape-fill.css +47 -0
  40. package/dist/collection/components/shared/kritzel-shape-fill/kritzel-shape-fill.js +93 -0
  41. package/dist/collection/components/shared/kritzel-split-button/kritzel-split-button.js +13 -7
  42. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.css +11 -2
  43. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.js +2 -2
  44. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.css +1 -1
  45. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js +6 -4
  46. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js +6 -3
  47. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.css +66 -0
  48. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +153 -50
  49. package/dist/collection/components/ui/kritzel-tool-config/kritzel-tool-config.css +38 -0
  50. package/dist/collection/components/ui/kritzel-tool-config/kritzel-tool-config.js +321 -0
  51. package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.js +3 -2
  52. package/dist/collection/components/ui/kritzel-workspace-manager/kritzel-workspace-manager.js +6 -3
  53. package/dist/collection/configs/default-brush-tool.config.js +2 -52
  54. package/dist/collection/configs/default-line-tool.config.js +2 -26
  55. package/dist/collection/configs/default-shape-tool.config.js +2 -15
  56. package/dist/collection/configs/default-text-tool.config.js +2 -26
  57. package/dist/collection/constants/color-palette.constants.js +30 -0
  58. package/dist/collection/helpers/color.helper.js +31 -0
  59. package/dist/collection/helpers/tool-config.helper.js +65 -0
  60. package/dist/collection/interfaces/tool-config.interface.js +1 -0
  61. package/dist/components/index.d.ts +8 -4
  62. package/dist/components/index.js +1 -1
  63. package/dist/components/kritzel-brush-style.js +1 -1
  64. package/dist/components/kritzel-color-palette.js +1 -1
  65. package/dist/components/kritzel-color.js +1 -1
  66. package/dist/components/kritzel-context-menu.js +1 -1
  67. package/dist/components/kritzel-controls.js +1 -1
  68. package/dist/components/kritzel-cursor-trail.js +1 -1
  69. package/dist/components/kritzel-dropdown.js +1 -1
  70. package/dist/components/kritzel-editor.js +1 -1
  71. package/dist/components/kritzel-engine.js +1 -1
  72. package/dist/components/kritzel-font-family.js +1 -1
  73. package/dist/components/kritzel-font-size.js +1 -1
  74. package/dist/components/kritzel-font.js +1 -1
  75. package/dist/components/kritzel-icon.js +1 -1
  76. package/dist/components/kritzel-line-endings.d.ts +11 -0
  77. package/dist/components/kritzel-line-endings.js +1 -0
  78. package/dist/components/kritzel-menu-item.js +1 -1
  79. package/dist/components/kritzel-menu.js +1 -1
  80. package/dist/components/kritzel-opacity-slider.d.ts +11 -0
  81. package/dist/components/kritzel-opacity-slider.js +1 -0
  82. package/dist/components/kritzel-portal.js +1 -1
  83. package/dist/components/kritzel-shape-fill.d.ts +11 -0
  84. package/dist/components/kritzel-shape-fill.js +1 -0
  85. package/dist/components/kritzel-split-button.js +1 -1
  86. package/dist/components/kritzel-stroke-size.js +1 -1
  87. package/dist/components/kritzel-tool-config.d.ts +11 -0
  88. package/dist/components/kritzel-tool-config.js +1 -0
  89. package/dist/components/kritzel-tooltip.js +1 -1
  90. package/dist/components/kritzel-utility-panel.js +1 -1
  91. package/dist/components/kritzel-workspace-manager.js +1 -1
  92. package/dist/components/p-83YX0-FS.js +1 -0
  93. package/dist/components/p-8iEiCuEN.js +1 -0
  94. package/dist/components/p-9XZbc_qK.js +1 -0
  95. package/dist/components/p-B3P64-gH.js +9 -0
  96. package/dist/components/p-B8QjTqOY.js +1 -0
  97. package/dist/components/p-BF6MdW17.js +1 -0
  98. package/dist/components/p-BVIY50lR.js +1 -0
  99. package/dist/components/p-BbqT9o1F.js +1 -0
  100. package/dist/components/{p-CXzfYQ_u.js → p-BnidlyU0.js} +1 -1
  101. package/dist/components/{p-Bj_Og27M.js → p-BxS4Pdpz.js} +1 -1
  102. package/dist/components/{p-g0N9j_uT.js → p-CCj8nmQH.js} +1 -1
  103. package/dist/components/{p-1z-ds26_.js → p-CLOnpu42.js} +1 -1
  104. package/dist/components/{p-D1tfzpy8.js → p-CSGeDE4f.js} +1 -1
  105. package/dist/components/p-CbuHMNa9.js +1 -0
  106. package/dist/components/p-ClMFs3KI.js +1 -0
  107. package/dist/components/{p-IAqZFssU.js → p-Cnpk2hfo.js} +1 -1
  108. package/dist/components/{p-Cy77SpWt.js → p-Ctv4NAxk.js} +1 -1
  109. package/dist/components/p-CyHZWbkS.js +1 -0
  110. package/dist/components/{p-C4krHoUl.js → p-D8GeJNUv.js} +1 -1
  111. package/dist/components/{p-DB5s1NY4.js → p-DKgqzi2Y.js} +1 -1
  112. package/dist/components/p-DOF5fWDU.js +1 -0
  113. package/dist/components/{p-4FEa4ADy.js → p-DV_h5Jo2.js} +1 -1
  114. package/dist/components/{p-DTezr6w9.js → p-DgCGSL2Q.js} +1 -1
  115. package/dist/components/{p-D5ZsALCP.js → p-wRXL928z.js} +1 -1
  116. package/dist/esm/{default-line-tool.config-CD5sTKH-.js → default-line-tool.config-DLpNl6R9.js} +702 -125
  117. package/dist/esm/{index-BqhmuUH2.js → index-OLdaFN6W.js} +84 -7
  118. package/dist/esm/index.js +2 -2
  119. package/dist/esm/kritzel-brush-style.entry.js +1 -1
  120. package/dist/esm/{kritzel-color_22.entry.js → kritzel-color_24.entry.js} +1009 -890
  121. package/dist/esm/loader.js +3 -3
  122. package/dist/esm/stencil.js +4 -4
  123. package/dist/stencil/index.esm.js +1 -1
  124. package/dist/stencil/{p-09295079.entry.js → p-802bc7cf.entry.js} +1 -1
  125. package/dist/stencil/p-DLpNl6R9.js +1 -0
  126. package/dist/stencil/p-OLdaFN6W.js +2 -0
  127. package/dist/stencil/p-caf30edb.entry.js +9 -0
  128. package/dist/stencil/stencil.esm.js +1 -1
  129. package/dist/types/classes/core/viewport.class.d.ts +6 -0
  130. package/dist/types/classes/managers/anchor.manager.d.ts +1 -1
  131. package/dist/types/classes/objects/line.class.d.ts +2 -0
  132. package/dist/types/classes/objects/shape.class.d.ts +1 -0
  133. package/dist/types/classes/tools/brush-tool.class.d.ts +1 -0
  134. package/dist/types/classes/tools/line-tool.class.d.ts +2 -1
  135. package/dist/types/classes/tools/selection-tool.class.d.ts +22 -0
  136. package/dist/types/classes/tools/shape-tool.class.d.ts +1 -0
  137. package/dist/types/classes/tools/text-tool.class.d.ts +1 -0
  138. package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +2 -0
  139. package/dist/types/components/shared/kritzel-color-palette/kritzel-color-palette.d.ts +1 -0
  140. package/dist/types/components/shared/kritzel-line-endings/kritzel-line-endings.d.ts +23 -0
  141. package/dist/types/components/shared/kritzel-opacity-slider/kritzel-opacity-slider.d.ts +17 -0
  142. package/dist/types/components/shared/kritzel-shape-fill/kritzel-shape-fill.d.ts +10 -0
  143. package/dist/types/components/ui/kritzel-controls/kritzel-controls.d.ts +15 -0
  144. package/dist/types/components/ui/kritzel-tool-config/kritzel-tool-config.d.ts +25 -0
  145. package/dist/types/components.d.ts +235 -82
  146. package/dist/types/constants/color-palette.constants.d.ts +5 -0
  147. package/dist/types/helpers/color.helper.d.ts +9 -0
  148. package/dist/types/helpers/tool-config.helper.d.ts +4 -0
  149. package/dist/types/interfaces/line-options.interface.d.ts +1 -0
  150. package/dist/types/interfaces/path-options.interface.d.ts +1 -0
  151. package/dist/types/interfaces/tool-config.interface.d.ts +26 -0
  152. package/dist/types/stencil-public-runtime.d.ts +29 -0
  153. package/package.json +5 -3
  154. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.css +0 -19
  155. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js +0 -134
  156. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.css +0 -19
  157. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.js +0 -114
  158. package/dist/components/kritzel-control-brush-config.d.ts +0 -11
  159. package/dist/components/kritzel-control-brush-config.js +0 -1
  160. package/dist/components/kritzel-control-text-config.d.ts +0 -11
  161. package/dist/components/kritzel-control-text-config.js +0 -1
  162. package/dist/components/p-B7Fdo5QJ.js +0 -1
  163. package/dist/components/p-BXaWhpO2.js +0 -1
  164. package/dist/components/p-BtuXeItZ.js +0 -1
  165. package/dist/components/p-C-d2IH4v.js +0 -1
  166. package/dist/components/p-C3UriJh7.js +0 -1
  167. package/dist/components/p-CF5L2Gdl.js +0 -1
  168. package/dist/components/p-CeKT_dTd.js +0 -1
  169. package/dist/components/p-Cp15toXH.js +0 -1
  170. package/dist/components/p-D3LRBk2t.js +0 -9
  171. package/dist/components/p-Du1vxHy8.js +0 -1
  172. package/dist/stencil/p-381c0e9c.entry.js +0 -9
  173. package/dist/stencil/p-BqhmuUH2.js +0 -2
  174. package/dist/stencil/p-CD5sTKH-.js +0 -1
  175. package/dist/types/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.d.ts +0 -15
  176. package/dist/types/components/ui/kritzel-control-text-config/kritzel-control-text-config.d.ts +0 -12
@@ -1,9 +0,0 @@
1
- import{p as t,H as n,c as e,h as i,d as s,t as r}from"./p-Bj_Og27M.js";import{K as o}from"./p-D8W6LE-c.js";import{e as h,f as c,g as u,h as a,i as l,S as f,s as d,j as v,E as p,k as w,l as y,T as g,d as b,m,c as A,b as k,K as M,a as x}from"./p-Cp15toXH.js";import{K as S,d as C}from"./p-IAqZFssU.js";import{O as T}from"./p-B0kd2rUI.js";import{K as j}from"./p-l10It7Nm.js";import{K as U,d as E}from"./p-DTezr6w9.js";import{K as $}from"./p-n789Y3S-.js";import{d as _}from"./p-D1tfzpy8.js";var I="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};class O extends h{__class__="KritzelImage";src="";maxWidth=300;maxHeight=300;maxCompressionSize=300;isDebugInfoVisible=!0;constructor(t){super(),this.src=t?.src||"",this.x=t?.x||0,this.y=t?.y||0,this.translateX=t?.translateX||0,this.translateY=t?.translateY||0,this.scale=t?.scale||1}static create(t){const n=new O;return n._core=t,n.id=n.generateId(),n.workspaceId=t.store.state.activeWorkspace.id,n.x=0,n.y=0,n.translateX=0,n.translateY=0,n.scale=n._core.store.state.scale,n.zIndex=t.store.currentZIndex,n}resize(t,n,e,i){if(e<=1||i<=1)return;const s=i/this.height;this.width=this.width*s,this.height=this.height*s,this.translateX=t,this.translateY=n,this._core.store.state.objects.update(this)}calculateScaledDimensions(t){let n=t.width,e=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const i=Math.min(this.maxWidth/t.width,this.maxHeight/t.height);n=t.width*i,e=t.height*i}return{scaledWidth:n,scaledHeight:e}}}class z extends h{__class__="KritzelLine";startX;startY;endX;endY;controlX;controlY;stroke;strokeWidth;scale=1;options;startAnchor;endAnchor;arrows;isVisible=!0;isDebugInfoVisible=!0;isCompleted=!1;_adjustedPoints=null;get d(){return void 0!==this.controlX&&void 0!==this.controlY?`M ${this.startX} ${this.startY} Q ${this.controlX} ${this.controlY} ${this.endX} ${this.endY}`:`M ${this.startX} ${this.startY} L ${this.endX} ${this.endY}`}get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t){super(),this.options=t,this.startX=t?.startX??0,this.startY=t?.startY??0,this.endX=t?.endX??0,this.endY=t?.endY??0,this.controlX=t?.controlX,this.controlY=t?.controlY,this.translateX=t?.translateX??0,this.translateY=t?.translateY??0,this.scale=t?.scale??1,this.strokeWidth=t?.strokeWidth??4,this.stroke=t?.stroke??"#000000",this.startAnchor=t?.startAnchor,this.endAnchor=t?.endAnchor,this.arrows=t?.arrows,this.updateDimensions()}static create(t,n){const e=new z;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.options=n,e.startX=n?.startX??0,e.startY=n?.startY??0,e.endX=n?.endX??0,e.endY=n?.endY??0,e.controlX=n?.controlX,e.controlY=n?.controlY,e.translateX=n?.translateX??0,e.translateY=n?.translateY??0,e.scale=n?.scale??1,e.strokeWidth=n?.strokeWidth??4,e.stroke=n?.stroke??"#000000",e.startAnchor=n?.startAnchor,e.endAnchor=n?.endAnchor,e.arrows=n?.arrows,e.zIndex=t.store.currentZIndex,e.updateDimensions(),e}resize(t,n,e,i){if(e<=1||i<=1)return;const s=e/this.width,r=i/this.height;this.startX=this.startX*s,this.startY=this.startY*r,this.endX=this.endX*s,this.endY=this.endY*r,void 0!==this.controlX&&void 0!==this.controlY&&(this.controlX=this.controlX*s,this.controlY=this.controlY*r);const{minX:o,minY:h,maxX:c,maxY:u}=this.calculateBoundingBox();this.width=c-o,this.height=u-h,this.x=o,this.y=h,this.translateX=t,this.translateY=n,this._adjustedPoints=null,this._core.store.state.objects.update(this),this._core.anchorManager.updateAnchorsForObject(this.id),this.startAnchor&&this._core.anchorManager.updateAnchorsForObject(this.startAnchor.objectId),this.endAnchor&&this._core.anchorManager.updateAnchorsForObject(this.endAnchor.objectId)}rotate(t){this.rotation=t,this._adjustedPoints=null,this._core.store.state.objects.update(this)}move(t,n,e,i){const s=(n-i)/this._core.store.state.scale;this.translateX+=(t-e)/this._core.store.state.scale,this.translateY+=s,this.startAnchor&&this._core.anchorManager.updateAnchorsForObject(this.startAnchor.objectId),this.endAnchor&&this._core.anchorManager.updateAnchorsForObject(this.endAnchor.objectId),this._adjustedPoints=null,this._core.store.state.objects.update(this)}hitTest(t,n){const e=Math.max(this.strokeWidth,20)/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),void 0!==this.controlX&&void 0!==this.controlY)return this.pointToBezierDistance(t,n)<=e;const i=this._adjustedPoints[0],s=this._adjustedPoints[1];return this.pointToLineSegmentDistance(t,n,i[0],i[1],s[0],s[1])<=e}hitTestPolygon(t){const n=this.strokeWidth/this.scale/2;null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const e=[{x:t.bottomLeft.x,y:t.bottomLeft.y},{x:t.bottomRight.x,y:t.bottomRight.y},{x:t.topRight.x,y:t.topRight.y},{x:t.topLeft.x,y:t.topLeft.y}];for(const[t,n]of this._adjustedPoints)if(c.isPointInPolygon({x:t,y:n},e))return!0;for(const t of e)if(this.hitTest(t.x,t.y))return!0;if(void 0!==this.controlX&&void 0!==this.controlY){const t=this._adjustedPoints[0],i=this._adjustedPoints[1],s=this.computeAdjustedControlPoint(),r=20;for(let o=1;o<r;o++){const h=o/r,u=1-h,a=u*u*t[0]+2*u*h*s[0]+h*h*i[0],l=u*u*t[1]+2*u*h*s[1]+h*h*i[1];if(c.isPointInPolygon({x:a,y:l},e))return!0;for(let t=0;t<e.length;t++){const i=e[t],s=e[(t+1)%e.length];if(this.pointToLineSegmentDistance(a,l,i.x,i.y,s.x,s.y)<=n)return!0}}return!1}const i={x:this._adjustedPoints[0][0],y:this._adjustedPoints[0][1]},s={x:this._adjustedPoints[1][0],y:this._adjustedPoints[1][1]};for(let t=0;t<e.length;t++){const r=e[t],o=e[(t+1)%e.length];if(c.intersectLines(i,s,r,o))return!0;const h=this.pointToLineSegmentDistance(r.x,r.y,i.x,i.y,s.x,s.y),u=this.pointToLineSegmentDistance(o.x,o.y,i.x,i.y,s.x,s.y),a=this.pointToLineSegmentDistance(i.x,i.y,r.x,r.y,o.x,o.y),l=this.pointToLineSegmentDistance(s.x,s.y,r.x,r.y,o.x,o.y);if(Math.min(h,u,a,l)<=n)return!0}return!1}updatePosition(t,n){this.translateX=t,this.translateY=n,this._adjustedPoints=null,this._core.store.state.objects.update(this)}updateEndpoint(t,n,e){"start"===t?(this.startX=n,this.startY=e):(this.endX=n,this.endY=e);const i=this.width,s=this.height,{minX:r,minY:o,maxX:h,maxY:c}=this.calculateBoundingBox(),u=r-this.x,a=o-this.y,l=h-r,f=c-o,d=(l-i)/2,v=(f-s)/2;this.x=r,this.y=o,this.width=l,this.height=f;const p=Math.cos(this.rotation),w=Math.sin(this.rotation),y=u+d,g=a+v,b=y*w+g*p-v;this.translateX+=(y*p-g*w-d)/this.scale,this.translateY+=b/this.scale,this._adjustedPoints=null,this._core.store.state.objects.update(this)}updateControlPoint(t,n){this.controlX=t,this.controlY=n;const e=this.width,i=this.height,{minX:s,minY:r,maxX:o,maxY:h}=this.calculateBoundingBox(),c=s-this.x,u=r-this.y,a=o-s,l=h-r,f=(a-e)/2,d=(l-i)/2;this.x=s,this.y=r,this.width=a,this.height=l;const v=Math.cos(this.rotation),p=Math.sin(this.rotation),w=c+f,y=u+d,g=w*p+y*v-d;this.translateX+=(w*v-y*p-f)/this.scale,this.translateY+=g/this.scale,this._adjustedPoints=null,this._core.store.state.objects.update(this)}computeAdjustedPoints(){const t=[[this.startX,this.startY],[this.endX,this.endY]],n=this.rotation,e=Math.cos(n),i=Math.sin(n),s=t.map((t=>t[0])),r=t.map((t=>t[1])),o={x:(Math.min(...s)+Math.max(...s))/2,y:(Math.min(...r)+Math.max(...r))/2},{x:h,y:c}=o;return t.map((([t,n])=>{const s=t-h,r=n-c;return[h+s*e-r*i,c+s*i+r*e]})).map((([t,n])=>[(t-this.x)/this.scale+this.translateX,(n-this.y)/this.scale+this.translateY]))}pointToLineSegmentDistance(t,n,e,i,s,r){const o=s-e,h=r-i,c=o*o+h*h;let u,a,l=-1;0!==c&&(l=((t-e)*o+(n-i)*h)/c),l<0?(u=e,a=i):l>1?(u=s,a=r):(u=e+l*o,a=i+l*h);const f=t-u,d=n-a;return Math.sqrt(f*f+d*d)}pointToBezierDistance(t,n){null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const e=this._adjustedPoints[0],i=this._adjustedPoints[1],s=this.computeAdjustedControlPoint();let r=1/0;for(let o=0;o<=20;o++){const h=o/20,c=1-h,u=t-(c*c*e[0]+2*c*h*s[0]+h*h*i[0]),a=n-(c*c*e[1]+2*c*h*s[1]+h*h*i[1]),l=Math.sqrt(u*u+a*a);l<r&&(r=l)}return r}computeAdjustedControlPoint(){if(void 0===this.controlX||void 0===this.controlY)return[(this.startX+this.endX)/2,(this.startY+this.endY)/2];const t=this.rotation,n=Math.cos(t),e=Math.sin(t),i=[this.startX,this.endX],s=[this.startY,this.endY],r={x:(Math.min(...i)+Math.max(...i))/2,y:(Math.min(...s)+Math.max(...s))/2},{x:o,y:h}=r,c=this.controlX-o,u=this.controlY-h;return[(o+c*n-u*e-this.x)/this.scale+this.translateX,(h+c*e+u*n-this.y)/this.scale+this.translateY]}get rotatedPolygon(){const t=this.padding,{minX:n,minY:e,maxX:i,maxY:s}=z.calculateBoundingBox(this.startX,this.startY,this.endX,this.endY,this.controlX,this.controlY,this.strokeWidth),r=n-this.x+t,o=e-this.y+t,h=i-this.x+t,c=s-this.y+t,u={x:r,y:o},a={x:h,y:o},l={x:h,y:c},f={x:r,y:c},d=this.totalWidth/2,v=this.totalHeight/2,p=this.rotation,w=Math.cos(p),y=Math.sin(p),g=t=>({x:((t.x-d)*w-(t.y-v)*y+d)/this.scale+this.translateX,y:((t.x-d)*y+(t.y-v)*w+v)/this.scale+this.translateY});return{topLeft:g(u),topRight:g(a),bottomRight:g(l),bottomLeft:g(f)}}static calculateBoundingBox(t,n,e,i,s,r,o){let h=Math.min(t,e),c=Math.min(n,i),u=Math.max(t,e),a=Math.max(n,i);if(void 0!==s&&void 0!==r){const o=t-2*s+e;if(0!==o){const n=(t-s)/o;if(n>0&&n<1){const i=(1-n)*(1-n)*t+2*(1-n)*n*s+n*n*e;h=Math.min(h,i),u=Math.max(u,i)}}const l=n-2*r+i;if(0!==l){const t=(n-r)/l;if(t>0&&t<1){const e=(1-t)*(1-t)*n+2*(1-t)*t*r+t*t*i;c=Math.min(c,e),a=Math.max(a,e)}}}const l=o/2;return{minX:h-l,minY:c-l,maxX:u+l,maxY:a+l}}calculateBoundingBox(){return z.calculateBoundingBox(this.startX,this.startY,this.endX,this.endY,this.controlX,this.controlY,this.strokeWidth)}updateDimensions(){const{minX:t,minY:n,maxX:e,maxY:i}=this.calculateBoundingBox();this.width=e-t,this.height=i-n,this.x=t,this.y=n,this.translateX=(this.x+this.translateX)/this.scale,this.translateY=(this.y+this.translateY)/this.scale}get startMarkerId(){return`arrow-start-${this.id}`}get endMarkerId(){return`arrow-end-${this.id}`}getArrowSize(t){const n="start"===t?this.arrows?.start:this.arrows?.end;return n?.size??3*this.strokeWidth}getArrowFill(t){const n="start"===t?this.arrows?.start:this.arrows?.end;return n?.fill??this.stroke}getArrowPath(t="triangle"){switch(t){case"triangle":default:return"M 0 0 L 10 5 L 0 10 z";case"open":return"M 0 0 L 10 5 L 0 10";case"diamond":return"M 0 5 L 5 0 L 10 5 L 5 10 z";case"circle":return"M 5,0 A 5,5 0 1,1 5,10 A 5,5 0 1,1 5,0"}}get hasStartArrow(){return!0===this.arrows?.start?.enabled}get hasEndArrow(){return!0===this.arrows?.end?.enabled}}class P extends h{__class__="KritzelGroup";childIds=[];unchangedChildSnapshots=new Map;snapshotRotation=0;snapshotTranslateX=0;snapshotTranslateY=0;snapshotTotalWidth=0;snapshotTotalHeight=0;snapshotScale=1;get children(){return this.childIds.map((t=>{const n=this._core.store.state.objects.filter((n=>n.id===t));return n.length>0?n[0]:null})).filter((t=>null!==t))}get length(){return this.childIds.length}static create(t){const n=new P;return n._core=t,n.id=n.generateId(),n.workspaceId=t.store.state.activeWorkspace.id,n.scale=t.store.state.scale,n.zIndex=t.store.currentZIndex,n}static createFromObjects(t,n){const e=P.create(t);return n.forEach((t=>{e.childIds.push(t.id)})),e.refreshBoundingBox(),e.captureChildSnapshots(),e}static findParentGroup(t,n){const e=t.store.state.objects.filter((t=>"KritzelGroup"===t.__class__));for(const t of e)if(t.childIds.includes(n))return t;return null}addChild(t){this.childIds.includes(t.id)||(this.childIds.push(t.id),this.refreshBoundingBox(),this.captureChildSnapshots())}removeChild(t){const n=this.childIds.indexOf(t);-1!==n&&(this.childIds.splice(n,1),this.refreshBoundingBox(),this.captureChildSnapshots())}ungroup(){return this.children}finalize(){this.refreshBoundingBox(),this.captureChildSnapshots()}refreshBoundingBox(){if(0===this.children.length)return this.width=0,this.height=0,this.translateX=0,void(this.translateY=0);if(1===this.children.length){const t=this.children[0];return this.translateX=t.boundingBox.x,this.translateY=t.boundingBox.y,this.width=t.boundingBox.width*this.scale,void(this.height=t.boundingBox.height*this.scale)}const t=this.rotation,n=Math.cos(-t),e=Math.sin(-t);let i=1/0,s=-1/0,r=1/0,o=-1/0;this.children.forEach((t=>{const h=t.rotatedPolygon;[h.topLeft,h.topRight,h.bottomRight,h.bottomLeft].forEach((t=>{const h=t.x*n-t.y*e,c=t.x*e+t.y*n;h<i&&(i=h),h>s&&(s=h),c<r&&(r=c),c>o&&(o=c)}))}));const h=o-r;this.width=(s-i-this.padding)*this.scale,this.height=(h-this.padding)*this.scale;const c=(i+s)/2,u=(r+o)/2,a=Math.cos(t),l=Math.sin(t),f=c*l+u*a;this.translateX=c*a-u*l-(this.width/this.scale+2*this.padding)/2,this.translateY=f-(this.height/this.scale+2*this.padding)/2}captureChildSnapshots(){this.unchangedChildSnapshots.clear(),this.snapshotRotation=this.rotation,this.snapshotTranslateX=this.translateX,this.snapshotTranslateY=this.translateY,this.snapshotTotalWidth=this.totalWidth,this.snapshotTotalHeight=this.totalHeight,this.snapshotScale=this.scale||1,this.children.forEach((t=>{this.unchangedChildSnapshots.set(t.id,{id:t.id,translateX:t.translateX,translateY:t.translateY,rotation:t.rotation,width:t.width,height:t.height,totalWidth:t.totalWidth,totalHeight:t.totalHeight,scale:t.scale})}))}move(t,n,e,i){const s=(t-e)/this._core.store.state.scale,r=(n-i)/this._core.store.state.scale;this.translateX+=s,this.translateY+=r,this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.children.forEach((s=>{s.move(t,n,e,i),this._core.anchorManager.updateAnchorsForObject(s.id)}))})),this.unchangedChildSnapshots.forEach((t=>{t.translateX+=s,t.translateY+=r}))}resize(t,n,e,i){const s=e/this.width,r=i/this.height,o=this.translateX+this.totalWidth/2/this.scale,h=this.translateY+this.totalHeight/2/this.scale,c=t+(e+2*this.padding)/2/this.scale,u=n+(i+2*this.padding)/2/this.scale,a=this.rotation,l=Math.cos(-a),f=Math.sin(-a),d=Math.cos(a),v=Math.sin(a);this._core.store.state.objects.transaction((()=>{this.children.forEach((t=>{const n=t.translateX+t.totalWidth/2/t.scale-o,e=t.translateY+t.totalHeight/2/t.scale-h,i=(n*l-e*f)*s,p=(n*f+e*l)*r,w=c+(i*d-p*v),y=u+(i*v+p*d),g=t.rotation-a,b=Math.cos(g),m=Math.sin(g),A=Math.sqrt(Math.pow(s*b,2)+Math.pow(r*m,2)),k=Math.sqrt(Math.pow(s*m,2)+Math.pow(r*b,2)),M=t.width*A,x=t.height*k;t.resize(w-(M+2*t.padding)/2/t.scale,y-(x+2*t.padding)/2/t.scale,M,x),this._core.anchorManager.updateAnchorsForObject(t.id)})),this.refreshBoundingBox(),this.captureChildSnapshots(),this._core.store.state.objects.update(this)}))}rotate(t){this.rotation=t;const n=this.translateX+this.totalWidth/2/this.scale,e=this.translateY+this.totalHeight/2/this.scale,i=t-this.snapshotRotation,s=Math.cos(i),r=Math.sin(i);this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.children.forEach((o=>{const h=this.unchangedChildSnapshots.get(o.id);if(!h)return;const c=this.getOffsetXToCenterFromSnapshot(h),u=this.getOffsetYToCenterFromSnapshot(h),a=r*c+s*u;o.translateX=n+(s*c-r*u)-o.totalWidth/2/o.scale,o.translateY=e+a-o.totalHeight/2/o.scale,o.rotate(1===this.children.length?t:h.rotation+i)}))}))}getOffsetXToCenterFromSnapshot(t){return t.translateX+t.totalWidth/t.scale/2-(this.snapshotTranslateX+this.snapshotTotalWidth/(this.snapshotScale||this.scale||1)/2)}getOffsetYToCenterFromSnapshot(t){return t.translateY+t.totalHeight/t.scale/2-(this.snapshotTranslateY+this.snapshotTotalHeight/(this.snapshotScale||this.scale||1)/2)}hitTest(t,n){return this.children.some((e=>e.hitTest(t,n)))}hitTestPolygon(t){return this.children.some((n=>n.hitTestPolygon(t)))}copy(){const t=P.create(this._core),n=[];return this.children.sort(((t,n)=>t.zIndex-n.zIndex)).forEach((e=>{const i=e.copy();n.push(i),t.childIds.push(i.id)})),t._pendingChildren=n,t.rotation=this.rotation,t.translateX=this.translateX,t.translateY=this.translateY,t.width=this.width,t.height=this.height,t}serialize(){const{_core:t,_elementRef:n,element:e,totalWidth:i,totalHeight:s,unchangedChildSnapshots:r,...o}=this,h=structuredClone(o);return h.unchangedChildSnapshots=Object.fromEntries(this.unchangedChildSnapshots),h}deserialize(t){return super.deserialize(t),t.unchangedChildSnapshots&&(this.unchangedChildSnapshots=new Map(Object.entries(t.unchangedChildSnapshots))),this}update(){this._core.store.state.objects.update(this)}updateWorkspaceId(t){this.workspaceId=t,this.children.forEach((n=>{n.workspaceId=t,n instanceof P&&n.updateWorkspaceId(t)}))}}class D extends h{__class__="KritzelSelectionGroup";objectIds=[];unchangedObjectSnapshots=new Map;snapshotRotation=0;minX;maxX;minY;maxY;get objects(){return this.objectIds.map((t=>{const n=this._core.store.state.objects.filter((n=>n.id===t));return n.length>0?n[0]:null})).filter((t=>null!==t))}get length(){return this.objectIds.length}static create(t){const n=new D;return n._core=t,n.id=n.generateId(),n.workspaceId=t.store.state.activeWorkspace.id,n.scale=t.store.state.scale,n.zIndex=99999,n}addOrRemove(t){const n=this.objectIds.findIndex((n=>n===t.id));-1===n?this.objectIds.push(t.id):this.objectIds.splice(n,1),this.captureUnchangedSnapshots(),this.refreshObjectDimensions()}beginTransform(){this.refreshObjectDimensions(),this.captureUnchangedSnapshots(),this.objects.forEach((t=>{t instanceof P&&t.finalize()}))}deselectAllChildren(){this.objects.forEach((t=>t.isSelected=!1))}updateWorkspaceId(t){this.workspaceId=t,this.objects.forEach((n=>n.workspaceId=t))}updateZIndices(t){this.objects.forEach(((n,e)=>{n.zIndex=t+e}))}updatePosition(t,n){this.objects.forEach((e=>{e.updatePosition(t+(e.translateX-this.translateX),n+(e.translateY-this.translateY))})),this.unchangedObjectSnapshots.forEach((e=>{const i=e.translateY-this.translateY;e.translateX=t+(e.translateX-this.translateX),e.translateY=n+i})),this.translateX=t,this.translateY=n,this._core.store.state.objects.update(this)}captureUnchangedSnapshots(){this.unchangedObjectSnapshots.clear(),this.snapshotRotation=this.rotation,this.objects.forEach((t=>{this.unchangedObjectSnapshots.set(t.id,{id:t.id,translateX:t.translateX,translateY:t.translateY,rotation:t.rotation,width:t.width,height:t.height,totalWidth:t.totalWidth,totalHeight:t.totalHeight,scale:t.scale})}))}serialize(){const{_core:t,_elementRef:n,element:e,totalWidth:i,totalHeight:s,unchangedObjectSnapshots:r,...o}=this,h=structuredClone(o);return e&&"object"==typeof e&&"nodeType"in e&&1===e.nodeType&&(h.element=e.cloneNode(!0)),h.unchangedObjectSnapshots=Object.fromEntries(this.unchangedObjectSnapshots),h}deserialize(t){return super.deserialize(t),t.unchangedObjectSnapshots&&(this.unchangedObjectSnapshots=new Map(Object.entries(t.unchangedObjectSnapshots))),this}update(){this._core.store.state.objects.update(this)}move(t,n,e,i){const s=(t-e)/this._core.store.state.scale,r=(n-i)/this._core.store.state.scale;this.translateX+=s,this.translateY+=r,this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.objects.forEach((s=>{s.move(t,n,e,i),this._core.anchorManager.updateAnchorsForObject(s.id)}))})),this.unchangedObjectSnapshots.forEach((t=>{t.translateX+=s,t.translateY+=r}))}resize(t,n,e,i){const s=e/this.width,r=i/this.height,o=this.translateX+this.totalWidth/2/this.scale,h=this.translateY+this.totalHeight/2/this.scale,c=t+(e+2*this.padding)/2/this.scale,u=n+(i+2*this.padding)/2/this.scale,a=this.rotation,l=Math.cos(-a),f=Math.sin(-a),d=Math.cos(a),v=Math.sin(a);this._core.store.state.objects.transaction((()=>{this.objects.forEach((t=>{const n=t.translateX+t.totalWidth/2/t.scale-o,e=t.translateY+t.totalHeight/2/t.scale-h,i=(n*l-e*f)*s,p=(n*f+e*l)*r,w=c+(i*d-p*v),y=u+(i*v+p*d),g=t.rotation-a,b=Math.cos(g),m=Math.sin(g),A=Math.sqrt(Math.pow(s*b,2)+Math.pow(r*m,2)),k=Math.sqrt(Math.pow(s*m,2)+Math.pow(r*b,2)),M=t.width*A,x=t.height*k;t.resize(w-(M+2*t.padding)/2/t.scale,y-(x+2*t.padding)/2/t.scale,M,x),this._core.anchorManager.updateAnchorsForObject(t.id)})),this.refreshObjectDimensions(),this.captureUnchangedSnapshots(),this._core.store.state.objects.update(this)}))}rotate(t){this.rotation=t;const n=this.translateX+this.totalWidth/2/this.scale,e=this.translateY+this.totalHeight/2/this.scale,i=t-this.snapshotRotation,s=Math.cos(i),r=Math.sin(i);this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.objects.forEach((o=>{const h=this.unchangedObjectSnapshots.get(o.id);if(!h)return;const c=this.getOffsetXToCenterFromSnapshot(h),u=this.getOffsetYToCenterFromSnapshot(h),a=r*c+s*u;o.translateX=n+(s*c-r*u)-o.totalWidth/2/o.scale,o.translateY=e+a-o.totalHeight/2/o.scale,o.rotate(1===this.objects.length?t:h.rotation+i)}))}))}copy(){const t=D.create(this._core);return this.objects.sort(((t,n)=>t.zIndex-n.zIndex)).forEach((n=>{const e=n.copy();t.addOrRemove(e)})),t.captureUnchangedSnapshots(),1===this.objects.length&&(t.rotation=this.objects[0].rotation),t}refreshObjectDimensions(){if(1===this.objects.length){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{const t=this.rotation,n=Math.cos(-t),e=Math.sin(-t);let i=1/0,s=-1/0,r=1/0,o=-1/0;this.objects.forEach((t=>{const h=t.rotatedPolygon;[h.topLeft,h.topRight,h.bottomRight,h.bottomLeft].forEach((t=>{const h=t.x*n-t.y*e,c=t.x*e+t.y*n;h<i&&(i=h),h>s&&(s=h),c<r&&(r=c),c>o&&(o=c)}))}));const h=o-r;this.width=(s-i-this.padding)*this.scale,this.height=(h-this.padding)*this.scale;const c=(i+s)/2,u=(r+o)/2,a=Math.cos(t),l=Math.sin(t),f=c*l+u*a;this.translateX=c*a-u*l-(this.width/this.scale+2*this.padding)/2,this.translateY=f-(this.height/this.scale+2*this.padding)/2}this._core.store.state.objects.update(this)}getOffsetXToCenterFromSnapshot(t){return t.translateX+t.totalWidth/t.scale/2-(this.translateX+this.totalWidth/this.scale/2)}getOffsetYToCenterFromSnapshot(t){return t.translateY+t.totalHeight/t.scale/2-(this.translateY+this.totalHeight/this.scale/2)}hitTest(t,n){if(1===this.objects.length&&"KritzelLine"===this.objects[0].__class__)return this.objects[0].hitTest(t,n);const e=this.rotatedPolygon;return!!c.isPointInPolygon({x:t,y:n},[e.topLeft,e.topRight,e.bottomRight,e.bottomLeft])||this.objects.some((e=>e.hitTest(t,n)))}}class F extends u{color="#000000";size=4;palettes=["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#808080","#C0C0C0","#800000","#008000","#000080","#808000","#800080"];arrows;_startX=0;_startY=0;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&a.isLeftClick(t)){this._core.store.state.isDrawing=!0;const n=t.clientX-this._core.store.offsetX,e=t.clientY-this._core.store.offsetY;this._startX=n,this._startY=e;const i=z.create(this._core,{startX:n,startY:e,endX:n,endY:e,translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,stroke:this.color,strokeWidth:this.size,arrows:this.arrows});i.isCompleted=!1,this._core.store.state.objects.insert(i)}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const n=Math.round(t[0].clientX-this._core.store.offsetX),e=Math.round(t[0].clientY-this._core.store.offsetY);this._core.store.state.isDrawing=!0,this._startX=n,this._startY=e;const i=z.create(this._core,{startX:n,startY:e,endX:n,endY:e,translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,stroke:this.color,strokeWidth:this.size,arrows:this.arrows});i.isCompleted=!1,this._core.store.state.objects.insert(i)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing){const n=this._core.store.currentLine;if(n){const e=z.create(this._core,{startX:this._startX,startY:this._startY,endX:t.clientX-this._core.store.offsetX,endY:t.clientY-this._core.store.offsetY,translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,stroke:this.color,strokeWidth:this.size,arrows:this.arrows});e.id=n.id,e.workspaceId=n.workspaceId,e.zIndex=n.zIndex,e.isCompleted=!1,this._core.store.state.objects.update(e)}}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const n=this._core.store.currentLine;if(n){const e=Math.round(t[0].clientX-this._core.store.offsetX),i=Math.round(t[0].clientY-this._core.store.offsetY),s=z.create(this._core,{startX:this._startX,startY:this._startY,endX:e,endY:i,translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,stroke:this.color,strokeWidth:this.size,arrows:this.arrows});s.id=n.id,s.workspaceId=n.workspaceId,s.zIndex=n.zIndex,s.isCompleted=!1,this._core.store.state.objects.update(s)}}}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing){this._core.store.state.isDrawing=!1;const t=this._core.store.currentLine;t&&(t.isCompleted=!0,this._core.store.state.objects.update(t),this._core.engine.emitObjectsChange(),this.selectLineAndSwitchTool(t))}if("touch"===t.pointerType&&this._core.store.state.isDrawing){this._core.store.state.isDrawing=!1;const t=this._core.store.currentLine;t&&(t.isCompleted=!0,this._core.store.state.objects.update(t),this._core.engine.emitObjectsChange(),this.selectLineAndSwitchTool(t))}}selectLineAndSwitchTool(t){const n=D.create(this._core);n.addOrRemove(t),n.isSelected=!0,n.rotation=t.rotation,this._core.addSelectionGroup(n),this._core.store.setState("activeTool",l.getTool("selection")),this._core.rerender()}}class R extends u{touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&a.isLeftClick(t)&&(this._core.store.state.isErasing=!0),"touch"===t.pointerType&&(this.touchStartTimeout=setTimeout((()=>{1!==this._core.store.state.pointers.size||this._core.store.state.isScaling||(this._core.store.state.isErasing=!0)}),80))}handlePointerMove(t){if("mouse"===t.pointerType&&this._core.store.state.isErasing){const n=this._core.getObjectsFromPointerEvent(t,".object");if(0===n.length)return;const e=this._core.store.state.pointerX,i=this._core.store.state.pointerY;n.forEach((t=>{t.markedForRemoval=t.hitTest(e,i)})),this._core.rerender()}if("touch"===t.pointerType&&1===this._core.store.state.pointers.size&&this._core.store.state.isErasing){const n=this._core.store.state.host?.shadowRoot;if(!n)return;const e=this._core.getObjectsFromPointerEvent(t,".object");if(0===e.length)return;const i=this._core.store.state.pointerX,s=this._core.store.state.pointerY;e.forEach((t=>{t.markedForRemoval=t.hitTest(i,s)})),this._core.rerender()}}handlePointerUp(t){if("mouse"===t.pointerType&&this._core.store.state.isErasing){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)})),t.length>0&&this._core.rerender(),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange()}if("touch"===t.pointerType&&(clearTimeout(this.touchStartTimeout),this._core.store.state.isErasing)){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)})),t.length>0&&this._core.rerender(),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange()}}}function L(t,n){return new Promise((function(e,i){let s;return W(t).then((function(t){try{return s=t,e(new Blob([n.slice(0,2),s,n.slice(2)],{type:"image/jpeg"}))}catch(t){return i(t)}}),i)}))}const W=t=>new Promise(((n,e)=>{const i=new FileReader;i.addEventListener("load",(({target:{result:t}})=>{const i=new DataView(t);let s=0;if(65496!==i.getUint16(s))return e("not a valid JPEG");for(s+=2;;){const r=i.getUint16(s);if(65498===r)break;const o=i.getUint16(s+2);if(65505===r&&1165519206===i.getUint32(s+4)){const r=s+10;let h;switch(i.getUint16(r)){case 18761:h=!0;break;case 19789:h=!1;break;default:return e("TIFF header contains invalid endian")}if(42!==i.getUint16(r+2,h))return e("TIFF header contains invalid version");const c=i.getUint32(r+4,h),u=r+c+2+12*i.getUint16(r+c,h);for(let t=r+c+2;t<u;t+=12)if(274==i.getUint16(t,h)){if(3!==i.getUint16(t+2,h))return e("Orientation data type is invalid");if(1!==i.getUint32(t+4,h))return e("Orientation data count is invalid");i.setUint16(t+8,1,h);break}return n(t.slice(s,s+2+o))}s+=2+o}return n(new Blob)})),i.readAsArrayBuffer(t)}));var B={},Y={get exports(){return B},set exports(t){B=t}};!function(){var t,n,e={};Y.exports=e,e.parse=function(t,n){for(var i=e.bin.readUshort,s=e.bin.readUint,r=0,o={},h=new Uint8Array(t),c=h.length-4;101010256!=s(h,c);)c--;r=c,r+=4;var u=i(h,r+=4);i(h,r+=2);var a=s(h,r+=2),l=s(h,r+=4);r+=4,r=l;for(var f=0;f<u;f++){s(h,r),r+=4,r+=4,r+=4,s(h,r+=4),a=s(h,r+=4);var d=s(h,r+=4),v=i(h,r+=4),p=i(h,r+2),w=i(h,r+4);r+=6;var y=s(h,r+=8);r+=4,r+=v+p+w,e._readLocal(h,y,o,a,d,n)}return o},e._readLocal=function(t,n,i,s,r,o){var h=e.bin.readUshort,c=e.bin.readUint;c(t,n),h(t,n+=4),h(t,n+=2);var u=h(t,n+=2);c(t,n+=2),c(t,n+=4),n+=4;var a=h(t,n+=8),l=h(t,n+=2),f=e.bin.readUTF8(t,n+=2,a);if(n+=a,n+=l,o)i[f]={size:r,csize:s};else{var d=new Uint8Array(t.buffer,n);if(0==u)i[f]=new Uint8Array(d.buffer.slice(n,n+s));else{if(8!=u)throw"unknown compression method: "+u;var v=new Uint8Array(r);e.inflateRaw(d,v),i[f]=v}}},e.inflateRaw=function(t,n){return e.F.inflate(t,n)},e.inflate=function(t,n){return e.inflateRaw(new Uint8Array(t.buffer,t.byteOffset+2,t.length-6),n)},e.deflate=function(t,n){null==n&&(n={level:6});var i=0,s=new Uint8Array(50+Math.floor(1.1*t.length));s[i]=120,s[i+1]=156,i=e.F.deflateRaw(t,s,i+=2,n.level);var r=e.adler(t,0,t.length);return s[i+0]=r>>>24&255,s[i+1]=r>>>16&255,s[i+2]=r>>>8&255,s[i+3]=r>>>0&255,new Uint8Array(s.buffer,0,i+4)},e.deflateRaw=function(t,n){null==n&&(n={level:6});var i=new Uint8Array(50+Math.floor(1.1*t.length)),s=e.F.deflateRaw(t,i,s,n.level);return new Uint8Array(i.buffer,0,s)},e.encode=function(t,n){null==n&&(n=!1);var i=0,s=e.bin.writeUint,r=e.bin.writeUshort,o={};for(var h in t){var c=!e._noNeed(h)&&!n,u=t[h],a=e.crc.crc(u,0,u.length);o[h]={cpr:c,usize:u.length,crc:a,file:c?e.deflateRaw(u):u}}for(var h in o)i+=o[h].file.length+30+46+2*e.bin.sizeUTF8(h);i+=22;var l=new Uint8Array(i),f=0,d=[];for(var h in o){var v=o[h];d.push(f),f=e._writeHeader(l,f,h,v,0)}var p=0,w=f;for(var h in o)v=o[h],d.push(f),f=e._writeHeader(l,f,h,v,1,d[p++]);var y=f-w;return s(l,f,101010256),f+=4,r(l,f+=4,p),r(l,f+=2,p),s(l,f+=2,y),s(l,f+=4,w),f+=4,f+=2,l.buffer},e._noNeed=function(t){var n=t.split(".").pop().toLowerCase();return-1!="png,jpg,jpeg,zip".indexOf(n)},e._writeHeader=function(t,n,i,s,r,o){var h=e.bin.writeUint,c=e.bin.writeUshort,u=s.file;return h(t,n,0==r?67324752:33639248),n+=4,1==r&&(n+=2),c(t,n,20),c(t,n+=2,0),c(t,n+=2,s.cpr?8:0),h(t,n+=2,0),h(t,n+=4,s.crc),h(t,n+=4,u.length),h(t,n+=4,s.usize),c(t,n+=4,e.bin.sizeUTF8(i)),c(t,n+=2,0),n+=2,1==r&&(n+=2,n+=2,h(t,n+=6,o),n+=4),n+=e.bin.writeUTF8(t,n,i),0==r&&(t.set(u,n),n+=u.length),n},e.crc={table:function(){for(var t=new Uint32Array(256),n=0;n<256;n++){for(var e=n,i=0;i<8;i++)1&e?e=3988292384^e>>>1:e>>>=1;t[n]=e}return t}(),update:function(t,n,i,s){for(var r=0;r<s;r++)t=e.crc.table[255&(t^n[i+r])]^t>>>8;return t},crc:function(t,n,i){return 4294967295^e.crc.update(4294967295,t,n,i)}},e.adler=function(t,n,e){for(var i=1,s=0,r=n,o=n+e;r<o;){for(var h=Math.min(r+5552,o);r<h;)s+=i+=t[r++];i%=65521,s%=65521}return s<<16|i},e.bin={readUshort:function(t,n){return t[n]|t[n+1]<<8},writeUshort:function(t,n,e){t[n]=255&e,t[n+1]=e>>8&255},readUint:function(t,n){return 16777216*t[n+3]+(t[n+2]<<16|t[n+1]<<8|t[n])},writeUint:function(t,n,e){t[n]=255&e,t[n+1]=e>>8&255,t[n+2]=e>>16&255,t[n+3]=e>>24&255},readASCII:function(t,n,e){for(var i="",s=0;s<e;s++)i+=String.fromCharCode(t[n+s]);return i},writeASCII:function(t,n,e){for(var i=0;i<e.length;i++)t[n+i]=e.charCodeAt(i)},pad:function(t){return t.length<2?"0"+t:t},readUTF8:function(t,n,i){for(var s,r="",o=0;o<i;o++)r+="%"+e.bin.pad(t[n+o].toString(16));try{s=decodeURIComponent(r)}catch(s){return e.bin.readASCII(t,n,i)}return s},writeUTF8:function(t,n,e){for(var i=e.length,s=0,r=0;r<i;r++){var o=e.charCodeAt(r);if(4294967168&o)if(4294965248&o)if(4294901760&o){if(4292870144&o)throw"e";t[n+s]=240|o>>18,t[n+s+1]=128|o>>12&63,t[n+s+2]=128|o>>6&63,t[n+s+3]=128|63&o,s+=4}else t[n+s]=224|o>>12,t[n+s+1]=128|o>>6&63,t[n+s+2]=128|63&o,s+=3;else t[n+s]=192|o>>6,t[n+s+1]=128|63&o,s+=2;else t[n+s]=o,s++}return s},sizeUTF8:function(t){for(var n=t.length,e=0,i=0;i<n;i++){var s=t.charCodeAt(i);if(4294967168&s)if(4294965248&s)if(4294901760&s){if(4292870144&s)throw"e";e+=4}else e+=3;else e+=2;else e++}return e}},e.F={},e.F.deflateRaw=function(t,n,i,s){var r=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]][s],o=e.F.U,h=e.F._goodIndex,c=e.F._putsE,u=0,a=i<<3,l=0,f=t.length;if(0==s){for(;u<f;)c(n,a,u+(x=Math.min(65535,f-u))==f?1:0),a=e.F._copyExact(t,u,x,n,a+8),u+=x;return a>>>3}var d=o.lits,v=o.strt,p=o.prev,w=0,y=0,g=0,b=0,m=0,A=0;for(f>2&&(v[A=e.F._hash(t,0)]=0),u=0;u<f;u++){if(m=A,u+1<f-2){A=e.F._hash(t,u+1);var k=u+1&32767;p[k]=v[A],v[A]=k}if(l<=u){(w>14e3||y>26697)&&f-u>100&&(l<u&&(d[w]=u-l,w+=2,l=u),a=e.F._writeBlock(u==f-1||l==f?1:0,d,w,b,t,g,u-g,n,a),w=y=b=0,g=u);var M=0;u<f-2&&(M=e.F._bestMatch(t,u,p,m,Math.min(r[2],f-u),r[3]));var x=M>>>16,S=65535&M;if(0!=M){S=65535&M;var C=h(x=M>>>16,o.of0);o.lhst[257+C]++;var T=h(S,o.df0);o.dhst[T]++,b+=o.exb[C]+o.dxb[T],d[w]=x<<23|u-l,d[w+1]=S<<16|C<<8|T,w+=2,l=u+x}else o.lhst[t[u]]++;y++}}for(g==u&&0!=t.length||(l<u&&(d[w]=u-l,w+=2,l=u),a=e.F._writeBlock(1,d,w,b,t,g,u-g,n,a),w=0,y=0,w=y=b=0,g=u);7&a;)a++;return a>>>3},e.F._bestMatch=function(t,n,i,s,r,o){var h=32767&n,c=i[h],u=h-c+32768&32767;if(c==h||s!=e.F._hash(t,n-u))return 0;for(var a=0,l=0,f=Math.min(32767,n);u<=f&&0!=--o&&c!=h;){if(0==a||t[n+a]==t[n+a-u]){var d=e.F._howLong(t,n,u);if(d>a){if(l=u,(a=d)>=r)break;u+2<d&&(d=u+2);for(var v=0,p=0;p<d-2;p++){var w=n-u+p+32768&32767,y=w-i[w]+32768&32767;y>v&&(v=y,c=w)}}}u+=(h=c)-(c=i[h])+32768&32767}return a<<16|l},e.F._howLong=function(t,n,e){if(t[n]!=t[n-e]||t[n+1]!=t[n+1-e]||t[n+2]!=t[n+2-e])return 0;var i=n,s=Math.min(t.length,n+258);for(n+=3;n<s&&t[n]==t[n-e];)n++;return n-i},e.F._hash=function(t,n){return(t[n]<<8|t[n+1])+(t[n+2]<<4)&65535},e.saved=0,e.F._writeBlock=function(t,n,i,s,r,o,h,c,u){var a,l,f,d,v,p,w,y,g,b=e.F.U,m=e.F._putsF,A=e.F._putsE;b.lhst[256]++,l=(a=e.F.getTrees())[0],f=a[1],d=a[2],v=a[3],p=a[4],w=a[5],y=a[6],g=a[7];var k=32+(u+3&7?8-(u+3&7):0)+(h<<3),M=s+e.F.contSize(b.fltree,b.lhst)+e.F.contSize(b.fdtree,b.dhst),x=s+e.F.contSize(b.ltree,b.lhst)+e.F.contSize(b.dtree,b.dhst);x+=14+3*w+e.F.contSize(b.itree,b.ihst)+(2*b.ihst[16]+3*b.ihst[17]+7*b.ihst[18]);for(var S=0;S<286;S++)b.lhst[S]=0;for(S=0;S<30;S++)b.dhst[S]=0;for(S=0;S<19;S++)b.ihst[S]=0;var C=k<M&&k<x?0:M<x?1:2;if(m(c,u,t),m(c,u+1,C),u+=3,0==C){for(;7&u;)u++;u=e.F._copyExact(r,o,h,c,u)}else{var T,j;if(1==C&&(T=b.fltree,j=b.fdtree),2==C){e.F.makeCodes(b.ltree,l),e.F.revCodes(b.ltree,l),e.F.makeCodes(b.dtree,f),e.F.revCodes(b.dtree,f),e.F.makeCodes(b.itree,d),e.F.revCodes(b.itree,d),T=b.ltree,j=b.dtree,A(c,u,v-257),A(c,u+=5,p-1),A(c,u+=5,w-4),u+=4;for(var U=0;U<w;U++)A(c,u+3*U,b.itree[1+(b.ordr[U]<<1)]);u=e.F._codeTiny(y,b.itree,c,u+=3*w),u=e.F._codeTiny(g,b.itree,c,u)}for(var E=o,$=0;$<i;$+=2){for(var _=n[$],I=_>>>23,O=E+(8388607&_);E<O;)u=e.F._writeLit(r[E++],T,c,u);if(0!=I){var z=n[$+1],P=z>>16,D=z>>8&255,F=255&z;A(c,u=e.F._writeLit(257+D,T,c,u),I-b.of0[D]),m(c,u=e.F._writeLit(F,j,c,u+=b.exb[D]),P-b.df0[F]),u+=b.dxb[F],E+=I}}u=e.F._writeLit(256,T,c,u)}return u},e.F._copyExact=function(t,n,e,i,s){var r=s>>>3;return i[r]=e,i[r+1]=e>>>8,i[r+2]=255-i[r],i[r+3]=255-i[r+1],r+=4,i.set(new Uint8Array(t.buffer,n,e),r),s+(e+4<<3)},e.F.getTrees=function(){for(var t=e.F.U,n=e.F._hufTree(t.lhst,t.ltree,15),i=e.F._hufTree(t.dhst,t.dtree,15),s=[],r=e.F._lenCodes(t.ltree,s),o=[],h=e.F._lenCodes(t.dtree,o),c=0;c<s.length;c+=2)t.ihst[s[c]]++;for(c=0;c<o.length;c+=2)t.ihst[o[c]]++;for(var u=e.F._hufTree(t.ihst,t.itree,7),a=19;a>4&&0==t.itree[1+(t.ordr[a-1]<<1)];)a--;return[n,i,u,r,h,a,s,o]},e.F.getSecond=function(t){for(var n=[],e=0;e<t.length;e+=2)n.push(t[e+1]);return n},e.F.nonZero=function(t){for(var n="",e=0;e<t.length;e+=2)0!=t[e+1]&&(n+=(e>>1)+",");return n},e.F.contSize=function(t,n){for(var e=0,i=0;i<n.length;i++)e+=n[i]*t[1+(i<<1)];return e},e.F._codeTiny=function(t,n,i,s){for(var r=0;r<t.length;r+=2){var o=t[r],h=t[r+1];s=e.F._writeLit(o,n,i,s);var c=16==o?2:17==o?3:7;o>15&&(e.F._putsE(i,s,h,c),s+=c)}return s},e.F._lenCodes=function(t,n){for(var e=t.length;2!=e&&0==t[e-1];)e-=2;for(var i=0;i<e;i+=2){var s=t[i+1],r=i+3<e?t[i+3]:-1,o=i+5<e?t[i+5]:-1,h=0==i?-1:t[i-1];if(0==s&&r==s&&o==s){for(var c=i+5;c+2<e&&t[c+2]==s;)c+=2;(u=Math.min(c+1-i>>>1,138))<11?n.push(17,u-3):n.push(18,u-11),i+=2*u-2}else if(s==h&&r==s&&o==s){for(c=i+5;c+2<e&&t[c+2]==s;)c+=2;var u=Math.min(c+1-i>>>1,6);n.push(16,u-3),i+=2*u-2}else n.push(s,0)}return e>>>1},e.F._hufTree=function(t,n,i){var s=[],r=t.length,o=n.length,h=0;for(h=0;h<o;h+=2)n[h]=0,n[h+1]=0;for(h=0;h<r;h++)0!=t[h]&&s.push({lit:h,f:t[h]});var c=s.length,u=s.slice(0);if(0==c)return 0;if(1==c){var a=s[0].lit;return u=0==a?1:0,n[1+(a<<1)]=1,n[1+(u<<1)]=1,1}s.sort((function(t,n){return t.f-n.f}));var l=s[0],f=s[1],d=0,v=1,p=2;for(s[0]={lit:-1,f:l.f+f.f,l,r:f,d:0};v!=c-1;)l=d!=v&&(p==c||s[d].f<s[p].f)?s[d++]:s[p++],f=d!=v&&(p==c||s[d].f<s[p].f)?s[d++]:s[p++],s[v++]={lit:-1,f:l.f+f.f,l,r:f};var w=e.F.setDepth(s[v-1],0);for(w>i&&(e.F.restrictDepth(u,i,w),w=i),h=0;h<c;h++)n[1+(u[h].lit<<1)]=u[h].d;return w},e.F.setDepth=function(t,n){return-1!=t.lit?(t.d=n,n):Math.max(e.F.setDepth(t.l,n+1),e.F.setDepth(t.r,n+1))},e.F.restrictDepth=function(t,n,e){var i=0,s=1<<e-n,r=0;for(t.sort((function(t,n){return n.d==t.d?t.f-n.f:n.d-t.d})),i=0;i<t.length&&t[i].d>n;i++){var o=t[i].d;t[i].d=n,r+=s-(1<<e-o)}for(r>>>=e-n;r>0;)(o=t[i].d)<n?(t[i].d++,r-=1<<n-o-1):i++;for(;i>=0;i--)t[i].d==n&&r<0&&(t[i].d--,r++);0!=r&&console.log("debt left")},e.F._goodIndex=function(t,n){var e=0;return n[16|e]<=t&&(e|=16),n[8|e]<=t&&(e|=8),n[4|e]<=t&&(e|=4),n[2|e]<=t&&(e|=2),n[1|e]<=t&&(e|=1),e},e.F._writeLit=function(t,n,i,s){return e.F._putsF(i,s,n[t<<1]),s+n[1+(t<<1)]},e.F.inflate=function(t,n){var i=Uint8Array;if(3==t[0]&&0==t[1])return n||new i(0);var s=e.F,r=s._bitsF,o=s._bitsE,h=s._decodeTiny,c=s.makeCodes,u=s.codes2map,a=s._get17,l=s.U,f=null==n;f&&(n=new i(t.length>>>2<<3));for(var d,v,p=0,w=0,y=0,g=0,b=0,m=0,A=0,k=0,M=0;0==p;)if(p=r(t,M,1),w=r(t,M+1,2),M+=3,0!=w){if(f&&(n=e.F._check(n,k+(1<<17))),1==w&&(d=l.flmap,v=l.fdmap,m=511,A=31),2==w){y=o(t,M,5)+257,g=o(t,M+5,5)+1,b=o(t,M+10,4)+4,M+=14;for(var x=0;x<38;x+=2)l.itree[x]=0,l.itree[x+1]=0;var S=1;for(x=0;x<b;x++){var C=o(t,M+3*x,3);l.itree[1+(l.ordr[x]<<1)]=C,C>S&&(S=C)}M+=3*b,c(l.itree,S),u(l.itree,S,l.imap),d=l.lmap,v=l.dmap,M=h(l.imap,(1<<S)-1,y+g,t,M,l.ttree);var T=s._copyOut(l.ttree,0,y,l.ltree);m=(1<<T)-1;var j=s._copyOut(l.ttree,y,g,l.dtree);A=(1<<j)-1,c(l.ltree,T),u(l.ltree,T,d),c(l.dtree,j),u(l.dtree,j,v)}for(;;){var U=d[a(t,M)&m];M+=15&U;var E=U>>>4;if(E>>>8==0)n[k++]=E;else{if(256==E)break;var $=k+E-254;if(E>264){var _=l.ldef[E-257];$=k+(_>>>3)+o(t,M,7&_),M+=7&_}var I=v[a(t,M)&A],O=l.ddef[I>>>4],z=(O>>>4)+r(t,M+=15&I,15&O);for(M+=15&O,f&&(n=e.F._check(n,k+(1<<17)));k<$;)n[k]=n[k++-z],n[k]=n[k++-z],n[k]=n[k++-z],n[k]=n[k++-z];k=$}}}else{7&M&&(M+=8-(7&M));var P=4+(M>>>3),D=t[P-4]|t[P-3]<<8;f&&(n=e.F._check(n,k+D)),n.set(new i(t.buffer,t.byteOffset+P,D),k),M=P+D<<3,k+=D}return n.length==k?n:n.slice(0,k)},e.F._check=function(t,n){var e=t.length;if(n<=e)return t;var i=new Uint8Array(Math.max(e<<1,n));return i.set(t,0),i},e.F._decodeTiny=function(t,n,i,s,r,o){for(var h=e.F._bitsE,c=e.F._get17,u=0;u<i;){var a=t[c(s,r)&n];r+=15&a;var l=a>>>4;if(l<=15)o[u]=l,u++;else{var f=0,d=0;16==l?(d=3+h(s,r,2),r+=2,f=o[u-1]):17==l?(d=3+h(s,r,3),r+=3):18==l&&(d=11+h(s,r,7),r+=7);for(var v=u+d;u<v;)o[u]=f,u++}}return r},e.F._copyOut=function(t,n,e,i){for(var s=0,r=0,o=i.length>>>1;r<e;){var h=t[r+n];i[r<<1]=0,i[1+(r<<1)]=h,h>s&&(s=h),r++}for(;r<o;)i[r<<1]=0,i[1+(r<<1)]=0,r++;return s},e.F.makeCodes=function(t,n){for(var i,s,r,o,h=e.F.U,c=t.length,u=h.bl_count,a=0;a<=n;a++)u[a]=0;for(a=1;a<c;a+=2)u[t[a]]++;var l=h.next_code;for(i=0,u[0]=0,s=1;s<=n;s++)l[s]=i=i+u[s-1]<<1;for(r=0;r<c;r+=2)0!=(o=t[r+1])&&(t[r]=l[o],l[o]++)},e.F.codes2map=function(t,n,i){for(var s=t.length,r=e.F.U.rev15,o=0;o<s;o+=2)if(0!=t[o+1])for(var h=t[o+1],c=o>>1<<4|h,u=n-h,a=t[o]<<u,l=a+(1<<u);a!=l;)i[r[a]>>>15-n]=c,a++},e.F.revCodes=function(t,n){for(var i=e.F.U.rev15,s=15-n,r=0;r<t.length;r+=2)t[r]=i[t[r]<<n-t[r+1]]>>>s},e.F._putsE=function(t,n,e){var i=n>>>3;t[i]|=e<<=7&n,t[i+1]|=e>>>8},e.F._putsF=function(t,n,e){var i=n>>>3;t[i]|=e<<=7&n,t[i+1]|=e>>>8,t[i+2]|=e>>>16},e.F._bitsE=function(t,n,e){return(t[n>>>3]|t[1+(n>>>3)]<<8)>>>(7&n)&(1<<e)-1},e.F._bitsF=function(t,n,e){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16)>>>(7&n)&(1<<e)-1},e.F._get17=function(t,n){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16)>>>(7&n)},e.F._get25=function(t,n){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16|t[3+(n>>>3)]<<24)>>>(7&n)},e.F.U=(t=Uint16Array,n=Uint32Array,{next_code:new t(16),bl_count:new t(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 t(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 n(32),flmap:new t(512),fltree:[],fdmap:new t(32),fdtree:[],lmap:new t(32768),ltree:[],ttree:[],dmap:new t(32768),dtree:[],imap:new t(512),itree:[],rev15:new t(32768),lhst:new n(286),dhst:new n(30),ihst:new n(19),lits:new n(15e3),strt:new t(65536),prev:new t(32768)}),function(){for(var t=e.F.U,n=0;n<32768;n++){var i=n;i=(4278255360&(i=(4042322160&(i=(3435973836&(i=(2863311530&i)>>>1|(1431655765&i)<<1))>>>2|(858993459&i)<<2))>>>4|(252645135&i)<<4))>>>8|(16711935&i)<<8,t.rev15[n]=(i>>>16|i<<16)>>>17}function s(t,n,e){for(;0!=n--;)t.push(0,e)}for(n=0;n<32;n++)t.ldef[n]=t.of0[n]<<3|t.exb[n],t.ddef[n]=t.df0[n]<<4|t.dxb[n];s(t.fltree,144,8),s(t.fltree,112,9),s(t.fltree,24,7),s(t.fltree,8,8),e.F.makeCodes(t.fltree,9),e.F.codes2map(t.fltree,9,t.flmap),e.F.revCodes(t.fltree,9),s(t.fdtree,32,5),e.F.makeCodes(t.fdtree,5),e.F.codes2map(t.fdtree,5,t.fdmap),e.F.revCodes(t.fdtree,5),s(t.itree,19,0),s(t.ltree,286,0),s(t.dtree,30,0),s(t.ttree,320,0)}()}();var X=function(t,n){return n.forEach((function(n){n&&"string"!=typeof n&&!Array.isArray(n)&&Object.keys(n).forEach((function(e){if("default"!==e&&!(e in t)){var i=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return n[e]}})}}))})),Object.freeze(t)}({__proto__:null,default:B},[B]);const H=function(){var t={nextZero(t,n){for(;0!=t[n];)n++;return n},readUshort:(t,n)=>t[n]<<8|t[n+1],writeUshort(t,n,e){t[n]=e>>8&255,t[n+1]=255&e},readUint:(t,n)=>16777216*t[n]+(t[n+1]<<16|t[n+2]<<8|t[n+3]),writeUint(t,n,e){t[n]=e>>24&255,t[n+1]=e>>16&255,t[n+2]=e>>8&255,t[n+3]=255&e},readASCII(t,n,e){let i="";for(let s=0;s<e;s++)i+=String.fromCharCode(t[n+s]);return i},writeASCII(t,n,e){for(let i=0;i<e.length;i++)t[n+i]=e.charCodeAt(i)},readBytes(t,n,e){const i=[];for(let s=0;s<e;s++)i.push(t[n+s]);return i},pad:t=>t.length<2?`0${t}`:t,readUTF8(n,e,i){let s,r="";for(let s=0;s<i;s++)r+=`%${t.pad(n[e+s].toString(16))}`;try{s=decodeURIComponent(r)}catch(s){return t.readASCII(n,e,i)}return s}};function n(n,e,i,s){const o=e*i,h=r(s),c=Math.ceil(e*h/8),u=new Uint8Array(4*o),a=new Uint32Array(u.buffer),{ctype:l}=s,{depth:f}=s,d=t.readUshort;if(6==l){const t=o<<2;if(8==f)for(var v=0;v<t;v+=4)u[v]=n[v],u[v+1]=n[v+1],u[v+2]=n[v+2],u[v+3]=n[v+3];if(16==f)for(v=0;v<t;v++)u[v]=n[v<<1]}else if(2==l){const t=s.tabs.tRNS;if(null==t){if(8==f)for(v=0;v<o;v++){var p=3*v;a[v]=255<<24|n[p+2]<<16|n[p+1]<<8|n[p]}if(16==f)for(v=0;v<o;v++)a[v]=255<<24|n[4+(p=6*v)]<<16|n[p+2]<<8|n[p]}else{var w=t[0];const e=t[1],i=t[2];if(8==f)for(v=0;v<o;v++){var y=v<<2;a[v]=255<<24|n[2+(p=3*v)]<<16|n[p+1]<<8|n[p],n[p]==w&&n[p+1]==e&&n[p+2]==i&&(u[y+3]=0)}if(16==f)for(v=0;v<o;v++)y=v<<2,a[v]=255<<24|n[4+(p=6*v)]<<16|n[p+2]<<8|n[p],d(n,p)==w&&d(n,p+2)==e&&d(n,p+4)==i&&(u[y+3]=0)}}else if(3==l){const t=s.tabs.PLTE,r=s.tabs.tRNS,h=r?r.length:0;if(1==f)for(var g=0;g<i;g++){var b=g*c,m=g*e;for(v=0;v<e;v++){var A=3*(k=n[b+(v>>3)]>>7-(7&v)&1);u[y=m+v<<2]=t[A],u[y+1]=t[A+1],u[y+2]=t[A+2],u[y+3]=k<h?r[k]:255}}if(2==f)for(g=0;g<i;g++)for(b=g*c,m=g*e,v=0;v<e;v++)A=3*(k=n[b+(v>>2)]>>6-((3&v)<<1)&3),u[y=m+v<<2]=t[A],u[y+1]=t[A+1],u[y+2]=t[A+2],u[y+3]=k<h?r[k]:255;if(4==f)for(g=0;g<i;g++)for(b=g*c,m=g*e,v=0;v<e;v++)A=3*(k=n[b+(v>>1)]>>4-((1&v)<<2)&15),u[y=m+v<<2]=t[A],u[y+1]=t[A+1],u[y+2]=t[A+2],u[y+3]=k<h?r[k]:255;if(8==f)for(v=0;v<o;v++){var k;A=3*(k=n[v]),u[y=v<<2]=t[A],u[y+1]=t[A+1],u[y+2]=t[A+2],u[y+3]=k<h?r[k]:255}}else if(4==l){if(8==f)for(v=0;v<o;v++){var M=n[x=v<<1];u[y=v<<2]=M,u[y+1]=M,u[y+2]=M,u[y+3]=n[x+1]}if(16==f)for(v=0;v<o;v++){var x;M=n[x=v<<2],u[y=v<<2]=M,u[y+1]=M,u[y+2]=M,u[y+3]=n[x+2]}}else if(0==l)for(w=s.tabs.tRNS?s.tabs.tRNS:-1,g=0;g<i;g++){const t=g*c,i=g*e;if(1==f)for(var S=0;S<e;S++){var C=(M=255*(n[t+(S>>>3)]>>>7-(7&S)&1))==255*w?0:255;a[i+S]=C<<24|M<<16|M<<8|M}else if(2==f)for(S=0;S<e;S++)C=(M=85*(n[t+(S>>>2)]>>>6-((3&S)<<1)&3))==85*w?0:255,a[i+S]=C<<24|M<<16|M<<8|M;else if(4==f)for(S=0;S<e;S++)C=(M=17*(n[t+(S>>>1)]>>>4-((1&S)<<2)&15))==17*w?0:255,a[i+S]=C<<24|M<<16|M<<8|M;else if(8==f)for(S=0;S<e;S++)C=(M=n[t+S])==w?0:255,a[i+S]=C<<24|M<<16|M<<8|M;else if(16==f)for(S=0;S<e;S++)M=n[t+(S<<1)],C=d(n,t+(S<<1))==w?0:255,a[i+S]=C<<24|M<<16|M<<8|M}return u}function e(t,n,e,h){const c=r(t),u=Math.ceil(e*c/8),a=new Uint8Array((u+1+t.interlace)*h);return n=t.tabs.CgBI?s(n,a):i(n,a),0==t.interlace?n=o(n,t,0,e,h):1==t.interlace&&(n=function(t,n){const e=n.width,i=n.height,s=r(n),h=s>>3,c=Math.ceil(e*s/8),u=new Uint8Array(i*c);let a=0;const l=[0,0,4,0,2,0,1],f=[0,4,0,2,0,1,0],d=[8,8,8,4,4,2,2],v=[8,8,4,4,2,2,1];let p=0;for(;p<7;){const r=d[p],y=v[p];let g=0,b=0,m=l[p];for(;m<i;)m+=r,b++;let A=f[p];for(;A<e;)A+=y,g++;const k=Math.ceil(g*s/8);o(t,n,a,g,b);let M=0,x=l[p];for(;x<i;){let n=f[p],i=a+M*k<<3;for(;n<e;){var w;if(1==s&&(w=(w=t[i>>3])>>7-(7&i)&1,u[x*c+(n>>3)]|=w<<7-(7&n)),2==s&&(w=(w=t[i>>3])>>6-(7&i)&3,u[x*c+(n>>2)]|=w<<6-((3&n)<<1)),4==s&&(w=(w=t[i>>3])>>4-(7&i)&15,u[x*c+(n>>1)]|=w<<4-((1&n)<<2)),s>=8){const e=x*c+n*h;for(let n=0;n<h;n++)u[e+n]=t[(i>>3)+n]}i+=s,n+=y}M++,x+=r}g*b!=0&&(a+=b*(1+k)),p+=1}return u}(n,t)),n}function i(t,n){return s(new Uint8Array(t.buffer,2,t.length-6),n)}var s=function(){const t={H:{}};return t.H.N=function(n,e){const i=Uint8Array;let s,r,o=0,h=0,c=0,u=0,a=0,l=0,f=0,d=0,v=0;if(3==n[0]&&0==n[1])return e||new i(0);const p=t.H,w=p.b,y=p.e,g=p.R,b=p.n,m=p.A,A=p.Z,k=p.m,M=null==e;for(M&&(e=new i(n.length>>>2<<5));0==o;)if(o=w(n,v,1),h=w(n,v+1,2),v+=3,0!=h){if(M&&(e=t.H.W(e,d+(1<<17))),1==h&&(s=k.J,r=k.h,l=511,f=31),2==h){c=y(n,v,5)+257,u=y(n,v+5,5)+1,a=y(n,v+10,4)+4,v+=14;let t=1;for(var x=0;x<38;x+=2)k.Q[x]=0,k.Q[x+1]=0;for(x=0;x<a;x++){const e=y(n,v+3*x,3);k.Q[1+(k.X[x]<<1)]=e,e>t&&(t=e)}v+=3*a,b(k.Q,t),m(k.Q,t,k.u),s=k.w,r=k.d,v=g(k.u,(1<<t)-1,c+u,n,v,k.v);const e=p.V(k.v,0,c,k.C);l=(1<<e)-1;const i=p.V(k.v,c,u,k.D);f=(1<<i)-1,b(k.C,e),m(k.C,e,s),b(k.D,i),m(k.D,i,r)}for(;;){const t=s[A(n,v)&l];v+=15&t;const i=t>>>4;if(i>>>8==0)e[d++]=i;else{if(256==i)break;{let t=d+i-254;if(i>264){const e=k.q[i-257];t=d+(e>>>3)+y(n,v,7&e),v+=7&e}const s=r[A(n,v)&f];v+=15&s;const o=k.c[s>>>4],h=(o>>>4)+w(n,v,15&o);for(v+=15&o;d<t;)e[d]=e[d++-h],e[d]=e[d++-h],e[d]=e[d++-h],e[d]=e[d++-h];d=t}}}}else{7&v&&(v+=8-(7&v));const s=4+(v>>>3),r=n[s-4]|n[s-3]<<8;M&&(e=t.H.W(e,d+r)),e.set(new i(n.buffer,n.byteOffset+s,r),d),v=s+r<<3,d+=r}return e.length==d?e:e.slice(0,d)},t.H.W=function(t,n){const e=t.length;if(n<=e)return t;const i=new Uint8Array(e<<1);return i.set(t,0),i},t.H.R=function(n,e,i,s,r,o){const h=t.H.e,c=t.H.Z;let u=0;for(;u<i;){const t=n[c(s,r)&e];r+=15&t;const i=t>>>4;if(i<=15)o[u]=i,u++;else{let t=0,n=0;16==i?(n=3+h(s,r,2),r+=2,t=o[u-1]):17==i?(n=3+h(s,r,3),r+=3):18==i&&(n=11+h(s,r,7),r+=7);const e=u+n;for(;u<e;)o[u]=t,u++}}return r},t.H.V=function(t,n,e,i){let s=0,r=0;const o=i.length>>>1;for(;r<e;){const e=t[r+n];i[r<<1]=0,i[1+(r<<1)]=e,e>s&&(s=e),r++}for(;r<o;)i[r<<1]=0,i[1+(r<<1)]=0,r++;return s},t.H.n=function(n,e){const i=t.H.m,s=n.length;let r,o,h,c;const u=i.j;for(var a=0;a<=e;a++)u[a]=0;for(a=1;a<s;a+=2)u[n[a]]++;const l=i.K;for(r=0,u[0]=0,o=1;o<=e;o++)r=r+u[o-1]<<1,l[o]=r;for(h=0;h<s;h+=2)c=n[h+1],0!=c&&(n[h]=l[c],l[c]++)},t.H.A=function(n,e,i){const s=n.length,r=t.H.m.r;for(let t=0;t<s;t+=2)if(0!=n[t+1]){const s=n[t+1],o=t>>1<<4|s,h=e-s;let c=n[t]<<h;const u=c+(1<<h);for(;c!=u;)i[r[c]>>>15-e]=o,c++}},t.H.l=function(n,e){const i=t.H.m.r,s=15-e;for(let t=0;t<n.length;t+=2)n[t]=i[n[t]<<e-n[t+1]]>>>s},t.H.M=function(t,n,e){const i=n>>>3;t[i]|=e<<=7&n,t[i+1]|=e>>>8},t.H.I=function(t,n,e){const i=n>>>3;t[i]|=e<<=7&n,t[i+1]|=e>>>8,t[i+2]|=e>>>16},t.H.e=function(t,n,e){return(t[n>>>3]|t[1+(n>>>3)]<<8)>>>(7&n)&(1<<e)-1},t.H.b=function(t,n,e){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16)>>>(7&n)&(1<<e)-1},t.H.Z=function(t,n){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16)>>>(7&n)},t.H.i=function(t,n){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16|t[3+(n>>>3)]<<24)>>>(7&n)},t.H.m=function(){const t=Uint16Array,n=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 n(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 n(286),Y:new n(30),a:new n(19),t:new n(15e3),k:new t(65536),g:new t(32768)}}(),function(){const n=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,n.r[e]=(t>>>16|t<<16)>>>17}function i(t,n,e){for(;0!=n--;)t.push(0,e)}for(e=0;e<32;e++)n.q[e]=n.S[e]<<3|n.T[e],n.c[e]=n.p[e]<<4|n.z[e];i(n._,144,8),i(n._,112,9),i(n._,24,7),i(n._,8,8),t.H.n(n._,9),t.H.A(n._,9,n.J),t.H.l(n._,9),i(n.$,32,5),t.H.n(n.$,5),t.H.A(n.$,5,n.h),t.H.l(n.$,5),i(n.Q,19,0),i(n.C,286,0),i(n.D,30,0),i(n.v,320,0)}(),t.H.N}();function r(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function o(t,n,e,i,s){let o=r(n);const c=Math.ceil(i*o/8);let u,a;o=Math.ceil(o/8);let l=t[e],f=0;if(l>1&&(t[e]=[0,0,1][l-2]),3==l)for(f=o;f<c;f++)t[f+1]=t[f+1]+(t[f+1-o]>>>1)&255;for(let n=0;n<s;n++)if(u=e+n*c,a=u+n+1,l=t[a-1],f=0,0==l)for(;f<c;f++)t[u+f]=t[a+f];else if(1==l){for(;f<o;f++)t[u+f]=t[a+f];for(;f<c;f++)t[u+f]=t[a+f]+t[u+f-o]}else if(2==l)for(;f<c;f++)t[u+f]=t[a+f]+t[u+f-c];else if(3==l){for(;f<o;f++)t[u+f]=t[a+f]+(t[u+f-c]>>>1);for(;f<c;f++)t[u+f]=t[a+f]+(t[u+f-c]+t[u+f-o]>>>1)}else{for(;f<o;f++)t[u+f]=t[a+f]+h(0,t[u+f-c],0);for(;f<c;f++)t[u+f]=t[a+f]+h(t[u+f-o],t[u+f-c],t[u+f-o-c])}return t}function h(t,n,e){const i=t+n-e,s=i-t,r=i-n,o=i-e;return s*s<=r*r&&s*s<=o*o?t:r*r<=o*o?n:e}function c(n,e,i){i.width=t.readUint(n,e),i.height=t.readUint(n,e+=4),i.depth=n[e+=4],e++,i.ctype=n[e],e++,i.compress=n[e],e++,i.filter=n[e],e++,i.interlace=n[e],e++}function u(t,n,e,i,s,r,o,h,c){const u=Math.min(n,s),a=Math.min(e,r);let l=0,f=0;for(let e=0;e<a;e++)for(let r=0;r<u;r++)if(o>=0&&h>=0?(l=e*n+r<<2,f=(h+e)*s+o+r<<2):(l=(-h+e)*n-o+r<<2,f=e*s+r<<2),0==c)i[f]=t[l],i[f+1]=t[l+1],i[f+2]=t[l+2],i[f+3]=t[l+3];else if(1==c){var d=t[l+3]*(1/255),v=t[l]*d,p=t[l+1]*d,w=t[l+2]*d,y=i[f+3]*(1/255),g=i[f]*y,b=i[f+1]*y,m=i[f+2]*y;const n=1-d,e=d+y*n,s=0==e?0:1/e;i[f+3]=255*e,i[f+0]=(v+g*n)*s,i[f+1]=(p+b*n)*s,i[f+2]=(w+m*n)*s}else if(2==c)v=t[l],p=t[l+1],w=t[l+2],g=i[f],b=i[f+1],m=i[f+2],(d=t[l+3])==(y=i[f+3])&&v==g&&p==b&&w==m?(i[f]=0,i[f+1]=0,i[f+2]=0,i[f+3]=0):(i[f]=v,i[f+1]=p,i[f+2]=w,i[f+3]=d);else if(3==c){if(v=t[l],p=t[l+1],w=t[l+2],g=i[f],b=i[f+1],m=i[f+2],(d=t[l+3])==(y=i[f+3])&&v==g&&p==b&&w==m)continue;if(d<220&&y>20)return!1}return!0}return{decode:function(n){const r=new Uint8Array(n);let o=8;const h=t,u=h.readUshort,a=h.readUint,l={tabs:{},frames:[]},f=new Uint8Array(r.length);let d,v=0,p=0;const w=[137,80,78,71,13,10,26,10];for(var y=0;y<8;y++)if(r[y]!=w[y])throw"The input is not a PNG file!";for(;o<r.length;){const t=h.readUint(r,o);o+=4;const n=h.readASCII(r,o,4);if(o+=4,"IHDR"==n)c(r,o,l);else if("iCCP"==n){for(var g=o;0!=r[g];)g++;h.readASCII(r,o,g-o);const e=r.slice(g+2,o+t);let c=null;try{c=i(e)}catch(t){c=s(e)}l.tabs[n]=c}else if("CgBI"==n)l.tabs[n]=r.slice(o,o+4);else if("IDAT"==n){for(y=0;y<t;y++)f[v+y]=r[o+y];v+=t}else if("acTL"==n)l.tabs[n]={num_frames:a(r,o),num_plays:a(r,o+4)},d=new Uint8Array(r.length);else if("fcTL"==n){0!=p&&((x=l.frames[l.frames.length-1]).data=e(l,d.slice(0,p),x.rect.width,x.rect.height),p=0);const t={x:a(r,o+12),y:a(r,o+16),width:a(r,o+4),height:a(r,o+8)};let n=u(r,o+22);n=u(r,o+20)/(0==n?100:n);const i={rect:t,delay:Math.round(1e3*n),dispose:r[o+24],blend:r[o+25]};l.frames.push(i)}else if("fdAT"==n){for(y=0;y<t-4;y++)d[p+y]=r[o+y+4];p+=t-4}else if("pHYs"==n)l.tabs[n]=[h.readUint(r,o),h.readUint(r,o+4),r[o+8]];else if("cHRM"==n)for(l.tabs[n]=[],y=0;y<8;y++)l.tabs[n].push(h.readUint(r,o+4*y));else if("tEXt"==n||"zTXt"==n){null==l.tabs[n]&&(l.tabs[n]={});var b=h.nextZero(r,o),m=h.readASCII(r,o,b-o),A=o+t-b-1;if("tEXt"==n)M=h.readASCII(r,b+1,A);else{var k=i(r.slice(b+2,b+2+A));M=h.readUTF8(k,0,k.length)}l.tabs[n][m]=M}else if("iTXt"==n){null==l.tabs[n]&&(l.tabs[n]={}),b=0,b=h.nextZero(r,g=o),m=h.readASCII(r,g,b-g);const e=r[g=b+1];var M;b=h.nextZero(r,g+=2),h.readASCII(r,g,b-g),b=h.nextZero(r,g=b+1),h.readUTF8(r,g,b-g),A=t-((g=b+1)-o),0==e?M=h.readUTF8(r,g,A):(k=i(r.slice(g,g+A)),M=h.readUTF8(k,0,k.length)),l.tabs[n][m]=M}else if("PLTE"==n)l.tabs[n]=h.readBytes(r,o,t);else if("hIST"==n){const t=l.tabs.PLTE.length/3;for(l.tabs[n]=[],y=0;y<t;y++)l.tabs[n].push(u(r,o+2*y))}else if("tRNS"==n)3==l.ctype?l.tabs[n]=h.readBytes(r,o,t):0==l.ctype?l.tabs[n]=u(r,o):2==l.ctype&&(l.tabs[n]=[u(r,o),u(r,o+2),u(r,o+4)]);else if("gAMA"==n)l.tabs[n]=h.readUint(r,o)/1e5;else if("sRGB"==n)l.tabs[n]=r[o];else if("bKGD"==n)0==l.ctype||4==l.ctype?l.tabs[n]=[u(r,o)]:2==l.ctype||6==l.ctype?l.tabs[n]=[u(r,o),u(r,o+2),u(r,o+4)]:3==l.ctype&&(l.tabs[n]=r[o]);else if("IEND"==n)break;o+=t,h.readUint(r,o),o+=4}var x;return 0!=p&&((x=l.frames[l.frames.length-1]).data=e(l,d.slice(0,p),x.rect.width,x.rect.height)),l.data=e(l,f,l.width,l.height),delete l.compress,delete l.interlace,delete l.filter,l},toRGBA8:function(t){const e=t.width,i=t.height;if(null==t.tabs.acTL)return[n(t.data,e,i,t).buffer];const s=[];null==t.frames[0].data&&(t.frames[0].data=t.data);const r=e*i*4,o=new Uint8Array(r),h=new Uint8Array(r),c=new Uint8Array(r);for(let l=0;l<t.frames.length;l++){const f=t.frames[l],d=f.rect.x,v=f.rect.y,p=f.rect.width,w=f.rect.height,y=n(f.data,p,w,t);if(0!=l)for(var a=0;a<r;a++)c[a]=o[a];if(0==f.blend?u(y,p,w,o,e,i,d,v,0):1==f.blend&&u(y,p,w,o,e,i,d,v,1),s.push(o.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)u(h,p,w,o,e,i,d,v,0);else if(2==f.dispose)for(a=0;a<r;a++)o[a]=c[a]}return s},_paeth:h,_copyTile:u,_bin:t}}();!function(){const{_copyTile:t}=H,{_bin:n}=H,e=H._paeth;var i={table:function(){const t=new Uint32Array(256);for(let n=0;n<256;n++){let e=n;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;t[n]=e}return t}(),update(t,n,e,s){for(let r=0;r<s;r++)t=i.table[255&(t^n[e+r])]^t>>>8;return t},crc:(t,n,e)=>4294967295^i.update(4294967295,t,n,e)};function s(t,n,e,i){n[e]+=t[0]*i>>4,n[e+1]+=t[1]*i>>4,n[e+2]+=t[2]*i>>4,n[e+3]+=t[3]*i>>4}function r(t){return Math.max(0,Math.min(255,t))}function o(t,n){const e=t[0]-n[0],i=t[1]-n[1],s=t[2]-n[2],r=t[3]-n[3];return e*e+i*i+s*s+r*r}function h(t,n,e,i,h,c,u){null==u&&(u=1);const a=i.length,l=[];for(var f=0;f<a;f++){const t=i[f];l.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(f=0;f<a;f++){let t=4294967295;for(var d=0,v=0;v<a;v++){var p=o(l[f],l[v]);v!=f&&p<t&&(t=p,d=v)}}const w=new Uint32Array(h.buffer),y=new Int16Array(n*e*4),g=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(f=0;f<g.length;f++)g[f]=255*((g[f]+.5)/16-.5);for(let h=0;h<e;h++)for(let m=0;m<n;m++){var b;f=4*(h*n+m),b=2!=u?[r(t[f]+y[f]),r(t[f+1]+y[f+1]),r(t[f+2]+y[f+2]),r(t[f+3]+y[f+3])]:[r(t[f]+(p=g[4*(3&h)+(3&m)])),r(t[f+1]+p),r(t[f+2]+p),r(t[f+3]+p)],d=0;let A=16777215;for(v=0;v<a;v++){const t=o(b,l[v]);t<A&&(A=t,d=v)}const k=l[d],M=[b[0]-k[0],b[1]-k[1],b[2]-k[2],b[3]-k[3]];1==u&&(m!=n-1&&s(M,y,f+4,7),h!=e-1&&(0!=m&&s(M,y,f+4*n-4,3),s(M,y,f+4*n,5),m!=n-1&&s(M,y,f+4*n+4,1))),c[f>>2]=d,w[f>>2]=i[d]}}function c(t,e,s,r,o){null==o&&(o={});const{crc:h}=i,c=n.writeUint,u=n.writeUshort,a=n.writeASCII;let l=8;const f=t.frames.length>1;let d,v=!1,p=33+(f?20:0);if(null!=o.sRGB&&(p+=13),null!=o.pHYs&&(p+=21),null!=o.iCCP&&(d=pako.deflate(o.iCCP),p+=21+d.length+4),3==t.ctype){for(var w=t.plte.length,y=0;y<w;y++)t.plte[y]>>>24!=255&&(v=!0);p+=8+3*w+4+(v?8+1*w+4:0)}for(var g=0;g<t.frames.length;g++)f&&(p+=38),p+=(k=t.frames[g]).cimg.length+12,0!=g&&(p+=4);p+=12;const b=new Uint8Array(p),m=[137,80,78,71,13,10,26,10];for(y=0;y<8;y++)b[y]=m[y];if(c(b,l,13),l+=4,a(b,l,"IHDR"),l+=4,c(b,l,e),l+=4,c(b,l,s),l+=4,b[l]=t.depth,l++,b[l]=t.ctype,l++,b[l]=0,l++,b[l]=0,l++,b[l]=0,l++,c(b,l,h(b,l-17,17)),l+=4,null!=o.sRGB&&(c(b,l,1),l+=4,a(b,l,"sRGB"),l+=4,b[l]=o.sRGB,l++,c(b,l,h(b,l-5,5)),l+=4),null!=o.iCCP){const t=13+d.length;c(b,l,t),l+=4,a(b,l,"iCCP"),l+=4,a(b,l,"ICC profile"),l+=11,l+=2,b.set(d,l),l+=d.length,c(b,l,h(b,l-(t+4),t+4)),l+=4}if(null!=o.pHYs&&(c(b,l,9),l+=4,a(b,l,"pHYs"),l+=4,c(b,l,o.pHYs[0]),l+=4,c(b,l,o.pHYs[1]),l+=4,b[l]=o.pHYs[2],l++,c(b,l,h(b,l-13,13)),l+=4),f&&(c(b,l,8),l+=4,a(b,l,"acTL"),l+=4,c(b,l,t.frames.length),l+=4,c(b,l,null!=o.loop?o.loop:0),l+=4,c(b,l,h(b,l-12,12)),l+=4),3==t.ctype){for(c(b,l,3*(w=t.plte.length)),l+=4,a(b,l,"PLTE"),l+=4,y=0;y<w;y++){const n=3*y,e=t.plte[y],i=e>>>8&255,s=e>>>16&255;b[l+n+0]=255&e,b[l+n+1]=i,b[l+n+2]=s}if(l+=3*w,c(b,l,h(b,l-3*w-4,3*w+4)),l+=4,v){for(c(b,l,w),l+=4,a(b,l,"tRNS"),l+=4,y=0;y<w;y++)b[l+y]=t.plte[y]>>>24&255;l+=w,c(b,l,h(b,l-w-4,w+4)),l+=4}}let A=0;for(g=0;g<t.frames.length;g++){var k=t.frames[g];f&&(c(b,l,26),l+=4,a(b,l,"fcTL"),l+=4,c(b,l,A++),l+=4,c(b,l,k.rect.width),l+=4,c(b,l,k.rect.height),l+=4,c(b,l,k.rect.x),l+=4,c(b,l,k.rect.y),l+=4,u(b,l,r[g]),l+=2,u(b,l,1e3),l+=2,b[l]=k.dispose,l++,b[l]=k.blend,l++,c(b,l,h(b,l-30,30)),l+=4);const n=k.cimg;c(b,l,(w=n.length)+(0==g?0:4)),l+=4;const e=l;a(b,l,0==g?"IDAT":"fdAT"),l+=4,0!=g&&(c(b,l,A++),l+=4),b.set(n,l),l+=w,c(b,l,h(b,e,l-e)),l+=4}return c(b,l,0),l+=4,a(b,l,"IEND"),l+=4,c(b,l,h(b,l-4,4)),l+=4,b.buffer}function u(t,n,e){for(let i=0;i<t.frames.length;i++){const s=t.frames[i],r=s.rect.height,o=new Uint8Array(r*s.bpl+r);s.cimg=d(s.img,r,s.bpp,s.bpl,o,n,e)}}function a(n,e,i,s,r){const o=r[0],c=r[1],u=r[2],a=r[3],d=r[4],v=r[5];let w=6,y=8,g=255;for(var b=0;b<n.length;b++){const t=new Uint8Array(n[b]);for(var m=t.length,A=0;A<m;A+=4)g&=t[A+3]}const k=255!=g,M=function(n,e,i,s,r,o){const h=[];for(var c=0;c<n.length;c++){const l=new Uint8Array(n[c]),d=new Uint32Array(l.buffer);var u;let p=0,w=0,y=e,g=i,b=s?1:0;if(0!=c){const m=o||s||1==c||0!=h[c-2].dispose?1:2;let A=0,k=1e9;for(let t=0;t<m;t++){var a=new Uint8Array(n[c-1-t]);const s=new Uint32Array(n[c-1-t]);let o=e,h=i,u=-1,l=-1;for(let t=0;t<i;t++)for(let n=0;n<e;n++)d[v=t*e+n]!=s[v]&&(n<o&&(o=n),n>u&&(u=n),t<h&&(h=t),t>l&&(l=t));-1==u&&(o=h=u=l=0),r&&(!(1&~o)&&o--,!(1&~h)&&h--);const f=(u-o+1)*(l-h+1);f<k&&(k=f,A=t,p=o,w=h,y=u-o+1,g=l-h+1)}a=new Uint8Array(n[c-1-A]),1==A&&(h[c-1].dispose=2),u=new Uint8Array(y*g*4),t(a,e,i,u,y,g,-p,-w,0),b=t(l,e,i,u,y,g,-p,-w,3)?1:0,1==b?f(l,e,i,u,{x:p,y:w,width:y,height:g}):t(l,e,i,u,y,g,-p,-w,0)}else u=l.slice(0);h.push({rect:{x:p,y:w,width:y,height:g},img:u,blend:b,dispose:0})}if(s)for(c=0;c<h.length;c++){if(1==(p=h[c]).blend)continue;const t=p.rect,s=h[c-1].rect,o=Math.min(t.x,s.x),u=Math.min(t.y,s.y),a={x:o,y:u,width:Math.max(t.x+t.width,s.x+s.width)-o,height:Math.max(t.y+t.height,s.y+s.height)-u};h[c-1].dispose=1,c-1!=0&&l(n,e,i,h,c-1,a,r),l(n,e,i,h,c,a,r)}let d=0;if(1!=n.length)for(var v=0;v<h.length;v++){var p;d+=(p=h[v]).rect.width*p.rect.height}return h}(n,e,i,o,c,u),x={},S=[],C=[];if(0!=s){const t=[];for(A=0;A<M.length;A++)t.push(M[A].img.buffer);const n=function(t){let n=0;for(var e=0;e<t.length;e++)n+=t[e].byteLength;const i=new Uint8Array(n);let s=0;for(e=0;e<t.length;e++){const n=new Uint8Array(t[e]),r=n.length;for(let t=0;t<r;t+=4){let e=n[t],r=n[t+1],o=n[t+2];const h=n[t+3];0==h&&(e=r=o=0),i[s+t]=e,i[s+t+1]=r,i[s+t+2]=o,i[s+t+3]=h}s+=r}return i.buffer}(t),e=p(n,s);for(A=0;A<e.plte.length;A++)S.push(e.plte[A].est.rgba);let i=0;for(A=0;A<M.length;A++){const t=(j=M[A]).img.length;var T=new Uint8Array(e.inds.buffer,i>>2,t>>2);C.push(T);const n=new Uint8Array(e.abuf,i,t);v&&h(j.img,j.rect.width,j.rect.height,S,n,T),j.img.set(n),i+=t}}else for(b=0;b<M.length;b++){var j=M[b];const t=new Uint32Array(j.img.buffer);var U=j.rect.width;for(m=t.length,T=new Uint8Array(m),C.push(T),A=0;A<m;A++){const n=t[A];if(0!=A&&n==t[A-1])T[A]=T[A-1];else if(A>U&&n==t[A-U])T[A]=T[A-U];else{let t=x[n];if(null==t&&(x[n]=t=S.length,S.push(n),S.length>=300))break;T[A]=t}}}const E=S.length;for(E<=256&&0==d&&(y=E<=2?1:E<=4?2:E<=16?4:8,y=Math.max(y,a)),b=0;b<M.length;b++){const t=(j=M[b]).rect.height;let n=j.img,e=4*(U=j.rect.width),i=4;if(E<=256&&0==d){e=Math.ceil(y*U/8);var $=new Uint8Array(e*t);const s=C[b];for(let n=0;n<t;n++){A=n*e;const t=n*U;if(8==y)for(var _=0;_<U;_++)$[A+_]=s[t+_];else if(4==y)for(_=0;_<U;_++)$[A+(_>>1)]|=s[t+_]<<4-4*(1&_);else if(2==y)for(_=0;_<U;_++)$[A+(_>>2)]|=s[t+_]<<6-2*(3&_);else if(1==y)for(_=0;_<U;_++)$[A+(_>>3)]|=s[t+_]<<7-1*(7&_)}n=$,w=3,i=1}else if(0==k&&1==M.length){$=new Uint8Array(U*t*3);const s=U*t;for(A=0;A<s;A++){const t=3*A,e=4*A;$[t]=n[e],$[t+1]=n[e+1],$[t+2]=n[e+2]}n=$,w=2,i=3,e=3*U}j.img=n,j.bpl=e,j.bpp=i}return{ctype:w,depth:y,plte:S,frames:M}}function l(n,e,i,s,r,o,h){const c=Uint8Array,u=Uint32Array,a=new c(n[r-1]),l=new u(n[r-1]),d=r+1<n.length?new c(n[r+1]):null,v=new c(n[r]),p=new u(v.buffer);let w=e,y=i,g=-1,b=-1;for(let t=0;t<o.height;t++)for(let n=0;n<o.width;n++){const i=o.x+n,h=o.y+t,c=h*e+i,u=p[c];0==u||0==s[r-1].dispose&&l[c]==u&&(null==d||0!=d[4*c+3])||(i<w&&(w=i),i>g&&(g=i),h<y&&(y=h),h>b&&(b=h))}-1==g&&(w=y=g=b=0),h&&(!(1&~w)&&w--,!(1&~y)&&y--);const m=s[r];m.rect=o={x:w,y,width:g-w+1,height:b-y+1},m.blend=1,m.img=new Uint8Array(o.width*o.height*4),0==s[r-1].dispose?(t(a,e,i,m.img,o.width,o.height,-o.x,-o.y,0),f(v,e,i,m.img,o)):t(v,e,i,m.img,o.width,o.height,-o.x,-o.y,0)}function f(n,e,i,s,r){t(n,e,i,s,r.width,r.height,-r.x,-r.y,2)}function d(t,n,e,i,s,r,o){const h=[];let c,u=[0,1,2,3,4];-1!=r?u=[r]:(n*i>5e5||1==e)&&(u=[0]),o&&(c={level:0});const a=X;for(var l=0;l<u.length;l++){for(let r=0;r<n;r++)v(s,t,r,i,e,u[l]);h.push(a.deflate(s,c))}let f,d=1e9;for(l=0;l<h.length;l++)h[l].length<d&&(f=l,d=h[l].length);return h[f]}function v(t,n,i,s,r,o){const h=i*s;let c=h+i;if(t[c]=o,c++,0==o)if(s<500)for(var u=0;u<s;u++)t[c+u]=n[h+u];else t.set(new Uint8Array(n.buffer,h,s),c);else if(1==o){for(u=0;u<r;u++)t[c+u]=n[h+u];for(u=r;u<s;u++)t[c+u]=n[h+u]-n[h+u-r]+256&255}else if(0==i){for(u=0;u<r;u++)t[c+u]=n[h+u];if(2==o)for(u=r;u<s;u++)t[c+u]=n[h+u];if(3==o)for(u=r;u<s;u++)t[c+u]=n[h+u]-(n[h+u-r]>>1)+256&255;if(4==o)for(u=r;u<s;u++)t[c+u]=n[h+u]-e(n[h+u-r],0,0)+256&255}else{if(2==o)for(u=0;u<s;u++)t[c+u]=n[h+u]+256-n[h+u-s]&255;if(3==o){for(u=0;u<r;u++)t[c+u]=n[h+u]+256-(n[h+u-s]>>1)&255;for(u=r;u<s;u++)t[c+u]=n[h+u]+256-(n[h+u-s]+n[h+u-r]>>1)&255}if(4==o){for(u=0;u<r;u++)t[c+u]=n[h+u]+256-e(0,n[h+u-s],0)&255;for(u=r;u<s;u++)t[c+u]=n[h+u]+256-e(n[h+u-r],n[h+u-s],n[h+u-r-s])&255}}}function p(t,n){const e=new Uint8Array(t),i=e.slice(0),s=new Uint32Array(i.buffer),r=w(i,n),o=r[0],h=r[1],c=e.length,u=new Uint8Array(c>>2);let a;if(e.length<2e7)for(var l=0;l<c;l+=4)a=y(o,f=e[l]*(1/255),d=e[l+1]*(1/255),v=e[l+2]*(1/255),p=e[l+3]*(1/255)),u[l>>2]=a.ind,s[l>>2]=a.est.rgba;else for(l=0;l<c;l+=4){var f=e[l]*(1/255),d=e[l+1]*(1/255),v=e[l+2]*(1/255),p=e[l+3]*(1/255);for(a=o;a.left;)a=g(a.est,f,d,v,p)<=0?a.left:a.right;u[l>>2]=a.ind,s[l>>2]=a.est.rgba}return{abuf:i.buffer,inds:u,plte:h}}function w(t,n,e){null==e&&(e=1e-4);const i=new Uint32Array(t.buffer),s={i0:0,i1:t.length,bst:null,est:null,tdst:0,left:null,right:null};s.bst=A(t,s.i0,s.i1),s.est=k(s.bst);const r=[s];for(;r.length<n;){let n=0,s=0;for(var o=0;o<r.length;o++)r[o].est.L>n&&(n=r[o].est.L,s=o);if(n<e)break;const h=r[s],c=b(t,i,h.i0,h.i1,h.est.e,h.est.eMq255);if(h.i0>=c||h.i1<=c){h.est.L=0;continue}const u={i0:h.i0,i1:c,bst:null,est:null,tdst:0,left:null,right:null};u.bst=A(t,u.i0,u.i1),u.est=k(u.bst);const a={i0:c,i1:h.i1,bst:null,est:null,tdst:0,left:null,right:null};for(a.bst={R:[],m:[],N:h.bst.N-u.bst.N},o=0;o<16;o++)a.bst.R[o]=h.bst.R[o]-u.bst.R[o];for(o=0;o<4;o++)a.bst.m[o]=h.bst.m[o]-u.bst.m[o];a.est=k(a.bst),h.left=u,h.right=a,r[s]=u,r.push(a)}for(r.sort(((t,n)=>n.bst.N-t.bst.N)),o=0;o<r.length;o++)r[o].ind=o;return[s,r]}function y(t,n,e,i,s){if(null==t.left)return t.tdst=function(t,n,e,i,s){const r=n-t[0],o=e-t[1],h=i-t[2],c=s-t[3];return r*r+o*o+h*h+c*c}(t.est.q,n,e,i,s),t;const r=g(t.est,n,e,i,s);let o=t.left,h=t.right;r>0&&(o=t.right,h=t.left);const c=y(o,n,e,i,s);if(c.tdst<=r*r)return c;const u=y(h,n,e,i,s);return u.tdst<c.tdst?u:c}function g(t,n,e,i,s){const{e:r}=t;return r[0]*n+r[1]*e+r[2]*i+r[3]*s-t.eMq}function b(t,n,e,i,s,r){for(i-=4;e<i;){for(;m(t,e,s)<=r;)e+=4;for(;m(t,i,s)>r;)i-=4;if(e>=i)break;const o=n[e>>2];n[e>>2]=n[i>>2],n[i>>2]=o,e+=4,i-=4}for(;m(t,e,s)>r;)e-=4;return e+4}function m(t,n,e){return t[n]*e[0]+t[n+1]*e[1]+t[n+2]*e[2]+t[n+3]*e[3]}function A(t,n,e){const i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],s=[0,0,0,0],r=e-n>>2;for(let r=n;r<e;r+=4){const n=t[r]*(1/255),e=t[r+1]*(1/255),o=t[r+2]*(1/255),h=t[r+3]*(1/255);s[0]+=n,s[1]+=e,s[2]+=o,s[3]+=h,i[0]+=n*n,i[1]+=n*e,i[2]+=n*o,i[3]+=n*h,i[5]+=e*e,i[6]+=e*o,i[7]+=e*h,i[10]+=o*o,i[11]+=o*h,i[15]+=h*h}return i[4]=i[1],i[8]=i[2],i[9]=i[6],i[12]=i[3],i[13]=i[7],i[14]=i[11],{R:i,m:s,N:r}}function k(t){const{R:n}=t,{m:e}=t,{N:i}=t,s=e[0],r=e[1],o=e[2],h=e[3],c=0==i?0:1/i,u=[n[0]-s*s*c,n[1]-s*r*c,n[2]-s*o*c,n[3]-s*h*c,n[4]-r*s*c,n[5]-r*r*c,n[6]-r*o*c,n[7]-r*h*c,n[8]-o*s*c,n[9]-o*r*c,n[10]-o*o*c,n[11]-o*h*c,n[12]-h*s*c,n[13]-h*r*c,n[14]-h*o*c,n[15]-h*h*c],a=u,l=M;let f=[Math.random(),Math.random(),Math.random(),Math.random()],d=0,v=0;if(0!=i)for(let t=0;t<16&&(f=l.multVec(a,f),v=Math.sqrt(l.dot(f,f)),f=l.sml(1/v,f),!(0!=t&&Math.abs(v-d)<1e-9));t++)d=v;const p=[s*c,r*c,o*c,h*c];return{Cov:u,q:p,e:f,L:d,eMq255:l.dot(l.sml(255,p),f),eMq:l.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}}var M={multVec:(t,n)=>[t[0]*n[0]+t[1]*n[1]+t[2]*n[2]+t[3]*n[3],t[4]*n[0]+t[5]*n[1]+t[6]*n[2]+t[7]*n[3],t[8]*n[0]+t[9]*n[1]+t[10]*n[2]+t[11]*n[3],t[12]*n[0]+t[13]*n[1]+t[14]*n[2]+t[15]*n[3]],dot:(t,n)=>t[0]*n[0]+t[1]*n[1]+t[2]*n[2]+t[3]*n[3],sml:(t,n)=>[t*n[0],t*n[1],t*n[2],t*n[3]]};H.encode=function(t,n,e,i,s,r,o){null==i&&(i=0),null==o&&(o=!1);const h=a(t,n,e,i,[!1,!1,!1,0,o,!1]);return u(h,-1),c(h,n,e,s,r)},H.encodeLL=function(t,n,e,i,s,r,o,h){const a={ctype:0+(1==i?0:2)+(0==s?0:4),depth:r,frames:[]},l=(i+s)*r,f=l*n;for(let i=0;i<t.length;i++)a.frames.push({rect:{x:0,y:0,width:n,height:e},img:new Uint8Array(t[i]),blend:0,dispose:1,bpp:Math.ceil(l/8),bpl:Math.ceil(f/8)});return u(a,0,!0),c(a,n,e,o,h)},H.encode.compress=a,H.encode.dither=h,H.quantize=p,H.quantize.getKDtree=w,H.quantize.getNearest=y}();const K={toArrayBuffer(t,n){const e=t.width,i=t.height,s=e<<2,r=t.getContext("2d").getImageData(0,0,e,i),o=new Uint32Array(r.data.buffer),h=(32*e+31)/32<<2,c=h*i,u=122+c,a=new ArrayBuffer(u),l=new DataView(a),f=1<<20;let d,v,p,w,y=f,g=0,b=0,m=0;function A(t){l.setUint16(b,t,!0),b+=2}function k(t){l.setUint32(b,t,!0),b+=4}function M(t){b+=t}A(19778),k(u),M(4),k(122),k(108),k(e),k(-i>>>0),A(1),A(32),k(3),k(c),k(2835),k(2835),M(8),k(16711680),k(65280),k(255),k(4278190080),k(1466527264),function t(){for(;g<i&&y>0;){for(w=122+g*h,d=0;d<s;)y--,v=o[m++],p=v>>>24,l.setUint32(w+d,v<<8|p),d+=4;g++}m<o.length?(y=f,setTimeout(t,K._dly)):n(a)}()},toBlob(t,n){this.toArrayBuffer(t,(t=>{n(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var N={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},Q={[N.CHROME]:16384,[N.FIREFOX]:11180,[N.DESKTOP_SAFARI]:16384,[N.IE]:8192,[N.IOS]:4096,[N.ETC]:8192};const V="undefined"!=typeof window,G="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,q=V&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),J=(V||G)&&(q&&q.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),Z=(V||G)&&(q&&q.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function tt(t,n,e=Date.now()){return new Promise((i=>{const s=t.split(","),r=s[0].match(/:(.*?);/)[1],o=globalThis.atob(s[1]);let h=o.length;const c=new Uint8Array(h);for(;h--;)c[h]=o.charCodeAt(h);const u=new Blob([c],{type:r});u.name=n,u.lastModified=e,i(u)}))}function nt(t){return new Promise(((n,e)=>{const i=new Z;i.onload=()=>n(i.result),i.onerror=t=>e(t),i.readAsDataURL(t)}))}function et(t){return new Promise(((n,e)=>{const i=new Image;i.onload=()=>n(i),i.onerror=t=>e(t),i.src=t}))}function it(){if(void 0!==it.cachedResult)return it.cachedResult;let t=N.ETC;const{userAgent:n}=navigator;return/Chrom(e|ium)/i.test(n)?t=N.CHROME:/iP(ad|od|hone)/i.test(n)&&/WebKit/i.test(n)?t=N.IOS:/Safari/i.test(n)?t=N.DESKTOP_SAFARI:/Firefox/i.test(n)?t=N.FIREFOX:(/MSIE/i.test(n)||1==!!document.documentMode)&&(t=N.IE),it.cachedResult=t}function st(t,n){const e=it(),i=Q[e];let s=t,r=n,o=s*r;const h=s>r?r/s:s/r;for(;o>i*i;){const t=(i+s)/2,n=(i+r)/2;t<n?(r=n,s=n*h):(r=t*h,s=t),o=s*r}return{width:s,height:r}}function rt(t,n){let e,i;try{if(e=new OffscreenCanvas(t,n),i=e.getContext("2d"),null===i)throw new Error("getContext of OffscreenCanvas returns null")}catch(t){e=document.createElement("canvas"),i=e.getContext("2d")}return e.width=t,e.height=n,[e,i]}function ot(t,n){const{width:e,height:i}=st(t.width,t.height),[s,r]=rt(e,i);return n&&/jpe?g/.test(n)&&(r.fillStyle="white",r.fillRect(0,0,s.width,s.height)),r.drawImage(t,0,0,s.width,s.height),s}function ht(){return void 0!==ht.cachedResult||(ht.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),ht.cachedResult}function ct(t,n={}){return new Promise((function(e,i){let s,r;var o=function(){try{return r=ot(s,n.fileType||t.type),e([s,r])}catch(t){return i(t)}},h=function(){try{var n=function(t){try{throw t}catch(t){return i(t)}};try{let e;return nt(t).then((function(t){try{return e=t,et(e).then((function(t){try{return s=t,function(){try{return o()}catch(t){return i(t)}}()}catch(t){return n(t)}}),n)}catch(t){return n(t)}}),n)}catch(t){n(t)}}catch(t){return i(t)}};try{if(ht()||[N.DESKTOP_SAFARI,N.MOBILE_SAFARI].includes(it()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return s=t,o()}catch(t){return h()}}),h)}catch(t){h()}}))}function ut(t,n,e,i,s=1){return new Promise((function(r,o){let h;if("image/png"===n){let u,a,l;return u=t.getContext("2d"),({data:a}=u.getImageData(0,0,t.width,t.height)),l=H.encode([a.buffer],t.width,t.height,4096*s),h=new Blob([l],{type:n}),h.name=e,h.lastModified=i,c.call(this)}{if("image/bmp"===n)return new Promise((n=>K.toBlob(t,n))).then(function(t){try{return h=t,h.name=e,h.lastModified=i,f.call(this)}catch(t){return o(t)}}.bind(this),o);{if("function"==typeof OffscreenCanvas&&t instanceof OffscreenCanvas)return t.convertToBlob({type:n,quality:s}).then(function(t){try{return h=t,h.name=e,h.lastModified=i,d.call(this)}catch(t){return o(t)}}.bind(this),o);{let v;return v=t.toDataURL(n,s),tt(v,e,i).then(function(t){try{return h=t,d.call(this)}catch(t){return o(t)}}.bind(this),o)}function d(){return f.call(this)}}function f(){return c.call(this)}}function c(){return r(h)}}))}function at(t){t.width=0,t.height=0}function lt(){return new Promise((function(t,n){let e,i,s,r;return void 0!==lt.cachedResult?t(lt.cachedResult):tt("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return e=o,ct(e).then((function(o){try{return i=o[1],ut(i,e.type,e.name,e.lastModified).then((function(e){try{return s=e,at(i),ct(s).then((function(e){try{return r=e[0],t(lt.cachedResult=1===r.width&&2===r.height)}catch(t){return n(t)}}),n)}catch(t){return n(t)}}),n)}catch(t){return n(t)}}),n)}catch(t){return n(t)}}),n)}))}function ft(t){return new Promise(((n,e)=>{const i=new Z;i.onload=t=>{const e=new DataView(t.target.result);if(65496!=e.getUint16(0,!1))return n(-2);const i=e.byteLength;let s=2;for(;s<i;){if(e.getUint16(s+2,!1)<=8)return n(-1);const t=e.getUint16(s,!1);if(s+=2,65505==t){if(1165519206!=e.getUint32(s+=2,!1))return n(-1);const t=18761==e.getUint16(s+=6,!1);s+=e.getUint32(s+4,t);const i=e.getUint16(s,t);s+=2;for(let r=0;r<i;r++)if(274==e.getUint16(s+12*r,t))return n(e.getUint16(s+12*r+8,t))}else{if(65280&~t)break;s+=e.getUint16(s,!1)}}return n(-1)},i.onerror=t=>e(t),i.readAsArrayBuffer(t)}))}function dt(t,n){const{width:e}=t,{height:i}=t,{maxWidthOrHeight:s}=n;let r,o=t;return isFinite(s)&&(e>s||i>s)&&([o,r]=rt(e,i),e>i?(o.width=s,o.height=i/e*s):(o.width=e/i*s,o.height=s),r.drawImage(t,0,0,o.width,o.height),at(t)),o}function vt(t,n){const{width:e}=t,{height:i}=t,[s,r]=rt(e,i);switch(n>4&&n<9?(s.width=i,s.height=e):(s.width=e,s.height=i),n){case 2:r.transform(-1,0,0,1,e,0);break;case 3:r.transform(-1,0,0,-1,e,i);break;case 4:r.transform(1,0,0,-1,0,i);break;case 5:r.transform(0,1,1,0,0,0);break;case 6:r.transform(0,1,-1,0,i,0);break;case 7:r.transform(0,-1,-1,0,i,e);break;case 8:r.transform(0,-1,1,0,0,e)}return r.drawImage(t,0,0,e,i),at(t),s}function pt(t,n,e=0){return new Promise((function(i,s){let r,o,h,c,u,a,l,f,d,v,p,w,y,g,b,m,A,k,M,x;function S(t=5){if(n.signal&&n.signal.aborted)throw n.signal.reason;r+=t,n.onProgress(Math.min(r,100))}function C(t){if(n.signal&&n.signal.aborted)throw n.signal.reason;r=Math.min(Math.max(t,r),100),n.onProgress(r)}return r=e,o=n.maxIteration||10,h=1024*n.maxSizeMB*1024,S(),ct(t,n).then(function(e){try{return[,c]=e,S(),u=dt(c,n),S(),new Promise((function(e,i){var s;if(!(s=n.exifOrientation))return ft(t).then(function(t){try{return s=t,r.call(this)}catch(t){return i(t)}}.bind(this),i);function r(){return e(s)}return r.call(this)})).then(function(e){try{return a=e,S(),lt().then(function(e){try{return l=e?u:vt(u,a),S(),f=n.initialQuality||1,d=n.fileType||t.type,ut(l,d,t.name,t.lastModified,f).then(function(e){try{{if(v=e,S(),p=v.size>h,w=v.size>t.size,!p&&!w)return C(100),i(v);var r;function a(){if(o--&&(b>h||b>y)){let n,e;return n=x?.95*M.width:M.width,e=x?.95*M.height:M.height,[A,k]=rt(n,e),k.drawImage(M,0,0,n,e),f*="image/png"===d?.85:.95,ut(A,d,t.name,t.lastModified,f).then((function(t){try{return m=t,at(M),M=A,b=m.size,C(Math.min(99,Math.floor((g-b)/(g-h)*100))),a}catch(t){return s(t)}}),s)}return[1]}return y=t.size,g=v.size,b=g,M=l,x=!n.alwaysKeepResolution&&p,(r=function(t){for(;t;){if(t.then)return void t.then(r,s);try{if(t.pop){if(t.length)return t.pop()?T.call(this):t;t=a}else t=t.call(this)}catch(t){return s(t)}}}.bind(this))(a);function T(){return at(M),at(A),at(u),at(l),at(c),C(100),i(m)}}}catch(j){return s(j)}}.bind(this),s)}catch(t){return s(t)}}.bind(this),s)}catch(t){return s(t)}}.bind(this),s)}catch(t){return s(t)}}.bind(this),s)}))}let wt;function yt(t,n){return new Promise(((e,i)=>{wt||(wt=function(){const t=[];return t.push("\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"),URL.createObjectURL(new Blob(t))}());const s=new Worker(wt);s.addEventListener("message",(function(t){if(n.signal&&n.signal.aborted)s.terminate();else if(void 0===t.data.progress){if(t.data.error)return i(new Error(t.data.error)),void s.terminate();e(t.data.file),s.terminate()}else n.onProgress(t.data.progress)})),s.addEventListener("error",i),n.signal&&n.signal.addEventListener("abort",(()=>{i(n.signal.reason),s.terminate()})),s.postMessage({file:t,imageCompressionLibUrl:n.libURL,options:{...n,onProgress:void 0,signal:void 0}})}))}function gt(t,n){return new Promise((function(e,i){let s,r,o,h,c,u;if(s={...n},o=0,({onProgress:h}=s),s.maxSizeMB=s.maxSizeMB||Number.POSITIVE_INFINITY,c="boolean"!=typeof s.useWebWorker||s.useWebWorker,delete s.useWebWorker,s.onProgress=t=>{o=t,"function"==typeof h&&h(o)},!(t instanceof Blob||t instanceof J))return i(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(t.type))return i(new Error("The file given is not an image"));if(u="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!c||"function"!=typeof Worker||u)return pt(t,s).then(function(t){try{return r=t,f.call(this)}catch(t){return i(t)}}.bind(this),i);var a=function(){try{return f.call(this)}catch(t){return i(t)}}.bind(this),l=function(){try{return pt(t,s).then((function(t){try{return r=t,a()}catch(t){return i(t)}}),i)}catch(t){return i(t)}};try{return s.libURL=s.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",yt(t,s).then((function(t){try{return r=t,a()}catch(t){return l()}}),l)}catch(t){l()}function f(){try{r.name=t.name,r.lastModified=t.lastModified}catch(t){}try{s.preserveExif&&"image/jpeg"===t.type&&(!s.fileType||s.fileType&&s.fileType===t.type)&&(r=L(t,r))}catch(t){}return e(r)}}))}gt.getDataUrlFromFile=nt,gt.getFilefromDataUrl=tt,gt.loadImage=et,gt.drawImageInCanvas=ot,gt.drawFileInCanvas=ct,gt.canvasToFile=ut,gt.getExifOrientation=ft,gt.handleMaxWidthOrHeight=dt,gt.followExifOrientation=vt,gt.cleanupCanvasMemory=at,gt.isAutoOrientationInBrowser=lt,gt.approximateBelowMaximumCanvasSizeOfBrowser=st,gt.copyExifWithoutOrientation=L,gt.getBrowserName=it,gt.version="2.0.2";class bt extends u{fileInput=null;maxCompressionSize=300;constructor(t){super(t),this.setupFileInput()}onActivate(){this.openFilePicker()}openFilePicker(){this._core.store.isDisabled||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 n=t.target;n.files&&n.files[0]?gt(n.files[0],{maxWidthOrHeight:this.maxCompressionSize}).then((t=>{this.readFile(t)})).catch((t=>{console.error("Error during image compression or processing:",t),this.handleCancel()})):(console.info("File selection cancelled by user."),this.handleCancel()),n&&(n.value="")}readFile(t){const n=new FileReader;n.onload=t=>{const n=new Image;n.src=t.target?.result,n.onload=()=>this.createKritzelImage(n)},n.readAsDataURL(t)}createKritzelImage(t){const n=O.create(this._core),{scaledWidth:e,scaledHeight:i}=n.calculateScaledDimensions(t);return n.src=t.src,n.width=e,n.height=i,n.zIndex=this._core.store.currentZIndex,n.centerInViewport(),this.addImageToStore(n),n}addImageToStore(t){this._core.addObject(t),this._core.store.setState("activeTool",l.getTool("selection")),this._core.selectObjects([t]),this._core.engine.emitObjectsChange()}handleCancel(){this._core.store.setState("activeTool",l.getTool("selection"))}}class mt{static _pointerCursor=null;static getPointerCursor(){return this._pointerCursor||(this._pointerCursor=this.getCursor({iconName:"pointer"})),this._pointerCursor}static getCursor(t){const n="default"===t.iconName?"mouse-pointer":t.iconName,e=U.get(n);if(!e)return console.warn(`Icon "${n}" not found in registry.`),"auto";const i=t.size||24,s=t.rotation||0,r=t.color||"black",o=t.hotspot||("default"===t.iconName?{x:4,y:4}:{x:i/2,y:i/2});let h=e.replace(/width="\d+"/,`width="${i}"`).replace(/height="\d+"/,`height="${i}"`).replace(/currentColor/g,r);const c=i/2;return`url('data:image/svg+xml;charset=utf-8,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="${i}" height="${i}" viewBox="0 0 ${i} ${i}">\n <g transform="rotate(${s} ${c} ${c})">\n ${h}\n </g>\n </svg>\n `.replace(/\s+/g," ").trim()).replace(/'/g,"%27").replace(/"/g,"%22")}') ${o.x} ${o.y}, auto`}}class At{_core;constructor(t){this._core=t}}class kt extends At{dragStartX;dragStartY;startX;startY;endX;endY;initialDragX=0;initialDragY=0;disconnectedLineIds=new Set;hasMoved=!1;trackedPointerId=null;constructor(t){super(t)}reset(){this.dragStartX=0,this.dragStartY=0,this.startX=0,this.startY=0,this.endX=0,this.endY=0,this.initialDragX=0,this.initialDragY=0,this.disconnectedLineIds.clear(),this.hasMoved=!1,this.trackedPointerId=null}cancelPendingDrag(){this._core.store.state.isDragging=!1,this.reset()}handlePointerDown(t){if("mouse"===t.pointerType)if(a.isLeftClick(t)){const n=this._core.store.selectionGroup;if(!n?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected)this.trackedPointerId=null;else{const n=t.clientX-this._core.store.offsetX,e=t.clientY-this._core.store.offsetY;this._core.store.state.isDragging=!0,this.dragStartX=n,this.dragStartY=e,this.startX=this.dragStartX,this.startY=this.dragStartY,this.initialDragX=n,this.initialDragY=e,this.disconnectedLineIds.clear(),this.trackedPointerId=t.pointerId}}else this.trackedPointerId=null;if("touch"===t.pointerType){const n=Array.from(this._core.store.state.pointers.values());if(1===this._core.store.state.pointers.size){if(this._core.store.state.isScaling)return void(this.trackedPointerId=null);const e=this._core.store.selectionGroup;if(!e?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected)this.trackedPointerId=null;else{const e=Math.round(n[0].clientX-this._core.store.offsetX),i=Math.round(n[0].clientY-this._core.store.offsetY);this.dragStartX=e,this.dragStartY=i,this.startX=e,this.startY=i,this.initialDragX=e,this.initialDragY=i,this.disconnectedLineIds.clear(),this.trackedPointerId=t.pointerId}}}}handlePointerMove(t){if(null!==this.trackedPointerId&&this.trackedPointerId===t.pointerId){if("mouse"===t.pointerType){const n=this._core.store.selectionGroup;if(this._core.store.state.isDragging&&n){const e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;this.endX=e,this.endY=i;const s=Math.abs(e-this.startX),r=Math.abs(i-this.startY),o=5;(s>o||r>o)&&(this.checkAndDisconnectAnchors(e,i),n.move(e,i,this.dragStartX,this.dragStartY),this.dragStartX=e,this.dragStartY=i,this.hasMoved=!0)}}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),n=this._core.store.selectionGroup;if(1===this._core.store.state.pointers.size&&n&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected&&!this._core.store.state.isScaling){const e=Math.round(t[0].clientX-this._core.store.offsetX),i=Math.round(t[0].clientY-this._core.store.offsetY);this._core.store.state.isDragging=!0,this.endX=e,this.endY=i;const s=Math.abs(e-this.startX),r=Math.abs(i-this.startY),o=5;(s>o||r>o)&&(clearTimeout(this._core.store.state.longTouchTimeout),this.checkAndDisconnectAnchors(e,i),n.move(e,i,this.dragStartX,this.dragStartY),this.dragStartX=e,this.dragStartY=i,this.hasMoved=!0)}}}}handlePointerUp(t){null!==this.trackedPointerId&&this.trackedPointerId===t.pointerId&&("mouse"===t.pointerType&&this._core.store.state.isDragging&&(this._core.store.state.isDragging=!1,this.hasMoved&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0)),"touch"===t.pointerType&&this._core.store.state.isDragging&&(this._core.store.state.isDragging=!1,this.hasMoved&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0)),this.reset())}checkAndDisconnectAnchors(t,n){const e=t-this.initialDragX,i=n-this.initialDragY;if(Math.sqrt(e*e+i*i)<30)return;const s=this._core.store.selectionGroup;if(s)for(const t of s.objects)if(!this.disconnectedLineIds.has(t.id)&&t instanceof z){const n=t;(n.startAnchor||n.endAnchor)&&(n.startAnchor&&this._core.anchorManager.removeAnchor(n.id,"start"),n.endAnchor&&this._core.anchorManager.removeAnchor(n.id,"end"),this.disconnectedLineIds.add(n.id),this._core.store.state.objects.update(n))}}}var Mt;!function(t){t.TopLeft="top-left",t.TopRight="top-right",t.BottomLeft="bottom-left",t.BottomRight="bottom-right"}(Mt||(Mt={}));class xt extends At{initialMouseX=0;initialMouseY=0;initialSize={x:0,y:0,width:0,height:0};newSize={x:0,y:0,width:0,height:0};hasResized=!1;constructor(t){super(t)}reset(){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},this.hasResized=!1}handlePointerDown(t){if("mouse"===t.pointerType&&a.isLeftClick(t)){const n=this._core.store.selectionGroup;if(n&&this._core.store.state.isResizeHandleSelected){const e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;this._core.store.state.isResizing=!0,this.initialMouseX=e,this.initialMouseY=i,this.initialSize.width=n.width,this.initialSize.height=n.height,this.initialSize.x=n.translateX,this.initialSize.y=n.translateY}}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),n=t[0];if(!n)return;if(1===t.length){const t=this._core.store.selectionGroup;if(t&&this._core.store.state.isResizeHandleSelected){const e=Math.round(n.clientX-this._core.store.offsetX),i=Math.round(n.clientY-this._core.store.offsetY);this._core.store.state.isResizing=!0,this.initialMouseX=e,this.initialMouseY=i,this.initialSize.width=t.width,this.initialSize.height=t.height,this.initialSize.x=t.translateX,this.initialSize.y=t.translateY,clearTimeout(this._core.store.state.longTouchTimeout)}}}}handlePointerMove(t){if("mouse"===t.pointerType){const n=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&n){const e=t.clientX-this._core.store.offsetX-this.initialMouseX,i=t.clientY-this._core.store.offsetY-this.initialMouseY,s=Math.abs(e),r=Math.abs(i),o=5;if((s>o||r>o)&&(this.hasResized=!0),!this.hasResized)return;const h=n.rotation,c=Math.sin(h),u=Math.cos(h),a=n.scale||1,l=this._core.store.state.scale,f=(e*u+i*c)/l,d=(-e*c+i*u)/l,v=this.initialSize.x+this.initialSize.width/a/2+e/l/2,p=this.initialSize.y+this.initialSize.height/a/2+i/l/2;switch(this._core.store.state.resizeHandleType){case Mt.TopLeft:this.newSize.width=this.initialSize.width-f*a,this.newSize.height=this.initialSize.height-d*a;break;case Mt.TopRight:this.newSize.width=this.initialSize.width+f*a,this.newSize.height=this.initialSize.height-d*a;break;case Mt.BottomLeft:this.newSize.width=this.initialSize.width-f*a,this.newSize.height=this.initialSize.height+d*a;break;case Mt.BottomRight:this.newSize.width=this.initialSize.width+f*a,this.newSize.height=this.initialSize.height+d*a}this.newSize.x=v-this.newSize.width/a/2,this.newSize.y=p-this.newSize.height/a/2,n.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values())[0];if(!t)return;const n=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&n){const e=Math.round(t.clientX-this._core.store.offsetX),i=Math.round(t.clientY-this._core.store.offsetY),s=e-this.initialMouseX,r=i-this.initialMouseY,o=Math.abs(s),h=Math.abs(r),c=5;if((o>c||h>c)&&(clearTimeout(this._core.store.state.longTouchTimeout),this.hasResized=!0),!this.hasResized)return;const u=n.rotation,a=Math.sin(u),l=Math.cos(u),f=n.scale||1,d=this._core.store.state.scale,v=(s*l+r*a)/d,p=(-s*a+r*l)/d,w=this.initialSize.x+this.initialSize.width/f/2+s/d/2,y=this.initialSize.y+this.initialSize.height/f/2+r/d/2;switch(this._core.store.state.resizeHandleType){case Mt.TopLeft:this.newSize.width=this.initialSize.width-v*f,this.newSize.height=this.initialSize.height-p*f;break;case Mt.TopRight:this.newSize.width=this.initialSize.width+v*f,this.newSize.height=this.initialSize.height-p*f;break;case Mt.BottomLeft:this.newSize.width=this.initialSize.width-v*f,this.newSize.height=this.initialSize.height+p*f;break;case Mt.BottomRight:this.newSize.width=this.initialSize.width+v*f,this.newSize.height=this.initialSize.height+p*f}this.newSize.x=w-this.newSize.width/f/2,this.newSize.y=y-this.newSize.height/f/2,n.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}}handlePointerUp(t){"mouse"===t.pointerType&&this._core.store.state.isResizing&&(this._core.store.state.isResizing=!1,this.hasResized&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0),this.reset()),"touch"===t.pointerType&&this._core.store.state.isResizing&&(this._core.store.state.isResizing=!1,this.hasResized&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0),this.reset(),clearTimeout(this._core.store.state.longTouchTimeout))}}class St extends At{initialRotation=0;rotation=0;unchangedObjects=[];initialSelectionGroupRotation=0;constructor(t){super(t)}reset(){this.initialRotation=0,this.rotation=0,this.unchangedObjects=[]}handlePointerDown(t){if("mouse"===t.pointerType&&a.isLeftClick(t)){const n=this._core.store.selectionGroup;if(n&&this._core.store.state.isRotationHandleSelected){n.beginTransform();const e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;this._core.store.state.isRotating=!0;const s=n.scale||1,r=n.translateX+n.width/2/s,o=n.translateY+n.height/2/s,h=(e-this._core.store.state.translateX)/this._core.store.state.scale,c=(i-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=n.rotation,this.initialRotation=Math.atan2(o-c,r-h)-n.rotation,this.unchangedObjects=n.objects.map((t=>t.clone()))}}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),n=t[0];if(!n)return;if(1===t.length){const t=this._core.store.selectionGroup;if(t&&this._core.store.state.isRotationHandleSelected){t.beginTransform();const e=Math.round(n.clientX-this._core.store.offsetX),i=Math.round(n.clientY-this._core.store.offsetY);this._core.store.state.isRotating=!0;const s=t.scale||1,r=t.translateX+t.width/2/s,o=t.translateY+t.height/2/s,h=(e-this._core.store.state.translateX)/this._core.store.state.scale,c=(i-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=t.rotation,this.initialRotation=Math.atan2(o-c,r-h)-t.rotation,this.unchangedObjects=t.objects.map((t=>t.clone())),clearTimeout(this._core.store.state.longTouchTimeout)}}}}handlePointerMove(t){if("mouse"===t.pointerType){const n=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&n){const e=n.scale||1,i=Math.atan2(n.translateY+n.height/2/e-(t.clientY-this._core.store.offsetY-this._core.store.state.translateY)/this._core.store.state.scale,n.translateX+n.width/2/e-(t.clientX-this._core.store.offsetX-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=i-this.initialRotation,n.rotate(this.rotation)}}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values())[0];if(!t)return;const n=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&n){const e=Math.round(t.clientX-this._core.store.offsetX),i=Math.round(t.clientY-this._core.store.offsetY),s=n.scale||1,r=Math.atan2(n.translateY+n.height/2/s-(i-this._core.store.state.translateY)/this._core.store.state.scale,n.translateX+n.width/2/s-(e-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=r-this.initialRotation,n.rotate(this.rotation),clearTimeout(this._core.store.state.longTouchTimeout)}}}handlePointerUp(t){"mouse"===t.pointerType&&this._core.store.state.isRotating&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.isRotating=!1,this._core.store.state.hasObjectsChanged=!0,this.reset()),"touch"===t.pointerType&&this._core.store.state.isRotating&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.isRotating=!1,this._core.store.state.hasObjectsChanged=!0,this.reset(),clearTimeout(this._core.store.state.longTouchTimeout))}}class Ct extends h{__class__="KritzelSelectionBox";static create(t){const n=new Ct;return n._core=t,n.id=n.generateId(),n.workspaceId=t.store.state.activeWorkspace.id,n.scale=t.store.state.scale,n.zIndex=99999,n.backgroundColor="var(--kritzel-selection-box-background-color, rgba(0, 122, 255, 0.2))",n.borderColor="var(--kritzel-selection-box-border-color, rgba(0, 122, 255, 0.5))",n.borderWidth=2,n.height=0,n.width=0,n}}class Tt extends At{startX;startY;touchStartX=0;touchStartY=0;touchStartTimeout=null;get isSelectionClick(){const t=this._core.store.selectionBox;return t&&0===t.width&&0===t.height}get isSelectionDrag(){const t=this._core.store.selectionBox;return t&&(t.width>0||t.height>0)}constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&a.isLeftClick(t)&&!this._core.store.selectionGroup&&this.startMouseSelection(t),"touch"===t.pointerType&&(this.touchStartTimeout=setTimeout((()=>{1!==this._core.store.state.pointers.size||this._core.store.state.isScaling||this._core.store.selectionGroup||(this.startTouchSelection(),this.updateTouchSelection())}),80))}handlePointerMove(t){if("mouse"===t.pointerType&&this._core.store.state.isSelecting&&this.updateMouseSelection(t),"touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),n=Math.round(t[0].clientX-this._core.store.offsetX),e=Math.round(t[0].clientY-this._core.store.offsetY),i=Math.abs(n-this.touchStartX),s=Math.abs(e-this.touchStartY),r=5;(i>r||s>r)&&this._core.store.state.isSelecting&&(this.updateTouchSelection(),clearTimeout(this._core.store.state.longTouchTimeout))}}handlePointerUp(t){if("mouse"===t.pointerType&&a.isLeftClick(t)){const n=this._core.store.state.hasObjectsChanged,e=this._core.store.selectionGroup;1===e?.objects.length&&!1===n&&e.objects[0].edit(t),this._core.store.state.hasObjectsChanged=!1,this._core.store.state.isSelecting&&(this.isSelectionClick&&this.handleSelectionClick(t),this.isSelectionDrag&&(this.updateMouseSelection(t),this.addSelectedObjectsToSelectionGroup(),this.removeSelectionBox()),this._core.engine.emitObjectsChange())}if("touch"===t.pointerType){clearTimeout(this.touchStartTimeout);const n=this._core.store.state.hasObjectsChanged,e=this._core.store.selectionGroup;1===e?.objects.length&&!1===n&&e.objects[0].edit(t),this._core.store.state.hasObjectsChanged=!1,this._core.store.state.isSelecting&&(this.isSelectionClick&&this.handleSelectionClick(t),this.isSelectionDrag&&(this.updateTouchSelection(),this.addSelectedObjectsToSelectionGroup(),this.removeSelectionBox()),this._core.engine.emitObjectsChange(),this._core.store.state.skipContextMenu=!1)}}removeSelectionBox(){this._core.store.state.isSelecting=!1,this._core.store.state.objects.remove((t=>t instanceof Ct))}startMouseSelection(t){let n,e;n=t.clientX-this._core.store.offsetX,e=t.clientY-this._core.store.offsetY;const i=Ct.create(this._core);this.startX=(n-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(e-this._core.store.state.translateY)/this._core.store.state.scale,i.translateX=this.startX,i.translateY=this.startY,this._core.store.state.isSelecting=!0,this._core.store.state.objects.remove((t=>t instanceof Ct||t instanceof D)),this._core.store.state.objects.insert(i)}startTouchSelection(){const t=Array.from(this._core.store.state.pointers.values())[0];if(!t)return;let n,e;n=Math.round(t.clientX-this._core.store.offsetX),e=Math.round(t.clientY-this._core.store.offsetY),this.touchStartX=n,this.touchStartY=e;const i=Ct.create(this._core);this.startX=(n-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(e-this._core.store.state.translateY)/this._core.store.state.scale,i.translateX=this.startX,i.translateY=this.startY,this._core.store.state.isSelecting=!0,this._core.store.state.objects.remove((t=>t instanceof Ct||t instanceof D)),this._core.store.state.objects.insert(i)}updateMouseSelection(t){let n,e;n=t.clientX-this._core.store.offsetX,e=t.clientY-this._core.store.offsetY;const i=this._core.store.selectionBox;if(i){const t=(n-this._core.store.state.translateX)/i.scale,s=(e-this._core.store.state.translateY)/i.scale,r=Math.abs(t-this.startX)*i.scale,o=Math.abs(s-this.startY)*i.scale;i.width=r,i.height=o,i.translateX=Math.min(t,this.startX),i.translateY=Math.min(s,this.startY),r>0||o>0?this.updateSelectedObjects():this.clearSelectionPreview()}}updateTouchSelection(){const t=Array.from(this._core.store.state.pointers.values())[0];if(!t)return;let n,e;n=Math.round(t.clientX-this._core.store.offsetX),e=Math.round(t.clientY-this._core.store.offsetY);const i=this._core.store.selectionBox;if(i){const t=(n-this._core.store.state.translateX)/i.scale,s=(e-this._core.store.state.translateY)/i.scale,r=Math.abs(t-this.startX)*i.scale,o=Math.abs(s-this.startY)*i.scale;i.width=r,i.height=o,i.translateX=Math.min(t,this.startX),i.translateY=Math.min(s,this.startY),r>0||o>0?this.updateSelectedObjects():this.clearSelectionPreview()}}updateSelectedObjects(){const t=this._core.store.selectionBox;t&&this._core.store.allObjects.filter((t=>!(t instanceof Ct))).forEach((n=>n.isSelected=n.hitTestPolygon(t.rotatedPolygon)))}handleSelectionClick(t){const n=this.getTopmostHitObject(t);this.clearSelectionPreview(),this.addObjectToSelectionGroup(n),this.removeSelectionBox()}getTopmostHitObject(t){const n=this._core.store.state.pointerX,e=this._core.store.state.pointerY,i=this._core.getObjectsFromPointerEvent(t,".object");for(const t of i)if(t.hitTest(n,e))return t;return null}clearSelectionPreview(){this._core.store.allNonSelectionObjects.forEach((t=>{t.isSelected=!1}))}addObjectToSelectionGroup(t){if(!t)return;const n=P.findParentGroup(this._core,t.id)||t;n.isSelected=!1;const e=D.create(this._core);e.addOrRemove(n),e.isSelected=!0,e.rotation=n.rotation,this._core.addSelectionGroup(e),this._core.rerender()}addSelectedObjectsToSelectionGroup(){const t=this._core.store.selectedObjects;if(0===t.length)return;const n=new Map;t.forEach((t=>{const e=P.findParentGroup(this._core,t.id);e?n.set(e.id,e):n.set(t.id,t),t.isSelected=!1}));const e=D.create(this._core);n.forEach((t=>{e.addOrRemove(t)})),e.isSelected=!0,1===e.length&&(e.rotation=e.objects[0].rotation),this._core.addSelectionGroup(e),this._core.rerender()}}class jt extends At{constructor(t){super(t)}handlePointerMove(t){if("mouse"===t.pointerType){const n=this._core.getObjectFromPointerEvent(t,".object");if(!n)return;n.isHovered=n.hitTest(this._core.store.state.pointerX,this._core.store.state.pointerY)}}}class Ut extends At{initialMouseX=0;initialMouseY=0;initialStartX=0;initialStartY=0;initialEndX=0;initialEndY=0;initialControlX;initialControlY;initialTranslateX=0;initialTranslateY=0;hasMoved=!1;currentSnapTarget=null;constructor(t){super(t)}reset(){this.initialMouseX=0,this.initialMouseY=0,this.initialStartX=0,this.initialStartY=0,this.initialEndX=0,this.initialEndY=0,this.initialControlX=void 0,this.initialControlY=void 0,this.initialTranslateX=0,this.initialTranslateY=0,this.hasMoved=!1,this.currentSnapTarget=null,this._core.anchorManager.clearSnapCandidate()}handlePointerDown(t){"mouse"===t.pointerType&&a.isLeftClick(t)&&this.startHandleDrag(t),"touch"===t.pointerType&&1===Array.from(this._core.store.state.pointers.values()).length&&this.startHandleDrag(t)}startHandleDrag(t){const n=this.getSelectedLine();if(!n||!this._core.store.state.isLineHandleSelected)return;const e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;this._core.store.state.isLineHandleDragging=!0,this.initialMouseX=e,this.initialMouseY=i,this.initialStartX=n.startX,this.initialStartY=n.startY,this.initialEndX=n.endX,this.initialEndY=n.endY,this.initialControlX=n.controlX,this.initialControlY=n.controlY,this.initialTranslateX=n.translateX,this.initialTranslateY=n.translateY;const s=this._core.store.state.lineHandleType;"start"!==s&&"end"!==s||this._core.anchorManager.removeAnchor(n.id,s),clearTimeout(this._core.store.state.longTouchTimeout)}handlePointerMove(t){const n=this.getSelectedLine();if(!n||!this._core.store.state.isLineHandleDragging)return;const e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY,s=e-this.initialMouseX,r=i-this.initialMouseY;if((Math.abs(s)>3||Math.abs(r)>3)&&(this.hasMoved=!0),!this.hasMoved)return;const o=this._core.store.state.scale,h=n.scale||1,c=n.rotation,u=s/o,a=r/o,l=Math.cos(-c),f=Math.sin(-c),d=(u*l-a*f)*h,v=(u*f+a*l)*h,p=this._core.store.state.lineHandleType;if("start"===p){const t=(e-this._core.store.state.translateX)/o,s=(i-this._core.store.state.translateY)/o,r=n.endAnchor?.objectId,h=this._core.anchorManager.findSnapTarget(t,s,n.id,r);if(this.currentSnapTarget=h,h){const t=this.worldToLineLocal(n,h.centerX,h.centerY);this.updateLineEndpoint(n,t.x,t.y,this.initialEndX,this.initialEndY);const e=this.lineLocalToWorld(n,this.initialEndX,this.initialEndY),i=this._core.store.allNonSelectionObjects.find((t=>t.id===h.objectId));let s,r,o,c;if(i){const t=this._core.anchorManager.computeAnchorClipInfo(n,"start",i);t&&(s=t.worldX,r=t.worldY,o=t.t)}void 0!==n.controlX&&void 0!==n.controlY&&(c=this.lineLocalToWorld(n,n.controlX,n.controlY)),this._core.anchorManager.setSnapCandidate({objectId:h.objectId,endpoint:"start",centerX:h.centerX,centerY:h.centerY,lineEndpointX:e.x,lineEndpointY:e.y,controlX:c?.x,controlY:c?.y,t:o,edgeX:s,edgeY:r,lineStroke:n.stroke,lineStrokeWidth:n.strokeWidth/n.scale,arrowOffset:n.hasStartArrow?n.getArrowSize("start")/n.scale:void 0,arrowStyle:n.hasStartArrow?n.arrows?.start?.style:void 0,arrowFill:n.hasStartArrow?n.getArrowFill("start"):void 0})}else this.updateLineEndpoint(n,this.initialStartX+d,this.initialStartY+v,this.initialEndX,this.initialEndY),this._core.anchorManager.clearSnapCandidate()}else if("end"===p){const t=(e-this._core.store.state.translateX)/o,s=(i-this._core.store.state.translateY)/o,r=n.startAnchor?.objectId,h=this._core.anchorManager.findSnapTarget(t,s,n.id,r);if(this.currentSnapTarget=h,h){const t=this.worldToLineLocal(n,h.centerX,h.centerY);this.updateLineEndpoint(n,this.initialStartX,this.initialStartY,t.x,t.y);const e=this.lineLocalToWorld(n,this.initialStartX,this.initialStartY),i=this._core.store.allNonSelectionObjects.find((t=>t.id===h.objectId));let s,r,o,c;if(i){const t=this._core.anchorManager.computeAnchorClipInfo(n,"end",i);t&&(s=t.worldX,r=t.worldY,o=t.t)}void 0!==n.controlX&&void 0!==n.controlY&&(c=this.lineLocalToWorld(n,n.controlX,n.controlY)),this._core.anchorManager.setSnapCandidate({objectId:h.objectId,endpoint:"end",centerX:h.centerX,centerY:h.centerY,lineEndpointX:e.x,lineEndpointY:e.y,controlX:c?.x,controlY:c?.y,t:o,edgeX:s,edgeY:r,lineStroke:n.stroke,lineStrokeWidth:n.strokeWidth/n.scale,arrowOffset:n.hasEndArrow?n.getArrowSize("end")/n.scale:void 0,arrowStyle:n.hasEndArrow?n.arrows?.end?.style:void 0,arrowFill:n.hasEndArrow?n.getArrowFill("end"):void 0})}else this.updateLineEndpoint(n,this.initialStartX,this.initialStartY,this.initialEndX+d,this.initialEndY+v),this._core.anchorManager.clearSnapCandidate()}else if("center"===p){const t=(this.initialControlX??(this.initialStartX+this.initialEndX)/2)+2*d,e=(this.initialControlY??(this.initialStartY+this.initialEndY)/2)+2*v,i=n.startX,s=n.startY,r=n.endX,o=n.endY,h=r-i,c=o-s,u=h*h+c*c;let a,l,f=-1;0!==u&&(f=((t-i)*h+(e-s)*c)/u),f<0?(a=i,l=s):f>1?(a=r,l=o):(a=i+f*h,l=s+f*c);const p=t-a,w=e-l;Math.sqrt(p*p+w*w)<15?n.updateControlPoint(void 0,void 0):n.updateControlPoint(t,e)}this._core.rerender()}worldToLineLocal(t,n,e){const i=(n-t.translateX)*t.scale,s=(e-t.translateY)*t.scale,r=t.totalWidth/2,o=t.totalHeight/2,h=Math.cos(-t.rotation),c=Math.sin(-t.rotation);return{x:(i-r)*h-(s-o)*c+r+t.x,y:(i-r)*c+(s-o)*h+o+t.y}}lineLocalToWorld(t,n,e){const i=n-t.x,s=e-t.y,r=t.totalWidth/2,o=t.totalHeight/2,h=Math.cos(t.rotation),c=Math.sin(t.rotation);return{x:((i-r)*h-(s-o)*c+r)/t.scale+t.translateX,y:((i-r)*c+(s-o)*h+o)/t.scale+t.translateY}}updateLineEndpoint(t,n,e,i,s){const{minX:r,minY:o,maxX:h,maxY:c}=z.calculateBoundingBox(n,e,i,s,t.controlX,t.controlY,t.strokeWidth),u=h-r,a=c-o,{minX:l,minY:f,maxX:d,maxY:v}=z.calculateBoundingBox(this.initialStartX,this.initialStartY,this.initialEndX,this.initialEndY,this.initialControlX,this.initialControlY,t.strokeWidth),p=d-l,w=v-f,y=r-l+(u-p)/2,g=o-f+(a-w)/2,b=t.rotation,m=Math.cos(b),A=Math.sin(b),k=1/t.scale,M=this.initialTranslateX+k*(p-u)/2+k*(y*m-g*A),x=this.initialTranslateY+k*(w-a)/2+k*(y*A+g*m);t.startX=n,t.startY=e,t.endX=i,t.endY=s,t.x=r,t.y=o,t.width=u,t.height=a,t.translateX=M,t.translateY=x,t._adjustedPoints=null,this._core.store.state.objects.update(t)}handlePointerUp(t){if(this._core.store.state.isLineHandleDragging){const t=this.getSelectedLine(),n=this._core.store.state.lineHandleType;if(t&&this.hasMoved){!this.currentSnapTarget||"start"!==n&&"end"!==n||this._core.anchorManager.setAnchor(t.id,n,this.currentSnapTarget.objectId);const e=this._core.store.selectionGroup;e&&(e.refreshObjectDimensions(),e.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0)}this._core.store.state.isLineHandleDragging=!1,this.reset(),this._core.rerender()}}getSelectedLine(){const t=this._core.store.selectionGroup;if(!t||1!==t.objects.length)return null;const n=t.objects[0];return n instanceof z?n:null}}class Et extends u{selectionHandler;moveHandler;hoverHandler;resizeHandler;rotationHandler;lineHandleHandler;constructor(t){super(t),this.selectionHandler=new Tt(this._core),this.moveHandler=new kt(this._core),this.hoverHandler=new jt(this._core),this.resizeHandler=new xt(this._core),this.rotationHandler=new St(this._core),this.lineHandleHandler=new Ut(this._core)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){if(a.isLeftClick(t)){this._core.store.state.isResizeHandleSelected=this.isHandleSelected(t),this._core.store.state.isRotationHandleSelected=this.isRotationHandleSelected(t),this._core.store.state.isLineHandleSelected=this.isLineHandleSelected(t),this._core.store.state.resizeHandleType=this.getHandleType(t),this._core.store.state.lineHandleType=this.getLineHandleType(t);const n=this.getSelectedObject(t),e=this._core.store.selectionGroup;if(null!==n&&!(n&&e&&n.id!==e.id)||!e||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||(this._core.removeSelectionGroup(),this._core.rerender()),n&&!1===n.isSelected&&1===n?.objects.length&&n.objects[0].isInteractive)return}this.lineHandleHandler.handlePointerDown(t),this.moveHandler.handlePointerDown(t),this.selectionHandler.handlePointerDown(t),this.resizeHandler.handlePointerDown(t),this.rotationHandler.handlePointerDown(t),this._core.rerender()}if("touch"===t.pointerType){if(!0===this._core.store.state.isScaling)return;if(1===this._core.store.state.pointers.size){this._core.store.state.isResizeHandleSelected=this.isHandleSelected(t),this._core.store.state.isRotationHandleSelected=this.isRotationHandleSelected(t),this._core.store.state.isLineHandleSelected=this.isLineHandleSelected(t),this._core.store.state.resizeHandleType=this.getHandleType(t),this._core.store.state.lineHandleType=this.getLineHandleType(t);const n=this.getSelectedObject(t),e=this._core.store.selectionGroup,i=n&&e&&n.id!==e.id;!e&&n&&(this._core.store.state.skipContextMenu=!0),null!==n&&!i||!e||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||(this._core.removeSelectionGroup(),this._core.rerender())}this.lineHandleHandler.handlePointerDown(t),this.rotationHandler.handlePointerDown(t),this.resizeHandler.handlePointerDown(t),this.moveHandler.handlePointerDown(t),this.selectionHandler.handlePointerDown(t),this._core.rerender()}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&(this.lineHandleHandler.handlePointerMove(t),this.moveHandler.handlePointerMove(t),this.hoverHandler.handlePointerMove(t),this.selectionHandler.handlePointerMove(t),this.resizeHandler.handlePointerMove(t),this.rotationHandler.handlePointerMove(t),this._core.rerender()),"touch"===t.pointerType){if(!0===this._core.store.state.isScaling)return;this.lineHandleHandler.handlePointerMove(t),this.rotationHandler.handlePointerMove(t),this.resizeHandler.handlePointerMove(t),this.moveHandler.handlePointerMove(t),this.selectionHandler.handlePointerMove(t),this._core.rerender()}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&(this.lineHandleHandler.handlePointerUp(t),this.moveHandler.handlePointerUp(t),this.resizeHandler.handlePointerUp(t),this.rotationHandler.handlePointerUp(t),this.selectionHandler.handlePointerUp(t),this._core.rerender()),"touch"===t.pointerType){if(!0===this._core.store.state.isScaling)return;this.lineHandleHandler.handlePointerUp(t),this.rotationHandler.handlePointerUp(t),this.resizeHandler.handlePointerUp(t),this.moveHandler.handlePointerUp(t),this.selectionHandler.handlePointerUp(t),this._core.rerender()}}getSelectedObject(t){const n=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),e=this._core.findObjectById(n?.id);if(!e)return null;const{x:i,y:s}=this._core.getCanvasPoint(t);if(!e.hitTest(i,s))return null;if(e instanceof D)return e;{const t=D.create(this._core);return t.translateX=0,t.translateY=0,t.addOrRemove(e),t}}getHandleType(t){const n=this._core.store.state.host?.shadowRoot;if(!n)return;const e=n.elementsFromPoint(t.clientX,t.clientY).find((t=>t.classList.contains("resize-handle-overlay")));return e?.classList[1]}isHandleSelected(t){const n=this._core.store.state.host?.shadowRoot;return!!n&&n.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("resize-handle-overlay")))}isRotationHandleSelected(t){const n=this._core.store.state.host?.shadowRoot;return!!n&&n.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("rotation-handle-overlay")))}isLineHandleSelected(t){const n=this._core.store.state.host?.shadowRoot;return!!n&&n.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("selection-line-handle-overlay")))}getLineHandleType(t){const n=this._core.store.state.host?.shadowRoot;if(!n)return;const e=n.elementsFromPoint(t.clientX,t.clientY).find((t=>t.classList.contains("selection-line-handle-overlay")));return e?.classList[1]}}const $t=()=>new Map,_t=t=>{const n=$t();return t.forEach(((t,e)=>{n.set(e,t)})),n},It=(t,n,e)=>{let i=t.get(n);return void 0===i&&t.set(n,i=e()),i},Ot=()=>new Set,zt=t=>t[t.length-1],Pt=(t,n)=>{for(let e=0;e<n.length;e++)t.push(n[e])},Dt=Array.from,Ft=(t,n)=>{for(let e=0;e<t.length;e++)if(!n(t[e],e,t))return!1;return!0},Rt=(t,n)=>{for(let e=0;e<t.length;e++)if(n(t[e],e,t))return!0;return!1},Lt=Array.isArray;class Wt{constructor(){this._observers=$t()}on(t,n){return It(this._observers,t,Ot).add(n),n}once(t,n){const e=(...i)=>{this.off(t,e),n(...i)};this.on(t,e)}off(t,n){const e=this._observers.get(t);void 0!==e&&(e.delete(n),0===e.size&&this._observers.delete(t))}emit(t,n){return Dt((this._observers.get(t)||$t()).values()).forEach((t=>t(...n)))}destroy(){this._observers=$t()}}let Bt=class{constructor(){this._observers=$t()}on(t,n){It(this._observers,t,Ot).add(n)}once(t,n){const e=(...i)=>{this.off(t,e),n(...i)};this.on(t,e)}off(t,n){const e=this._observers.get(t);void 0!==e&&(e.delete(n),0===e.size&&this._observers.delete(t))}emit(t,n){return Dt((this._observers.get(t)||$t()).values()).forEach((t=>t(...n)))}destroy(){this._observers=$t()}};const Yt=Math.floor,Xt=Math.abs,Ht=(t,n)=>t<n?t:n,Kt=(t,n)=>t>n?t:n,Nt=Math.pow,Qt=t=>0!==t?t<0:1/t<0,Vt=64,Gt=128,qt=127,Jt=Number.MAX_SAFE_INTEGER,Zt=Number.MIN_SAFE_INTEGER,tn=Number.isInteger||(t=>"number"==typeof t&&isFinite(t)&&Yt(t)===t),nn=String.fromCharCode,en=/^\s*/g,sn=/([A-Z])/g,rn=(t,n)=>(t=>t.replace(en,""))(t.replace(sn,(t=>`${n}${(t=>t.toLowerCase())(t)}`))),on="undefined"!=typeof TextEncoder?new TextEncoder:null,hn=on?t=>on.encode(t):t=>{const n=unescape(encodeURIComponent(t)),e=n.length,i=new Uint8Array(e);for(let t=0;t<e;t++)i[t]=n.codePointAt(t);return i};let cn="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});cn&&1===cn.decode(new Uint8Array).length&&(cn=null);let un=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}};const an=()=>new un,ln=t=>{let n=t.cpos;for(let e=0;e<t.bufs.length;e++)n+=t.bufs[e].length;return n},fn=t=>{const n=new Uint8Array(ln(t));let e=0;for(let i=0;i<t.bufs.length;i++){const s=t.bufs[i];n.set(s,e),e+=s.length}return n.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),e),n},dn=(t,n)=>{const e=t.cbuf.length;t.cpos===e&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*e),t.cpos=0),t.cbuf[t.cpos++]=n},vn=dn,pn=(t,n)=>{for(;n>qt;)dn(t,Gt|qt&n),n=Yt(n/128);dn(t,qt&n)},wn=(t,n)=>{const e=Qt(n);for(e&&(n=-n),dn(t,(n>63?Gt:0)|(e?Vt:0)|63&n),n=Yt(n/64);n>0;)dn(t,(n>qt?Gt:0)|qt&n),n=Yt(n/128)},yn=new Uint8Array(3e4),gn=yn.length/3,bn=on&&on.encodeInto?(t,n)=>{if(n.length<gn){const e=on.encodeInto(n,yn).written||0;pn(t,e);for(let n=0;n<e;n++)dn(t,yn[n])}else An(t,hn(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),i=e.length;pn(t,i);for(let n=0;n<i;n++)dn(t,e.codePointAt(n))},mn=(t,n)=>{const e=t.cbuf.length,i=t.cpos,s=Ht(e-i,n.length),r=n.length-s;t.cbuf.set(n.subarray(0,s),i),t.cpos+=s,r>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(Kt(2*e,r)),t.cbuf.set(n.subarray(s)),t.cpos=r)},An=(t,n)=>{pn(t,n.byteLength),mn(t,n)},kn=(t,n)=>{((t,n)=>{const e=t.cbuf.length;e-t.cpos<n&&(t.bufs.push(new Uint8Array(t.cbuf.buffer,0,t.cpos)),t.cbuf=new Uint8Array(2*Kt(e,n)),t.cpos=0)})(t,n);const e=new DataView(t.cbuf.buffer,t.cpos,n);return t.cpos+=n,e},Mn=new DataView(new ArrayBuffer(4)),xn=(t,n)=>{switch(typeof n){case"string":dn(t,119),bn(t,n);break;case"number":tn(n)&&Xt(n)<=2147483647?(dn(t,125),wn(t,n)):(Mn.setFloat32(0,e=n),Mn.getFloat32(0)===e?(dn(t,124),((t,n)=>{kn(t,4).setFloat32(0,n,!1)})(t,n)):(dn(t,123),((t,n)=>{kn(t,8).setFloat64(0,n,!1)})(t,n)));break;case"bigint":dn(t,122),((t,n)=>{kn(t,8).setBigInt64(0,n,!1)})(t,n);break;case"object":if(null===n)dn(t,126);else if(Lt(n)){dn(t,117),pn(t,n.length);for(let e=0;e<n.length;e++)xn(t,n[e])}else if(n instanceof Uint8Array)dn(t,116),An(t,n);else{dn(t,118);const e=Object.keys(n);pn(t,e.length);for(let i=0;i<e.length;i++){const s=e[i];bn(t,s),xn(t,n[s])}}break;case"boolean":dn(t,n?120:121);break;default:dn(t,127)}var e};class Sn extends un{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&pn(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const Cn=t=>{t.count>0&&(wn(t.encoder,1===t.count?t.s:-t.s),t.count>1&&pn(t.encoder,t.count-2))};class Tn{constructor(){this.encoder=new un,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Cn(this),this.count=1,this.s=t)}toUint8Array(){return Cn(this),fn(this.encoder)}}const jn=t=>{t.count>0&&(wn(t.encoder,2*t.diff+(1===t.count?0:1)),t.count>1&&pn(t.encoder,t.count-2))};class Un{constructor(){this.encoder=new un,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(jn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return jn(this),fn(this.encoder)}}class En{constructor(){this.sarr=[],this.s="",this.lensE=new Tn}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new un;return this.sarr.push(this.s),this.s="",bn(t,this.sarr.join("")),mn(t,this.lensE.toUint8Array()),fn(t)}}const $n=t=>new Error(t),_n=()=>{throw $n("Method unimplemented")},In=()=>{throw $n("Unexpected case")},On=$n("Unexpected end of array"),zn=$n("Integer out of Range");let Pn=class{constructor(t){this.arr=t,this.pos=0}};const Dn=t=>new Pn(t),Fn=t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,Ln(t)),Rn=t=>t.arr[t.pos++],Ln=t=>{let n=0,e=1;const i=t.arr.length;for(;t.pos<i;){const i=t.arr[t.pos++];if(n+=(i&qt)*e,e*=128,i<Gt)return n;if(n>Jt)throw zn}throw On},Wn=t=>{let n=t.arr[t.pos++],e=63&n,i=64;const s=(n&Vt)>0?-1:1;if(!(n&Gt))return s*e;const r=t.arr.length;for(;t.pos<r;){if(n=t.arr[t.pos++],e+=(n&qt)*i,i*=128,n<Gt)return s*e;if(e>Jt)throw zn}throw On},Bn=cn?t=>cn.decode(Fn(t)):t=>{let n=Ln(t);if(0===n)return"";{let e=String.fromCodePoint(Rn(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(Rn(t));else for(;n>0;){const i=n<1e4?n:1e4,s=t.arr.subarray(t.pos,t.pos+i);t.pos+=i,e+=String.fromCodePoint.apply(null,s),n-=i}return decodeURIComponent(escape(e))}},Yn=(t,n)=>{const e=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,n);return t.pos+=n,e},Xn=[()=>{},()=>null,Wn,t=>Yn(t,4).getFloat32(0,!1),t=>Yn(t,8).getFloat64(0,!1),t=>Yn(t,8).getBigInt64(0,!1),()=>!1,()=>!0,Bn,t=>{const n=Ln(t),e={};for(let i=0;i<n;i++)e[Bn(t)]=Hn(t);return e},t=>{const n=Ln(t),e=[];for(let i=0;i<n;i++)e.push(Hn(t));return e},Fn],Hn=t=>Xn[127-Rn(t)](t);class Kn extends Pn{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return 0===this.count&&(this.s=this.reader(this),this.count=this.pos!==this.arr.length?Ln(this)+1:-1),this.count--,this.s}}class Nn extends Pn{constructor(t){super(t),this.s=0,this.count=0}read(){if(0===this.count){this.s=Wn(this);const t=Qt(this.s);this.count=1,t&&(this.s=-this.s,this.count=Ln(this)+2)}return this.count--,this.s}}class Qn extends Pn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const t=Wn(this),n=1&t;this.diff=Yt(t/2),this.count=1,n&&(this.count=Ln(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Vn{constructor(t){this.decoder=new Nn(t),this.str=Bn(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const Gn=crypto.getRandomValues.bind(crypto),qn=()=>Gn(new Uint32Array(1))[0],Jn=[1e7]+-1e3+-4e3+-8e3+-1e11,Zn=()=>Jn.replace(/[018]/g,(t=>(t^qn()&15>>t/4).toString(16))),te=Date.now,ne=t=>new Promise(t);Promise.all.bind(Promise);let ee=new class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},ie=!0;try{"undefined"!=typeof localStorage&&localStorage&&(ee=localStorage,ie=!1)}catch(B){}const se=ee,re=t=>ie||addEventListener("storage",t),oe=t=>ie||removeEventListener("storage",t),he=Symbol("Equality"),ce=(t,n)=>t===n||!!t?.[he]?.(n)||!1,ue=Object.assign,ae=Object.keys,le=(t,n)=>{const e=[];for(const i in t)e.push(n(t[i],i));return e},fe=t=>ae(t).length,de=(t,n)=>{for(const e in t)if(!n(t[e],e))return!1;return!0},ve=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),pe=Object.freeze,we=t=>{for(const n in t){const e=t[n];"object"!=typeof e&&"function"!=typeof e||we(t[n])}return pe(t)},ye=(t,n,e=0)=>{try{for(;e<t.length;e++)t[e](...n)}finally{e<t.length&&ye(t,n,e+1)}},ge=t=>t,be=(t,n)=>{if(t===n)return!0;if(null==t||null==n||t.constructor!==n.constructor&&(t.constructor||Object)!==(n.constructor||Object))return!1;if(null!=t[he])return t[he](n);switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),n=new Uint8Array(n);case Uint8Array:if(t.byteLength!==n.byteLength)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;break;case Set:if(t.size!==n.size)return!1;for(const e of t)if(!n.has(e))return!1;break;case Map:if(t.size!==n.size)return!1;for(const e of t.keys())if(!n.has(e)||!be(t.get(e),n.get(e)))return!1;break;case void 0:case Object:if(fe(t)!==fe(n))return!1;for(const e in t)if(!ve(t,e)||!be(t[e],n[e]))return!1;break;case Array:if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(!be(t[e],n[e]))return!1;break;default:return!1}return!0},me="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),Ae="undefined"!=typeof window&&"undefined"!=typeof document&&!me;let ke;const Me=t=>(()=>{if(void 0===ke)if(me){ke=$t();const t=process.argv;let n=null;for(let e=0;e<t.length;e++){const i=t[e];"-"===i[0]?(null!==n&&ke.set(n,""),n=i):null!==n&&(ke.set(n,i),n=null)}null!==n&&ke.set(n,"")}else"object"==typeof location?(ke=$t(),(location.search||"?").slice(1).split("&").forEach((t=>{if(0!==t.length){const[n,e]=t.split("=");ke.set(`--${rn(n,"-")}`,e),ke.set(`-${rn(n,"-")}`,e)}}))):ke=$t();return ke})().has(t),xe=t=>{return void 0===(n=me?process.env[t.toUpperCase().replaceAll("-","_")]:se.getItem(t))?null:n;var n},Se=t=>Me("--"+t)||null!==xe(t),Ce=Se("production");var Te;const je=me&&(Te=process.env.FORCE_COLOR,["true","1","2"].includes(Te))||!Me("--no-colors")&&!Se("no-color")&&(!me||process.stdout.isTTY)&&(!me||Me("--color")||null!==xe("COLORTERM")||(xe("TERM")||"").includes("color")),Ue=t=>new Uint8Array(t),Ee=t=>new Uint8Array(t),$e=Ae?t=>{let n="";for(let e=0;e<t.byteLength;e++)n+=nn(t[e]);return btoa(n)}:t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),_e=Ae?t=>{const n=atob(t),e=Ue(n.length);for(let t=0;t<n.length;t++)e[t]=n.charCodeAt(t);return e}:t=>{const n=Buffer.from(t,"base64");return((t,n,e)=>new Uint8Array(t,n,e))(n.buffer,n.byteOffset,n.byteLength)};class Ie{constructor(t,n){this.left=t,this.right=n}}const Oe=(t,n)=>new Ie(t,n),ze=t=>t.next()>=.5,Pe=(t,n,e)=>Yt(t.next()*(e+1-n)+n),De=(t,n,e)=>Yt(t.next()*(e+1-n)+n),Fe=(t,n,e)=>De(t,n,e),Re=t=>nn(Fe(t,97,122)),Le=(t,n)=>n[Fe(t,0,n.length-1)],We=Symbol("0schema");class Be{constructor(){this._rerrs=[]}extend(t,n,e,i=null){this._rerrs.push({path:t,expected:n,has:e,message:i})}toString(){const t=[];for(let e=this._rerrs.length-1;e>0;e--){const i=this._rerrs[e];t.push((n=" ",(t=>{const e=new Array(t);for(let i=0;i<t;i++)e[i]=n;return e})(2*(this._rerrs.length-e)).join("")+`${null!=i.path?`[${i.path}] `:""}${i.has} doesn't match ${i.expected}. ${i.message}`))}var n;return t.join("\n")}}const Ye=(t,n)=>t===n||null!=t&&null!=n&&t.constructor===n.constructor&&(t[he]?ce(t,n):Lt(t)?Ft(t,(t=>Rt(n,(n=>Ye(t,n))))):!!(t=>"object"==typeof t)(t)&&de(t,((t,e)=>Ye(t,n[e]))));class Xe{static _dilutes=!1;extends(t){let[n,e]=[this.shape,t.shape];return this.constructor._dilutes&&([e,n]=[n,e]),Ye(n,e)}equals(t){return this.constructor===t.constructor&&be(this.shape,t.shape)}[We](){return!0}[he](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){_n()}get nullable(){return bi(this,Oi)}get optional(){return new ni(this)}cast(t){return Fi(t,this),t}expect(t){return Fi(t,this),t}}class He extends Xe{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const e=t?.constructor===this.shape&&(null==this._c||this._c(t));return!e&&n?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),e}}const Ke=(t,n=null)=>new He(t,n);Ke(He);class Ne extends Xe{constructor(t){super(),this.shape=t}check(t,n){const e=this.shape(t);return!e&&n?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),e}}const Qe=t=>new Ne(t);Ke(Ne);class Ve extends Xe{constructor(t){super(),this.shape=t}check(t,n){const e=this.shape.some((n=>n===t));return!e&&n?.extend(null,this.shape.join(" | "),t.toString()),e}}const Ge=(...t)=>new Ve(t),qe=Ke(Ve),Je=RegExp.escape||(t=>t.replace(/[().|&,$^[\]]/g,(t=>"\\"+t))),Ze=t=>Ui.check(t)?[Je(t)]:qe.check(t)?t.shape.map((t=>t+"")):ji.check(t)?["[+-]?\\d+.?\\d*"]:Ei.check(t)?[".*"]:mi.check(t)?t.shape.map(Ze).flat(1):void In();Ke(class extends Xe{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(Ze).map((t=>`(${t.join("|")})`)).join("")+"$")}check(t,n){const e=null!=this._r.exec(t);return!e&&n?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),e}});const ti=Symbol("optional");class ni extends Xe{constructor(t){super(),this.shape=t}check(t,n){const e=void 0===t||this.shape.check(t);return!e&&n?.extend(null,"undefined (optional)","()"),e}get[ti](){return!0}}const ei=Ke(ni);Ke(class extends Xe{check(t,n){return n?.extend(null,"never",typeof t),!1}});class ii extends Xe{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}static _dilutes=!0;get partial(){return new ii(this.shape,!0)}check(t,n){return null==t?(n?.extend(null,"object","null"),!1):de(this.shape,((e,i)=>{const s=this._isPartial&&!ve(t,i)||e.check(t[i],n);return!s&&n?.extend(i.toString(),e.toString(),typeof t[i],"Object property does not match"),s}))}}const si=Ke(ii),ri=Qe((t=>null!=t&&(t.constructor===Object||null==t.constructor)));class oi extends Xe{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return null!=t&&de(t,((e,i)=>{const s=this.shape.keys.check(i,n);return!s&&n?.extend(i+"","Record",typeof t,s?"Key doesn't match schema":"Value doesn't match value"),s&&this.shape.values.check(e,n)}))}}const hi=(t,n)=>new oi(t,n),ci=Ke(oi);class ui extends Xe{constructor(t){super(),this.shape=t}check(t,n){return null!=t&&de(this.shape,((e,i)=>{const s=e.check(t[i],n);return!s&&n?.extend(i.toString(),"Tuple",typeof e),s}))}}Ke(ui);class ai extends Xe{constructor(t){super(),this.shape=1===t.length?t[0]:new gi(t)}check(t,n){const e=Lt(t)&&Ft(t,(t=>this.shape.check(t)));return!e&&n?.extend(null,"Array",""),e}}const li=(...t)=>new ai(t),fi=Ke(ai),di=Qe((t=>Lt(t)));class vi extends Xe{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const e=t instanceof this.shape&&(null==this._c||this._c(t));return!e&&n?.extend(null,this.shape.name,t?.constructor.name),e}}Ke(vi);const pi=((t,n=null)=>new vi(Xe,n))(),wi=Ke(class extends Xe{constructor(t){super(),this.len=t.length-1,this.args=((...t)=>new ui(t))(...t.slice(-1)),this.res=t[this.len]}check(t,n){const e=t.constructor===Function&&t.length<=this.len;return!e&&n?.extend(null,"function",typeof t),e}}),yi=Qe((t=>"function"==typeof t));Ke(class extends Xe{constructor(t){super(),this.shape=t}check(t,n){const e=Ft(this.shape,(e=>e.check(t,n)));return!e&&n?.extend(null,"Intersectinon",typeof t),e}},(t=>t.shape.length>0));class gi extends Xe{static _dilutes=!0;constructor(t){super(),this.shape=t}check(t,n){const e=Rt(this.shape,(e=>e.check(t,n)));return n?.extend(null,"Union",typeof t),e}}const bi=(...t)=>t.findIndex((t=>mi.check(t)))>=0?bi(...t.map((t=>Di(t))).map((t=>mi.check(t)?t.shape:[t])).flat(1)):1===t.length?t[0]:new gi(t),mi=Ke(gi),Ai=()=>!0,ki=Qe(Ai),Mi=Ke(Ne,(t=>t.shape===Ai)),xi=Qe((t=>"bigint"==typeof t)),Si=Qe((t=>t===xi)),Ci=Qe((t=>"symbol"==typeof t));Qe((t=>t===Ci));const Ti=Qe((t=>"number"==typeof t)),ji=Qe((t=>t===Ti)),Ui=Qe((t=>"string"==typeof t)),Ei=Qe((t=>t===Ui)),$i=Qe((t=>"boolean"==typeof t)),_i=Qe((t=>t===$i)),Ii=Ge(void 0);Ke(Ve,(t=>1===t.shape.length&&void 0===t.shape[0])),Ge(void 0);const Oi=Ge(null),zi=Ke(Ve,(t=>1===t.shape.length&&null===t.shape[0]));Ke(Uint8Array),Ke(He,(t=>t.shape===Uint8Array));const Pi=bi(Ti,Ui,Oi,Ii,xi,$i,Ci);(()=>{const t=li(ki),n=hi(Ui,ki),e=bi(Ti,Ui,Oi,$i,t,n);t.shape=e,n.shape.values=e})();const Di=t=>{if(pi.check(t))return t;if(ri.check(t)){const n={};for(const e in t)n[e]=Di(t[e]);return new ii(n)}return di.check(t)?bi(...t.map(Di)):Pi.check(t)?Ge(t):yi.check(t)?Ke(t):void In()},Fi=Ce?()=>{}:(t,n)=>{const e=new Be;if(!n.check(t,e))throw $n(`Expected value to be of type ${n.constructor.name}.\n${e.toString()}`)};const Ri=(Li=ki,new class{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Di(t),h:n}),this}else(t){return this.if(ki,t)}done(){return(t,n)=>{for(let e=0;e<this.patterns.length;e++){const i=this.patterns[e];if(i.if.check(t))return i.h(t,n)}throw $n("Unhandled pattern")}}}(Li)).if(ji,((t,n)=>Pe(n,Zt,Jt))).if(Ei,((t,n)=>((t,n=0,e=20)=>{const i=Fe(t,n,e);let s="";for(let n=0;n<i;n++)s+=Re(t);return s})(n))).if(_i,((t,n)=>ze(n))).if(Si,((t,n)=>BigInt(Pe(n,Zt,Jt)))).if(mi,((t,n)=>Wi(n,Le(n,t.shape)))).if(si,((t,n)=>{const e={};for(const i in t.shape){let s=t.shape[i];if(ei.check(s)){if(ze(n))continue;s=s.shape}e[i]=Ri(s,n)}return e})).if(fi,((t,n)=>{const e=[],i=De(n,0,42);for(let s=0;s<i;s++)e.push(Wi(n,t.shape));return e})).if(qe,((t,n)=>Le(n,t.shape))).if(zi,(()=>null)).if(wi,((t,n)=>{const e=Wi(n,t.res);return()=>e})).if(Mi,((t,n)=>Wi(n,Le(n,[Ti,Ui,Oi,Ii,xi,$i,li(Ti),hi(bi("a","b","c"),Ti)])))).if(ci,((t,n)=>{const e={},i=Pe(n,0,3);for(let s=0;s<i;s++){const i=Wi(n,t.shape.keys),s=Wi(n,t.shape.values);e[i]=s}return e})).done();var Li;const Wi=(t,n)=>Ri(Di(n),t),Bi="undefined"!=typeof document?document:{};Qe((t=>t.nodeType===Ki)),"undefined"!=typeof DOMParser&&new DOMParser,Qe((t=>t.nodeType===Yi)),Qe((t=>t.nodeType===Xi));const Yi=Bi.ELEMENT_NODE,Xi=Bi.TEXT_NODE,Hi=Bi.DOCUMENT_NODE,Ki=Bi.DOCUMENT_FRAGMENT_NODE;Qe((t=>t.nodeType===Hi));const Ni=Symbol,Qi=Ni(),Vi=Ni(),Gi=Ni(),qi=Ni(),Ji=Ni(),Zi=Ni(),ts=Ni(),ns=Ni(),es=Ni(),is={[Qi]:Oe("font-weight","bold"),[Vi]:Oe("font-weight","normal"),[Gi]:Oe("color","blue"),[Ji]:Oe("color","green"),[qi]:Oe("color","grey"),[Zi]:Oe("color","red"),[ts]:Oe("color","purple"),[ns]:Oe("color","orange"),[es]:Oe("color","black")},ss=je?t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const n=[],e=[],i=$t();let s=[],r=0;for(;r<t.length;r++){const s=t[r],o=is[s];if(void 0!==o)i.set(o.left,o.right);else{if(void 0===s)break;if(s.constructor!==String&&s.constructor!==Number)break;{const t=((t,n)=>{const e=[];for(const[i,s]of t)e.push(n(s,i));return e})(i,((t,n)=>`${n}:${t};`)).join("");r>0||t.length>0?(n.push("%c"+s),e.push(t)):n.push(s)}}}for(r>0&&(s=e,s.unshift(n.join("")));r<t.length;r++){const n=t[r];n instanceof Symbol||s.push(n)}return s}:t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const n=[],e=[];let i=0;for(;i<t.length;i++){const e=t[i];if(void 0===e)break;if(e.constructor===String||e.constructor===Number)n.push(e);else if(e.constructor===Object)break}for(i>0&&e.push(n.join(""));i<t.length;i++){const n=t[i];n instanceof Symbol||e.push(n)}return e},rs=(...t)=>{console.warn(...ss(t)),t.unshift(ns),os.forEach((n=>n.print(t)))},os=Ot(),hs=t=>({[Symbol.iterator](){return this},next:t}),cs=(t,n)=>hs((()=>{const{done:e,value:i}=t.next();return{done:e,value:e?void 0:n(i)}}));class us{constructor(t,n){this.clock=t,this.len=n}}class as{constructor(){this.clients=new Map}}const ls=(t,n,e)=>n.clients.forEach(((n,i)=>{const s=t.doc.store.clients.get(i);if(null!=s){const i=s[s.length-1],r=i.id.clock+i.length;for(let i=0,o=n[i];i<n.length&&o.clock<r;o=n[++i])ir(t,s,o.clock,o.len,e)}})),fs=(t,n)=>{const e=t.clients.get(n.client);return void 0!==e&&null!==((t,n)=>{let e=0,i=t.length-1;for(;e<=i;){const s=Yt((e+i)/2),r=t[s],o=r.clock;if(o<=n){if(n<o+r.len)return s;e=s+1}else i=s-1}return null})(e,n.clock)},ds=t=>{t.clients.forEach((t=>{let n,e;for(t.sort(((t,n)=>t.clock-n.clock)),n=1,e=1;n<t.length;n++){const i=t[e-1],s=t[n];i.clock+i.len>=s.clock?i.len=Kt(i.len,s.clock+s.len-i.clock):(e<n&&(t[e]=s),e++)}t.length=e}))},vs=t=>{const n=new as;for(let e=0;e<t.length;e++)t[e].clients.forEach(((i,s)=>{if(!n.clients.has(s)){const r=i.slice();for(let n=e+1;n<t.length;n++)Pt(r,t[n].clients.get(s)||[]);n.clients.set(s,r)}}));return ds(n),n},ps=(t,n,e,i)=>{It(t.clients,n,(()=>[])).push(new us(e,i))},ws=(t,n)=>{pn(t.restEncoder,n.clients.size),Dt(n.clients.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([n,e])=>{t.resetDsCurVal(),pn(t.restEncoder,n);const i=e.length;pn(t.restEncoder,i);for(let n=0;n<i;n++){const i=e[n];t.writeDsClock(i.clock),t.writeDsLen(i.len)}}))},ys=t=>{const n=new as,e=Ln(t.restDecoder);for(let i=0;i<e;i++){t.resetDsCurVal();const e=Ln(t.restDecoder),i=Ln(t.restDecoder);if(i>0){const s=It(n.clients,e,(()=>[]));for(let n=0;n<i;n++)s.push(new us(t.readDsClock(),t.readDsLen()))}}return n},gs=(t,n,e)=>{const i=new as,s=Ln(t.restDecoder);for(let r=0;r<s;r++){t.resetDsCurVal();const s=Ln(t.restDecoder),r=Ln(t.restDecoder),o=e.clients.get(s)||[],h=Gs(e,s);for(let e=0;e<r;e++){const e=t.readDsClock(),r=e+t.readDsLen();if(e<h){h<r&&ps(i,s,h,r-h);let t=Js(o,e),c=o[t];for(!c.deleted&&c.id.clock<e&&(o.splice(t+1,0,No(n,c,e-c.id.clock)),t++);t<o.length&&(c=o[t++],c.id.clock<r);)c.deleted||(r<c.id.clock+c.length&&o.splice(t,0,No(n,c,r-c.id.clock)),c.delete(n))}else ps(i,s,e,r-e)}}if(i.clients.size>0){const t=new js;return pn(t.restEncoder,0),ws(t,i),t.toUint8Array()}return null},bs=qn;class ms extends Wt{constructor({guid:t=Zn(),collectionid:n=null,gc:e=!0,gcFilter:i=()=>!0,meta:s=null,autoLoad:r=!1,shouldLoad:o=!0}={}){super(),this.gc=e,this.gcFilter=i,this.clientID=bs(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Qs,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=r,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=ne((t=>{this.on("load",(()=>{this.isLoaded=!0,t(this)}))}));const h=()=>ne((t=>{const n=e=>{void 0!==e&&!0!==e||(this.off("sync",n),t())};this.on("sync",n)}));this.on("sync",(t=>{!1===t&&this.isSynced&&(this.whenSynced=h()),this.isSynced=void 0===t||!0===t,this.isSynced&&!this.isLoaded&&this.emit("load",[this])})),this.whenSynced=h()}load(){const t=this._item;null===t||this.shouldLoad||ur(t.parent.doc,(t=>{t.subdocsLoaded.add(this)}),null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Dt(this.subdocs).map((t=>t.guid)))}transact(t,n=null){return ur(this,t,n)}get(t,n=Or){const e=It(this.share,t,(()=>{const t=new n;return t._integrate(this,null),t})),i=e.constructor;if(n!==Or&&i!==n){if(i===Or){const i=new n;i._map=e._map,e._map.forEach((t=>{for(;null!==t;t=t.left)t.parent=i})),i._start=e._start;for(let t=i._start;null!==t;t=t.right)t.parent=i;return i._length=e._length,this.share.set(t,i),i._integrate(this,null),i}throw new Error(`Type with the name ${t} has already been defined with a different constructor`)}return e}getArray(t=""){return this.get(t,Jr)}getText(t=""){return this.get(t,yo)}getMap(t=""){return this.get(t,to)}getXmlElement(t=""){return this.get(t,mo)}getXmlFragment(t=""){return this.get(t,bo)}toJSON(){const t={};return this.share.forEach(((n,e)=>{t[e]=n.toJSON()})),t}destroy(){this.isDestroyed=!0,Dt(this.subdocs).forEach((t=>t.destroy()));const t=this._item;if(null!==t){this._item=null;const n=t.content;n.doc=new ms({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,ur(t.parent.doc,(e=>{t.deleted||e.subdocsAdded.add(n.doc),e.subdocsRemoved.add(this)}),null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class As{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return Ln(this.restDecoder)}readDsLen(){return Ln(this.restDecoder)}}class ks extends As{readLeftID(){return Xs(Ln(this.restDecoder),Ln(this.restDecoder))}readRightID(){return Xs(Ln(this.restDecoder),Ln(this.restDecoder))}readClient(){return Ln(this.restDecoder)}readInfo(){return Rn(this.restDecoder)}readString(){return Bn(this.restDecoder)}readParentInfo(){return 1===Ln(this.restDecoder)}readTypeRef(){return Ln(this.restDecoder)}readLen(){return Ln(this.restDecoder)}readAny(){return Hn(this.restDecoder)}readBuf(){return(t=>{const n=Ue(t.byteLength);return n.set(t),n})(Fn(this.restDecoder))}readJSON(){return JSON.parse(Bn(this.restDecoder))}readKey(){return Bn(this.restDecoder)}}class Ms{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Ln(this.restDecoder),this.dsCurrVal}readDsLen(){const t=Ln(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class xs extends Ms{constructor(t){super(t),this.keys=[],Ln(t),this.keyClockDecoder=new Qn(Fn(t)),this.clientDecoder=new Nn(Fn(t)),this.leftClockDecoder=new Qn(Fn(t)),this.rightClockDecoder=new Qn(Fn(t)),this.infoDecoder=new Kn(Fn(t),Rn),this.stringDecoder=new Vn(Fn(t)),this.parentInfoDecoder=new Kn(Fn(t),Rn),this.typeRefDecoder=new Nn(Fn(t)),this.lenDecoder=new Nn(Fn(t))}readLeftID(){return new Bs(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Bs(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Hn(this.restDecoder)}readBuf(){return Fn(this.restDecoder)}readJSON(){return Hn(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const t=this.stringDecoder.read();return this.keys.push(t),t}}}class Ss{constructor(){this.restEncoder=an()}toUint8Array(){return fn(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){pn(this.restEncoder,t)}writeDsLen(t){pn(this.restEncoder,t)}}class Cs extends Ss{writeLeftID(t){pn(this.restEncoder,t.client),pn(this.restEncoder,t.clock)}writeRightID(t){pn(this.restEncoder,t.client),pn(this.restEncoder,t.clock)}writeClient(t){pn(this.restEncoder,t)}writeInfo(t){vn(this.restEncoder,t)}writeString(t){bn(this.restEncoder,t)}writeParentInfo(t){pn(this.restEncoder,t?1:0)}writeTypeRef(t){pn(this.restEncoder,t)}writeLen(t){pn(this.restEncoder,t)}writeAny(t){xn(this.restEncoder,t)}writeBuf(t){An(this.restEncoder,t)}writeJSON(t){bn(this.restEncoder,JSON.stringify(t))}writeKey(t){bn(this.restEncoder,t)}}class Ts{constructor(){this.restEncoder=an(),this.dsCurrVal=0}toUint8Array(){return fn(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,pn(this.restEncoder,n)}writeDsLen(t){0===t&&In(),pn(this.restEncoder,t-1),this.dsCurrVal+=t}}class js extends Ts{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Un,this.clientEncoder=new Tn,this.leftClockEncoder=new Un,this.rightClockEncoder=new Un,this.infoEncoder=new Sn(vn),this.stringEncoder=new En,this.parentInfoEncoder=new Sn(vn),this.typeRefEncoder=new Tn,this.lenEncoder=new Tn}toUint8Array(){const t=an();return pn(t,0),An(t,this.keyClockEncoder.toUint8Array()),An(t,this.clientEncoder.toUint8Array()),An(t,this.leftClockEncoder.toUint8Array()),An(t,this.rightClockEncoder.toUint8Array()),An(t,fn(this.infoEncoder)),An(t,this.stringEncoder.toUint8Array()),An(t,fn(this.parentInfoEncoder)),An(t,this.typeRefEncoder.toUint8Array()),An(t,this.lenEncoder.toUint8Array()),mn(t,fn(this.restEncoder)),fn(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){xn(this.restEncoder,t)}writeBuf(t){An(this.restEncoder,t)}writeJSON(t){xn(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);void 0===n?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const Us=(t,n,e)=>{const i=new Map;e.forEach(((t,e)=>{Gs(n,e)>t&&i.set(e,t)})),Vs(n).forEach(((t,n)=>{e.has(n)||i.set(n,0)})),pn(t.restEncoder,i.size),Dt(i.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([e,i])=>{((t,n,e,i)=>{i=Kt(i,n[0].id.clock);const s=Js(n,i);pn(t.restEncoder,n.length-s),t.writeClient(e),pn(t.restEncoder,i);const r=n[s];r.write(t,i-r.id.clock);for(let e=s+1;e<n.length;e++)n[e].write(t,0)})(t,n.clients.get(e),e,i)}))},Es=(t,n,e,i=xs)=>{const s=Dn(n);((t,n,e,i=new xs(t))=>{ur(n,(t=>{t.local=!1;let n=!1;const e=t.doc,s=e.store,r=((t,n)=>{const e=$t(),i=Ln(t.restDecoder);for(let s=0;s<i;s++){const i=Ln(t.restDecoder),s=new Array(i),r=t.readClient();let o=Ln(t.restDecoder);e.set(r,{i:0,refs:s});for(let e=0;e<i;e++){const i=t.readInfo();switch(31&i){case 0:{const n=t.readLen();s[e]=new So(Xs(r,o),n),o+=n;break}case 10:{const n=Ln(t.restDecoder);s[e]=new Zo(Xs(r,o),n),o+=n;break}default:{const h=!(192&i),c=new Go(Xs(r,o),null,(i&Gt)===Gt?t.readLeftID():null,null,(i&Vt)===Vt?t.readRightID():null,h?t.readParentInfo()?n.get(t.readString()):t.readLeftID():null,!h||32&~i?null:t.readString(),qo(t,i));s[e]=c,o+=c.length}}}}return e})(i,e),o=((t,n,e)=>{const i=[];let s=Dt(e.keys()).sort(((t,n)=>t-n));if(0===s.length)return null;const r=()=>{if(0===s.length)return null;let t=e.get(s[s.length-1]);for(;t.refs.length===t.i;){if(s.pop(),!(s.length>0))return null;t=e.get(s[s.length-1])}return t};let o=r();if(null===o)return null;const h=new Qs,c=new Map,u=(t,n)=>{const e=c.get(t);(null==e||e>n)&&c.set(t,n)};let a=o.refs[o.i++];const l=new Map,f=()=>{for(const t of i){const n=t.id.client,i=e.get(n);i?(i.i--,h.clients.set(n,i.refs.slice(i.i)),e.delete(n),i.i=0,i.refs=[]):h.clients.set(n,[t]),s=s.filter((t=>t!==n))}i.length=0};for(;;){if(a.constructor!==Zo){const s=It(l,a.id.client,(()=>Gs(n,a.id.client)))-a.id.clock;if(s<0)i.push(a),u(a.id.client,a.id.clock-1),f();else{const r=a.getMissing(t,n);if(null!==r){i.push(a);const t=e.get(r)||{refs:[],i:0};if(t.refs.length!==t.i){a=t.refs[t.i++];continue}u(r,Gs(n,r)),f()}else(0===s||s<a.length)&&(a.integrate(t,s),l.set(a.id.client,a.id.clock+a.length))}}if(i.length>0)a=i.pop();else if(null!==o&&o.i<o.refs.length)a=o.refs[o.i++];else{if(o=r(),null===o)break;a=o.refs[o.i++]}}if(h.clients.size>0){const t=new js;return Us(t,h,new Map),pn(t.restEncoder,0),{missing:c,update:t.toUint8Array()}}return null})(t,s,r),h=s.pendingStructs;if(h){for(const[t,e]of h.missing)if(e<Gs(s,t)){n=!0;break}if(o){for(const[t,n]of o.missing){const e=h.missing.get(t);(null==e||e>n)&&h.missing.set(t,n)}h.update=gr([h.update,o.update])}}else s.pendingStructs=o;const c=gs(i,t,s);if(s.pendingDs){const n=new xs(Dn(s.pendingDs));Ln(n.restDecoder);const e=gs(n,t,s);s.pendingDs=c&&e?gr([c,e]):c||e}else s.pendingDs=c;if(n){const n=s.pendingStructs.update;s.pendingStructs=null,Es(t.doc,n)}}),e,!1)})(s,t,e,new i(s))},$s=(t,n,e)=>Es(t,n,e,ks),_s=(t,n=new Uint8Array([0]),e=new js)=>{((t,n,e=new Map)=>{Us(t,n.store,e),ws(t,(t=>{const n=new as;return t.clients.forEach(((t,e)=>{const i=[];for(let n=0;n<t.length;n++){const e=t[n];if(e.deleted){const s=e.id.clock;let r=e.length;if(n+1<t.length)for(let e=t[n+1];n+1<t.length&&e.deleted;e=t[1+ ++n])r+=e.length;i.push(new us(s,r))}}i.length>0&&n.clients.set(e,i)})),n})(n.store))})(e,t,Os(n));const i=[e.toUint8Array()];if(t.store.pendingDs&&i.push(t.store.pendingDs),t.store.pendingStructs&&i.push(br(t.store.pendingStructs.update,n)),i.length>1){if(e.constructor===Cs)return wr(i.map(((t,n)=>0===n?t:Mr(t))));if(e.constructor===js)return gr(i)}return i[0]},Is=(t,n)=>_s(t,n,new Cs),Os=t=>(t=>{const n=new Map,e=Ln(t.restDecoder);for(let i=0;i<e;i++){const e=Ln(t.restDecoder),i=Ln(t.restDecoder);n.set(e,i)}return n})(new As(Dn(t))),zs=(t,n)=>(pn(t.restEncoder,n.size),Dt(n.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([n,e])=>{pn(t.restEncoder,n),pn(t.restEncoder,e)})),t),Ps=t=>((t,n=new Ts)=>(t instanceof Map?zs(n,t):((t,n)=>{zs(t,Vs(n.store))})(n,t),n.toUint8Array()))(t,new Ss);class Ds{constructor(){this.l=[]}}const Fs=()=>new Ds,Rs=(t,n)=>t.l.push(n),Ls=(t,n)=>{const e=t.l,i=e.length;t.l=e.filter((t=>n!==t)),i===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Ws=(t,n,e)=>ye(t.l,[n,e]);class Bs{constructor(t,n){this.client=t,this.clock=n}}const Ys=(t,n)=>t===n||null!==t&&null!==n&&t.client===n.client&&t.clock===n.clock,Xs=(t,n)=>new Bs(t,n),Hs=(t,n)=>{for(;null!==n;){if(n.parent===t)return!0;n=n.parent._item}return!1},Ks=(t,n)=>void 0===n?!t.deleted:n.sv.has(t.id.client)&&(n.sv.get(t.id.client)||0)>t.id.clock&&!fs(n.ds,t.id),Ns=(t,n)=>{const e=It(t.meta,Ns,Ot),i=t.doc.store;e.has(n)||(n.sv.forEach(((n,e)=>{n<Gs(i,e)&&nr(t,Xs(e,n))})),ls(t,n.ds,(()=>{})),e.add(n))};class Qs{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Vs=t=>{const n=new Map;return t.clients.forEach(((t,e)=>{const i=t[t.length-1];n.set(e,i.id.clock+i.length)})),n},Gs=(t,n)=>{const e=t.clients.get(n);if(void 0===e)return 0;const i=e[e.length-1];return i.id.clock+i.length},qs=(t,n)=>{let e=t.clients.get(n.id.client);if(void 0===e)e=[],t.clients.set(n.id.client,e);else{const t=e[e.length-1];if(t.id.clock+t.length!==n.id.clock)throw In()}e.push(n)},Js=(t,n)=>{let e=0,i=t.length-1,s=t[i],r=s.id.clock;if(r===n)return i;let o=Yt(n/(r+s.length-1)*i);for(;e<=i;){if(s=t[o],r=s.id.clock,r<=n){if(n<r+s.length)return o;e=o+1}else i=o-1;o=Yt((e+i)/2)}throw In()},Zs=(t,n)=>{const e=t.clients.get(n.client);return e[Js(e,n.clock)]},tr=(t,n,e)=>{const i=Js(n,e),s=n[i];return s.id.clock<e&&s instanceof Go?(n.splice(i+1,0,No(t,s,e-s.id.clock)),i+1):i},nr=(t,n)=>{const e=t.doc.store.clients.get(n.client);return e[tr(t,e,n.clock)]},er=(t,n,e)=>{const i=n.clients.get(e.client),s=Js(i,e.clock),r=i[s];return e.clock!==r.id.clock+r.length-1&&r.constructor!==So&&i.splice(s+1,0,No(t,r,e.clock-r.id.clock+1)),r},ir=(t,n,e,i,s)=>{if(0===i)return;const r=e+i;let o,h=tr(t,n,e);do{o=n[h++],r<o.id.clock+o.length&&tr(t,n,r),s(o)}while(h<n.length&&n[h].id.clock<r)};class sr{constructor(t,n,e){this.doc=t,this.deleteSet=new as,this.beforeState=Vs(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=e,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const rr=(t,n)=>!(0===n.deleteSet.clients.size&&!(t=>{for(const[i,s]of t)if(e=s,n.beforeState.get(i)!==e)return!0;var e;return!1})(n.afterState)||(ds(n.deleteSet),((t,n)=>{Us(t,n.doc.store,n.beforeState)})(t,n),ws(t,n.deleteSet),0)),or=(t,n,e)=>{const i=n._item;(null===i||i.id.clock<(t.beforeState.get(i.id.client)||0)&&!i.deleted)&&It(t.changed,n,Ot).add(e)},hr=(t,n)=>{let e=t[n],i=t[n-1],s=n;for(;s>0&&i.deleted===e.deleted&&i.constructor===e.constructor&&i.mergeWith(e);e=i,i=t[--s-1])e instanceof Go&&null!==e.parentSub&&e.parent._map.get(e.parentSub)===e&&e.parent._map.set(e.parentSub,i);const r=n-s;return r&&t.splice(n+1-r,r),r},cr=(t,n)=>{if(n<t.length){const e=t[n],i=e.doc,s=i.store,r=e.deleteSet,o=e._mergeStructs;try{ds(r),e.afterState=Vs(e.doc.store),i.emit("beforeObserverCalls",[e,i]);const t=[];e.changed.forEach(((n,i)=>t.push((()=>{null!==i._item&&i._item.deleted||i._callObserver(e,n)})))),t.push((()=>{e.changedParentTypes.forEach(((t,n)=>{n._dEH.l.length>0&&(null===n._item||!n._item.deleted)&&((t=t.filter((t=>null===t.target._item||!t.target._item.deleted))).forEach((t=>{t.currentTarget=n,t._path=null})),t.sort(((t,n)=>t.path.length-n.path.length)),Ws(n._dEH,t,e))}))})),t.push((()=>i.emit("afterTransaction",[e,i]))),ye(t,[]),e._needFormattingCleanup&&vo(e)}finally{i.gc&&((t,n,e)=>{for(const[i,s]of t.clients.entries()){const t=n.clients.get(i);for(let i=s.length-1;i>=0;i--){const r=s[i],o=r.clock+r.len;for(let i=Js(t,r.clock),s=t[i];i<t.length&&s.id.clock<o;s=t[++i]){const s=t[i];if(r.clock+r.len<=s.id.clock)break;s instanceof Go&&s.deleted&&!s.keep&&e(s)&&s.gc(n,!1)}}}})(r,s,i.gcFilter),((t,n)=>{t.clients.forEach(((t,e)=>{const i=n.clients.get(e);for(let n=t.length-1;n>=0;n--){const e=t[n];for(let t=Ht(i.length-1,1+Js(i,e.clock+e.len-1)),n=i[t];t>0&&n.id.clock>=e.clock;n=i[t])t-=1+hr(i,t)}}))})(r,s),e.afterState.forEach(((t,n)=>{const i=e.beforeState.get(n)||0;if(i!==t){const t=s.clients.get(n),e=Kt(Js(t,i),1);for(let n=t.length-1;n>=e;)n-=1+hr(t,n)}}));for(let t=o.length-1;t>=0;t--){const{client:n,clock:e}=o[t].id,i=s.clients.get(n),r=Js(i,e);r+1<i.length&&hr(i,r+1)>1||r>0&&hr(i,r)}if(e.local||e.afterState.get(i.clientID)===e.beforeState.get(i.clientID)||(((...t)=>{console.log(...ss(t)),os.forEach((n=>n.print(t)))})(ns,Qi,"[yjs] ",Vi,Zi,"Changed the client-id because another client seems to be using it."),i.clientID=bs()),i.emit("afterTransactionCleanup",[e,i]),i._observers.has("update")){const t=new Cs;rr(t,e)&&i.emit("update",[t.toUint8Array(),e.origin,i,e])}if(i._observers.has("updateV2")){const t=new js;rr(t,e)&&i.emit("updateV2",[t.toUint8Array(),e.origin,i,e])}const{subdocsAdded:h,subdocsLoaded:c,subdocsRemoved:u}=e;(h.size>0||u.size>0||c.size>0)&&(h.forEach((t=>{t.clientID=i.clientID,null==t.collectionid&&(t.collectionid=i.collectionid),i.subdocs.add(t)})),u.forEach((t=>i.subdocs.delete(t))),i.emit("subdocs",[{loaded:c,added:h,removed:u},i,e]),u.forEach((t=>t.destroy()))),t.length<=n+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,t])):cr(t,n+1)}}},ur=(t,n,e=null,i=!0)=>{const s=t._transactionCleanups;let r=!1,o=null;null===t._transaction&&(r=!0,t._transaction=new sr(t,e,i),s.push(t._transaction),1===s.length&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{o=n(t._transaction)}finally{if(r){const n=t._transaction===s[0];t._transaction=null,n&&cr(s,0)}}return o};class ar{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const lr=(t,n,e)=>{ls(t,e.deletions,(e=>{e instanceof Go&&n.scope.some((n=>n===t.doc||Hs(n,e)))&&Ko(e,!1)}))},fr=(t,n,e)=>{let i=null;const s=t.doc,r=t.scope;ur(s,(e=>{for(;n.length>0&&null===t.currStackItem;){const i=s.store,o=n.pop(),h=new Set,c=[];let u=!1;ls(e,o.insertions,(t=>{if(t instanceof Go){if(null!==t.redone){let{item:n,diff:s}=Ho(i,t.id);s>0&&(n=nr(e,Xs(n.id.client,n.id.clock+s))),t=n}!t.deleted&&r.some((n=>n===e.doc||Hs(n,t)))&&c.push(t)}})),ls(e,o.deletions,(t=>{t instanceof Go&&r.some((n=>n===e.doc||Hs(n,t)))&&!fs(o.insertions,t.id)&&h.add(t)})),h.forEach((n=>{u=null!==Vo(e,n,h,o.insertions,t.ignoreRemoteMapChanges,t)||u}));for(let n=c.length-1;n>=0;n--){const i=c[n];t.deleteFilter(i)&&(i.delete(e),u=!0)}t.currStackItem=u?o:null}e.changed.forEach(((t,n)=>{t.has(null)&&n._searchMarker&&(n._searchMarker.length=0)})),i=e}),t);const o=t.currStackItem;return null!=o&&(t.emit("stack-item-popped",[{stackItem:o,type:e,changedParentTypes:i.changedParentTypes,origin:t},t]),t.currStackItem=null),o};class dr extends Wt{constructor(t,{captureTimeout:n=500,captureTransaction:e=()=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:r=!1,doc:o=(Lt(t)?t[0].doc:t instanceof ms?t:t.doc)}={}){super(),this.scope=[],this.doc=o,this.addToScope(t),this.deleteFilter=i,s.add(this),this.trackedOrigins=s,this.captureTransaction=e,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=r,this.captureTimeout=n,this.afterTransactionHandler=t=>{if(!(this.captureTransaction(t)&&this.scope.some((n=>t.changedParentTypes.has(n)||n===this.doc))&&(this.trackedOrigins.has(t.origin)||t.origin&&this.trackedOrigins.has(t.origin.constructor))))return;const n=this.undoing,e=this.redoing,i=n?this.redoStack:this.undoStack;n?this.stopCapturing():e||this.clear(!1,!0);const s=new as;t.afterState.forEach(((n,e)=>{const i=t.beforeState.get(e)||0,r=n-i;r>0&&ps(s,e,i,r)}));const r=te();let o=!1;if(this.lastChange>0&&r-this.lastChange<this.captureTimeout&&i.length>0&&!n&&!e){const n=i[i.length-1];n.deletions=vs([n.deletions,t.deleteSet]),n.insertions=vs([n.insertions,s])}else i.push(new ar(t.deleteSet,s)),o=!0;n||e||(this.lastChange=r),ls(t,t.deleteSet,(n=>{n instanceof Go&&this.scope.some((e=>e===t.doc||Hs(e,n)))&&Ko(n,!0)}));this.emit(o?"stack-item-added":"stack-item-updated",[{stackItem:i[i.length-1],origin:t.origin,type:n?"redo":"undo",changedParentTypes:t.changedParentTypes},this])},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",(()=>{this.destroy()}))}addToScope(t){const n=new Set(this.scope);(t=Lt(t)?t:[t]).forEach((t=>{n.has(t)||(n.add(t),(t instanceof Or?t.doc!==this.doc:t!==this.doc)&&rs("[yjs#509] Not same Y.Doc"),this.scope.push(t))}))}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact((e=>{t&&(this.undoStack.forEach((t=>lr(e,this,t))),this.undoStack=[]),n&&(this.redoStack.forEach((t=>lr(e,this,t))),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])}))}stopCapturing(){this.lastChange=0}undo(){let t;this.undoing=!0;try{t=fr(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){let t;this.redoing=!0;try{t=fr(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}class vr{constructor(t,n){this.gen=function*(t){const n=Ln(t.restDecoder);for(let e=0;e<n;e++){const n=Ln(t.restDecoder),e=t.readClient();let i=Ln(t.restDecoder);for(let s=0;s<n;s++){const n=t.readInfo();if(10===n){const n=Ln(t.restDecoder);yield new Zo(Xs(e,i),n),i+=n}else if(31&n){const s=!(192&n),r=new Go(Xs(e,i),null,(n&Gt)===Gt?t.readLeftID():null,null,(n&Vt)===Vt?t.readRightID():null,s?t.readParentInfo()?t.readString():t.readLeftID():null,!s||32&~n?null:t.readString(),qo(t,n));yield r,i+=r.length}else{const n=t.readLen();yield new So(Xs(e,i),n),i+=n}}}}(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===Zo);return this.curr}}class pr{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const wr=t=>gr(t,ks,Cs),yr=(t,n)=>{if(t.constructor===So){const{client:e,clock:i}=t.id;return new So(Xs(e,i+n),t.length-n)}if(t.constructor===Zo){const{client:e,clock:i}=t.id;return new Zo(Xs(e,i+n),t.length-n)}{const e=t,{client:i,clock:s}=e.id;return new Go(Xs(i,s+n),null,Xs(i,s+n-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n))}},gr=(t,n=xs,e=js)=>{if(1===t.length)return t[0];const i=t.map((t=>new n(Dn(t))));let s=i.map((t=>new vr(t,!0))),r=null;const o=new e,h=new pr(o);for(;s=s.filter((t=>null!==t.curr)),s.sort(((t,n)=>{if(t.curr.id.client===n.curr.id.client){const e=t.curr.id.clock-n.curr.id.clock;return 0===e?t.curr.constructor===n.curr.constructor?0:t.curr.constructor===Zo?1:-1:e}return n.curr.id.client-t.curr.id.client})),0!==s.length;){const t=s[0],n=t.curr.id.client;if(null!==r){let e=t.curr,i=!1;for(;null!==e&&e.id.clock+e.length<=r.struct.id.clock+r.struct.length&&e.id.client>=r.struct.id.client;)e=t.next(),i=!0;if(null===e||e.id.client!==n||i&&e.id.clock>r.struct.id.clock+r.struct.length)continue;if(n!==r.struct.id.client)Ar(h,r.struct,r.offset),r={struct:e,offset:0},t.next();else if(r.struct.id.clock+r.struct.length<e.id.clock)if(r.struct.constructor===Zo)r.struct.length=e.id.clock+e.length-r.struct.id.clock;else{Ar(h,r.struct,r.offset);const t=e.id.clock-r.struct.id.clock-r.struct.length;r={struct:new Zo(Xs(n,r.struct.id.clock+r.struct.length),t),offset:0}}else{const n=r.struct.id.clock+r.struct.length-e.id.clock;n>0&&(r.struct.constructor===Zo?r.struct.length-=n:e=yr(e,n)),r.struct.mergeWith(e)||(Ar(h,r.struct,r.offset),r={struct:e,offset:0},t.next())}}else r={struct:t.curr,offset:0},t.next();for(let e=t.curr;null!==e&&e.id.client===n&&e.id.clock===r.struct.id.clock+r.struct.length&&e.constructor!==Zo;e=t.next())Ar(h,r.struct,r.offset),r={struct:e,offset:0}}null!==r&&(Ar(h,r.struct,r.offset),r=null),kr(h);const c=i.map((t=>ys(t))),u=vs(c);return ws(o,u),o.toUint8Array()},br=(t,n,e=xs,i=js)=>{const s=Os(n),r=new i,o=new pr(r),h=new e(Dn(t)),c=new vr(h,!1);for(;c.curr;){const t=c.curr,n=t.id.client,e=s.get(n)||0;if(c.curr.constructor!==Zo)if(t.id.clock+t.length>e)for(Ar(o,t,Kt(e-t.id.clock,0)),c.next();c.curr&&c.curr.id.client===n;)Ar(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===n&&c.curr.id.clock+c.curr.length<=e;)c.next();else c.next()}kr(o);const u=ys(h);return ws(r,u),r.toUint8Array()},mr=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:fn(t.encoder.restEncoder)}),t.encoder.restEncoder=an(),t.written=0)},Ar=(t,n,e)=>{t.written>0&&t.currClient!==n.id.client&&mr(t),0===t.written&&(t.currClient=n.id.client,t.encoder.writeClient(n.id.client),pn(t.encoder.restEncoder,n.id.clock+e)),n.write(t.encoder,e),t.written++},kr=t=>{mr(t);const n=t.encoder.restEncoder;pn(n,t.clientStructs.length);for(let e=0;e<t.clientStructs.length;e++){const i=t.clientStructs[e];pn(n,i.written),mn(n,i.restEncoder)}},Mr=t=>((t,n,e,i)=>{const s=new xs(Dn(t)),r=new vr(s,!1),o=new i,h=new pr(o);for(let t=r.curr;null!==t;t=r.next())Ar(h,n(t),0);kr(h);const c=ys(s);return ws(o,c),o.toUint8Array()})(t,ge,0,Cs),xr="You must not compute changes after the event-handler fired.";class Sr{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Cr(this.currentTarget,this.target))}deletes(t){return fs(this.transaction.deleteSet,t.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw $n(xr);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach((e=>{if(null!==e){const i=n._map.get(e);let s,r;if(this.adds(i)){let t=i.left;for(;null!==t&&this.adds(t);)t=t.left;if(this.deletes(i)){if(null===t||!this.deletes(t))return;s="delete",r=zt(t.content.getContent())}else null!==t&&this.deletes(t)?(s="update",r=zt(t.content.getContent())):(s="add",r=void 0)}else{if(!this.deletes(i))return;s="delete",r=zt(i.content.getContent())}t.set(e,{action:s,oldValue:r})}})),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(null===t){if(0===this.transaction.doc._transactionCleanups.length)throw $n(xr);const n=this.target,e=Ot(),i=Ot(),s=[];if(t={added:e,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(n).has(null)){let t=null;const r=()=>{t&&s.push(t)};for(let s=n._start;null!==s;s=s.right)s.deleted?this.deletes(s)&&!this.adds(s)&&(null!==t&&void 0!==t.delete||(r(),t={delete:0}),t.delete+=s.length,i.add(s)):this.adds(s)?(null!==t&&void 0!==t.insert||(r(),t={insert:[]}),t.insert=t.insert.concat(s.content.getContent()),e.add(s)):(null!==t&&void 0!==t.retain||(r(),t={retain:0}),t.retain+=s.length);null!==t&&void 0===t.retain&&r()}this._changes=t}return t}}const Cr=(t,n)=>{const e=[];for(;null!==n._item&&n!==t;){if(null!==n._item.parentSub)e.unshift(n._item.parentSub);else{let t=0,i=n._item.parent._start;for(;i!==n._item&&null!==i;)!i.deleted&&i.countable&&(t+=i.length),i=i.right;e.unshift(t)}n=n._item.parent}return e},Tr=()=>{rs("Invalid access: Add Yjs type to a document before reading data.")};let jr=0;class Ur{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=jr++}}const Er=(t,n,e)=>{t.p.marker=!1,t.p=n,n.marker=!0,t.index=e,t.timestamp=jr++},$r=(t,n)=>{if(null===t._start||0===n||null===t._searchMarker)return null;const e=0===t._searchMarker.length?null:t._searchMarker.reduce(((t,e)=>Xt(n-t.index)<Xt(n-e.index)?t:e));let i=t._start,s=0;for(null!==e&&(i=e.p,s=e.index,(t=>{t.timestamp=jr++})(e));null!==i.right&&s<n;){if(!i.deleted&&i.countable){if(n<s+i.length)break;s+=i.length}i=i.right}for(;null!==i.left&&s>n;)i=i.left,!i.deleted&&i.countable&&(s-=i.length);for(;null!==i.left&&i.left.id.client===i.id.client&&i.left.id.clock+i.left.length===i.id.clock;)i=i.left,!i.deleted&&i.countable&&(s-=i.length);return null!==e&&Xt(e.index-s)<i.parent.length/80?(Er(e,i,s),e):((t,n,e)=>{if(t.length>=80){const i=t.reduce(((t,n)=>t.timestamp<n.timestamp?t:n));return Er(i,n,e),i}{const i=new Ur(n,e);return t.push(i),i}})(t._searchMarker,i,s)},_r=(t,n,e)=>{for(let i=t.length-1;i>=0;i--){const s=t[i];if(e>0){let n=s.p;for(n.marker=!1;n&&(n.deleted||!n.countable);)n=n.left,n&&!n.deleted&&n.countable&&(s.index-=n.length);if(null===n||!0===n.marker){t.splice(i,1);continue}s.p=n,n.marker=!0}(n<s.index||e>0&&n===s.index)&&(s.index=Kt(n,s.index+e))}},Ir=(t,n,e)=>{const i=t,s=n.changedParentTypes;for(;It(s,t,(()=>[])).push(e),null!==t._item;)t=t._item.parent;Ws(i._eH,e,n)};class Or{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Fs(),this._dEH=Fs(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw _n()}clone(){throw _n()}_write(t){}get _first(){let t=this._start;for(;null!==t&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Rs(this._eH,t)}observeDeep(t){Rs(this._dEH,t)}unobserve(t){Ls(this._eH,t)}unobserveDeep(t){Ls(this._dEH,t)}toJSON(){}}const zr=(t,n,e)=>{t.doc??Tr(),n<0&&(n=t._length+n),e<0&&(e=t._length+e);let i=e-n;const s=[];let r=t._start;for(;null!==r&&i>0;){if(r.countable&&!r.deleted){const t=r.content.getContent();if(t.length<=n)n-=t.length;else{for(let e=n;e<t.length&&i>0;e++)s.push(t[e]),i--;n=0}}r=r.right}return s},Pr=t=>{t.doc??Tr();const n=[];let e=t._start;for(;null!==e;){if(e.countable&&!e.deleted){const t=e.content.getContent();for(let e=0;e<t.length;e++)n.push(t[e])}e=e.right}return n},Dr=(t,n)=>{let e=0,i=t._start;for(t.doc??Tr();null!==i;){if(i.countable&&!i.deleted){const s=i.content.getContent();for(let i=0;i<s.length;i++)n(s[i],e++,t)}i=i.right}},Fr=(t,n)=>{const e=[];return Dr(t,((i,s)=>{e.push(n(i,s,t))})),e},Rr=t=>{let n=t._start,e=null,i=0;return{[Symbol.iterator](){return this},next:()=>{if(null===e){for(;null!==n&&n.deleted;)n=n.right;if(null===n)return{done:!0,value:void 0};e=n.content.getContent(),i=0,n=n.right}const t=e[i++];return e.length<=i&&(e=null),{done:!1,value:t}}}},Lr=(t,n)=>{t.doc??Tr();const e=$r(t,n);let i=t._start;for(null!==e&&(i=e.p,n-=e.index);null!==i;i=i.right)if(!i.deleted&&i.countable){if(n<i.length)return i.content.getContent()[n];n-=i.length}},Wr=(t,n,e,i)=>{let s=e;const r=t.doc,o=r.clientID,h=r.store,c=null===e?n._start:e.right;let u=[];const a=()=>{u.length>0&&(s=new Go(Xs(o,Gs(h,o)),s,s&&s.lastId,c,c&&c.id,n,null,new Oo(u)),s.integrate(t,0),u=[])};i.forEach((e=>{if(null===e)u.push(e);else switch(e.constructor){case Number:case Object:case Boolean:case Array:case String:u.push(e);break;default:switch(a(),e.constructor){case Uint8Array:case ArrayBuffer:s=new Go(Xs(o,Gs(h,o)),s,s&&s.lastId,c,c&&c.id,n,null,new Co(new Uint8Array(e))),s.integrate(t,0);break;case ms:s=new Go(Xs(o,Gs(h,o)),s,s&&s.lastId,c,c&&c.id,n,null,new Uo(e)),s.integrate(t,0);break;default:if(!(e instanceof Or))throw new Error("Unexpected content type in insert operation");s=new Go(Xs(o,Gs(h,o)),s,s&&s.lastId,c,c&&c.id,n,null,new Xo(e)),s.integrate(t,0)}}})),a()},Br=()=>$n("Length exceeded!"),Yr=(t,n,e,i)=>{if(e>n._length)throw Br();if(0===e)return n._searchMarker&&_r(n._searchMarker,e,i.length),Wr(t,n,null,i);const s=e,r=$r(n,e);let o=n._start;for(null!==r&&(o=r.p,0==(e-=r.index)&&(o=o.prev,e+=o&&o.countable&&!o.deleted?o.length:0));null!==o;o=o.right)if(!o.deleted&&o.countable){if(e<=o.length){e<o.length&&nr(t,Xs(o.id.client,o.id.clock+e));break}e-=o.length}return n._searchMarker&&_r(n._searchMarker,s,i.length),Wr(t,n,o,i)},Xr=(t,n,e,i)=>{if(0===i)return;const s=e,r=i,o=$r(n,e);let h=n._start;for(null!==o&&(h=o.p,e-=o.index);null!==h&&e>0;h=h.right)!h.deleted&&h.countable&&(e<h.length&&nr(t,Xs(h.id.client,h.id.clock+e)),e-=h.length);for(;i>0&&null!==h;)h.deleted||(i<h.length&&nr(t,Xs(h.id.client,h.id.clock+i)),h.delete(t),i-=h.length),h=h.right;if(i>0)throw Br();n._searchMarker&&_r(n._searchMarker,s,-r+i)},Hr=(t,n,e)=>{const i=n._map.get(e);void 0!==i&&i.delete(t)},Kr=(t,n,e,i)=>{const s=n._map.get(e)||null,r=t.doc,o=r.clientID;let h;if(null==i)h=new Oo([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:h=new Oo([i]);break;case Uint8Array:h=new Co(i);break;case ms:h=new Uo(i);break;default:if(!(i instanceof Or))throw new Error("Unexpected content type");h=new Xo(i)}new Go(Xs(o,Gs(r.store,o)),s,s&&s.lastId,null,null,n,e,h).integrate(t,0)},Nr=(t,n)=>{t.doc??Tr();const e=t._map.get(n);return void 0===e||e.deleted?void 0:e.content.getContent()[e.length-1]},Qr=t=>{const n={};return t.doc??Tr(),t._map.forEach(((t,e)=>{t.deleted||(n[e]=t.content.getContent()[t.length-1])})),n},Vr=(t,n)=>{t.doc??Tr();const e=t._map.get(n);return void 0!==e&&!e.deleted},Gr=t=>{return t.doc??Tr(),n=t._map.entries(),e=t=>!t[1].deleted,hs((()=>{let t;do{t=n.next()}while(!t.done&&!e(t.value));return t}));var n,e};class qr extends Sr{}class Jr extends Or{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Jr;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Jr}clone(){const t=new Jr;return t.insert(0,this.toArray().map((t=>t instanceof Or?t.clone():t))),t}get length(){return this.doc??Tr(),this._length}_callObserver(t,n){super._callObserver(t,n),Ir(this,t,new qr(this,t))}insert(t,n){null!==this.doc?ur(this.doc,(e=>{Yr(e,this,t,n)})):this._prelimContent.splice(t,0,...n)}push(t){null!==this.doc?ur(this.doc,(n=>{((t,n,e)=>{let i=(n._searchMarker||[]).reduce(((t,n)=>n.index>t.index?n:t),{index:0,p:n._start}).p;if(i)for(;i.right;)i=i.right;Wr(t,n,i,e)})(n,this,t)})):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){null!==this.doc?ur(this.doc,(e=>{Xr(e,this,t,n)})):this._prelimContent.splice(t,n)}get(t){return Lr(this,t)}toArray(){return Pr(this)}slice(t=0,n=this.length){return zr(this,t,n)}toJSON(){return this.map((t=>t instanceof Or?t.toJSON():t))}map(t){return Fr(this,t)}forEach(t){Dr(this,t)}[Symbol.iterator](){return Rr(this)}_write(t){t.writeTypeRef(Do)}}class Zr extends Sr{constructor(t,n,e){super(t,n),this.keysChanged=e}}class to extends Or{constructor(t){super(),this._prelimContent=null,this._prelimContent=void 0===t?new Map:new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach(((t,n)=>{this.set(n,t)})),this._prelimContent=null}_copy(){return new to}clone(){const t=new to;return this.forEach(((n,e)=>{t.set(e,n instanceof Or?n.clone():n)})),t}_callObserver(t,n){Ir(this,t,new Zr(this,t,n))}toJSON(){this.doc??Tr();const t={};return this._map.forEach(((n,e)=>{if(!n.deleted){const i=n.content.getContent()[n.length-1];t[e]=i instanceof Or?i.toJSON():i}})),t}get size(){return[...Gr(this)].length}keys(){return cs(Gr(this),(t=>t[0]))}values(){return cs(Gr(this),(t=>t[1].content.getContent()[t[1].length-1]))}entries(){return cs(Gr(this),(t=>[t[0],t[1].content.getContent()[t[1].length-1]]))}forEach(t){this.doc??Tr(),this._map.forEach(((n,e)=>{n.deleted||t(n.content.getContent()[n.length-1],e,this)}))}[Symbol.iterator](){return this.entries()}delete(t){null!==this.doc?ur(this.doc,(n=>{Hr(n,this,t)})):this._prelimContent.delete(t)}set(t,n){return null!==this.doc?ur(this.doc,(e=>{Kr(e,this,t,n)})):this._prelimContent.set(t,n),n}get(t){return Nr(this,t)}has(t){return Vr(this,t)}clear(){null!==this.doc?ur(this.doc,(t=>{this.forEach((function(n,e,i){Hr(t,i,e)}))})):this._prelimContent.clear()}_write(t){t.writeTypeRef(Fo)}}const no=(t,n)=>t===n||"object"==typeof t&&"object"==typeof n&&t&&n&&((t,n)=>t===n||fe(t)===fe(n)&&de(t,((t,e)=>(void 0!==t||ve(n,e))&&ce(n[e],t))))(t,n);class eo{constructor(t,n,e,i){this.left=t,this.right=n,this.index=e,this.currentAttributes=i}forward(){null===this.right&&In(),this.right.content.constructor===$o?this.right.deleted||oo(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const io=(t,n,e)=>{for(;null!==n.right&&e>0;)n.right.content.constructor===$o?n.right.deleted||oo(n.currentAttributes,n.right.content):n.right.deleted||(e<n.right.length&&nr(t,Xs(n.right.id.client,n.right.id.clock+e)),n.index+=n.right.length,e-=n.right.length),n.left=n.right,n.right=n.right.right;return n},so=(t,n,e,i)=>{const s=new Map,r=i?$r(n,e):null;if(r){const n=new eo(r.p.left,r.p,r.index,s);return io(t,n,e-r.index)}{const i=new eo(null,n._start,0,s);return io(t,i,e)}},ro=(t,n,e,i)=>{for(;null!==e.right&&(!0===e.right.deleted||e.right.content.constructor===$o&&no(i.get(e.right.content.key),e.right.content.value));)e.right.deleted||i.delete(e.right.content.key),e.forward();const s=t.doc,r=s.clientID;i.forEach(((i,o)=>{const h=e.left,c=e.right,u=new Go(Xs(r,Gs(s.store,r)),h,h&&h.lastId,c,c&&c.id,n,null,new $o(o,i));u.integrate(t,0),e.right=u,e.forward()}))},oo=(t,n)=>{const{key:e,value:i}=n;null===i?t.delete(e):t.set(e,i)},ho=(t,n)=>{for(;null!==t.right&&(t.right.deleted||t.right.content.constructor===$o&&no(n[t.right.content.key]??null,t.right.content.value));)t.forward()},co=(t,n,e,i)=>{const s=t.doc,r=s.clientID,o=new Map;for(const h in i){const c=i[h],u=e.currentAttributes.get(h)??null;if(!no(u,c)){o.set(h,u);const{left:i,right:a}=e;e.right=new Go(Xs(r,Gs(s.store,r)),i,i&&i.lastId,a,a&&a.id,n,null,new $o(h,c)),e.right.integrate(t,0),e.forward()}}return o},uo=(t,n,e,i,s)=>{e.currentAttributes.forEach(((t,n)=>{void 0===s[n]&&(s[n]=null)}));const r=t.doc,o=r.clientID;ho(e,s);const h=co(t,n,e,s),c=i.constructor===String?new zo(i):i instanceof Or?new Xo(i):new Eo(i);let{left:u,right:a,index:l}=e;n._searchMarker&&_r(n._searchMarker,e.index,c.getLength()),a=new Go(Xs(o,Gs(r.store,o)),u,u&&u.lastId,a,a&&a.id,n,null,c),a.integrate(t,0),e.right=a,e.index=l,e.forward(),ro(t,n,e,h)},ao=(t,n,e,i,s)=>{const r=t.doc,o=r.clientID;ho(e,s);const h=co(t,n,e,s);t:for(;null!==e.right&&(i>0||h.size>0&&(e.right.deleted||e.right.content.constructor===$o));){if(!e.right.deleted)switch(e.right.content.constructor){case $o:{const{key:n,value:r}=e.right.content,o=s[n];if(void 0!==o){if(no(o,r))h.delete(n);else{if(0===i)break t;h.set(n,r)}e.right.delete(t)}else e.currentAttributes.set(n,r);break}default:i<e.right.length&&nr(t,Xs(e.right.id.client,e.right.id.clock+i)),i-=e.right.length}e.forward()}if(i>0){let s="";for(;i>0;i--)s+="\n";e.right=new Go(Xs(o,Gs(r.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,n,null,new zo(s)),e.right.integrate(t,0),e.forward()}ro(t,n,e,h)},lo=(t,n,e,i,s)=>{let r=n;const o=$t();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===$o){const t=r.content;o.set(t.key,t)}r=r.right}let h=0,c=!1;for(;n!==r;){if(e===n&&(c=!0),!n.deleted){const e=n.content;switch(e.constructor){case $o:{const{key:r,value:u}=e,a=i.get(r)??null;o.get(r)===e&&a!==u||(n.delete(t),h++,c||(s.get(r)??null)!==u||a===u||(null===a?s.delete(r):s.set(r,a))),c||n.deleted||oo(s,e);break}}}n=n.right}return h},fo=t=>{let n=0;return ur(t.doc,(e=>{let i=t._start,s=t._start,r=$t();const o=_t(r);for(;s;)!1===s.deleted&&(s.content.constructor===$o?oo(o,s.content):(n+=lo(e,i,s,r,o),r=_t(o),i=s)),s=s.right})),n},vo=t=>{const n=new Set,e=t.doc;for(const[i,s]of t.afterState.entries()){const r=t.beforeState.get(i)||0;s!==r&&ir(t,e.store.clients.get(i),r,s,(t=>{t.deleted||t.content.constructor!==$o||t.constructor===So||n.add(t.parent)}))}ur(e,(e=>{ls(t,t.deleteSet,(t=>{t instanceof So||!t.parent._hasFormatting||n.has(t.parent)||(t.content.constructor===$o?n.add(t.parent):((t,n)=>{for(;n&&n.right&&(n.right.deleted||!n.right.countable);)n=n.right;const e=new Set;for(;n&&(n.deleted||!n.countable);){if(!n.deleted&&n.content.constructor===$o){const i=n.content.key;e.has(i)?n.delete(t):e.add(i)}n=n.left}})(e,t))}));for(const t of n)fo(t)}))},po=(t,n,e)=>{const i=e,s=_t(n.currentAttributes),r=n.right;for(;e>0&&null!==n.right;){if(!1===n.right.deleted)switch(n.right.content.constructor){case Xo:case Eo:case zo:e<n.right.length&&nr(t,Xs(n.right.id.client,n.right.id.clock+e)),e-=n.right.length,n.right.delete(t)}n.forward()}r&&lo(t,r,n.right,s,n.currentAttributes);const o=(n.left||n.right).parent;return o._searchMarker&&_r(o._searchMarker,n.index,-i+e),n};class wo extends Sr{constructor(t,n,e){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,e.forEach((t=>{null===t?this.childListChanged=!0:this.keysChanged.add(t)}))}get changes(){if(null===this._changes){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(null===this._delta){const t=[];ur(this.target.doc,(n=>{const e=new Map,i=new Map;let s=this.target._start,r=null;const o={};let h="",c=0,u=0;const a=()=>{if(null!==r){let n=null;switch(r){case"delete":u>0&&(n={delete:u}),u=0;break;case"insert":("object"==typeof h||h.length>0)&&(n={insert:h},e.size>0&&(n.attributes={},e.forEach(((t,e)=>{null!==t&&(n.attributes[e]=t)})))),h="";break;case"retain":c>0&&(n={retain:c},(t=>{for(const n in t)return!1;return!0})(o)||(n.attributes=ue({},o))),c=0}n&&t.push(n),r=null}};for(;null!==s;){switch(s.content.constructor){case Xo:case Eo:this.adds(s)?this.deletes(s)||(a(),r="insert",h=s.content.getContent()[0],a()):this.deletes(s)?("delete"!==r&&(a(),r="delete"),u+=1):s.deleted||("retain"!==r&&(a(),r="retain"),c+=1);break;case zo:this.adds(s)?this.deletes(s)||("insert"!==r&&(a(),r="insert"),h+=s.content.str):this.deletes(s)?("delete"!==r&&(a(),r="delete"),u+=s.length):s.deleted||("retain"!==r&&(a(),r="retain"),c+=s.length);break;case $o:{const{key:t,value:h}=s.content;if(this.adds(s)){if(!this.deletes(s)){const c=e.get(t)??null;no(c,h)?null!==h&&s.delete(n):("retain"===r&&a(),no(h,i.get(t)??null)?delete o[t]:o[t]=h)}}else if(this.deletes(s)){i.set(t,h);const n=e.get(t)??null;no(n,h)||("retain"===r&&a(),o[t]=n)}else if(!s.deleted){i.set(t,h);const e=o[t];void 0!==e&&(no(e,h)?null!==e&&s.delete(n):("retain"===r&&a(),null===h?delete o[t]:o[t]=h))}s.deleted||("insert"===r&&a(),oo(e,s.content));break}}s=s.right}for(a();t.length>0;){const n=t[t.length-1];if(void 0===n.retain||void 0!==n.attributes)break;t.pop()}})),this._delta=t}return this._delta}}class yo extends Or{constructor(t){super(),this._pending=void 0!==t?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Tr(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach((t=>t()))}catch(t){console.error(t)}this._pending=null}_copy(){return new yo}clone(){const t=new yo;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const e=new wo(this,t,n);Ir(this,t,e),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??Tr();let t="",n=this._start;for(;null!==n;)!n.deleted&&n.countable&&n.content.constructor===zo&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){null!==this.doc?ur(this.doc,(e=>{const i=new eo(null,this._start,0,new Map);for(let s=0;s<t.length;s++){const r=t[s];if(void 0!==r.insert){const o=n||"string"!=typeof r.insert||s!==t.length-1||null!==i.right||"\n"!==r.insert.slice(-1)?r.insert:r.insert.slice(0,-1);("string"!=typeof o||o.length>0)&&uo(e,this,i,o,r.attributes||{})}else void 0!==r.retain?ao(e,this,i,r.retain,r.attributes||{}):void 0!==r.delete&&po(e,i,r.delete)}})):this._pending.push((()=>this.applyDelta(t)))}toDelta(t,n,e){this.doc??Tr();const i=[],s=new Map;let r="",o=this._start;function h(){if(r.length>0){const t={};let n=!1;s.forEach(((e,i)=>{n=!0,t[i]=e}));const e={insert:r};n&&(e.attributes=t),i.push(e),r=""}}const c=()=>{for(;null!==o;){if(Ks(o,t)||void 0!==n&&Ks(o,n))switch(o.content.constructor){case zo:{const i=s.get("ychange");void 0===t||Ks(o,t)?void 0===n||Ks(o,n)?void 0!==i&&(h(),s.delete("ychange")):void 0!==i&&i.user===o.id.client&&"added"===i.type||(h(),s.set("ychange",e?e("added",o.id):{type:"added"})):void 0!==i&&i.user===o.id.client&&"removed"===i.type||(h(),s.set("ychange",e?e("removed",o.id):{type:"removed"})),r+=o.content.str;break}case Xo:case Eo:{h();const t={insert:o.content.getContent()[0]};if(s.size>0){const n={};t.attributes=n,s.forEach(((t,e)=>{n[e]=t}))}i.push(t);break}case $o:Ks(o,t)&&(h(),oo(s,o.content))}o=o.right}h()};return t||n?ur(this.doc,(e=>{t&&Ns(e,t),n&&Ns(e,n),c()}),"cleanup"):c(),i}insert(t,n,e){if(n.length<=0)return;const i=this.doc;null!==i?ur(i,(i=>{const s=so(i,this,t,!e);e||(e={},s.currentAttributes.forEach(((t,n)=>{e[n]=t}))),uo(i,this,s,n,e)})):this._pending.push((()=>this.insert(t,n,e)))}insertEmbed(t,n,e){const i=this.doc;null!==i?ur(i,(i=>{const s=so(i,this,t,!e);uo(i,this,s,n,e||{})})):this._pending.push((()=>this.insertEmbed(t,n,e||{})))}delete(t,n){if(0===n)return;const e=this.doc;null!==e?ur(e,(e=>{po(e,so(e,this,t,!0),n)})):this._pending.push((()=>this.delete(t,n)))}format(t,n,e){if(0===n)return;const i=this.doc;null!==i?ur(i,(i=>{const s=so(i,this,t,!1);null!==s.right&&ao(i,this,s,n,e)})):this._pending.push((()=>this.format(t,n,e)))}removeAttribute(t){null!==this.doc?ur(this.doc,(n=>{Hr(n,this,t)})):this._pending.push((()=>this.removeAttribute(t)))}setAttribute(t,n){null!==this.doc?ur(this.doc,(e=>{Kr(e,this,t,n)})):this._pending.push((()=>this.setAttribute(t,n)))}getAttribute(t){return Nr(this,t)}getAttributes(){return Qr(this)}_write(t){t.writeTypeRef(Ro)}}class go{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??Tr()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(null!==t&&(!this._firstCall||t.deleted||!this._filter(n)))do{if(n=t.content.type,t.deleted||n.constructor!==mo&&n.constructor!==bo||null===n._start)for(;null!==t;){const n=t.next;if(null!==n){t=n;break}t=t.parent===this._root?null:t.parent._item}else t=n._start}while(null!==t&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,null===t?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class bo extends Or{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new bo}clone(){const t=new bo;return t.insert(0,this.toArray().map((t=>t instanceof Or?t.clone():t))),t}get length(){return this.doc??Tr(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(t){return new go(this,t)}querySelector(t){t=t.toUpperCase();const n=new go(this,(n=>n.nodeName&&n.nodeName.toUpperCase()===t)).next();return n.done?null:n.value}querySelectorAll(t){return t=t.toUpperCase(),Dt(new go(this,(n=>n.nodeName&&n.nodeName.toUpperCase()===t)))}_callObserver(t,n){Ir(this,t,new Ao(this,n,t))}toString(){return Fr(this,(t=>t.toString())).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},e){const i=t.createDocumentFragment();return void 0!==e&&e._createAssociation(i,this),Dr(this,(s=>{i.insertBefore(s.toDOM(t,n,e),null)})),i}insert(t,n){null!==this.doc?ur(this.doc,(e=>{Yr(e,this,t,n)})):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(null!==this.doc)ur(this.doc,(e=>{Wr(e,this,t&&t instanceof Or?t._item:t,n)}));else{const e=this._prelimContent,i=null===t?0:e.findIndex((n=>n===t))+1;if(0===i&&null!==t)throw $n("Reference item not found");e.splice(i,0,...n)}}delete(t,n=1){null!==this.doc?ur(this.doc,(e=>{Xr(e,this,t,n)})):this._prelimContent.splice(t,n)}toArray(){return Pr(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Lr(this,t)}slice(t=0,n=this.length){return zr(this,t,n)}forEach(t){Dr(this,t)}_write(t){t.writeTypeRef(Wo)}}class mo extends bo{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach(((t,n)=>{this.setAttribute(n,t)})),this._prelimAttrs=null}_copy(){return new mo(this.nodeName)}clone(){const t=new mo(this.nodeName);return((t,n)=>{for(const e in t)n(t[e],e)})(this.getAttributes(),((n,e)=>{t.setAttribute(e,n)})),t.insert(0,this.toArray().map((t=>t instanceof Or?t.clone():t))),t}toString(){const t=this.getAttributes(),n=[],e=[];for(const n in t)e.push(n);e.sort();const i=e.length;for(let s=0;s<i;s++){const i=e[s];n.push(i+'="'+t[i]+'"')}const s=this.nodeName.toLocaleLowerCase();return`<${s}${n.length>0?" "+n.join(" "):""}>${super.toString()}</${s}>`}removeAttribute(t){null!==this.doc?ur(this.doc,(n=>{Hr(n,this,t)})):this._prelimAttrs.delete(t)}setAttribute(t,n){null!==this.doc?ur(this.doc,(e=>{Kr(e,this,t,n)})):this._prelimAttrs.set(t,n)}getAttribute(t){return Nr(this,t)}hasAttribute(t){return Vr(this,t)}getAttributes(t){return t?((t,n)=>{const e={};return this._map.forEach(((t,i)=>{let s=t;for(;null!==s&&(!n.sv.has(s.id.client)||s.id.clock>=(n.sv.get(s.id.client)||0));)s=s.left;null!==s&&Ks(s,n)&&(e[i]=s.content.getContent()[s.length-1])})),e})(0,t):Qr(this)}toDOM(t=document,n={},e){const i=t.createElement(this.nodeName),s=this.getAttributes();for(const t in s){const n=s[t];"string"==typeof n&&i.setAttribute(t,n)}return Dr(this,(s=>{i.appendChild(s.toDOM(t,n,e))})),void 0!==e&&e._createAssociation(i,this),i}_write(t){t.writeTypeRef(Lo),t.writeKey(this.nodeName)}}class Ao extends Sr{constructor(t,n,e){super(t,e),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach((t=>{null===t?this.childListChanged=!0:this.attributesChanged.add(t)}))}}class ko extends to{constructor(t){super(),this.hookName=t}_copy(){return new ko(this.hookName)}clone(){const t=new ko(this.hookName);return this.forEach(((n,e)=>{t.set(e,n)})),t}toDOM(t=document,n={},e){const i=n[this.hookName];let s;return s=void 0!==i?i.createDom(this):document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),void 0!==e&&e._createAssociation(s,this),s}_write(t){t.writeTypeRef(Bo),t.writeKey(this.hookName)}}class Mo extends yo{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new Mo}clone(){const t=new Mo;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,e){const i=t.createTextNode(this.toString());return void 0!==e&&e._createAssociation(i,this),i}toString(){return this.toDelta().map((t=>{const n=[];for(const e in t.attributes){const i=[];for(const n in t.attributes[e])i.push({key:n,value:t.attributes[e][n]});i.sort(((t,n)=>t.key<n.key?-1:1)),n.push({nodeName:e,attrs:i})}n.sort(((t,n)=>t.nodeName<n.nodeName?-1:1));let e="";for(let t=0;t<n.length;t++){const i=n[t];e+=`<${i.nodeName}`;for(let t=0;t<i.attrs.length;t++){const n=i.attrs[t];e+=` ${n.key}="${n.value}"`}e+=">"}e+=t.insert;for(let t=n.length-1;t>=0;t--)e+=`</${n[t].nodeName}>`;return e})).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Yo)}}class xo{constructor(t,n){this.id=t,this.length=n}get deleted(){throw _n()}mergeWith(t){return!1}write(t,n,e){throw _n()}integrate(t,n){throw _n()}}class So extends xo{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),qs(t.doc.store,this)}write(t,n){t.writeInfo(0),t.writeLen(this.length-n)}getMissing(t,n){return null}}class Co{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Co(this.content)}splice(t){throw _n()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}class To{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new To(this.len)}splice(t){const n=new To(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){ps(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const jo=(t,n)=>new ms({guid:t,...n,shouldLoad:n.shouldLoad||n.autoLoad||!1});class Uo{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),null!==t.meta&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Uo(jo(this.doc.guid,this.opts))}splice(t){throw _n()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}class Eo{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Eo(this.embed)}splice(t){throw _n()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}class $o{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new $o(this.key,this.value)}splice(t){throw _n()}mergeWith(t){return!1}integrate(t,n){const e=n.parent;e._searchMarker=null,e._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}class _o{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new _o(this.arr)}splice(t){const n=new _o(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const e=this.arr.length;t.writeLen(e-n);for(let i=n;i<e;i++){const n=this.arr[i];t.writeString(void 0===n?"undefined":JSON.stringify(n))}}getRef(){return 2}}const Io="development"===xe("node_env");class Oo{constructor(t){this.arr=t,Io&&we(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Oo(this.arr)}splice(t){const n=new Oo(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const e=this.arr.length;t.writeLen(e-n);for(let i=n;i<e;i++)t.writeAny(this.arr[i])}getRef(){return 8}}class zo{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new zo(this.str)}splice(t){const n=new zo(this.str.slice(t));this.str=this.str.slice(0,t);const e=this.str.charCodeAt(t-1);return e>=55296&&e<=56319&&(this.str=this.str.slice(0,t-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(0===n?this.str:this.str.slice(n))}getRef(){return 4}}const Po=[()=>new Jr,()=>new to,()=>new yo,t=>new mo(t.readKey()),()=>new bo,t=>new ko(t.readKey()),()=>new Mo],Do=0,Fo=1,Ro=2,Lo=3,Wo=4,Bo=5,Yo=6;class Xo{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Xo(this.type._copy())}splice(t){throw _n()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;null!==n;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach((n=>{n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t)})),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;null!==n;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach((n=>{for(;null!==n;)n.gc(t,!0),n=n.left})),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const Ho=(t,n)=>{let e,i=n,s=0;do{s>0&&(i=Xs(i.client,i.clock+s)),e=Zs(t,i),s=i.clock-e.id.clock,i=e.redone}while(null!==i&&e instanceof Go);return{item:e,diff:s}},Ko=(t,n)=>{for(;null!==t&&t.keep!==n;)t.keep=n,t=t.parent._item},No=(t,n,e)=>{const{client:i,clock:s}=n.id,r=new Go(Xs(i,s+e),n,Xs(i,s+e-1),n.right,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e));return n.deleted&&r.markDeleted(),n.keep&&(r.keep=!0),null!==n.redone&&(r.redone=Xs(n.redone.client,n.redone.clock+e)),n.right=r,null!==r.right&&(r.right.left=r),t._mergeStructs.push(r),null!==r.parentSub&&null===r.right&&r.parent._map.set(r.parentSub,r),n.length=e,r},Qo=(t,n)=>Rt(t,(t=>fs(t.deletions,n))),Vo=(t,n,e,i,s,r)=>{const o=t.doc,h=o.store,c=o.clientID,u=n.redone;if(null!==u)return nr(t,u);let a,l=n.parent._item,f=null;if(null!==l&&!0===l.deleted){if(null===l.redone&&(!e.has(l)||null===Vo(t,l,e,i,s,r)))return null;for(;null!==l.redone;)l=nr(t,l.redone)}const d=null===l?n.parent:l.content.type;if(null===n.parentSub){for(f=n.left,a=n;null!==f;){let n=f;for(;null!==n&&n.parent._item!==l;)n=null===n.redone?null:nr(t,n.redone);if(null!==n&&n.parent._item===l){f=n;break}f=f.left}for(;null!==a;){let n=a;for(;null!==n&&n.parent._item!==l;)n=null===n.redone?null:nr(t,n.redone);if(null!==n&&n.parent._item===l){a=n;break}a=a.right}}else if(a=null,n.right&&!s){for(f=n;null!==f&&null!==f.right&&(f.right.redone||fs(i,f.right.id)||Qo(r.undoStack,f.right.id)||Qo(r.redoStack,f.right.id));)for(f=f.right;f.redone;)f=nr(t,f.redone);if(f&&null!==f.right)return null}else f=d._map.get(n.parentSub)||null;const v=Gs(h,c),p=Xs(c,v),w=new Go(p,f,f&&f.lastId,a,a&&a.id,d,n.parentSub,n.content.copy());return n.redone=p,Ko(w,!0),w.integrate(t,0),w};class Go extends xo{constructor(t,n,e,i,s,r,o,h){super(t,h.getLength()),this.origin=e,this.left=n,this.right=i,this.rightOrigin=s,this.parent=r,this.parentSub=o,this.redone=null,this.content=h,this.info=this.content.isCountable()?2:0}set marker(t){(8&this.info)>0!==t&&(this.info^=8)}get marker(){return(8&this.info)>0}get keep(){return(1&this.info)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(2&this.info)>0}get deleted(){return(4&this.info)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Gs(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Gs(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Bs&&this.id.client!==this.parent.client&&this.parent.clock>=Gs(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=er(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=nr(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===So||this.right&&this.right.constructor===So)this.parent=null;else if(this.parent){if(this.parent.constructor===Bs){const t=Zs(n,this.parent);this.parent=t.constructor===So?null:t.content.type}}else this.left&&this.left.constructor===Go?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Go&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=er(t,t.doc.store,Xs(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||null!==this.right.left)||this.left&&this.left.right!==this.right){let n,e=this.left;if(null!==e)n=e.right;else if(null!==this.parentSub)for(n=this.parent._map.get(this.parentSub)||null;null!==n&&null!==n.left;)n=n.left;else n=this.parent._start;const i=new Set,s=new Set;for(;null!==n&&n!==this.right;){if(s.add(n),i.add(n),Ys(this.origin,n.origin)){if(n.id.client<this.id.client)e=n,i.clear();else if(Ys(this.rightOrigin,n.rightOrigin))break}else{if(null===n.origin||!s.has(Zs(t.doc.store,n.origin)))break;i.has(Zs(t.doc.store,n.origin))||(e=n,i.clear())}n=n.right}this.left=e}if(null!==this.left)this.right=this.left.right,this.left.right=this;else{let t;if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start,this.parent._start=this;this.right=t}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(t)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),qs(t.doc.store,this),this.content.integrate(t,this),or(t,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(t)}else new So(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;null!==t&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;null!==t&&t.deleted;)t=t.left;return t}get lastId(){return 1===this.length?this.id:Xs(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Ys(t.origin,this.lastId)&&this.right===t&&Ys(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&null===this.redone&&null===t.redone&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach((n=>{n.p===t&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))})),t.keep&&(this.keep=!0),this.right=t.right,null!==this.right&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&null===this.parentSub&&(n._length-=this.length),this.markDeleted(),ps(t.deleteSet,this.id.client,this.id.clock,this.length),or(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw In();this.content.gc(t),n?((t,n,e)=>{const i=t.clients.get(n.id.client);i[Js(i,n.id.clock)]=e})(t,this,new So(this.id,this.length)):this.content=new To(this.length)}write(t,n){const e=n>0?Xs(this.id.client,this.id.clock+n-1):this.origin,i=this.rightOrigin,s=this.parentSub,r=31&this.content.getRef()|(null===e?0:Gt)|(null===i?0:Vt)|(null===s?0:32);if(t.writeInfo(r),null!==e&&t.writeLeftID(e),null!==i&&t.writeRightID(i),null===e&&null===i){const n=this.parent;if(void 0!==n._item){const e=n._item;if(null===e){const e=(t=>{for(const[n,e]of t.doc.share.entries())if(e===t)return n;throw In()})(n);t.writeParentInfo(!0),t.writeString(e)}else t.writeParentInfo(!1),t.writeLeftID(e.id)}else n.constructor===String?(t.writeParentInfo(!0),t.writeString(n)):n.constructor===Bs?(t.writeParentInfo(!1),t.writeLeftID(n)):In();null!==s&&t.writeString(s)}this.content.write(t,n)}}const qo=(t,n)=>Jo[31&n](t),Jo=[()=>{In()},t=>new To(t.readLen()),t=>{const n=t.readLen(),e=[];for(let i=0;i<n;i++){const n=t.readString();e.push("undefined"===n?void 0:JSON.parse(n))}return new _o(e)},t=>new Co(t.readBuf()),t=>new zo(t.readString()),t=>new Eo(t.readJSON()),t=>new $o(t.readKey(),t.readJSON()),t=>new Xo(Po[t.readTypeRef()](t)),t=>{const n=t.readLen(),e=[];for(let i=0;i<n;i++)e.push(t.readAny());return new Oo(e)},t=>new Uo(jo(t.readString(),t.readAny())),()=>{In()}];class Zo extends xo{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,n){In()}write(t,n){t.writeInfo(10),pn(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const th="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},nh="__ $YJS$ __";!0===th[nh]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),th[nh]=!0;const eh=t=>ne(((n,e)=>{t.onerror=t=>e(new Error(t.target.error)),t.onsuccess=t=>n(t.target.result)})),ih=(t,n,e="readwrite")=>{const i=t.transaction(n,e);return n.map((t=>ch(i,t)))},sh=(t,n)=>eh(t.count(n)),rh=(t,n)=>eh(t.delete(n)),oh=(t,n)=>eh(t.add(n)),hh=(t,n,e,i="next")=>((t,n)=>ne(((e,i)=>{t.onerror=i,t.onsuccess=async t=>{const i=t.target.result;if(null===i||!1===await n(i))return e();i.continue()}})))(t.openKeyCursor(n,i),(t=>e(t.key))),ch=(t,n)=>t.objectStore(n),uh="custom",ah="updates",lh=(t,n=()=>{},e=()=>{})=>{const[i]=ih(t.db,[ah]);return(s=i,o=t._dbref,r=IDBKeyRange.lowerBound(o,false),eh(s.getAll(r,undefined))).then((s=>{t._destroyed||(n(i),ur(t.doc,(()=>{s.forEach((n=>$s(t.doc,n)))}),t,!1),e(i))})).then((()=>((t,n=null)=>((t,n)=>{let e=null;return hh(t,n,(t=>(e=t,!1)),"prev").then((()=>e))})(t,n))(i).then((n=>{t._dbref=n+1})))).then((()=>sh(i).then((n=>{t._dbsize=n})))).then((()=>i));var s,r,o};class fh extends Bt{constructor(t,n){super(),this.doc=n,this.name=t,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=(t=>ne(((n,e)=>{const i=indexedDB.open(t);i.onupgradeneeded=t=>(t=>[["updates",{autoIncrement:!0}],["custom"]].forEach((n=>t.createObjectStore.apply(t,n))))(t.target.result),i.onerror=t=>e($n(t.target.error)),i.onsuccess=t=>{const e=t.target.result;e.onversionchange=()=>{e.close()},n(e)}})))(t),this.whenSynced=ne((t=>this.on("synced",(()=>t(this))))),this._db.then((t=>{this.db=t,lh(this,(t=>oh(t,Is(n))),(()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])}))})),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(t,n)=>{if(this.db&&n!==this){const[n]=ih(this.db,[ah]);oh(n,t),++this._dbsize>=500&&(null!==this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout((()=>{((t,n=!0)=>{lh(t).then((e=>{(n||t._dbsize>=500)&&oh(e,Is(t.doc)).then((()=>rh(e,IDBKeyRange.upperBound(t._dbref,!0)))).then((()=>sh(e).then((n=>{t._dbsize=n}))))}))})(this,!1),this._storeTimeoutId=null}),this._storeTimeout))}},n.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),n.on("destroy",this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off("update",this._storeUpdate),this.doc.off("destroy",this.destroy),this._destroyed=!0,this._db.then((t=>{t.close()}))}clearData(){return this.destroy().then((()=>{eh(indexedDB.deleteDatabase(this.name))}))}get(t){return this._db.then((n=>{const[e]=ih(n,[uh],"readonly");return((t,n)=>eh(t.get(n)))(e,t)}))}set(t,n){return this._db.then((e=>{const[i]=ih(e,[uh]);return((t,n,e)=>eh(t.put(n,e)))(i,n,t)}))}del(t){return this._db.then((n=>{const[e]=ih(n,[uh]);return rh(e,t)}))}}class dh{provider;isConnected=!1;constructor(t,n,e){const i=e?.name||t;this.provider=new fh(i,n),console.info(`IndexedDB Persistence initialized: ${i}`)}async connect(){if(!this.isConnected)return new Promise((t=>{this.provider.on("synced",(()=>{this.isConnected=!0,t()}))}))}disconnect(){this.isConnected=!1}destroy(){this.provider&&this.provider.destroy(),this.isConnected=!1}}const vh=Math.floor,ph=127,wh=Number.MAX_SAFE_INTEGER,yh="undefined"!=typeof TextEncoder?new TextEncoder:null,gh=yh?t=>yh.encode(t):t=>{const n=unescape(encodeURIComponent(t)),e=n.length,i=new Uint8Array(e);for(let t=0;t<e;t++)i[t]=n.codePointAt(t);return i};let bh="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});bh&&1===bh.decode(new Uint8Array).length&&(bh=null);const mh=(t,n)=>{const e=t.cbuf.length;t.cpos===e&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*e),t.cpos=0),t.cbuf[t.cpos++]=n},Ah=(t,n)=>{for(;n>ph;)mh(t,128|ph&n),n=vh(n/128);mh(t,ph&n)},kh=new Uint8Array(3e4),Mh=kh.length/3,xh=yh&&yh.encodeInto?(t,n)=>{if(n.length<Mh){const e=yh.encodeInto(n,kh).written||0;Ah(t,e);for(let n=0;n<e;n++)mh(t,kh[n])}else Sh(t,gh(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),i=e.length;Ah(t,i);for(let n=0;n<i;n++)mh(t,e.codePointAt(n))},Sh=(t,n)=>{Ah(t,n.byteLength),((t,n)=>{const e=t.cbuf.length,i=t.cpos,s=((t,n)=>t<n?t:n)(e-i,n.length),r=n.length-s;t.cbuf.set(n.subarray(0,s),i),t.cpos+=s,r>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(((t,n)=>t>n?t:n)(2*e,r)),t.cbuf.set(n.subarray(s)),t.cpos=r)})(t,n)},Ch=t=>new Error(t),Th=Ch("Unexpected end of array"),jh=Ch("Integer out of Range"),Uh=t=>t.arr[t.pos++],Eh=t=>{let n=0,e=1;const i=t.arr.length;for(;t.pos<i;){const i=t.arr[t.pos++];if(n+=(i&ph)*e,e*=128,i<128)return n;if(n>wh)throw jh}throw Th},$h=bh?t=>bh.decode((t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,Eh(t)))(t)):t=>{let n=Eh(t);if(0===n)return"";{let e=String.fromCodePoint(Uh(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(Uh(t));else for(;n>0;){const i=n<1e4?n:1e4,s=t.arr.subarray(t.pos,t.pos+i);t.pos+=i,e+=String.fromCodePoint.apply(null,s),n-=i}return decodeURIComponent(escape(e))}};var _h;!function(t){t[t.Token=0]="Token",t[t.PermissionDenied=1]="PermissionDenied",t[t.Authenticated=2]="Authenticated"}(_h||(_h={}));const Ih=t=>Array.from(t.entries()).map((([t,n])=>({clientId:t,...n})));var Oh;async function zh(t){return new Promise((n=>setTimeout(n,t)))}function Ph(t,n){let e=n.delay;if(0===e)return 0;if(n.factor&&(e*=Math.pow(n.factor,t.attemptNum-1),0!==n.maxDelay&&(e=Math.min(e,n.maxDelay))),n.jitter){const t=Math.ceil(n.minDelay),i=Math.floor(e);e=Math.floor(Math.random()*(i-t+1))+t}return Math.round(e)}!function(t){t[t.Connecting=0]="Connecting",t[t.Open=1]="Open",t[t.Closing=2]="Closing",t[t.Closed=3]="Closed"}(Oh||(Oh={}));const Dh=Math.floor,Fh=128,Rh=127,Lh=Number.MAX_SAFE_INTEGER,Wh=()=>new Set,Bh=Array.from,Yh="undefined"!=typeof TextEncoder?new TextEncoder:null,Xh=Yh?t=>Yh.encode(t):t=>{const n=unescape(encodeURIComponent(t)),e=n.length,i=new Uint8Array(e);for(let t=0;t<e;t++)i[t]=n.codePointAt(t);return i};let Hh="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Hh&&1===Hh.decode(new Uint8Array).length&&(Hh=null);class Kh{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Nh=()=>new Kh,Qh=t=>{let n=t.cpos;for(let e=0;e<t.bufs.length;e++)n+=t.bufs[e].length;return n},Vh=t=>{const n=new Uint8Array(Qh(t));let e=0;for(let i=0;i<t.bufs.length;i++){const s=t.bufs[i];n.set(s,e),e+=s.length}return n.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),e),n},Gh=(t,n)=>{const e=t.cbuf.length;t.cpos===e&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*e),t.cpos=0),t.cbuf[t.cpos++]=n},qh=(t,n)=>{for(;n>Rh;)Gh(t,Fh|Rh&n),n=Dh(n/128);Gh(t,Rh&n)},Jh=new Uint8Array(3e4),Zh=Jh.length/3,tc=Yh&&Yh.encodeInto?(t,n)=>{if(n.length<Zh){const e=Yh.encodeInto(n,Jh).written||0;qh(t,e);for(let n=0;n<e;n++)Gh(t,Jh[n])}else nc(t,Xh(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),i=e.length;qh(t,i);for(let n=0;n<i;n++)Gh(t,e.codePointAt(n))},nc=(t,n)=>{qh(t,n.byteLength),((t,n)=>{const e=t.cbuf.length,i=t.cpos,s=((t,n)=>t<n?t:n)(e-i,n.length),r=n.length-s;t.cbuf.set(n.subarray(0,s),i),t.cpos+=s,r>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(((t,n)=>t>n?t:n)(2*e,r)),t.cbuf.set(n.subarray(s)),t.cpos=r)})(t,n)},ec=t=>new Error(t),ic=ec("Unexpected end of array"),sc=ec("Integer out of Range");class rc{constructor(t){this.arr=t,this.pos=0}}const oc=t=>new rc(t),hc=t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,uc(t)),cc=t=>t.arr[t.pos++],uc=t=>{let n=0,e=1;const i=t.arr.length;for(;t.pos<i;){const i=t.arr[t.pos++];if(n+=(i&Rh)*e,e*=128,i<Fh)return n;if(n>Lh)throw sc}throw ic},ac=Hh?t=>Hh.decode(hc(t)):t=>{let n=uc(t);if(0===n)return"";{let e=String.fromCodePoint(cc(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(cc(t));else for(;n>0;){const i=n<1e4?n:1e4,s=t.arr.subarray(t.pos,t.pos+i);t.pos+=i,e+=String.fromCodePoint.apply(null,s),n-=i}return decodeURIComponent(escape(e))}},lc=Date.now,fc=()=>new Map;class dc{constructor(){this._observers=fc()}on(t,n){((t,n,e)=>{let i=t.get(n);return void 0===i&&t.set(n,i=e()),i})(this._observers,t,Wh).add(n)}once(t,n){const e=(...i)=>{this.off(t,e),n(...i)};this.on(t,e)}off(t,n){const e=this._observers.get(t);void 0!==e&&(e.delete(n),0===e.size&&this._observers.delete(t))}emit(t,n){return Bh((this._observers.get(t)||fc()).values()).forEach((t=>t(...n)))}destroy(){this._observers=fc()}}const vc=Object.keys,pc=t=>vc(t).length,wc=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),yc=(t,n)=>{if(null==t||null==n)return((t,n)=>t===n)(t,n);if(t.constructor!==n.constructor)return!1;if(t===n)return!0;switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),n=new Uint8Array(n);case Uint8Array:if(t.byteLength!==n.byteLength)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;break;case Set:if(t.size!==n.size)return!1;for(const e of t)if(!n.has(e))return!1;break;case Map:if(t.size!==n.size)return!1;for(const e of t.keys())if(!n.has(e)||!yc(t.get(e),n.get(e)))return!1;break;case Object:if(pc(t)!==pc(n))return!1;for(const e in t)if(!wc(t,e)||!yc(t[e],n[e]))return!1;break;case Array:if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(!yc(t[e],n[e]))return!1;break;default:return!1}return!0};class gc extends dc{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const t=lc();null!==this.getLocalState()&&15e3<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const n=[];this.meta.forEach(((e,i)=>{i!==this.clientID&&3e4<=t-e.lastUpdated&&this.states.has(i)&&n.push(i)})),n.length>0&&bc(this,n,"timeout")}),Dh(3e3)),t.on("destroy",(()=>{this.destroy()})),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(t){const n=this.clientID,e=this.meta.get(n),i=void 0===e?0:e.clock+1,s=this.states.get(n);null===t?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:i,lastUpdated:lc()});const r=[],o=[],h=[],c=[];null===t?c.push(n):null==s?null!=t&&r.push(n):(o.push(n),yc(s,t)||h.push(n)),(r.length>0||h.length>0||c.length>0)&&this.emit("change",[{added:r,updated:h,removed:c},"local"]),this.emit("update",[{added:r,updated:o,removed:c},"local"])}setLocalStateField(t,n){const e=this.getLocalState();null!==e&&this.setLocalState({...e,[t]:n})}getStates(){return this.states}}const bc=(t,n,e)=>{const i=[];for(let e=0;e<n.length;e++){const s=n[e];if(t.states.has(s)){if(t.states.delete(s),s===t.clientID){const n=t.meta.get(s);t.meta.set(s,{clock:n.clock+1,lastUpdated:lc()})}i.push(s)}}i.length>0&&(t.emit("change",[{added:[],updated:[],removed:i},e]),t.emit("update",[{added:[],updated:[],removed:i},e]))},mc=(t,n,e=t.states)=>{const i=n.length,s=Nh();qh(s,i);for(let r=0;r<i;r++){const i=n[r],o=e.get(i)||null,h=t.meta.get(i).clock;qh(s,i),qh(s,h),tc(s,JSON.stringify(o))}return Vh(s)};class Ac{constructor(){this.callbacks={}}on(t,n){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(n),this}emit(t,...n){const e=this.callbacks[t];return e&&e.forEach((t=>t.apply(this,n))),this}off(t,n){const e=this.callbacks[t];return e&&(n?this.callbacks[t]=e.filter((t=>t!==n)):delete this.callbacks[t]),this}removeAllListeners(){this.callbacks={}}}class kc{constructor(t){this.data=t,this.encoder=Nh(),this.decoder=oc(new Uint8Array(this.data))}peekVarString(){return(t=>{const n=t.pos,e=ac(t);return t.pos=n,e})(this.decoder)}readVarUint(){return uc(this.decoder)}readVarString(){return ac(this.decoder)}readVarUint8Array(){return hc(this.decoder)}writeVarUint(t){return qh(this.encoder,t)}writeVarString(t){return tc(this.encoder,t)}writeVarUint8Array(t){return nc(this.encoder,t)}length(){return Qh(this.encoder)}}var Mc,xc;!function(t){t[t.Sync=0]="Sync",t[t.Awareness=1]="Awareness",t[t.Auth=2]="Auth",t[t.QueryAwareness=3]="QueryAwareness",t[t.Stateless=5]="Stateless",t[t.CLOSE=7]="CLOSE",t[t.SyncStatus=8]="SyncStatus"}(Mc||(Mc={})),function(t){t.Connecting="connecting",t.Connected="connected",t.Disconnected="disconnected"}(xc||(xc={}));class Sc{constructor(){this.encoder=Nh()}get(t){return t.encoder}toUint8Array(){return Vh(this.encoder)}}class Cc extends Sc{constructor(){super(...arguments),this.type=Mc.CLOSE,this.description="Ask the server to close the connection"}get(t){return tc(this.encoder,t.documentName),qh(this.encoder,this.type),this.encoder}}class Tc extends Ac{constructor(t){super(),this.messageQueue=[],this.configuration={url:"",autoConnect:!0,document:void 0,WebSocketPolyfill:void 0,messageReconnectTimeout:3e4,delay:1e3,initialDelay:0,factor:2,maxAttempts:0,minDelay:1e3,maxDelay:3e4,jitter:!0,timeout:0,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,handleTimeout:null,providerMap:new Map},this.webSocket=null,this.webSocketHandlers={},this.shouldConnect=!0,this.status=xc.Disconnected,this.lastMessageReceived=0,this.identifier=0,this.intervals={connectionChecker:null},this.connectionAttempt=null,this.receivedOnOpenPayload=void 0,this.closeTries=0,this.setConfiguration(t),this.configuration.WebSocketPolyfill=t.WebSocketPolyfill?t.WebSocketPolyfill:WebSocket,this.on("open",this.configuration.onOpen),this.on("open",this.onOpen.bind(this)),this.on("connect",this.configuration.onConnect),this.on("message",this.configuration.onMessage),this.on("outgoingMessage",this.configuration.onOutgoingMessage),this.on("status",this.configuration.onStatus),this.on("disconnect",this.configuration.onDisconnect),this.on("close",this.configuration.onClose),this.on("destroy",this.configuration.onDestroy),this.on("awarenessUpdate",this.configuration.onAwarenessUpdate),this.on("awarenessChange",this.configuration.onAwarenessChange),this.on("close",this.onClose.bind(this)),this.on("message",this.onMessage.bind(this)),this.intervals.connectionChecker=setInterval(this.checkConnection.bind(this),this.configuration.messageReconnectTimeout/10),this.shouldConnect&&this.connect()}async onOpen(t){this.status=xc.Connected,this.emit("status",{status:xc.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=t}attach(t){this.configuration.providerMap.set(t.configuration.name,t),this.status===xc.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===xc.Connected&&t.onOpen(this.receivedOnOpenPayload)}detach(t){this.configuration.providerMap.has(t.configuration.name)&&(t.send(Cc,{documentName:t.configuration.name}),this.configuration.providerMap.delete(t.configuration.name))}setConfiguration(t={}){this.configuration={...this.configuration,...t},this.configuration.autoConnect||(this.shouldConnect=!1)}async connect(){if(this.status===xc.Connected)return;this.cancelWebsocketRetry&&(this.cancelWebsocketRetry(),this.cancelWebsocketRetry=void 0),this.receivedOnOpenPayload=void 0,this.shouldConnect=!0;const{retryPromise:t,cancelFunc:n}=(()=>{let t=!1;const n=async function(t,n){const e=function(t){return t||(t={}),{delay:void 0===t.delay?200:t.delay,initialDelay:void 0===t.initialDelay?0:t.initialDelay,minDelay:void 0===t.minDelay?0:t.minDelay,maxDelay:void 0===t.maxDelay?0:t.maxDelay,factor:void 0===t.factor?0:t.factor,maxAttempts:void 0===t.maxAttempts?3:t.maxAttempts,timeout:void 0===t.timeout?0:t.timeout,jitter:!0===t.jitter,initialJitter:!0===t.initialJitter,handleError:void 0===t.handleError?null:t.handleError,handleTimeout:void 0===t.handleTimeout?null:t.handleTimeout,beforeAttempt:void 0===t.beforeAttempt?null:t.beforeAttempt,calculateDelay:void 0===t.calculateDelay?null:t.calculateDelay}}(n);for(const t of["delay","initialDelay","minDelay","maxDelay","maxAttempts","timeout"]){const n=e[t];if(!Number.isInteger(n)||n<0)throw new Error(`Value for ${t} must be an integer greater than or equal to 0`)}if(e.factor.constructor!==Number||e.factor<0)throw new Error("Value for factor must be a number greater than or equal to 0");if(e.delay<e.minDelay)throw new Error(`delay cannot be less than minDelay (delay: ${e.delay}, minDelay: ${e.minDelay}`);const i={attemptNum:0,attemptsRemaining:e.maxAttempts?e.maxAttempts:-1,aborted:!1,abort(){i.aborted=!0}},s=e.calculateDelay||Ph,r=e.calculateDelay?e.calculateDelay(i,e):e.initialDelay;if(r&&await zh(r),i.attemptNum<1&&e.initialJitter){const t=s(i,e);t&&await zh(t)}return async function n(){if(e.beforeAttempt&&e.beforeAttempt(i,e),i.aborted){const t=new Error("Attempt aborted");throw t.code="ATTEMPT_ABORTED",t}const r=async t=>{if(e.handleError&&await e.handleError(t,i,e),i.aborted||0===i.attemptsRemaining)throw t;i.attemptNum++;const r=s(i,e);return r&&await zh(r),n()};return i.attemptsRemaining>0&&i.attemptsRemaining--,e.timeout?new Promise(((n,s)=>{const o=setTimeout((()=>{if(e.handleTimeout)try{n(e.handleTimeout(i,e))}catch(t){s(t)}else{const t=new Error(`Retry timeout (attemptNum: ${i.attemptNum}, timeout: ${e.timeout})`);t.code="ATTEMPT_TIMEOUT",s(t)}}),e.timeout);t(i,e).then((t=>{clearTimeout(o),n(t)})).catch((t=>{clearTimeout(o),r(t).then(n).catch(s)}))})):t(i,e).catch(r)}()}(this.createWebSocketConnection.bind(this),{delay:this.configuration.delay,initialDelay:this.configuration.initialDelay,factor:this.configuration.factor,maxAttempts:this.configuration.maxAttempts,minDelay:this.configuration.minDelay,maxDelay:this.configuration.maxDelay,jitter:this.configuration.jitter,timeout:this.configuration.timeout,handleTimeout:this.configuration.handleTimeout,beforeAttempt:n=>{this.shouldConnect&&!t||n.abort()}}).catch((t=>{if(t&&"ATTEMPT_ABORTED"!==t.code)throw t}));return{retryPromise:n,cancelFunc:()=>{t=!0}}})();return this.cancelWebsocketRetry=n,t}attachWebSocketListeners(t,n){const{identifier:e}=t;this.webSocketHandlers[e]={message:t=>this.emit("message",t),close:t=>this.emit("close",{event:t}),open:t=>this.emit("open",t),error:t=>{n(t)}};const i=this.webSocketHandlers[t.identifier];Object.keys(i).forEach((n=>{t.addEventListener(n,i[n])}))}cleanupWebSocket(){if(!this.webSocket)return;const{identifier:t}=this.webSocket,n=this.webSocketHandlers[t];Object.keys(n).forEach((e=>{var i;null===(i=this.webSocket)||void 0===i||i.removeEventListener(e,n[e]),delete this.webSocketHandlers[t]})),this.webSocket.close(),this.webSocket=null}createWebSocketConnection(){return new Promise(((t,n)=>{this.webSocket&&(this.messageQueue=[],this.cleanupWebSocket()),this.lastMessageReceived=0,this.identifier+=1;const e=new this.configuration.WebSocketPolyfill(this.url);e.binaryType="arraybuffer",e.identifier=this.identifier,this.attachWebSocketListeners(e,n),this.webSocket=e,this.status=xc.Connecting,this.emit("status",{status:xc.Connecting}),this.connectionAttempt={resolve:t,reject:n}}))}onMessage(t){var n;this.resolveConnectionAttempt(),this.lastMessageReceived=lc();const e=new kc(t.data).peekVarString();null===(n=this.configuration.providerMap.get(e))||void 0===n||n.onMessage(t)}resolveConnectionAttempt(){this.connectionAttempt&&(this.connectionAttempt.resolve(),this.connectionAttempt=null,this.status=xc.Connected,this.emit("status",{status:xc.Connected}),this.emit("connect"),this.messageQueue.forEach((t=>this.send(t))),this.messageQueue=[])}stopConnectionAttempt(){this.connectionAttempt=null}rejectConnectionAttempt(){var t;null===(t=this.connectionAttempt)||void 0===t||t.reject(),this.connectionAttempt=null}checkConnection(){var t;this.status===xc.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=lc()-this.lastMessageReceived||(this.closeTries+=1,this.closeTries>2?(this.onClose({event:{code:4408,reason:"forced"}}),this.closeTries=0):(null===(t=this.webSocket)||void 0===t||t.close(),this.messageQueue=[])))}get serverUrl(){for(;"/"===this.configuration.url[this.configuration.url.length-1];)return this.configuration.url.slice(0,this.configuration.url.length-1);return this.configuration.url}get url(){return this.serverUrl}disconnect(){if(this.shouldConnect=!1,null!==this.webSocket)try{this.webSocket.close(),this.messageQueue=[]}catch(t){console.error(t)}}send(t){var n;(null===(n=this.webSocket)||void 0===n?void 0:n.readyState)===Oh.Open?this.webSocket.send(t):this.messageQueue.push(t)}onClose({event:t}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=xc.Disconnected,this.emit("status",{status:xc.Disconnected}),this.emit("disconnect",{event:t}),!this.cancelWebsocketRetry&&this.shouldConnect&&setTimeout((()=>{this.connect()}),this.configuration.delay)}destroy(){this.emit("destroy"),clearInterval(this.intervals.connectionChecker),this.stopConnectionAttempt(),this.disconnect(),this.removeAllListeners(),this.cleanupWebSocket()}}const jc=(t,n,e)=>{try{$s(n,hc(t),e)}catch(t){console.error("Caught error while handling a Yjs update",t)}},Uc=jc;class Ec{constructor(t){this.message=t}apply(t,n){const{message:e}=this,i=e.readVarUint(),s=e.length();switch(i){case Mc.Sync:this.applySyncMessage(t,n);break;case Mc.Awareness:this.applyAwarenessMessage(t);break;case Mc.Auth:this.applyAuthMessage(t);break;case Mc.QueryAwareness:this.applyQueryAwarenessMessage(t);break;case Mc.Stateless:t.receiveStateless(ac(e.decoder));break;case Mc.SyncStatus:this.applySyncStatusMessage(t,1===(t=>{let n=t.arr[t.pos++],e=63&n,i=64;const s=(64&n)>0?-1:1;if(!(n&Fh))return s*e;const r=t.arr.length;for(;t.pos<r;){if(n=t.arr[t.pos++],e+=(n&Rh)*i,i*=128,n<Fh)return s*e;if(e>Lh)throw sc}throw ic})(e.decoder));break;case Mc.CLOSE:const s={code:1e3,reason:ac(e.decoder),target:t.configuration.websocketProvider.webSocket,type:"close"};t.onClose(),t.configuration.onClose({event:s}),t.forwardClose(s);break;default:throw new Error(`Can’t apply message of unknown type: ${i}`)}e.length()>s+1&&t.send(Sc,{encoder:e.encoder})}applySyncMessage(t,n){const{message:e}=this;e.writeVarUint(Mc.Sync);const i=((t,n,e,i)=>{const s=uc(t);switch(s){case 0:((t,n,e)=>{((t,n,e)=>{qh(t,1),nc(t,Is(n,e))})(n,e,hc(t))})(t,n,e);break;case 1:jc(t,e,i);break;case 2:Uc(t,e,i);break;default:throw new Error("Unknown message type")}return s})(e.decoder,e.encoder,t.document,t);n&&1===i&&(t.synced=!0)}applySyncStatusMessage(t,n){n&&t.decrementUnsyncedChanges()}applyAwarenessMessage(t){if(!t.awareness)return;const{message:n}=this;((t,n,e)=>{const i=oc(n),s=lc(),r=[],o=[],h=[],c=[],u=uc(i);for(let n=0;n<u;n++){const n=uc(i);let e=uc(i);const u=JSON.parse(ac(i)),a=t.meta.get(n),l=t.states.get(n),f=void 0===a?0:a.clock;(f<e||f===e&&null===u&&t.states.has(n))&&(null===u?n===t.clientID&&null!=t.getLocalState()?e++:t.states.delete(n):t.states.set(n,u),t.meta.set(n,{clock:e,lastUpdated:s}),void 0===a&&null!==u?r.push(n):void 0!==a&&null===u?c.push(n):null!==u&&(yc(u,l)||h.push(n),o.push(n)))}(r.length>0||h.length>0||c.length>0)&&t.emit("change",[{added:r,updated:h,removed:c},e]),(r.length>0||o.length>0||c.length>0)&&t.emit("update",[{added:r,updated:o,removed:c},e])})(t.awareness,n.readVarUint8Array(),t)}applyAuthMessage(t){const{message:n}=this;((t,n,e,i)=>{switch(Eh(t)){case _h.Token:n();break;case _h.PermissionDenied:e($h(t));break;case _h.Authenticated:i($h(t))}})(n.decoder,t.sendToken.bind(t),t.permissionDeniedHandler.bind(t),t.authenticatedHandler.bind(t))}applyQueryAwarenessMessage(t){if(!t.awareness)return;const{message:n}=this;n.writeVarUint(Mc.Awareness),n.writeVarUint8Array(mc(t.awareness,Array.from(t.awareness.getStates().keys())))}}class $c{constructor(t,n={}){this.message=new t,this.encoder=this.message.get(n)}create(){return Vh(this.encoder)}send(t){null==t||t.send(this.create())}}class _c extends Sc{constructor(){super(...arguments),this.type=Mc.Auth,this.description="Authentication"}get(t){if(void 0===t.token)throw new Error("The authentication message requires `token` as an argument.");var n,e;return tc(this.encoder,t.documentName),qh(this.encoder,this.type),e=t.token,Ah(n=this.encoder,_h.Token),xh(n,e),this.encoder}}class Ic extends Sc{constructor(){super(...arguments),this.type=Mc.Awareness,this.description="Awareness states update"}get(t){if(void 0===t.awareness)throw new Error("The awareness message requires awareness as an argument");if(void 0===t.clients)throw new Error("The awareness message requires clients as an argument");let n;return tc(this.encoder,t.documentName),qh(this.encoder,this.type),n=void 0===t.states?mc(t.awareness,t.clients):mc(t.awareness,t.clients,t.states),nc(this.encoder,n),this.encoder}}class Oc extends Sc{constructor(){super(...arguments),this.type=Mc.Stateless,this.description="A stateless message"}get(t){var n;return tc(this.encoder,t.documentName),qh(this.encoder,this.type),tc(this.encoder,null!==(n=t.payload)&&void 0!==n?n:""),this.encoder}}class zc extends Sc{constructor(){super(...arguments),this.type=Mc.Sync,this.description="First sync step"}get(t){if(void 0===t.document)throw new Error("The sync step one message requires document as an argument");return tc(this.encoder,t.documentName),qh(this.encoder,this.type),((t,n)=>{qh(t,0);const e=Ps(n);nc(t,e)})(this.encoder,t.document),this.encoder}}class Pc extends Sc{constructor(){super(...arguments),this.type=Mc.Sync,this.description="A document update"}get(t){var n,e;return tc(this.encoder,t.documentName),qh(this.encoder,this.type),e=t.update,qh(n=this.encoder,2),nc(n,e),this.encoder}}class Dc extends Error{constructor(){super(...arguments),this.code=1001}}class Fc extends Ac{constructor(t){var n,e,i;super(),this.configuration={name:"",document:void 0,awareness:void 0,token:null,forceSyncInterval:!1,onAuthenticated:()=>null,onAuthenticationFailed:()=>null,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onSynced:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,onStateless:()=>null,onUnsyncedChanges:()=>null},this.isSynced=!1,this.unsyncedChanges=0,this.isAuthenticated=!1,this.authorizedScope=void 0,this.manageSocket=!1,this._isAttached=!1,this.intervals={forceSync:null},this.boundDocumentUpdateHandler=this.documentUpdateHandler.bind(this),this.boundAwarenessUpdateHandler=this.awarenessUpdateHandler.bind(this),this.boundPageHide=this.pageHide.bind(this),this.boundOnOpen=this.onOpen.bind(this),this.boundOnClose=this.onClose.bind(this),this.forwardConnect=()=>this.emit("connect"),this.forwardStatus=t=>this.emit("status",t),this.forwardClose=t=>this.emit("close",t),this.forwardDisconnect=t=>this.emit("disconnect",t),this.forwardDestroy=()=>this.emit("destroy"),this.setConfiguration(t),this.configuration.document=t.document?t.document:new ms,this.configuration.awareness=void 0!==t.awareness?t.awareness:new gc(this.document),this.on("open",this.configuration.onOpen),this.on("message",this.configuration.onMessage),this.on("outgoingMessage",this.configuration.onOutgoingMessage),this.on("synced",this.configuration.onSynced),this.on("destroy",this.configuration.onDestroy),this.on("awarenessUpdate",this.configuration.onAwarenessUpdate),this.on("awarenessChange",this.configuration.onAwarenessChange),this.on("stateless",this.configuration.onStateless),this.on("unsyncedChanges",this.configuration.onUnsyncedChanges),this.on("authenticated",this.configuration.onAuthenticated),this.on("authenticationFailed",this.configuration.onAuthenticationFailed),null===(n=this.awareness)||void 0===n||n.on("update",(()=>{this.emit("awarenessUpdate",{states:Ih(this.awareness.getStates())})})),null===(e=this.awareness)||void 0===e||e.on("change",(()=>{this.emit("awarenessChange",{states:Ih(this.awareness.getStates())})})),this.document.on("update",this.boundDocumentUpdateHandler),null===(i=this.awareness)||void 0===i||i.on("update",this.boundAwarenessUpdateHandler),this.registerEventListeners(),this.configuration.forceSyncInterval&&"number"==typeof this.configuration.forceSyncInterval&&(this.intervals.forceSync=setInterval(this.forceSync.bind(this),this.configuration.forceSyncInterval)),this.manageSocket&&this.attach()}setConfiguration(t={}){if(!t.websocketProvider){const n=t;this.manageSocket=!0,this.configuration.websocketProvider=new Tc({url:n.url})}this.configuration={...this.configuration,...t}}get document(){return this.configuration.document}get isAttached(){return this._isAttached}get awareness(){return this.configuration.awareness}get hasUnsyncedChanges(){return this.unsyncedChanges>0}resetUnsyncedChanges(){this.unsyncedChanges=1,this.emit("unsyncedChanges",{number:this.unsyncedChanges})}incrementUnsyncedChanges(){this.unsyncedChanges+=1,this.emit("unsyncedChanges",{number:this.unsyncedChanges})}decrementUnsyncedChanges(){this.unsyncedChanges>0&&(this.unsyncedChanges-=1),0===this.unsyncedChanges&&(this.synced=!0),this.emit("unsyncedChanges",{number:this.unsyncedChanges})}forceSync(){this.resetUnsyncedChanges(),this.send(zc,{document:this.document,documentName:this.configuration.name})}pageHide(){this.awareness&&bc(this.awareness,[this.document.clientID],"page hide")}registerEventListeners(){"undefined"!=typeof window&&"addEventListener"in window&&window.addEventListener("pagehide",this.boundPageHide)}sendStateless(t){this.send(Oc,{documentName:this.configuration.name,payload:t})}async sendToken(){let t;try{t=await this.getToken()}catch(t){return void this.permissionDeniedHandler(`Failed to get token during sendToken(): ${t}`)}this.send(_c,{token:null!=t?t:"",documentName:this.configuration.name})}documentUpdateHandler(t,n){n!==this&&(this.incrementUnsyncedChanges(),this.send(Pc,{update:t,documentName:this.configuration.name}))}awarenessUpdateHandler({added:t,updated:n,removed:e},i){const s=t.concat(n).concat(e);this.send(Ic,{awareness:this.awareness,clients:s,documentName:this.configuration.name})}get synced(){return this.isSynced}set synced(t){this.isSynced!==t&&(this.isSynced=t,t&&this.emit("synced",{state:t}))}receiveStateless(t){this.emit("stateless",{payload:t})}async connect(){if(this.manageSocket)return this.configuration.websocketProvider.connect();console.warn("HocuspocusProvider::connect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.")}disconnect(){if(this.manageSocket)return this.configuration.websocketProvider.disconnect();console.warn("HocuspocusProvider::disconnect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.")}async onOpen(t){this.isAuthenticated=!1,this.emit("open",{event:t}),await this.sendToken(),this.startSync()}async getToken(){return"function"==typeof this.configuration.token?await this.configuration.token():this.configuration.token}startSync(){this.resetUnsyncedChanges(),this.send(zc,{document:this.document,documentName:this.configuration.name}),this.awareness&&null!==this.awareness.getLocalState()&&this.send(Ic,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.configuration.name})}send(t,n){if(!this._isAttached)return;const e=new $c(t,n);this.emit("outgoingMessage",{message:e.message}),e.send(this.configuration.websocketProvider)}onMessage(t){const n=new kc(t.data),e=n.readVarString();n.writeVarString(e),this.emit("message",{event:t,message:new kc(t.data)}),new Ec(n).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&bc(this.awareness,Array.from(this.awareness.getStates().keys()).filter((t=>t!==this.document.clientID)),this)}destroy(){this.emit("destroy"),this.intervals.forceSync&&clearInterval(this.intervals.forceSync),this.awareness&&(bc(this.awareness,[this.document.clientID],"provider destroy"),this.awareness.off("update",this.boundAwarenessUpdateHandler),this.awareness.destroy()),this.document.off("update",this.boundDocumentUpdateHandler),this.removeAllListeners(),this.detach(),this.manageSocket&&this.configuration.websocketProvider.destroy(),"undefined"!=typeof window&&"removeEventListener"in window&&window.removeEventListener("pagehide",this.boundPageHide)}detach(){this.configuration.websocketProvider.off("connect",this.configuration.onConnect),this.configuration.websocketProvider.off("connect",this.forwardConnect),this.configuration.websocketProvider.off("status",this.forwardStatus),this.configuration.websocketProvider.off("status",this.configuration.onStatus),this.configuration.websocketProvider.off("open",this.boundOnOpen),this.configuration.websocketProvider.off("close",this.boundOnClose),this.configuration.websocketProvider.off("close",this.configuration.onClose),this.configuration.websocketProvider.off("close",this.forwardClose),this.configuration.websocketProvider.off("disconnect",this.configuration.onDisconnect),this.configuration.websocketProvider.off("disconnect",this.forwardDisconnect),this.configuration.websocketProvider.off("destroy",this.configuration.onDestroy),this.configuration.websocketProvider.off("destroy",this.forwardDestroy),this.configuration.websocketProvider.detach(this),this._isAttached=!1}attach(){this._isAttached||(this.configuration.websocketProvider.on("connect",this.configuration.onConnect),this.configuration.websocketProvider.on("connect",this.forwardConnect),this.configuration.websocketProvider.on("status",this.configuration.onStatus),this.configuration.websocketProvider.on("status",this.forwardStatus),this.configuration.websocketProvider.on("open",this.boundOnOpen),this.configuration.websocketProvider.on("close",this.boundOnClose),this.configuration.websocketProvider.on("close",this.configuration.onClose),this.configuration.websocketProvider.on("close",this.forwardClose),this.configuration.websocketProvider.on("disconnect",this.configuration.onDisconnect),this.configuration.websocketProvider.on("disconnect",this.forwardDisconnect),this.configuration.websocketProvider.on("destroy",this.configuration.onDestroy),this.configuration.websocketProvider.on("destroy",this.forwardDestroy),this.configuration.websocketProvider.attach(this),this._isAttached=!0)}permissionDeniedHandler(t){this.emit("authenticationFailed",{reason:t}),this.isAuthenticated=!1}authenticatedHandler(t){this.isAuthenticated=!0,this.authorizedScope=t,this.emit("authenticated",{scope:t})}setAwarenessField(t,n){if(!this.awareness)throw new Dc(`Cannot set awareness field "${t}" to ${JSON.stringify(n)}. You have disabled Awareness for this provider by explicitly passing awareness: null in the provider configuration.`);this.awareness.setLocalStateField(t,n)}}const Rc={providers:[dh]};class Lc{map;_ydoc=null;_workspacesMap=null;_providers=[];_core=null;_isReady=!1;_onRemoteChangeCallback=null;get isReady(){return this._isReady}constructor(){this.map=new Map}onRemoteChange(t){this._onRemoteChangeCallback=t}async initialize(t,n){this._core=t,this._ydoc=new ms,this._workspacesMap=this._ydoc.getMap("workspaces");const e="kritzel-app-state",i=n??Rc;for(const t of i.providers){let n;n="function"==typeof t?new t(e,this._ydoc):t.create(e,this._ydoc),this._providers.push(n)}this._workspacesMap.observe((t=>{this.handleWorkspacesChange(t)})),await Promise.all(this._providers.map((t=>t.connect()))),this._isReady=!0,this.loadFromYjs()}handleWorkspacesChange(t){if("local"===t.transaction.origin)return void this._core?.rerender();const n=Array.from(t.keysChanged),e=[],i=[];n.forEach((n=>{const s=t.changes.keys.get(n);if(s&&"delete"===s.action)i.push(n);else{const t=this._workspacesMap.get(n);if(t){const n=this.reviveWorkspace(t);e.push(n)}}})),i.forEach((t=>{this.map.delete(t)})),e.forEach((t=>{this.map.set(t.id,t)})),this._core?.store&&(this._core.store.state.workspaces=this.allWorkspaces()),this._onRemoteChangeCallback&&this._onRemoteChangeCallback(),this._core?.rerender()}reviveWorkspace(t){const n=new $(t.id,t.name,t.viewport);return n._core=this._core,n.createdAt=new Date(t.createdAt),n.updatedAt=new Date(t.updatedAt),n}transaction(t){this._ydoc&&this._ydoc.transact(t,"local")}loadFromYjs(){this._workspacesMap&&(this.map.clear(),this._workspacesMap.forEach(((t,n)=>{const e=this.reviveWorkspace(t);this.map.set(n,e)})))}reset(){this.map.clear(),this._ydoc.transact((()=>{this._workspacesMap.clear()}),"local")}insert(t){if(!t.id)return!1;if(this.map.set(t.id,t),this._workspacesMap){const n=t.serialize();this._ydoc.transact((()=>{this._workspacesMap.set(t.id,n)}),"local")}return!0}update(t){if(!t.id||!this.map.has(t.id))return!1;if(this.map.set(t.id,t),this._workspacesMap){const n=t.serialize();this._ydoc.transact((()=>{this._workspacesMap.set(t.id,n)}),"local")}return!0}remove(t){const n=Array.from(this.map.values()).find(t);return!!n&&(this.map.delete(n.id),this._workspacesMap&&this._ydoc.transact((()=>{this._workspacesMap.delete(n.id)}),"local"),!0)}get(t){return this.map.get(t)}allWorkspaces(){return Array.from(this.map.values())}filter(t){return Array.from(this.map.values()).filter(t)}find(t){return Array.from(this.map.values()).find(t)}has(t){return this.map.has(t)}destroy(){this._providers.forEach((t=>t.disconnect())),this._providers=[],this.map.clear(),this._workspacesMap=null,this._ydoc&&(this._ydoc.destroy(),this._ydoc=null),this._isReady=!1}}class Wc{static isInstanceOf(t,n){return!!t&&t.__class__===n}}class Bc{_core;_anchorIndex=new Map;constructor(t){this._core=t}setAnchor(t,n,e){const i=this.getLineById(t);if(!i)return;if("start"===n&&i.endAnchor?.objectId===e)return;if("end"===n&&i.startAnchor?.objectId===e)return;this.removeAnchor(t,n);const s={objectId:e};"start"===n?i.startAnchor=s:i.endAnchor=s,this.addToIndex(e,t,n),this.snapEndpointToObject(i,n,e),this._core.store.state.objects.update(i)}removeAnchor(t,n){const e=this.getLineById(t);if(!e)return;const i="start"===n?e.startAnchor:e.endAnchor;i&&(this.removeFromIndex(i.objectId,t,n),"start"===n?e.startAnchor=void 0:e.endAnchor=void 0)}getAnchor(t,n){const e=this.getLineById(t);return e?("start"===n?e.startAnchor:e.endAnchor)??null:null}getLinesAnchoredTo(t){const n=this._anchorIndex.get(t);return n?Array.from(n):[]}updateAnchorsForObject(t){const n=this.getLinesAnchoredTo(t);if(0!==n.length&&this.getObjectById(t))for(const e of n){const n=this.getLineById(e.lineId);n&&this.snapEndpointToObject(n,e.endpoint,t)}}snapEndpointToObject(t,n,e){const i=this.getObjectById(e);if(!i)return;const s=this.worldToLineLocal(t,i.centerX,i.centerY);t.updateEndpoint(n,s.x,s.y)}worldToLineLocal(t,n,e){const i=n-t.centerX,s=e-t.centerY,r=Math.cos(-t.rotation),o=Math.sin(-t.rotation);return{x:(i*r-s*o+t.totalWidth/2/t.scale)*t.scale+t.x,y:(i*o+s*r+t.totalHeight/2/t.scale)*t.scale+t.y}}findSnapTarget(t,n,e,i){let s=null,r=-1/0;const o=this._core.store.allNonSelectionObjects;for(const h of o){if(h.id===e)continue;if(i&&h.id===i)continue;if(!this.isAnchorable(h))continue;const o=h.rotatedPolygon;c.isPointInPolygon({x:t,y:n},[o.topLeft,o.topRight,o.bottomRight,o.bottomLeft])&&h.zIndex>r&&(r=h.zIndex,s={objectId:h.id,centerX:h.centerX,centerY:h.centerY})}return s}setSnapCandidate(t){this._core.store.state.snapCandidate=t,this._core.rerender()}getSnapCandidate(){return this._core.store.state.snapCandidate??null}clearSnapCandidate(){this._core.store.state.snapCandidate=null,this._core.rerender()}getAnchorLinesRenderData(){const t=this._core.store.selectionGroup;if(!t||1!==t.objects.length)return null;const n=t.objects[0];if(!Wc.isInstanceOf(n,"KritzelLine"))return null;const e=n,i=this.computeAnchorVisualization(e,"start"),s=this.computeAnchorVisualization(e,"end");if(!i&&!s)return null;const r=this._core.store.state.scale,o=e.strokeWidth/e.scale,h=""+2/r,c=Math.max(2*o,4/r);return{lineStrokeWidth:o,indicatorStrokeWidth:h,dashArray:`${c} ${c}`,indicatorRadius:8/r,startAnchorViz:i,endAnchorViz:s}}getSnapIndicatorRenderData(){const t=this.getSnapCandidate();if(!t)return null;const n=this._core.store.state.scale,e=8/n,i=""+2/n,s=t.lineStrokeWidth?`${t.lineStrokeWidth}`:""+4/n,r=Math.max(2*(t.lineStrokeWidth||4/n),4/n),o=`${r} ${r}`,h=t.lineStroke||"#000000";let c,u=t.edgeX,a=t.edgeY;if(t.arrowOffset&&void 0!==t.edgeX&&void 0!==t.edgeY){const n=t.lineEndpointX-t.edgeX,e=t.lineEndpointY-t.edgeY,i=Math.sqrt(n*n+e*e);i>t.arrowOffset&&(u=t.edgeX+n/i*t.arrowOffset,a=t.edgeY+e/i*t.arrowOffset);const s=t.edgeX-t.lineEndpointX,r=t.edgeY-t.lineEndpointY,o=Math.sqrt(s*s+r*r);if(o>0){const n=s/o,e=r/o,i=-e,h=t.arrowOffset,u=t.edgeX,a=t.edgeY,l=u-n*h,f=a-e*h;c=`${u},${a} ${l+i*h/2},${f+n*h/2} ${l-i*h/2},${f-n*h/2}`}}return{indicatorRadius:e,indicatorStrokeWidth:i,lineStrokeWidth:s,dashArray:o,lineStroke:h,centerX:t.centerX,centerY:t.centerY,lineEndpointX:t.lineEndpointX,lineEndpointY:t.lineEndpointY,edgeX:t.edgeX,edgeY:t.edgeY,arrowOffset:t.arrowOffset,arrowStyle:t.arrowStyle,arrowFill:t.arrowFill,solidLineEndX:u,solidLineEndY:a,arrowPoints:c,snapLinePath:(()=>{if(void 0!==t.controlX&&void 0!==t.controlY&&void 0!==t.t){const n="start"===t.endpoint?1-t.t:t.t;if(n>=1)return;const e=this.extractQuadraticSegment({x:t.lineEndpointX,y:t.lineEndpointY},{x:t.controlX,y:t.controlY},{x:t.centerX,y:t.centerY},n,1);return`M ${e.start.x} ${e.start.y} Q ${e.control.x} ${e.control.y} ${e.end.x} ${e.end.y}`}})()}}handleObjectDeleted(t){const n=this.getLinesAnchoredTo(t);for(const t of n){this.removeAnchor(t.lineId,t.endpoint);const n=this.getLineById(t.lineId);n&&this._core.store.state.objects.update(n)}this._anchorIndex.delete(t)}handleLineDeleted(t){const n=this.getLineById(t);n&&(n.startAnchor&&this.removeFromIndex(n.startAnchor.objectId,t,"start"),n.endAnchor&&this.removeFromIndex(n.endAnchor.objectId,t,"end"))}rebuildIndex(){this._anchorIndex.clear();const t=this._core.store.allObjects;for(const n of t)n instanceof z&&(n.startAnchor&&this.addToIndex(n.startAnchor.objectId,n.id,"start"),n.endAnchor&&this.addToIndex(n.endAnchor.objectId,n.id,"end"))}addToIndex(t,n,e){this._anchorIndex.has(t)||this._anchorIndex.set(t,new Set);const i=this._anchorIndex.get(t);for(const t of i)if(t.lineId===n&&t.endpoint===e)return;i.add({lineId:n,endpoint:e})}removeFromIndex(t,n,e){const i=this._anchorIndex.get(t);if(i){for(const t of i)if(t.lineId===n&&t.endpoint===e){i.delete(t);break}0===i.size&&this._anchorIndex.delete(t)}}getLineById(t){const n=this._core.store.state.objects.filter((n=>n.id===t));if(0===n.length)return null;const e=n[0];return e instanceof z?e:null}getObjectById(t){const n=this._core.store.state.objects.filter((n=>n.id===t));return n.length>0?n[0]:null}findAnchorTarget(t,n){const e="start"===n?t.startAnchor:t.endAnchor;return e?this._core.store.allNonSelectionObjects.find((t=>t.id===e.objectId))??null:null}computeAnchorVisualization(t,n){if(!("start"===n?t.startAnchor:t.endAnchor))return null;const e=this.findAnchorTarget(t,n);if(!e)return null;const i=this.computeAnchorClipInfo(t,n,e);return i?{edgeX:i.worldX,edgeY:i.worldY,centerX:e.centerX,centerY:e.centerY,pathD:this.buildAnchorPath(t,n,i,e)??void 0}:null}computeClippedLinePath(t,n=!1){const e=this.getSnapCandidate(),i=this._core.store.selectionGroup,s=e&&i&&1===i.objects.length&&i.objects[0].id===t.id;if(!t.startAnchor&&!t.endAnchor&&!s)return n?void 0!==t.controlX&&void 0!==t.controlY?`M ${t.startX-t.x} ${t.startY-t.y} Q ${t.controlX-t.x} ${t.controlY-t.y} ${t.endX-t.x} ${t.endY-t.y}`:`M ${t.startX-t.x} ${t.startY-t.y} L ${t.endX-t.x} ${t.endY-t.y}`:t.d;const r=t.startAnchor?this.findAnchorTarget(t,"start"):null,o=t.endAnchor?this.findAnchorTarget(t,"end"):null;let h=r?this.computeAnchorClipInfo(t,"start",r):null,c=o?this.computeAnchorClipInfo(t,"end",o):null;if(s&&void 0!==e.edgeX&&void 0!==e.edgeY){const n=this.lineWorldToLocal(t,e.edgeX,e.edgeY),i={worldX:e.edgeX,worldY:e.edgeY,localX:n.x,localY:n.y,t:e.t};"start"===e.endpoint?h=i:c=i}const u=n?t.x:0,a=n?t.y:0;if(void 0!==t.controlX&&void 0!==t.controlY){let n=h?.t??0,e=c?.t??1;if(h&&t.hasStartArrow){const e=t.getArrowSize("start"),i=this.evaluateDerivativeSpeedAtT(t,n);i>0&&(n+=e/i)}if(c&&t.hasEndArrow){const n=t.getArrowSize("end"),i=this.evaluateDerivativeSpeedAtT(t,e);i>0&&(e-=n/i)}if(n<0&&(n=0),e>1&&(e=1),e<=n){const t=(n+e)/2;n=t,e=t}const i=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},n,e);return`M ${i.start.x-u} ${i.start.y-a} Q ${i.control.x-u} ${i.control.y-a} ${i.end.x-u} ${i.end.y-a}`}let l=h?.localX??t.startX,f=h?.localY??t.startY,d=c?.localX??t.endX,v=c?.localY??t.endY;if(h&&t.hasStartArrow){const n=t.getArrowSize("start"),e=d-l,i=v-f,s=Math.sqrt(e*e+i*i);s>n&&(l+=e/s*n,f+=i/s*n)}if(c&&t.hasEndArrow){const n=t.getArrowSize("end"),e=l-d,i=f-v,s=Math.sqrt(e*e+i*i);s>n&&(d+=e/s*n,v+=i/s*n)}return`M ${l-u} ${f-a} L ${d-u} ${v-a}`}computeAnchorClipInfo(t,n,e){return void 0!==t.controlX&&void 0!==t.controlY?this.computeCurvedClipInfo(t,n,e):this.computeStraightClipInfo(t,n,e)}computeStraightClipInfo(t,n,e){const i="start"===n?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY),s=this.getPathClipPoint(e,i);if(s){const e=this.lineWorldToLocal(t,s.x,s.y),i=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),r=Math.sqrt(Math.pow(e.x-t.startX,2)+Math.pow(e.y-t.startY,2));return{localX:e.x,localY:e.y,worldX:s.x,worldY:s.y,t:i>0?r/i:"start"===n?0:1}}const r=this.getClipPolygonForObject(e);let o;if(o=r?c.getLinePointsArrayIntersection(i,{x:e.centerX,y:e.centerY},r):c.getLinePolygonIntersection(i,{x:e.centerX,y:e.centerY},e.rotatedPolygon),!o)return null;const h=this.lineWorldToLocal(t,o.x,o.y),u=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),a=Math.sqrt(Math.pow(h.x-t.startX,2)+Math.pow(h.y-t.startY,2));return{localX:h.x,localY:h.y,worldX:o.x,worldY:o.y,t:u>0?a/u:"start"===n?0:1}}computeCurvedClipInfo(t,n,e){if(Wc.isInstanceOf(e,"KritzelPath"))return this.findCurveExitPointForPath(t,n,e);const i=this.getClipPolygonForObject(e),s=i??this.getPolygonPoints(e.rotatedPolygon),r=this.findCurveExitPoint(t,n,s);if(r)return r;const o="start"===n?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY);let h;if(h=i?c.getLinePointsArrayIntersection(o,{x:e.centerX,y:e.centerY},i):c.getLinePolygonIntersection(o,{x:e.centerX,y:e.centerY},e.rotatedPolygon),!h)return null;const u=this.lineWorldToLocal(t,h.x,h.y),a=this.approximateParameterForWorldPoint(t,h);return{localX:u.x,localY:u.y,worldX:h.x,worldY:h.y,t:a}}findCurveExitPoint(t,n,e){const i="start"===n?0:1,s=this.evaluateLineAtT(t,i);let r=c.isPointInPolygon({x:s.worldX,y:s.worldY},e),o=i;for(let i=1;i<=64;i++){const s="start"===n?i/64:1-i/64,h=this.evaluateLineAtT(t,s),u=c.isPointInPolygon({x:h.worldX,y:h.worldY},e);if(r&&!u){const n=this.refineCurveExitParameter(t,e,o,s),i=this.evaluateLineAtT(t,n);return{localX:i.localX,localY:i.localY,worldX:i.worldX,worldY:i.worldY,t:n}}r=u,o=s}return null}findCurveExitPointForPath(t,n,e){const i="start"===n?0:1,s=e.strokeWidth/e.scale/2,r=this.getPathAdjustedPoints(e);if(r.length<1)return null;const o=this.evaluateLineAtT(t,i);let h=this.isPointInPathStroke(o.worldX,o.worldY,r,s),c=i;for(let e=1;e<=64;e++){const i="start"===n?e/64:1-e/64,o=this.evaluateLineAtT(t,i),u=this.isPointInPathStroke(o.worldX,o.worldY,r,s);if(h&&!u){const n=this.refineCurveExitParameterForPath(t,r,s,c,i),e=this.evaluateLineAtT(t,n);return{localX:e.localX,localY:e.localY,worldX:e.worldX,worldY:e.worldY,t:n}}h=u,c=i}return null}refineCurveExitParameterForPath(t,n,e,i,s){let r=i,o=s;for(let i=0;i<8;i++){const i=(r+o)/2,s=this.evaluateLineAtT(t,i);this.isPointInPathStroke(s.worldX,s.worldY,n,e)?r=i:o=i}return(r+o)/2}getPathAdjustedPoints(t){return this.computePathAdjustedPoints(t)}computePathAdjustedPoints(t){if(!t.points?.length)return[];const n=t.rotation,e=Math.cos(n),i=Math.sin(n),s=t.points.map((t=>t[0])),r=t.points.map((t=>t[1])),o={x:(Math.min(...s)+Math.max(...s))/2,y:(Math.min(...r)+Math.max(...r))/2},{x:h,y:c}=o;return t.points.map((([t,n])=>{const s=t-h,r=n-c;return[h+s*e-r*i,c+s*i+r*e]})).map((([n,e])=>[Math.abs(n-t.x)/t.scale+t.translateX,Math.abs(e-t.y)/t.scale+t.translateY]))}isPointInPathStroke(t,n,e,i){if(1===e.length){const s=e[0],r=t-s[0],o=n-s[1];return Math.sqrt(r*r+o*o)<=i}for(let s=0;s<e.length-1;s++){const r=e[s],o=e[s+1];if(this.pointToSegmentDistance(t,n,r[0],r[1],o[0],o[1])<=i)return!0}return!1}pointToSegmentDistance(t,n,e,i,s,r){const o=s-e,h=r-i,c=o*o+h*h;if(0===c)return Math.sqrt((t-e)*(t-e)+(n-i)*(n-i));let u=((t-e)*o+(n-i)*h)/c;u=Math.max(0,Math.min(1,u));const a=e+u*o,l=i+u*h;return Math.sqrt((t-a)*(t-a)+(n-l)*(n-l))}refineCurveExitParameter(t,n,e,i){let s=e,r=i;for(let e=0;e<8;e++){const e=(s+r)/2,i=this.evaluateLineAtT(t,e);c.isPointInPolygon({x:i.worldX,y:i.worldY},n)?s=e:r=e}return(s+r)/2}approximateParameterForWorldPoint(t,n){let e=0,i=1/0;for(let s=0;s<=80;s++){const r=s/80,o=this.evaluateLineAtT(t,r),h=Math.hypot(o.worldX-n.x,o.worldY-n.y);h<i&&(i=h,e=r)}return e}evaluateLineAtT(t,n){const e=Math.max(0,Math.min(1,n));let i,s;if(void 0!==t.controlX&&void 0!==t.controlY){const n=1-e;i=n*n*t.startX+2*n*e*t.controlX+e*e*t.endX,s=n*n*t.startY+2*n*e*t.controlY+e*e*t.endY}else i=t.startX+(t.endX-t.startX)*e,s=t.startY+(t.endY-t.startY)*e;const r=this.lineLocalToWorld(t,i,s);return{t:e,localX:i,localY:s,worldX:r.x,worldY:r.y}}evaluateDerivativeSpeedAtT(t,n){const e=Math.max(0,Math.min(1,n));if(void 0!==t.controlX&&void 0!==t.controlY){const n=t.controlX,i=t.controlY,s=2*(1-e)*(n-t.startX)+2*e*(t.endX-n),r=2*(1-e)*(i-t.startY)+2*e*(t.endY-i);return Math.sqrt(s*s+r*r)}{const n=t.endX-t.startX,e=t.endY-t.startY;return Math.sqrt(n*n+e*e)}}extractQuadraticSegment(t,n,e,i,s){let r=Math.max(0,Math.min(1,i)),o=Math.max(0,Math.min(1,s));if(o<r){const t=r;r=o,o=t}let h={start:t,control:n,end:e};if(r>0){h=this.splitQuadraticSegment(h,r).right;const t=1-r;o=t>0?(o-r)/t:1}return o<1&&(h=this.splitQuadraticSegment(h,o).left),h}splitQuadraticSegment(t,n){const e=Math.max(0,Math.min(1,n)),i=t.start,s=t.control,r=t.end,o=this.lerpPoint(i,s,e),h=this.lerpPoint(s,r,e),c=this.lerpPoint(o,h,e);return{left:{start:i,control:o,end:c},right:{start:c,control:h,end:r}}}lerpPoint(t,n,e){return{x:t.x+(n.x-t.x)*e,y:t.y+(n.y-t.y)*e}}buildAnchorPath(t,n,e,i){if(void 0===t.controlX||void 0===t.controlY||void 0===e.t)return`M ${e.worldX} ${e.worldY} L ${i.centerX} ${i.centerY}`;const s="start"===n?0:e.t,r="start"===n?e.t:1;if(r<=s)return`M ${e.worldX} ${e.worldY} L ${i.centerX} ${i.centerY}`;const o=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},s,r);return this.buildWorldQuadraticPath(t,o,"start"===n)}buildWorldQuadraticPath(t,n,e=!1){const i=e?n.end:n.start,s=e?n.start:n.end,r=n.control,o=this.lineLocalToWorld(t,i.x,i.y),h=this.lineLocalToWorld(t,r.x,r.y),c=this.lineLocalToWorld(t,s.x,s.y);return`M ${o.x} ${o.y} Q ${h.x} ${h.y} ${c.x} ${c.y}`}getPolygonPoints(t){return[t.topLeft,t.topRight,t.bottomRight,t.bottomLeft]}getClipPolygonForObject(t){return Wc.isInstanceOf(t,"KritzelShape")?t.getClipPolygon():null}getPathClipPoint(t,n){return Wc.isInstanceOf(t,"KritzelPath")?t.getClipPoint(n):null}lineLocalToWorld(t,n,e){const i=n-t.x,s=e-t.y,r=t.totalWidth/2,o=t.totalHeight/2,h=Math.cos(t.rotation),c=Math.sin(t.rotation);return{x:((i-r)*h-(s-o)*c+r)/t.scale+t.translateX,y:((i-r)*c+(s-o)*h+o)/t.scale+t.translateY}}lineWorldToLocal(t,n,e){const i=(n-t.translateX)*t.scale,s=(e-t.translateY)*t.scale,r=t.totalWidth/2,o=t.totalHeight/2,h=Math.cos(-t.rotation),c=Math.sin(-t.rotation);return{x:(i-r)*h-(s-o)*c+r+t.x,y:(i-r)*c+(s-o)*h+o+t.y}}isAnchorable(t){return!(t instanceof Ct||t instanceof D)&&!(t instanceof z)&&t.isVisible}}var Yc;!function(t){t.Rectangle="rectangle",t.Ellipse="ellipse",t.Triangle="triangle"}(Yc||(Yc={}));class Xc extends h{__class__="KritzelShape";shapeType=Yc.Rectangle;fillColor="transparent";strokeColor="#000000";strokeWidth=4;fontFamily="Arial";fontSize=16;fontColor="#000000";x=0;y=0;scale=1;scaleFactor=1;isDebugInfoVisible=!0;isEditable=!0;isEditing=!1;editor=null;content=null;_schema=new f({nodes:v(d.spec.nodes,"paragraph block*","block"),marks:d.spec.marks});uneditedObject=null;get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t){super(),t&&(this.x=t.x??0,this.y=t.y??0,this.translateX=t.translateX??0,this.translateY=t.translateY??0,this.width=t.width??100,this.height=t.height??100,this.shapeType=t.shapeType??Yc.Rectangle,this.fillColor=t.fillColor??"transparent",this.strokeColor=t.strokeColor??"#000000",this.strokeWidth=t.strokeWidth??4,this.fontSize=t.fontSize??16,this.fontFamily=t.fontFamily??"Arial",this.fontColor=t.fontColor??"#000000",this.scale=t.scale??1,this.scaleFactor=t.scaleX??1)}static create(t,n){const e=new Xc;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.x=n?.x??0,e.y=n?.y??0,e.translateX=n?.translateX??0,e.translateY=n?.translateY??0,e.width=n?.width??100,e.height=n?.height??100,e.shapeType=n?.shapeType??Yc.Rectangle,e.fillColor=n?.fillColor??"transparent",e.strokeColor=n?.strokeColor??"#000000",e.strokeWidth=n?.strokeWidth??4,e.fontSize=n?.fontSize??16,e.fontFamily=n?.fontFamily??"Arial",e.fontColor=n?.fontColor??"#000000",e.backgroundColor="transparent",e.scaleFactor=1,e.scale=t.store.state.scale,e.zIndex=t.store.currentZIndex,e.editor=e.createEditor(),e.updateDimensions(),e}updateDimensions(){this.translateX=(this.x+this.translateX)/this.scale,this.translateY=(this.y+this.translateY)/this.scale}mount(t){null!==t&&!1!==this.isInViewport()&&(this.isMounted&&this.elementRef===t&&this.editor.dom.parentElement===t||(this.elementRef=t,this.isMounted=!0))}mountTextEditor(t){null!==t&&this.editor.dom.parentElement!==t&&(t.style.fontFamily=this.fontFamily,t.style.fontSize=`${this.fontSize}pt`,t.style.color=this.fontColor,t.style.whiteSpace="pre-wrap",t.style.wordWrap="break-word",t.innerHTML="",t.appendChild(this.editor.dom))}createEditor(){const t=this._schema.node("doc",null,[this._schema.node("paragraph")]);return new p(null,{state:w.create({doc:t,plugins:[y(m)]}),editable:()=>!1,dispatchTransaction:t=>{const n=this.editor.state.apply(t);this.editor.updateState(n),t.docChanged&&(this.content=n.doc.toJSON(),t.getMeta("fromRemote")||this._core.store.state.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const n=this.editor.state.schema.nodeFromJSON(t),e=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,n.content);e.setMeta("fromRemote",!0),this.editor.dispatch(e)}}resize(t,n,e,i){e<=1||i<=1||(this.width=e,this.height=i,this.translateX=t,this.translateY=n,this._core.store.state.objects.update(this))}focus(t){if(this.editor){const n=this.editor.state.doc;if(t?.x&&t?.y){const e=this.editor.posAtCoords({left:t.x,top:t.y});if(e)return this.editor.dispatch(this.editor.state.tr.setSelection(g.create(n,e.pos))),this.editor.focus(),void(j.isIOS()&&this.scrollIntoViewOnIOS())}const e=Math.max(1,n.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(g.create(n,e))),this.editor.focus(),j.isIOS()&&this.scrollIntoViewOnIOS()}}scrollIntoViewOnIOS(){setTimeout((()=>{this.editor&&this.editor.dom&&this.editor.dom.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"})}),300)}edit(t){b.disableInteractiveWidget(),this.uneditedObject=this.clone(),this._core.store.setState("activeTool",l.getTool("shape")),this.editor.setProps({editable:()=>!0}),this.isEditing=!0,this._core.rerender(),this.focus({x:t?.clientX,y:t?.clientY}),b.enableInteractiveWidget()}save(){this.content=this.editor.state.doc.toJSON(),this.editor.setProps({editable:()=>!1}),this.editor.dom.blur(),this.isEditing=!1,this._core.store.state.objects.consolidateTemporaryItems(),this._core.store.state.objects.update(this),this._core.engine.emitObjectsChange()}handlePointerDown(t){this.isEditing&&t.stopPropagation()}handlePointerMove(t){this.isEditing&&t.stopPropagation()}handlePointerUp(t){this.isEditing&&t.stopPropagation()}copy(){const t=super.copy();return t.editor=t.createEditor(),this.content&&t.setContent(this.content),t}serialize(){const{_core:t,_elementRef:n,_schema:e,element:i,totalWidth:s,totalHeight:r,editor:o,uneditedObject:h,...c}=this,u=structuredClone(c);return i&&"object"==typeof i&&"nodeType"in i&&1===i.nodeType&&(u.element=i.cloneNode(!0)),u}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}getClipPolygon(){const t=this.totalWidth/this.scale,n=this.totalHeight/this.scale,e=this.translateX+t/2,i=this.translateY+n/2,s=this.strokeWidth/this.scale/2;switch(this.shapeType){case Yc.Ellipse:return c.getEllipsePolygonApproximation(e,i,t/2+s,n/2+s,32,this.rotation);case Yc.Triangle:const r=(t,n)=>{const r=t-e,o=n-i,h=Math.sqrt(r*r+o*o);if(0===h)return{x:t,y:n};const c=(h+s)/h;return{x:e+r*c,y:i+o*c}},o=this.translateX,h=this.translateY+n,u=this.translateX+t,a=this.translateY+n,l=r(this.translateX+t/2,this.translateY),f=r(u,a),d=r(o,h);if(0!==this.rotation){const t=Math.cos(this.rotation),n=Math.sin(this.rotation),s=s=>{const r=s.x-e,o=s.y-i;return{x:e+r*t-o*n,y:i+r*n+o*t}};return[s(l),s(f),s(d)]}return[l,f,d];default:return null}}getSvgPath(){const t=this.width,n=this.height;switch(this.shapeType){case Yc.Rectangle:return`M ${this.x} ${this.y} L ${this.x+t} ${this.y} L ${this.x+t} ${this.y+n} L ${this.x} ${this.y+n} Z`;case Yc.Ellipse:const e=this.x+t/2,i=this.y+n/2,s=t/2,r=n/2;return`M ${e-s} ${i} A ${s} ${r} 0 1 0 ${e+s} ${i} A ${s} ${r} 0 1 0 ${e-s} ${i}`;case Yc.Triangle:return`M ${this.x+t/2} ${this.y} L ${this.x+t} ${this.y+n} L ${this.x} ${this.y+n} Z`;default:return`M ${this.x} ${this.y} L ${this.x+t} ${this.y} L ${this.x+t} ${this.y+n} L ${this.x} ${this.y+n} Z`}}}class Hc extends u{shapeType=Yc.Rectangle;fillColor="transparent";strokeColor="#000000";strokeWidth=4;fontFamily="Arial";fontSize=16;fontColor="#000000";palette=["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#808080","#C0C0C0","#800000","#008000","#000080","#808000","#800080"];startX=0;startY=0;isDrawing=!1;currentShape=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){const n=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),e=this._core.findObjectById(n?.id),i=this._core.store.activeShape;if(null===i&&e instanceof Xc)return void e.edit(t);if(null!==i&&e instanceof Xc)return i.save(),void e.edit(t);if(null!==i&&e instanceof Xc==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",l.getTool("selection"));if(!1===a.isLeftClick(t))return;this.startDrawing(t.clientX,t.clientY)}if("touch"===t.pointerType){const n=Array.from(this._core.store.state.pointers.values()),e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),i=this._core.findObjectById(e?.id),s=this._core.store.activeShape;if(null===s&&i instanceof Xc)return void i.edit(t);if(null!==s&&i instanceof Xc)return s.save(),void i.edit(t);if(null!==s&&i instanceof Xc==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",l.getTool("selection"));if(n.length>1)return;const r=Math.round(n[0].clientX),o=Math.round(n[0].clientY);this.startDrawing(r,o)}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),this.isDrawing&&this.currentShape&&("mouse"===t.pointerType&&this.updateShapeSize(t.clientX,t.clientY),"touch"===t.pointerType)){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const n=Math.round(t[0].clientX),e=Math.round(t[0].clientY);this.updateShapeSize(n,e)}}}handlePointerUp(t){t.cancelable&&t.preventDefault(),this.isDrawing&&this.currentShape&&this.finishDrawing()}startDrawing(t,n){this.startX=t-this._core.store.offsetX,this.startY=n-this._core.store.offsetY,this.isDrawing=!0,this.currentShape=Xc.create(this._core,{x:this.startX,y:this.startY,translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,width:1,height:1,shapeType:this.shapeType,fillColor:this.fillColor,strokeColor:this.strokeColor,strokeWidth:this.strokeWidth,fontSize:this.fontSize,fontFamily:this.fontFamily,fontColor:this.fontColor}),this._core.store.state.objects.insert(this.currentShape),this._core.rerender()}updateShapeSize(t,n){if(!this.currentShape)return;const e=t-this._core.store.offsetX,i=n-this._core.store.offsetY,s=Math.min(this.startX,e),r=Math.min(this.startY,i),o=Math.abs(e-this.startX),h=Math.abs(i-this.startY);this.currentShape.x=s,this.currentShape.y=r,this.currentShape.width=Math.max(1,o),this.currentShape.height=Math.max(1,h),this.currentShape.translateX=-this._core.store.state.translateX,this.currentShape.translateY=-this._core.store.state.translateY,this.currentShape.updateDimensions(),this._core.store.state.objects.update(this.currentShape)}finishDrawing(){if(this.currentShape){if(this.currentShape.width<10&&this.currentShape.height<10){const t=this.currentShape.id;this._core.store.state.objects.remove((n=>n.id===t))}else this.currentShape.zIndex=this._core.store.currentZIndex,this._core.store.state.objects.update(this.currentShape),this._core.engine.emitObjectsChange(),this._core.selectObjects([this.currentShape]),this._core.store.setState("activeTool",l.getTool("selection"));this.isDrawing=!1,this.currentShape=null,this._core.rerender()}}}const Kc=1e3,Nc=1e-4;var Qc,Vc,Gc,qc={exports:{}},Jc=(Qc||(Qc=1,Vc=qc,Gc=qc.exports,function(){var t,n="Expected a function",e="__lodash_hash_undefined__",i="__lodash_placeholder__",s=32,r=128,o=1/0,h=9007199254740991,c=NaN,u=4294967295,a=[["ary",r],["bind",1],["bindKey",2],["curry",8],["curryRight",16],["flip",512],["partial",s],["partialRight",64],["rearg",256]],l="[object Arguments]",f="[object Array]",d="[object Boolean]",v="[object Date]",p="[object Error]",w="[object Function]",y="[object GeneratorFunction]",g="[object Map]",b="[object Number]",m="[object Object]",A="[object Promise]",k="[object RegExp]",M="[object Set]",x="[object String]",S="[object Symbol]",C="[object WeakMap]",T="[object ArrayBuffer]",j="[object DataView]",U="[object Float32Array]",E="[object Float64Array]",$="[object Int8Array]",_="[object Int16Array]",O="[object Int32Array]",z="[object Uint8Array]",P="[object Uint8ClampedArray]",D="[object Uint16Array]",F="[object Uint32Array]",R=/\b__p \+= '';/g,L=/\b(__p \+=) '' \+/g,W=/(__e\(.*?\)|\b__t\)) \+\n'';/g,B=/&(?:amp|lt|gt|quot|#39);/g,Y=/[&<>"']/g,X=RegExp(B.source),H=RegExp(Y.source),K=/<%-([\s\S]+?)%>/g,N=/<%([\s\S]+?)%>/g,Q=/<%=([\s\S]+?)%>/g,V=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,G=/^\w*$/,q=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,J=/[\\^$.*+?()[\]{}|]/g,Z=RegExp(J.source),tt=/^\s+/,nt=/\s/,et=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,it=/\{\n\/\* \[wrapped with (.+)\] \*/,st=/,? & /,rt=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,ot=/[()=,{}\[\]\/\s]/,ht=/\\(\\)?/g,ct=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,ut=/\w*$/,at=/^[-+]0x[0-9a-f]+$/i,lt=/^0b[01]+$/i,ft=/^\[object .+?Constructor\]$/,dt=/^0o[0-7]+$/i,vt=/^(?:0|[1-9]\d*)$/,pt=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,wt=/($^)/,yt=/['\n\r\u2028\u2029\\]/g,gt="\\ud800-\\udfff",bt="\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff",mt="\\u2700-\\u27bf",At="a-z\\xdf-\\xf6\\xf8-\\xff",kt="A-Z\\xc0-\\xd6\\xd8-\\xde",Mt="\\ufe0e\\ufe0f",xt="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",St="["+gt+"]",Ct="["+xt+"]",Tt="["+bt+"]",jt="\\d+",Ut="["+mt+"]",Et="["+At+"]",$t="[^"+gt+xt+jt+mt+At+kt+"]",_t="\\ud83c[\\udffb-\\udfff]",It="[^"+gt+"]",Ot="(?:\\ud83c[\\udde6-\\uddff]){2}",zt="[\\ud800-\\udbff][\\udc00-\\udfff]",Pt="["+kt+"]",Dt="\\u200d",Ft="(?:"+Et+"|"+$t+")",Rt="(?:"+Pt+"|"+$t+")",Lt="(?:['’](?:d|ll|m|re|s|t|ve))?",Wt="(?:['’](?:D|LL|M|RE|S|T|VE))?",Bt="(?:"+Tt+"|"+_t+")?",Yt="["+Mt+"]?",Xt=Yt+Bt+"(?:"+Dt+"(?:"+[It,Ot,zt].join("|")+")"+Yt+Bt+")*",Ht="(?:"+[Ut,Ot,zt].join("|")+")"+Xt,Kt="(?:"+[It+Tt+"?",Tt,Ot,zt,St].join("|")+")",Nt=RegExp("['’]","g"),Qt=RegExp(Tt,"g"),Vt=RegExp(_t+"(?="+_t+")|"+Kt+Xt,"g"),Gt=RegExp([Pt+"?"+Et+"+"+Lt+"(?="+[Ct,Pt,"$"].join("|")+")",Rt+"+"+Wt+"(?="+[Ct,Pt+Ft,"$"].join("|")+")",Pt+"?"+Ft+"+"+Lt,Pt+"+"+Wt,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])","\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",jt,Ht].join("|"),"g"),qt=RegExp("["+Dt+gt+bt+Mt+"]"),Jt=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Zt=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],tn=-1,nn={};nn[U]=nn[E]=nn[$]=nn[_]=nn[O]=nn[z]=nn[P]=nn[D]=nn[F]=!0,nn[l]=nn[f]=nn[T]=nn[d]=nn[j]=nn[v]=nn[p]=nn[w]=nn[g]=nn[b]=nn[m]=nn[k]=nn[M]=nn[x]=nn[C]=!1;var en={};en[l]=en[f]=en[T]=en[j]=en[d]=en[v]=en[U]=en[E]=en[$]=en[_]=en[O]=en[g]=en[b]=en[m]=en[k]=en[M]=en[x]=en[S]=en[z]=en[P]=en[D]=en[F]=!0,en[p]=en[w]=en[C]=!1;var sn={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},rn=parseFloat,on=parseInt,hn="object"==typeof I&&I&&I.Object===Object&&I,cn="object"==typeof self&&self&&self.Object===Object&&self,un=hn||cn||Function("return this")(),an=Gc&&!Gc.nodeType&&Gc,ln=an&&Vc&&!Vc.nodeType&&Vc,fn=ln&&ln.exports===an,dn=fn&&hn.process,vn=function(){try{return ln&&ln.require&&ln.require("util").types||dn&&dn.binding&&dn.binding("util")}catch(t){}}(),pn=vn&&vn.isArrayBuffer,wn=vn&&vn.isDate,yn=vn&&vn.isMap,gn=vn&&vn.isRegExp,bn=vn&&vn.isSet,mn=vn&&vn.isTypedArray;function An(t,n,e){switch(e.length){case 0:return t.call(n);case 1:return t.call(n,e[0]);case 2:return t.call(n,e[0],e[1]);case 3:return t.call(n,e[0],e[1],e[2])}return t.apply(n,e)}function kn(t,n,e,i){for(var s=-1,r=null==t?0:t.length;++s<r;){var o=t[s];n(i,o,e(o),t)}return i}function Mn(t,n){for(var e=-1,i=null==t?0:t.length;++e<i&&!1!==n(t[e],e,t););return t}function xn(t,n){for(var e=null==t?0:t.length;e--&&!1!==n(t[e],e,t););return t}function Sn(t,n){for(var e=-1,i=null==t?0:t.length;++e<i;)if(!n(t[e],e,t))return!1;return!0}function Cn(t,n){for(var e=-1,i=null==t?0:t.length,s=0,r=[];++e<i;){var o=t[e];n(o,e,t)&&(r[s++]=o)}return r}function Tn(t,n){return!(null==t||!t.length)&&Dn(t,n,0)>-1}function jn(t,n,e){for(var i=-1,s=null==t?0:t.length;++i<s;)if(e(n,t[i]))return!0;return!1}function Un(t,n){for(var e=-1,i=null==t?0:t.length,s=Array(i);++e<i;)s[e]=n(t[e],e,t);return s}function En(t,n){for(var e=-1,i=n.length,s=t.length;++e<i;)t[s+e]=n[e];return t}function $n(t,n,e,i){var s=-1,r=null==t?0:t.length;for(i&&r&&(e=t[++s]);++s<r;)e=n(e,t[s],s,t);return e}function _n(t,n,e,i){var s=null==t?0:t.length;for(i&&s&&(e=t[--s]);s--;)e=n(e,t[s],s,t);return e}function In(t,n){for(var e=-1,i=null==t?0:t.length;++e<i;)if(n(t[e],e,t))return!0;return!1}var On=Wn("length");function zn(t,n,e){var i;return e(t,(function(t,e,s){if(n(t,e,s))return i=e,!1})),i}function Pn(t,n,e,i){for(var s=t.length,r=e+(i?1:-1);i?r--:++r<s;)if(n(t[r],r,t))return r;return-1}function Dn(t,n,e){return n==n?function(t,n,e){for(var i=e-1,s=t.length;++i<s;)if(t[i]===n)return i;return-1}(t,n,e):Pn(t,Rn,e)}function Fn(t,n,e,i){for(var s=e-1,r=t.length;++s<r;)if(i(t[s],n))return s;return-1}function Rn(t){return t!=t}function Ln(t,n){var e=null==t?0:t.length;return e?Xn(t,n)/e:c}function Wn(n){return function(e){return null==e?t:e[n]}}function Bn(n){return function(e){return null==n?t:n[e]}}function Yn(t,n,e,i,s){return s(t,(function(t,s,r){e=i?(i=!1,t):n(e,t,s,r)})),e}function Xn(n,e){for(var i,s=-1,r=n.length;++s<r;){var o=e(n[s]);o!==t&&(i=i===t?o:i+o)}return i}function Hn(t,n){for(var e=-1,i=Array(t);++e<t;)i[e]=n(e);return i}function Kn(t){return t?t.slice(0,ue(t)+1).replace(tt,""):t}function Nn(t){return function(n){return t(n)}}function Qn(t,n){return Un(n,(function(n){return t[n]}))}function Vn(t,n){return t.has(n)}function Gn(t,n){for(var e=-1,i=t.length;++e<i&&Dn(n,t[e],0)>-1;);return e}function qn(t,n){for(var e=t.length;e--&&Dn(n,t[e],0)>-1;);return e}var Jn=Bn({À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E",Ë:"E",è:"e",é:"e",ê:"e",ë:"e",Ì:"I",Í:"I",Î:"I",Ï:"I",ì:"i",í:"i",î:"i",ï:"i",Ñ:"N",ñ:"n",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ø:"O",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ø:"o",Ù:"U",Ú:"U",Û:"U",Ü:"U",ù:"u",ú:"u",û:"u",ü:"u",Ý:"Y",ý:"y",ÿ:"y",Æ:"Ae",æ:"ae",Þ:"Th",þ:"th",ß:"ss",Ā:"A",Ă:"A",Ą:"A",ā:"a",ă:"a",ą:"a",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",ć:"c",ĉ:"c",ċ:"c",č:"c",Ď:"D",Đ:"D",ď:"d",đ:"d",Ē:"E",Ĕ:"E",Ė:"E",Ę:"E",Ě:"E",ē:"e",ĕ:"e",ė:"e",ę:"e",ě:"e",Ĝ:"G",Ğ:"G",Ġ:"G",Ģ:"G",ĝ:"g",ğ:"g",ġ:"g",ģ:"g",Ĥ:"H",Ħ:"H",ĥ:"h",ħ:"h",Ĩ:"I",Ī:"I",Ĭ:"I",Į:"I",İ:"I",ĩ:"i",ī:"i",ĭ:"i",į:"i",ı:"i",Ĵ:"J",ĵ:"j",Ķ:"K",ķ:"k",ĸ:"k",Ĺ:"L",Ļ:"L",Ľ:"L",Ŀ:"L",Ł:"L",ĺ:"l",ļ:"l",ľ:"l",ŀ:"l",ł:"l",Ń:"N",Ņ:"N",Ň:"N",Ŋ:"N",ń:"n",ņ:"n",ň:"n",ŋ:"n",Ō:"O",Ŏ:"O",Ő:"O",ō:"o",ŏ:"o",ő:"o",Ŕ:"R",Ŗ:"R",Ř:"R",ŕ:"r",ŗ:"r",ř:"r",Ś:"S",Ŝ:"S",Ş:"S",Š:"S",ś:"s",ŝ:"s",ş:"s",š:"s",Ţ:"T",Ť:"T",Ŧ:"T",ţ:"t",ť:"t",ŧ:"t",Ũ:"U",Ū:"U",Ŭ:"U",Ů:"U",Ű:"U",Ų:"U",ũ:"u",ū:"u",ŭ:"u",ů:"u",ű:"u",ų:"u",Ŵ:"W",ŵ:"w",Ŷ:"Y",ŷ:"y",Ÿ:"Y",Ź:"Z",Ż:"Z",Ž:"Z",ź:"z",ż:"z",ž:"z",IJ:"IJ",ij:"ij",Œ:"Oe",œ:"oe",ʼn:"'n",ſ:"s"}),Zn=Bn({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});function te(t){return"\\"+sn[t]}function ne(t){return qt.test(t)}function ee(t){var n=-1,e=Array(t.size);return t.forEach((function(t,i){e[++n]=[i,t]})),e}function ie(t,n){return function(e){return t(n(e))}}function se(t,n){for(var e=-1,s=t.length,r=0,o=[];++e<s;){var h=t[e];h!==n&&h!==i||(t[e]=i,o[r++]=e)}return o}function re(t){var n=-1,e=Array(t.size);return t.forEach((function(t){e[++n]=t})),e}function oe(t){var n=-1,e=Array(t.size);return t.forEach((function(t){e[++n]=[t,t]})),e}function he(t){return ne(t)?function(t){for(var n=Vt.lastIndex=0;Vt.test(t);)++n;return n}(t):On(t)}function ce(t){return ne(t)?function(t){return t.match(Vt)||[]}(t):function(t){return t.split("")}(t)}function ue(t){for(var n=t.length;n--&&nt.test(t.charAt(n)););return n}var ae=Bn({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"}),le=function I(nt){var gt,bt=(nt=null==nt?un:le.defaults(un.Object(),nt,le.pick(un,Zt))).Array,mt=nt.Date,At=nt.Error,kt=nt.Function,Mt=nt.Math,xt=nt.Object,St=nt.RegExp,Ct=nt.String,Tt=nt.TypeError,jt=bt.prototype,Ut=xt.prototype,Et=nt["__core-js_shared__"],$t=kt.prototype.toString,_t=Ut.hasOwnProperty,It=0,Ot=(gt=/[^.]+$/.exec(Et&&Et.keys&&Et.keys.IE_PROTO||""))?"Symbol(src)_1."+gt:"",zt=Ut.toString,Pt=$t.call(xt),Dt=un._,Ft=St("^"+$t.call(_t).replace(J,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Rt=fn?nt.Buffer:t,Lt=nt.Symbol,Wt=nt.Uint8Array,Bt=Rt?Rt.allocUnsafe:t,Yt=ie(xt.getPrototypeOf,xt),Xt=xt.create,Ht=Ut.propertyIsEnumerable,Kt=jt.splice,Vt=Lt?Lt.isConcatSpreadable:t,qt=Lt?Lt.iterator:t,sn=Lt?Lt.toStringTag:t,hn=function(){try{var t=hr(xt,"defineProperty");return t({},"",{}),t}catch(t){}}(),cn=nt.clearTimeout!==un.clearTimeout&&nt.clearTimeout,an=mt&&mt.now!==un.Date.now&&mt.now,ln=nt.setTimeout!==un.setTimeout&&nt.setTimeout,dn=Mt.ceil,vn=Mt.floor,On=xt.getOwnPropertySymbols,Bn=Rt?Rt.isBuffer:t,fe=nt.isFinite,de=jt.join,ve=ie(xt.keys,xt),pe=Mt.max,we=Mt.min,ye=mt.now,ge=nt.parseInt,be=Mt.random,me=jt.reverse,Ae=hr(nt,"DataView"),ke=hr(nt,"Map"),Me=hr(nt,"Promise"),xe=hr(nt,"Set"),Se=hr(nt,"WeakMap"),Ce=hr(xt,"create"),Te=Se&&new Se,je={},Ue=zr(Ae),Ee=zr(ke),$e=zr(Me),_e=zr(xe),Ie=zr(Se),Oe=Lt?Lt.prototype:t,ze=Oe?Oe.valueOf:t,Pe=Oe?Oe.toString:t;function De(t){if(Zo(t)&&!Bo(t)&&!(t instanceof We)){if(t instanceof Le)return t;if(_t.call(t,"__wrapped__"))return Pr(t)}return new Le(t)}var Fe=function(){function n(){}return function(e){if(!Jo(e))return{};if(Xt)return Xt(e);n.prototype=e;var i=new n;return n.prototype=t,i}}();function Re(){}function Le(n,e){this.__wrapped__=n,this.__actions__=[],this.__chain__=!!e,this.__index__=0,this.__values__=t}function We(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=u,this.__views__=[]}function Be(t){var n=-1,e=null==t?0:t.length;for(this.clear();++n<e;){var i=t[n];this.set(i[0],i[1])}}function Ye(t){var n=-1,e=null==t?0:t.length;for(this.clear();++n<e;){var i=t[n];this.set(i[0],i[1])}}function Xe(t){var n=-1,e=null==t?0:t.length;for(this.clear();++n<e;){var i=t[n];this.set(i[0],i[1])}}function He(t){var n=-1,e=null==t?0:t.length;for(this.__data__=new Xe;++n<e;)this.add(t[n])}function Ke(t){var n=this.__data__=new Ye(t);this.size=n.size}function Ne(t,n){var e=Bo(t),i=!e&&Wo(t),s=!e&&!i&&Ko(t),r=!e&&!i&&!s&&hh(t),o=e||i||s||r,h=o?Hn(t.length,Ct):[],c=h.length;for(var u in t)!n&&!_t.call(t,u)||o&&("length"==u||s&&("offset"==u||"parent"==u)||r&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||vr(u,c))||h.push(u);return h}function Qe(n){var e=n.length;return e?n[Xi(0,e-1)]:t}function Ve(t,n){return Er(Ss(t),si(n,0,t.length))}function Ge(t){return Er(Ss(t))}function qe(n,e,i){(i!==t&&!Fo(n[e],i)||i===t&&!(e in n))&&ei(n,e,i)}function Je(n,e,i){var s=n[e];_t.call(n,e)&&Fo(s,i)&&(i!==t||e in n)||ei(n,e,i)}function Ze(t,n){for(var e=t.length;e--;)if(Fo(t[e][0],n))return e;return-1}function ti(t,n,e,i){return ui(t,(function(t,s,r){n(i,t,e(t),r)})),i}function ni(t,n){return t&&Cs(n,Uh(n),t)}function ei(t,n,e){"__proto__"==n&&hn?hn(t,n,{configurable:!0,enumerable:!0,value:e,writable:!0}):t[n]=e}function ii(n,e){for(var i=-1,s=e.length,r=bt(s),o=null==n;++i<s;)r[i]=o?t:xh(n,e[i]);return r}function si(n,e,i){return n==n&&(i!==t&&(n=n<=i?n:i),e!==t&&(n=n>=e?n:e)),n}function ri(n,e,i,s,r,o){var h,c=1&e,u=2&e,a=4&e;if(i&&(h=r?i(n,s,r,o):i(n)),h!==t)return h;if(!Jo(n))return n;var f=Bo(n);if(f){if(h=function(t){var n=t.length,e=new t.constructor(n);return n&&"string"==typeof t[0]&&_t.call(t,"index")&&(e.index=t.index,e.input=t.input),e}(n),!c)return Ss(n,h)}else{var p=ar(n),A=p==w||p==y;if(Ko(n))return bs(n,c);if(p==m||p==l||A&&!r){if(h=u||A?{}:fr(n),!c)return u?function(t,n){return Cs(t,ur(t),n)}(n,function(t,n){return t&&Cs(n,Eh(n),t)}(h,n)):function(t,n){return Cs(t,cr(t),n)}(n,ni(h,n))}else{if(!en[p])return r?n:{};h=function(t,n,e){var i=t.constructor;switch(n){case T:return ms(t);case d:case v:return new i(+t);case j:return function(t,n){var e=n?ms(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.byteLength)}(t,e);case U:case E:case $:case _:case O:case z:case P:case D:case F:return As(t,e);case g:return new i;case b:case x:return new i(t);case k:return function(t){var n=new t.constructor(t.source,ut.exec(t));return n.lastIndex=t.lastIndex,n}(t);case M:return new i;case S:return ze?xt(ze.call(t)):{}}}(n,p,c)}}o||(o=new Ke);var C=o.get(n);if(C)return C;o.set(n,h),sh(n)?n.forEach((function(t){h.add(ri(t,e,i,t,n,o))})):th(n)&&n.forEach((function(t,s){h.set(s,ri(t,e,i,s,n,o))}));var I=f?t:(a?u?tr:Zs:u?Eh:Uh)(n);return Mn(I||n,(function(t,s){I&&(t=n[s=t]),Je(h,s,ri(t,e,i,s,n,o))})),h}function oi(n,e,i){var s=i.length;if(null==n)return!s;for(n=xt(n);s--;){var r=i[s],o=n[r];if(o===t&&!(r in n)||!(0,e[r])(o))return!1}return!0}function hi(e,i,s){if("function"!=typeof e)throw new Tt(n);return Cr((function(){e.apply(t,s)}),i)}function ci(t,n,e,i){var s=-1,r=Tn,o=!0,h=t.length,c=[],u=n.length;if(!h)return c;e&&(n=Un(n,Nn(e))),i?(r=jn,o=!1):n.length>=200&&(r=Vn,o=!1,n=new He(n));t:for(;++s<h;){var a=t[s],l=null==e?a:e(a);if(a=i||0!==a?a:0,o&&l==l){for(var f=u;f--;)if(n[f]===l)continue t;c.push(a)}else r(n,l,i)||c.push(a)}return c}De.templateSettings={escape:K,evaluate:N,interpolate:Q,variable:"",imports:{_:De}},(De.prototype=Re.prototype).constructor=De,(Le.prototype=Fe(Re.prototype)).constructor=Le,(We.prototype=Fe(Re.prototype)).constructor=We,Be.prototype.clear=function(){this.__data__=Ce?Ce(null):{},this.size=0},Be.prototype.delete=function(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n},Be.prototype.get=function(n){var i=this.__data__;if(Ce){var s=i[n];return s===e?t:s}return _t.call(i,n)?i[n]:t},Be.prototype.has=function(n){var e=this.__data__;return Ce?e[n]!==t:_t.call(e,n)},Be.prototype.set=function(n,i){var s=this.__data__;return this.size+=this.has(n)?0:1,s[n]=Ce&&i===t?e:i,this},Ye.prototype.clear=function(){this.__data__=[],this.size=0},Ye.prototype.delete=function(t){var n=this.__data__,e=Ze(n,t);return!(e<0||(e==n.length-1?n.pop():Kt.call(n,e,1),--this.size,0))},Ye.prototype.get=function(n){var e=this.__data__,i=Ze(e,n);return i<0?t:e[i][1]},Ye.prototype.has=function(t){return Ze(this.__data__,t)>-1},Ye.prototype.set=function(t,n){var e=this.__data__,i=Ze(e,t);return i<0?(++this.size,e.push([t,n])):e[i][1]=n,this},Xe.prototype.clear=function(){this.size=0,this.__data__={hash:new Be,map:new(ke||Ye),string:new Be}},Xe.prototype.delete=function(t){var n=rr(this,t).delete(t);return this.size-=n?1:0,n},Xe.prototype.get=function(t){return rr(this,t).get(t)},Xe.prototype.has=function(t){return rr(this,t).has(t)},Xe.prototype.set=function(t,n){var e=rr(this,t),i=e.size;return e.set(t,n),this.size+=e.size==i?0:1,this},He.prototype.add=He.prototype.push=function(t){return this.__data__.set(t,e),this},He.prototype.has=function(t){return this.__data__.has(t)},Ke.prototype.clear=function(){this.__data__=new Ye,this.size=0},Ke.prototype.delete=function(t){var n=this.__data__,e=n.delete(t);return this.size=n.size,e},Ke.prototype.get=function(t){return this.__data__.get(t)},Ke.prototype.has=function(t){return this.__data__.has(t)},Ke.prototype.set=function(t,n){var e=this.__data__;if(e instanceof Ye){var i=e.__data__;if(!ke||i.length<199)return i.push([t,n]),this.size=++e.size,this;e=this.__data__=new Xe(i)}return e.set(t,n),this.size=e.size,this};var ui=Us(yi),ai=Us(gi,!0);function li(t,n){var e=!0;return ui(t,(function(t,i,s){return e=!!n(t,i,s)})),e}function fi(n,e,i){for(var s=-1,r=n.length;++s<r;){var o=n[s],h=e(o);if(null!=h&&(c===t?h==h&&!oh(h):i(h,c)))var c=h,u=o}return u}function di(t,n){var e=[];return ui(t,(function(t,i,s){n(t,i,s)&&e.push(t)})),e}function vi(t,n,e,i,s){var r=-1,o=t.length;for(e||(e=dr),s||(s=[]);++r<o;){var h=t[r];n>0&&e(h)?n>1?vi(h,n-1,e,i,s):En(s,h):i||(s[s.length]=h)}return s}var pi=Es(),wi=Es(!0);function yi(t,n){return t&&pi(t,n,Uh)}function gi(t,n){return t&&wi(t,n,Uh)}function bi(t,n){return Cn(n,(function(n){return Vo(t[n])}))}function mi(n,e){for(var i=0,s=(e=ps(e,n)).length;null!=n&&i<s;)n=n[Or(e[i++])];return i&&i==s?n:t}function Ai(t,n,e){var i=n(t);return Bo(t)?i:En(i,e(t))}function ki(n){return null==n?n===t?"[object Undefined]":"[object Null]":sn&&sn in xt(n)?function(n){var e=_t.call(n,sn),i=n[sn];try{n[sn]=t;var s=!0}catch(t){}var r=zt.call(n);return s&&(e?n[sn]=i:delete n[sn]),r}(n):function(t){return zt.call(t)}(n)}function Mi(t,n){return t>n}function xi(t,n){return null!=t&&_t.call(t,n)}function Si(t,n){return null!=t&&n in xt(t)}function Ci(n,e,i){for(var s=i?jn:Tn,r=n[0].length,o=n.length,h=o,c=bt(o),u=1/0,a=[];h--;){var l=n[h];h&&e&&(l=Un(l,Nn(e))),u=we(l.length,u),c[h]=!i&&(e||r>=120&&l.length>=120)?new He(h&&l):t}l=n[0];var f=-1,d=c[0];t:for(;++f<r&&a.length<u;){var v=l[f],p=e?e(v):v;if(v=i||0!==v?v:0,!(d?Vn(d,p):s(a,p,i))){for(h=o;--h;){var w=c[h];if(!(w?Vn(w,p):s(n[h],p,i)))continue t}d&&d.push(p),a.push(v)}}return a}function Ti(n,e,i){var s=null==(n=Mr(n,e=ps(e,n)))?n:n[Or(Nr(e))];return null==s?t:An(s,n,i)}function ji(t){return Zo(t)&&ki(t)==l}function Ui(n,e,i,s,r){return n===e||(null==n||null==e||!Zo(n)&&!Zo(e)?n!=n&&e!=e:function(n,e,i,s,r,o){var h=Bo(n),c=Bo(e),u=h?f:ar(n),a=c?f:ar(e),w=(u=u==l?m:u)==m,y=(a=a==l?m:a)==m,A=u==a;if(A&&Ko(n)){if(!Ko(e))return!1;h=!0,w=!1}if(A&&!w)return o||(o=new Ke),h||hh(n)?qs(n,e,i,s,r,o):function(t,n,e,i,s,r,o){switch(e){case j:if(t.byteLength!=n.byteLength||t.byteOffset!=n.byteOffset)return!1;t=t.buffer,n=n.buffer;case T:return!(t.byteLength!=n.byteLength||!r(new Wt(t),new Wt(n)));case d:case v:case b:return Fo(+t,+n);case p:return t.name==n.name&&t.message==n.message;case k:case x:return t==n+"";case g:var h=ee;case M:if(h||(h=re),t.size!=n.size&&!(1&i))return!1;var c=o.get(t);if(c)return c==n;i|=2,o.set(t,n);var u=qs(h(t),h(n),i,s,r,o);return o.delete(t),u;case S:if(ze)return ze.call(t)==ze.call(n)}return!1}(n,e,u,i,s,r,o);if(!(1&i)){var C=w&&_t.call(n,"__wrapped__"),U=y&&_t.call(e,"__wrapped__");if(C||U){var E=C?n.value():n,$=U?e.value():e;return o||(o=new Ke),r(E,$,i,s,o)}}return!!A&&(o||(o=new Ke),function(n,e,i,s,r,o){var h=1&i,c=Zs(n),u=c.length;if(u!=Zs(e).length&&!h)return!1;for(var a=u;a--;){var l=c[a];if(!(h?l in e:_t.call(e,l)))return!1}var f=o.get(n),d=o.get(e);if(f&&d)return f==e&&d==n;var v=!0;o.set(n,e),o.set(e,n);for(var p=h;++a<u;){var w=n[l=c[a]],y=e[l];if(s)var g=h?s(y,w,l,e,n,o):s(w,y,l,n,e,o);if(!(g===t?w===y||r(w,y,i,s,o):g)){v=!1;break}p||(p="constructor"==l)}if(v&&!p){var b=n.constructor,m=e.constructor;b==m||!("constructor"in n)||!("constructor"in e)||"function"==typeof b&&b instanceof b&&"function"==typeof m&&m instanceof m||(v=!1)}return o.delete(n),o.delete(e),v}(n,e,i,s,r,o))}(n,e,i,s,Ui,r))}function Ei(n,e,i,s){var r=i.length,o=r,h=!s;if(null==n)return!o;for(n=xt(n);r--;){var c=i[r];if(h&&c[2]?c[1]!==n[c[0]]:!(c[0]in n))return!1}for(;++r<o;){var u=(c=i[r])[0],a=n[u],l=c[1];if(h&&c[2]){if(a===t&&!(u in n))return!1}else{var f=new Ke;if(s)var d=s(a,l,u,n,e,f);if(!(d===t?Ui(l,a,3,s,f):d))return!1}}return!0}function $i(t){return!(!Jo(t)||(n=t,Ot&&Ot in n))&&(Vo(t)?Ft:ft).test(zr(t));var n}function _i(t){return"function"==typeof t?t:null==t?nc:"object"==typeof t?Bo(t)?Di(t[0],t[1]):Pi(t):ac(t)}function Ii(t){if(!br(t))return ve(t);var n=[];for(var e in xt(t))_t.call(t,e)&&"constructor"!=e&&n.push(e);return n}function Oi(t,n){return t<n}function zi(t,n){var e=-1,i=Xo(t)?bt(t.length):[];return ui(t,(function(t,s,r){i[++e]=n(t,s,r)})),i}function Pi(t){var n=or(t);return 1==n.length&&n[0][2]?Ar(n[0][0],n[0][1]):function(e){return e===t||Ei(e,t,n)}}function Di(n,e){return wr(n)&&mr(e)?Ar(Or(n),e):function(i){var s=xh(i,n);return s===t&&s===e?Sh(i,n):Ui(e,s,3)}}function Fi(n,e,i,s,r){n!==e&&pi(e,(function(o,h){if(r||(r=new Ke),Jo(o))!function(n,e,i,s,r,o,h){var c=xr(n,i),u=xr(e,i),a=h.get(u);if(a)qe(n,i,a);else{var l=o?o(c,u,i+"",n,e,h):t,f=l===t;if(f){var d=Bo(u),v=!d&&Ko(u),p=!d&&!v&&hh(u);l=u,d||v||p?Bo(c)?l=c:Ho(c)?l=Ss(c):v?(f=!1,l=bs(u,!0)):p?(f=!1,l=As(u,!0)):l=[]:eh(u)||Wo(u)?(l=c,Wo(c)?l=ph(c):Jo(c)&&!Vo(c)||(l=fr(u))):f=!1}f&&(h.set(u,l),r(l,u,s,o,h),h.delete(u)),qe(n,i,l)}}(n,e,h,i,Fi,s,r);else{var c=s?s(xr(n,h),o,h+"",n,e,r):t;c===t&&(c=o),qe(n,h,c)}}),Eh)}function Ri(n,e){var i=n.length;if(i)return vr(e+=e<0?i:0,i)?n[e]:t}function Li(t,n,e){n=n.length?Un(n,(function(t){return Bo(t)?function(n){return mi(n,1===t.length?t[0]:t)}:t})):[nc];var i=-1;n=Un(n,Nn(sr()));var s=zi(t,(function(t){var e=Un(n,(function(n){return n(t)}));return{criteria:e,index:++i,value:t}}));return function(t){var n=t.length;for(t.sort((function(t,n){return function(t,n,e){for(var i=-1,s=t.criteria,r=n.criteria,o=s.length,h=e.length;++i<o;){var c=ks(s[i],r[i]);if(c)return i>=h?c:c*("desc"==e[i]?-1:1)}return t.index-n.index}(t,n,e)}));n--;)t[n]=t[n].value;return t}(s)}function Wi(t,n,e){for(var i=-1,s=n.length,r={};++i<s;){var o=n[i],h=mi(t,o);e(h,o)&&Vi(r,ps(o,t),h)}return r}function Bi(t,n,e,i){var s=i?Fn:Dn,r=-1,o=n.length,h=t;for(t===n&&(n=Ss(n)),e&&(h=Un(t,Nn(e)));++r<o;)for(var c=0,u=n[r],a=e?e(u):u;(c=s(h,a,c,i))>-1;)h!==t&&Kt.call(h,c,1),Kt.call(t,c,1);return t}function Yi(t,n){for(var e=t?n.length:0,i=e-1;e--;){var s=n[e];if(e==i||s!==r){var r=s;vr(s)?Kt.call(t,s,1):hs(t,s)}}return t}function Xi(t,n){return t+vn(be()*(n-t+1))}function Hi(t,n){var e="";if(!t||n<1||n>h)return e;do{n%2&&(e+=t),(n=vn(n/2))&&(t+=t)}while(n);return e}function Ki(t,n){return Tr(kr(t,n,nc),t+"")}function Ni(t){return Qe(Fh(t))}function Qi(t,n){var e=Fh(t);return Er(e,si(n,0,e.length))}function Vi(n,e,i,s){if(!Jo(n))return n;for(var r=-1,o=(e=ps(e,n)).length,h=o-1,c=n;null!=c&&++r<o;){var u=Or(e[r]),a=i;if("__proto__"===u||"constructor"===u||"prototype"===u)return n;if(r!=h){var l=c[u];(a=s?s(l,u,c):t)===t&&(a=Jo(l)?l:vr(e[r+1])?[]:{})}Je(c,u,a),c=c[u]}return n}var Gi=Te?function(t,n){return Te.set(t,n),t}:nc,qi=hn?function(t,n){return hn(t,"toString",{configurable:!0,enumerable:!1,value:Jh(n),writable:!0})}:nc;function Ji(t){return Er(Fh(t))}function Zi(t,n,e){var i=-1,s=t.length;n<0&&(n=-n>s?0:s+n),(e=e>s?s:e)<0&&(e+=s),s=n>e?0:e-n>>>0,n>>>=0;for(var r=bt(s);++i<s;)r[i]=t[i+n];return r}function ts(t,n){var e;return ui(t,(function(t,i,s){return!(e=n(t,i,s))})),!!e}function ns(t,n,e){var i=0,s=null==t?i:t.length;if("number"==typeof n&&n==n&&s<=2147483647){for(;i<s;){var r=i+s>>>1,o=t[r];null!==o&&!oh(o)&&(e?o<=n:o<n)?i=r+1:s=r}return s}return es(t,n,nc,e)}function es(n,e,i,s){var r=0,o=null==n?0:n.length;if(0===o)return 0;for(var h=(e=i(e))!=e,c=null===e,u=oh(e),a=e===t;r<o;){var l=vn((r+o)/2),f=i(n[l]),d=f!==t,v=null===f,p=f==f,w=oh(f);if(h)var y=s||p;else y=a?p&&(s||d):c?p&&d&&(s||!v):u?p&&d&&!v&&(s||!w):!v&&!w&&(s?f<=e:f<e);y?r=l+1:o=l}return we(o,4294967294)}function is(t,n){for(var e=-1,i=t.length,s=0,r=[];++e<i;){var o=t[e],h=n?n(o):o;if(!e||!Fo(h,c)){var c=h;r[s++]=0===o?0:o}}return r}function ss(t){return"number"==typeof t?t:oh(t)?c:+t}function rs(t){if("string"==typeof t)return t;if(Bo(t))return Un(t,rs)+"";if(oh(t))return Pe?Pe.call(t):"";var n=t+"";return"0"==n&&1/t==-1/0?"-0":n}function os(t,n,e){var i=-1,s=Tn,r=t.length,o=!0,h=[],c=h;if(e)o=!1,s=jn;else if(r>=200){var u=n?null:Hs(t);if(u)return re(u);o=!1,s=Vn,c=new He}else c=n?[]:h;t:for(;++i<r;){var a=t[i],l=n?n(a):a;if(a=e||0!==a?a:0,o&&l==l){for(var f=c.length;f--;)if(c[f]===l)continue t;n&&c.push(l),h.push(a)}else s(c,l,e)||(c!==h&&c.push(l),h.push(a))}return h}function hs(t,n){return null==(t=Mr(t,n=ps(n,t)))||delete t[Or(Nr(n))]}function cs(t,n,e,i){return Vi(t,n,e(mi(t,n)),i)}function us(t,n,e,i){for(var s=t.length,r=i?s:-1;(i?r--:++r<s)&&n(t[r],r,t););return e?Zi(t,i?0:r,i?r+1:s):Zi(t,i?r+1:0,i?s:r)}function as(t,n){var e=t;return e instanceof We&&(e=e.value()),$n(n,(function(t,n){return n.func.apply(n.thisArg,En([t],n.args))}),e)}function ls(t,n,e){var i=t.length;if(i<2)return i?os(t[0]):[];for(var s=-1,r=bt(i);++s<i;)for(var o=t[s],h=-1;++h<i;)h!=s&&(r[s]=ci(r[s]||o,t[h],n,e));return os(vi(r,1),n,e)}function fs(n,e,i){for(var s=-1,r=n.length,o=e.length,h={};++s<r;)i(h,n[s],s<o?e[s]:t);return h}function ds(t){return Ho(t)?t:[]}function vs(t){return"function"==typeof t?t:nc}function ps(t,n){return Bo(t)?t:wr(t,n)?[t]:Ir(wh(t))}var ws=Ki;function ys(n,e,i){var s=n.length;return i=i===t?s:i,!e&&i>=s?n:Zi(n,e,i)}var gs=cn||function(t){return un.clearTimeout(t)};function bs(t,n){if(n)return t.slice();var e=t.length,i=Bt?Bt(e):new t.constructor(e);return t.copy(i),i}function ms(t){var n=new t.constructor(t.byteLength);return new Wt(n).set(new Wt(t)),n}function As(t,n){var e=n?ms(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.length)}function ks(n,e){if(n!==e){var i=n!==t,s=null===n,r=n==n,o=oh(n),h=e!==t,c=null===e,u=e==e,a=oh(e);if(!c&&!a&&!o&&n>e||o&&h&&u&&!c&&!a||s&&h&&u||!i&&u||!r)return 1;if(!s&&!o&&!a&&n<e||a&&i&&r&&!s&&!o||c&&i&&r||!h&&r||!u)return-1}return 0}function Ms(t,n,e,i){for(var s=-1,r=t.length,o=e.length,h=-1,c=n.length,u=pe(r-o,0),a=bt(c+u),l=!i;++h<c;)a[h]=n[h];for(;++s<o;)(l||s<r)&&(a[e[s]]=t[s]);for(;u--;)a[h++]=t[s++];return a}function xs(t,n,e,i){for(var s=-1,r=t.length,o=-1,h=e.length,c=-1,u=n.length,a=pe(r-h,0),l=bt(a+u),f=!i;++s<a;)l[s]=t[s];for(var d=s;++c<u;)l[d+c]=n[c];for(;++o<h;)(f||s<r)&&(l[d+e[o]]=t[s++]);return l}function Ss(t,n){var e=-1,i=t.length;for(n||(n=bt(i));++e<i;)n[e]=t[e];return n}function Cs(n,e,i,s){var r=!i;i||(i={});for(var o=-1,h=e.length;++o<h;){var c=e[o],u=s?s(i[c],n[c],c,i,n):t;u===t&&(u=n[c]),r?ei(i,c,u):Je(i,c,u)}return i}function Ts(t,n){return function(e,i){var s=Bo(e)?kn:ti,r=n?n():{};return s(e,t,sr(i,2),r)}}function js(n){return Ki((function(e,i){var s=-1,r=i.length,o=r>1?i[r-1]:t,h=r>2?i[2]:t;for(o=n.length>3&&"function"==typeof o?(r--,o):t,h&&pr(i[0],i[1],h)&&(o=r<3?t:o,r=1),e=xt(e);++s<r;){var c=i[s];c&&n(e,c,s,o)}return e}))}function Us(t,n){return function(e,i){if(null==e)return e;if(!Xo(e))return t(e,i);for(var s=e.length,r=n?s:-1,o=xt(e);(n?r--:++r<s)&&!1!==i(o[r],r,o););return e}}function Es(t){return function(n,e,i){for(var s=-1,r=xt(n),o=i(n),h=o.length;h--;){var c=o[t?h:++s];if(!1===e(r[c],c,r))break}return n}}function $s(n){return function(e){var i=ne(e=wh(e))?ce(e):t,s=i?i[0]:e.charAt(0),r=i?ys(i,1).join(""):e.slice(1);return s[n]()+r}}function _s(t){return function(n){return $n(Vh(Wh(n).replace(Nt,"")),t,"")}}function Is(t){return function(){var n=arguments;switch(n.length){case 0:return new t;case 1:return new t(n[0]);case 2:return new t(n[0],n[1]);case 3:return new t(n[0],n[1],n[2]);case 4:return new t(n[0],n[1],n[2],n[3]);case 5:return new t(n[0],n[1],n[2],n[3],n[4]);case 6:return new t(n[0],n[1],n[2],n[3],n[4],n[5]);case 7:return new t(n[0],n[1],n[2],n[3],n[4],n[5],n[6])}var e=Fe(t.prototype),i=t.apply(e,n);return Jo(i)?i:e}}function Os(n){return function(e,i,s){var r=xt(e);if(!Xo(e)){var o=sr(i,3);e=Uh(e),i=function(t){return o(r[t],t,r)}}var h=n(e,i,s);return h>-1?r[o?e[h]:h]:t}}function zs(e){return Js((function(i){var s=i.length,r=s,o=Le.prototype.thru;for(e&&i.reverse();r--;){var h=i[r];if("function"!=typeof h)throw new Tt(n);if(o&&!c&&"wrapper"==er(h))var c=new Le([],!0)}for(r=c?r:s;++r<s;){var u=er(h=i[r]),a="wrapper"==u?nr(h):t;c=a&&yr(a[0])&&424==a[1]&&!a[4].length&&1==a[9]?c[er(a[0])].apply(c,a[3]):1==h.length&&yr(h)?c[u]():c.thru(h)}return function(){var t=arguments,n=t[0];if(c&&1==t.length&&Bo(n))return c.plant(n).value();for(var e=0,r=s?i[e].apply(this,t):n;++e<s;)r=i[e].call(this,r);return r}}))}function Ps(n,e,i,s,o,h,c,u,a,l){var f=e&r,d=1&e,v=2&e,p=24&e,w=512&e,y=v?t:Is(n);return function r(){for(var g=arguments.length,b=bt(g),m=g;m--;)b[m]=arguments[m];if(p)var A=ir(r),k=function(t,n){for(var e=t.length,i=0;e--;)t[e]===n&&++i;return i}(b,A);if(s&&(b=Ms(b,s,o,p)),h&&(b=xs(b,h,c,p)),g-=k,p&&g<l){var M=se(b,A);return Ys(n,e,Ps,r.placeholder,i,b,M,u,a,l-g)}var x=d?i:this,S=v?x[n]:n;return g=b.length,u?b=function(n,e){for(var i=n.length,s=we(e.length,i),r=Ss(n);s--;){var o=e[s];n[s]=vr(o,i)?r[o]:t}return n}(b,u):w&&g>1&&b.reverse(),f&&a<g&&(b.length=a),this&&this!==un&&this instanceof r&&(S=y||Is(S)),S.apply(x,b)}}function Ds(t,n){return function(e,i){return function(t,n,e,i){return yi(t,(function(t,s,r){n(i,e(t),s,r)})),i}(e,t,n(i),{})}}function Fs(n,e){return function(i,s){var r;if(i===t&&s===t)return e;if(i!==t&&(r=i),s!==t){if(r===t)return s;"string"==typeof i||"string"==typeof s?(i=rs(i),s=rs(s)):(i=ss(i),s=ss(s)),r=n(i,s)}return r}}function Rs(t){return Js((function(n){return n=Un(n,Nn(sr())),Ki((function(e){var i=this;return t(n,(function(t){return An(t,i,e)}))}))}))}function Ls(n,e){var i=(e=e===t?" ":rs(e)).length;if(i<2)return i?Hi(e,n):e;var s=Hi(e,dn(n/he(e)));return ne(e)?ys(ce(s),0,n).join(""):s.slice(0,n)}function Ws(n){return function(e,i,s){return s&&"number"!=typeof s&&pr(e,i,s)&&(i=s=t),e=lh(e),i===t?(i=e,e=0):i=lh(i),function(t,n,e,i){for(var s=-1,r=pe(dn((n-t)/(e||1)),0),o=bt(r);r--;)o[i?r:++s]=t,t+=e;return o}(e,i,s=s===t?e<i?1:-1:lh(s),n)}}function Bs(t){return function(n,e){return"string"==typeof n&&"string"==typeof e||(n=vh(n),e=vh(e)),t(n,e)}}function Ys(n,e,i,r,o,h,c,u,a,l){var f=8&e;e|=f?s:64,4&(e&=~(f?64:s))||(e&=-4);var d=[n,e,o,f?h:t,f?c:t,f?t:h,f?t:c,u,a,l],v=i.apply(t,d);return yr(n)&&Sr(v,d),v.placeholder=r,jr(v,n,e)}function Xs(t){var n=Mt[t];return function(t,e){if(t=vh(t),(e=null==e?0:we(fh(e),292))&&fe(t)){var i=(wh(t)+"e").split("e");return+((i=(wh(n(i[0]+"e"+(+i[1]+e)))+"e").split("e"))[0]+"e"+(+i[1]-e))}return n(t)}}var Hs=xe&&1/re(new xe([,-0]))[1]==o?function(t){return new xe(t)}:oc;function Ks(t){return function(n){var e=ar(n);return e==g?ee(n):e==M?oe(n):function(t,n){return Un(n,(function(n){return[n,t[n]]}))}(n,t(n))}}function Ns(e,o,h,c,u,a,l,f){var d=2&o;if(!d&&"function"!=typeof e)throw new Tt(n);var v=c?c.length:0;if(v||(o&=-97,c=u=t),l=l===t?l:pe(fh(l),0),f=f===t?f:fh(f),v-=u?u.length:0,64&o){var p=c,w=u;c=u=t}var y=d?t:nr(e),g=[e,o,h,c,u,p,w,a,l,f];if(y&&function(t,n){var e=t[1],s=n[1],o=e|s;if(!(o<131||(s==r&&8==e||s==r&&256==e&&t[7].length<=n[8]||384==s&&n[7].length<=n[8]&&8==e)))return t;1&s&&(t[2]=n[2],o|=1&e?0:4);var h=n[3];if(h){var c=t[3];t[3]=c?Ms(c,h,n[4]):h,t[4]=c?se(t[3],i):n[4]}(h=n[5])&&(t[5]=(c=t[5])?xs(c,h,n[6]):h,t[6]=c?se(t[5],i):n[6]),(h=n[7])&&(t[7]=h),s&r&&(t[8]=null==t[8]?n[8]:we(t[8],n[8])),null==t[9]&&(t[9]=n[9]),t[0]=n[0],t[1]=o}(g,y),e=g[0],o=g[1],h=g[2],c=g[3],u=g[4],!(f=g[9]=g[9]===t?d?0:e.length:pe(g[9]-v,0))&&24&o&&(o&=-25),o&&1!=o)b=8==o||16==o?function(n,e,i){var s=Is(n);return function r(){for(var o=arguments.length,h=bt(o),c=o,u=ir(r);c--;)h[c]=arguments[c];var a=o<3&&h[0]!==u&&h[o-1]!==u?[]:se(h,u);return(o-=a.length)<i?Ys(n,e,Ps,r.placeholder,t,h,a,t,t,i-o):An(this&&this!==un&&this instanceof r?s:n,this,h)}}(e,o,f):o!=s&&33!=o||u.length?Ps.apply(t,g):function(t,n,e,i){var s=1&n,r=Is(t);return function n(){for(var o=-1,h=arguments.length,c=-1,u=i.length,a=bt(u+h),l=this&&this!==un&&this instanceof n?r:t;++c<u;)a[c]=i[c];for(;h--;)a[c++]=arguments[++o];return An(l,s?e:this,a)}}(e,o,h,c);else var b=function(t,n,e){var i=1&n,s=Is(t);return function n(){return(this&&this!==un&&this instanceof n?s:t).apply(i?e:this,arguments)}}(e,o,h);return jr((y?Gi:Sr)(b,g),e,o)}function Qs(n,e,i,s){return n===t||Fo(n,Ut[i])&&!_t.call(s,i)?e:n}function Vs(n,e,i,s,r,o){return Jo(n)&&Jo(e)&&(o.set(e,n),Fi(n,e,t,Vs,o),o.delete(e)),n}function Gs(n){return eh(n)?t:n}function qs(n,e,i,s,r,o){var h=1&i,c=n.length,u=e.length;if(c!=u&&!(h&&u>c))return!1;var a=o.get(n),l=o.get(e);if(a&&l)return a==e&&l==n;var f=-1,d=!0,v=2&i?new He:t;for(o.set(n,e),o.set(e,n);++f<c;){var p=n[f],w=e[f];if(s)var y=h?s(w,p,f,e,n,o):s(p,w,f,n,e,o);if(y!==t){if(y)continue;d=!1;break}if(v){if(!In(e,(function(t,n){if(!Vn(v,n)&&(p===t||r(p,t,i,s,o)))return v.push(n)}))){d=!1;break}}else if(p!==w&&!r(p,w,i,s,o)){d=!1;break}}return o.delete(n),o.delete(e),d}function Js(n){return Tr(kr(n,t,Br),n+"")}function Zs(t){return Ai(t,Uh,cr)}function tr(t){return Ai(t,Eh,ur)}var nr=Te?function(t){return Te.get(t)}:oc;function er(t){for(var n=t.name+"",e=je[n],i=_t.call(je,n)?e.length:0;i--;){var s=e[i],r=s.func;if(null==r||r==t)return s.name}return n}function ir(t){return(_t.call(De,"placeholder")?De:t).placeholder}function sr(){var t=De.iteratee||ec;return t=t===ec?_i:t,arguments.length?t(arguments[0],arguments[1]):t}function rr(t,n){var e=t.__data__;return function(t){var n=typeof t;return"string"==n||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==t:null===t}(n)?e["string"==typeof n?"string":"hash"]:e.map}function or(t){for(var n=Uh(t),e=n.length;e--;){var i=n[e],s=t[i];n[e]=[i,s,mr(s)]}return n}function hr(n,e){var i=function(n,e){return null==n?t:n[e]}(n,e);return $i(i)?i:t}var cr=On?function(t){return null==t?[]:(t=xt(t),Cn(On(t),(function(n){return Ht.call(t,n)})))}:dc,ur=On?function(t){for(var n=[];t;)En(n,cr(t)),t=Yt(t);return n}:dc,ar=ki;function lr(t,n,e){for(var i=-1,s=(n=ps(n,t)).length,r=!1;++i<s;){var o=Or(n[i]);if(!(r=null!=t&&e(t,o)))break;t=t[o]}return r||++i!=s?r:!!(s=null==t?0:t.length)&&qo(s)&&vr(o,s)&&(Bo(t)||Wo(t))}function fr(t){return"function"!=typeof t.constructor||br(t)?{}:Fe(Yt(t))}function dr(t){return Bo(t)||Wo(t)||!!(Vt&&t&&t[Vt])}function vr(t,n){var e=typeof t;return!!(n=null==n?h:n)&&("number"==e||"symbol"!=e&&vt.test(t))&&t>-1&&t%1==0&&t<n}function pr(t,n,e){if(!Jo(e))return!1;var i=typeof n;return!!("number"==i?Xo(e)&&vr(n,e.length):"string"==i&&n in e)&&Fo(e[n],t)}function wr(t,n){if(Bo(t))return!1;var e=typeof t;return!("number"!=e&&"symbol"!=e&&"boolean"!=e&&null!=t&&!oh(t))||G.test(t)||!V.test(t)||null!=n&&t in xt(n)}function yr(t){var n=er(t),e=De[n];if("function"!=typeof e||!(n in We.prototype))return!1;if(t===e)return!0;var i=nr(e);return!!i&&t===i[0]}(Ae&&ar(new Ae(new ArrayBuffer(1)))!=j||ke&&ar(new ke)!=g||Me&&ar(Me.resolve())!=A||xe&&ar(new xe)!=M||Se&&ar(new Se)!=C)&&(ar=function(n){var e=ki(n),i=e==m?n.constructor:t,s=i?zr(i):"";if(s)switch(s){case Ue:return j;case Ee:return g;case $e:return A;case _e:return M;case Ie:return C}return e});var gr=Et?Vo:vc;function br(t){var n=t&&t.constructor;return t===("function"==typeof n&&n.prototype||Ut)}function mr(t){return t==t&&!Jo(t)}function Ar(n,e){return function(i){return null!=i&&i[n]===e&&(e!==t||n in xt(i))}}function kr(n,e,i){return e=pe(e===t?n.length-1:e,0),function(){for(var t=arguments,s=-1,r=pe(t.length-e,0),o=bt(r);++s<r;)o[s]=t[e+s];s=-1;for(var h=bt(e+1);++s<e;)h[s]=t[s];return h[e]=i(o),An(n,this,h)}}function Mr(t,n){return n.length<2?t:mi(t,Zi(n,0,-1))}function xr(t,n){if(("constructor"!==n||"function"!=typeof t[n])&&"__proto__"!=n)return t[n]}var Sr=Ur(Gi),Cr=ln||function(t,n){return un.setTimeout(t,n)},Tr=Ur(qi);function jr(t,n,e){var i=n+"";return Tr(t,function(t,n){var e=n.length;if(!e)return t;var i=e-1;return n[i]=(e>1?"& ":"")+n[i],n=n.join(e>2?", ":" "),t.replace(et,"{\n/* [wrapped with "+n+"] */\n")}(i,function(t,n){return Mn(a,(function(e){var i="_."+e[0];n&e[1]&&!Tn(t,i)&&t.push(i)})),t.sort()}(function(t){var n=t.match(it);return n?n[1].split(st):[]}(i),e)))}function Ur(n){var e=0,i=0;return function(){var s=ye(),r=16-(s-i);if(i=s,r>0){if(++e>=800)return arguments[0]}else e=0;return n.apply(t,arguments)}}function Er(n,e){var i=-1,s=n.length,r=s-1;for(e=e===t?s:e;++i<e;){var o=Xi(i,r),h=n[o];n[o]=n[i],n[i]=h}return n.length=e,n}var $r,_r,Ir=($r=_o((function(t){var n=[];return 46===t.charCodeAt(0)&&n.push(""),t.replace(q,(function(t,e,i,s){n.push(i?s.replace(ht,"$1"):e||t)})),n}),(function(t){return 500===_r.size&&_r.clear(),t})),_r=$r.cache,$r);function Or(t){if("string"==typeof t||oh(t))return t;var n=t+"";return"0"==n&&1/t==-1/0?"-0":n}function zr(t){if(null!=t){try{return $t.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function Pr(t){if(t instanceof We)return t.clone();var n=new Le(t.__wrapped__,t.__chain__);return n.__actions__=Ss(t.__actions__),n.__index__=t.__index__,n.__values__=t.__values__,n}var Dr=Ki((function(t,n){return Ho(t)?ci(t,vi(n,1,Ho,!0)):[]})),Fr=Ki((function(n,e){var i=Nr(e);return Ho(i)&&(i=t),Ho(n)?ci(n,vi(e,1,Ho,!0),sr(i,2)):[]})),Rr=Ki((function(n,e){var i=Nr(e);return Ho(i)&&(i=t),Ho(n)?ci(n,vi(e,1,Ho,!0),t,i):[]}));function Lr(t,n,e){var i=null==t?0:t.length;if(!i)return-1;var s=null==e?0:fh(e);return s<0&&(s=pe(i+s,0)),Pn(t,sr(n,3),s)}function Wr(n,e,i){var s=null==n?0:n.length;if(!s)return-1;var r=s-1;return i!==t&&(r=fh(i),r=i<0?pe(s+r,0):we(r,s-1)),Pn(n,sr(e,3),r,!0)}function Br(t){return null!=t&&t.length?vi(t,1):[]}function Yr(n){return n&&n.length?n[0]:t}var Xr=Ki((function(t){var n=Un(t,ds);return n.length&&n[0]===t[0]?Ci(n):[]})),Hr=Ki((function(n){var e=Nr(n),i=Un(n,ds);return e===Nr(i)?e=t:i.pop(),i.length&&i[0]===n[0]?Ci(i,sr(e,2)):[]})),Kr=Ki((function(n){var e=Nr(n),i=Un(n,ds);return(e="function"==typeof e?e:t)&&i.pop(),i.length&&i[0]===n[0]?Ci(i,t,e):[]}));function Nr(n){var e=null==n?0:n.length;return e?n[e-1]:t}var Qr=Ki(Vr);function Vr(t,n){return t&&t.length&&n&&n.length?Bi(t,n):t}var Gr=Js((function(t,n){var e=null==t?0:t.length,i=ii(t,n);return Yi(t,Un(n,(function(t){return vr(t,e)?+t:t})).sort(ks)),i}));function qr(t){return null==t?t:me.call(t)}var Jr=Ki((function(t){return os(vi(t,1,Ho,!0))})),Zr=Ki((function(n){var e=Nr(n);return Ho(e)&&(e=t),os(vi(n,1,Ho,!0),sr(e,2))})),to=Ki((function(n){var e=Nr(n);return e="function"==typeof e?e:t,os(vi(n,1,Ho,!0),t,e)}));function no(t){if(!t||!t.length)return[];var n=0;return t=Cn(t,(function(t){if(Ho(t))return n=pe(t.length,n),!0})),Hn(n,(function(n){return Un(t,Wn(n))}))}function eo(n,e){if(!n||!n.length)return[];var i=no(n);return null==e?i:Un(i,(function(n){return An(e,t,n)}))}var io=Ki((function(t,n){return Ho(t)?ci(t,n):[]})),so=Ki((function(t){return ls(Cn(t,Ho))})),ro=Ki((function(n){var e=Nr(n);return Ho(e)&&(e=t),ls(Cn(n,Ho),sr(e,2))})),oo=Ki((function(n){var e=Nr(n);return e="function"==typeof e?e:t,ls(Cn(n,Ho),t,e)})),ho=Ki(no),co=Ki((function(n){var e=n.length,i=e>1?n[e-1]:t;return i="function"==typeof i?(n.pop(),i):t,eo(n,i)}));function uo(t){var n=De(t);return n.__chain__=!0,n}function ao(t,n){return n(t)}var lo=Js((function(n){var e=n.length,i=e?n[0]:0,s=this.__wrapped__,r=function(t){return ii(t,n)};return!(e>1||this.__actions__.length)&&s instanceof We&&vr(i)?((s=s.slice(i,+i+(e?1:0))).__actions__.push({func:ao,args:[r],thisArg:t}),new Le(s,this.__chain__).thru((function(n){return e&&!n.length&&n.push(t),n}))):this.thru(r)})),fo=Ts((function(t,n,e){_t.call(t,e)?++t[e]:ei(t,e,1)})),vo=Os(Lr),po=Os(Wr);function wo(t,n){return(Bo(t)?Mn:ui)(t,sr(n,3))}function yo(t,n){return(Bo(t)?xn:ai)(t,sr(n,3))}var go=Ts((function(t,n,e){_t.call(t,e)?t[e].push(n):ei(t,e,[n])})),bo=Ki((function(t,n,e){var i=-1,s="function"==typeof n,r=Xo(t)?bt(t.length):[];return ui(t,(function(t){r[++i]=s?An(n,t,e):Ti(t,n,e)})),r})),mo=Ts((function(t,n,e){ei(t,e,n)}));function Ao(t,n){return(Bo(t)?Un:zi)(t,sr(n,3))}var ko=Ts((function(t,n,e){t[e?0:1].push(n)}),(function(){return[[],[]]})),Mo=Ki((function(t,n){if(null==t)return[];var e=n.length;return e>1&&pr(t,n[0],n[1])?n=[]:e>2&&pr(n[0],n[1],n[2])&&(n=[n[0]]),Li(t,vi(n,1),[])})),xo=an||function(){return un.Date.now()};function So(n,e,i){return e=i?t:e,Ns(n,r,t,t,t,t,e=n&&null==e?n.length:e)}function Co(e,i){var s;if("function"!=typeof i)throw new Tt(n);return e=fh(e),function(){return--e>0&&(s=i.apply(this,arguments)),e<=1&&(i=t),s}}var To=Ki((function(t,n,e){var i=1;if(e.length){var r=se(e,ir(To));i|=s}return Ns(t,i,n,e,r)})),jo=Ki((function(t,n,e){var i=3;if(e.length){var r=se(e,ir(jo));i|=s}return Ns(n,i,t,e,r)}));function Uo(e,i,s){var r,o,h,c,u,a,l=0,f=!1,d=!1,v=!0;if("function"!=typeof e)throw new Tt(n);function p(n){var i=r,s=o;return r=o=t,l=n,c=e.apply(s,i)}function w(n){var e=n-a;return a===t||e>=i||e<0||d&&n-l>=h}function y(){var t=xo();if(w(t))return g(t);u=Cr(y,function(t){var n=i-(t-a);return d?we(n,h-(t-l)):n}(t))}function g(n){return u=t,v&&r?p(n):(r=o=t,c)}function b(){var n=xo(),e=w(n);if(r=arguments,o=this,a=n,e){if(u===t)return function(t){return l=t,u=Cr(y,i),f?p(t):c}(a);if(d)return gs(u),u=Cr(y,i),p(a)}return u===t&&(u=Cr(y,i)),c}return i=vh(i)||0,Jo(s)&&(f=!!s.leading,h=(d="maxWait"in s)?pe(vh(s.maxWait)||0,i):h,v="trailing"in s?!!s.trailing:v),b.cancel=function(){u!==t&&gs(u),l=0,r=a=o=u=t},b.flush=function(){return u===t?c:g(xo())},b}var Eo=Ki((function(t,n){return hi(t,1,n)})),$o=Ki((function(t,n,e){return hi(t,vh(n)||0,e)}));function _o(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new Tt(n);var i=function(){var n=arguments,s=e?e.apply(this,n):n[0],r=i.cache;if(r.has(s))return r.get(s);var o=t.apply(this,n);return i.cache=r.set(s,o)||r,o};return i.cache=new(_o.Cache||Xe),i}function Io(t){if("function"!=typeof t)throw new Tt(n);return function(){var n=arguments;switch(n.length){case 0:return!t.call(this);case 1:return!t.call(this,n[0]);case 2:return!t.call(this,n[0],n[1]);case 3:return!t.call(this,n[0],n[1],n[2])}return!t.apply(this,n)}}_o.Cache=Xe;var Oo=ws((function(t,n){var e=(n=1==n.length&&Bo(n[0])?Un(n[0],Nn(sr())):Un(vi(n,1),Nn(sr()))).length;return Ki((function(i){for(var s=-1,r=we(i.length,e);++s<r;)i[s]=n[s].call(this,i[s]);return An(t,this,i)}))})),zo=Ki((function(n,e){var i=se(e,ir(zo));return Ns(n,s,t,e,i)})),Po=Ki((function(n,e){var i=se(e,ir(Po));return Ns(n,64,t,e,i)})),Do=Js((function(n,e){return Ns(n,256,t,t,t,e)}));function Fo(t,n){return t===n||t!=t&&n!=n}var Ro=Bs(Mi),Lo=Bs((function(t,n){return t>=n})),Wo=ji(function(){return arguments}())?ji:function(t){return Zo(t)&&_t.call(t,"callee")&&!Ht.call(t,"callee")},Bo=bt.isArray,Yo=pn?Nn(pn):function(t){return Zo(t)&&ki(t)==T};function Xo(t){return null!=t&&qo(t.length)&&!Vo(t)}function Ho(t){return Zo(t)&&Xo(t)}var Ko=Bn||vc,No=wn?Nn(wn):function(t){return Zo(t)&&ki(t)==v};function Qo(t){if(!Zo(t))return!1;var n=ki(t);return n==p||"[object DOMException]"==n||"string"==typeof t.message&&"string"==typeof t.name&&!eh(t)}function Vo(t){if(!Jo(t))return!1;var n=ki(t);return n==w||n==y||"[object AsyncFunction]"==n||"[object Proxy]"==n}function Go(t){return"number"==typeof t&&t==fh(t)}function qo(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=h}function Jo(t){var n=typeof t;return null!=t&&("object"==n||"function"==n)}function Zo(t){return null!=t&&"object"==typeof t}var th=yn?Nn(yn):function(t){return Zo(t)&&ar(t)==g};function nh(t){return"number"==typeof t||Zo(t)&&ki(t)==b}function eh(t){if(!Zo(t)||ki(t)!=m)return!1;var n=Yt(t);if(null===n)return!0;var e=_t.call(n,"constructor")&&n.constructor;return"function"==typeof e&&e instanceof e&&$t.call(e)==Pt}var ih=gn?Nn(gn):function(t){return Zo(t)&&ki(t)==k},sh=bn?Nn(bn):function(t){return Zo(t)&&ar(t)==M};function rh(t){return"string"==typeof t||!Bo(t)&&Zo(t)&&ki(t)==x}function oh(t){return"symbol"==typeof t||Zo(t)&&ki(t)==S}var hh=mn?Nn(mn):function(t){return Zo(t)&&qo(t.length)&&!!nn[ki(t)]},ch=Bs(Oi),uh=Bs((function(t,n){return t<=n}));function ah(t){if(!t)return[];if(Xo(t))return rh(t)?ce(t):Ss(t);if(qt&&t[qt])return function(t){for(var n,e=[];!(n=t.next()).done;)e.push(n.value);return e}(t[qt]());var n=ar(t);return(n==g?ee:n==M?re:Fh)(t)}function lh(t){return t?(t=vh(t))===o||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function fh(t){var n=lh(t),e=n%1;return n==n?e?n-e:n:0}function dh(t){return t?si(fh(t),0,u):0}function vh(t){if("number"==typeof t)return t;if(oh(t))return c;if(Jo(t)){var n="function"==typeof t.valueOf?t.valueOf():t;t=Jo(n)?n+"":n}if("string"!=typeof t)return 0===t?t:+t;t=Kn(t);var e=lt.test(t);return e||dt.test(t)?on(t.slice(2),e?2:8):at.test(t)?c:+t}function ph(t){return Cs(t,Eh(t))}function wh(t){return null==t?"":rs(t)}var yh=js((function(t,n){if(br(n)||Xo(n))Cs(n,Uh(n),t);else for(var e in n)_t.call(n,e)&&Je(t,e,n[e])})),gh=js((function(t,n){Cs(n,Eh(n),t)})),bh=js((function(t,n,e,i){Cs(n,Eh(n),t,i)})),mh=js((function(t,n,e,i){Cs(n,Uh(n),t,i)})),Ah=Js(ii),kh=Ki((function(n,e){n=xt(n);var i=-1,s=e.length,r=s>2?e[2]:t;for(r&&pr(e[0],e[1],r)&&(s=1);++i<s;)for(var o=e[i],h=Eh(o),c=-1,u=h.length;++c<u;){var a=h[c],l=n[a];(l===t||Fo(l,Ut[a])&&!_t.call(n,a))&&(n[a]=o[a])}return n})),Mh=Ki((function(n){return n.push(t,Vs),An(_h,t,n)}));function xh(n,e,i){var s=null==n?t:mi(n,e);return s===t?i:s}function Sh(t,n){return null!=t&&lr(t,n,Si)}var Ch=Ds((function(t,n,e){null!=n&&"function"!=typeof n.toString&&(n=zt.call(n)),t[n]=e}),Jh(nc)),Th=Ds((function(t,n,e){null!=n&&"function"!=typeof n.toString&&(n=zt.call(n)),_t.call(t,n)?t[n].push(e):t[n]=[e]}),sr),jh=Ki(Ti);function Uh(t){return Xo(t)?Ne(t):Ii(t)}function Eh(t){return Xo(t)?Ne(t,!0):function(t){if(!Jo(t))return function(t){var n=[];if(null!=t)for(var e in xt(t))n.push(e);return n}(t);var n=br(t),e=[];for(var i in t)("constructor"!=i||!n&&_t.call(t,i))&&e.push(i);return e}(t)}var $h=js((function(t,n,e){Fi(t,n,e)})),_h=js((function(t,n,e,i){Fi(t,n,e,i)})),Ih=Js((function(t,n){var e={};if(null==t)return e;var i=!1;n=Un(n,(function(n){return n=ps(n,t),i||(i=n.length>1),n})),Cs(t,tr(t),e),i&&(e=ri(e,7,Gs));for(var s=n.length;s--;)hs(e,n[s]);return e})),Oh=Js((function(t,n){return null==t?{}:function(t,n){return Wi(t,n,(function(n,e){return Sh(t,e)}))}(t,n)}));function zh(t,n){if(null==t)return{};var e=Un(tr(t),(function(t){return[t]}));return n=sr(n),Wi(t,e,(function(t,e){return n(t,e[0])}))}var Ph=Ks(Uh),Dh=Ks(Eh);function Fh(t){return null==t?[]:Qn(t,Uh(t))}var Rh=_s((function(t,n,e){return n=n.toLowerCase(),t+(e?Lh(n):n)}));function Lh(t){return Qh(wh(t).toLowerCase())}function Wh(t){return(t=wh(t))&&t.replace(pt,Jn).replace(Qt,"")}var Bh=_s((function(t,n,e){return t+(e?"-":"")+n.toLowerCase()})),Yh=_s((function(t,n,e){return t+(e?" ":"")+n.toLowerCase()})),Xh=$s("toLowerCase"),Hh=_s((function(t,n,e){return t+(e?"_":"")+n.toLowerCase()})),Kh=_s((function(t,n,e){return t+(e?" ":"")+Qh(n)})),Nh=_s((function(t,n,e){return t+(e?" ":"")+n.toUpperCase()})),Qh=$s("toUpperCase");function Vh(n,e,i){return n=wh(n),(e=i?t:e)===t?function(t){return Jt.test(t)}(n)?function(t){return t.match(Gt)||[]}(n):function(t){return t.match(rt)||[]}(n):n.match(e)||[]}var Gh=Ki((function(n,e){try{return An(n,t,e)}catch(t){return Qo(t)?t:new At(t)}})),qh=Js((function(t,n){return Mn(n,(function(n){n=Or(n),ei(t,n,To(t[n],t))})),t}));function Jh(t){return function(){return t}}var Zh=zs(),tc=zs(!0);function nc(t){return t}function ec(t){return _i("function"==typeof t?t:ri(t,1))}var ic=Ki((function(t,n){return function(e){return Ti(e,t,n)}})),sc=Ki((function(t,n){return function(e){return Ti(t,e,n)}}));function rc(t,n,e){var i=Uh(n),s=bi(n,i);null!=e||Jo(n)&&(s.length||!i.length)||(e=n,n=t,t=this,s=bi(n,Uh(n)));var r=!(Jo(e)&&"chain"in e&&!e.chain),o=Vo(t);return Mn(s,(function(e){var i=n[e];t[e]=i,o&&(t.prototype[e]=function(){var n=this.__chain__;if(r||n){var e=t(this.__wrapped__);return(e.__actions__=Ss(this.__actions__)).push({func:i,args:arguments,thisArg:t}),e.__chain__=n,e}return i.apply(t,En([this.value()],arguments))})})),t}function oc(){}var hc=Rs(Un),cc=Rs(Sn),uc=Rs(In);function ac(t){return wr(t)?Wn(Or(t)):function(t){return function(n){return mi(n,t)}}(t)}var lc=Ws(),fc=Ws(!0);function dc(){return[]}function vc(){return!1}var pc,wc=Fs((function(t,n){return t+n}),0),yc=Xs("ceil"),gc=Fs((function(t,n){return t/n}),1),bc=Xs("floor"),mc=Fs((function(t,n){return t*n}),1),Ac=Xs("round"),kc=Fs((function(t,n){return t-n}),0);return De.after=function(t,e){if("function"!=typeof e)throw new Tt(n);return t=fh(t),function(){if(--t<1)return e.apply(this,arguments)}},De.ary=So,De.assign=yh,De.assignIn=gh,De.assignInWith=bh,De.assignWith=mh,De.at=Ah,De.before=Co,De.bind=To,De.bindAll=qh,De.bindKey=jo,De.castArray=function(){if(!arguments.length)return[];var t=arguments[0];return Bo(t)?t:[t]},De.chain=uo,De.chunk=function(n,e,i){e=(i?pr(n,e,i):e===t)?1:pe(fh(e),0);var s=null==n?0:n.length;if(!s||e<1)return[];for(var r=0,o=0,h=bt(dn(s/e));r<s;)h[o++]=Zi(n,r,r+=e);return h},De.compact=function(t){for(var n=-1,e=null==t?0:t.length,i=0,s=[];++n<e;){var r=t[n];r&&(s[i++]=r)}return s},De.concat=function(){var t=arguments.length;if(!t)return[];for(var n=bt(t-1),e=arguments[0],i=t;i--;)n[i-1]=arguments[i];return En(Bo(e)?Ss(e):[e],vi(n,1))},De.cond=function(t){var e=null==t?0:t.length,i=sr();return t=e?Un(t,(function(t){if("function"!=typeof t[1])throw new Tt(n);return[i(t[0]),t[1]]})):[],Ki((function(n){for(var i=-1;++i<e;){var s=t[i];if(An(s[0],this,n))return An(s[1],this,n)}}))},De.conforms=function(t){return function(t){var n=Uh(t);return function(e){return oi(e,t,n)}}(ri(t,1))},De.constant=Jh,De.countBy=fo,De.create=function(t,n){var e=Fe(t);return null==n?e:ni(e,n)},De.curry=function n(e,i,s){var r=Ns(e,8,t,t,t,t,t,i=s?t:i);return r.placeholder=n.placeholder,r},De.curryRight=function n(e,i,s){var r=Ns(e,16,t,t,t,t,t,i=s?t:i);return r.placeholder=n.placeholder,r},De.debounce=Uo,De.defaults=kh,De.defaultsDeep=Mh,De.defer=Eo,De.delay=$o,De.difference=Dr,De.differenceBy=Fr,De.differenceWith=Rr,De.drop=function(n,e,i){var s=null==n?0:n.length;return s?Zi(n,(e=i||e===t?1:fh(e))<0?0:e,s):[]},De.dropRight=function(n,e,i){var s=null==n?0:n.length;return s?Zi(n,0,(e=s-(e=i||e===t?1:fh(e)))<0?0:e):[]},De.dropRightWhile=function(t,n){return t&&t.length?us(t,sr(n,3),!0,!0):[]},De.dropWhile=function(t,n){return t&&t.length?us(t,sr(n,3),!0):[]},De.fill=function(n,e,i,s){var r=null==n?0:n.length;return r?(i&&"number"!=typeof i&&pr(n,e,i)&&(i=0,s=r),function(n,e,i,s){var r=n.length;for((i=fh(i))<0&&(i=-i>r?0:r+i),(s=s===t||s>r?r:fh(s))<0&&(s+=r),s=i>s?0:dh(s);i<s;)n[i++]=e;return n}(n,e,i,s)):[]},De.filter=function(t,n){return(Bo(t)?Cn:di)(t,sr(n,3))},De.flatMap=function(t,n){return vi(Ao(t,n),1)},De.flatMapDeep=function(t,n){return vi(Ao(t,n),o)},De.flatMapDepth=function(n,e,i){return i=i===t?1:fh(i),vi(Ao(n,e),i)},De.flatten=Br,De.flattenDeep=function(t){return null!=t&&t.length?vi(t,o):[]},De.flattenDepth=function(n,e){return null!=n&&n.length?vi(n,e=e===t?1:fh(e)):[]},De.flip=function(t){return Ns(t,512)},De.flow=Zh,De.flowRight=tc,De.fromPairs=function(t){for(var n=-1,e=null==t?0:t.length,i={};++n<e;){var s=t[n];i[s[0]]=s[1]}return i},De.functions=function(t){return null==t?[]:bi(t,Uh(t))},De.functionsIn=function(t){return null==t?[]:bi(t,Eh(t))},De.groupBy=go,De.initial=function(t){return null!=t&&t.length?Zi(t,0,-1):[]},De.intersection=Xr,De.intersectionBy=Hr,De.intersectionWith=Kr,De.invert=Ch,De.invertBy=Th,De.invokeMap=bo,De.iteratee=ec,De.keyBy=mo,De.keys=Uh,De.keysIn=Eh,De.map=Ao,De.mapKeys=function(t,n){var e={};return n=sr(n,3),yi(t,(function(t,i,s){ei(e,n(t,i,s),t)})),e},De.mapValues=function(t,n){var e={};return n=sr(n,3),yi(t,(function(t,i,s){ei(e,i,n(t,i,s))})),e},De.matches=function(t){return Pi(ri(t,1))},De.matchesProperty=function(t,n){return Di(t,ri(n,1))},De.memoize=_o,De.merge=$h,De.mergeWith=_h,De.method=ic,De.methodOf=sc,De.mixin=rc,De.negate=Io,De.nthArg=function(t){return t=fh(t),Ki((function(n){return Ri(n,t)}))},De.omit=Ih,De.omitBy=function(t,n){return zh(t,Io(sr(n)))},De.once=function(t){return Co(2,t)},De.orderBy=function(n,e,i,s){return null==n?[]:(Bo(e)||(e=null==e?[]:[e]),Bo(i=s?t:i)||(i=null==i?[]:[i]),Li(n,e,i))},De.over=hc,De.overArgs=Oo,De.overEvery=cc,De.overSome=uc,De.partial=zo,De.partialRight=Po,De.partition=ko,De.pick=Oh,De.pickBy=zh,De.property=ac,De.propertyOf=function(n){return function(e){return null==n?t:mi(n,e)}},De.pull=Qr,De.pullAll=Vr,De.pullAllBy=function(t,n,e){return t&&t.length&&n&&n.length?Bi(t,n,sr(e,2)):t},De.pullAllWith=function(n,e,i){return n&&n.length&&e&&e.length?Bi(n,e,t,i):n},De.pullAt=Gr,De.range=lc,De.rangeRight=fc,De.rearg=Do,De.reject=function(t,n){return(Bo(t)?Cn:di)(t,Io(sr(n,3)))},De.remove=function(t,n){var e=[];if(!t||!t.length)return e;var i=-1,s=[],r=t.length;for(n=sr(n,3);++i<r;){var o=t[i];n(o,i,t)&&(e.push(o),s.push(i))}return Yi(t,s),e},De.rest=function(e,i){if("function"!=typeof e)throw new Tt(n);return Ki(e,i=i===t?i:fh(i))},De.reverse=qr,De.sampleSize=function(n,e,i){return e=(i?pr(n,e,i):e===t)?1:fh(e),(Bo(n)?Ve:Qi)(n,e)},De.set=function(t,n,e){return null==t?t:Vi(t,n,e)},De.setWith=function(n,e,i,s){return s="function"==typeof s?s:t,null==n?n:Vi(n,e,i,s)},De.shuffle=function(t){return(Bo(t)?Ge:Ji)(t)},De.slice=function(n,e,i){var s=null==n?0:n.length;return s?(i&&"number"!=typeof i&&pr(n,e,i)?(e=0,i=s):(e=null==e?0:fh(e),i=i===t?s:fh(i)),Zi(n,e,i)):[]},De.sortBy=Mo,De.sortedUniq=function(t){return t&&t.length?is(t):[]},De.sortedUniqBy=function(t,n){return t&&t.length?is(t,sr(n,2)):[]},De.split=function(n,e,i){return i&&"number"!=typeof i&&pr(n,e,i)&&(e=i=t),(i=i===t?u:i>>>0)?(n=wh(n))&&("string"==typeof e||null!=e&&!ih(e))&&!(e=rs(e))&&ne(n)?ys(ce(n),0,i):n.split(e,i):[]},De.spread=function(t,e){if("function"!=typeof t)throw new Tt(n);return e=null==e?0:pe(fh(e),0),Ki((function(n){var i=n[e],s=ys(n,0,e);return i&&En(s,i),An(t,this,s)}))},De.tail=function(t){var n=null==t?0:t.length;return n?Zi(t,1,n):[]},De.take=function(n,e,i){return n&&n.length?Zi(n,0,(e=i||e===t?1:fh(e))<0?0:e):[]},De.takeRight=function(n,e,i){var s=null==n?0:n.length;return s?Zi(n,(e=s-(e=i||e===t?1:fh(e)))<0?0:e,s):[]},De.takeRightWhile=function(t,n){return t&&t.length?us(t,sr(n,3),!1,!0):[]},De.takeWhile=function(t,n){return t&&t.length?us(t,sr(n,3)):[]},De.tap=function(t,n){return n(t),t},De.throttle=function(t,e,i){var s=!0,r=!0;if("function"!=typeof t)throw new Tt(n);return Jo(i)&&(s="leading"in i?!!i.leading:s,r="trailing"in i?!!i.trailing:r),Uo(t,e,{leading:s,maxWait:e,trailing:r})},De.thru=ao,De.toArray=ah,De.toPairs=Ph,De.toPairsIn=Dh,De.toPath=function(t){return Bo(t)?Un(t,Or):oh(t)?[t]:Ss(Ir(wh(t)))},De.toPlainObject=ph,De.transform=function(t,n,e){var i=Bo(t),s=i||Ko(t)||hh(t);if(n=sr(n,4),null==e){var r=t&&t.constructor;e=s?i?new r:[]:Jo(t)&&Vo(r)?Fe(Yt(t)):{}}return(s?Mn:yi)(t,(function(t,i,s){return n(e,t,i,s)})),e},De.unary=function(t){return So(t,1)},De.union=Jr,De.unionBy=Zr,De.unionWith=to,De.uniq=function(t){return t&&t.length?os(t):[]},De.uniqBy=function(t,n){return t&&t.length?os(t,sr(n,2)):[]},De.uniqWith=function(n,e){return e="function"==typeof e?e:t,n&&n.length?os(n,t,e):[]},De.unset=function(t,n){return null==t||hs(t,n)},De.unzip=no,De.unzipWith=eo,De.update=function(t,n,e){return null==t?t:cs(t,n,vs(e))},De.updateWith=function(n,e,i,s){return s="function"==typeof s?s:t,null==n?n:cs(n,e,vs(i),s)},De.values=Fh,De.valuesIn=function(t){return null==t?[]:Qn(t,Eh(t))},De.without=io,De.words=Vh,De.wrap=function(t,n){return zo(vs(n),t)},De.xor=so,De.xorBy=ro,De.xorWith=oo,De.zip=ho,De.zipObject=function(t,n){return fs(t||[],n||[],Je)},De.zipObjectDeep=function(t,n){return fs(t||[],n||[],Vi)},De.zipWith=co,De.entries=Ph,De.entriesIn=Dh,De.extend=gh,De.extendWith=bh,rc(De,De),De.add=wc,De.attempt=Gh,De.camelCase=Rh,De.capitalize=Lh,De.ceil=yc,De.clamp=function(n,e,i){return i===t&&(i=e,e=t),i!==t&&(i=(i=vh(i))==i?i:0),e!==t&&(e=(e=vh(e))==e?e:0),si(vh(n),e,i)},De.clone=function(t){return ri(t,4)},De.cloneDeep=function(t){return ri(t,5)},De.cloneDeepWith=function(n,e){return ri(n,5,e="function"==typeof e?e:t)},De.cloneWith=function(n,e){return ri(n,4,e="function"==typeof e?e:t)},De.conformsTo=function(t,n){return null==n||oi(t,n,Uh(n))},De.deburr=Wh,De.defaultTo=function(t,n){return null==t||t!=t?n:t},De.divide=gc,De.endsWith=function(n,e,i){n=wh(n),e=rs(e);var s=n.length,r=i=i===t?s:si(fh(i),0,s);return(i-=e.length)>=0&&n.slice(i,r)==e},De.eq=Fo,De.escape=function(t){return(t=wh(t))&&H.test(t)?t.replace(Y,Zn):t},De.escapeRegExp=function(t){return(t=wh(t))&&Z.test(t)?t.replace(J,"\\$&"):t},De.every=function(n,e,i){var s=Bo(n)?Sn:li;return i&&pr(n,e,i)&&(e=t),s(n,sr(e,3))},De.find=vo,De.findIndex=Lr,De.findKey=function(t,n){return zn(t,sr(n,3),yi)},De.findLast=po,De.findLastIndex=Wr,De.findLastKey=function(t,n){return zn(t,sr(n,3),gi)},De.floor=bc,De.forEach=wo,De.forEachRight=yo,De.forIn=function(t,n){return null==t?t:pi(t,sr(n,3),Eh)},De.forInRight=function(t,n){return null==t?t:wi(t,sr(n,3),Eh)},De.forOwn=function(t,n){return t&&yi(t,sr(n,3))},De.forOwnRight=function(t,n){return t&&gi(t,sr(n,3))},De.get=xh,De.gt=Ro,De.gte=Lo,De.has=function(t,n){return null!=t&&lr(t,n,xi)},De.hasIn=Sh,De.head=Yr,De.identity=nc,De.includes=function(t,n,e,i){t=Xo(t)?t:Fh(t),e=e&&!i?fh(e):0;var s=t.length;return e<0&&(e=pe(s+e,0)),rh(t)?e<=s&&t.indexOf(n,e)>-1:!!s&&Dn(t,n,e)>-1},De.indexOf=function(t,n,e){var i=null==t?0:t.length;if(!i)return-1;var s=null==e?0:fh(e);return s<0&&(s=pe(i+s,0)),Dn(t,n,s)},De.inRange=function(n,e,i){return e=lh(e),i===t?(i=e,e=0):i=lh(i),function(t,n,e){return t>=we(n,e)&&t<pe(n,e)}(n=vh(n),e,i)},De.invoke=jh,De.isArguments=Wo,De.isArray=Bo,De.isArrayBuffer=Yo,De.isArrayLike=Xo,De.isArrayLikeObject=Ho,De.isBoolean=function(t){return!0===t||!1===t||Zo(t)&&ki(t)==d},De.isBuffer=Ko,De.isDate=No,De.isElement=function(t){return Zo(t)&&1===t.nodeType&&!eh(t)},De.isEmpty=function(t){if(null==t)return!0;if(Xo(t)&&(Bo(t)||"string"==typeof t||"function"==typeof t.splice||Ko(t)||hh(t)||Wo(t)))return!t.length;var n=ar(t);if(n==g||n==M)return!t.size;if(br(t))return!Ii(t).length;for(var e in t)if(_t.call(t,e))return!1;return!0},De.isEqual=function(t,n){return Ui(t,n)},De.isEqualWith=function(n,e,i){var s=(i="function"==typeof i?i:t)?i(n,e):t;return s===t?Ui(n,e,t,i):!!s},De.isError=Qo,De.isFinite=function(t){return"number"==typeof t&&fe(t)},De.isFunction=Vo,De.isInteger=Go,De.isLength=qo,De.isMap=th,De.isMatch=function(t,n){return t===n||Ei(t,n,or(n))},De.isMatchWith=function(n,e,i){return i="function"==typeof i?i:t,Ei(n,e,or(e),i)},De.isNaN=function(t){return nh(t)&&t!=+t},De.isNative=function(t){if(gr(t))throw new At("Unsupported core-js use. Try https://npms.io/search?q=ponyfill.");return $i(t)},De.isNil=function(t){return null==t},De.isNull=function(t){return null===t},De.isNumber=nh,De.isObject=Jo,De.isObjectLike=Zo,De.isPlainObject=eh,De.isRegExp=ih,De.isSafeInteger=function(t){return Go(t)&&t>=-9007199254740991&&t<=h},De.isSet=sh,De.isString=rh,De.isSymbol=oh,De.isTypedArray=hh,De.isUndefined=function(n){return n===t},De.isWeakMap=function(t){return Zo(t)&&ar(t)==C},De.isWeakSet=function(t){return Zo(t)&&"[object WeakSet]"==ki(t)},De.join=function(t,n){return null==t?"":de.call(t,n)},De.kebabCase=Bh,De.last=Nr,De.lastIndexOf=function(n,e,i){var s=null==n?0:n.length;if(!s)return-1;var r=s;return i!==t&&(r=(r=fh(i))<0?pe(s+r,0):we(r,s-1)),e==e?function(t,n,e){for(var i=e+1;i--;)if(t[i]===n)return i;return i}(n,e,r):Pn(n,Rn,r,!0)},De.lowerCase=Yh,De.lowerFirst=Xh,De.lt=ch,De.lte=uh,De.max=function(n){return n&&n.length?fi(n,nc,Mi):t},De.maxBy=function(n,e){return n&&n.length?fi(n,sr(e,2),Mi):t},De.mean=function(t){return Ln(t,nc)},De.meanBy=function(t,n){return Ln(t,sr(n,2))},De.min=function(n){return n&&n.length?fi(n,nc,Oi):t},De.minBy=function(n,e){return n&&n.length?fi(n,sr(e,2),Oi):t},De.stubArray=dc,De.stubFalse=vc,De.stubObject=function(){return{}},De.stubString=function(){return""},De.stubTrue=function(){return!0},De.multiply=mc,De.nth=function(n,e){return n&&n.length?Ri(n,fh(e)):t},De.noConflict=function(){return un._===this&&(un._=Dt),this},De.noop=oc,De.now=xo,De.pad=function(t,n,e){t=wh(t);var i=(n=fh(n))?he(t):0;if(!n||i>=n)return t;var s=(n-i)/2;return Ls(vn(s),e)+t+Ls(dn(s),e)},De.padEnd=function(t,n,e){t=wh(t);var i=(n=fh(n))?he(t):0;return n&&i<n?t+Ls(n-i,e):t},De.padStart=function(t,n,e){t=wh(t);var i=(n=fh(n))?he(t):0;return n&&i<n?Ls(n-i,e)+t:t},De.parseInt=function(t,n,e){return e||null==n?n=0:n&&(n=+n),ge(wh(t).replace(tt,""),n||0)},De.random=function(n,e,i){if(i&&"boolean"!=typeof i&&pr(n,e,i)&&(e=i=t),i===t&&("boolean"==typeof e?(i=e,e=t):"boolean"==typeof n&&(i=n,n=t)),n===t&&e===t?(n=0,e=1):(n=lh(n),e===t?(e=n,n=0):e=lh(e)),n>e){var s=n;n=e,e=s}if(i||n%1||e%1){var r=be();return we(n+r*(e-n+rn("1e-"+((r+"").length-1))),e)}return Xi(n,e)},De.reduce=function(t,n,e){var i=Bo(t)?$n:Yn,s=arguments.length<3;return i(t,sr(n,4),e,s,ui)},De.reduceRight=function(t,n,e){var i=Bo(t)?_n:Yn,s=arguments.length<3;return i(t,sr(n,4),e,s,ai)},De.repeat=function(n,e,i){return e=(i?pr(n,e,i):e===t)?1:fh(e),Hi(wh(n),e)},De.replace=function(){var t=arguments,n=wh(t[0]);return t.length<3?n:n.replace(t[1],t[2])},De.result=function(n,e,i){var s=-1,r=(e=ps(e,n)).length;for(r||(r=1,n=t);++s<r;){var o=null==n?t:n[Or(e[s])];o===t&&(s=r,o=i),n=Vo(o)?o.call(n):o}return n},De.round=Ac,De.runInContext=I,De.sample=function(t){return(Bo(t)?Qe:Ni)(t)},De.size=function(t){if(null==t)return 0;if(Xo(t))return rh(t)?he(t):t.length;var n=ar(t);return n==g||n==M?t.size:Ii(t).length},De.snakeCase=Hh,De.some=function(n,e,i){var s=Bo(n)?In:ts;return i&&pr(n,e,i)&&(e=t),s(n,sr(e,3))},De.sortedIndex=function(t,n){return ns(t,n)},De.sortedIndexBy=function(t,n,e){return es(t,n,sr(e,2))},De.sortedIndexOf=function(t,n){var e=null==t?0:t.length;if(e){var i=ns(t,n);if(i<e&&Fo(t[i],n))return i}return-1},De.sortedLastIndex=function(t,n){return ns(t,n,!0)},De.sortedLastIndexBy=function(t,n,e){return es(t,n,sr(e,2),!0)},De.sortedLastIndexOf=function(t,n){if(null!=t&&t.length){var e=ns(t,n,!0)-1;if(Fo(t[e],n))return e}return-1},De.startCase=Kh,De.startsWith=function(t,n,e){return t=wh(t),e=null==e?0:si(fh(e),0,t.length),n=rs(n),t.slice(e,e+n.length)==n},De.subtract=kc,De.sum=function(t){return t&&t.length?Xn(t,nc):0},De.sumBy=function(t,n){return t&&t.length?Xn(t,sr(n,2)):0},De.template=function(n,e,i){var s=De.templateSettings;i&&pr(n,e,i)&&(e=t),n=wh(n),e=bh({},e,s,Qs);var r,o,h=bh({},e.imports,s.imports,Qs),c=Uh(h),u=Qn(h,c),a=0,l=e.interpolate||wt,f="__p += '",d=St((e.escape||wt).source+"|"+l.source+"|"+(l===Q?ct:wt).source+"|"+(e.evaluate||wt).source+"|$","g"),v="//# sourceURL="+(_t.call(e,"sourceURL")?(e.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++tn+"]")+"\n";n.replace(d,(function(t,e,i,s,h,c){return i||(i=s),f+=n.slice(a,c).replace(yt,te),e&&(r=!0,f+="' +\n__e("+e+") +\n'"),h&&(o=!0,f+="';\n"+h+";\n__p += '"),i&&(f+="' +\n((__t = ("+i+")) == null ? '' : __t) +\n'"),a=c+t.length,t})),f+="';\n";var p=_t.call(e,"variable")&&e.variable;if(p){if(ot.test(p))throw new At("Invalid `variable` option passed into `_.template`")}else f="with (obj) {\n"+f+"\n}\n";f=(o?f.replace(R,""):f).replace(L,"$1").replace(W,"$1;"),f="function("+(p||"obj")+") {\n"+(p?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(r?", __e = _.escape":"")+(o?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+f+"return __p\n}";var w=Gh((function(){return kt(c,v+"return "+f).apply(t,u)}));if(w.source=f,Qo(w))throw w;return w},De.times=function(t,n){if((t=fh(t))<1||t>h)return[];var e=u,i=we(t,u);n=sr(n),t-=u;for(var s=Hn(i,n);++e<t;)n(e);return s},De.toFinite=lh,De.toInteger=fh,De.toLength=dh,De.toLower=function(t){return wh(t).toLowerCase()},De.toNumber=vh,De.toSafeInteger=function(t){return t?si(fh(t),-9007199254740991,h):0===t?t:0},De.toString=wh,De.toUpper=function(t){return wh(t).toUpperCase()},De.trim=function(n,e,i){if((n=wh(n))&&(i||e===t))return Kn(n);if(!n||!(e=rs(e)))return n;var s=ce(n),r=ce(e);return ys(s,Gn(s,r),qn(s,r)+1).join("")},De.trimEnd=function(n,e,i){if((n=wh(n))&&(i||e===t))return n.slice(0,ue(n)+1);if(!n||!(e=rs(e)))return n;var s=ce(n);return ys(s,0,qn(s,ce(e))+1).join("")},De.trimStart=function(n,e,i){if((n=wh(n))&&(i||e===t))return n.replace(tt,"");if(!n||!(e=rs(e)))return n;var s=ce(n);return ys(s,Gn(s,ce(e))).join("")},De.truncate=function(n,e){var i=30,s="...";if(Jo(e)){var r="separator"in e?e.separator:r;i="length"in e?fh(e.length):i,s="omission"in e?rs(e.omission):s}var o=(n=wh(n)).length;if(ne(n)){var h=ce(n);o=h.length}if(i>=o)return n;var c=i-he(s);if(c<1)return s;var u=h?ys(h,0,c).join(""):n.slice(0,c);if(r===t)return u+s;if(h&&(c+=u.length-c),ih(r)){if(n.slice(c).search(r)){var a,l=u;for(r.global||(r=St(r.source,wh(ut.exec(r))+"g")),r.lastIndex=0;a=r.exec(l);)var f=a.index;u=u.slice(0,f===t?c:f)}}else if(n.indexOf(rs(r),c)!=c){var d=u.lastIndexOf(r);d>-1&&(u=u.slice(0,d))}return u+s},De.unescape=function(t){return(t=wh(t))&&X.test(t)?t.replace(B,ae):t},De.uniqueId=function(t){var n=++It;return wh(t)+n},De.upperCase=Nh,De.upperFirst=Qh,De.each=wo,De.eachRight=yo,De.first=Yr,rc(De,(pc={},yi(De,(function(t,n){_t.call(De.prototype,n)||(pc[n]=t)})),pc),{chain:!1}),De.VERSION="4.17.21",Mn(["bind","bindKey","curry","curryRight","partial","partialRight"],(function(t){De[t].placeholder=De})),Mn(["drop","take"],(function(n,e){We.prototype[n]=function(i){i=i===t?1:pe(fh(i),0);var s=this.__filtered__&&!e?new We(this):this.clone();return s.__filtered__?s.__takeCount__=we(i,s.__takeCount__):s.__views__.push({size:we(i,u),type:n+(s.__dir__<0?"Right":"")}),s},We.prototype[n+"Right"]=function(t){return this.reverse()[n](t).reverse()}})),Mn(["filter","map","takeWhile"],(function(t,n){var e=n+1,i=1==e||3==e;We.prototype[t]=function(t){var n=this.clone();return n.__iteratees__.push({iteratee:sr(t,3),type:e}),n.__filtered__=n.__filtered__||i,n}})),Mn(["head","last"],(function(t,n){var e="take"+(n?"Right":"");We.prototype[t]=function(){return this[e](1).value()[0]}})),Mn(["initial","tail"],(function(t,n){var e="drop"+(n?"":"Right");We.prototype[t]=function(){return this.__filtered__?new We(this):this[e](1)}})),We.prototype.compact=function(){return this.filter(nc)},We.prototype.find=function(t){return this.filter(t).head()},We.prototype.findLast=function(t){return this.reverse().find(t)},We.prototype.invokeMap=Ki((function(t,n){return"function"==typeof t?new We(this):this.map((function(e){return Ti(e,t,n)}))})),We.prototype.reject=function(t){return this.filter(Io(sr(t)))},We.prototype.slice=function(n,e){n=fh(n);var i=this;return i.__filtered__&&(n>0||e<0)?new We(i):(n<0?i=i.takeRight(-n):n&&(i=i.drop(n)),e!==t&&(i=(e=fh(e))<0?i.dropRight(-e):i.take(e-n)),i)},We.prototype.takeRightWhile=function(t){return this.reverse().takeWhile(t).reverse()},We.prototype.toArray=function(){return this.take(u)},yi(We.prototype,(function(n,e){var i=/^(?:filter|find|map|reject)|While$/.test(e),s=/^(?:head|last)$/.test(e),r=De[s?"take"+("last"==e?"Right":""):e],o=s||/^find/.test(e);r&&(De.prototype[e]=function(){var e=this.__wrapped__,h=s?[1]:arguments,c=e instanceof We,u=h[0],a=c||Bo(e),l=function(t){var n=r.apply(De,En([t],h));return s&&f?n[0]:n};a&&i&&"function"==typeof u&&1!=u.length&&(c=a=!1);var f=this.__chain__,d=o&&!f,v=c&&!this.__actions__.length;if(!o&&a){e=v?e:new We(this);var p=n.apply(e,h);return p.__actions__.push({func:ao,args:[l],thisArg:t}),new Le(p,f)}return d&&v?n.apply(this,h):(p=this.thru(l),d?s?p.value()[0]:p.value():p)})})),Mn(["pop","push","shift","sort","splice","unshift"],(function(t){var n=jt[t],e=/^(?:push|sort|unshift)$/.test(t)?"tap":"thru",i=/^(?:pop|shift)$/.test(t);De.prototype[t]=function(){var t=arguments;if(i&&!this.__chain__){var s=this.value();return n.apply(Bo(s)?s:[],t)}return this[e]((function(e){return n.apply(Bo(e)?e:[],t)}))}})),yi(We.prototype,(function(t,n){var e=De[n];if(e){var i=e.name+"";_t.call(je,i)||(je[i]=[]),je[i].push({name:n,func:e})}})),je[Ps(t,2).name]=[{name:"wrapper",func:t}],We.prototype.clone=function(){var t=new We(this.__wrapped__);return t.__actions__=Ss(this.__actions__),t.__dir__=this.__dir__,t.__filtered__=this.__filtered__,t.__iteratees__=Ss(this.__iteratees__),t.__takeCount__=this.__takeCount__,t.__views__=Ss(this.__views__),t},We.prototype.reverse=function(){if(this.__filtered__){var t=new We(this);t.__dir__=-1,t.__filtered__=!0}else(t=this.clone()).__dir__*=-1;return t},We.prototype.value=function(){var t=this.__wrapped__.value(),n=this.__dir__,e=Bo(t),i=n<0,s=e?t.length:0,r=function(t,n,e){for(var i=-1,s=e.length;++i<s;){var r=e[i],o=r.size;switch(r.type){case"drop":t+=o;break;case"dropRight":n-=o;break;case"take":n=we(n,t+o);break;case"takeRight":t=pe(t,n-o)}}return{start:t,end:n}}(0,s,this.__views__),o=r.start,h=r.end,c=h-o,u=i?h:o-1,a=this.__iteratees__,l=a.length,f=0,d=we(c,this.__takeCount__);if(!e||!i&&s==c&&d==c)return as(t,this.__actions__);var v=[];t:for(;c--&&f<d;){for(var p=-1,w=t[u+=n];++p<l;){var y=a[p],g=y.type,b=(0,y.iteratee)(w);if(2==g)w=b;else if(!b){if(1==g)continue t;break t}}v[f++]=w}return v},De.prototype.at=lo,De.prototype.chain=function(){return uo(this)},De.prototype.commit=function(){return new Le(this.value(),this.__chain__)},De.prototype.next=function(){this.__values__===t&&(this.__values__=ah(this.value()));var n=this.__index__>=this.__values__.length;return{done:n,value:n?t:this.__values__[this.__index__++]}},De.prototype.plant=function(n){for(var e,i=this;i instanceof Re;){var s=Pr(i);s.__index__=0,s.__values__=t,e?r.__wrapped__=s:e=s;var r=s;i=i.__wrapped__}return r.__wrapped__=n,e},De.prototype.reverse=function(){var n=this.__wrapped__;if(n instanceof We){var e=n;return this.__actions__.length&&(e=new We(this)),(e=e.reverse()).__actions__.push({func:ao,args:[qr],thisArg:t}),new Le(e,this.__chain__)}return this.thru(qr)},De.prototype.toJSON=De.prototype.valueOf=De.prototype.value=function(){return as(this.__wrapped__,this.__actions__)},De.prototype.first=De.prototype.head,qt&&(De.prototype[qt]=function(){return this}),De}();ln?((ln.exports=le)._=le,an._=le):un._=le}.call(qc.exports)),qc.exports);
2
- /**
3
- * @license
4
- * Lodash <https://lodash.com/>
5
- * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
6
- * Released under MIT license <https://lodash.com/license>
7
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
8
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
9
- */class Zc{_core;_debounceUpdate;_debounceEndScaling;initialTouchDistance=0;startX=0;startY=0;constructor(t,n){this._core=t,this._core.store.state.host=n,this._core.store.state.viewportWidth=n.clientWidth,this._core.store.state.viewportHeight=n.clientHeight,this._core.store.state.startX=0,this._core.store.state.startY=0,this._core.store.state.translateX=0,this._core.store.state.translateY=0,this._debounceUpdate=Jc.debounce((()=>{this._core.updateWorkspaceViewport(this._core.store.state.translateX,this._core.store.state.translateY,this._core.store.state.scale)}),300),this._debounceEndScaling=Jc.debounce((()=>{this._core.store.state.isScaling=!1,this._core.rerender()}),100)}cancelPendingUpdates(){this._debounceUpdate.cancel()}handleResize(){this._core.store.state.viewportWidth=this._core.store.state.host.clientWidth,this._core.store.state.viewportHeight=this._core.store.state.host.clientHeight,this._core.store.state.hasViewportChanged=!0,this._core.rerender()}handlePointerDown(t){if("mouse"===t.pointerType){const n=t.clientX-this._core.store.offsetX,e=t.clientY-this._core.store.offsetY;t.button===o.Right&&(this._core.store.state.isPanning=!0,this._core.store.state.startX=n,this._core.store.state.startY=e)}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(2===t.length){const n=this._core.store.currentPath;n&&this._core.store.state.objects.remove((t=>t.id===n.id)),this._core.store.state.isScaling=!0;const e=t[0].clientX-this._core.store.offsetX,i=t[0].clientY-this._core.store.offsetY,s=t[1].clientX-this._core.store.offsetX,r=t[1].clientY-this._core.store.offsetY;this.initialTouchDistance=Math.sqrt(Math.pow(e-s,2)+Math.pow(i-r,2)),this.startX=(e+s)/2,this.startY=(i+r)/2,this._core.rerender()}}}handlePointerMove(t){if("mouse"===t.pointerType){const n=this._core.store.state.host.getBoundingClientRect(),e=t.clientX-n.left,i=t.clientY-n.top;if(this._core.store.state.pointerX=(e-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(i-this._core.store.state.translateY)/this._core.store.state.scale,this._core.store.state.isPanning){const t=i-this._core.store.state.startY;this._core.store.state.translateX+=e-this._core.store.state.startX,this._core.store.state.translateY+=t,this._core.store.state.startX=e,this._core.store.state.startY=i,this._core.store.state.hasViewportChanged=!0,this._core.store.state.skipContextMenu=!0,this._core.rerender(),this._debounceUpdate()}}if("touch"===t.pointerType){const n=this._core.store.state.host.getBoundingClientRect(),e=t.clientY-n.top;this._core.store.state.pointerX=(t.clientX-n.left-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(e-this._core.store.state.translateY)/this._core.store.state.scale;const i=Array.from(this._core.store.state.pointers.values());if(2===i.length){const t=i[0].clientX-this._core.store.offsetX,n=i[0].clientY-this._core.store.offsetY,e=i[1].clientX-this._core.store.offsetX,s=i[1].clientY-this._core.store.offsetY,r=Math.sqrt(Math.pow(t-e,2)+Math.pow(n-s,2)),o=(t+e)/2,h=(n+s)/2,c=r/this.initialTouchDistance,u=this._core.store.state.scale*c;if(u>this._core.store.state.scaleMax||u<this._core.store.state.scaleMin)this._core.store.state.translateX=this._core.store.state.translateX+o-this.startX,this._core.store.state.translateY=this._core.store.state.translateY+h-this.startY;else{const t=(h-this._core.store.state.translateY)*(c-1);this._core.store.state.translateX=this._core.store.state.translateX+o-this.startX-(o-this._core.store.state.translateX)*(c-1),this._core.store.state.translateY=this._core.store.state.translateY+h-this.startY-t,this._core.store.state.scale=u,this.initialTouchDistance=r}this.startX=o,this.startY=h,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}}}handlePointerUp(t){"mouse"===t.pointerType&&this._core.store.state.isPanning&&(this._core.store.state.isPanning=!1,this._core.rerender()),"touch"===t.pointerType&&0===this._core.store.state.pointers.size&&this._debounceEndScaling()}handleWheel(t){t.preventDefault(),!0===t.ctrlKey&&Math.abs(t.deltaY)>0&&0===Math.abs(t.deltaX)&&this.handleZoom(t),t.ctrlKey||this.handlePan(t)}centerInViewport(t){const{scale:n,viewportWidth:e,viewportHeight:i}=this._core.store.state,{x:s,y:r,width:o,height:h}=t.rotatedBoundingBox,c=r+h/2;this._core.store.state.translateX=e/2-(s+o/2)*n,this._core.store.state.translateY=i/2-c*n,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}centerFitInViewport(t){const n=Math.min(this._core.store.state.viewportWidth/(1.1*t.rotatedBoundingBox.width),this._core.store.state.viewportHeight/(1.1*t.rotatedBoundingBox.height),this._core.store.state.scaleMax),e=Math.max(n,this._core.store.state.scaleMin);this._core.store.state.scale=e,this.centerInViewport(t)}handleZoom(t){this._core.store.state.isScaling=!0;const n=this._core.store.state.host.getBoundingClientRect(),e=t.clientX-n.left,i=t.clientY-n.top;this._core.store.state.pointerX=(e-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(i-this._core.store.state.translateY)/this._core.store.state.scale;const s=Math.max(.8,Math.min(1.2,1+-.012*t.deltaY)),r=Math.min(this._core.store.state.scaleMax,Math.max(this._core.store.state.scaleMin,this._core.store.state.scale*s)),o=r/this._core.store.state.scale,h=(e-this._core.store.state.translateX)*(o-1),c=(i-this._core.store.state.translateY)*(o-1);this._core.store.state.scale=r,this._core.store.state.translateX=this._core.store.state.translateX-h,this._core.store.state.translateY=this._core.store.state.translateY-c,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate(),this._debounceEndScaling()}handlePan(t){this._core.store.state.translateX=this._core.store.state.translateX-.8*t.deltaX,this._core.store.state.translateY=this._core.store.state.translateY-.8*t.deltaY,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}}class tu extends At{shortcuts=[{key:"Escape",condition:t=>!!t.store.selectionGroup,action:t=>t.clearSelection()},{key:"Delete",condition:t=>!!t.store.selectionGroup,action:t=>t.delete()},{key:"z",ctrl:!0,action:t=>t.undo()},{key:"y",ctrl:!0,action:t=>t.redo()},{key:"s",ctrl:!0,action:()=>this.switchTool("selection")},{key:"b",ctrl:!0,action:()=>this.switchTool("brush")},{key:"e",ctrl:!0,action:()=>this.switchTool("eraser")},{key:"i",ctrl:!0,action:()=>this.switchTool("image")},{key:"x",ctrl:!0,action:()=>this.switchTool("text")},{key:"c",ctrl:!0,condition:t=>!!t.store.selectionGroup,action:t=>{t.copy(),t.rerender()}},{key:"v",ctrl:!0,condition:t=>!!t.store.state.copiedObjects&&!t.store.activeText,action:t=>t.paste()},{key:"+",ctrl:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.bringForward()},{key:"-",ctrl:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.sendBackward()},{key:"*",shift:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.bringToFront()},{key:"_",shift:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.sendToBack()},{key:"g",ctrl:!0,condition:t=>!!t.store.selectionGroup&&t.store.selectionGroup.objects.length>=2,action:t=>t.group()},{key:"G",ctrl:!0,shift:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.ungroup()}];constructor(t){super(t)}switchTool(t){const n=l.getTool(t);this._core.store.setState("activeTool",n),this._core.deselectAllObjects(),n.onActivate()}handleKeyDown(t){this._core.store.state.isCtrlKeyPressed=t.ctrlKey;const n=this.shortcuts.find((n=>n.key===t.key&&!!n.ctrl===t.ctrlKey&&!!n.shift===t.shiftKey&&(!n.condition||n.condition(this._core))));n&&(t.preventDefault(),n.action(this._core))}handleKeyUp(t){this._core.store.state.isCtrlKeyPressed=t.ctrlKey}}class nu extends At{globalContextMenuItems=[];objectContextMenuItems=[];constructor(t,n,e){super(t),this.globalContextMenuItems=n,this.objectContextMenuItems=e}handleContextMenu(t){if(!(this._core.store.state.activeTool instanceof Et))return;if(this._core.store.state.skipContextMenu)return void(this._core.store.state.skipContextMenu=!1);const n=this._core.store.state.activeTool;n?.moveHandler?.cancelPendingDrag(),this._core.store.selectionBox&&(this._core.store.state.objects.remove((t=>t instanceof Ct)),this._core.store.state.isSelecting=!1);const e=this._core.getObjectFromPointerEvent(t,".object");if(e&&!(e instanceof D)&&!(e instanceof Ct)){const t=D.create(this._core);t.addOrRemove(e),t.isSelected=!0,t.rotation=e.rotation,this._core.store.state.isSelecting=!1,this._core.store.selectionGroup&&this._core.removeSelectionGroup(),this._core.addSelectionGroup(t),this._core.rerender()}this._core.store.state.contextMenuItems=this._core.store.selectionGroup?this.objectContextMenuItems:this.globalContextMenuItems;let i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;const r=10;i+150>window.innerWidth-r&&(i=window.innerWidth-150-r),s+200>window.innerHeight-r&&(s=window.innerHeight-200-r),i=Math.max(r,i),s=Math.max(r,s),this._core.store.state.contextMenuX=i,this._core.store.state.contextMenuY=s,this._core.store.state.isContextMenuVisible=!0,this._core.store.state.isEnabled=!1,this._core.rerender()}}const eu={activeWorkspace:null,activeTool:null,copiedObjects:null,objects:null,snapCandidate:null,resizeHandleType:null,lineHandleType:null,hasViewportChanged:!1,hasObjectsChanged:!1,isReady:!1,isEnabled:!0,isScaling:!1,isPanning:!1,isSelecting:!1,isResizing:!1,isResizeHandleHovered:!1,isResizeHandleSelected:!1,isRotating:!1,isRotationHandleHovered:!1,isRotationHandleSelected:!1,isLineHandleSelected:!1,isLineHandleDragging:!1,isDragging:!1,isDrawing:!1,isErasing:!1,isWriting:!1,isCtrlKeyPressed:!1,isContextMenuVisible:!1,contextMenuItems:[],contextMenuX:0,contextMenuY:0,skipContextMenu:!1,debugInfo:{showObjectInfo:!1,showViewportInfo:!1},host:null,pointerX:0,pointerY:0,scale:1,scaleMax:1,scaleMin:1,startX:0,startY:0,translateX:0,translateXMax:400,translateXMin:0,translateY:0,translateYMax:400,translateYMin:0,viewportWidth:0,viewportHeight:0,longTouchTimeout:null,longTouchDelay:300,pointers:new Map,workspaces:[],cursor:{icon:"default",iconActive:"default"}};class iu extends h{__class__="KritzelCustomElement";element;isInteractive=!0;constructor(t){super(),t&&(this.translateX=t.translateX||0,this.translateY=t.translateY||0,this.scale=t.scale||1,this.element=t.element,this.height=t.height||0,this.width=t.width||0)}static create(t,n){const e=new iu(n);return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e}mount(t){null!==t&&(this.isMounted&&this.elementRef===t&&this.element.parentElement===t||(this.elementRef=t,this.isMounted=!0,this.elementRef.innerHTML="",this.elementRef.appendChild(this.element)))}resize(t,n,e,i){e<=1||i<=1||(this.width=e,this.height=i,this.translateX=t,this.translateY=n,this.element&&(this.element.style.width=`${e}px`,this.element.style.height=`${i}px`),this._core.store.state.objects.update(this))}copy(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.generateId(),t.isMounted=!1,t.element=this.element.cloneNode(!0),t}}class su{_core;constructor(t){this._core=t}revive(t){if(t&&"object"==typeof t){if(t.__class__){let n;switch(t.__class__){case"KritzelPath":n=x.create(this._core).deserialize(t);break;case"KritzelLine":n=z.create(this._core).deserialize(t);break;case"KritzelText":n=M.create(this._core,t.fontSize,t.fontFamily).deserialize(t);break;case"KritzelShape":n=Xc.create(this._core,{shapeType:t.shapeType,fillColor:t.fillColor,strokeColor:t.strokeColor,strokeWidth:t.strokeWidth,fontSize:t.fontSize,fontFamily:t.fontFamily,fontColor:t.fontColor}).deserialize(t);break;case"KritzelImage":n=O.create(this._core).deserialize(t);break;case"KritzelCustomElement":n=iu.create(this._core).deserialize(t);break;case"KritzelSelectionGroup":n=D.create(this._core).deserialize(t);break;case"KritzelGroup":n=P.create(this._core).deserialize(t);break;case"KritzelWorkspace":n=$.create(this._core,t).deserialize(t);break;case"KritzelBrushTool":n=new k(this._core);break;case"KritzelEraserTool":n=new R(this._core);break;case"KritzelImageTool":n=new bt(this._core);break;case"KritzelSelectionTool":n=new Et(this._core);break;case"KritzelTextTool":n=new A(this._core);break;case"KritzelLineTool":n=new F(this._core);break;case"KritzelShapeTool":n=new Hc(this._core);break;default:n=t}return n}const n=Array.isArray(t)?[]:{};for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&(n[e]=this.revive(t[e]));return n}return t}}class ru{bounds;capacity;objects=[];children=null;constructor(t,n=16){this.bounds=t,this.capacity=n}reset(){this.objects=[],this.children=null}insert(t){if(!this.intersects(t.rotatedBoundingBox,this.bounds))return!1;if(this.objects.length<this.capacity&&null===this.children)return this.objects.push(t),!0;null===this.children&&this.subdivide();for(const n of this.children)if(n.insert(t))return!0;return!1}update(t){const n=this.objects.findIndex((n=>n.id===t.id));if(-1!==n)return this.objects[n]=t,!0;if(null!==this.children)for(const n of this.children)if(n.update(t))return!0;return!1}remove(t){const n=this.objects.findIndex((n=>t(n)));if(-1!==n&&this.objects.splice(n,1),null!==this.children)for(const n of this.children)n.remove(t)}query(t){const n=[];if(!this.intersects(t,this.bounds))return n;for(const e of this.objects)this.intersects(e.rotatedBoundingBox,t)&&n.push(e);if(null!==this.children)for(const e of this.children)n.push(...e.query(t));return n}filter(t){const n=this.objects.filter((n=>t(n)));if(null!==this.children)for(const e of this.children)n.push(...e.filter(t));return n}allObjects(){const t=[...this.objects];if(null!==this.children)for(const n of this.children)t.push(...n.allObjects());return t}subdivide(){const{x:t,y:n,z:e,width:i,height:s}=this.bounds,r=i/2,o=s/2;this.children=[new ru({x:t,y:n,z:e,width:r,height:o},this.capacity),new ru({x:t+r,y:n,z:e,width:r,height:o},this.capacity),new ru({x:t,y:n+o,z:e,width:r,height:o},this.capacity),new ru({x:t+r,y:n+o,z:e,width:r,height:o},this.capacity)]}intersects(t,n){return!(t.x>=n.x+n.width||t.x+t.width<=n.x||t.y>=n.y+n.height||t.y+t.height<=n.y)}}class ou{quadtree;_ydoc=null;_objectsMap=null;_providers=[];_undoManager=null;_reviver=null;_core=null;_workspaceId=null;_isReady=!1;_temporaryItemsCount=0;get isReady(){return this._isReady}get undoManager(){return this._undoManager}get workspaceId(){return this._workspaceId}get undoState(){return{canUndo:!!this._undoManager&&this._undoManager.canUndo(),canRedo:!!this._undoManager&&this._undoManager.canRedo(),undoStackSize:this._undoManager?this._undoManager.undoStack.length:0,redoStackSize:this._undoManager?this._undoManager.redoStack.length:0}}constructor(){this.quadtree=new ru({x:-1/0,y:-1/0,z:0,width:1/0,height:1/0},8)}async initialize(t,n,e){this._core=t,this._workspaceId=n,this._reviver=new su(t),this._ydoc=new ms,this._objectsMap=this._ydoc.getMap("objects");const i=`kritzel-workspace-${n}`,s=e??Rc;for(const t of s.providers){let n;n="function"==typeof t?new t(i,this._ydoc):t.create(i,this._ydoc),this._providers.push(n)}this._undoManager=new dr([this._objectsMap],{captureTimeout:200,trackedOrigins:new Set(["local","temporary"]),ignoreRemoteMapChanges:!0}),this._undoManager.on("stack-item-added",(t=>{"undo"===t.type&&"temporary"===t.origin&&this._temporaryItemsCount++})),this._undoManager.on("stack-item-popped",(t=>{"undo"===t.type&&"temporary"===t.origin&&this._temporaryItemsCount>0&&this._temporaryItemsCount--})),this._objectsMap.observe((t=>{this.handleObjectsChange(t)})),await Promise.all(this._providers.map((t=>t.connect()))),this._isReady=!0,this.loadFromYjs()}handleObjectsChange(t){if("local"===t.transaction.origin||"temporary"===t.transaction.origin)return void this._core?.rerender();const n=Array.from(t.keysChanged),e=[],i=[],s=[];n.forEach((n=>{const r=t.changes.keys.get(n);if(r&&"delete"===r.action)s.push(n);else{const t=this._objectsMap.get(n);if(t){const n=this._reviver.revive(t);n instanceof D?i.push(n):e.push(n)}}})),s.forEach((t=>{this.quadtree.remove((n=>n.id===t))})),e.forEach((t=>{const n=this.quadtree.filter((n=>n.id===t.id)).length>0;n?this.quadtree.update(t):this.quadtree.insert(t)})),i.forEach((t=>{const n=this.quadtree.filter((n=>n.id===t.id)).length>0;n?this.quadtree.update(t):this.quadtree.insert(t)})),this._core?.rerender()}transaction(t){this._ydoc&&this._ydoc.transact(t,"local")}loadFromYjs(){this._objectsMap&&this._reviver&&(this.quadtree.reset(),this._objectsMap.forEach((t=>{const n=this._reviver.revive(t);this.quadtree.insert(n)})))}reset(){this.quadtree.reset(),this._ydoc.transact((()=>{this._objectsMap.clear()}),"local")}insert(t){if(!t.id)return!1;if(this.quadtree.insert(t),this._objectsMap&&this.isPersistable(t)){const n=t.serialize();this._ydoc.transact((()=>{this._objectsMap.set(t.id,n)}),"local")}return!0}update(t,n={}){if(!t.id)return!1;const e=this.quadtree.filter((n=>n.id===t.id)).length>0;if(!e)return!1;if(this.quadtree.update(t),this._objectsMap&&this.isPersistable(t)){const e=t.serialize();this._ydoc.transact((()=>{this._objectsMap.set(t.id,e)}),n.temporary?"temporary":"local")}return!0}remove(t){const n=this.quadtree.filter(t);for(const t of n)this.quadtree.remove((n=>n.id===t.id)),this._objectsMap&&this.isPersistable(t)&&this._ydoc.transact((()=>{this._objectsMap.delete(t.id)}),"local")}filter(t){return this.quadtree.filter(t)}allObjects(){return this.quadtree.allObjects()}query(t){return this.quadtree.query(t)}isPersistable(t){return!(t instanceof Ct)}undo(){this._undoManager&&this._undoManager.canUndo()&&(this._undoManager.undo(),this._core.engine.emitObjectsChange())}redo(){this._undoManager&&this._undoManager.canRedo()&&(this._undoManager.redo(),this._core.engine.emitObjectsChange())}canUndo(){return!!this._undoManager&&this._undoManager.canUndo()}canRedo(){return!!this._undoManager&&this._undoManager.canRedo()}clearHistory(){this._undoManager&&(this._undoManager.clear(),this._temporaryItemsCount=0)}consolidateTemporaryItems(){if(!this._undoManager||0===this._temporaryItemsCount)return;const t=this._undoManager.undoStack.length;if(0===t)return void(this._temporaryItemsCount=0);this._undoManager.stopCapturing();const n=Math.min(this._temporaryItemsCount,t);if(n>1){for(let t=0;t<n;t++)this._undoManager.canUndo()&&this._undoManager.undo();this._ydoc.transact((()=>{for(let t=n-1;t>=0;t--)this._undoManager.canRedo()&&this._undoManager.redo()}),"local")}this._temporaryItemsCount=0}clearTemporaryItems(){if(!this._undoManager||0===this._temporaryItemsCount)return;const t=Math.min(this._temporaryItemsCount,this._undoManager.undoStack.length);for(let n=0;n<t;n++)this._undoManager.undoStack.length>0&&this._undoManager.undoStack.pop();this._temporaryItemsCount=0}destroy(){this._providers.forEach((t=>t.destroy())),this._providers=[],this._ydoc&&this._ydoc.destroy()}}class hu{_state;_listeners=new Map;get state(){return this._state}get currentZIndex(){return Math.max(0,...this._state.objects.filter((t=>!(t instanceof D||t instanceof Ct))).map((t=>t.zIndex)))+1}get allObjects(){return this._state.objects.allObjects()}get allNonSelectionObjects(){return this._state.objects.allObjects().filter((t=>!(t instanceof D||t instanceof Ct)))}get selectedObjects(){return this.allObjects.filter((t=>!(t instanceof D))).filter((t=>t.isSelected))}get selectionBox(){const t=this._state.objects.filter((t=>t instanceof Ct));return t.length>0?t[0]:null}get selectionGroup(){const t=this._state.objects.filter((t=>t instanceof D));return t.length>0?t[0]:null}get activeText(){const t=this._state.objects.filter((t=>t instanceof M&&t.isEditing));return t.length>0?t[0]:null}get activeShape(){const t=this._state.objects.filter((t=>t instanceof Xc&&t.isEditing));return t.length>0?t[0]:null}get currentPath(){const t=this._state.objects.filter((t=>t instanceof x&&!1===t.isCompleted));return t.length>0?t[0]:null}get currentLine(){const t=this._state.objects.filter((t=>t instanceof z&&!1===t.isCompleted));return t.length>0?t[0]:null}get offsetX(){return this._state.host.getBoundingClientRect().left}get offsetY(){return this._state.host.getBoundingClientRect().top}get isDisabled(){return!1===this._state.isEnabled||!1===this._state.isReady||null===this._state.activeWorkspace}get isPointerDown(){return this._state.pointers.size>0}constructor(t){this._state=t,this._state.objects=new ou}onStateChange(t,n){this._listeners.has(t)||this._listeners.set(t,new Set),this._listeners.get(t).add(n)}getState(t){return this._state[t]}setState(t,n){const e=this._state[t];e!==n&&(this._state[t]=n,this._listeners.has(t)&&this._listeners.get(t).forEach((i=>i(n,e,String(t)))))}}class cu{_core;_targetElement=null;_shadowRoot=null;constructor(t){this._core=t}setTargetElement(t){this._targetElement&&(this._targetElement.style.cursor="",this._targetElement.style.removeProperty("--kritzel-pointer-cursor")),this._targetElement=t,this._targetElement&&this._targetElement.style.setProperty("--kritzel-pointer-cursor",mt.getPointerCursor())}getTargetElement(){return this._targetElement}setShadowRoot(t){this._shadowRoot=t}resetToDefault(){this._core.store.state.cursor={icon:"default",iconActive:"default"}}updateHoverState(t){if(this._core.store.isPointerDown)return;if(!this._shadowRoot)return;const n=this._shadowRoot.elementsFromPoint(t.clientX,t.clientY);if(!n||0===n.length)return;const e=n.find((t=>t.classList.contains("resize-handle-overlay")));if(e){const t=this._core.store.selectionGroup,n=t?.rotationDegrees??0,i=e.classList.contains("top-left"),s=e.classList.contains("bottom-right");this._core.store.state.cursor={icon:"move-vertical",rotation:n+(i||s?-45:45)}}else this._core.store.state.cursor=n.find((t=>t.classList.contains("rotation-handle-overlay")))||n.find((t=>t.classList.contains("selection-line-handle-overlay")))?{icon:"hand",iconActive:"hand-grab"}:{icon:"default",iconActive:"default"}}applyCursor(){const t=this._core.store.state,n=this._core.store.isPointerDown,e=t.cursor?.icon,i=t.cursor?.iconActive??e,s=t.cursor?.rotation,r=mt.getCursor({iconName:n?i:e,rotation:s});this._targetElement&&(this._targetElement.style.cursor=r)}cleanup(){this._targetElement&&(this._targetElement.style.cursor="",this._targetElement.style.removeProperty("--kritzel-pointer-cursor")),this._targetElement=null,this._shadowRoot=null}}class uu{_kritzelEngine;_store;_syncConfig;_appStateMap;_anchorManager;_cursorManager;get engine(){return this._kritzelEngine}get store(){return this._store}get appStateMap(){return this._appStateMap}get anchorManager(){return this._anchorManager}get cursorManager(){return this._cursorManager}constructor(t){this._kritzelEngine=t,this._store=new hu(eu),this._appStateMap=new Lc,this._anchorManager=new Bc(this),this._cursorManager=new cu(this)}setSyncConfig(t){this._syncConfig=t}async initializeYjs(){await this._appStateMap.initialize(this,this._syncConfig)}loadWorkspacesFromAppState(){return this._appStateMap.allWorkspaces()}saveWorkspaceToAppState(t){this._appStateMap.has(t.id)?this._appStateMap.update(t):this._appStateMap.insert(t)}deleteWorkspaceFromAppState(t){this._appStateMap.remove((n=>n.id===t))}async initializeWorkspace(t){const n=this.loadWorkspacesFromAppState(),e=n.length>0?[...n].sort(((t,n)=>n.updatedAt.getTime()-t.updatedAt.getTime()))[0]:null,i=localStorage.getItem("kritzel-active-workspace-id"),s=i?n.find((t=>t.id===i)):null;let r;t?(r=t,n.find((n=>n.id===t.id))||(r._core=this,this.saveWorkspaceToAppState(r))):s?r=s:e?r=e:(r=new $(T.generateUUID(),"New Workspace"),r._core=this,this.saveWorkspaceToAppState(r)),localStorage.setItem("kritzel-active-workspace-id",r.id),this._store.state.objects&&this._store.state.objects.isReady&&this._store.state.objects.destroy();const o=new ou;this._store.state.objects=o,this._store.state.activeWorkspace=r,this._store.state.workspaces=this.loadWorkspacesFromAppState();const h=r.viewport??{translateX:0,translateY:0,scale:1};this._store.state.translateX=h.translateX??0,this._store.state.translateY=h.translateY??0,this._store.state.scale=h.scale??1,await o.initialize(this,r.id,this._syncConfig),this._anchorManager.rebuildIndex(),this.engine.emitObjectsChange(),this.rerender()}rerender(){this._kritzelEngine&&this._kritzelEngine.forceUpdate++}findObjectById(t){for(const n of this._store.allObjects)if(n.id===t)return n;return null}getWorkspaces(){return this.loadWorkspacesFromAppState()}createWorkspace(t){t._core=this,t.createdAt=new Date,t.updatedAt=new Date,this.saveWorkspaceToAppState(t),this._store.state.workspaces=this.loadWorkspacesFromAppState()}updateWorkspace(t){t.updatedAt=new Date,this.saveWorkspaceToAppState(t);const n=this._store.state.workspaces,e=n.findIndex((n=>n.id===t.id));-1!==e&&(n[e]=t,this._store.state.workspaces=n)}deleteWorkspace(t){this._store.state.activeWorkspace?.id===t.id&&this._store.state.objects?.destroy(),this.deleteWorkspaceFromAppState(t.id),this._store.state.workspaces=this.loadWorkspacesFromAppState(),window.indexedDB.deleteDatabase(`kritzel-workspace-${t.id}`)}updateWorkspaceViewport(t,n,e){const i=this._store.state.activeWorkspace;i&&(i.viewport={translateX:t,translateY:n,scale:e},i.updatedAt=new Date,this.saveWorkspaceToAppState(i))}addObject(t){this._store.state.objects.insert(t)}removeObject(t,n=!1){t instanceof P&&!n&&[...t.children].forEach((t=>{this.removeObject(t)})),t instanceof z?this._anchorManager.handleLineDeleted(t.id):this._anchorManager.handleObjectDeleted(t.id),t.isMounted=!1,this._store.state.objects.remove((n=>n.id===t.id))}updateObject(t,n){for(const e in n)n.hasOwnProperty(e)&&(t[e]=n[e]);this._store.state.objects.update(t)}addSelectionGroup(t){this.removeSelectionGroup(),this.removeSelectionBox(),this._store.state.objects.insert(t)}removeSelectionGroup(){const t=this._store.selectionGroup;t&&this._store.state.objects.remove((n=>n.id===t.id))}removeSelectionBox(){const t=this._store.selectionBox;t&&this._store.state.objects.remove((n=>n.id===t.id))}deselectAllObjects(){this.removeSelectionGroup(),this.rerender()}delete(){const t=this._store.selectionGroup;t&&(t.objects.forEach((t=>this.removeObject(t))),this.removeSelectionGroup(),this.rerender())}undo(){this._store.state.objects?.undo()}redo(){this._store.state.objects?.redo()}deleteObject(t){const n=this.findObjectById(t);n&&(this.removeObject(n),this.rerender())}copy(){const t=this._store.selectionGroup;if(t){const n=new Map,e=t.objects.sort(((t,n)=>t.zIndex-n.zIndex)).map((t=>{const e=t.copy();return n.set(e.id,t.id),e}));this._store.state.copiedObjects=e,this._store.state.copiedObjectIdMapping=n}}paste(t,n){const e=this._store.state.copiedObjects;if(!e||0===e.length)return;const i=this._store.state.activeWorkspace,s=this._store.state.copiedObjectIdMapping,r=e.some((t=>t.workspaceId!==i.id)),o=Math.min(...e.map((t=>t.translateX))),h=Math.min(...e.map((t=>t.translateY)));let c,u;void 0!==t&&void 0!==n?(c=t,u=n):r?(c=o,u=h):(c=o+25/this._store.state.scale,u=h+25/this._store.state.scale);const a=c-o,f=u-h;this.removeSelectionGroup(),this.removeSelectionBox();const d=D.create(this),v=new Map;s&&s.forEach(((t,n)=>{v.set(t,n)})),e.forEach(((t,n)=>{if(t.workspaceId!==i.id&&(t.workspaceId=i.id),t.updatePosition(t.translateX+a,t.translateY+f),t.zIndex=this._store.currentZIndex+n,t instanceof P){const e=t._pendingChildren;e&&(e.forEach(((t,e)=>{t.workspaceId!==i.id&&(t.workspaceId=i.id),t.updatePosition(t.translateX+a,t.translateY+f),t.zIndex=this._store.currentZIndex+n+e,this.addObject(t)})),delete t._pendingChildren,t.finalize())}this.addObject(t),d.addOrRemove(t)})),e.forEach((t=>{if(t instanceof z){let n=!1;t.startAnchor&&v.has(t.startAnchor.objectId)&&(t.startAnchor={objectId:v.get(t.startAnchor.objectId)},n=!0),t.endAnchor&&v.has(t.endAnchor.objectId)&&(t.endAnchor={objectId:v.get(t.endAnchor.objectId)},n=!0),n&&this._store.state.objects.update(t)}})),this._anchorManager.rebuildIndex(),d.isSelected=!0,1===e.length&&(d.rotation=e[0].rotation),this.addSelectionGroup(d),r&&(void 0!==t&&void 0!==n?d.updatePosition(t,n):d.centerInViewport(),this.engine.viewport.centerFitInViewport(d)),this._store.state.isSelecting=!1;const p=this._store.selectionGroup;if(p){const t=new Map,n=p.objects.sort(((t,n)=>t.zIndex-n.zIndex)).map((n=>{const e=n.copy();return t.set(e.id,n.id),e}));this._store.state.copiedObjects=n,this._store.state.copiedObjectIdMapping=t}this._store.setState("activeTool",l.getTool("selection")),this.engine.emitObjectsChange(),this.rerender()}bringForward(t){const n=this._store.selectionGroup,e=t?[t]:n?.objects||[],i=this._store.allNonSelectionObjects.filter((t=>-1===e.findIndex((n=>n.id===t.id)))),s=i.length>0?Math.max(...i.map((t=>t.zIndex)))+1:0;e.forEach((t=>{t.zIndex!==s&&this.updateObject(t,{zIndex:t.zIndex+1})})),this.rerender()}sendBackward(t){const n=this._store.selectionGroup,e=t?[t]:n?.objects||[],i=this._store.allNonSelectionObjects.filter((t=>-1===e.findIndex((n=>n.id===t.id)))),s=i.length>0?Math.min(...i.map((t=>t.zIndex)))-1:0;e.forEach((t=>{t.zIndex!==s&&this.updateObject(t,{zIndex:t.zIndex-1})})),this.rerender()}bringToFront(t){const n=this._store.selectionGroup,e=t?[t]:n?.objects||[],i=this._store.allNonSelectionObjects.filter((t=>-1===e.findIndex((n=>n.id===t.id)))),s=Math.max(...i.map((t=>t.zIndex)))+1;e.forEach((t=>{this.updateObject(t,{zIndex:s})})),this.rerender()}sendToBack(t){const n=this._store.selectionGroup,e=t?[t]:n?.objects||[],i=this._store.allNonSelectionObjects.filter((t=>-1===e.findIndex((n=>n.id===t.id)))),s=Math.min(...i.map((t=>t.zIndex)))-1;e.forEach((t=>{this.updateObject(t,{zIndex:s})})),this.rerender()}group(){const t=this._store.selectionGroup;if(!t||t.objects.length<2)return;const n=P.createFromObjects(this,t.objects);this.addObject(n),this.removeSelectionGroup();const e=D.create(this);e.addOrRemove(n),e.isSelected=!0,e.rotation=n.rotation,this.addSelectionGroup(e),this.engine.emitObjectsChange(),this.rerender()}ungroup(){const t=this._store.selectionGroup;if(!t)return;const n=t.objects.filter((t=>t instanceof P));if(0===n.length)return;const e=[],i=t.objects.filter((t=>!(t instanceof P)));n.forEach((t=>{const n=t.ungroup();e.push(...n),this.removeObject(t,!0)})),this.removeSelectionGroup();const s=D.create(this);[...e,...i].forEach((t=>{s.addOrRemove(t)})),s.isSelected=!0,this.addSelectionGroup(s),this.engine.emitObjectsChange(),this.rerender()}selectObjects(t){if(0===t.length)return;const n=D.create(this);t.forEach((t=>{t.isSelected=!1,n.addOrRemove(t)})),n.isSelected=!0,1===t.length&&(n.rotation=n.objects[0].rotation),this.addSelectionGroup(n),this.rerender()}selectAllObjectsInViewport(){const t=this._store.state.objects.query({x:-this._store.state.translateX/this._store.state.scale,y:-this._store.state.translateY/this._store.state.scale,z:this._store.state.scale,width:this._store.state.viewportWidth/this._store.state.scale,height:this._store.state.viewportHeight/this._store.state.scale,depth:100}).filter((t=>t.isInViewport())).filter((t=>!(t instanceof D||t instanceof Ct||t instanceof S)));if(t.length>0){const n=D.create(this);t.forEach((t=>{t.isSelected=!1,n.addOrRemove(t)})),n.isSelected=!0,this._store.state.isSelecting=!1,1===t.length&&(n.rotation=n.objects[0].rotation),this.addSelectionGroup(n),this._store.setState("activeTool",l.getTool("selection")),this.rerender()}}clearSelection(){this.removeSelectionGroup(),this._store.state.objects.remove((t=>t instanceof Ct||t instanceof D)),this._store.state.isSelecting=!1,this._store.state.isResizeHandleSelected=!1,this._store.state.isRotationHandleSelected=!1,this._store.state.isLineHandleSelected=!1,this._store.state.isLineHandleDragging=!1,this._store.state.lineHandleType=null,this.rerender()}resetActiveText(){const t=this._store.activeText;t&&(t.isEmpty?this.deleteObject(t.id):t.save())}resetActiveShape(){const t=this._store.activeShape;t&&t.save()}getObjectFromPointerEvent(t,n=".object"){const e=this._store.state.host?.shadowRoot;if(!e)return null;const i=t.clientX,s=t.clientY,r=e.elementFromPoint(i,s);if(!r)return null;const o=r.closest(n);if(o){const t=this._store.allObjects.find((t=>o.id===t.id)),n=t?.hitTest(i,s);return n?t:null}return null}getObjectsFromPointerEvent(t,n=".object"){const e=this._store.state.host?.shadowRoot;if(!e)return[];const i=e.elementsFromPoint(t.clientX,t.clientY);if(!i||0===i.length)return[];const s=new Set;return i.forEach((t=>{const e=t.closest(n);e&&e.id&&s.add(e.id)})),s.size>0?this._store.allObjects.filter((t=>s.has(t.id))).sort(((t,n)=>n.zIndex-t.zIndex)):[]}getElementsAtPoint(t,n){const e=this._store.state.host?.shadowRoot;if(!e)return[];const i=e.elementsFromPoint(t.clientX,t.clientY);return i&&0!==i.length?i.filter((t=>t.matches(n))):[]}isPointerOverElement(t,n){return this.getElementsAtPoint(t,n).length>0}getCanvasPoint(t){if(!this._store.state.host)return{x:0,y:0};const n=this._store.state.host.getBoundingClientRect();return{x:(t.clientX-n.left-this._store.state.translateX)/this._store.state.scale,y:(t.clientY-n.top-this._store.state.translateY)/this._store.state.scale}}beforeWorkspaceChange(){this._kritzelEngine.viewport?.cancelPendingUpdates(),this._store.state.activeWorkspace&&this.updateWorkspaceViewport(this._store.state.translateX,this._store.state.translateY,this._store.state.scale),this.resetActiveText(),this.clearSelection(),this._store.setState("activeTool",l.getTool("selection"))}displaySelectionGroupUI(t){if(!t.isSelected)return!1;const n=this._store.selectionGroup;return n?n.objects.length>1||(1!==n.objects.length||!(n.objects[0]instanceof z)):!(t instanceof z)}displaySelectionLineUI(t){if(!(t instanceof z))return!1;const n=this._store.selectionGroup;if(!n)return t.isSelected;if(!n.isSelected)return!1;if(1===n.objects.length){const e=n.objects[0];return e instanceof z&&e.id===t.id}return!1}}const au=t(class extends n{get host(){return this}workspace;syncConfig;onWorkspaceChange(t){const n=this.core.store.state.activeWorkspace?.id,e=t?.id;n!==e&&(this.core.beforeWorkspaceChange(),this.core.initializeWorkspace(t))}activeTool;globalContextMenuItems;objectContextMenuItems;scaleMax=Kc;validateScaleMax(t){t>Kc?(console.warn("scaleMax cannot be greater than 1000."),this.scaleMax=Kc,this.core.store.state.scaleMax=this.scaleMax):this.core.store.state.scaleMax=t}scaleMin=Nc;validateScaleMin(t){t<Nc?(console.warn("scaleMin cannot be less than 0.0001."),this.scaleMin=Nc,this.core.store.state.scaleMin=this.scaleMin):this.core.store.state.scaleMin=t}cursorTarget;onCursorTargetChange(t){this.core.cursorManager.setTargetElement(t||document.body)}isEngineReady;activeToolChange;workspacesChange;longpress;objectsChange;undoStateChange;forceUpdate=0;throttledWheel=Jc.throttle((t=>{this.viewport.handleWheel(t),this.core.store.state?.activeTool?.handleWheel(t)}),16);handleWheel(t){this.core.store.isDisabled||(this.core.store.state.isContextMenuVisible&&this.hideContextMenu(),this.throttledWheel(t))}handlePointerDown(t){this.core.store.isDisabled||(j.isTouchDevice()&&a.onLongPress(t,(t=>this.longpress.emit(t))),this.host.setPointerCapture(t.pointerId),this.core.store.state.pointers.set(t.pointerId,t),this.viewport.handlePointerDown(t),this.core.store.state?.activeTool?.handlePointerDown(t))}throttledPointerMoveMulti=Jc.throttle((t=>{this.viewport.handlePointerMove(t),this.core.store.state?.activeTool?.handlePointerMove(t)}),16);handlePointerMove(t){this.core.store.isDisabled||(this.core.store.state.pointers.has(t.pointerId)&&this.core.store.state.pointers.set(t.pointerId,t),this.core.store.state.pointers.size>1&&this.throttledPointerMoveMulti(t),this.core.cursorManager.updateHoverState(t),this.viewport.handlePointerMove(t),this.core.store.state?.activeTool?.handlePointerMove(t))}handlePointerUp(t){this.core.store.isDisabled||(this.core.store.state.pointers.delete(t.pointerId),this.host.releasePointerCapture(t.pointerId),0===this.core.store.state.pointers.size&&this.core.cursorManager.resetToDefault(),this.viewport.handlePointerUp(t),this.core.store.state?.activeTool?.handlePointerUp(t))}handlePointerCancel(t){this.core.store.isDisabled||(this.host.releasePointerCapture(t.pointerId),this.core.store.state.pointers.delete(t.pointerId),0===this.core.store.state.pointers.size&&this.core.cursorManager.resetToDefault(),this.viewport.handlePointerUp(t),this.core.store.state?.activeTool?.handlePointerUp(t))}handleLongPress(t){this.contextMenuHandler.handleContextMenu(t.detail)}handleContextMenu(t){t.preventDefault(),this.core.store.isDisabled||"touch"!==t.pointerType&&this.contextMenuHandler.handleContextMenu(t)}handleResize(){this.viewport.handleResize()}handleKeyDown(t){this.core.store.isDisabled||this.keyHandler.handleKeyDown(t)}handleKeyUp(t){this.core.store.isDisabled||this.keyHandler.handleKeyUp(t)}preventDoubleTapZoomOnTouchDevices(t){t.preventDefault()}async registerTool(t,n,e){if("function"!=typeof n||!(n.prototype instanceof u))return console.error(`Failed to register tool "${t}": Tool class must be a constructor function`),null;const i=l.registerTool(t,n,this.core);return e&&Object.entries(e).forEach((([t,n])=>{i[t]=n})),Promise.resolve(i)}async changeActiveTool(t){this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",t),this.core.deselectAllObjects(),t?.onActivate()}async disable(){this.core.store.state.isEnabled=!1,this.core.rerender()}async enable(){this.core.store.state.isEnabled=!0,this.core.rerender()}async delete(){this.core.delete()}async copy(){this.core.copy()}async paste(t,n){this.core.paste(t,n)}async bringForward(t){this.core.bringForward(t)}async sendBackward(t){this.core.sendBackward(t)}async bringToFront(t){this.core.bringToFront(t)}async sendToBack(t){this.core.sendToBack(t)}async group(){this.core.group()}async ungroup(){this.core.ungroup()}async undo(){this.core.undo()}async redo(){this.core.redo()}async hideContextMenu(){this.core.store.state.pointers.clear(),this.core.store.state.isContextMenuVisible=!1,this.core.store.state.objects.remove((t=>t instanceof Ct)),this.core.store.state.isSelecting=!1,this.core.store.state.isEnabled=!0,this.core.rerender()}async getObjectById(t){return this.core.store.allObjects.find((n=>n.id===t))||null}async addObject(t){return this.core.deselectAllObjects(),t.id=t.generateId(),t._core=this.core,t.scale=t.scale?t.scale:this.core.store.state.scale,t.zIndex=this.core.store.currentZIndex,this.core.addObject(t),this.core.rerender(),t}async updateObject(t,n){return this.core.deselectAllObjects(),this.core.updateObject(t,n),this.core.rerender(),t}async removeObject(t){return this.core.deselectAllObjects(),this.core.store.state.objects.remove((n=>n.id===t.id)),this.core.rerender(),t}async getSelectedObjects(){const t=this.core.store.selectionGroup;return t?t.objects:[]}async selectObjects(t){this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",l.getTool("selection")),this.core.deselectAllObjects(),this.core.selectObjects(t)}async selectAllObjectsInViewport(){this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",l.getTool("selection")),this.core.deselectAllObjects(),this.core.selectAllObjectsInViewport()}async clearSelection(){this.core.clearSelection()}async centerObjectInViewport(t){return t.centerInViewport(),this.core.updateObject(t,t),this.core.rerender(),t}async getCopiedObjects(){return this.core.store.state.copiedObjects||[]}async createWorkspace(t){return await this.core.createWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces),t}async updateWorkspace(t){await this.core.updateWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces)}async deleteWorkspace(t){await this.core.deleteWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces)}async getWorkspaces(){return await this.core.getWorkspaces()}async getActiveWorkspace(){return this.core.store.state.activeWorkspace}core;viewport;contextMenuHandler;keyHandler;contextMenuElement=null;get isSelecting(){return this.core.store.state.activeTool instanceof Et&&this.core.store.state.isSelecting}get isSelectionActive(){return this.core.store.state.activeTool instanceof Et&&null!==this.core.store.selectionGroup}constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.isEngineReady=e(this,"isEngineReady"),this.activeToolChange=e(this,"activeToolChange"),this.workspacesChange=e(this,"workspacesChange"),this.longpress=e(this,"longpress"),this.objectsChange=e(this,"objectsChange"),this.undoStateChange=e(this,"undoStateChange"),this.core=new uu(this)}disconnectedCallback(){this.throttledWheel.cancel(),this.throttledPointerMoveMulti.cancel(),this.core.cursorManager.cleanup()}componentWillLoad(){this.validateScaleMax(this.scaleMax),this.validateScaleMin(this.scaleMin)}async componentDidLoad(){this.contextMenuHandler=new nu(this.core,this.globalContextMenuItems,this.objectContextMenuItems),this.keyHandler=new tu(this.core),this.viewport=new Zc(this.core,this.host),this.core.cursorManager.setTargetElement(this.cursorTarget||document.body),this.core.cursorManager.setShadowRoot(this.host.shadowRoot),this.syncConfig&&this.core.setSyncConfig(this.syncConfig),await this.core.initializeYjs(),await this.core.initializeWorkspace(this.workspace),this.core.appStateMap.onRemoteChange((()=>{this.workspacesChange.emit(this.core.store.state.workspaces)})),this._registerStateChangeListeners(),!1===this.core.store.state.isReady&&(this.core.store.state.isReady=!0,this.isEngineReady.emit(this.core.store.state))}emitObjectsChange(){const t=this.core.store.state.objects.undoState;this.objectsChange.emit(this.core.store.allObjects),this.undoStateChange.emit(t)}_registerStateChangeListeners(){this.core.store.onStateChange("activeTool",this._handleActiveToolChange.bind(this))}_handleActiveToolChange(t){t instanceof Et||(this.core.clearSelection(),this.core.store.state.objects.remove((t=>t instanceof Ct)),this.core.store.state.isSelecting=!1,this.core.store.state.isResizeHandleSelected=!1,this.core.store.state.isRotationHandleSelected=!1),this.core.store.state.skipContextMenu=!1,this.core.store.state.copiedObjects=null,this.activeToolChange.emit(t),b.forceHideKeyboard(),this.core.rerender()}render(){const t=window.getComputedStyle(this.host).getPropertyValue("--kritzel-selection-handle-size").trim()||"6px",n=parseFloat(t),e=2*n<14?14:n,r=this.core.store.state.viewportWidth/2+this.core.store.state.translateX,o=this.core.store.state.viewportHeight/2+this.core.store.state.translateY,h=this.core.store.state.objects.query({x:-this.core.store.state.translateX/this.core.store.state.scale,y:-this.core.store.state.translateY/this.core.store.state.scale,z:this.core.store.state.scale,width:this.core.store.state.viewportWidth/this.core.store.state.scale,height:this.core.store.state.viewportHeight/this.core.store.state.scale,depth:100}).sort(((t,n)=>t.zIndex-n.zIndex));return this.core.cursorManager.applyCursor(),i(s,{key:"cf63f71e5ab763750f0857595a6b2d56e99b29fd"},this.core.store.state.debugInfo.showViewportInfo&&i("div",{key:"cf6d5221edb666692bbed086d1fa5bb57f591442",class:"debug-panel"},i("div",{key:"d1e94a59352063d08412c13bee8632b468229431"},"ActiveWorkspaceId: ",this.core.store.state?.activeWorkspace?.id),i("div",{key:"0eeff49b2c3bd703ef3b0fa574a323822ecef8a3"},"ActiveWorkspaceName: ",this.core.store.state?.activeWorkspace?.name),i("div",{key:"884aaab5f8c10a21541139cbc1c824a80233c7bb"},"TranslateX: ",this.core.store.state?.translateX),i("div",{key:"6633c2b83830bc5091825b9c51af2aa82fbc935e"},"TranslateY: ",this.core.store.state?.translateY),i("div",{key:"905bf21fed43acbada2e5d18dd9eb33979d368a4"},"ViewportWidth: ",this.core.store.state?.viewportWidth),i("div",{key:"d2abcda891791cee5386fe065de9b781c2db2e0a"},"ViewportHeight: ",this.core.store.state?.viewportHeight),i("div",{key:"9f64a19ac4510a2eae4d605dfdbb9a855b001b19"},"PointerCount: ",this.core.store.state.pointers.size),i("div",{key:"25634969756ec8505e2b169c4f8f77fa5260932a"},"Scale: ",this.core.store.state?.scale),i("div",{key:"2aea36a0521a5e59154836da290e7c615e4dc36d"},"ActiveTool: ",this.core.store.state?.activeTool?.name),i("div",{key:"599bafe7e87b23df191849ad23f56eea0009272f"},"HasViewportChanged: ",this.core.store.state?.hasViewportChanged?"true":"false"),i("div",{key:"d5e466d0b64b0f64a808dc8f08dba21530579a49"},"IsEnabled: ",this.core.store.state?.isEnabled?"true":"false"),i("div",{key:"6143b384caa285cd850111b3d6d3fe95f3a468db"},"IsScaling: ",this.core.store.state?.isScaling?"true":"false"),i("div",{key:"5695722e2e07e024fe1b5db1be22c890fa16b7d9"},"IsPanning: ",this.core.store.state?.isPanning?"true":"false"),i("div",{key:"93c2d1a6669b397637d6918055fc14c96493cc65"},"IsSelecting: ",this.isSelecting?"true":"false"),i("div",{key:"2245f5894f7460d9d31ee33125260334920c6847"},"IsSelectionActive: ",this.isSelectionActive?"true":"false"),i("div",{key:"57fd33a984b7975198d87285658ec4de2824aa34"},"IsResizeHandleSelected: ",this.core.store.state.isResizeHandleSelected?"true":"false"),i("div",{key:"257cc4badaa694f04c839ca68ee79d1b695a006b"},"IsRotationHandleSelected: ",this.core.store.state.isRotationHandleSelected?"true":"false"),i("div",{key:"c00f461af4e4b1523e7e5feccfb0abfc6d45f5b7"},"IsRotationHandleHovered: ",this.core.store.state.isRotationHandleHovered?"true":"false"),i("div",{key:"3f1bd888dfa360153b930fc5e498ccb348879d81"},"IsDrawing: ",this.core.store.state.isDrawing?"true":"false"),i("div",{key:"4b33ce03143d6f96e359bc0a21697a3788fa6d3e"},"IsWriting: ",this.core.store.state.isWriting?"true":"false"),i("div",{key:"d603a0a226357378889c87d1bda5dd194388a81c"},"IsPointerDown: ",this.core.store.isPointerDown?"true":"false"),i("div",{key:"e0cb4c098e14c44c7c4d96a35f75a609a5d83144"},"PointerX: ",this.core.store.state?.pointerX),i("div",{key:"d663eff93d7884aa36da56a46e06cb65f0b14c54"},"PointerY: ",this.core.store.state?.pointerY),i("div",{key:"fe44809fc10454d605bad012300e8a46a8f180c9"},"SelectedObjects: ",this.core.store.selectionGroup?.objects.length||0),i("div",{key:"d69d570660f6ec9d37d842f24f61e534d4f349e1"},"ViewportCenter: (",r.toFixed(2),", ",o.toFixed(2),")")),i("div",{key:"aa6674f91511007c52f7faba849dd82f206e20ed",id:"origin",class:"origin",style:{transform:`matrix(${this.core.store.state?.scale}, 0, 0, ${this.core.store.state?.scale}, ${this.core.store.state?.translateX}, ${this.core.store.state?.translateY})`}},h?.map((t=>i("div",{key:t.id,style:{transform:t?.transformationMatrix,transformOrigin:"top left",position:"absolute",pointerEvents:this.core.store.state.isScaling?"none":"auto"}},i("svg",{xmlns:"http://www.w3.org/2000/svg",id:t.id,class:"object",style:{zIndex:t.zIndex.toString(),height:t?.totalHeight+"px",width:t?.totalWidth+"px",left:"0",top:"0",position:"absolute",transform:0!==t.rotationDegrees?`rotate(${t.rotationDegrees}deg)`:void 0,transformOrigin:0!==t.rotationDegrees?`${t.totalWidth/2}px ${t.totalHeight/2}px`:void 0,opacity:t.markedForRemoval?"0.5":t.opacity.toString(),pointerEvents:t.markedForRemoval?"none":"auto"}},Wc.isInstanceOf(t,"KritzelPath")&&i("svg",{ref:n=>t.mount(n),xmlns:"http://www.w3.org/2000/svg",style:{overflow:"visible"},viewBox:t?.viewBox},i("path",{d:t?.d,fill:t.fill,stroke:t?.stroke,"shape-rendering":t.isLowRes()?"optimizeSpeed":"auto"})),Wc.isInstanceOf(t,"KritzelLine")&&i("svg",{ref:n=>t.mount(n),xmlns:"http://www.w3.org/2000/svg",style:{overflow:"visible"},viewBox:t?.viewBox},i("defs",null,t.hasStartArrow&&i("marker",{id:t.startMarkerId,markerWidth:t.getArrowSize("start"),markerHeight:t.getArrowSize("start"),refX:0,refY:t.getArrowSize("start")/2,orient:"auto-start-reverse",markerUnits:"userSpaceOnUse"},i("path",{d:t.getArrowPath(t.arrows?.start?.style),fill:t.getArrowFill("start"),transform:`scale(${t.getArrowSize("start")/10})`})),t.hasEndArrow&&i("marker",{id:t.endMarkerId,markerWidth:t.getArrowSize("end"),markerHeight:t.getArrowSize("end"),refX:0,refY:t.getArrowSize("end")/2,orient:"auto",markerUnits:"userSpaceOnUse"},i("path",{d:t.getArrowPath(t.arrows?.end?.style),fill:t.getArrowFill("end"),transform:`scale(${t.getArrowSize("end")/10})`}))),i("path",{d:this.core.anchorManager.computeClippedLinePath(t),fill:"none",stroke:"transparent","stroke-width":Math.max(t?.strokeWidth||0,10),"stroke-linecap":"round"}),i("path",{d:this.core.anchorManager.computeClippedLinePath(t),fill:"none",stroke:t?.stroke,"stroke-width":t?.strokeWidth,"stroke-linecap":"round","marker-start":t.hasStartArrow?`url(#${t.startMarkerId})`:void 0,"marker-end":t.hasEndArrow?`url(#${t.endMarkerId})`:void 0})),i("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",display:Wc.isInstanceOf(t,"KritzelLine")||Wc.isInstanceOf(t,"KritzelPath")?"none":"block"}},Wc.isInstanceOf(t,"KritzelImage")&&i("img",{ref:n=>t.mount(n),src:t.src,style:{width:"100%",height:"100%",userSelect:"none",pointerEvents:"none",imageRendering:this.core.store.state.isScaling||this.core.store.state.isPanning?"pixelated":"auto"},draggable:!1,onDragStart:t=>t.preventDefault()}),Wc.isInstanceOf(t,"KritzelText")&&i("div",{id:"text-object",ref:n=>t.mount(n),onPointerDown:n=>t.handlePointerDown(n),onPointerMove:n=>t.handlePointerMove(n),onPointerUp:n=>t.handlePointerUp(n),style:{minWidth:t.initialWidth+"px",minHeight:t.initialHeight+"px",maxWidth:"500px",height:"auto",width:"max-content",transformOrigin:"top left",transform:`scale(${t.scaleFactor})`,backgroundColor:t.backgroundColor,overflow:"visible",textRendering:this.core.store.state.isScaling||this.core.store.state.isPanning?"optimizeSpeed":"auto"}}),Wc.isInstanceOf(t,"KritzelShape")&&i("div",{ref:n=>t.mount(n),onPointerDown:n=>t.handlePointerDown(n),onPointerMove:n=>t.handlePointerMove(n),onPointerUp:n=>t.handlePointerUp(n),style:{width:"100%",height:"100%",position:"relative",overflow:"visible"}},i("svg",{xmlns:"http://www.w3.org/2000/svg",style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:t.viewBox,preserveAspectRatio:"none"},i("path",{d:t.getSvgPath(),fill:t.fillColor,stroke:t.strokeColor,"stroke-width":t.strokeWidth})),i("div",{ref:n=>t.mountTextEditor(n),style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center",overflow:"hidden",pointerEvents:t.isEditing?"auto":"none"}})),Wc.isInstanceOf(t,"KritzelCustomElement")&&i("div",{ref:n=>t.mount(n),style:{width:"100%",height:"100%",pointerEvents:"auto",overflow:"hidden",display:"block"}}),Wc.isInstanceOf(t,"KritzelSelectionGroup")&&!this.core.displaySelectionLineUI(t)&&i("div",{ref:n=>t.mount(n),style:{width:"100%",height:"100%"}}),Wc.isInstanceOf(t,"KritzelSelectionBox")&&i("div",{ref:n=>t.mount(n),style:{width:"100%",height:"100%",backgroundColor:j.isFirefox()?t.backgroundColor:"transparent",borderWidth:j.isFirefox()?t.borderWidth+"px":"0",borderStyle:j.isFirefox()?"solid":"none",borderColor:j.isFirefox()?t.borderColor:"transparent"}}))),this.core.store.state.debugInfo.showObjectInfo&&t.isDebugInfoVisible&&i("div",{style:{pointerEvents:"none",position:"absolute",left:`${t.totalWidth}px`,top:"0",zIndex:(t.zIndex+2).toString()}},i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"Id: ",t.id),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"width: ",t.width),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"height: ",t.height),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateX: ",t.translateX),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateY: ",t.translateY),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"rotationDegrees: ",t.rotationDegrees),i("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"zIndex: ",t.zIndex)),i("svg",{xmlns:"http://www.w3.org/2000/svg",style:{zIndex:(t.zIndex+1).toString(),height:t?.totalHeight.toString(),width:t?.totalWidth.toString(),left:"0",top:"0",position:"absolute",transform:`rotate(${t.rotationDegrees}deg)`,transformOrigin:`${t.totalWidth/2}px ${t.totalHeight/2}px`,overflow:"visible",pointerEvents:"none"}},this.core.displaySelectionGroupUI(t)&&i("g",{class:"selection-group-ui",style:{pointerEvents:"none"}},i("g",{class:"selection-group-borders"},i("line",{x1:"0",y1:"0",x2:t.totalWidth,y2:"0",style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),i("line",{x1:"0",y1:"0",x2:"0",y2:t.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),i("line",{x1:"0",y1:t.totalHeight,x2:t.totalWidth,y2:t.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),i("line",{x1:t.totalWidth,y1:"0",x2:t.totalWidth,y2:t.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}})),!this.isSelecting&&i("g",{class:"selection-group-handles",style:{pointerEvents:"auto"}},i("circle",{class:"resize-handle top-left",cx:"0",cy:"0",r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),i("circle",{class:"resize-handle-overlay top-left",cx:"0",cy:"0",r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("circle",{class:"resize-handle top-right",cx:t.totalWidth,cy:"0",r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),i("circle",{class:"resize-handle-overlay top-right",cx:t.totalWidth,cy:"0",r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("circle",{class:"resize-handle bottom-left",cx:"0",cy:t.totalHeight,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),i("circle",{class:"resize-handle-overlay bottom-left",cx:"0",cy:t.totalHeight,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("circle",{class:"resize-handle bottom-right",cx:t.totalWidth,cy:t.totalHeight,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),i("circle",{class:"resize-handle-overlay bottom-right",cx:t.totalWidth,cy:t.totalHeight,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("line",{x1:t.totalWidth/2,y1:"0",x2:t.totalWidth/2,y2:-15*t.scale/this.core.store.state?.scale,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`}}),i("circle",{class:"rotation-handle",cx:t.totalWidth/2,cy:-15*t.scale/this.core.store.state?.scale,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),i("circle",{class:"rotation-handle-overlay",cx:t.totalWidth/2,cy:-15*t.scale/this.core.store.state?.scale,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}))),this.core.displaySelectionLineUI(t)&&Wc.isInstanceOf(t,"KritzelLine")&&i("g",{class:"selection-line-ui",style:{pointerEvents:"none"}},i("g",{class:"selection-line-borders"},i("path",{class:"selection-line-border",d:this.core.anchorManager.computeClippedLinePath(t,!0),style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"round",fill:"none"}})),!this.isSelecting&&i("g",{class:"selection-line-handles",style:{pointerEvents:"auto"}},i("circle",{class:"selection-line-handle start",cx:t.startX-t.x,cy:t.startY-t.y,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),i("circle",{class:"selection-line-handle-overlay start",cx:t.startX-t.x,cy:t.startY-t.y,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("circle",{class:"selection-line-handle center",cx:void 0!==t.controlX?(t.startX+2*t.controlX+t.endX)/4-t.x:(t.startX-t.x+t.endX-t.x)/2,cy:void 0!==t.controlY?(t.startY+2*t.controlY+t.endY)/4-t.y:(t.startY-t.y+t.endY-t.y)/2,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),i("circle",{class:"selection-line-handle-overlay center",cx:void 0!==t.controlX?(t.startX+2*t.controlX+t.endX)/4-t.x:(t.startX-t.x+t.endX-t.x)/2,cy:void 0!==t.controlY?(t.startY+2*t.controlY+t.endY)/4-t.y:(t.startY-t.y+t.endY-t.y)/2,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),i("circle",{class:"selection-line-handle end",cx:t.endX-t.x,cy:t.endY-t.y,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),i("circle",{class:"selection-line-handle-overlay end",cx:t.endX-t.x,cy:t.endY-t.y,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}))))))),(()=>{const t=this.core.anchorManager.getAnchorLinesRenderData();return t?i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"anchor-lines",style:{position:"absolute",left:"0",top:"0",width:"1px",height:"1px",pointerEvents:"none",zIndex:"9998",overflow:"visible"}},t.startAnchorViz&&i("g",{class:"anchor-line-start"},t.startAnchorViz.pathD?i("path",{d:t.startAnchorViz.pathD,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.3))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round",fill:"none"}}):i("line",{x1:t.startAnchorViz.edgeX,y1:t.startAnchorViz.edgeY,x2:t.startAnchorViz.centerX,y2:t.startAnchorViz.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.3))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),i("circle",{cx:t.startAnchorViz.centerX,cy:t.startAnchorViz.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(0, 0, 0))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}})),t.endAnchorViz&&i("g",{class:"anchor-line-end"},t.endAnchorViz.pathD?i("path",{d:t.endAnchorViz.pathD,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round",fill:"none"}}):i("line",{x1:t.endAnchorViz.edgeX,y1:t.endAnchorViz.edgeY,x2:t.endAnchorViz.centerX,y2:t.endAnchorViz.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),i("circle",{cx:t.endAnchorViz.centerX,cy:t.endAnchorViz.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(59, 130, 246, 0.3))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}}))):null})(),(()=>{const t=this.core.anchorManager.getSnapIndicatorRenderData();return t?i("svg",{xmlns:"http://www.w3.org/2000/svg",class:"snap-indicator",style:{position:"absolute",left:"0",top:"0",width:"1px",height:"1px",pointerEvents:"none",zIndex:"9999",overflow:"visible"}},i("g",null,t.snapLinePath?i("path",{d:t.snapLinePath,fill:"none",style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:t.lineStrokeWidth,strokeDasharray:t.dashArray,strokeLinecap:"round"}}):void 0!==t.edgeX&&void 0!==t.edgeY&&i("line",{x1:t.edgeX,y1:t.edgeY,x2:t.centerX,y2:t.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:t.lineStrokeWidth,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),i("circle",{cx:t.centerX,cy:t.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(59, 130, 246, 0.3))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}}))):null})()),this.core.store.state.isContextMenuVisible&&i("kritzel-context-menu",{key:"95f98d34b26eca7124f973002c2689e9a90f6748",class:"context-menu",ref:t=>this.contextMenuElement=t,items:this.core.store.state.contextMenuItems,objects:this.core.store.selectionGroup?.objects||[],style:{position:"fixed",left:`${this.core.store.state.contextMenuX}px`,top:`${this.core.store.state.contextMenuY}px`,zIndex:"10002"},onActionSelected:t=>{t.detail.action({x:(-this.core.store.state.translateX+this.core.store.state.contextMenuX)/this.core.store.state.scale,y:(-this.core.store.state.translateY+this.core.store.state.contextMenuY)/this.core.store.state.scale},this.core.store.selectionGroup?.objects),this.hideContextMenu()},onClose:()=>this.hideContextMenu()}),this.core.store.state?.activeTool instanceof R&&!this.core.store.state.isScaling&&i("kritzel-cursor-trail",{key:"412f67f0a484b7f5e37a4e9fa25d9124c389f62b",core:this.core}))}static get watchers(){return{workspace:[{onWorkspaceChange:0}],scaleMax:[{validateScaleMax:0}],scaleMin:[{validateScaleMin:0}],cursorTarget:[{onCursorTargetChange:0}]}}static get style(){return":host{display:block;position:relative;height:100%;width:100%;overflow:hidden;background-color:var(--kritzel-engine-background-color, #ffffff)}:host,:host *{touch-action:none;user-select:none}.ProseMirror{outline:none}p,h1,h2,h3,h4,h5,h6,blockquote,pre{margin:0;padding:0}.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}.PlaygroundEditorTheme__quote{margin:0;margin-left:20px;margin-bottom:10px;font-size:15px;color:rgb(101, 103, 107);border-left-color:rgb(206, 208, 212);border-left-width:4px;border-left-style:solid;padding-left:16px}"}},[513,"kritzel-engine",{workspace:[16],syncConfig:[16],activeTool:[16],globalContextMenuItems:[16],objectContextMenuItems:[16],scaleMax:[1026,"scale-max"],scaleMin:[1026,"scale-min"],cursorTarget:[16],forceUpdate:[32],registerTool:[64],changeActiveTool:[64],disable:[64],enable:[64],delete:[64],copy:[64],paste:[64],bringForward:[64],sendBackward:[64],bringToFront:[64],sendToBack:[64],group:[64],ungroup:[64],undo:[64],redo:[64],hideContextMenu:[64],getObjectById:[64],addObject:[64],updateObject:[64],removeObject:[64],getSelectedObjects:[64],selectObjects:[64],selectAllObjectsInViewport:[64],clearSelection:[64],centerObjectInViewport:[64],getCopiedObjects:[64],createWorkspace:[64],updateWorkspace:[64],deleteWorkspace:[64],getWorkspaces:[64],getActiveWorkspace:[64]},[[0,"wheel","handleWheel"],[0,"pointerdown","handlePointerDown"],[0,"pointermove","handlePointerMove"],[0,"pointerup","handlePointerUp"],[0,"pointercancel","handlePointerCancel"],[0,"longpress","handleLongPress"],[0,"contextmenu","handleContextMenu"],[9,"resize","handleResize"],[8,"keydown","handleKeyDown"],[8,"keyup","handleKeyUp"],[4,"dblclick","preventDoubleTapZoomOnTouchDevices"]],{workspace:[{onWorkspaceChange:0}],scaleMax:[{validateScaleMax:0}],scaleMin:[{validateScaleMin:0}],cursorTarget:[{onCursorTargetChange:0}]}]);function lu(){"undefined"!=typeof customElements&&["kritzel-engine","kritzel-context-menu","kritzel-cursor-trail","kritzel-icon"].forEach((t=>{switch(t){case"kritzel-engine":customElements.get(r(t))||customElements.define(r(t),au);break;case"kritzel-context-menu":customElements.get(r(t))||C();break;case"kritzel-cursor-trail":customElements.get(r(t))||_();break;case"kritzel-icon":customElements.get(r(t))||E()}}))}export{me as A,Ht as B,Nt as C,Tc as D,z as E,P as F,F as G,Fc as H,R as I,bt as J,O as K,mt as L,Et as M,dh as N,Bt as O,Lc as P,Bc as Q,Kc as R,Yc as S,Nc as T,Hc as U,lu as V,au as W,An as a,Fn as b,$s as c,Ps as d,Is as e,an as f,Dn as g,Ot as h,_e as i,$e as j,Ee as k,oe as l,Bn as m,Yt as n,re as o,te as p,be as q,Ln as r,It as s,fn as t,bn as u,se as v,pn as w,le as x,Wt as y,ln as z}