kritzel-stencil 0.1.1 → 0.1.3

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 (171) hide show
  1. package/dist/cjs/{default-line-tool.config-SdMGkNhv.js → default-line-tool.config-MA02HCrH.js} +635 -118
  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} +832 -771
  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/objects/line.class.js +1 -0
  10. package/dist/collection/classes/objects/path.class.js +1 -0
  11. package/dist/collection/classes/objects/shape.class.js +1 -0
  12. package/dist/collection/classes/objects/text.class.js +4 -3
  13. package/dist/collection/classes/providers/indexeddb-sync-provider.class.js +0 -1
  14. package/dist/collection/classes/tools/brush-tool.class.js +5 -0
  15. package/dist/collection/classes/tools/line-tool.class.js +31 -1
  16. package/dist/collection/classes/tools/selection-tool.class.js +193 -0
  17. package/dist/collection/classes/tools/shape-tool.class.js +2 -0
  18. package/dist/collection/classes/tools/text-tool.class.js +3 -0
  19. package/dist/collection/collection-manifest.json +5 -3
  20. package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js +3 -2
  21. package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +37 -19
  22. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +108 -36
  23. package/dist/collection/components/shared/kritzel-color/kritzel-color.js +2 -2
  24. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.css +1 -1
  25. package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.js +24 -2
  26. package/dist/collection/components/shared/kritzel-font/kritzel-font.js +1 -1
  27. package/dist/collection/components/shared/kritzel-font-family/kritzel-font-family.css +1 -1
  28. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.css +1 -1
  29. package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js +1 -1
  30. package/dist/collection/components/shared/kritzel-line-endings/kritzel-line-endings.css +60 -0
  31. package/dist/collection/components/shared/kritzel-line-endings/kritzel-line-endings.js +187 -0
  32. package/dist/collection/components/shared/kritzel-menu/kritzel-menu.js +15 -8
  33. package/dist/collection/components/shared/kritzel-menu-item/kritzel-menu-item.js +16 -9
  34. package/dist/collection/components/shared/kritzel-opacity-slider/kritzel-opacity-slider.css +85 -0
  35. package/dist/collection/components/shared/kritzel-opacity-slider/kritzel-opacity-slider.js +163 -0
  36. package/dist/collection/components/shared/kritzel-portal/kritzel-portal.js +1 -1
  37. package/dist/collection/components/shared/kritzel-shape-fill/kritzel-shape-fill.css +47 -0
  38. package/dist/collection/components/shared/kritzel-shape-fill/kritzel-shape-fill.js +93 -0
  39. package/dist/collection/components/shared/kritzel-split-button/kritzel-split-button.js +13 -7
  40. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.css +11 -2
  41. package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.js +2 -2
  42. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.css +1 -1
  43. package/dist/collection/components/shared/kritzel-tooltip/kritzel-tooltip.js +6 -4
  44. package/dist/collection/components/ui/kritzel-context-menu/kritzel-context-menu.js +6 -3
  45. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.css +4 -4
  46. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +95 -14
  47. package/dist/collection/components/ui/kritzel-tool-config/kritzel-tool-config.css +38 -0
  48. package/dist/collection/components/ui/kritzel-tool-config/kritzel-tool-config.js +321 -0
  49. package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.js +3 -2
  50. package/dist/collection/components/ui/kritzel-workspace-manager/kritzel-workspace-manager.js +6 -3
  51. package/dist/collection/configs/default-brush-tool.config.js +2 -52
  52. package/dist/collection/configs/default-line-tool.config.js +2 -26
  53. package/dist/collection/configs/default-shape-tool.config.js +2 -15
  54. package/dist/collection/configs/default-text-tool.config.js +2 -26
  55. package/dist/collection/constants/color-palette.constants.js +30 -0
  56. package/dist/collection/helpers/color.helper.js +31 -0
  57. package/dist/collection/helpers/tool-config.helper.js +65 -0
  58. package/dist/collection/interfaces/tool-config.interface.js +1 -0
  59. package/dist/components/index.d.ts +8 -4
  60. package/dist/components/index.js +1 -1
  61. package/dist/components/kritzel-brush-style.js +1 -1
  62. package/dist/components/kritzel-color-palette.js +1 -1
  63. package/dist/components/kritzel-color.js +1 -1
  64. package/dist/components/kritzel-context-menu.js +1 -1
  65. package/dist/components/kritzel-controls.js +1 -1
  66. package/dist/components/kritzel-cursor-trail.js +1 -1
  67. package/dist/components/kritzel-dropdown.js +1 -1
  68. package/dist/components/kritzel-editor.js +1 -1
  69. package/dist/components/kritzel-engine.js +1 -1
  70. package/dist/components/kritzel-font-family.js +1 -1
  71. package/dist/components/kritzel-font-size.js +1 -1
  72. package/dist/components/kritzel-font.js +1 -1
  73. package/dist/components/kritzel-icon.js +1 -1
  74. package/dist/components/kritzel-line-endings.d.ts +11 -0
  75. package/dist/components/kritzel-line-endings.js +1 -0
  76. package/dist/components/kritzel-menu-item.js +1 -1
  77. package/dist/components/kritzel-menu.js +1 -1
  78. package/dist/components/kritzel-opacity-slider.d.ts +11 -0
  79. package/dist/components/kritzel-opacity-slider.js +1 -0
  80. package/dist/components/kritzel-portal.js +1 -1
  81. package/dist/components/kritzel-shape-fill.d.ts +11 -0
  82. package/dist/components/kritzel-shape-fill.js +1 -0
  83. package/dist/components/kritzel-split-button.js +1 -1
  84. package/dist/components/kritzel-stroke-size.js +1 -1
  85. package/dist/components/kritzel-tool-config.d.ts +11 -0
  86. package/dist/components/kritzel-tool-config.js +1 -0
  87. package/dist/components/kritzel-tooltip.js +1 -1
  88. package/dist/components/kritzel-utility-panel.js +1 -1
  89. package/dist/components/kritzel-workspace-manager.js +1 -1
  90. package/dist/components/p-83YX0-FS.js +1 -0
  91. package/dist/components/p-9XZbc_qK.js +1 -0
  92. package/dist/components/p-BVIY50lR.js +1 -0
  93. package/dist/components/{p-D1tfzpy8.js → p-BlUr7oVq.js} +1 -1
  94. package/dist/components/{p-Bj_Og27M.js → p-BxS4Pdpz.js} +1 -1
  95. package/dist/components/{p-g0N9j_uT.js → p-CCj8nmQH.js} +1 -1
  96. package/dist/components/{p-1z-ds26_.js → p-CLOnpu42.js} +1 -1
  97. package/dist/components/p-CNneo_RD.js +1 -0
  98. package/dist/components/p-CkpOndCn.js +1 -0
  99. package/dist/components/{p-IAqZFssU.js → p-Cnpk2hfo.js} +1 -1
  100. package/dist/components/{p-Cy77SpWt.js → p-Ctv4NAxk.js} +1 -1
  101. package/dist/components/p-CzjSdJio.js +1 -0
  102. package/dist/components/{p-XGgKC_Fe.js → p-DKgqzi2Y.js} +1 -1
  103. package/dist/components/{p-C4krHoUl.js → p-DLijNISu.js} +1 -1
  104. package/dist/components/p-DMJI6opm.js +1 -0
  105. package/dist/components/p-DOF5fWDU.js +1 -0
  106. package/dist/components/{p-4FEa4ADy.js → p-DV_h5Jo2.js} +1 -1
  107. package/dist/components/{p-DTezr6w9.js → p-DgCGSL2Q.js} +1 -1
  108. package/dist/components/p-DwJUC6cw.js +9 -0
  109. package/dist/components/p-FOxrXeq4.js +1 -0
  110. package/dist/components/p-S5GeUsJP.js +1 -0
  111. package/dist/components/{p-CXzfYQ_u.js → p-e1r5dgeP.js} +1 -1
  112. package/dist/components/p-pKbfOI5a.js +1 -0
  113. package/dist/components/{p-D5ZsALCP.js → p-wRXL928z.js} +1 -1
  114. package/dist/esm/{default-line-tool.config-Cw8mdDpt.js → default-line-tool.config-DLpNl6R9.js} +634 -110
  115. package/dist/esm/{index-BqhmuUH2.js → index-OLdaFN6W.js} +84 -7
  116. package/dist/esm/index.js +2 -2
  117. package/dist/esm/kritzel-brush-style.entry.js +1 -1
  118. package/dist/esm/{kritzel-color_22.entry.js → kritzel-color_24.entry.js} +821 -762
  119. package/dist/esm/loader.js +3 -3
  120. package/dist/esm/stencil.js +4 -4
  121. package/dist/stencil/index.esm.js +1 -1
  122. package/dist/stencil/p-361ebc7e.entry.js +9 -0
  123. package/dist/stencil/{p-09295079.entry.js → p-802bc7cf.entry.js} +1 -1
  124. package/dist/stencil/p-DLpNl6R9.js +1 -0
  125. package/dist/stencil/p-OLdaFN6W.js +2 -0
  126. package/dist/stencil/stencil.esm.js +1 -1
  127. package/dist/types/classes/objects/shape.class.d.ts +1 -0
  128. package/dist/types/classes/tools/brush-tool.class.d.ts +1 -0
  129. package/dist/types/classes/tools/line-tool.class.d.ts +2 -1
  130. package/dist/types/classes/tools/selection-tool.class.d.ts +22 -0
  131. package/dist/types/classes/tools/shape-tool.class.d.ts +1 -0
  132. package/dist/types/classes/tools/text-tool.class.d.ts +1 -0
  133. package/dist/types/components/core/kritzel-engine/kritzel-engine.d.ts +2 -0
  134. package/dist/types/components/shared/kritzel-color-palette/kritzel-color-palette.d.ts +1 -0
  135. package/dist/types/components/shared/kritzel-line-endings/kritzel-line-endings.d.ts +23 -0
  136. package/dist/types/components/shared/kritzel-opacity-slider/kritzel-opacity-slider.d.ts +17 -0
  137. package/dist/types/components/shared/kritzel-shape-fill/kritzel-shape-fill.d.ts +10 -0
  138. package/dist/types/components/ui/kritzel-controls/kritzel-controls.d.ts +9 -0
  139. package/dist/types/components/ui/kritzel-tool-config/kritzel-tool-config.d.ts +25 -0
  140. package/dist/types/components.d.ts +235 -82
  141. package/dist/types/constants/color-palette.constants.d.ts +5 -0
  142. package/dist/types/helpers/color.helper.d.ts +9 -0
  143. package/dist/types/helpers/tool-config.helper.d.ts +4 -0
  144. package/dist/types/interfaces/line-options.interface.d.ts +1 -0
  145. package/dist/types/interfaces/path-options.interface.d.ts +1 -0
  146. package/dist/types/interfaces/tool-config.interface.d.ts +26 -0
  147. package/dist/types/stencil-public-runtime.d.ts +29 -0
  148. package/package.json +5 -3
  149. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.css +0 -19
  150. package/dist/collection/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.js +0 -134
  151. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.css +0 -19
  152. package/dist/collection/components/ui/kritzel-control-text-config/kritzel-control-text-config.js +0 -114
  153. package/dist/components/kritzel-control-brush-config.d.ts +0 -11
  154. package/dist/components/kritzel-control-brush-config.js +0 -1
  155. package/dist/components/kritzel-control-text-config.d.ts +0 -11
  156. package/dist/components/kritzel-control-text-config.js +0 -1
  157. package/dist/components/p-BXaWhpO2.js +0 -1
  158. package/dist/components/p-BtuXeItZ.js +0 -1
  159. package/dist/components/p-C-d2IH4v.js +0 -1
  160. package/dist/components/p-C3UriJh7.js +0 -1
  161. package/dist/components/p-CF5L2Gdl.js +0 -1
  162. package/dist/components/p-CeKT_dTd.js +0 -1
  163. package/dist/components/p-Cp15toXH.js +0 -1
  164. package/dist/components/p-D4n7UbGY.js +0 -1
  165. package/dist/components/p-Du1vxHy8.js +0 -1
  166. package/dist/components/p-exWKDgI8.js +0 -9
  167. package/dist/stencil/p-BqhmuUH2.js +0 -2
  168. package/dist/stencil/p-Cw8mdDpt.js +0 -1
  169. package/dist/stencil/p-d21a009f.entry.js +0 -9
  170. package/dist/types/components/ui/kritzel-control-brush-config/kritzel-control-brush-config.d.ts +0 -15
  171. package/dist/types/components/ui/kritzel-control-text-config/kritzel-control-text-config.d.ts +0 -12
@@ -0,0 +1 @@
1
+ class t{static registry={};static registerTool(t,e,i){const s=new e(i);return s.name=t,this.registry[t]=s,s}static getTool(t){return this.registry[t]||(console.warn(`Unknown tool: ${t}`),null)}}class e{static generateUUID(){return Math.random().toString(36).substr(2,9)}static isEmpty(t){return null==t||0===Object?.keys(t).length&&t?.constructor===Object}}class i{static doPolygonsIntersect(t,e){const i=[t.bottomLeft,t.bottomRight,t.topRight,t.topLeft],s=[e.bottomLeft,e.bottomRight,e.topRight,e.topLeft];for(const t of i)if(this.isPointInPolygon(t,s))return!0;for(const t of s)if(this.isPointInPolygon(t,i))return!0;for(let t=0;t<i.length;t++){const e=i[t],n=i[(t+1)%i.length];for(let t=0;t<s.length;t++)if(this.intersectLines(e,n,s[t],s[(t+1)%s.length]))return!0}return!1}static isPointInPolygon(t,e){let i=!1;for(let s=0,n=e.length-1;s<e.length;n=s++){const r=e[s].x,h=e[s].y,o=e[n].y;h>t.y!=o>t.y&&t.x<(e[n].x-r)*(t.y-h)/(o-h)+r&&(i=!i)}return i}static intersectLines(t,e,i,s){const n=(e.x-t.x)*(s.y-i.y)-(e.y-t.y)*(s.x-i.x);if(0===n)return!1;const r=((i.x-t.x)*(s.y-i.y)-(i.y-t.y)*(s.x-i.x))/n,h=-((t.x-i.x)*(e.y-t.y)-(t.y-i.y)*(e.x-t.x))/n;return r>=0&&r<=1&&h>=0&&h<=1}static getLineIntersectionPoint(t,e,i,s){const n=(e.x-t.x)*(s.y-i.y)-(e.y-t.y)*(s.x-i.x);if(0===n)return null;const r=((i.x-t.x)*(s.y-i.y)-(i.y-t.y)*(s.x-i.x))/n,h=-((t.x-i.x)*(e.y-t.y)-(t.y-i.y)*(e.x-t.x))/n;return r>=0&&r<=1&&h>=0&&h<=1?{x:t.x+r*(e.x-t.x),y:t.y+r*(e.y-t.y)}:null}static getLinePolygonIntersection(t,e,i){const s=[i.topLeft,i.topRight,i.bottomRight,i.bottomLeft];let n=null,r=1/0;for(let i=0;i<s.length;i++){const h=this.getLineIntersectionPoint(t,e,s[i],s[(i+1)%s.length]);if(h){const e=Math.sqrt(Math.pow(h.x-t.x,2)+Math.pow(h.y-t.y,2));e<r&&(r=e,n=h)}}return n}static getEllipsePolygonApproximation(t,e,i,s,n=32,r=0){const h=[],o=Math.cos(r),l=Math.sin(r);for(let r=0;r<n;r++){const u=2*Math.PI*r/n,a=i*Math.cos(u),c=s*Math.sin(u);h.push({x:t+a*o-c*l,y:e+a*l+c*o})}return h}static getLinePointsArrayIntersection(t,e,i){let s=null,n=1/0;for(let r=0;r<i.length;r++){const h=this.getLineIntersectionPoint(t,e,i[r],i[(r+1)%i.length]);if(h){const e=Math.sqrt(Math.pow(h.x-t.x,2)+Math.pow(h.y-t.y,2));e<n&&(n=e,s=h)}}return s}static isPointInPolygonPoints(t,e){return this.isPointInPolygon(t,e)}}class s{__class__="KritzelBaseObject";_core;_elementRef;id;workspaceId;x;y;translateX;translateY;height;width;backgroundColor;borderColor;borderWidth=0;opacity=1;padding=0;scale;resizing=!1;rotation=0;markedForRemoval=!1;zIndex=0;isVisible=!0;isSelected=!1;isHovered=!1;isMounted=!1;isEditable=!1;isInteractive=!1;isDebugInfoVisible=!1;get totalWidth(){return this.width+2*this.padding}get totalHeight(){return this.height+2*this.padding}set elementRef(t){this._elementRef=t}get elementRef(){return this._elementRef}get boundingBox(){return{x:this.translateX,y:this.translateY,z:this.scale,width:this.totalWidth/this.scale,height:this.totalHeight/this.scale}}get rotatedBoundingBox(){return{x:this.minXRotated,y:this.minYRotated,z:this.scale,width:this.maxXRotated-this.minXRotated,height:this.maxYRotated-this.minYRotated}}get rotatedPolygon(){const t=this.translateX+this.totalWidth/2/this.scale,e=this.translateY+this.totalHeight/2/this.scale,i=this.rotation,s=this.totalWidth/this.scale,n=this.totalHeight/this.scale,r={topLeft:{x:this.translateX,y:this.translateY},topRight:{x:this.translateX+s,y:this.translateY},bottomRight:{x:this.translateX+s,y:this.translateY+n},bottomLeft:{x:this.translateX,y:this.translateY+n}};return Object.keys(r).reduce(((s,n)=>{const h=r[n],o=Math.cos(i)*(h.x-t)-Math.sin(i)*(h.y-e)+t,l=Math.sin(i)*(h.x-t)+Math.cos(i)*(h.y-e)+e;return s[n]={x:o,y:l},s}),{})}get minXRotated(){return Math.min(this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x)}get minYRotated(){return Math.min(this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y)}get maxXRotated(){return Math.max(this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x)}get maxYRotated(){return Math.max(this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y)}get transformationMatrix(){const t=1/this.scale;return`matrix(${t}, 0, 0, ${t}, ${this.translateX}, ${this.translateY})`}get rotationDegrees(){return this.rotation*(180/Math.PI)}get centerX(){return this.translateX+this.totalWidth/2/this.scale}get centerY(){return this.translateY+this.totalHeight/2/this.scale}constructor(){this.id=this.generateId()}static create(t){const e=new s;return e._core=t,e.zIndex=t.store.currentZIndex,e.workspaceId=t.store.state.activeWorkspace.id,e}mount(t){this.isMounted||(this.elementRef=t,this.isMounted=!0)}generateId(){return e.generateUUID()}isInViewport(){const t=this._core.store.state.scale;if(this.boundingBox.width*t*(this.boundingBox.height*t)<.5)return!1;const e=-this._core.store.state.translateX/this._core.store.state.scale,i=-this._core.store.state.translateY/this._core.store.state.scale;return this.rotatedBoundingBox.x<e+this._core.store.state.viewportWidth/this._core.store.state.scale&&this.rotatedBoundingBox.x+this.rotatedBoundingBox.width>e&&this.rotatedBoundingBox.y<i+this._core.store.state.viewportHeight/this._core.store.state.scale&&this.rotatedBoundingBox.y+this.rotatedBoundingBox.height>i}centerInViewport(){const{viewportWidth:t,viewportHeight:e,translateX:i,translateY:s,scale:n}=this._core.store.state,{x:r,y:h,width:o,height:l}=this.rotatedBoundingBox;this.updatePosition(this.translateX+((t/2-i)/n-(r+o/2)),this.translateY+((e/2-s)/n-(h+l/2)))}update(){this._core.store.state.objects.update(this)}move(t,e,i,s){const n=(e-s)/this._core.store.state.scale;this.translateX+=(t-i)/this._core.store.state.scale,this.translateY+=n,this._core.store.state.objects.update(this)}resize(t,e,i,s){i<=1||s<=1||(this.width=i,this.height=s,this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this),this._core.anchorManager.updateAnchorsForObject(this.id))}rotate(t){this.rotation=t,this._core.store.state.objects.update(this)}clone(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.id,t}copy(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.generateId(),t.isMounted=!1,t}serialize(){const{_core:t,_elementRef:e,element:i,totalWidth:s,totalHeight:n,...r}=this,h=structuredClone(r);return i&&"object"==typeof i&&"nodeType"in i&&1===i.nodeType&&(h.element=i.cloneNode(!0)),h}deserialize(t){return Object.assign(this,t),this}isClass(t){return this.__class__===t}edit(t){}hitTest(t,e){return!0}hitTestPolygon(t){return i.doPolygonsIntersect(this.rotatedPolygon,t)}updatePosition(t,e){this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this)}}class n{static forceHideKeyboard(){document.activeElement instanceof HTMLElement&&document.activeElement.blur()}static enableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let e=t.getAttribute("content");e.includes("interactive-widget=resizes-content")||(e+=", interactive-widget=resizes-content"),t.setAttribute("content",e)}}static disableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let e=t.getAttribute("content").replace(/\s*interactive-widget=resizes-content\s*[,;]?/g,"");e=e.replace(/,(\s*,)+/g,",").replace(/^,/,"").replace(/,$/,"").trim(),t.setAttribute("content",e)}}static onKeyboardVisibleChanged(t){if("visualViewport"in window){const e=.75,i=i=>{const s=i.target,n=s.height*s.scale/window.screen.height<e;t(n)};return window.visualViewport.addEventListener("resize",i),()=>window.visualViewport.removeEventListener("resize",i)}return console.warn("Listening for keyboard visibility changes is not reliably supported in this browser."),()=>{}}}class r{static isTouchDevice(){return window.matchMedia("(any-pointer: coarse)").matches}static isAndroid(){return/android/i.test(navigator.userAgent)}static isIOS(){return/iPad|iPhone|iPod/.test(navigator.userAgent)}static detectOS(){return this.isIOS()?"iOS":this.isAndroid()?"Android":"Other"}static isFirefox(){return/firefox/i.test(navigator.userAgent)}}function h(t){this.content=t}function o(t,e,i){for(let s=0;;s++){if(s==t.childCount||s==e.childCount)return t.childCount==e.childCount?null:i;let n=t.child(s),r=e.child(s);if(n!=r){if(!n.sameMarkup(r))return i;if(n.isText&&n.text!=r.text){for(let t=0;n.text[t]==r.text[t];t++)i++;return i}if(n.content.size||r.content.size){let t=o(n.content,r.content,i+1);if(null!=t)return t}i+=n.nodeSize}else i+=n.nodeSize}}function l(t,e,i,s){for(let n=t.childCount,r=e.childCount;;){if(0==n||0==r)return n==r?null:{a:i,b:s};let h=t.child(--n),o=e.child(--r),u=h.nodeSize;if(h!=o){if(!h.sameMarkup(o))return{a:i,b:s};if(h.isText&&h.text!=o.text){let t=0,e=Math.min(h.text.length,o.text.length);for(;t<e&&h.text[h.text.length-t-1]==o.text[o.text.length-t-1];)t++,i--,s--;return{a:i,b:s}}if(h.content.size||o.content.size){let t=l(h.content,o.content,i-1,s-1);if(t)return t}i-=u,s-=u}else i-=u,s-=u}}h.prototype={constructor:h,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return-1==e?void 0:this.content[e+1]},update:function(t,e,i){var s=i&&i!=t?this.remove(i):this,n=s.find(t),r=s.content.slice();return-1==n?r.push(i||t,e):(r[n+1]=e,i&&(r[n]=i)),new h(r)},remove:function(t){var e=this.find(t);if(-1==e)return this;var i=this.content.slice();return i.splice(e,2),new h(i)},addToStart:function(t,e){return new h([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var i=this.remove(t).content.slice();return i.push(t,e),new h(i)},addBefore:function(t,e,i){var s=this.remove(e),n=s.content.slice(),r=s.find(t);return n.splice(-1==r?n.length:r,0,e,i),new h(n)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){return(t=h.from(t)).size?new h(t.content.concat(this.subtract(t).content)):this},append:function(t){return(t=h.from(t)).size?new h(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=h.from(t);for(var i=0;i<t.content.length;i+=2)e=e.remove(t.content[i]);return e},toObject:function(){var t={};return this.forEach((function(e,i){t[e]=i})),t},get size(){return this.content.length>>1}},h.from=function(t){if(t instanceof h)return t;var e=[];if(t)for(var i in t)e.push(i,t[i]);return new h(e)};class u{constructor(t,e){if(this.content=t,this.size=e||0,null==e)for(let e=0;e<t.length;e++)this.size+=t[e].nodeSize}nodesBetween(t,e,i,s=0,n){for(let r=0,h=0;h<e;r++){let o=this.content[r],l=h+o.nodeSize;if(l>t&&!1!==i(o,s+h,n||null,r)&&o.content.size){let n=h+1;o.nodesBetween(Math.max(0,t-n),Math.min(o.content.size,e-n),i,s+n)}h=l}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,e,i,s){let n="",r=!0;return this.nodesBetween(t,e,((h,o)=>{let l=h.isText?h.text.slice(Math.max(t,o)-o,e-o):h.isLeaf?s?"function"==typeof s?s(h):s:h.type.spec.leafText?h.type.spec.leafText(h):"":"";h.isBlock&&(h.isLeaf&&l||h.isTextblock)&&i&&(r?r=!1:n+=i),n+=l}),0),n}append(t){if(!t.size)return this;if(!this.size)return t;let e=this.lastChild,i=t.firstChild,s=this.content.slice(),n=0;for(e.isText&&e.sameMarkup(i)&&(s[s.length-1]=e.withText(e.text+i.text),n=1);n<t.content.length;n++)s.push(t.content[n]);return new u(s,this.size+t.size)}cut(t,e=this.size){if(0==t&&e==this.size)return this;let i=[],s=0;if(e>t)for(let n=0,r=0;r<e;n++){let h=this.content[n],o=r+h.nodeSize;o>t&&((r<t||o>e)&&(h=h.isText?h.cut(Math.max(0,t-r),Math.min(h.text.length,e-r)):h.cut(Math.max(0,t-r-1),Math.min(h.content.size,e-r-1))),i.push(h),s+=h.nodeSize),r=o}return new u(i,s)}cutByIndex(t,e){return t==e?u.empty:0==t&&e==this.content.length?this:new u(this.content.slice(t,e))}replaceChild(t,e){let i=this.content[t];if(i==e)return this;let s=this.content.slice(),n=this.size+e.nodeSize-i.nodeSize;return s[t]=e,new u(s,n)}addToStart(t){return new u([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new u(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let e=0;e<this.content.length;e++)if(!this.content[e].eq(t.content[e]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(t){let e=this.content[t];if(!e)throw new RangeError("Index "+t+" out of range for "+this);return e}maybeChild(t){return this.content[t]||null}forEach(t){for(let e=0,i=0;e<this.content.length;e++){let s=this.content[e];t(s,i,e),i+=s.nodeSize}}findDiffStart(t,e=0){return o(this,t,e)}findDiffEnd(t,e=this.size,i=t.size){return l(this,t,e,i)}findIndex(t){if(0==t)return c(0,t);if(t==this.size)return c(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let e=0,i=0;;e++){let s=i+this.child(e).nodeSize;if(s>=t)return s==t?c(e+1,s):c(e,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map((t=>t.toJSON())):null}static fromJSON(t,e){if(!e)return u.empty;if(!Array.isArray(e))throw new RangeError("Invalid input for Fragment.fromJSON");return new u(e.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return u.empty;let e,i=0;for(let s=0;s<t.length;s++){let n=t[s];i+=n.nodeSize,s&&n.isText&&t[s-1].sameMarkup(n)?(e||(e=t.slice(0,s)),e[e.length-1]=n.withText(e[e.length-1].text+n.text)):e&&e.push(n)}return new u(e||t,i)}static from(t){if(!t)return u.empty;if(t instanceof u)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new u([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}u.empty=new u([],0);const a={index:0,offset:0};function c(t,e){return a.index=t,a.offset=e,a}function f(t,e){if(t===e)return!0;if(!t||"object"!=typeof t||!e||"object"!=typeof e)return!1;let i=Array.isArray(t);if(Array.isArray(e)!=i)return!1;if(i){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!f(t[i],e[i]))return!1}else{for(let i in t)if(!(i in e)||!f(t[i],e[i]))return!1;for(let i in e)if(!(i in t))return!1}return!0}class d{constructor(t,e){this.type=t,this.attrs=e}addToSet(t){let e,i=!1;for(let s=0;s<t.length;s++){let n=t[s];if(this.eq(n))return t;if(this.type.excludes(n.type))e||(e=t.slice(0,s));else{if(n.type.excludes(this.type))return t;!i&&n.type.rank>this.type.rank&&(e||(e=t.slice(0,s)),e.push(this),i=!0),e&&e.push(n)}}return e||(e=t.slice()),i||e.push(this),e}removeFromSet(t){for(let e=0;e<t.length;e++)if(this.eq(t[e]))return t.slice(0,e).concat(t.slice(e+1));return t}isInSet(t){for(let e=0;e<t.length;e++)if(this.eq(t[e]))return!0;return!1}eq(t){return this==t||this.type==t.type&&f(this.attrs,t.attrs)}toJSON(){let t={type:this.type.name};for(let e in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Mark.fromJSON");let i=t.marks[e.type];if(!i)throw new RangeError(`There is no mark type ${e.type} in this schema`);let s=i.create(e.attrs);return i.checkAttrs(s.attrs),s}static sameSet(t,e){if(t==e)return!0;if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].eq(e[i]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&0==t.length)return d.none;if(t instanceof d)return[t];let e=t.slice();return e.sort(((t,e)=>t.type.rank-e.type.rank)),e}}d.none=[];class p extends Error{}class w{constructor(t,e,i){this.content=t,this.openStart=e,this.openEnd=i}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,e){let i=m(this.content,t+this.openStart,e);return i&&new w(i,this.openStart,this.openEnd)}removeBetween(t,e){return new w(g(this.content,t+this.openStart,e+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,e){if(!e)return w.empty;let i=e.openStart||0,s=e.openEnd||0;if("number"!=typeof i||"number"!=typeof s)throw new RangeError("Invalid input for Slice.fromJSON");return new w(u.fromJSON(t,e.content),i,s)}static maxOpen(t,e=!0){let i=0,s=0;for(let s=t.firstChild;s&&!s.isLeaf&&(e||!s.type.spec.isolating);s=s.firstChild)i++;for(let i=t.lastChild;i&&!i.isLeaf&&(e||!i.type.spec.isolating);i=i.lastChild)s++;return new w(t,i,s)}}function g(t,e,i){let{index:s,offset:n}=t.findIndex(e),r=t.maybeChild(s),{index:h,offset:o}=t.findIndex(i);if(n==e||r.isText){if(o!=i&&!t.child(h).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(i))}if(s!=h)throw new RangeError("Removing non-flat range");return t.replaceChild(s,r.copy(g(r.content,e-n-1,i-n-1)))}function m(t,e,i,s){let{index:n,offset:r}=t.findIndex(e),h=t.maybeChild(n);if(r==e||h.isText)return s&&!s.canReplace(n,n,i)?null:t.cut(0,e).append(i).append(t.cut(e));let o=m(h.content,e-r-1,i,h);return o&&t.replaceChild(n,h.copy(o))}function y(t,e,i){if(i.openStart>t.depth)throw new p("Inserted content deeper than insertion position");if(t.depth-i.openStart!=e.depth-i.openEnd)throw new p("Inconsistent open depths");return v(t,e,i,0)}function v(t,e,i,s){let n=t.index(s),r=t.node(s);if(n==e.index(s)&&s<t.depth-i.openStart){let h=v(t,e,i,s+1);return r.copy(r.content.replaceChild(n,h))}if(i.content.size){if(i.openStart||i.openEnd||t.depth!=s||e.depth!=s){let{start:n,end:h}=function(t,e){let i=e.depth-t.openStart,s=e.node(i).copy(t.content);for(let t=i-1;t>=0;t--)s=e.node(t).copy(u.from(s));return{start:s.resolveNoCache(t.openStart+i),end:s.resolveNoCache(s.content.size-t.openEnd-i)}}(i,t);return x(r,S(t,n,h,e,s))}{let s=t.parent,n=s.content;return x(s,n.cut(0,t.parentOffset).append(i.content).append(n.cut(e.parentOffset)))}}return x(r,C(t,e,s))}function b(t,e){if(!e.type.compatibleContent(t.type))throw new p("Cannot join "+e.type.name+" onto "+t.type.name)}function M(t,e,i){let s=t.node(i);return b(s,e.node(i)),s}function k(t,e){let i=e.length-1;i>=0&&t.isText&&t.sameMarkup(e[i])?e[i]=t.withText(e[i].text+t.text):e.push(t)}function A(t,e,i,s){let n=(e||t).node(i),r=0,h=e?e.index(i):n.childCount;t&&(r=t.index(i),t.depth>i?r++:t.textOffset&&(k(t.nodeAfter,s),r++));for(let t=r;t<h;t++)k(n.child(t),s);e&&e.depth==i&&e.textOffset&&k(e.nodeBefore,s)}function x(t,e){return t.type.checkContent(e),t.copy(e)}function S(t,e,i,s,n){let r=t.depth>n&&M(t,e,n+1),h=s.depth>n&&M(i,s,n+1),o=[];return A(null,t,n,o),r&&h&&e.index(n)==i.index(n)?(b(r,h),k(x(r,S(t,e,i,s,n+1)),o)):(r&&k(x(r,C(t,e,n+1)),o),A(e,i,n,o),h&&k(x(h,C(i,s,n+1)),o)),A(s,null,n,o),new u(o)}function C(t,e,i){let s=[];return A(null,t,i,s),t.depth>i&&k(x(M(t,e,i+1),C(t,e,i+1)),s),A(e,null,i,s),new u(s)}w.empty=new w(u.empty,0,0);class O{constructor(t,e,i){this.pos=t,this.path=e,this.parentOffset=i,this.depth=e.length/3-1}resolveDepth(t){return null==t?this.depth:t<0?this.depth+t:t}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(t){return this.path[3*this.resolveDepth(t)]}index(t){return this.path[3*this.resolveDepth(t)+1]}indexAfter(t){return t=this.resolveDepth(t),this.index(t)+(t!=this.depth||this.textOffset?1:0)}start(t){return 0==(t=this.resolveDepth(t))?0:this.path[3*t-1]+1}end(t){return t=this.resolveDepth(t),this.start(t)+this.node(t).content.size}before(t){if(!(t=this.resolveDepth(t)))throw new RangeError("There is no position before the top-level node");return t==this.depth+1?this.pos:this.path[3*t-1]}after(t){if(!(t=this.resolveDepth(t)))throw new RangeError("There is no position after the top-level node");return t==this.depth+1?this.pos:this.path[3*t-1]+this.path[3*t].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let t=this.parent,e=this.index(this.depth);if(e==t.childCount)return null;let i=this.pos-this.path[this.path.length-1],s=t.child(e);return i?t.child(e).cut(i):s}get nodeBefore(){let t=this.index(this.depth),e=this.pos-this.path[this.path.length-1];return e?this.parent.child(t).cut(0,e):0==t?null:this.parent.child(t-1)}posAtIndex(t,e){e=this.resolveDepth(e);let i=this.path[3*e],s=0==e?0:this.path[3*e-1]+1;for(let e=0;e<t;e++)s+=i.child(e).nodeSize;return s}marks(){let t=this.parent,e=this.index();if(0==t.content.size)return d.none;if(this.textOffset)return t.child(e).marks;let i=t.maybeChild(e-1),s=t.maybeChild(e);if(!i){let t=i;i=s,s=t}let n=i.marks;for(var r=0;r<n.length;r++)!1!==n[r].type.spec.inclusive||s&&n[r].isInSet(s.marks)||(n=n[r--].removeFromSet(n));return n}marksAcross(t){let e=this.parent.maybeChild(this.index());if(!e||!e.isInline)return null;let i=e.marks,s=t.parent.maybeChild(t.index());for(var n=0;n<i.length;n++)!1!==i[n].type.spec.inclusive||s&&i[n].isInSet(s.marks)||(i=i[n--].removeFromSet(i));return i}sharedDepth(t){for(let e=this.depth;e>0;e--)if(this.start(e)<=t&&this.end(e)>=t)return e;return 0}blockRange(t=this,e){if(t.pos<this.pos)return t.blockRange(this);for(let i=this.depth-(this.parent.inlineContent||this.pos==t.pos?1:0);i>=0;i--)if(t.pos<=this.end(i)&&(!e||e(this.node(i))))return new $(this,t,i);return null}sameParent(t){return this.pos-this.parentOffset==t.pos-t.parentOffset}max(t){return t.pos>this.pos?t:this}min(t){return t.pos<this.pos?t:this}toString(){let t="";for(let e=1;e<=this.depth;e++)t+=(t?"/":"")+this.node(e).type.name+"_"+this.index(e-1);return t+":"+this.parentOffset}static resolve(t,e){if(!(e>=0&&e<=t.content.size))throw new RangeError("Position "+e+" out of range");let i=[],s=0,n=e;for(let e=t;;){let{index:t,offset:r}=e.content.findIndex(n),h=n-r;if(i.push(e,t,s+r),!h)break;if(e=e.child(t),e.isText)break;n=h-1,s+=r+1}return new O(e,i,n)}static resolveCached(t,e){let i=D.get(t);if(i)for(let t=0;t<i.elts.length;t++){let s=i.elts[t];if(s.pos==e)return s}else D.set(t,i=new E);let s=i.elts[i.i]=O.resolve(t,e);return i.i=(i.i+1)%T,s}}class E{constructor(){this.elts=[],this.i=0}}const T=12,D=new WeakMap;class ${constructor(t,e,i){this.$from=t,this.$to=e,this.depth=i}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const P=Object.create(null);class R{constructor(t,e,i,s=d.none){this.type=t,this.attrs=e,this.marks=s,this.content=i||u.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(t){return this.content.child(t)}maybeChild(t){return this.content.maybeChild(t)}forEach(t){this.content.forEach(t)}nodesBetween(t,e,i,s=0){this.content.nodesBetween(t,e,i,s,this)}descendants(t){this.nodesBetween(0,this.content.size,t)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(t,e,i,s){return this.content.textBetween(t,e,i,s)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(t){return this==t||this.sameMarkup(t)&&this.content.eq(t.content)}sameMarkup(t){return this.hasMarkup(t.type,t.attrs,t.marks)}hasMarkup(t,e,i){return this.type==t&&f(this.attrs,e||t.defaultAttrs||P)&&d.sameSet(this.marks,i||d.none)}copy(t=null){return t==this.content?this:new R(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new R(this.type,this.attrs,this.content,t)}cut(t,e=this.content.size){return 0==t&&e==this.content.size?this:this.copy(this.content.cut(t,e))}slice(t,e=this.content.size,i=!1){if(t==e)return w.empty;let s=this.resolve(t),n=this.resolve(e),r=i?0:s.sharedDepth(e),h=s.start(r),o=s.node(r).content.cut(s.pos-h,n.pos-h);return new w(o,s.depth-r,n.depth-r)}replace(t,e,i){return y(this.resolve(t),this.resolve(e),i)}nodeAt(t){for(let e=this;;){let{index:i,offset:s}=e.content.findIndex(t);if(e=e.maybeChild(i),!e)return null;if(s==t||e.isText)return e;t-=s+1}}childAfter(t){let{index:e,offset:i}=this.content.findIndex(t);return{node:this.content.maybeChild(e),index:e,offset:i}}childBefore(t){if(0==t)return{node:null,index:0,offset:0};let{index:e,offset:i}=this.content.findIndex(t);if(i<t)return{node:this.content.child(e),index:e,offset:i};let s=this.content.child(e-1);return{node:s,index:e-1,offset:i-s.nodeSize}}resolve(t){return O.resolveCached(this,t)}resolveNoCache(t){return O.resolve(this,t)}rangeHasMark(t,e,i){let s=!1;return e>t&&this.nodesBetween(t,e,(t=>(i.isInSet(t.marks)&&(s=!0),!s))),s}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let t=this.type.name;return this.content.size&&(t+="("+this.content.toStringInner()+")"),U(this.marks,t)}contentMatchAt(t){let e=this.type.contentMatch.matchFragment(this.content,0,t);if(!e)throw new Error("Called contentMatchAt on a node with invalid content");return e}canReplace(t,e,i=u.empty,s=0,n=i.childCount){let r=this.contentMatchAt(t).matchFragment(i,s,n),h=r&&r.matchFragment(this.content,e);if(!h||!h.validEnd)return!1;for(let t=s;t<n;t++)if(!this.type.allowsMarks(i.child(t).marks))return!1;return!0}canReplaceWith(t,e,i,s){if(s&&!this.type.allowsMarks(s))return!1;let n=this.contentMatchAt(t).matchType(i),r=n&&n.matchFragment(this.content,e);return!!r&&r.validEnd}canAppend(t){return t.content.size?this.canReplace(this.childCount,this.childCount,t.content):this.type.compatibleContent(t.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let t=d.none;for(let e=0;e<this.marks.length;e++){let i=this.marks[e];i.type.checkAttrs(i.attrs),t=i.addToSet(t)}if(!d.sameSet(t,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((t=>t.type.name))}`);this.content.forEach((t=>t.check()))}toJSON(){let t={type:this.type.name};for(let e in this.attrs){t.attrs=this.attrs;break}return this.content.size&&(t.content=this.content.toJSON()),this.marks.length&&(t.marks=this.marks.map((t=>t.toJSON()))),t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Node.fromJSON");let i;if(e.marks){if(!Array.isArray(e.marks))throw new RangeError("Invalid mark data for Node.fromJSON");i=e.marks.map(t.markFromJSON)}if("text"==e.type){if("string"!=typeof e.text)throw new RangeError("Invalid text node in JSON");return t.text(e.text,i)}let s=u.fromJSON(t,e.content),n=t.nodeType(e.type).create(e.attrs,s,i);return n.type.checkAttrs(n.attrs),n}}R.prototype.text=void 0;class I extends R{constructor(t,e,i,s){if(super(t,e,null,s),!i)throw new RangeError("Empty text nodes are not allowed");this.text=i}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):U(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(t,e){return this.text.slice(t,e)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new I(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new I(this.type,this.attrs,t,this.marks)}cut(t=0,e=this.text.length){return 0==t&&e==this.text.length?this:this.withText(this.text.slice(t,e))}eq(t){return this.sameMarkup(t)&&this.text==t.text}toJSON(){let t=super.toJSON();return t.text=this.text,t}}function U(t,e){for(let i=t.length-1;i>=0;i--)e=t[i].type.name+"("+e+")";return e}class j{constructor(t){this.validEnd=t,this.next=[],this.wrapCache=[]}static parse(t,e){let i=new B(t,e);if(null==i.next)return j.empty;let s=N(i);i.next&&i.err("Unexpected trailing text");let n=function(t){let e=Object.create(null);return function i(s){let n=[];s.forEach((e=>{t[e].forEach((({term:e,to:i})=>{if(!e)return;let s;for(let t=0;t<n.length;t++)n[t][0]==e&&(s=n[t][1]);W(t,i).forEach((t=>{s||n.push([e,s=[]]),-1==s.indexOf(t)&&s.push(t)}))}))}));let r=e[s.join(",")]=new j(s.indexOf(t.length-1)>-1);for(let t=0;t<n.length;t++){let s=n[t][1].sort(Y);r.next.push({type:n[t][0],next:e[s.join(",")]||i(s)})}return r}(W(t,0))}(function(t){let e=[[]];return n(function t(e,r){if("choice"==e.type)return e.exprs.reduce(((e,i)=>e.concat(t(i,r))),[]);if("seq"!=e.type){if("star"==e.type){let h=i();return s(r,h),n(t(e.expr,h),h),[s(h)]}if("plus"==e.type){let h=i();return n(t(e.expr,r),h),n(t(e.expr,h),h),[s(h)]}if("opt"==e.type)return[s(r)].concat(t(e.expr,r));if("range"==e.type){let h=r;for(let s=0;s<e.min;s++){let s=i();n(t(e.expr,h),s),h=s}if(-1==e.max)n(t(e.expr,h),h);else for(let r=e.min;r<e.max;r++){let r=i();s(h,r),n(t(e.expr,h),r),h=r}return[s(h)]}if("name"==e.type)return[s(r,void 0,e.value)];throw new Error("Unknown expr type")}for(let s=0;;s++){let h=t(e.exprs[s],r);if(s==e.exprs.length-1)return h;n(h,r=i())}}(t,0),i()),e;function i(){return e.push([])-1}function s(t,i,s){let n={term:s,to:i};return e[t].push(n),n}function n(t,e){t.forEach((t=>t.to=e))}}(s));return function(t,e){for(let i=0,s=[t];i<s.length;i++){let t=s[i],n=!t.validEnd,r=[];for(let e=0;e<t.next.length;e++){let{type:i,next:h}=t.next[e];r.push(i.name),!n||i.isText||i.hasRequiredAttrs()||(n=!1),-1==s.indexOf(h)&&s.push(h)}n&&e.err("Only non-generatable nodes ("+r.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(n,i),n}matchType(t){for(let e=0;e<this.next.length;e++)if(this.next[e].type==t)return this.next[e].next;return null}matchFragment(t,e=0,i=t.childCount){let s=this;for(let n=e;s&&n<i;n++)s=s.matchType(t.child(n).type);return s}get inlineContent(){return 0!=this.next.length&&this.next[0].type.isInline}get defaultType(){for(let t=0;t<this.next.length;t++){let{type:e}=this.next[t];if(!e.isText&&!e.hasRequiredAttrs())return e}return null}compatible(t){for(let e=0;e<this.next.length;e++)for(let i=0;i<t.next.length;i++)if(this.next[e].type==t.next[i].type)return!0;return!1}fillBefore(t,e=!1,i=0){let s=[this];return function n(r,h){let o=r.matchFragment(t,i);if(o&&(!e||o.validEnd))return u.from(h.map((t=>t.createAndFill())));for(let t=0;t<r.next.length;t++){let{type:e,next:i}=r.next[t];if(!e.isText&&!e.hasRequiredAttrs()&&-1==s.indexOf(i)){s.push(i);let t=n(i,h.concat(e));if(t)return t}}return null}(this,[])}findWrapping(t){for(let e=0;e<this.wrapCache.length;e+=2)if(this.wrapCache[e]==t)return this.wrapCache[e+1];let e=this.computeWrapping(t);return this.wrapCache.push(t,e),e}computeWrapping(t){let e=Object.create(null),i=[{match:this,type:null,via:null}];for(;i.length;){let s=i.shift(),n=s.match;if(n.matchType(t)){let t=[];for(let e=s;e.type;e=e.via)t.push(e.type);return t.reverse()}for(let t=0;t<n.next.length;t++){let{type:r,next:h}=n.next[t];r.isLeaf||r.hasRequiredAttrs()||r.name in e||s.type&&!h.validEnd||(i.push({match:r.contentMatch,type:r,via:s}),e[r.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(t){if(t>=this.next.length)throw new RangeError(`There's no ${t}th edge in this content match`);return this.next[t]}toString(){let t=[];return function e(i){t.push(i);for(let s=0;s<i.next.length;s++)-1==t.indexOf(i.next[s].next)&&e(i.next[s].next)}(this),t.map(((e,i)=>{let s=i+(e.validEnd?"*":" ")+" ";for(let i=0;i<e.next.length;i++)s+=(i?", ":"")+e.next[i].type.name+"->"+t.indexOf(e.next[i].next);return s})).join("\n")}}j.empty=new j(!0);class B{constructor(t,e){this.string=t,this.nodeTypes=e,this.inline=null,this.pos=0,this.tokens=t.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(t){return this.next==t&&(this.pos++||!0)}err(t){throw new SyntaxError(t+" (in content expression '"+this.string+"')")}}function N(t){let e=[];do{e.push(F(t))}while(t.eat("|"));return 1==e.length?e[0]:{type:"choice",exprs:e}}function F(t){let e=[];do{e.push(_(t))}while(t.next&&")"!=t.next&&"|"!=t.next);return 1==e.length?e[0]:{type:"seq",exprs:e}}function _(t){let e=function(t){if(t.eat("(")){let e=N(t);return t.eat(")")||t.err("Missing closing paren"),e}if(!/\W/.test(t.next)){let e=function(t,e){let i=t.nodeTypes,s=i[e];if(s)return[s];let n=[];for(let t in i){let s=i[t];s.isInGroup(e)&&n.push(s)}return 0==n.length&&t.err("No node type or group '"+e+"' found"),n}(t,t.next).map((e=>(null==t.inline?t.inline=e.isInline:t.inline!=e.isInline&&t.err("Mixing inline and block content"),{type:"name",value:e})));return t.pos++,1==e.length?e[0]:{type:"choice",exprs:e}}t.err("Unexpected token '"+t.next+"'")}(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else{if(!t.eat("{"))break;e=z(t,e)}return e}function L(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function z(t,e){let i=L(t),s=i;return t.eat(",")&&(s="}"!=t.next?L(t):-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:i,max:s,expr:e}}function Y(t,e){return e-t}function W(t,e){let i=[];return function e(s){let n=t[s];if(1==n.length&&!n[0].term)return e(n[0].to);i.push(s);for(let t=0;t<n.length;t++){let{term:s,to:r}=n[t];s||-1!=i.indexOf(r)||e(r)}}(e),i.sort(Y)}function X(t){let e=Object.create(null);for(let i in t){let s=t[i];if(!s.hasDefault)return null;e[i]=s.default}return e}function J(t,e){let i=Object.create(null);for(let s in t){let n=e&&e[s];if(void 0===n){let e=t[s];if(!e.hasDefault)throw new RangeError("No value supplied for attribute "+s);n=e.default}i[s]=n}return i}function H(t,e,i){for(let s in e)if(!(s in t))throw new RangeError(`Unsupported attribute ${s} for ${i} of type ${s}`);for(let i in t){let s=t[i];s.validate&&s.validate(e[i])}}function V(t,e){let i=Object.create(null);if(e)for(let s in e)i[s]=new K(t,s,e[s]);return i}let Q=class t{constructor(t,e,i){this.name=t,this.schema=e,this.spec=i,this.markSet=null,this.groups=i.group?i.group.split(" "):[],this.attrs=V(t,i.attrs),this.defaultAttrs=X(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(i.inline||"text"==t),this.isText="text"==t}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==j.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(t){return this.groups.indexOf(t)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let t in this.attrs)if(this.attrs[t].isRequired)return!0;return!1}compatibleContent(t){return this==t||this.contentMatch.compatible(t.contentMatch)}computeAttrs(t){return!t&&this.defaultAttrs?this.defaultAttrs:J(this.attrs,t)}create(t=null,e,i){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new R(this,this.computeAttrs(t),u.from(e),d.setFrom(i))}createChecked(t=null,e,i){return e=u.from(e),this.checkContent(e),new R(this,this.computeAttrs(t),e,d.setFrom(i))}createAndFill(t=null,e,i){if(t=this.computeAttrs(t),(e=u.from(e)).size){let t=this.contentMatch.fillBefore(e);if(!t)return null;e=t.append(e)}let s=this.contentMatch.matchFragment(e),n=s&&s.fillBefore(u.empty,!0);return n?new R(this,t,e.append(n),d.setFrom(i)):null}validContent(t){let e=this.contentMatch.matchFragment(t);if(!e||!e.validEnd)return!1;for(let e=0;e<t.childCount;e++)if(!this.allowsMarks(t.child(e).marks))return!1;return!0}checkContent(t){if(!this.validContent(t))throw new RangeError(`Invalid content for node ${this.name}: ${t.toString().slice(0,50)}`)}checkAttrs(t){H(this.attrs,t,"node")}allowsMarkType(t){return null==this.markSet||this.markSet.indexOf(t)>-1}allowsMarks(t){if(null==this.markSet)return!0;for(let e=0;e<t.length;e++)if(!this.allowsMarkType(t[e].type))return!1;return!0}allowedMarks(t){if(null==this.markSet)return t;let e;for(let i=0;i<t.length;i++)this.allowsMarkType(t[i].type)?e&&e.push(t[i]):e||(e=t.slice(0,i));return e?e.length?e:d.none:t}static compile(e,i){let s=Object.create(null);e.forEach(((e,n)=>s[e]=new t(e,i,n)));let n=i.spec.topNode||"doc";if(!s[n])throw new RangeError("Schema is missing its top node type ('"+n+"')");if(!s.text)throw new RangeError("Every schema needs a 'text' type");for(let t in s.text.attrs)throw new RangeError("The text node type should not have attributes");return s}};class K{constructor(t,e,i){this.hasDefault=Object.prototype.hasOwnProperty.call(i,"default"),this.default=i.default,this.validate="string"==typeof i.validate?function(t,e,i){let s=i.split("|");return i=>{let n=null===i?"null":typeof i;if(s.indexOf(n)<0)throw new RangeError(`Expected value of type ${s} for attribute ${e} on type ${t}, got ${n}`)}}(t,e,i.validate):i.validate}get isRequired(){return!this.hasDefault}}class q{constructor(t,e,i,s){this.name=t,this.rank=e,this.schema=i,this.spec=s,this.attrs=V(t,s.attrs),this.excluded=null;let n=X(this.attrs);this.instance=n?new d(this,n):null}create(t=null){return!t&&this.instance?this.instance:new d(this,J(this.attrs,t))}static compile(t,e){let i=Object.create(null),s=0;return t.forEach(((t,n)=>i[t]=new q(t,s++,e,n))),i}removeFromSet(t){for(var e=0;e<t.length;e++)t[e].type==this&&(t=t.slice(0,e).concat(t.slice(e+1)),e--);return t}isInSet(t){for(let e=0;e<t.length;e++)if(t[e].type==this)return t[e]}checkAttrs(t){H(this.attrs,t,"mark")}excludes(t){return this.excluded.indexOf(t)>-1}}let G=class{constructor(t){this.linebreakReplacement=null,this.cached=Object.create(null);let e=this.spec={};for(let i in t)e[i]=t[i];e.nodes=h.from(t.nodes),e.marks=h.from(t.marks||{}),this.nodes=Q.compile(this.spec.nodes,this),this.marks=q.compile(this.spec.marks,this);let i=Object.create(null);for(let t in this.nodes){if(t in this.marks)throw new RangeError(t+" can not be both a node and a mark");let e=this.nodes[t],s=e.spec.content||"",n=e.spec.marks;if(e.contentMatch=i[s]||(i[s]=j.parse(s,this.nodes)),e.inlineContent=e.contentMatch.inlineContent,e.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!e.isInline||!e.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=e}e.markSet="_"==n?null:n?Z(this,n.split(" ")):""!=n&&e.inlineContent?null:[]}for(let t in this.marks){let e=this.marks[t],i=e.spec.excludes;e.excluded=null==i?[e]:""==i?[]:Z(this,i.split(" "))}this.nodeFromJSON=t=>R.fromJSON(this,t),this.markFromJSON=t=>d.fromJSON(this,t),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(t,e=null,i,s){if("string"==typeof t)t=this.nodeType(t);else{if(!(t instanceof Q))throw new RangeError("Invalid node type: "+t);if(t.schema!=this)throw new RangeError("Node type from different schema used ("+t.name+")")}return t.createChecked(e,i,s)}text(t,e){let i=this.nodes.text;return new I(i,i.defaultAttrs,t,d.setFrom(e))}mark(t,e){return"string"==typeof t&&(t=this.marks[t]),t.create(e)}nodeType(t){let e=this.nodes[t];if(!e)throw new RangeError("Unknown node type: "+t);return e}};function Z(t,e){let i=[];for(let s=0;s<e.length;s++){let n=e[s],r=t.marks[n],h=r;if(r)i.push(r);else for(let e in t.marks){let s=t.marks[e];("_"==n||s.spec.group&&s.spec.group.split(" ").indexOf(n)>-1)&&i.push(h=s)}if(!h)throw new SyntaxError("Unknown mark type: '"+e[s]+"'")}return i}let tt=class t{constructor(t,e){this.schema=t,this.rules=e,this.tags=[],this.styles=[];let i=this.matchedStyles=[];e.forEach((t=>{if(function(t){return null!=t.tag}(t))this.tags.push(t);else if(function(t){return null!=t.style}(t)){let e=/[^=]*/.exec(t.style)[0];i.indexOf(e)<0&&i.push(e),this.styles.push(t)}})),this.normalizeLists=!this.tags.some((e=>{if(!/^(ul|ol)\b/.test(e.tag)||!e.node)return!1;let i=t.nodes[e.node];return i.contentMatch.matchType(i)}))}parse(t,e={}){let i=new ht(this,e,!1);return i.addAll(t,d.none,e.from,e.to),i.finish()}parseSlice(t,e={}){let i=new ht(this,e,!0);return i.addAll(t,d.none,e.from,e.to),w.maxOpen(i.finish())}matchTag(t,e,i){for(let s=i?this.tags.indexOf(i)+1:0;s<this.tags.length;s++){let i=this.tags[s];if(ot(t,i.tag)&&(void 0===i.namespace||t.namespaceURI==i.namespace)&&(!i.context||e.matchesContext(i.context))){if(i.getAttrs){let e=i.getAttrs(t);if(!1===e)continue;i.attrs=e||void 0}return i}}}matchStyle(t,e,i,s){for(let n=s?this.styles.indexOf(s)+1:0;n<this.styles.length;n++){let s=this.styles[n],r=s.style;if(!(0!=r.indexOf(t)||s.context&&!i.matchesContext(s.context)||r.length>t.length&&(61!=r.charCodeAt(t.length)||r.slice(t.length+1)!=e))){if(s.getAttrs){let t=s.getAttrs(e);if(!1===t)continue;s.attrs=t||void 0}return s}}}static schemaRules(t){let e=[];function i(t){let i=null==t.priority?50:t.priority,s=0;for(;s<e.length;s++){let t=e[s];if((null==t.priority?50:t.priority)<i)break}e.splice(s,0,t)}for(let e in t.marks){let s=t.marks[e].spec.parseDOM;s&&s.forEach((t=>{i(t=lt(t)),t.mark||t.ignore||t.clearMark||(t.mark=e)}))}for(let e in t.nodes){let s=t.nodes[e].spec.parseDOM;s&&s.forEach((t=>{i(t=lt(t)),t.node||t.ignore||t.mark||(t.node=e)}))}return e}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new t(e,t.schemaRules(e)))}};const et={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},it={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},st={ol:!0,ul:!0};function nt(t,e,i){return null!=e?(e?1:0)|("full"===e?2:0):t&&"pre"==t.whitespace?3:-5&i}class rt{constructor(t,e,i,s,n,r){this.type=t,this.attrs=e,this.marks=i,this.solid=s,this.options=r,this.content=[],this.activeMarks=d.none,this.match=n||(4&r?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let e=this.type.contentMatch.fillBefore(u.from(t));if(!e){let e,i=this.type.contentMatch;return(e=i.findWrapping(t.type))?(this.match=i,e):null}this.match=this.type.contentMatch.matchFragment(e)}return this.match.findWrapping(t.type)}finish(t){if(!(1&this.options)){let t,e=this.content[this.content.length-1];if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let i=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=i.withText(i.text.slice(0,i.text.length-t[0].length))}}let e=u.from(this.content);return!t&&this.match&&(e=e.append(this.match.fillBefore(u.empty,!0))),this.type?this.type.create(this.attrs,e,this.marks):e}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!et.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class ht{constructor(t,e,i){this.parser=t,this.options=e,this.isOpen=i,this.open=0,this.localPreserveWS=!1;let s,n=e.topNode,r=nt(null,e.preserveWhitespace,0)|(i?4:0);s=n?new rt(n.type,n.attrs,d.none,!0,e.topMatch||n.type.contentMatch,r):new rt(i?null:t.schema.topNodeType,null,d.none,!0,null,r),this.nodes=[s],this.find=e.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t,e){3==t.nodeType?this.addTextNode(t,e):1==t.nodeType&&this.addElement(t,e)}addTextNode(t,e){let i=t.nodeValue,s=this.top,n=2&s.options?"full":this.localPreserveWS||(1&s.options)>0,{schema:r}=this.parser;if("full"===n||s.inlineContext(t)||/[^ \t\r\n\u000c]/.test(i)){if(n)if("full"===n)i=i.replace(/\r\n?/g,"\n");else if(r.linebreakReplacement&&/[\r\n]/.test(i)&&this.top.findWrapping(r.linebreakReplacement.create())){let t=i.split(/\r?\n|\r/);for(let i=0;i<t.length;i++)i&&this.insertNode(r.linebreakReplacement.create(),e,!0),t[i]&&this.insertNode(r.text(t[i]),e,!/\S/.test(t[i]));i=""}else i=i.replace(/\r?\n|\r/g," ");else if(i=i.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(i)&&this.open==this.nodes.length-1){let e=s.content[s.content.length-1],n=t.previousSibling;(!e||n&&"BR"==n.nodeName||e.isText&&/[ \t\r\n\u000c]$/.test(e.text))&&(i=i.slice(1))}i&&this.insertNode(r.text(i),e,!/\S/.test(i)),this.findInText(t)}else this.findInside(t)}addElement(t,e,i){let s=this.localPreserveWS,n=this.top;("PRE"==t.tagName||/pre/.test(t.style&&t.style.whiteSpace))&&(this.localPreserveWS=!0);let r,h=t.nodeName.toLowerCase();st.hasOwnProperty(h)&&this.parser.normalizeLists&&function(t){for(let e=t.firstChild,i=null;e;e=e.nextSibling){let t=1==e.nodeType?e.nodeName.toLowerCase():null;t&&st.hasOwnProperty(t)&&i?(i.appendChild(e),e=i):"li"==t?i=e:t&&(i=null)}}(t);let o=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(r=this.parser.matchTag(t,this,i));t:if(o?o.ignore:it.hasOwnProperty(h))this.findInside(t),this.ignoreFallback(t,e);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(t=o.skip);let i,s=this.needsBlock;if(et.hasOwnProperty(h))n.content.length&&n.content[0].isInline&&this.open&&(this.open--,n=this.top),i=!0,n.type||(this.needsBlock=!0);else if(!t.firstChild){this.leafFallback(t,e);break t}let r=o&&o.skip?e:this.readStyles(t,e);r&&this.addAll(t,r),i&&this.sync(n),this.needsBlock=s}else{let i=this.readStyles(t,e);i&&this.addElementByRule(t,o,i,!1===o.consuming?r:void 0)}this.localPreserveWS=s}leafFallback(t,e){"BR"==t.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode("\n"),e)}ignoreFallback(t,e){"BR"!=t.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),e,!0)}readStyles(t,e){let i=t.style;if(i&&i.length)for(let t=0;t<this.parser.matchedStyles.length;t++){let s=this.parser.matchedStyles[t],n=i.getPropertyValue(s);if(n)for(let t;;){let i=this.parser.matchStyle(s,n,this,t);if(!i)break;if(i.ignore)return null;if(e=i.clearMark?e.filter((t=>!i.clearMark(t))):e.concat(this.parser.schema.marks[i.mark].create(i.attrs)),!1!==i.consuming)break;t=i}}return e}addElementByRule(t,e,i,s){let n,r;if(e.node)if(r=this.parser.schema.nodes[e.node],r.isLeaf)this.insertNode(r.create(e.attrs),i,"BR"==t.nodeName)||this.leafFallback(t,i);else{let t=this.enter(r,e.attrs||null,i,e.preserveWhitespace);t&&(n=!0,i=t)}else i=i.concat(this.parser.schema.marks[e.mark].create(e.attrs));let h=this.top;if(r&&r.isLeaf)this.findInside(t);else if(s)this.addElement(t,i,s);else if(e.getContent)this.findInside(t),e.getContent(t,this.parser.schema).forEach((t=>this.insertNode(t,i,!1)));else{let s=t;"string"==typeof e.contentElement?s=t.querySelector(e.contentElement):"function"==typeof e.contentElement?s=e.contentElement(t):e.contentElement&&(s=e.contentElement),this.findAround(t,s,!0),this.addAll(s,i),this.findAround(t,s,!1)}n&&this.sync(h)&&this.open--}addAll(t,e,i,s){let n=i||0;for(let r=i?t.childNodes[i]:t.firstChild,h=null==s?null:t.childNodes[s];r!=h;r=r.nextSibling,++n)this.findAtPoint(t,n),this.addDOM(r,e);this.findAtPoint(t,n)}findPlace(t,e,i){let s,n;for(let e=this.open,r=0;e>=0;e--){let h=this.nodes[e],o=h.findWrapping(t);if(o&&(!s||s.length>o.length+r)&&(s=o,n=h,!o.length))break;if(h.solid){if(i)break;r+=2}}if(!s)return null;this.sync(n);for(let t=0;t<s.length;t++)e=this.enterInner(s[t],null,e,!1);return e}insertNode(t,e,i){if(t.isInline&&this.needsBlock&&!this.top.type){let t=this.textblockFromContext();t&&(e=this.enterInner(t,null,e))}let s=this.findPlace(t,e,i);if(s){this.closeExtra();let e=this.top;e.match&&(e.match=e.match.matchType(t.type));let i=d.none;for(let n of s.concat(t.marks))(e.type?e.type.allowsMarkType(n.type):ut(n.type,t.type))&&(i=n.addToSet(i));return e.content.push(t.mark(i)),!0}return!1}enter(t,e,i,s){let n=this.findPlace(t.create(e),i,!1);return n&&(n=this.enterInner(t,e,i,!0,s)),n}enterInner(t,e,i,s=!1,n){this.closeExtra();let r=this.top;r.match=r.match&&r.match.matchType(t);let h=nt(t,n,r.options);4&r.options&&0==r.content.length&&(h|=4);let o=d.none;return i=i.filter((e=>!(r.type?r.type.allowsMarkType(e.type):ut(e.type,t))||(o=e.addToSet(o),!1))),this.nodes.push(new rt(t,e,o,s,null,h)),this.open++,i}closeExtra(t=!1){let e=this.nodes.length-1;if(e>this.open){for(;e>this.open;e--)this.nodes[e-1].content.push(this.nodes[e].finish(t));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!(!this.isOpen&&!this.options.topOpen))}sync(t){for(let e=this.open;e>=0;e--){if(this.nodes[e]==t)return this.open=e,!0;this.localPreserveWS&&(this.nodes[e].options|=1)}return!1}get currentPos(){this.closeExtra();let t=0;for(let e=this.open;e>=0;e--){let i=this.nodes[e].content;for(let e=i.length-1;e>=0;e--)t+=i[e].nodeSize;e&&t++}return t}findAtPoint(t,e){if(this.find)for(let i=0;i<this.find.length;i++)this.find[i].node==t&&this.find[i].offset==e&&(this.find[i].pos=this.currentPos)}findInside(t){if(this.find)for(let e=0;e<this.find.length;e++)null==this.find[e].pos&&1==t.nodeType&&t.contains(this.find[e].node)&&(this.find[e].pos=this.currentPos)}findAround(t,e,i){if(t!=e&&this.find)for(let s=0;s<this.find.length;s++)null==this.find[s].pos&&1==t.nodeType&&t.contains(this.find[s].node)&&e.compareDocumentPosition(this.find[s].node)&(i?2:4)&&(this.find[s].pos=this.currentPos)}findInText(t){if(this.find)for(let e=0;e<this.find.length;e++)this.find[e].node==t&&(this.find[e].pos=this.currentPos-(t.nodeValue.length-this.find[e].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let e=t.split("/"),i=this.options.context,s=!(this.isOpen||i&&i.parent.type!=this.nodes[0].type),n=(s?0:1)-(i?i.depth+1:0),r=(t,h)=>{for(;t>=0;t--){let o=e[t];if(""==o){if(t==e.length-1||0==t)continue;for(;h>=n;h--)if(r(t-1,h))return!0;return!1}{let t=h>0||0==h&&s?this.nodes[h].type:i&&h>=n?i.node(h-n).type:null;if(!t||t.name!=o&&!t.isInGroup(o))return!1;h--}}return!0};return r(e.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let e=t.depth;e>=0;e--){let i=t.node(e).contentMatchAt(t.indexAfter(e)).defaultType;if(i&&i.isTextblock&&i.defaultAttrs)return i}for(let t in this.parser.schema.nodes){let e=this.parser.schema.nodes[t];if(e.isTextblock&&e.defaultAttrs)return e}}}function ot(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function lt(t){let e={};for(let i in t)e[i]=t[i];return e}function ut(t,e){let i=e.schema.nodes;for(let s in i){let n=i[s];if(!n.allowsMarkType(t))continue;let r=[],h=t=>{r.push(t);for(let i=0;i<t.edgeCount;i++){let{type:s,next:n}=t.edge(i);if(s==e)return!0;if(r.indexOf(n)<0&&h(n))return!0}};if(h(n.contentMatch))return!0}}class at{constructor(t,e){this.nodes=t,this.marks=e}serializeFragment(t,e={},i){i||(i=ft(e).createDocumentFragment());let s=i,n=[];return t.forEach((t=>{if(n.length||t.marks.length){let i=0,r=0;for(;i<n.length&&r<t.marks.length;){let e=t.marks[r];if(this.marks[e.type.name]){if(!e.eq(n[i][0])||!1===e.type.spec.spanning)break;i++,r++}else r++}for(;i<n.length;)s=n.pop()[1];for(;r<t.marks.length;){let i=t.marks[r++],h=this.serializeMark(i,t.isInline,e);h&&(n.push([i,s]),s.appendChild(h.dom),s=h.contentDOM||h.dom)}}s.appendChild(this.serializeNodeInner(t,e))})),i}serializeNodeInner(t,e){let{dom:i,contentDOM:s}=pt(ft(e),this.nodes[t.type.name](t),null,t.attrs);if(s){if(t.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(t.content,e,s)}return i}serializeNode(t,e={}){let i=this.serializeNodeInner(t,e);for(let s=t.marks.length-1;s>=0;s--){let n=this.serializeMark(t.marks[s],t.isInline,e);n&&((n.contentDOM||n.dom).appendChild(i),i=n.dom)}return i}serializeMark(t,e,i={}){let s=this.marks[t.type.name];return s&&pt(ft(i),s(t,e),null,t.attrs)}static renderSpec(t,e,i=null,s){return pt(t,e,i,s)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new at(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(t){let e=ct(t.nodes);return e.text||(e.text=t=>t.text),e}static marksFromSchema(t){return ct(t.marks)}}function ct(t){let e={};for(let i in t){let s=t[i].spec.toDOM;s&&(e[i]=s)}return e}function ft(t){return t.document||window.document}const dt=new WeakMap;function pt(t,e,i,s){if("string"==typeof e)return{dom:t.createTextNode(e)};if(null!=e.nodeType)return{dom:e};if(e.dom&&null!=e.dom.nodeType)return e;let n,r=e[0];if("string"!=typeof r)throw new RangeError("Invalid array passed to renderSpec");if(s&&(n=function(t){let e=dt.get(t);return void 0===e&&dt.set(t,e=function(t){let e=null;return function t(i){if(i&&"object"==typeof i)if(Array.isArray(i))if("string"==typeof i[0])e||(e=[]),e.push(i);else for(let e=0;e<i.length;e++)t(i[e]);else for(let e in i)t(i[e])}(t),e}(t)),e}(s))&&n.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let h,o=r.indexOf(" ");o>0&&(i=r.slice(0,o),r=r.slice(o+1));let l=i?t.createElementNS(i,r):t.createElement(r),u=e[1],a=1;if(u&&"object"==typeof u&&null==u.nodeType&&!Array.isArray(u)){a=2;for(let t in u)if(null!=u[t]){let e=t.indexOf(" ");e>0?l.setAttributeNS(t.slice(0,e),t.slice(e+1),u[t]):"style"==t&&l.style?l.style.cssText=u[t]:l.setAttribute(t,u[t])}}for(let n=a;n<e.length;n++){let r=e[n];if(0===r){if(n<e.length-1||n>a)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}{let{dom:e,contentDOM:n}=pt(t,r,i,s);if(l.appendChild(e),n){if(h)throw new RangeError("Multiple content holes");h=n}}}return{dom:l,contentDOM:h}}const wt=Math.pow(2,16);function gt(t){return 65535&t}class mt{constructor(t,e,i){this.pos=t,this.delInfo=e,this.recover=i}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class yt{constructor(t,e=!1){if(this.ranges=t,this.inverted=e,!t.length&&yt.empty)return yt.empty}recover(t){let e=0,i=gt(t);if(!this.inverted)for(let t=0;t<i;t++)e+=this.ranges[3*t+2]-this.ranges[3*t+1];return this.ranges[3*i]+e+function(t){return(t-(65535&t))/wt}(t)}mapResult(t,e=1){return this._map(t,e,!1)}map(t,e=1){return this._map(t,e,!0)}_map(t,e,i){let s=0,n=this.inverted?2:1,r=this.inverted?1:2;for(let h=0;h<this.ranges.length;h+=3){let o=this.ranges[h]-(this.inverted?s:0);if(o>t)break;let l=this.ranges[h+n],u=this.ranges[h+r],a=o+l;if(t<=a){let n=o+s+((l?t==o?-1:t==a?1:e:e)<0?0:u);if(i)return n;let r=t==o?2:t==a?1:4;return(e<0?t!=o:t!=a)&&(r|=8),new mt(n,r,t==(e<0?o:a)?null:h/3+(t-o)*wt)}s+=u-l}return i?t+s:new mt(t+s,0,null)}touches(t,e){let i=0,s=gt(e),n=this.inverted?2:1,r=this.inverted?1:2;for(let e=0;e<this.ranges.length;e+=3){let h=this.ranges[e]-(this.inverted?i:0);if(h>t)break;let o=this.ranges[e+n];if(t<=h+o&&e==3*s)return!0;i+=this.ranges[e+r]-o}return!1}forEach(t){let e=this.inverted?2:1,i=this.inverted?1:2;for(let s=0,n=0;s<this.ranges.length;s+=3){let r=this.ranges[s],h=r-(this.inverted?n:0),o=r+(this.inverted?0:n),l=this.ranges[s+e],u=this.ranges[s+i];t(h,h+l,o,o+u),n+=u-l}}invert(){return new yt(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return 0==t?yt.empty:new yt(t<0?[0,-t,0]:[0,0,t])}}yt.empty=new yt([]);class vt{constructor(t,e,i=0,s=(t?t.length:0)){this.mirror=e,this.from=i,this.to=s,this._maps=t||[],this.ownData=!(t||e)}get maps(){return this._maps}slice(t=0,e=this.maps.length){return new vt(this._maps,this.mirror,t,e)}appendMap(t,e){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(t),null!=e&&this.setMirror(this._maps.length-1,e)}appendMapping(t){for(let e=0,i=this._maps.length;e<t._maps.length;e++){let s=t.getMirror(e);this.appendMap(t._maps[e],null!=s&&s<e?i+s:void 0)}}getMirror(t){if(this.mirror)for(let e=0;e<this.mirror.length;e++)if(this.mirror[e]==t)return this.mirror[e+(e%2?-1:1)]}setMirror(t,e){this.mirror||(this.mirror=[]),this.mirror.push(t,e)}appendMappingInverted(t){for(let e=t.maps.length-1,i=this._maps.length+t._maps.length;e>=0;e--){let s=t.getMirror(e);this.appendMap(t._maps[e].invert(),null!=s&&s>e?i-s-1:void 0)}}invert(){let t=new vt;return t.appendMappingInverted(this),t}map(t,e=1){if(this.mirror)return this._map(t,e,!0);for(let i=this.from;i<this.to;i++)t=this._maps[i].map(t,e);return t}mapResult(t,e=1){return this._map(t,e,!1)}_map(t,e,i){let s=0;for(let i=this.from;i<this.to;i++){let n=this._maps[i].mapResult(t,e);if(null!=n.recover){let e=this.getMirror(i);if(null!=e&&e>i&&e<this.to){i=e,t=this._maps[e].recover(n.recover);continue}}s|=n.delInfo,t=n.pos}return i?t:new mt(t,s,null)}}const bt=Object.create(null);class Mt{getMap(){return yt.empty}merge(t){return null}static fromJSON(t,e){if(!e||!e.stepType)throw new RangeError("Invalid input for Step.fromJSON");let i=bt[e.stepType];if(!i)throw new RangeError(`No step type ${e.stepType} defined`);return i.fromJSON(t,e)}static jsonID(t,e){if(t in bt)throw new RangeError("Duplicate use of step JSON ID "+t);return bt[t]=e,e.prototype.jsonID=t,e}}class kt{constructor(t,e){this.doc=t,this.failed=e}static ok(t){return new kt(t,null)}static fail(t){return new kt(null,t)}static fromReplace(t,e,i,s){try{return kt.ok(t.replace(e,i,s))}catch(t){if(t instanceof p)return kt.fail(t.message);throw t}}}function At(t,e,i){let s=[];for(let n=0;n<t.childCount;n++){let r=t.child(n);r.content.size&&(r=r.copy(At(r.content,e,r))),r.isInline&&(r=e(r,i,n)),s.push(r)}return u.fromArray(s)}class xt extends Mt{constructor(t,e,i){super(),this.from=t,this.to=e,this.mark=i}apply(t){let e=t.slice(this.from,this.to),i=t.resolve(this.from),s=i.node(i.sharedDepth(this.to)),n=new w(At(e.content,((t,e)=>t.isAtom&&e.type.allowsMarkType(this.mark.type)?t.mark(this.mark.addToSet(t.marks)):t),s),e.openStart,e.openEnd);return kt.fromReplace(t,this.from,this.to,n)}invert(){return new St(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);return e.deleted&&i.deleted||e.pos>=i.pos?null:new xt(e.pos,i.pos,this.mark)}merge(t){return t instanceof xt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new xt(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new xt(e.from,e.to,t.markFromJSON(e.mark))}}Mt.jsonID("addMark",xt);class St extends Mt{constructor(t,e,i){super(),this.from=t,this.to=e,this.mark=i}apply(t){let e=t.slice(this.from,this.to),i=new w(At(e.content,(t=>t.mark(this.mark.removeFromSet(t.marks))),t),e.openStart,e.openEnd);return kt.fromReplace(t,this.from,this.to,i)}invert(){return new xt(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);return e.deleted&&i.deleted||e.pos>=i.pos?null:new St(e.pos,i.pos,this.mark)}merge(t){return t instanceof St&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new St(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new St(e.from,e.to,t.markFromJSON(e.mark))}}Mt.jsonID("removeMark",St);class Ct extends Mt{constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return kt.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.addToSet(e.marks));return kt.fromReplace(t,this.pos,this.pos+1,new w(u.from(i),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);if(e){let t=this.mark.addToSet(e.marks);if(t.length==e.marks.length){for(let i=0;i<e.marks.length;i++)if(!e.marks[i].isInSet(t))return new Ct(this.pos,e.marks[i]);return new Ct(this.pos,this.mark)}}return new Ot(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Ct(e.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Ct(e.pos,t.markFromJSON(e.mark))}}Mt.jsonID("addNodeMark",Ct);class Ot extends Mt{constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return kt.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.removeFromSet(e.marks));return kt.fromReplace(t,this.pos,this.pos+1,new w(u.from(i),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);return e&&this.mark.isInSet(e.marks)?new Ct(this.pos,this.mark):this}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Ot(e.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Ot(e.pos,t.markFromJSON(e.mark))}}Mt.jsonID("removeNodeMark",Ot);class Et extends Mt{constructor(t,e,i,s=!1){super(),this.from=t,this.to=e,this.slice=i,this.structure=s}apply(t){return this.structure&&Dt(t,this.from,this.to)?kt.fail("Structure replace would overwrite content"):kt.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new yt([this.from,this.to-this.from,this.slice.size])}invert(t){return new Et(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);return e.deletedAcross&&i.deletedAcross?null:new Et(e.pos,Math.max(e.pos,i.pos),this.slice,this.structure)}merge(t){if(!(t instanceof Et)||t.structure||this.structure)return null;if(this.from+this.slice.size!=t.from||this.slice.openEnd||t.slice.openStart){if(t.to!=this.from||this.slice.openStart||t.slice.openEnd)return null;{let e=this.slice.size+t.slice.size==0?w.empty:new w(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new Et(t.from,this.to,e,this.structure)}}{let e=this.slice.size+t.slice.size==0?w.empty:new w(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new Et(this.from,this.to+(t.to-t.from),e,this.structure)}}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Et(e.from,e.to,w.fromJSON(t,e.slice),!!e.structure)}}Mt.jsonID("replace",Et);class Tt extends Mt{constructor(t,e,i,s,n,r,h=!1){super(),this.from=t,this.to=e,this.gapFrom=i,this.gapTo=s,this.slice=n,this.insert=r,this.structure=h}apply(t){if(this.structure&&(Dt(t,this.from,this.gapFrom)||Dt(t,this.gapTo,this.to)))return kt.fail("Structure gap-replace would overwrite content");let e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return kt.fail("Gap is not a flat range");let i=this.slice.insertAt(this.insert,e.content);return i?kt.fromReplace(t,this.from,this.to,i):kt.fail("Content does not fit in gap")}getMap(){return new yt([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let e=this.gapTo-this.gapFrom;return new Tt(this.from,this.from+this.slice.size+e,this.from+this.insert,this.from+this.insert+e,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1),s=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1),n=this.to==this.gapTo?i.pos:t.map(this.gapTo,1);return e.deletedAcross&&i.deletedAcross||s<e.pos||n>i.pos?null:new Tt(e.pos,i.pos,s,n,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to||"number"!=typeof e.gapFrom||"number"!=typeof e.gapTo||"number"!=typeof e.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Tt(e.from,e.to,e.gapFrom,e.gapTo,w.fromJSON(t,e.slice),e.insert,!!e.structure)}}function Dt(t,e,i){let s=t.resolve(e),n=i-e,r=s.depth;for(;n>0&&r>0&&s.indexAfter(r)==s.node(r).childCount;)r--,n--;if(n>0){let t=s.node(r).maybeChild(s.indexAfter(r));for(;n>0;){if(!t||t.isLeaf)return!0;t=t.firstChild,n--}}return!1}function $t(t,e,i,s=i.contentMatch,n=!0){let r=t.doc.nodeAt(e),h=[],o=e+1;for(let e=0;e<r.childCount;e++){let l=r.child(e),a=o+l.nodeSize,c=s.matchType(l.type);if(c){s=c;for(let e=0;e<l.marks.length;e++)i.allowsMarkType(l.marks[e].type)||t.step(new St(o,a,l.marks[e]));if(n&&l.isText&&"pre"!=i.whitespace){let t,e,s=/\r?\n|\r/g;for(;t=s.exec(l.text);)e||(e=new w(u.from(i.schema.text(" ",i.allowedMarks(l.marks))),0,0)),h.push(new Et(o+t.index,o+t.index+t[0].length,e))}}else h.push(new Et(o,a,w.empty));o=a}if(!s.validEnd){let e=s.fillBefore(u.empty,!0);t.replace(o,o,new w(e,0,0))}for(let e=h.length-1;e>=0;e--)t.step(h[e])}function Pt(t,e,i){return(0==e||t.canReplace(e,t.childCount))&&(i==t.childCount||t.canReplace(0,i))}function Rt(t){let e=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let i=t.depth,s=0,n=0;;--i){let r=t.$from.node(i),h=t.$from.index(i)+s,o=t.$to.indexAfter(i)-n;if(i<t.depth&&r.canReplace(h,o,e))return i;if(0==i||r.type.spec.isolating||!Pt(r,h,o))break;h&&(s=1),o<r.childCount&&(n=1)}return null}function It(t,e,i,s){e.forEach(((n,r)=>{if(n.isText){let h,o=/\r?\n|\r/g;for(;h=o.exec(n.text);){let n=t.mapping.slice(s).map(i+1+r+h.index);t.replaceWith(n,n+1,e.type.schema.linebreakReplacement.create())}}}))}function Ut(t,e,i,s){e.forEach(((n,r)=>{if(n.type==n.type.schema.linebreakReplacement){let n=t.mapping.slice(s).map(i+1+r);t.replaceWith(n,n+1,e.type.schema.text("\n"))}}))}function jt(t,e,i=1,s){let n=t.resolve(e),r=n.depth-i,h=s&&s[s.length-1]||n.parent;if(r<0||n.parent.type.spec.isolating||!n.parent.canReplace(n.index(),n.parent.childCount)||!h.type.validContent(n.parent.content.cutByIndex(n.index(),n.parent.childCount)))return!1;for(let t=n.depth-1,e=i-2;t>r;t--,e--){let i=n.node(t),r=n.index(t);if(i.type.spec.isolating)return!1;let h=i.content.cutByIndex(r,i.childCount),o=s&&s[e+1];o&&(h=h.replaceChild(0,o.type.create(o.attrs)));let l=s&&s[e]||i;if(!i.canReplace(r+1,i.childCount)||!l.type.validContent(h))return!1}let o=n.indexAfter(r),l=s&&s[0];return n.node(r).canReplaceWith(o,o,l?l.type:n.node(r+1).type)}function Bt(t,e){let i=t.resolve(e),s=i.index();return function(t,e){return!(!t||!e||t.isLeaf||!function(t,e){e.content.size||t.type.compatibleContent(e.type);let i=t.contentMatchAt(t.childCount),{linebreakReplacement:s}=t.type.schema;for(let n=0;n<e.childCount;n++){let r=e.child(n);if(i=i.matchType(r.type==s?t.type.schema.nodes.text:r.type),!i)return!1;if(!t.type.allowsMarks(r.marks))return!1}return i.validEnd}(t,e))}(i.nodeBefore,i.nodeAfter)&&i.parent.canReplace(s,s+1)}function Nt(t,e,i=e,s=w.empty){if(e==i&&!s.size)return null;let n=t.resolve(e),r=t.resolve(i);return Ft(n,r,s)?new Et(e,i,s):new _t(n,r,s).fit()}function Ft(t,e,i){return!i.openStart&&!i.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),i.content)}Mt.jsonID("replaceAround",Tt);class _t{constructor(t,e,i){this.$from=t,this.$to=e,this.unplaced=i,this.frontier=[],this.placed=u.empty;for(let e=0;e<=t.depth;e++){let i=t.node(e);this.frontier.push({type:i.type,match:i.contentMatchAt(t.indexAfter(e))})}for(let e=t.depth;e>0;e--)this.placed=u.from(t.node(e).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let t=this.findFittable();t?this.placeNodes(t):this.openMore()||this.dropNode()}let t=this.mustMoveInline(),e=this.placed.size-this.depth-this.$from.depth,i=this.$from,s=this.close(t<0?this.$to:i.doc.resolve(t));if(!s)return null;let n=this.placed,r=i.depth,h=s.depth;for(;r&&h&&1==n.childCount;)n=n.firstChild.content,r--,h--;let o=new w(n,r,h);return t>-1?new Tt(i.pos,t,this.$to.pos,this.$to.end(),o,e):o.size||i.pos!=this.$to.pos?new Et(i.pos,s.pos,o):null}findFittable(){let t=this.unplaced.openStart;for(let e=this.unplaced.content,i=0,s=this.unplaced.openEnd;i<t;i++){let n=e.firstChild;if(e.childCount>1&&(s=0),n.type.spec.isolating&&s<=i){t=i;break}e=n.content}for(let e=1;e<=2;e++)for(let i=1==e?t:this.unplaced.openStart;i>=0;i--){let t,s=null;i?(s=Yt(this.unplaced.content,i-1).firstChild,t=s.content):t=this.unplaced.content;let n=t.firstChild;for(let t=this.depth;t>=0;t--){let r,{type:h,match:o}=this.frontier[t],l=null;if(1==e&&(n?o.matchType(n.type)||(l=o.fillBefore(u.from(n),!1)):s&&h.compatibleContent(s.type)))return{sliceDepth:i,frontierDepth:t,parent:s,inject:l};if(2==e&&n&&(r=o.findWrapping(n.type)))return{sliceDepth:i,frontierDepth:t,parent:s,wrap:r};if(s&&o.matchType(s.type))break}}}openMore(){let{content:t,openStart:e,openEnd:i}=this.unplaced,s=Yt(t,e);return!(!s.childCount||s.firstChild.isLeaf||(this.unplaced=new w(t,e+1,Math.max(i,s.size+e>=t.size-i?e+1:0)),0))}dropNode(){let{content:t,openStart:e,openEnd:i}=this.unplaced,s=Yt(t,e);if(s.childCount<=1&&e>0){let n=t.size-e<=e+s.size;this.unplaced=new w(Lt(t,e-1,1),e-1,n?e-1:i)}else this.unplaced=new w(Lt(t,e,1),e,i)}placeNodes({sliceDepth:t,frontierDepth:e,parent:i,inject:s,wrap:n}){for(;this.depth>e;)this.closeFrontierNode();if(n)for(let t=0;t<n.length;t++)this.openFrontierNode(n[t]);let r=this.unplaced,h=i?i.content:r.content,o=r.openStart-t,l=0,a=[],{match:c,type:f}=this.frontier[e];if(s){for(let t=0;t<s.childCount;t++)a.push(s.child(t));c=c.matchFragment(s)}let d=h.size+t-(r.content.size-r.openEnd);for(;l<h.childCount;){let t=h.child(l),e=c.matchType(t.type);if(!e)break;l++,(l>1||0==o||t.content.size)&&(c=e,a.push(Wt(t.mark(f.allowedMarks(t.marks)),1==l?o:0,l==h.childCount?d:-1)))}let p=l==h.childCount;p||(d=-1),this.placed=zt(this.placed,e,u.from(a)),this.frontier[e].match=c,p&&d<0&&i&&i.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let t=0,e=h;t<d;t++){let t=e.lastChild;this.frontier.push({type:t.type,match:t.contentMatchAt(t.childCount)}),e=t.content}this.unplaced=p?0==t?w.empty:new w(Lt(r.content,t-1,1),t-1,d<0?r.openEnd:t-1):new w(Lt(r.content,t,l),r.openStart,r.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let t,e=this.frontier[this.depth];if(!e.type.isTextblock||!Xt(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:i}=this.$to,s=this.$to.after(i);for(;i>1&&s==this.$to.end(--i);)++s;return s}findCloseLevel(t){t:for(let e=Math.min(this.depth,t.depth);e>=0;e--){let{match:i,type:s}=this.frontier[e],n=e<t.depth&&t.end(e+1)==t.pos+(t.depth-(e+1)),r=Xt(t,e,s,i,n);if(r){for(let i=e-1;i>=0;i--){let{match:e,type:s}=this.frontier[i],n=Xt(t,i,s,e,!0);if(!n||n.childCount)continue t}return{depth:e,fit:r,move:n?t.doc.resolve(t.after(e+1)):t}}}}close(t){let e=this.findCloseLevel(t);if(!e)return null;for(;this.depth>e.depth;)this.closeFrontierNode();e.fit.childCount&&(this.placed=zt(this.placed,e.depth,e.fit)),t=e.move;for(let i=e.depth+1;i<=t.depth;i++){let e=t.node(i),s=e.type.contentMatch.fillBefore(e.content,!0,t.index(i));this.openFrontierNode(e.type,e.attrs,s)}return t}openFrontierNode(t,e=null,i){let s=this.frontier[this.depth];s.match=s.match.matchType(t),this.placed=zt(this.placed,this.depth,u.from(t.create(e,i))),this.frontier.push({type:t,match:t.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(u.empty,!0);t.childCount&&(this.placed=zt(this.placed,this.frontier.length,t))}}function Lt(t,e,i){return 0==e?t.cutByIndex(i,t.childCount):t.replaceChild(0,t.firstChild.copy(Lt(t.firstChild.content,e-1,i)))}function zt(t,e,i){return 0==e?t.append(i):t.replaceChild(t.childCount-1,t.lastChild.copy(zt(t.lastChild.content,e-1,i)))}function Yt(t,e){for(let i=0;i<e;i++)t=t.firstChild.content;return t}function Wt(t,e,i){if(e<=0)return t;let s=t.content;return e>1&&(s=s.replaceChild(0,Wt(s.firstChild,e-1,1==s.childCount?i-1:0))),e>0&&(s=t.type.contentMatch.fillBefore(s).append(s),i<=0&&(s=s.append(t.type.contentMatch.matchFragment(s).fillBefore(u.empty,!0)))),t.copy(s)}function Xt(t,e,i,s,n){let r=t.node(e),h=n?t.indexAfter(e):t.index(e);if(h==r.childCount&&!i.compatibleContent(r.type))return null;let o=s.fillBefore(r.content,!0,h);return o&&!function(t,e,i){for(let s=i;s<e.childCount;s++)if(!t.allowsMarks(e.child(s).marks))return!0;return!1}(i,r.content,h)?o:null}function Jt(t,e,i,s,n){if(e<i){let n=t.firstChild;t=t.replaceChild(0,n.copy(Jt(n.content,e+1,i,s,n)))}if(e>s){let e=n.contentMatchAt(0),i=e.fillBefore(t).append(t);t=i.append(e.matchFragment(i).fillBefore(u.empty,!0))}return t}function Ht(t,e){let i=[];for(let s=Math.min(t.depth,e.depth);s>=0;s--){let n=t.start(s);if(n<t.pos-(t.depth-s)||e.end(s)>e.pos+(e.depth-s)||t.node(s).type.spec.isolating||e.node(s).type.spec.isolating)break;(n==e.start(s)||s==t.depth&&s==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&s&&e.start(s-1)==n-1)&&i.push(s)}return i}class Vt extends Mt{constructor(t,e,i){super(),this.pos=t,this.attr=e,this.value=i}apply(t){let e=t.nodeAt(this.pos);if(!e)return kt.fail("No node at attribute step's position");let i=Object.create(null);for(let t in e.attrs)i[t]=e.attrs[t];i[this.attr]=this.value;let s=e.type.create(i,null,e.marks);return kt.fromReplace(t,this.pos,this.pos+1,new w(u.from(s),0,e.isLeaf?0:1))}getMap(){return yt.empty}invert(t){return new Vt(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Vt(e.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,e){if("number"!=typeof e.pos||"string"!=typeof e.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new Vt(e.pos,e.attr,e.value)}}Mt.jsonID("attr",Vt);class Qt extends Mt{constructor(t,e){super(),this.attr=t,this.value=e}apply(t){let e=Object.create(null);for(let i in t.attrs)e[i]=t.attrs[i];e[this.attr]=this.value;let i=t.type.create(e,t.content,t.marks);return kt.ok(i)}getMap(){return yt.empty}invert(t){return new Qt(this.attr,t.attrs[this.attr])}map(t){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(t,e){if("string"!=typeof e.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Qt(e.attr,e.value)}}Mt.jsonID("docAttr",Qt);let Kt=class extends Error{};Kt=function t(e){let i=Error.call(this,e);return i.__proto__=t.prototype,i},(Kt.prototype=Object.create(Error.prototype)).constructor=Kt,Kt.prototype.name="TransformError";class qt{constructor(t){this.doc=t,this.steps=[],this.docs=[],this.mapping=new vt}get before(){return this.docs.length?this.docs[0]:this.doc}step(t){let e=this.maybeStep(t);if(e.failed)throw new Kt(e.failed);return this}maybeStep(t){let e=t.apply(this.doc);return e.failed||this.addStep(t,e.doc),e}get docChanged(){return this.steps.length>0}addStep(t,e){this.docs.push(this.doc),this.steps.push(t),this.mapping.appendMap(t.getMap()),this.doc=e}replace(t,e=t,i=w.empty){let s=Nt(this.doc,t,e,i);return s&&this.step(s),this}replaceWith(t,e,i){return this.replace(t,e,new w(u.from(i),0,0))}delete(t,e){return this.replace(t,e,w.empty)}insert(t,e){return this.replaceWith(t,t,e)}replaceRange(t,e,i){return function(t,e,i,s){if(!s.size)return t.deleteRange(e,i);let n=t.doc.resolve(e),r=t.doc.resolve(i);if(Ft(n,r,s))return t.step(new Et(e,i,s));let h=Ht(n,r);0==h[h.length-1]&&h.pop();let o=-(n.depth+1);h.unshift(o);for(let t=n.depth,e=n.pos-1;t>0;t--,e--){let i=n.node(t).type.spec;if(i.defining||i.definingAsContext||i.isolating)break;h.indexOf(t)>-1?o=t:n.before(t)==e&&h.splice(1,0,-t)}let l=h.indexOf(o),u=[],a=s.openStart;for(let t=s.content,e=0;;e++){let i=t.firstChild;if(u.push(i),e==s.openStart)break;t=i.content}for(let t=a-1;t>=0;t--){let e=u[t],i=(c=e.type).spec.defining||c.spec.definingForContent;if(i&&!e.sameMarkup(n.node(Math.abs(o)-1)))a=t;else if(i||!e.type.isTextblock)break}var c;for(let e=s.openStart;e>=0;e--){let o=(e+a+1)%(s.openStart+1),c=u[o];if(c)for(let e=0;e<h.length;e++){let u=h[(e+l)%h.length],a=!0;u<0&&(a=!1,u=-u);let f=n.node(u-1),d=n.index(u-1);if(f.canReplaceWith(d,d,c.type,c.marks))return t.replace(n.before(u),a?r.after(u):i,new w(Jt(s.content,0,s.openStart,o),o,s.openEnd))}}let f=t.steps.length;for(let o=h.length-1;o>=0&&(t.replace(e,i,s),!(t.steps.length>f));o--){let t=h[o];t<0||(e=n.before(t),i=r.after(t))}}(this,t,e,i),this}replaceRangeWith(t,e,i){return function(t,e,i,s){if(!s.isInline&&e==i&&t.doc.resolve(e).parent.content.size){let n=function(t,e,i){let s=t.resolve(e);if(s.parent.canReplaceWith(s.index(),s.index(),i))return e;if(0==s.parentOffset)for(let t=s.depth-1;t>=0;t--){let e=s.index(t);if(s.node(t).canReplaceWith(e,e,i))return s.before(t+1);if(e>0)return null}if(s.parentOffset==s.parent.content.size)for(let t=s.depth-1;t>=0;t--){let e=s.indexAfter(t);if(s.node(t).canReplaceWith(e,e,i))return s.after(t+1);if(e<s.node(t).childCount)return null}return null}(t.doc,e,s.type);null!=n&&(e=i=n)}t.replaceRange(e,i,new w(u.from(s),0,0))}(this,t,e,i),this}deleteRange(t,e){return function(t,e,i){let s=t.doc.resolve(e),n=t.doc.resolve(i),r=Ht(s,n);for(let e=0;e<r.length;e++){let i=r[e],h=e==r.length-1;if(h&&0==i||s.node(i).type.contentMatch.validEnd)return t.delete(s.start(i),n.end(i));if(i>0&&(h||s.node(i-1).canReplace(s.index(i-1),n.indexAfter(i-1))))return t.delete(s.before(i),n.after(i))}for(let r=1;r<=s.depth&&r<=n.depth;r++)if(e-s.start(r)==s.depth-r&&i>s.end(r)&&n.end(r)-i!=n.depth-r&&s.start(r-1)==n.start(r-1)&&s.node(r-1).canReplace(s.index(r-1),n.index(r-1)))return t.delete(s.before(r),i);t.delete(e,i)}(this,t,e),this}lift(t,e){return function(t,e,i){let{$from:s,$to:n,depth:r}=e,h=s.before(r+1),o=n.after(r+1),l=h,a=o,c=u.empty,f=0;for(let t=r,e=!1;t>i;t--)e||s.index(t)>0?(e=!0,c=u.from(s.node(t).copy(c)),f++):l--;let d=u.empty,p=0;for(let t=r,e=!1;t>i;t--)e||n.after(t+1)<n.end(t)?(e=!0,d=u.from(n.node(t).copy(d)),p++):a++;t.step(new Tt(l,a,h,o,new w(c.append(d),f,p),c.size-f,!0))}(this,t,e),this}join(t,e=1){return function(t,e,i){let s=null,{linebreakReplacement:n}=t.doc.type.schema,r=t.doc.resolve(e-i),h=r.node().type;if(n&&h.inlineContent){let t="pre"==h.whitespace,e=!!h.contentMatch.matchType(n);t&&!e?s=!1:!t&&e&&(s=!0)}let o=t.steps.length;if(!1===s){let s=t.doc.resolve(e+i);Ut(t,s.node(),s.before(),o)}h.inlineContent&&$t(t,e+i-1,h,r.node().contentMatchAt(r.index()),null==s);let l=t.mapping.slice(o),u=l.map(e-i);if(t.step(new Et(u,l.map(e+i,-1),w.empty,!0)),!0===s){let e=t.doc.resolve(u);It(t,e.node(),e.before(),t.steps.length)}}(this,t,e),this}wrap(t,e){return function(t,e,i){let s=u.empty;for(let t=i.length-1;t>=0;t--){if(s.size){let e=i[t].type.contentMatch.matchFragment(s);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}s=u.from(i[t].type.create(i[t].attrs,s))}let n=e.start,r=e.end;t.step(new Tt(n,r,n,r,new w(s,0,0),i.length,!0))}(this,t,e),this}setBlockType(t,e=t,i,s=null){return function(t,e,i,s,n){if(!s.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let r=t.steps.length;t.doc.nodesBetween(e,i,((e,i)=>{let h="function"==typeof n?n(e):n;if(e.isTextblock&&!e.hasMarkup(s,h)&&function(t,e,i){let s=t.resolve(e),n=s.index();return s.parent.canReplaceWith(n,n+1,i)}(t.doc,t.mapping.slice(r).map(i),s)){let n=null;if(s.schema.linebreakReplacement){let t="pre"==s.whitespace,e=!!s.contentMatch.matchType(s.schema.linebreakReplacement);t&&!e?n=!1:!t&&e&&(n=!0)}!1===n&&Ut(t,e,i,r),$t(t,t.mapping.slice(r).map(i,1),s,void 0,null===n);let o=t.mapping.slice(r),l=o.map(i,1),a=o.map(i+e.nodeSize,1);return t.step(new Tt(l,a,l+1,a-1,new w(u.from(s.create(h,null,e.marks)),0,0),1,!0)),!0===n&&It(t,e,i,r),!1}}))}(this,t,e,i,s),this}setNodeMarkup(t,e,i=null,s){return function(t,e,i,s,n){let r=t.doc.nodeAt(e);if(!r)throw new RangeError("No node at given position");i||(i=r.type);let h=i.create(s,null,n||r.marks);if(r.isLeaf)return t.replaceWith(e,e+r.nodeSize,h);if(!i.validContent(r.content))throw new RangeError("Invalid content for node type "+i.name);t.step(new Tt(e,e+r.nodeSize,e+1,e+r.nodeSize-1,new w(u.from(h),0,0),1,!0))}(this,t,e,i,s),this}setNodeAttribute(t,e,i){return this.step(new Vt(t,e,i)),this}setDocAttribute(t,e){return this.step(new Qt(t,e)),this}addNodeMark(t,e){return this.step(new Ct(t,e)),this}removeNodeMark(t,e){let i=this.doc.nodeAt(t);if(!i)throw new RangeError("No node at position "+t);if(e instanceof d)e.isInSet(i.marks)&&this.step(new Ot(t,e));else{let s,n=i.marks,r=[];for(;s=e.isInSet(n);)r.push(new Ot(t,s)),n=s.removeFromSet(n);for(let t=r.length-1;t>=0;t--)this.step(r[t])}return this}split(t,e=1,i){return function(t,e,i=1,s){let n=t.doc.resolve(e),r=u.empty,h=u.empty;for(let t=n.depth,e=n.depth-i,o=i-1;t>e;t--,o--){r=u.from(n.node(t).copy(r));let e=s&&s[o];h=u.from(e?e.type.create(e.attrs,h):n.node(t).copy(h))}t.step(new Et(e,e,new w(r.append(h),i,i),!0))}(this,t,e,i),this}addMark(t,e,i){return function(t,e,i,s){let n,r,h=[],o=[];t.doc.nodesBetween(e,i,((t,l,u)=>{if(!t.isInline)return;let a=t.marks;if(!s.isInSet(a)&&u.type.allowsMarkType(s.type)){let u=Math.max(l,e),c=Math.min(l+t.nodeSize,i),f=s.addToSet(a);for(let t=0;t<a.length;t++)a[t].isInSet(f)||(n&&n.to==u&&n.mark.eq(a[t])?n.to=c:h.push(n=new St(u,c,a[t])));r&&r.to==u?r.to=c:o.push(r=new xt(u,c,s))}})),h.forEach((e=>t.step(e))),o.forEach((e=>t.step(e)))}(this,t,e,i),this}removeMark(t,e,i){return function(t,e,i,s){let n=[],r=0;t.doc.nodesBetween(e,i,((t,h)=>{if(!t.isInline)return;r++;let o=null;if(s instanceof q){let e,i=t.marks;for(;e=s.isInSet(i);)(o||(o=[])).push(e),i=e.removeFromSet(i)}else s?s.isInSet(t.marks)&&(o=[s]):o=t.marks;if(o&&o.length){let s=Math.min(h+t.nodeSize,i);for(let t=0;t<o.length;t++){let i,l=o[t];for(let t=0;t<n.length;t++){let e=n[t];e.step==r-1&&l.eq(n[t].style)&&(i=e)}i?(i.to=s,i.step=r):n.push({style:l,from:Math.max(h,e),to:s,step:r})}}})),n.forEach((e=>t.step(new St(e.from,e.to,e.style))))}(this,t,e,i),this}clearIncompatible(t,e,i){return $t(this,t,e,i),this}}const Gt=Object.create(null);class Zt{constructor(t,e,i){this.$anchor=t,this.$head=e,this.ranges=i||[new te(t.min(e),t.max(e))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let t=this.ranges;for(let e=0;e<t.length;e++)if(t[e].$from.pos!=t[e].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,e=w.empty){let i=e.content.lastChild,s=null;for(let t=0;t<e.openEnd;t++)s=i,i=i.lastChild;let n=t.steps.length,r=this.ranges;for(let h=0;h<r.length;h++){let{$from:o,$to:l}=r[h],u=t.mapping.slice(n);t.replaceRange(u.map(o.pos),u.map(l.pos),h?w.empty:e),0==h&&ae(t,n,(i?i.isInline:s&&s.isTextblock)?-1:1)}}replaceWith(t,e){let i=t.steps.length,s=this.ranges;for(let n=0;n<s.length;n++){let{$from:r,$to:h}=s[n],o=t.mapping.slice(i),l=o.map(r.pos),u=o.map(h.pos);n?t.deleteRange(l,u):(t.replaceRangeWith(l,u,e),ae(t,i,e.isInline?-1:1))}}static findFrom(t,e,i=!1){let s=t.parent.inlineContent?new se(t):ue(t.node(0),t.parent,t.pos,t.index(),e,i);if(s)return s;for(let s=t.depth-1;s>=0;s--){let n=e<0?ue(t.node(0),t.node(s),t.before(s+1),t.index(s),e,i):ue(t.node(0),t.node(s),t.after(s+1),t.index(s)+1,e,i);if(n)return n}return null}static near(t,e=1){return this.findFrom(t,e)||this.findFrom(t,-e)||new oe(t.node(0))}static atStart(t){return ue(t,t,0,0,1)||new oe(t)}static atEnd(t){return ue(t,t,t.content.size,t.childCount,-1)||new oe(t)}static fromJSON(t,e){if(!e||!e.type)throw new RangeError("Invalid input for Selection.fromJSON");let i=Gt[e.type];if(!i)throw new RangeError(`No selection type ${e.type} defined`);return i.fromJSON(t,e)}static jsonID(t,e){if(t in Gt)throw new RangeError("Duplicate use of selection JSON ID "+t);return Gt[t]=e,e.prototype.jsonID=t,e}getBookmark(){return se.between(this.$anchor,this.$head).getBookmark()}}Zt.prototype.visible=!0;class te{constructor(t,e){this.$from=t,this.$to=e}}let ee=!1;function ie(t){ee||t.parent.inlineContent||(ee=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class se extends Zt{constructor(t,e=t){ie(t),ie(e),super(t,e)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,e){let i=t.resolve(e.map(this.head));if(!i.parent.inlineContent)return Zt.near(i);let s=t.resolve(e.map(this.anchor));return new se(s.parent.inlineContent?s:i,i)}replace(t,e=w.empty){if(super.replace(t,e),e==w.empty){let e=this.$from.marksAcross(this.$to);e&&t.ensureMarks(e)}}eq(t){return t instanceof se&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new ne(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,e){if("number"!=typeof e.anchor||"number"!=typeof e.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new se(t.resolve(e.anchor),t.resolve(e.head))}static create(t,e,i=e){let s=t.resolve(e);return new this(s,i==e?s:t.resolve(i))}static between(t,e,i){let s=t.pos-e.pos;if(i&&!s||(i=s>=0?1:-1),!e.parent.inlineContent){let t=Zt.findFrom(e,i,!0)||Zt.findFrom(e,-i,!0);if(!t)return Zt.near(e,i);e=t.$head}return t.parent.inlineContent||(0==s||(t=(Zt.findFrom(t,-i,!0)||Zt.findFrom(t,i,!0)).$anchor).pos<e.pos!=s<0)&&(t=e),new se(t,e)}}Zt.jsonID("text",se);class ne{constructor(t,e){this.anchor=t,this.head=e}map(t){return new ne(t.map(this.anchor),t.map(this.head))}resolve(t){return se.between(t.resolve(this.anchor),t.resolve(this.head))}}class re extends Zt{constructor(t){let e=t.nodeAfter,i=t.node(0).resolve(t.pos+e.nodeSize);super(t,i),this.node=e}map(t,e){let{deleted:i,pos:s}=e.mapResult(this.anchor),n=t.resolve(s);return i?Zt.near(n):new re(n)}content(){return new w(u.from(this.node),0,0)}eq(t){return t instanceof re&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new he(this.anchor)}static fromJSON(t,e){if("number"!=typeof e.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new re(t.resolve(e.anchor))}static create(t,e){return new re(t.resolve(e))}static isSelectable(t){return!t.isText&&!1!==t.type.spec.selectable}}re.prototype.visible=!1,Zt.jsonID("node",re);class he{constructor(t){this.anchor=t}map(t){let{deleted:e,pos:i}=t.mapResult(this.anchor);return e?new ne(i,i):new he(i)}resolve(t){let e=t.resolve(this.anchor),i=e.nodeAfter;return i&&re.isSelectable(i)?new re(e):Zt.near(e)}}class oe extends Zt{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,e=w.empty){if(e==w.empty){t.delete(0,t.doc.content.size);let e=Zt.atStart(t.doc);e.eq(t.selection)||t.setSelection(e)}else super.replace(t,e)}toJSON(){return{type:"all"}}static fromJSON(t){return new oe(t)}map(t){return new oe(t)}eq(t){return t instanceof oe}getBookmark(){return le}}Zt.jsonID("all",oe);const le={map(){return this},resolve:t=>new oe(t)};function ue(t,e,i,s,n,r=!1){if(e.inlineContent)return se.create(t,i);for(let h=s-(n>0?0:1);n>0?h<e.childCount:h>=0;h+=n){let s=e.child(h);if(s.isAtom){if(!r&&re.isSelectable(s))return re.create(t,i-(n<0?s.nodeSize:0))}else{let e=ue(t,s,i+n,n<0?s.childCount:0,n,r);if(e)return e}i+=s.nodeSize*n}return null}function ae(t,e,i){let s=t.steps.length-1;if(s<e)return;let n,r=t.steps[s];(r instanceof Et||r instanceof Tt)&&(t.mapping.maps[s].forEach(((t,e,i,s)=>{null==n&&(n=s)})),t.setSelection(Zt.near(t.doc.resolve(n),i)))}let ce=class extends qt{constructor(t){super(t.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=t.selection,this.storedMarks=t.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(t){if(t.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=t,this.curSelectionFor=this.steps.length,this.updated=-3&this.updated|1,this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(t){return this.storedMarks=t,this.updated|=2,this}ensureMarks(t){return d.sameSet(this.storedMarks||this.selection.$from.marks(),t)||this.setStoredMarks(t),this}addStoredMark(t){return this.ensureMarks(t.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(t){return this.ensureMarks(t.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(2&this.updated)>0}addStep(t,e){super.addStep(t,e),this.updated=-3&this.updated,this.storedMarks=null}setTime(t){return this.time=t,this}replaceSelection(t){return this.selection.replace(this,t),this}replaceSelectionWith(t,e=!0){let i=this.selection;return e&&(t=t.mark(this.storedMarks||(i.empty?i.$from.marks():i.$from.marksAcross(i.$to)||d.none))),i.replaceWith(this,t),this}deleteSelection(){return this.selection.replace(this),this}insertText(t,e,i){let s=this.doc.type.schema;if(null==e)return t?this.replaceSelectionWith(s.text(t),!0):this.deleteSelection();{if(null==i&&(i=e),!t)return this.deleteRange(e,i);let n=this.storedMarks;if(!n){let t=this.doc.resolve(e);n=i==e?t.marks():t.marksAcross(this.doc.resolve(i))}return this.replaceRangeWith(e,i,s.text(t,n)),this.selection.empty||this.selection.to!=e+t.length||this.setSelection(Zt.near(this.selection.$to)),this}}setMeta(t,e){return this.meta["string"==typeof t?t:t.key]=e,this}getMeta(t){return this.meta["string"==typeof t?t:t.key]}get isGeneric(){for(let t in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}};function fe(t,e){return e&&t?t.bind(e):t}class de{constructor(t,e,i){this.name=t,this.init=fe(e.init,i),this.apply=fe(e.apply,i)}}const pe=[new de("doc",{init:t=>t.doc||t.schema.topNodeType.createAndFill(),apply:t=>t.doc}),new de("selection",{init:(t,e)=>t.selection||Zt.atStart(e.doc),apply:t=>t.selection}),new de("storedMarks",{init:t=>t.storedMarks||null,apply:(t,e,i,s)=>s.selection.$cursor?t.storedMarks:null}),new de("scrollToSelection",{init:()=>0,apply:(t,e)=>t.scrolledIntoView?e+1:e})];class we{constructor(t,e){this.schema=t,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=pe.slice(),e&&e.forEach((t=>{if(this.pluginsByKey[t.key])throw new RangeError("Adding different instances of a keyed plugin ("+t.key+")");this.plugins.push(t),this.pluginsByKey[t.key]=t,t.spec.state&&this.fields.push(new de(t.key,t.spec.state,t))}))}}class ge{constructor(t){this.config=t}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(t){return this.applyTransaction(t).state}filterTransaction(t,e=-1){for(let i=0;i<this.config.plugins.length;i++)if(i!=e){let e=this.config.plugins[i];if(e.spec.filterTransaction&&!e.spec.filterTransaction.call(e,t,this))return!1}return!0}applyTransaction(t){if(!this.filterTransaction(t))return{state:this,transactions:[]};let e=[t],i=this.applyInner(t),s=null;for(;;){let n=!1;for(let r=0;r<this.config.plugins.length;r++){let h=this.config.plugins[r];if(h.spec.appendTransaction){let o=s?s[r].n:0,l=s?s[r].state:this,u=o<e.length&&h.spec.appendTransaction.call(h,o?e.slice(o):e,l,i);if(u&&i.filterTransaction(u,r)){if(u.setMeta("appendedTransaction",t),!s){s=[];for(let t=0;t<this.config.plugins.length;t++)s.push(t<r?{state:i,n:e.length}:{state:this,n:0})}e.push(u),i=i.applyInner(u),n=!0}s&&(s[r]={state:i,n:e.length})}}if(!n)return{state:i,transactions:e}}}applyInner(t){if(!t.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let e=new ge(this.config),i=this.config.fields;for(let s=0;s<i.length;s++){let n=i[s];e[n.name]=n.apply(t,this[n.name],this,e)}return e}get tr(){return new ce(this)}static create(t){let e=new we(t.doc?t.doc.type.schema:t.schema,t.plugins),i=new ge(e);for(let s=0;s<e.fields.length;s++)i[e.fields[s].name]=e.fields[s].init(t,i);return i}reconfigure(t){let e=new we(this.schema,t.plugins),i=e.fields,s=new ge(e);for(let e=0;e<i.length;e++){let n=i[e].name;s[n]=this.hasOwnProperty(n)?this[n]:i[e].init(t,s)}return s}toJSON(t){let e={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(e.storedMarks=this.storedMarks.map((t=>t.toJSON()))),t&&"object"==typeof t)for(let i in t){if("doc"==i||"selection"==i)throw new RangeError("The JSON fields `doc` and `selection` are reserved");let s=t[i],n=s.spec.state;n&&n.toJSON&&(e[i]=n.toJSON.call(s,this[s.key]))}return e}static fromJSON(t,e,i){if(!e)throw new RangeError("Invalid input for EditorState.fromJSON");if(!t.schema)throw new RangeError("Required config field 'schema' missing");let s=new we(t.schema,t.plugins),n=new ge(s);return s.fields.forEach((s=>{if("doc"==s.name)n.doc=R.fromJSON(t.schema,e.doc);else if("selection"==s.name)n.selection=Zt.fromJSON(n.doc,e.selection);else if("storedMarks"==s.name)e.storedMarks&&(n.storedMarks=e.storedMarks.map(t.schema.markFromJSON));else{if(i)for(let r in i){let h=i[r],o=h.spec.state;if(h.key==s.name&&o&&o.fromJSON&&Object.prototype.hasOwnProperty.call(e,r))return void(n[s.name]=o.fromJSON.call(h,t,e[r],n))}n[s.name]=s.init(t,n)}})),n}}function me(t,e,i){for(let s in t){let n=t[s];n instanceof Function?n=n.bind(e):"handleDOMEvents"==s&&(n=me(n,e,{})),i[s]=n}return i}class ye{constructor(t){var e;this.spec=t,this.props={},t.props&&me(t.props,this,this.props),this.key=t.key?t.key.key:(e="plugin")in ve?e+"$"+ ++ve[e]:(ve[e]=0,e+"$")}getState(t){return t[this.key]}}const ve=Object.create(null),be=function(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e},Me=function(t){let e=t.assignedSlot||t.parentNode;return e&&11==e.nodeType?e.host:e};let ke=null;const Ae=function(t,e,i){let s=ke||(ke=document.createRange());return s.setEnd(t,null==i?t.nodeValue.length:i),s.setStart(t,e||0),s},xe=function(t,e,i,s){return i&&(Ce(t,e,i,s,-1)||Ce(t,e,i,s,1))},Se=/^(img|br|input|textarea|hr)$/i;function Ce(t,e,i,s,n){for(var r;;){if(t==i&&e==s)return!0;if(e==(n<0?0:Oe(t))){let i=t.parentNode;if(!i||1!=i.nodeType||Ee(t)||Se.test(t.nodeName)||"false"==t.contentEditable)return!1;e=be(t)+(n<0?0:1),t=i}else{if(1!=t.nodeType)return!1;{let i=t.childNodes[e+(n<0?-1:0)];if(1==i.nodeType&&"false"==i.contentEditable){if(!(null===(r=i.pmViewDesc)||void 0===r?void 0:r.ignoreForSelection))return!1;e+=n}else t=i,e=n<0?Oe(t):0}}}}function Oe(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function Ee(t){let e;for(let i=t;i&&!(e=i.pmViewDesc);i=i.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const Te=function(t){return t.focusNode&&xe(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function De(t,e){let i=document.createEvent("Event");return i.initEvent("keydown",!0,!0),i.keyCode=t,i.key=i.code=e,i}const $e="undefined"!=typeof navigator?navigator:null,Pe="undefined"!=typeof document?document:null,Re=$e&&$e.userAgent||"",Ie=/Edge\/(\d+)/.exec(Re),Ue=/MSIE \d/.exec(Re),je=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Re),Be=!!(Ue||je||Ie),Ne=Ue?document.documentMode:je?+je[1]:Ie?+Ie[1]:0,Fe=!Be&&/gecko\/(\d+)/i.test(Re),_e=!Be&&/Chrome\/(\d+)/.exec(Re),Le=!!_e,ze=_e?+_e[1]:0,Ye=!Be&&!!$e&&/Apple Computer/.test($e.vendor),We=Ye&&(/Mobile\/\w+/.test(Re)||!!$e&&$e.maxTouchPoints>2),Xe=We||!!$e&&/Mac/.test($e.platform),Je=!!$e&&/Win/.test($e.platform),He=/Android \d/.test(Re),Ve=!!Pe&&"webkitFontSmoothing"in Pe.documentElement.style,Qe=Ve?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Ke(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function qe(t,e){return"number"==typeof t?t:t[e]}function Ge(t){let e=t.getBoundingClientRect();return{left:e.left,right:e.left+t.clientWidth*(e.width/t.offsetWidth||1),top:e.top,bottom:e.top+t.clientHeight*(e.height/t.offsetHeight||1)}}function Ze(t,e,i){let s=t.someProp("scrollThreshold")||0,n=t.someProp("scrollMargin")||5,r=t.dom.ownerDocument;for(let h=i||t.dom;h;){if(1!=h.nodeType){h=Me(h);continue}let t=h,i=t==r.body,o=i?Ke(r):Ge(t),l=0,u=0;if(e.top<o.top+qe(s,"top")?u=-(o.top-e.top+qe(n,"top")):e.bottom>o.bottom-qe(s,"bottom")&&(u=e.bottom-e.top>o.bottom-o.top?e.top+qe(n,"top")-o.top:e.bottom-o.bottom+qe(n,"bottom")),e.left<o.left+qe(s,"left")?l=-(o.left-e.left+qe(n,"left")):e.right>o.right-qe(s,"right")&&(l=e.right-o.right+qe(n,"right")),l||u)if(i)r.defaultView.scrollBy(l,u);else{let i=t.scrollLeft,s=t.scrollTop;u&&(t.scrollTop+=u),l&&(t.scrollLeft+=l);let n=t.scrollLeft-i,r=t.scrollTop-s;e={left:e.left-n,top:e.top-r,right:e.right-n,bottom:e.bottom-r}}let a=i?"fixed":getComputedStyle(h).position;if(/^(fixed|sticky)$/.test(a))break;h="absolute"==a?h.offsetParent:Me(h)}}function ti(t){let e=[],i=t.ownerDocument;for(let s=t;s&&(e.push({dom:s,top:s.scrollTop,left:s.scrollLeft}),t!=i);s=Me(s));return e}function ei(t,e){for(let i=0;i<t.length;i++){let{dom:s,top:n,left:r}=t[i];s.scrollTop!=n+e&&(s.scrollTop=n+e),s.scrollLeft!=r&&(s.scrollLeft=r)}}let ii=null;function si(t,e){let i,s,n,r,h=2e8,o=0,l=e.top,u=e.top;for(let a=t.firstChild,c=0;a;a=a.nextSibling,c++){let t;if(1==a.nodeType)t=a.getClientRects();else{if(3!=a.nodeType)continue;t=Ae(a).getClientRects()}for(let f=0;f<t.length;f++){let d=t[f];if(d.top<=l&&d.bottom>=u){l=Math.max(d.bottom,l),u=Math.min(d.top,u);let t=d.left>e.left?d.left-e.left:d.right<e.left?e.left-d.right:0;if(t<h){i=a,h=t,s=t&&3==i.nodeType?{left:d.right<e.left?d.right:d.left,top:e.top}:e,1==a.nodeType&&t&&(o=c+(e.left>=(d.left+d.right)/2?1:0));continue}}else d.top>e.top&&!n&&d.left<=e.left&&d.right>=e.left&&(n=a,r={left:Math.max(d.left,Math.min(d.right,e.left)),top:d.top});!i&&(e.left>=d.right&&e.top>=d.top||e.left>=d.left&&e.top>=d.bottom)&&(o=c+1)}}return!i&&n&&(i=n,s=r,h=0),i&&3==i.nodeType?function(t,e){let i,s=t.nodeValue.length,n=document.createRange();for(let r=0;r<s;r++){n.setEnd(t,r+1),n.setStart(t,r);let s=li(n,1);if(s.top!=s.bottom&&ni(e,s)){i={node:t,offset:r+(e.left>=(s.left+s.right)/2?1:0)};break}}return n.detach(),i||{node:t,offset:0}}(i,s):!i||h&&1==i.nodeType?{node:t,offset:o}:si(i,s)}function ni(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function ri(t,e,i){let s=t.childNodes.length;if(s&&i.top<i.bottom)for(let n=Math.max(0,Math.min(s-1,Math.floor(s*(e.top-i.top)/(i.bottom-i.top))-2)),r=n;;){let i=t.childNodes[r];if(1==i.nodeType){let t=i.getClientRects();for(let s=0;s<t.length;s++){let n=t[s];if(ni(e,n))return ri(i,e,n)}}if((r=(r+1)%s)==n)break}return t}function hi(t,e){let i,s=t.dom.ownerDocument,n=0,r=function(t,e,i){if(t.caretPositionFromPoint)try{let s=t.caretPositionFromPoint(e,i);if(s)return{node:s.offsetNode,offset:Math.min(Oe(s.offsetNode),s.offset)}}catch(t){}if(t.caretRangeFromPoint){let s=t.caretRangeFromPoint(e,i);if(s)return{node:s.startContainer,offset:Math.min(Oe(s.startContainer),s.startOffset)}}}(s,e.left,e.top);r&&({node:i,offset:n}=r);let h,o=(t.root.elementFromPoint?t.root:s).elementFromPoint(e.left,e.top);if(!o||!t.dom.contains(1!=o.nodeType?o.parentNode:o)){let i=t.dom.getBoundingClientRect();if(!ni(e,i))return null;if(o=ri(t.dom,e,i),!o)return null}if(Ye)for(let t=o;i&&t;t=Me(t))t.draggable&&(i=void 0);if(o=function(t,e){let i=t.parentNode;return i&&/^li$/i.test(i.nodeName)&&e.left<t.getBoundingClientRect().left?i:t}(o,e),i){if(Fe&&1==i.nodeType&&(n=Math.min(n,i.childNodes.length),n<i.childNodes.length)){let t,s=i.childNodes[n];"IMG"==s.nodeName&&(t=s.getBoundingClientRect()).right<=e.left&&t.bottom>e.top&&n++}let s;Ve&&n&&1==i.nodeType&&1==(s=i.childNodes[n-1]).nodeType&&"false"==s.contentEditable&&s.getBoundingClientRect().top>=e.top&&n--,i==t.dom&&n==i.childNodes.length-1&&1==i.lastChild.nodeType&&e.top>i.lastChild.getBoundingClientRect().bottom?h=t.state.doc.content.size:0!=n&&1==i.nodeType&&"BR"==i.childNodes[n-1].nodeName||(h=function(t,e,i,s){let n=-1;for(let i=e,r=!1;i!=t.dom;){let e,h=t.docView.nearestDesc(i,!0);if(!h)return null;if(1==h.dom.nodeType&&(h.node.isBlock&&h.parent||!h.contentDOM)&&((e=h.dom.getBoundingClientRect()).width||e.height)&&(h.node.isBlock&&h.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(h.dom.nodeName)&&(!r&&e.left>s.left||e.top>s.top?n=h.posBefore:(!r&&e.right<s.left||e.bottom<s.top)&&(n=h.posAfter),r=!0),!h.contentDOM&&n<0&&!h.node.isText))return(h.node.isBlock?s.top<(e.top+e.bottom)/2:s.left<(e.left+e.right)/2)?h.posBefore:h.posAfter;i=h.dom.parentNode}return n>-1?n:t.docView.posFromDOM(e,i,-1)}(t,i,n,e))}null==h&&(h=function(t,e,i){let{node:s,offset:n}=si(e,i),r=-1;if(1==s.nodeType&&!s.firstChild){let t=s.getBoundingClientRect();r=t.left!=t.right&&i.left>(t.left+t.right)/2?1:-1}return t.docView.posFromDOM(s,n,r)}(t,o,e));let l=t.docView.nearestDesc(o,!0);return{pos:h,inside:l?l.posAtStart-l.border:-1}}function oi(t){return t.top<t.bottom||t.left<t.right}function li(t,e){let i=t.getClientRects();if(i.length){let t=i[e<0?0:i.length-1];if(oi(t))return t}return Array.prototype.find.call(i,oi)||t.getBoundingClientRect()}const ui=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function ai(t,e,i){let{node:s,offset:n,atom:r}=t.docView.domFromPos(e,i<0?-1:1),h=Ve||Fe;if(3==s.nodeType){if(!h||!ui.test(s.nodeValue)&&(i<0?n:n!=s.nodeValue.length)){let t=n,e=n,r=i<0?1:-1;return i<0&&!n?(e++,r=-1):i>=0&&n==s.nodeValue.length?(t--,r=1):i<0?t--:e++,ci(li(Ae(s,t,e),r),r<0)}{let t=li(Ae(s,n,n),i);if(Fe&&n&&/\s/.test(s.nodeValue[n-1])&&n<s.nodeValue.length){let e=li(Ae(s,n-1,n-1),-1);if(e.top==t.top){let i=li(Ae(s,n,n+1),-1);if(i.top!=t.top)return ci(i,i.left<e.left)}}return t}}if(!t.state.doc.resolve(e-(r||0)).parent.inlineContent){if(null==r&&n&&(i<0||n==Oe(s))){let t=s.childNodes[n-1];if(1==t.nodeType)return fi(t.getBoundingClientRect(),!1)}if(null==r&&n<Oe(s)){let t=s.childNodes[n];if(1==t.nodeType)return fi(t.getBoundingClientRect(),!0)}return fi(s.getBoundingClientRect(),i>=0)}if(null==r&&n&&(i<0||n==Oe(s))){let t=s.childNodes[n-1],e=3==t.nodeType?Ae(t,Oe(t)-(h?0:1)):1!=t.nodeType||"BR"==t.nodeName&&t.nextSibling?null:t;if(e)return ci(li(e,1),!1)}if(null==r&&n<Oe(s)){let t=s.childNodes[n];for(;t.pmViewDesc&&t.pmViewDesc.ignoreForCoords;)t=t.nextSibling;let e=t?3==t.nodeType?Ae(t,0,h?0:1):1==t.nodeType?t:null:null;if(e)return ci(li(e,-1),!0)}return ci(li(3==s.nodeType?Ae(s):s,-i),i>=0)}function ci(t,e){if(0==t.width)return t;let i=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:i,right:i}}function fi(t,e){if(0==t.height)return t;let i=e?t.top:t.bottom;return{top:i,bottom:i,left:t.left,right:t.right}}function di(t,e,i){let s=t.state,n=t.root.activeElement;s!=e&&t.updateState(e),n!=t.dom&&t.focus();try{return i()}finally{s!=e&&t.updateState(s),n!=t.dom&&n&&n.focus()}}const pi=/[\u0590-\u08ac]/;let wi=null,gi=null,mi=!1;class yi{constructor(t,e,i,s){this.parent=t,this.children=e,this.dom=i,this.contentDOM=s,this.dirty=0,i.pmViewDesc=this}matchesWidget(t){return!1}matchesMark(t){return!1}matchesNode(t,e,i){return!1}matchesHack(t){return!1}parseRule(){return null}stopEvent(t){return!1}get size(){let t=0;for(let e=0;e<this.children.length;e++)t+=this.children[e].size;return t}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let t=0;t<this.children.length;t++)this.children[t].destroy()}posBeforeChild(t){for(let e=0,i=this.posAtStart;;e++){let s=this.children[e];if(s==t)return i;i+=s.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(t,e,i){if(this.contentDOM&&this.contentDOM.contains(1==t.nodeType?t:t.parentNode)){if(i<0){let i,s;if(t==this.contentDOM)i=t.childNodes[e-1];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.previousSibling}for(;i&&(!(s=i.pmViewDesc)||s.parent!=this);)i=i.previousSibling;return i?this.posBeforeChild(s)+s.size:this.posAtStart}{let i,s;if(t==this.contentDOM)i=t.childNodes[e];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.nextSibling}for(;i&&(!(s=i.pmViewDesc)||s.parent!=this);)i=i.nextSibling;return i?this.posBeforeChild(s):this.posAtEnd}}let s;if(t==this.dom&&this.contentDOM)s=e>be(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))s=2&t.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==e)for(let e=t;;e=e.parentNode){if(e==this.dom){s=!1;break}if(e.previousSibling)break}if(null==s&&e==t.childNodes.length)for(let e=t;;e=e.parentNode){if(e==this.dom){s=!0;break}if(e.nextSibling)break}}return(null==s?i>0:s)?this.posAtEnd:this.posAtStart}nearestDesc(t,e=!1){for(let i=!0,s=t;s;s=s.parentNode){let n,r=this.getDesc(s);if(r&&(!e||r.node)){if(!i||!(n=r.nodeDOM)||(1==n.nodeType?n.contains(1==t.nodeType?t:t.parentNode):n==t))return r;i=!1}}}getDesc(t){let e=t.pmViewDesc;for(let t=e;t;t=t.parent)if(t==this)return e}posFromDOM(t,e,i){for(let s=t;s;s=s.parentNode){let n=this.getDesc(s);if(n)return n.localPosFromDOM(t,e,i)}return-1}descAt(t){for(let e=0,i=0;e<this.children.length;e++){let s=this.children[e],n=i+s.size;if(i==t&&n!=i){for(;!s.border&&s.children.length;)for(let t=0;t<s.children.length;t++){let e=s.children[t];if(e.size){s=e;break}}return s}if(t<n)return s.descAt(t-i-s.border);i=n}}domFromPos(t,e){if(!this.contentDOM)return{node:this.dom,offset:0,atom:t+1};let i=0,s=0;for(let e=0;i<this.children.length;i++){let n=this.children[i],r=e+n.size;if(r>t||n instanceof Si){s=t-e;break}e=r}if(s)return this.children[i].domFromPos(s-this.children[i].border,e);for(let t;i&&!(t=this.children[i-1]).size&&t instanceof vi&&t.side>=0;i--);if(e<=0){let t,s=!0;for(;t=i?this.children[i-1]:null,t&&t.dom.parentNode!=this.contentDOM;i--,s=!1);return t&&e&&s&&!t.border&&!t.domAtom?t.domFromPos(t.size,e):{node:this.contentDOM,offset:t?be(t.dom)+1:0}}{let t,s=!0;for(;t=i<this.children.length?this.children[i]:null,t&&t.dom.parentNode!=this.contentDOM;i++,s=!1);return t&&s&&!t.border&&!t.domAtom?t.domFromPos(0,e):{node:this.contentDOM,offset:t?be(t.dom):this.contentDOM.childNodes.length}}}parseRange(t,e,i=0){if(0==this.children.length)return{node:this.contentDOM,from:t,to:e,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let s=-1,n=-1;for(let r=i,h=0;;h++){let i=this.children[h],o=r+i.size;if(-1==s&&t<=o){let n=r+i.border;if(t>=n&&e<=o-i.border&&i.node&&i.contentDOM&&this.contentDOM.contains(i.contentDOM))return i.parseRange(t,e,n);t=r;for(let e=h;e>0;e--){let i=this.children[e-1];if(i.size&&i.dom.parentNode==this.contentDOM&&!i.emptyChildAt(1)){s=be(i.dom)+1;break}t-=i.size}-1==s&&(s=0)}if(s>-1&&(o>e||h==this.children.length-1)){e=o;for(let t=h+1;t<this.children.length;t++){let i=this.children[t];if(i.size&&i.dom.parentNode==this.contentDOM&&!i.emptyChildAt(-1)){n=be(i.dom);break}e+=i.size}-1==n&&(n=this.contentDOM.childNodes.length);break}r=o}return{node:this.contentDOM,from:t,to:e,fromOffset:s,toOffset:n}}emptyChildAt(t){if(this.border||!this.contentDOM||!this.children.length)return!1;let e=this.children[t<0?0:this.children.length-1];return 0==e.size||e.emptyChildAt(t)}domAfterPos(t){let{node:e,offset:i}=this.domFromPos(t,0);if(1!=e.nodeType||i==e.childNodes.length)throw new RangeError("No node after pos "+t);return e.childNodes[i]}setSelection(t,e,i,s=!1){let n=Math.min(t,e),r=Math.max(t,e);for(let h=0,o=0;h<this.children.length;h++){let l=this.children[h],u=o+l.size;if(n>o&&r<u)return l.setSelection(t-o-l.border,e-o-l.border,i,s);o=u}let h=this.domFromPos(t,t?-1:1),o=e==t?h:this.domFromPos(e,e?-1:1),l=i.root.getSelection(),u=i.domSelectionRange(),a=!1;if((Fe||Ye)&&t==e){let{node:t,offset:e}=h;if(3==t.nodeType){if(a=!(!e||"\n"!=t.nodeValue[e-1]),a&&e==t.nodeValue.length)for(let e,i=t;i;i=i.parentNode){if(e=i.nextSibling){"BR"==e.nodeName&&(h=o={node:e.parentNode,offset:be(e)+1});break}let t=i.pmViewDesc;if(t&&t.node&&t.node.isBlock)break}}else{let i=t.childNodes[e-1];a=i&&("BR"==i.nodeName||"false"==i.contentEditable)}}if(Fe&&u.focusNode&&u.focusNode!=o.node&&1==u.focusNode.nodeType){let t=u.focusNode.childNodes[u.focusOffset];t&&"false"==t.contentEditable&&(s=!0)}if(!(s||a&&Ye)&&xe(h.node,h.offset,u.anchorNode,u.anchorOffset)&&xe(o.node,o.offset,u.focusNode,u.focusOffset))return;let c=!1;if((l.extend||t==e)&&(!a||!Fe)){l.collapse(h.node,h.offset);try{t!=e&&l.extend(o.node,o.offset),c=!0}catch(t){}}if(!c){if(t>e){let t=h;h=o,o=t}let i=document.createRange();i.setEnd(o.node,o.offset),i.setStart(h.node,h.offset),l.removeAllRanges(),l.addRange(i)}}ignoreMutation(t){return!this.contentDOM&&"selection"!=t.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(t,e){for(let i=0,s=0;s<this.children.length;s++){let n=this.children[s],r=i+n.size;if(i==r?t<=r&&e>=i:t<r&&e>i){let s=i+n.border,h=r-n.border;if(t>=s&&e<=h)return this.dirty=t==i||e==r?2:1,void(t!=s||e!=h||!n.contentLost&&n.dom.parentNode==this.contentDOM?n.markDirty(t-s,e-s):n.dirty=3);n.dirty=n.dom!=n.contentDOM||n.dom.parentNode!=this.contentDOM||n.children.length?3:2}i=r}this.dirty=2}markParentsDirty(){let t=1;for(let e=this.parent;e;e=e.parent,t++){let i=1==t?2:1;e.dirty<i&&(e.dirty=i)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(t){return!1}}class vi extends yi{constructor(t,e,i,s){let n,r=e.type.toDOM;if("function"==typeof r&&(r=r(i,(()=>n?n.parent?n.parent.posBeforeChild(n):void 0:s))),!e.type.spec.raw){if(1!=r.nodeType){let t=document.createElement("span");t.appendChild(r),r=t}r.contentEditable="false",r.classList.add("ProseMirror-widget")}super(t,[],r,null),this.widget=e,this.widget=e,n=this}matchesWidget(t){return 0==this.dirty&&t.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(t){let e=this.widget.spec.stopEvent;return!!e&&e(t)}ignoreMutation(t){return"selection"!=t.type||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class bi extends yi{constructor(t,e,i,s){super(t,[],e,null),this.textDOM=i,this.text=s}get size(){return this.text.length}localPosFromDOM(t,e){return t!=this.textDOM?this.posAtStart+(e?this.size:0):this.posAtStart+e}domFromPos(t){return{node:this.textDOM,offset:t}}ignoreMutation(t){return"characterData"===t.type&&t.target.nodeValue==t.oldValue}}class Mi extends yi{constructor(t,e,i,s,n){super(t,[],i,s),this.mark=e,this.spec=n}static create(t,e,i,s){let n=s.nodeViews[e.type.name],r=n&&n(e,s,i);return r&&r.dom||(r=at.renderSpec(document,e.type.spec.toDOM(e,i),null,e.attrs)),new Mi(t,e,r.dom,r.contentDOM||r.dom,r)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(t){return 3!=this.dirty&&this.mark.eq(t)}markDirty(t,e){if(super.markDirty(t,e),0!=this.dirty){let t=this.parent;for(;!t.node;)t=t.parent;t.dirty<this.dirty&&(t.dirty=this.dirty),this.dirty=0}}slice(t,e,i){let s=Mi.create(this.parent,this.mark,!0,i),n=this.children,r=this.size;e<r&&(n=Ni(n,e,r,i)),t>0&&(n=Ni(n,0,t,i));for(let t=0;t<n.length;t++)n[t].parent=s;return s.children=n,s}ignoreMutation(t){return this.spec.ignoreMutation?this.spec.ignoreMutation(t):super.ignoreMutation(t)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class ki extends yi{constructor(t,e,i,s,n,r,h,o,l){super(t,[],n,r),this.node=e,this.outerDeco=i,this.innerDeco=s,this.nodeDOM=h}static create(t,e,i,s,n,r){let h,o=n.nodeViews[e.type.name],l=o&&o(e,n,(()=>h?h.parent?h.parent.posBeforeChild(h):void 0:r),i,s),u=l&&l.dom,a=l&&l.contentDOM;if(e.isText)if(u){if(3!=u.nodeType)throw new RangeError("Text must be rendered as a DOM text node")}else u=document.createTextNode(e.text);else if(!u){let t=at.renderSpec(document,e.type.spec.toDOM(e),null,e.attrs);({dom:u,contentDOM:a}=t)}a||e.isText||"BR"==u.nodeName||(u.hasAttribute("contenteditable")||(u.contentEditable="false"),e.type.spec.draggable&&(u.draggable=!0));let c=u;return u=Ri(u,i,e),l?h=new Ci(t,e,i,s,u,a||null,c,l,n,r+1):e.isText?new xi(t,e,i,s,u,c,n):new ki(t,e,i,s,u,a||null,c,n,r+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if("pre"==this.node.type.whitespace&&(t.preserveWhitespace="full"),this.contentDOM)if(this.contentLost){for(let e=this.children.length-1;e>=0;e--){let i=this.children[e];if(this.dom.contains(i.dom.parentNode)){t.contentElement=i.dom.parentNode;break}}t.contentElement||(t.getContent=()=>u.empty)}else t.contentElement=this.contentDOM;else t.getContent=()=>this.node.content;return t}matchesNode(t,e,i){return 0==this.dirty&&t.eq(this.node)&&Ii(e,this.outerDeco)&&i.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(t,e){let i=this.node.inlineContent,s=e,n=t.composing?this.localCompositionInfo(t,e):null,r=n&&n.pos>-1?n:null,h=n&&n.pos<0,o=new ji(this,r&&r.node,t);!function(t,e,i,s){let n=e.locals(t),r=0;if(0==n.length){for(let i=0;i<t.childCount;i++){let h=t.child(i);s(h,n,e.forChild(r,h),i),r+=h.nodeSize}return}let h=0,o=[],l=null;for(let u=0;;){let a,c,f,d;for(;h<n.length&&n[h].to==r;){let t=n[h++];t.widget&&(a?(c||(c=[a])).push(t):a=t)}if(a)if(c){c.sort(Bi);for(let t=0;t<c.length;t++)i(c[t],u,!!l)}else i(a,u,!!l);if(l)d=-1,f=l,l=null;else{if(!(u<t.childCount))break;d=u,f=t.child(u++)}for(let t=0;t<o.length;t++)o[t].to<=r&&o.splice(t--,1);for(;h<n.length&&n[h].from<=r&&n[h].to>r;)o.push(n[h++]);let p=r+f.nodeSize;if(f.isText){let t=p;h<n.length&&n[h].from<t&&(t=n[h].from);for(let e=0;e<o.length;e++)o[e].to<t&&(t=o[e].to);t<p&&(l=f.cut(t-r),f=f.cut(0,t-r),p=t,d=-1)}else for(;h<n.length&&n[h].to<p;)h++;s(f,f.isInline&&!f.isLeaf?o.filter((t=>!t.inline)):o.slice(),e.forChild(r,f),d),r=p}}(this.node,this.innerDeco,((e,n,r)=>{e.spec.marks?o.syncToMarks(e.spec.marks,i,t):e.type.side>=0&&!r&&o.syncToMarks(n==this.node.childCount?d.none:this.node.child(n).marks,i,t),o.placeWidget(e,t,s)}),((e,r,l,u)=>{let a;o.syncToMarks(e.marks,i,t),o.findNodeMatch(e,r,l,u)||h&&t.state.selection.from>s&&t.state.selection.to<s+e.nodeSize&&(a=o.findIndexWithChild(n.node))>-1&&o.updateNodeAt(e,r,l,a,t)||o.updateNextNode(e,r,l,t,u,s)||o.addNode(e,r,l,t,s),s+=e.nodeSize})),o.syncToMarks([],i,t),this.node.isTextblock&&o.addTextblockHacks(),o.destroyRest(),(o.changed||2==this.dirty)&&(r&&this.protectLocalComposition(t,r),Oi(this.contentDOM,this.children,t),We&&function(t){if("UL"==t.nodeName||"OL"==t.nodeName){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t),t.style.cssText=e}}(this.dom))}localCompositionInfo(t,e){let{from:i,to:s}=t.state.selection;if(!(t.state.selection instanceof se)||i<e||s>e+this.node.content.size)return null;let n=t.input.compositionNode;if(!n||!this.dom.contains(n.parentNode))return null;if(this.node.inlineContent){let t=n.nodeValue,r=function(t,e,i,s){for(let n=0,r=0;n<t.childCount&&r<=s;){let h=t.child(n++),o=r;if(r+=h.nodeSize,!h.isText)continue;let l=h.text;for(;n<t.childCount;){let e=t.child(n++);if(r+=e.nodeSize,!e.isText)break;l+=e.text}if(r>=i){if(r>=s&&l.slice(s-e.length-o,s-o)==e)return s-e.length;let t=o<s?l.lastIndexOf(e,s-o-1):-1;if(t>=0&&t+e.length+o>=i)return o+t;if(i==s&&l.length>=s+e.length-o&&l.slice(s-o,s-o+e.length)==e)return s}}return-1}(this.node.content,t,i-e,s-e);return r<0?null:{node:n,pos:r,text:t}}return{node:n,pos:-1,text:""}}protectLocalComposition(t,{node:e,pos:i,text:s}){if(this.getDesc(e))return;let n=e;for(;n.parentNode!=this.contentDOM;n=n.parentNode){for(;n.previousSibling;)n.parentNode.removeChild(n.previousSibling);for(;n.nextSibling;)n.parentNode.removeChild(n.nextSibling);n.pmViewDesc&&(n.pmViewDesc=void 0)}let r=new bi(this,n,e,s);t.input.compositionNodes.push(r),this.children=Ni(this.children,i,i+s.length,t,r)}update(t,e,i,s){return!(3==this.dirty||!t.sameMarkup(this.node)||(this.updateInner(t,e,i,s),0))}updateInner(t,e,i,s){this.updateOuterDeco(e),this.node=t,this.innerDeco=i,this.contentDOM&&this.updateChildren(s,this.posAtStart),this.dirty=0}updateOuterDeco(t){if(Ii(t,this.outerDeco))return;let e=1!=this.nodeDOM.nodeType,i=this.dom;this.dom=$i(this.dom,this.nodeDOM,Di(this.outerDeco,this.node,e),Di(t,this.node,e)),this.dom!=i&&(i.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=t}selectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||(this.nodeDOM.draggable=!0))}deselectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Ai(t,e,i,s,n){Ri(s,e,t);let r=new ki(void 0,t,e,i,s,s,s,n,0);return r.contentDOM&&r.updateChildren(n,0),r}class xi extends ki{constructor(t,e,i,s,n,r,h){super(t,e,i,s,n,null,r,h,0)}parseRule(){let t=this.nodeDOM.parentNode;for(;t&&t!=this.dom&&!t.pmIsDeco;)t=t.parentNode;return{skip:t||!0}}update(t,e,i,s){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!t.sameMarkup(this.node)||(this.updateOuterDeco(e),0==this.dirty&&t.text==this.node.text||t.text==this.nodeDOM.nodeValue||(this.nodeDOM.nodeValue=t.text,s.trackWrites==this.nodeDOM&&(s.trackWrites=null)),this.node=t,this.dirty=0,0))}inParent(){let t=this.parent.contentDOM;for(let e=this.nodeDOM;e;e=e.parentNode)if(e==t)return!0;return!1}domFromPos(t){return{node:this.nodeDOM,offset:t}}localPosFromDOM(t,e,i){return t==this.nodeDOM?this.posAtStart+Math.min(e,this.node.text.length):super.localPosFromDOM(t,e,i)}ignoreMutation(t){return"characterData"!=t.type&&"selection"!=t.type}slice(t,e,i){let s=this.node.cut(t,e),n=document.createTextNode(s.text);return new xi(this.parent,s,this.outerDeco,this.innerDeco,n,n,i)}markDirty(t,e){super.markDirty(t,e),this.dom==this.nodeDOM||0!=t&&e!=this.nodeDOM.nodeValue.length||(this.dirty=3)}get domAtom(){return!1}isText(t){return this.node.text==t}}class Si extends yi{parseRule(){return{ignore:!0}}matchesHack(t){return 0==this.dirty&&this.dom.nodeName==t}get domAtom(){return!0}get ignoreForCoords(){return"IMG"==this.dom.nodeName}}class Ci extends ki{constructor(t,e,i,s,n,r,h,o,l,u){super(t,e,i,s,n,r,h,l,u),this.spec=o}update(t,e,i,s){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==t.type||this.spec.multiType)){let n=this.spec.update(t,e,i);return n&&this.updateInner(t,e,i,s),n}return!(!this.contentDOM&&!t.isLeaf)&&super.update(t,e,i,s)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(t,e,i,s){this.spec.setSelection?this.spec.setSelection(t,e,i.root):super.setSelection(t,e,i,s)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(t){return!!this.spec.stopEvent&&this.spec.stopEvent(t)}ignoreMutation(t){return this.spec.ignoreMutation?this.spec.ignoreMutation(t):super.ignoreMutation(t)}}function Oi(t,e,i){let s=t.firstChild,n=!1;for(let r=0;r<e.length;r++){let h=e[r],o=h.dom;if(o.parentNode==t){for(;o!=s;)s=Ui(s),n=!0;s=s.nextSibling}else n=!0,t.insertBefore(o,s);if(h instanceof Mi){let e=s?s.previousSibling:t.lastChild;Oi(h.contentDOM,h.children,i),s=e?e.nextSibling:t.firstChild}}for(;s;)s=Ui(s),n=!0;n&&i.trackWrites==t&&(i.trackWrites=null)}const Ei=function(t){t&&(this.nodeName=t)};Ei.prototype=Object.create(null);const Ti=[new Ei];function Di(t,e,i){if(0==t.length)return Ti;let s=i?Ti[0]:new Ei,n=[s];for(let r=0;r<t.length;r++){let h=t[r].type.attrs;if(h){h.nodeName&&n.push(s=new Ei(h.nodeName));for(let t in h){let r=h[t];null!=r&&(i&&1==n.length&&n.push(s=new Ei(e.isInline?"span":"div")),"class"==t?s.class=(s.class?s.class+" ":"")+r:"style"==t?s.style=(s.style?s.style+";":"")+r:"nodeName"!=t&&(s[t]=r))}}}return n}function $i(t,e,i,s){if(i==Ti&&s==Ti)return e;let n=e;for(let e=0;e<s.length;e++){let r=s[e],h=i[e];if(e){let e;h&&h.nodeName==r.nodeName&&n!=t&&(e=n.parentNode)&&e.nodeName.toLowerCase()==r.nodeName||(e=document.createElement(r.nodeName),e.pmIsDeco=!0,e.appendChild(n),h=Ti[0]),n=e}Pi(n,h||Ti[0],r)}return n}function Pi(t,e,i){for(let s in e)"class"==s||"style"==s||"nodeName"==s||s in i||t.removeAttribute(s);for(let s in i)"class"!=s&&"style"!=s&&"nodeName"!=s&&i[s]!=e[s]&&t.setAttribute(s,i[s]);if(e.class!=i.class){let s=e.class?e.class.split(" ").filter(Boolean):[],n=i.class?i.class.split(" ").filter(Boolean):[];for(let e=0;e<s.length;e++)-1==n.indexOf(s[e])&&t.classList.remove(s[e]);for(let e=0;e<n.length;e++)-1==s.indexOf(n[e])&&t.classList.add(n[e]);0==t.classList.length&&t.removeAttribute("class")}if(e.style!=i.style){if(e.style){let i,s=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;i=s.exec(e.style);)t.style.removeProperty(i[1])}i.style&&(t.style.cssText+=i.style)}}function Ri(t,e,i){return $i(t,t,Ti,Di(e,i,1!=t.nodeType))}function Ii(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].type.eq(e[i].type))return!1;return!0}function Ui(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}class ji{constructor(t,e,i){this.lock=e,this.view=i,this.index=0,this.stack=[],this.changed=!1,this.top=t,this.preMatch=function(t,e){let i=e,s=i.children.length,n=t.childCount,r=new Map,h=[];t:for(;n>0;){let o;for(;;)if(s){let t=i.children[s-1];if(!(t instanceof Mi)){o=t,s--;break}i=t,s=t.children.length}else{if(i==e)break t;s=i.parent.children.indexOf(i),i=i.parent}let l=o.node;if(l){if(l!=t.child(n-1))break;--n,r.set(o,n),h.push(o)}}return{index:n,matched:r,matches:h.reverse()}}(t.node.content,t)}destroyBetween(t,e){if(t!=e){for(let i=t;i<e;i++)this.top.children[i].destroy();this.top.children.splice(t,e-t),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(t,e,i){let s=0,n=this.stack.length>>1,r=Math.min(n,t.length);for(;s<r&&(s==n-1?this.top:this.stack[s+1<<1]).matchesMark(t[s])&&!1!==t[s].type.spec.spanning;)s++;for(;s<n;)this.destroyRest(),this.top.dirty=0,this.index=this.stack.pop(),this.top=this.stack.pop(),n--;for(;n<t.length;){this.stack.push(this.top,this.index+1);let s=-1;for(let e=this.index;e<Math.min(this.index+3,this.top.children.length);e++){let i=this.top.children[e];if(i.matchesMark(t[n])&&!this.isLocked(i.dom)){s=e;break}}if(s>-1)s>this.index&&(this.changed=!0,this.destroyBetween(this.index,s)),this.top=this.top.children[this.index];else{let s=Mi.create(this.top,t[n],e,i);this.top.children.splice(this.index,0,s),this.top=s,this.changed=!0}this.index=0,n++}}findNodeMatch(t,e,i,s){let n,r=-1;if(s>=this.preMatch.index&&(n=this.preMatch.matches[s-this.preMatch.index]).parent==this.top&&n.matchesNode(t,e,i))r=this.top.children.indexOf(n,this.index);else for(let s=this.index,n=Math.min(this.top.children.length,s+5);s<n;s++){let n=this.top.children[s];if(n.matchesNode(t,e,i)&&!this.preMatch.matched.has(n)){r=s;break}}return!(r<0||(this.destroyBetween(this.index,r),this.index++,0))}updateNodeAt(t,e,i,s,n){let r=this.top.children[s];return 3==r.dirty&&r.dom==r.contentDOM&&(r.dirty=2),!!r.update(t,e,i,n)&&(this.destroyBetween(this.index,s),this.index++,!0)}findIndexWithChild(t){for(;;){let e=t.parentNode;if(!e)return-1;if(e==this.top.contentDOM){let e=t.pmViewDesc;if(e)for(let t=this.index;t<this.top.children.length;t++)if(this.top.children[t]==e)return t;return-1}t=e}}updateNextNode(t,e,i,s,n,r){for(let h=this.index;h<this.top.children.length;h++){let o=this.top.children[h];if(o instanceof ki){let l=this.preMatch.matched.get(o);if(null!=l&&l!=n)return!1;let u,a=o.dom,c=this.isLocked(a)&&!(t.isText&&o.node&&o.node.isText&&o.nodeDOM.nodeValue==t.text&&3!=o.dirty&&Ii(e,o.outerDeco));if(!c&&o.update(t,e,i,s))return this.destroyBetween(this.index,h),o.dom!=a&&(this.changed=!0),this.index++,!0;if(!c&&(u=this.recreateWrapper(o,t,e,i,s,r)))return this.destroyBetween(this.index,h),this.top.children[this.index]=u,u.contentDOM&&(u.dirty=2,u.updateChildren(s,r+1),u.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(t,e,i,s,n,r){if(t.dirty||e.isAtom||!t.children.length||!t.node.content.eq(e.content)||!Ii(i,t.outerDeco)||!s.eq(t.innerDeco))return null;let h=ki.create(this.top,e,i,s,n,r);if(h.contentDOM){h.children=t.children,t.children=[];for(let t of h.children)t.parent=h}return t.destroy(),h}addNode(t,e,i,s,n){let r=ki.create(this.top,t,e,i,s,n);r.contentDOM&&r.updateChildren(s,n+1),this.top.children.splice(this.index++,0,r),this.changed=!0}placeWidget(t,e,i){let s=this.index<this.top.children.length?this.top.children[this.index]:null;if(!s||!s.matchesWidget(t)||t!=s.widget&&s.widget.type.toDOM.parentNode){let s=new vi(this.top,t,e,i);this.top.children.splice(this.index++,0,s),this.changed=!0}else this.index++}addTextblockHacks(){let t=this.top.children[this.index-1],e=this.top;for(;t instanceof Mi;)e=t,t=e.children[e.children.length-1];(!t||!(t instanceof xi)||/\n$/.test(t.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(t.node.text))&&((Ye||Le)&&t&&"false"==t.dom.contentEditable&&this.addHackNode("IMG",e),this.addHackNode("BR",this.top))}addHackNode(t,e){if(e==this.top&&this.index<e.children.length&&e.children[this.index].matchesHack(t))this.index++;else{let i=document.createElement(t);"IMG"==t&&(i.className="ProseMirror-separator",i.alt=""),"BR"==t&&(i.className="ProseMirror-trailingBreak");let s=new Si(this.top,[],i,null);e!=this.top?e.children.push(s):e.children.splice(this.index++,0,s),this.changed=!0}}isLocked(t){return this.lock&&(t==this.lock||1==t.nodeType&&t.contains(this.lock.parentNode))}}function Bi(t,e){return t.type.side-e.type.side}function Ni(t,e,i,s,n){let r=[];for(let h=0,o=0;h<t.length;h++){let l=t[h],u=o,a=o+=l.size;u>=i||a<=e?r.push(l):(u<e&&r.push(l.slice(0,e-u,s)),n&&(r.push(n),n=void 0),a>i&&r.push(l.slice(i-u,l.size,s)))}return r}function Fi(t,e=null){let i=t.domSelectionRange(),s=t.state.doc;if(!i.focusNode)return null;let n=t.docView.nearestDesc(i.focusNode),r=n&&0==n.size,h=t.docView.posFromDOM(i.focusNode,i.focusOffset,1);if(h<0)return null;let o,l,u=s.resolve(h);if(Te(i)){for(o=h;n&&!n.node;)n=n.parent;let t=n.node;if(n&&t.isAtom&&re.isSelectable(t)&&n.parent&&(!t.isInline||!function(t,e,i){for(let s=0==e,n=e==Oe(t);s||n;){if(t==i)return!0;let e=be(t);if(!(t=t.parentNode))return!1;s=s&&0==e,n=n&&e==Oe(t)}}(i.focusNode,i.focusOffset,n.dom))){let t=n.posBefore;l=new re(h==t?u:s.resolve(t))}}else{if(i instanceof t.dom.ownerDocument.defaultView.Selection&&i.rangeCount>1){let e=h,n=h;for(let s=0;s<i.rangeCount;s++){let r=i.getRangeAt(s);e=Math.min(e,t.docView.posFromDOM(r.startContainer,r.startOffset,1)),n=Math.max(n,t.docView.posFromDOM(r.endContainer,r.endOffset,-1))}if(e<0)return null;[o,h]=n==t.state.selection.anchor?[n,e]:[e,n],u=s.resolve(h)}else o=t.docView.posFromDOM(i.anchorNode,i.anchorOffset,1);if(o<0)return null}let a=s.resolve(o);return l||(l=Vi(t,a,u,"pointer"==e||t.state.selection.head<u.pos&&!r?1:-1)),l}function _i(t){return t.editable?t.hasFocus():Ki(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function Li(t,e=!1){let i=t.state.selection;if(Ji(t,i),_i(t)){if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&Le){let e=t.domSelectionRange(),i=t.domObserver.currentSelection;if(e.anchorNode&&i.anchorNode&&xe(e.anchorNode,e.anchorOffset,i.anchorNode,i.anchorOffset))return t.input.mouseDown.delayedSelectionSync=!0,void t.domObserver.setCurSelection()}if(t.domObserver.disconnectSelection(),t.cursorWrapper)!function(t){let e=t.domSelection();if(!e)return;let i=t.cursorWrapper.dom,s="IMG"==i.nodeName;s?e.collapse(i.parentNode,be(i)+1):e.collapse(i,0),!s&&!t.state.selection.visible&&Be&&Ne<=11&&(i.disabled=!0,i.disabled=!1)}(t);else{let s,n,{anchor:r,head:h}=i;!zi||i instanceof se||(i.$from.parent.inlineContent||(s=Yi(t,i.from)),i.empty||i.$from.parent.inlineContent||(n=Yi(t,i.to))),t.docView.setSelection(r,h,t,e),zi&&(s&&Xi(s),n&&Xi(n)),i.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(t){let e=t.dom.ownerDocument;e.removeEventListener("selectionchange",t.input.hideSelectionGuard);let i=t.domSelectionRange(),s=i.anchorNode,n=i.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{i.anchorNode==s&&i.anchorOffset==n||(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout((()=>{_i(t)&&!t.state.selection.visible||t.dom.classList.remove("ProseMirror-hideselection")}),20))})}(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}const zi=Ye||Le&&ze<63;function Yi(t,e){let{node:i,offset:s}=t.docView.domFromPos(e,0),n=s<i.childNodes.length?i.childNodes[s]:null,r=s?i.childNodes[s-1]:null;if(Ye&&n&&"false"==n.contentEditable)return Wi(n);if(!(n&&"false"!=n.contentEditable||r&&"false"!=r.contentEditable)){if(n)return Wi(n);if(r)return Wi(r)}}function Wi(t){return t.contentEditable="true",Ye&&t.draggable&&(t.draggable=!1,t.wasDraggable=!0),t}function Xi(t){t.contentEditable="false",t.wasDraggable&&(t.draggable=!0,t.wasDraggable=null)}function Ji(t,e){if(e instanceof re){let i=t.docView.descAt(e.from);i!=t.lastSelectedViewDesc&&(Hi(t),i&&i.selectNode(),t.lastSelectedViewDesc=i)}else Hi(t)}function Hi(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Vi(t,e,i,s){return t.someProp("createSelectionBetween",(s=>s(t,e,i)))||se.between(e,i,s)}function Qi(t){return!(t.editable&&!t.hasFocus())&&Ki(t)}function Ki(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(3==e.anchorNode.nodeType?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(3==e.focusNode.nodeType?e.focusNode.parentNode:e.focusNode))}catch(t){return!1}}function qi(t,e){let{$anchor:i,$head:s}=t.selection,n=e>0?i.max(s):i.min(s),r=n.parent.inlineContent?n.depth?t.doc.resolve(e>0?n.after():n.before()):null:n;return r&&Zt.findFrom(r,e)}function Gi(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function Zi(t,e,i){let s=t.state.selection;if(!(s instanceof se)){if(s instanceof re&&s.node.isInline)return Gi(t,new se(e>0?s.$to:s.$from));{let i=qi(t.state,e);return!!i&&Gi(t,i)}}if(i.indexOf("s")>-1){let{$head:i}=s,n=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!n||n.isText||!n.isLeaf)return!1;let r=t.state.doc.resolve(i.pos+n.nodeSize*(e<0?-1:1));return Gi(t,new se(s.$anchor,r))}if(!s.empty)return!1;if(t.endOfTextblock(e>0?"forward":"backward")){let i=qi(t.state,e);return!!(i&&i instanceof re)&&Gi(t,i)}if(!(Xe&&i.indexOf("m")>-1)){let i,n=s.$head,r=n.textOffset?null:e<0?n.nodeBefore:n.nodeAfter;if(!r||r.isText)return!1;let h=e<0?n.pos-r.nodeSize:n.pos;return!!(r.isAtom||(i=t.docView.descAt(h))&&!i.contentDOM)&&(re.isSelectable(r)?Gi(t,new re(e<0?t.state.doc.resolve(n.pos-r.nodeSize):n)):!!Ve&&Gi(t,new se(t.state.doc.resolve(e<0?h:h+r.nodeSize))))}}function ts(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function es(t,e){let i=t.pmViewDesc;return i&&0==i.size&&(e<0||t.nextSibling||"BR"!=t.nodeName)}function is(t,e){return e<0?function(t){let e=t.domSelectionRange(),i=e.focusNode,s=e.focusOffset;if(!i)return;let n,r,h=!1;for(Fe&&1==i.nodeType&&s<ts(i)&&es(i.childNodes[s],-1)&&(h=!0);;)if(s>0){if(1!=i.nodeType)break;{let t=i.childNodes[s-1];if(es(t,-1))n=i,r=--s;else{if(3!=t.nodeType)break;i=t,s=i.nodeValue.length}}}else{if(ss(i))break;{let e=i.previousSibling;for(;e&&es(e,-1);)n=i.parentNode,r=be(e),e=e.previousSibling;if(e)i=e,s=ts(i);else{if(i=i.parentNode,i==t.dom)break;s=0}}}h?ns(t,i,s):n&&ns(t,n,r)}(t):function(t){let e=t.domSelectionRange(),i=e.focusNode,s=e.focusOffset;if(!i)return;let n,r,h=ts(i);for(;;)if(s<h){if(1!=i.nodeType)break;if(!es(i.childNodes[s],1))break;n=i,r=++s}else{if(ss(i))break;{let e=i.nextSibling;for(;e&&es(e,1);)n=e.parentNode,r=be(e)+1,e=e.nextSibling;if(e)i=e,s=0,h=ts(i);else{if(i=i.parentNode,i==t.dom)break;s=h=0}}}n&&ns(t,n,r)}(t)}function ss(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function ns(t,e,i){if(3!=e.nodeType){let t,s;(s=function(t,e){for(;t&&e==t.childNodes.length&&!Ee(t);)e=be(t)+1,t=t.parentNode;for(;t&&e<t.childNodes.length;){let i=t.childNodes[e];if(3==i.nodeType)return i;if(1==i.nodeType&&"false"==i.contentEditable)break;t=i,e=0}}(e,i))?(e=s,i=0):(t=function(t,e){for(;t&&!e&&!Ee(t);)e=be(t),t=t.parentNode;for(;t&&e;){let i=t.childNodes[e-1];if(3==i.nodeType)return i;if(1==i.nodeType&&"false"==i.contentEditable)break;e=(t=i).childNodes.length}}(e,i))&&(e=t,i=t.nodeValue.length)}let s=t.domSelection();if(!s)return;if(Te(s)){let t=document.createRange();t.setEnd(e,i),t.setStart(e,i),s.removeAllRanges(),s.addRange(t)}else s.extend&&s.extend(e,i);t.domObserver.setCurSelection();let{state:n}=t;setTimeout((()=>{t.state==n&&Li(t)}),50)}function rs(t,e){let i=t.state.doc.resolve(e);if(!Le&&!Je&&i.parent.inlineContent){let s=t.coordsAtPos(e);if(e>i.start()){let i=t.coordsAtPos(e-1),n=(i.top+i.bottom)/2;if(n>s.top&&n<s.bottom&&Math.abs(i.left-s.left)>1)return i.left<s.left?"ltr":"rtl"}if(e<i.end()){let i=t.coordsAtPos(e+1),n=(i.top+i.bottom)/2;if(n>s.top&&n<s.bottom&&Math.abs(i.left-s.left)>1)return i.left>s.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(t.dom).direction?"rtl":"ltr"}function hs(t,e,i){let s=t.state.selection;if(s instanceof se&&!s.empty||i.indexOf("s")>-1)return!1;if(Xe&&i.indexOf("m")>-1)return!1;let{$from:n,$to:r}=s;if(!n.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let i=qi(t.state,e);if(i&&i instanceof re)return Gi(t,i)}if(!n.parent.inlineContent){let i=e<0?n:r,h=s instanceof oe?Zt.near(i,e):Zt.findFrom(i,e);return!!h&&Gi(t,h)}return!1}function ls(t,e){if(!(t.state.selection instanceof se))return!0;let{$head:i,$anchor:s,empty:n}=t.state.selection;if(!i.sameParent(s))return!0;if(!n)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let r=!i.textOffset&&(e<0?i.nodeBefore:i.nodeAfter);if(r&&!r.isText){let s=t.state.tr;return e<0?s.delete(i.pos-r.nodeSize,i.pos):s.delete(i.pos,i.pos+r.nodeSize),t.dispatch(s),!0}return!1}function us(t,e,i){t.domObserver.stop(),e.contentEditable=i,t.domObserver.start()}function as(t,e){t.someProp("transformCopied",(i=>{e=i(e,t)}));let i=[],{content:s,openStart:n,openEnd:r}=e;for(;n>1&&r>1&&1==s.childCount&&1==s.firstChild.childCount;){n--,r--;let t=s.firstChild;i.push(t.type.name,t.attrs!=t.type.defaultAttrs?t.attrs:null),s=t.content}let h=t.someProp("clipboardSerializer")||at.fromSchema(t.state.schema),o=bs(),l=o.createElement("div");l.appendChild(h.serializeFragment(s,{document:o}));let u,a=l.firstChild,c=0;for(;a&&1==a.nodeType&&(u=ys[a.nodeName.toLowerCase()]);){for(let t=u.length-1;t>=0;t--){let e=o.createElement(u[t]);for(;l.firstChild;)e.appendChild(l.firstChild);l.appendChild(e),c++}a=l.firstChild}a&&1==a.nodeType&&a.setAttribute("data-pm-slice",`${n} ${r}${c?` -${c}`:""} ${JSON.stringify(i)}`);let f=t.someProp("clipboardTextSerializer",(i=>i(e,t)))||e.content.textBetween(0,e.content.size,"\n\n");return{dom:l,text:f,slice:e}}function cs(t,e,i,s,n){let r,h,o=n.parent.type.spec.code;if(!i&&!e)return null;let l=!!e&&(s||o||!i);if(l){if(t.someProp("transformPastedText",(i=>{e=i(e,o||s,t)})),o)return h=new w(u.from(t.state.schema.text(e.replace(/\r\n?/g,"\n"))),0,0),t.someProp("transformPasted",(e=>{h=e(h,t,!0)})),h;let i=t.someProp("clipboardTextParser",(i=>i(e,n,s,t)));if(i)h=i;else{let i=n.marks(),{schema:s}=t.state,h=at.fromSchema(s);r=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach((t=>{let e=r.appendChild(document.createElement("p"));t&&e.appendChild(h.serializeNode(s.text(t,i)))}))}}else t.someProp("transformPastedHTML",(e=>{i=e(i,t)})),r=function(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let i,s=bs().createElement("div"),n=/<([a-z][^>\s]+)/i.exec(t);if((i=n&&ys[n[1].toLowerCase()])&&(t=i.map((t=>"<"+t+">")).join("")+t+i.map((t=>"</"+t+">")).reverse().join("")),s.innerHTML=function(t){let e=window.trustedTypes;return e?(Ms||(Ms=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),Ms.createHTML(t)):t}(t),i)for(let t=0;t<i.length;t++)s=s.querySelector(i[t])||s;return s}(i),Ve&&function(t){let e=t.querySelectorAll(Le?"span:not([class]):not([style])":"span.Apple-converted-space");for(let i=0;i<e.length;i++){let s=e[i];1==s.childNodes.length&&" "==s.textContent&&s.parentNode&&s.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),s)}}(r);let a=r&&r.querySelector("[data-pm-slice]"),c=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let t=+c[3];t>0;t--){let t=r.firstChild;for(;t&&1!=t.nodeType;)t=t.nextSibling;if(!t)break;r=t}if(!h){let e=t.someProp("clipboardParser")||t.someProp("domParser")||tt.fromSchema(t.state.schema);h=e.parseSlice(r,{preserveWhitespace:!(!l&&!c),context:n,ruleFromNode:t=>"BR"!=t.nodeName||t.nextSibling||!t.parentNode||fs.test(t.parentNode.nodeName)?null:{ignore:!0}})}if(c)h=function(t,e){if(!t.size)return t;let i,s=t.content.firstChild.type.schema;try{i=JSON.parse(e)}catch(e){return t}let{content:n,openStart:r,openEnd:h}=t;for(let t=i.length-2;t>=0;t-=2){let e=s.nodes[i[t]];if(!e||e.hasRequiredAttrs())break;n=u.from(e.create(i[t+1],n)),r++,h++}return new w(n,r,h)}(ms(h,+c[1],+c[2]),c[4]);else if(h=w.maxOpen(function(t,e){if(t.childCount<2)return t;for(let i=e.depth;i>=0;i--){let s,n=e.node(i).contentMatchAt(e.index(i)),r=[];if(t.forEach((t=>{if(!r)return;let e,i=n.findWrapping(t.type);if(!i)return r=null;if(e=r.length&&s.length&&ps(i,s,t,r[r.length-1],0))r[r.length-1]=e;else{r.length&&(r[r.length-1]=ws(r[r.length-1],s.length));let e=ds(t,i);r.push(e),n=n.matchType(e.type),s=i}})),r)return u.from(r)}return t}(h.content,n),!0),h.openStart||h.openEnd){let t=0,e=0;for(let e=h.content.firstChild;t<h.openStart&&!e.type.spec.isolating;t++,e=e.firstChild);for(let t=h.content.lastChild;e<h.openEnd&&!t.type.spec.isolating;e++,t=t.lastChild);h=ms(h,t,e)}return t.someProp("transformPasted",(e=>{h=e(h,t,l)})),h}const fs=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function ds(t,e,i=0){for(let s=e.length-1;s>=i;s--)t=e[s].create(null,u.from(t));return t}function ps(t,e,i,s,n){if(n<t.length&&n<e.length&&t[n]==e[n]){let r=ps(t,e,i,s.lastChild,n+1);if(r)return s.copy(s.content.replaceChild(s.childCount-1,r));if(s.contentMatchAt(s.childCount).matchType(n==t.length-1?i.type:t[n+1]))return s.copy(s.content.append(u.from(ds(i,t,n+1))))}}function ws(t,e){if(0==e)return t;let i=t.content.replaceChild(t.childCount-1,ws(t.lastChild,e-1)),s=t.contentMatchAt(t.childCount).fillBefore(u.empty,!0);return t.copy(i.append(s))}function gs(t,e,i,s,n,r){let h=e<0?t.firstChild:t.lastChild,o=h.content;return t.childCount>1&&(r=0),n<s-1&&(o=gs(o,e,i,s,n+1,r)),n>=i&&(o=e<0?h.contentMatchAt(0).fillBefore(o,r<=n).append(o):o.append(h.contentMatchAt(h.childCount).fillBefore(u.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,h.copy(o))}function ms(t,e,i){return e<t.openStart&&(t=new w(gs(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),i<t.openEnd&&(t=new w(gs(t.content,1,i,t.openEnd,0,0),t.openStart,i)),t}const ys={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let vs=null;function bs(){return vs||(vs=document.implementation.createHTMLDocument("title"))}let Ms=null;const ks={},As={},xs={touchstart:!0,touchmove:!0};class Ss{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Cs(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function Os(t){t.someProp("handleDOMEvents",(e=>{for(let i in e)t.input.eventHandlers[i]||t.dom.addEventListener(i,t.input.eventHandlers[i]=e=>Es(t,e))}))}function Es(t,e){return t.someProp("handleDOMEvents",(i=>{let s=i[e.type];return!!s&&(s(t,e)||e.defaultPrevented)}))}function Ts(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i=e.target;i!=t.dom;i=i.parentNode)if(!i||11==i.nodeType||i.pmViewDesc&&i.pmViewDesc.stopEvent(e))return!1;return!0}function Ds(t){return{left:t.clientX,top:t.clientY}}function $s(t,e,i,s,n){if(-1==s)return!1;let r=t.state.doc.resolve(s);for(let s=r.depth+1;s>0;s--)if(t.someProp(e,(e=>s>r.depth?e(t,i,r.nodeAfter,r.before(s),n,!0):e(t,i,r.node(s),r.before(s),n,!1))))return!0;return!1}function Ps(t,e){if(t.focused||t.focus(),t.state.selection.eq(e))return;let i=t.state.tr.setSelection(e);i.setMeta("pointer",!0),t.dispatch(i)}function Rs(t,e,i,s){return $s(t,"handleDoubleClickOn",e,i,s)||t.someProp("handleDoubleClick",(i=>i(t,e,s)))}function Is(t,e,i,s){return $s(t,"handleTripleClickOn",e,i,s)||t.someProp("handleTripleClick",(i=>i(t,e,s)))||function(t,e,i){if(0!=i.button)return!1;let s=t.state.doc;if(-1==e)return!!s.inlineContent&&(Ps(t,se.create(s,0,s.content.size)),!0);let n=s.resolve(e);for(let e=n.depth+1;e>0;e--){let i=e>n.depth?n.nodeAfter:n.node(e),r=n.before(e);if(i.inlineContent)Ps(t,se.create(s,r+1,r+1+i.content.size));else{if(!re.isSelectable(i))continue;Ps(t,re.create(s,r))}return!0}}(t,i,s)}function Us(t){return zs(t)}As.keydown=(t,e)=>{let i=e;if(t.input.shiftKey=16==i.keyCode||i.shiftKey,!Ns(t,i)&&(t.input.lastKeyCode=i.keyCode,t.input.lastKeyCodeTime=Date.now(),!He||!Le||13!=i.keyCode))if(229!=i.keyCode&&t.domObserver.forceFlush(),!We||13!=i.keyCode||i.ctrlKey||i.altKey||i.metaKey)t.someProp("handleKeyDown",(e=>e(t,i)))||function(t,e){let i=e.keyCode,s=function(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}(e);if(8==i||Xe&&72==i&&"c"==s)return ls(t,-1)||is(t,-1);if(46==i&&!e.shiftKey||Xe&&68==i&&"c"==s)return ls(t,1)||is(t,1);if(13==i||27==i)return!0;if(37==i||Xe&&66==i&&"c"==s){let e=37==i?"ltr"==rs(t,t.state.selection.from)?-1:1:-1;return Zi(t,e,s)||is(t,e)}if(39==i||Xe&&70==i&&"c"==s){let e=39==i?"ltr"==rs(t,t.state.selection.from)?1:-1:1;return Zi(t,e,s)||is(t,e)}return 38==i||Xe&&80==i&&"c"==s?hs(t,-1,s)||is(t,-1):40==i||Xe&&78==i&&"c"==s?function(t){if(!Ye||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(e&&1==e.nodeType&&0==i&&e.firstChild&&"false"==e.firstChild.contentEditable){let i=e.firstChild;us(t,i,"true"),setTimeout((()=>us(t,i,"false")),20)}return!1}(t)||hs(t,1,s)||is(t,1):s==(Xe?"m":"c")&&(66==i||73==i||89==i||90==i)}(t,i)?i.preventDefault():Cs(t,"key");else{let e=Date.now();t.input.lastIOSEnter=e,t.input.lastIOSEnterFallbackTimeout=setTimeout((()=>{t.input.lastIOSEnter==e&&(t.someProp("handleKeyDown",(e=>e(t,De(13,"Enter")))),t.input.lastIOSEnter=0)}),200)}},As.keyup=(t,e)=>{16==e.keyCode&&(t.input.shiftKey=!1)},As.keypress=(t,e)=>{let i=e;if(Ns(t,i)||!i.charCode||i.ctrlKey&&!i.altKey||Xe&&i.metaKey)return;if(t.someProp("handleKeyPress",(e=>e(t,i))))return void i.preventDefault();let s=t.state.selection;if(!(s instanceof se&&s.$from.sameParent(s.$to))){let e=String.fromCharCode(i.charCode),n=()=>t.state.tr.insertText(e).scrollIntoView();/[\r\n]/.test(e)||t.someProp("handleTextInput",(i=>i(t,s.$from.pos,s.$to.pos,e,n)))||t.dispatch(n()),i.preventDefault()}};const js=Xe?"metaKey":"ctrlKey";ks.mousedown=(t,e)=>{let i=e;t.input.shiftKey=i.shiftKey;let s=Us(t),n=Date.now(),r="singleClick";n-t.input.lastClick.time<500&&function(t,e){let i=e.x-t.clientX,s=e.y-t.clientY;return i*i+s*s<100}(i,t.input.lastClick)&&!i[js]&&t.input.lastClick.button==i.button&&("singleClick"==t.input.lastClick.type?r="doubleClick":"doubleClick"==t.input.lastClick.type&&(r="tripleClick")),t.input.lastClick={time:n,x:i.clientX,y:i.clientY,type:r,button:i.button};let h=t.posAtCoords(Ds(i));h&&("singleClick"==r?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new Bs(t,h,i,!!s)):("doubleClick"==r?Rs:Is)(t,h.pos,h.inside,i)?i.preventDefault():Cs(t,"pointer"))};class Bs{constructor(t,e,i,s){let n,r;if(this.view=t,this.pos=e,this.event=i,this.flushed=s,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=t.state.doc,this.selectNode=!!i[js],this.allowDefault=i.shiftKey,e.inside>-1)n=t.state.doc.nodeAt(e.inside),r=e.inside;else{let i=t.state.doc.resolve(e.pos);n=i.parent,r=i.depth?i.before():0}const h=s?null:i.target,o=h?t.docView.nearestDesc(h,!0):null;this.target=o&&1==o.nodeDOM.nodeType?o.nodeDOM:null;let{selection:l}=t.state;(0==i.button&&n.type.spec.draggable&&!1!==n.type.spec.selectable||l instanceof re&&l.from<=r&&l.to>r)&&(this.mightDrag={node:n,pos:r,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!Fe||this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout((()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")}),20),this.view.domObserver.start()),t.root.addEventListener("mouseup",this.up=this.up.bind(this)),t.root.addEventListener("mousemove",this.move=this.move.bind(this)),Cs(t,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout((()=>Li(this.view))),this.view.input.mouseDown=null}up(t){if(this.done(),!this.view.dom.contains(t.target))return;let e=this.pos;this.view.state.doc!=this.startDoc&&(e=this.view.posAtCoords(Ds(t))),this.updateAllowDefault(t),this.allowDefault||!e?Cs(this.view,"pointer"):function(t,e,i,s,n){return $s(t,"handleClickOn",e,i,s)||t.someProp("handleClick",(i=>i(t,e,s)))||(n?function(t,e){if(-1==e)return!1;let i,s,n=t.state.selection;n instanceof re&&(i=n.node);let r=t.state.doc.resolve(e);for(let t=r.depth+1;t>0;t--){let e=t>r.depth?r.nodeAfter:r.node(t);if(re.isSelectable(e)){s=i&&n.$from.depth>0&&t>=n.$from.depth&&r.before(n.$from.depth+1)==n.$from.pos?r.before(n.$from.depth):r.before(t);break}}return null!=s&&(Ps(t,re.create(t.state.doc,s)),!0)}(t,i):function(t,e){if(-1==e)return!1;let i=t.state.doc.resolve(e),s=i.nodeAfter;return!!(s&&s.isAtom&&re.isSelectable(s))&&(Ps(t,new re(i)),!0)}(t,i))}(this.view,e.pos,e.inside,t,this.selectNode)?t.preventDefault():0==t.button&&(this.flushed||Ye&&this.mightDrag&&!this.mightDrag.node.isAtom||Le&&!this.view.state.selection.visible&&Math.min(Math.abs(e.pos-this.view.state.selection.from),Math.abs(e.pos-this.view.state.selection.to))<=2)?(Ps(this.view,Zt.near(this.view.state.doc.resolve(e.pos))),t.preventDefault()):Cs(this.view,"pointer")}move(t){this.updateAllowDefault(t),Cs(this.view,"pointer"),0==t.buttons&&this.done()}updateAllowDefault(t){!this.allowDefault&&(Math.abs(this.event.x-t.clientX)>4||Math.abs(this.event.y-t.clientY)>4)&&(this.allowDefault=!0)}}function Ns(t,e){return!!t.composing||!!(Ye&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500)&&(t.input.compositionEndedAt=-2e8,!0)}ks.touchstart=t=>{t.input.lastTouch=Date.now(),Us(t),Cs(t,"pointer")},ks.touchmove=t=>{t.input.lastTouch=Date.now(),Cs(t,"pointer")},ks.contextmenu=t=>Us(t);const Fs=He?5e3:-1;function _s(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout((()=>zs(t)),e))}function Ls(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=function(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function zs(t,e=!1){if(!(He&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Ls(t),e||t.docView&&t.docView.dirty){let i=Fi(t),s=t.state.selection;return i&&!i.eq(s)?t.dispatch(t.state.tr.setSelection(i)):!t.markCursor&&!e||s.$from.node(s.$from.sharedDepth(s.to)).inlineContent?t.updateState(t.state):t.dispatch(t.state.tr.deleteSelection()),!0}return!1}}As.compositionstart=As.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,i=e.selection.$to;if(e.selection instanceof se&&(e.storedMarks||!i.textOffset&&i.parentOffset&&i.nodeBefore.marks.some((t=>!1===t.type.spec.inclusive))||Le&&Je&&function(t){let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(!e||1!=e.nodeType||i>=e.childNodes.length)return!1;let s=e.childNodes[i];return 1==s.nodeType&&"false"==s.contentEditable}(t)))t.markCursor=t.state.storedMarks||i.marks(),zs(t,!0),t.markCursor=null;else if(zs(t,!e.selection.empty),Fe&&e.selection.empty&&i.parentOffset&&!i.textOffset&&i.nodeBefore.marks.length){let e=t.domSelectionRange();for(let i=e.focusNode,s=e.focusOffset;i&&1==i.nodeType&&0!=s;){let e=s<0?i.lastChild:i.childNodes[s-1];if(!e)break;if(3==e.nodeType){let i=t.domSelection();i&&i.collapse(e,e.nodeValue.length);break}i=e,s=-1}}t.input.composing=!0}_s(t,Fs)},As.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.timeStamp,t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.compositionPendingChanges&&Promise.resolve().then((()=>t.domObserver.flush())),t.input.compositionID++,_s(t,20))};const Ys=Be&&Ne<15||We&&Qe<604;function Ws(t,e,i,s,n){let r=cs(t,e,i,s,t.state.selection.$from);if(t.someProp("handlePaste",(e=>e(t,n,r||w.empty))))return!0;if(!r)return!1;let h=function(t){return 0==t.openStart&&0==t.openEnd&&1==t.content.childCount?t.content.firstChild:null}(r),o=h?t.state.tr.replaceSelectionWith(h,s):t.state.tr.replaceSelection(r);return t.dispatch(o.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Xs(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let i=t.getData("text/uri-list");return i?i.replace(/\r?\n/g," "):""}ks.copy=As.cut=(t,e)=>{let i=e,s=t.state.selection,n="cut"==i.type;if(s.empty)return;let r=Ys?null:i.clipboardData,h=s.content(),{dom:o,text:l}=as(t,h);r?(i.preventDefault(),r.clearData(),r.setData("text/html",o.innerHTML),r.setData("text/plain",l)):function(t,e){if(!t.dom.parentNode)return;let i=t.dom.parentNode.appendChild(document.createElement("div"));i.appendChild(e),i.style.cssText="position: fixed; left: -10000px; top: 10px";let s=getSelection(),n=document.createRange();n.selectNodeContents(e),t.dom.blur(),s.removeAllRanges(),s.addRange(n),setTimeout((()=>{i.parentNode&&i.parentNode.removeChild(i),t.focus()}),50)}(t,o),n&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},As.paste=(t,e)=>{let i=e;if(t.composing&&!He)return;let s=Ys?null:i.clipboardData,n=t.input.shiftKey&&45!=t.input.lastKeyCode;s&&Ws(t,Xs(s),s.getData("text/html"),n,i)?i.preventDefault():function(t,e){if(!t.dom.parentNode)return;let i=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,s=t.dom.parentNode.appendChild(document.createElement(i?"textarea":"div"));i||(s.contentEditable="true"),s.style.cssText="position: fixed; left: -10000px; top: 10px",s.focus();let n=t.input.shiftKey&&45!=t.input.lastKeyCode;setTimeout((()=>{t.focus(),s.parentNode&&s.parentNode.removeChild(s),i?Ws(t,s.value,null,n,e):Ws(t,s.textContent,s.innerHTML,n,e)}),50)}(t,i)};class Js{constructor(t,e,i){this.slice=t,this.move=e,this.node=i}}const Hs=Xe?"altKey":"ctrlKey";function Vs(t,e){let i=t.someProp("dragCopies",(t=>!t(e)));return null!=i?i:!e[Hs]}ks.dragstart=(t,e)=>{let i=e,s=t.input.mouseDown;if(s&&s.done(),!i.dataTransfer)return;let n,r=t.state.selection,h=r.empty?null:t.posAtCoords(Ds(i));if(h&&h.pos>=r.from&&h.pos<=(r instanceof re?r.to-1:r.to));else if(s&&s.mightDrag)n=re.create(t.state.doc,s.mightDrag.pos);else if(i.target&&1==i.target.nodeType){let e=t.docView.nearestDesc(i.target,!0);e&&e.node.type.spec.draggable&&e!=t.docView&&(n=re.create(t.state.doc,e.posBefore))}let o=(n||t.state.selection).content(),{dom:l,text:u,slice:a}=as(t,o);(!i.dataTransfer.files.length||!Le||ze>120)&&i.dataTransfer.clearData(),i.dataTransfer.setData(Ys?"Text":"text/html",l.innerHTML),i.dataTransfer.effectAllowed="copyMove",Ys||i.dataTransfer.setData("text/plain",u),t.dragging=new Js(a,Vs(t,i),n)},ks.dragend=t=>{let e=t.dragging;window.setTimeout((()=>{t.dragging==e&&(t.dragging=null)}),50)},As.dragover=As.dragenter=(t,e)=>e.preventDefault(),As.drop=(t,e)=>{try{!function(t,e,i){if(!e.dataTransfer)return;let s=t.posAtCoords(Ds(e));if(!s)return;let n=t.state.doc.resolve(s.pos),r=i&&i.slice;r?t.someProp("transformPasted",(e=>{r=e(r,t,!1)})):r=cs(t,Xs(e.dataTransfer),Ys?null:e.dataTransfer.getData("text/html"),!1,n);let h=!(!i||!Vs(t,e));if(t.someProp("handleDrop",(i=>i(t,e,r||w.empty,h))))return void e.preventDefault();if(!r)return;e.preventDefault();let o=r?function(t,e,i){let s=t.resolve(e);if(!i.content.size)return e;let n=i.content;for(let t=0;t<i.openStart;t++)n=n.firstChild.content;for(let t=1;t<=(0==i.openStart&&i.size?2:1);t++)for(let e=s.depth;e>=0;e--){let i=e==s.depth?0:s.pos<=(s.start(e+1)+s.end(e+1))/2?-1:1,r=s.index(e)+(i>0?1:0),h=s.node(e),o=!1;if(1==t)o=h.canReplace(r,r,n);else{let t=h.contentMatchAt(r).findWrapping(n.firstChild.type);o=t&&h.canReplaceWith(r,r,t[0])}if(o)return 0==i?s.pos:i<0?s.before(e+1):s.after(e+1)}return null}(t.state.doc,n.pos,r):n.pos;null==o&&(o=n.pos);let l=t.state.tr;if(h){let{node:t}=i;t?t.replace(l):l.deleteSelection()}let u=l.mapping.map(o),a=0==r.openStart&&0==r.openEnd&&1==r.content.childCount,c=l.doc;if(a?l.replaceRangeWith(u,u,r.content.firstChild):l.replaceRange(u,u,r),l.doc.eq(c))return;let f=l.doc.resolve(u);if(a&&re.isSelectable(r.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(r.content.firstChild))l.setSelection(new re(f));else{let e=l.mapping.map(o);l.mapping.maps[l.mapping.maps.length-1].forEach(((t,i,s,n)=>e=n)),l.setSelection(Vi(t,f,l.doc.resolve(e)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}(t,e,t.dragging)}finally{t.dragging=null}},ks.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout((()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&Li(t)}),20))},ks.blur=(t,e)=>{let i=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),i.relatedTarget&&t.dom.contains(i.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)},ks.beforeinput=(t,e)=>{if(Le&&He&&"deleteContentBackward"==e.inputType){t.domObserver.flushSoon();let{domChangeCount:e}=t.input;setTimeout((()=>{if(t.input.domChangeCount!=e)return;if(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",(e=>e(t,De(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())}),50)}};for(let t in As)ks[t]=As[t];function Qs(t,e){if(t==e)return!0;for(let i in t)if(t[i]!==e[i])return!1;for(let i in e)if(!(i in t))return!1;return!0}class Ks{constructor(t,e){this.toDOM=t,this.spec=e||en,this.side=this.spec.side||0}map(t,e,i,s){let{pos:n,deleted:r}=t.mapResult(e.from+s,this.side<0?-1:1);return r?null:new Zs(n-i,n-i,this)}valid(){return!0}eq(t){return this==t||t instanceof Ks&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&Qs(this.spec,t.spec))}destroy(t){this.spec.destroy&&this.spec.destroy(t)}}class qs{constructor(t,e){this.attrs=t,this.spec=e||en}map(t,e,i,s){let n=t.map(e.from+s,this.spec.inclusiveStart?-1:1)-i,r=t.map(e.to+s,this.spec.inclusiveEnd?1:-1)-i;return n>=r?null:new Zs(n,r,this)}valid(t,e){return e.from<e.to}eq(t){return this==t||t instanceof qs&&Qs(this.attrs,t.attrs)&&Qs(this.spec,t.spec)}static is(t){return t.type instanceof qs}destroy(){}}class Gs{constructor(t,e){this.attrs=t,this.spec=e||en}map(t,e,i,s){let n=t.mapResult(e.from+s,1);if(n.deleted)return null;let r=t.mapResult(e.to+s,-1);return r.deleted||r.pos<=n.pos?null:new Zs(n.pos-i,r.pos-i,this)}valid(t,e){let i,{index:s,offset:n}=t.content.findIndex(e.from);return n==e.from&&!(i=t.child(s)).isText&&n+i.nodeSize==e.to}eq(t){return this==t||t instanceof Gs&&Qs(this.attrs,t.attrs)&&Qs(this.spec,t.spec)}destroy(){}}class Zs{constructor(t,e,i){this.from=t,this.to=e,this.type=i}copy(t,e){return new Zs(t,e,this.type)}eq(t,e=0){return this.type.eq(t.type)&&this.from+e==t.from&&this.to+e==t.to}map(t,e,i){return this.type.map(t,this,e,i)}static widget(t,e,i){return new Zs(t,t,new Ks(e,i))}static inline(t,e,i,s){return new Zs(t,e,new qs(i,s))}static node(t,e,i,s){return new Zs(t,e,new Gs(i,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof qs}get widget(){return this.type instanceof Ks}}const tn=[],en={};class sn{constructor(t,e){this.local=t.length?t:tn,this.children=e.length?e:tn}static create(t,e){return e.length?un(e,t,0,en):nn}find(t,e,i){let s=[];return this.findInner(null==t?0:t,null==e?1e9:e,s,0,i),s}findInner(t,e,i,s,n){for(let r=0;r<this.local.length;r++){let h=this.local[r];h.from<=e&&h.to>=t&&(!n||n(h.spec))&&i.push(h.copy(h.from+s,h.to+s))}for(let r=0;r<this.children.length;r+=3)if(this.children[r]<e&&this.children[r+1]>t){let h=this.children[r]+1;this.children[r+2].findInner(t-h,e-h,i,s+h,n)}}map(t,e,i){return this==nn||0==t.maps.length?this:this.mapInner(t,e,0,0,i||en)}mapInner(t,e,i,s,n){let r;for(let h=0;h<this.local.length;h++){let o=this.local[h].map(t,i,s);o&&o.type.valid(e,o)?(r||(r=[])).push(o):n.onRemove&&n.onRemove(this.local[h].spec)}return this.children.length?function(t,e,i,s,n,r,h){let o=t.slice();for(let t=0,e=r;t<i.maps.length;t++){let s=0;i.maps[t].forEach(((t,i,n,r)=>{let h=r-n-(i-t);for(let n=0;n<o.length;n+=3){let r=o[n+1];if(r<0||t>r+e-s)continue;let l=o[n]+e-s;i>=l?o[n+1]=t<=l?-2:-1:t>=e&&h&&(o[n]+=h,o[n+1]+=h)}s+=h})),e=i.maps[t].map(e,-1)}let l=!1;for(let e=0;e<o.length;e+=3)if(o[e+1]<0){if(-2==o[e+1]){l=!0,o[e+1]=-1;continue}let u=i.map(t[e]+r),a=u-n;if(a<0||a>=s.content.size){l=!0;continue}let c=i.map(t[e+1]+r,-1)-n,{index:f,offset:d}=s.content.findIndex(a),p=s.maybeChild(f);if(p&&d==a&&d+p.nodeSize==c){let s=o[e+2].mapInner(i,p,u+1,t[e]+r+1,h);s!=nn?(o[e]=a,o[e+1]=c,o[e+2]=s):(o[e+1]=-2,l=!0)}else l=!0}if(l){let l=function(t,e,i,s,n,r,h){function o(t,e){for(let r=0;r<t.local.length;r++){let o=t.local[r].map(s,n,e);o?i.push(o):h.onRemove&&h.onRemove(t.local[r].spec)}for(let i=0;i<t.children.length;i+=3)o(t.children[i+2],t.children[i]+e+1)}for(let i=0;i<t.length;i+=3)-1==t[i+1]&&o(t[i+2],e[i]+r+1);return i}(o,t,e,i,n,r,h),u=un(l,s,0,h);e=u.local;for(let t=0;t<o.length;t+=3)o[t+1]<0&&(o.splice(t,3),t-=3);for(let t=0,e=0;t<u.children.length;t+=3){let i=u.children[t];for(;e<o.length&&o[e]<i;)e+=3;o.splice(e,0,u.children[t],u.children[t+1],u.children[t+2])}}return new sn(e.sort(an),o)}(this.children,r||[],t,e,i,s,n):r?new sn(r.sort(an),tn):nn}add(t,e){return e.length?this==nn?sn.create(t,e):this.addInner(t,e,0):this}addInner(t,e,i){let s,n=0;t.forEach(((t,r)=>{let h,o=r+i;if(h=on(e,t,o)){for(s||(s=this.children.slice());n<s.length&&s[n]<r;)n+=3;s[n]==r?s[n+2]=s[n+2].addInner(t,h,o+1):s.splice(n,0,r,r+t.nodeSize,un(h,t,o+1,en)),n+=3}}));let r=hn(n?ln(e):e,-i);for(let e=0;e<r.length;e++)r[e].type.valid(t,r[e])||r.splice(e--,1);return new sn(r.length?this.local.concat(r).sort(an):this.local,s||this.children)}remove(t){return 0==t.length||this==nn?this:this.removeInner(t,0)}removeInner(t,e){let i=this.children,s=this.local;for(let s=0;s<i.length;s+=3){let n,r=i[s]+e,h=i[s+1]+e;for(let e,i=0;i<t.length;i++)(e=t[i])&&e.from>r&&e.to<h&&(t[i]=null,(n||(n=[])).push(e));if(!n)continue;i==this.children&&(i=this.children.slice());let o=i[s+2].removeInner(n,r+1);o!=nn?i[s+2]=o:(i.splice(s,3),s-=3)}if(s.length)for(let i,n=0;n<t.length;n++)if(i=t[n])for(let t=0;t<s.length;t++)s[t].eq(i,e)&&(s==this.local&&(s=this.local.slice()),s.splice(t--,1));return i==this.children&&s==this.local?this:s.length||i.length?new sn(s,i):nn}forChild(t,e){if(this==nn)return this;if(e.isLeaf)return sn.empty;let i,s;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){this.children[e]==t&&(i=this.children[e+2]);break}let n=t+1,r=n+e.content.size;for(let t=0;t<this.local.length;t++){let e=this.local[t];if(e.from<r&&e.to>n&&e.type instanceof qs){let t=Math.max(n,e.from)-n,i=Math.min(r,e.to)-n;t<i&&(s||(s=[])).push(e.copy(t,i))}}if(s){let t=new sn(s.sort(an),tn);return i?new rn([t,i]):t}return i||nn}eq(t){if(this==t)return!0;if(!(t instanceof sn)||this.local.length!=t.local.length||this.children.length!=t.children.length)return!1;for(let e=0;e<this.local.length;e++)if(!this.local[e].eq(t.local[e]))return!1;for(let e=0;e<this.children.length;e+=3)if(this.children[e]!=t.children[e]||this.children[e+1]!=t.children[e+1]||!this.children[e+2].eq(t.children[e+2]))return!1;return!0}locals(t){return cn(this.localsInner(t))}localsInner(t){if(this==nn)return tn;if(t.inlineContent||!this.local.some(qs.is))return this.local;let e=[];for(let t=0;t<this.local.length;t++)this.local[t].type instanceof qs||e.push(this.local[t]);return e}forEachSet(t){t(this)}}sn.empty=new sn([],[]),sn.removeOverlap=cn;const nn=sn.empty;class rn{constructor(t){this.members=t}map(t,e){const i=this.members.map((i=>i.map(t,e,en)));return rn.from(i)}forChild(t,e){if(e.isLeaf)return sn.empty;let i=[];for(let s=0;s<this.members.length;s++){let n=this.members[s].forChild(t,e);n!=nn&&(n instanceof rn?i=i.concat(n.members):i.push(n))}return rn.from(i)}eq(t){if(!(t instanceof rn)||t.members.length!=this.members.length)return!1;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return!1;return!0}locals(t){let e,i=!0;for(let s=0;s<this.members.length;s++){let n=this.members[s].localsInner(t);if(n.length)if(e){i&&(e=e.slice(),i=!1);for(let t=0;t<n.length;t++)e.push(n[t])}else e=n}return e?cn(i?e:e.sort(an)):tn}static from(t){switch(t.length){case 0:return nn;case 1:return t[0];default:return new rn(t.every((t=>t instanceof sn))?t:t.reduce(((t,e)=>t.concat(e instanceof sn?e:e.members)),[]))}}forEachSet(t){for(let e=0;e<this.members.length;e++)this.members[e].forEachSet(t)}}function hn(t,e){if(!e||!t.length)return t;let i=[];for(let s=0;s<t.length;s++){let n=t[s];i.push(new Zs(n.from+e,n.to+e,n.type))}return i}function on(t,e,i){if(e.isLeaf)return null;let s=i+e.nodeSize,n=null;for(let e,r=0;r<t.length;r++)(e=t[r])&&e.from>i&&e.to<s&&((n||(n=[])).push(e),t[r]=null);return n}function ln(t){let e=[];for(let i=0;i<t.length;i++)null!=t[i]&&e.push(t[i]);return e}function un(t,e,i,s){let n=[],r=!1;e.forEach(((e,h)=>{let o=on(t,e,h+i);if(o){r=!0;let t=un(o,e,i+h+1,s);t!=nn&&n.push(h,h+e.nodeSize,t)}}));let h=hn(r?ln(t):t,-i).sort(an);for(let t=0;t<h.length;t++)h[t].type.valid(e,h[t])||(s.onRemove&&s.onRemove(h[t].spec),h.splice(t--,1));return h.length||n.length?new sn(h,n):nn}function an(t,e){return t.from-e.from||t.to-e.to}function cn(t){let e=t;for(let i=0;i<e.length-1;i++){let s=e[i];if(s.from!=s.to)for(let n=i+1;n<e.length;n++){let r=e[n];if(r.from!=s.from){r.from<s.to&&(e==t&&(e=t.slice()),e[i]=s.copy(s.from,r.from),fn(e,n,s.copy(r.from,s.to)));break}r.to!=s.to&&(e==t&&(e=t.slice()),e[n]=r.copy(r.from,s.to),fn(e,n+1,r.copy(s.to,r.to)))}}return e}function fn(t,e,i){for(;e<t.length&&an(i,t[e])>0;)e++;t.splice(e,0,i)}function dn(t){let e=[];return t.someProp("decorations",(i=>{let s=i(t.state);s&&s!=nn&&e.push(s)})),t.cursorWrapper&&e.push(sn.create(t.state.doc,[t.cursorWrapper.deco])),rn.from(e)}const pn={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},wn=Be&&Ne<=11;class gn{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(t){this.anchorNode=t.anchorNode,this.anchorOffset=t.anchorOffset,this.focusNode=t.focusNode,this.focusOffset=t.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(t){return t.anchorNode==this.anchorNode&&t.anchorOffset==this.anchorOffset&&t.focusNode==this.focusNode&&t.focusOffset==this.focusOffset}}class mn{constructor(t,e){this.view=t,this.handleDOMChange=e,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new gn,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver((t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);Be&&Ne<=11&&t.some((t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length))?this.flushSoon():this.flush()})),wn&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout((()=>{this.flushingSoon=-1,this.flush()}),20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,pn)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let t=this.observer.takeRecords();if(t.length){for(let e=0;e<t.length;e++)this.queue.push(t[e]);window.setTimeout((()=>this.flush()),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout((()=>this.suppressingSelectionUpdates=!1),50)}onSelectionChange(){if(Qi(this.view)){if(this.suppressingSelectionUpdates)return Li(this.view);if(Be&&Ne<=11&&!this.view.state.selection.empty){let t=this.view.domSelectionRange();if(t.focusNode&&xe(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(t){if(!t.focusNode)return!0;let e,i=new Set;for(let e=t.focusNode;e;e=Me(e))i.add(e);for(let s=t.anchorNode;s;s=Me(s))if(i.has(s)){e=s;break}let s=e&&this.view.docView.nearestDesc(e);return s&&s.ignoreMutation({type:"selection",target:3==e.nodeType?e.parentNode:e})?(this.setCurSelection(),!0):void 0}pendingRecords(){if(this.observer)for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}flush(){let{view:t}=this;if(!t.docView||this.flushingSoon>-1)return;let e=this.pendingRecords();e.length&&(this.queue=[]);let i=t.domSelectionRange(),s=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(i)&&Qi(t)&&!this.ignoreSelectionChange(i),n=-1,r=-1,h=!1,o=[];if(t.editable)for(let t=0;t<e.length;t++){let i=this.registerMutation(e[t],o);i&&(n=n<0?i.from:Math.min(i.from,n),r=r<0?i.to:Math.max(i.to,r),i.typeOver&&(h=!0))}if(Fe&&o.length){let e=o.filter((t=>"BR"==t.nodeName));if(2==e.length){let[t,i]=e;t.parentNode&&t.parentNode.parentNode==i.parentNode?i.remove():t.remove()}else{let{focusNode:i}=this.currentSelection;for(let s of e){let e=s.parentNode;!e||"LI"!=e.nodeName||i&&Mn(t,i)==e||s.remove()}}}else if((Le||Ye)&&o.some((t=>"BR"==t.nodeName))&&(8==t.input.lastKeyCode||46==t.input.lastKeyCode))for(let t of o)if("BR"==t.nodeName&&t.parentNode){let e=t.nextSibling;e&&1==e.nodeType&&"false"==e.contentEditable&&t.parentNode.removeChild(t)}let l=null;n<0&&s&&t.input.lastFocus>Date.now()-200&&Math.max(t.input.lastTouch,t.input.lastClick.time)<Date.now()-300&&Te(i)&&(l=Fi(t))&&l.eq(Zt.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,Li(t),this.currentSelection.set(i),t.scrollToSelection()):(n>-1||s)&&(n>-1&&(t.docView.markDirty(n,r),function(t){if(!yn.has(t)&&(yn.set(t,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace))){if(t.requiresGeckoHackNode=Fe,vn)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),vn=!0}}(t)),this.handleDOMChange(n,r,h,o),t.docView&&t.docView.dirty?t.updateState(t.state):this.currentSelection.eq(i)||Li(t),this.currentSelection.set(i))}registerMutation(t,e){if(e.indexOf(t.target)>-1)return null;let i=this.view.docView.nearestDesc(t.target);if("attributes"==t.type&&(i==this.view.docView||"contenteditable"==t.attributeName||"style"==t.attributeName&&!t.oldValue&&!t.target.getAttribute("style")))return null;if(!i||i.ignoreMutation(t))return null;if("childList"==t.type){for(let i=0;i<t.addedNodes.length;i++){let s=t.addedNodes[i];e.push(s),3==s.nodeType&&(this.lastChangedTextNode=s)}if(i.contentDOM&&i.contentDOM!=i.dom&&!i.contentDOM.contains(t.target))return{from:i.posBefore,to:i.posAfter};let s=t.previousSibling,n=t.nextSibling;if(Be&&Ne<=11&&t.addedNodes.length)for(let e=0;e<t.addedNodes.length;e++){let{previousSibling:i,nextSibling:r}=t.addedNodes[e];(!i||Array.prototype.indexOf.call(t.addedNodes,i)<0)&&(s=i),(!r||Array.prototype.indexOf.call(t.addedNodes,r)<0)&&(n=r)}let r=s&&s.parentNode==t.target?be(s)+1:0,h=i.localPosFromDOM(t.target,r,-1),o=n&&n.parentNode==t.target?be(n):t.target.childNodes.length;return{from:h,to:i.localPosFromDOM(t.target,o,1)}}return"attributes"==t.type?{from:i.posAtStart-i.border,to:i.posAtEnd+i.border}:(this.lastChangedTextNode=t.target,{from:i.posAtStart,to:i.posAtEnd,typeOver:t.target.nodeValue==t.oldValue})}}let yn=new WeakMap,vn=!1;function bn(t,e){let i=e.startContainer,s=e.startOffset,n=e.endContainer,r=e.endOffset,h=t.domAtPos(t.state.selection.anchor);return xe(h.node,h.offset,n,r)&&([i,s,n,r]=[n,r,i,s]),{anchorNode:i,anchorOffset:s,focusNode:n,focusOffset:r}}function Mn(t,e){for(let i=e.parentNode;i&&i!=t.dom;i=i.parentNode){let e=t.docView.nearestDesc(i,!0);if(e&&e.node.isBlock)return i}return null}function kn(t){let e=t.pmViewDesc;if(e)return e.parseRule();if("BR"==t.nodeName&&t.parentNode){if(Ye&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}if(t.parentNode.lastChild==t||Ye&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if("IMG"==t.nodeName&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}const An=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function xn(t,e,i){return Math.max(i.anchor,i.head)>e.content.size?null:Vi(t,e.resolve(i.anchor),e.resolve(i.head))}function Sn(t,e,i){let s=t.depth,n=e?t.end():t.pos;for(;s>0&&(e||t.indexAfter(s)==t.node(s).childCount);)s--,n++,e=!1;if(i){let e=t.node(s).maybeChild(t.indexAfter(s));for(;e&&!e.isLeaf;)e=e.firstChild,n++}return n}function Cn(t){if(2!=t.length)return!1;let e=t.charCodeAt(0),i=t.charCodeAt(1);return e>=56320&&e<=57343&&i>=55296&&i<=56319}class On{constructor(t,e){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new Ss,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=e,this.state=e.state,this.directPlugins=e.plugins||[],this.directPlugins.forEach(Pn),this.dispatch=this.dispatch.bind(this),this.dom=t&&t.mount||document.createElement("div"),t&&(t.appendChild?t.appendChild(this.dom):"function"==typeof t?t(this.dom):t.mount&&(this.mounted=!0)),this.editable=Dn(this),Tn(this),this.nodeViews=$n(this),this.docView=Ai(this.state.doc,En(this),dn(this),this.dom,this),this.domObserver=new mn(this,((t,e,i,s)=>function(t,e,i,s,n){let r=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let e=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,i=Fi(t,e);if(i&&!t.state.selection.eq(i)){if(Le&&He&&13===t.input.lastKeyCode&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",(e=>e(t,De(13,"Enter")))))return;let s=t.state.tr.setSelection(i);"pointer"==e?s.setMeta("pointer",!0):"key"==e&&s.scrollIntoView(),r&&s.setMeta("composition",r),t.dispatch(s)}return}let h=t.state.doc.resolve(e),o=h.sharedDepth(i);e=h.before(o+1),i=t.state.doc.resolve(i).after(o+1);let l,a,c=t.state.selection,f=function(t,e,i){let s,{node:n,fromOffset:r,toOffset:h,from:o,to:l}=t.docView.parseRange(e,i),u=t.domSelectionRange(),a=u.anchorNode;if(a&&t.dom.contains(1==a.nodeType?a:a.parentNode)&&(s=[{node:a,offset:u.anchorOffset}],Te(u)||s.push({node:u.focusNode,offset:u.focusOffset})),Le&&8===t.input.lastKeyCode)for(let t=h;t>r;t--){let e=n.childNodes[t-1],i=e.pmViewDesc;if("BR"==e.nodeName&&!i){h=t;break}if(!i||i.size)break}let c=t.state.doc,f=t.someProp("domParser")||tt.fromSchema(t.state.schema),d=c.resolve(o),p=null,w=f.parse(n,{topNode:d.parent,topMatch:d.parent.contentMatchAt(d.index()),topOpen:!0,from:r,to:h,preserveWhitespace:"pre"!=d.parent.type.whitespace||"full",findPositions:s,ruleFromNode:kn,context:d});if(s&&null!=s[0].pos){let t=s[0].pos,e=s[1]&&s[1].pos;null==e&&(e=t),p={anchor:t+o,head:e+o}}return{doc:w,sel:p,from:o,to:l}}(t,e,i),d=t.state.doc,p=d.slice(f.from,f.to);8===t.input.lastKeyCode&&Date.now()-100<t.input.lastKeyCodeTime?(l=t.state.selection.to,a="end"):(l=t.state.selection.from,a="start"),t.input.lastKeyCode=null;let w=function(t,e,i,s,n){let r=t.findDiffStart(e,i);if(null==r)return null;let{a:h,b:o}=t.findDiffEnd(e,i+t.size,i+e.size);if("end"==n&&(s-=h+Math.max(0,r-Math.min(h,o))-r),h<r&&t.size<e.size){let t=s<=r&&s>=h?r-s:0;r-=t,r&&r<e.size&&Cn(e.textBetween(r-1,r+1))&&(r+=t?1:-1),o=r+(o-h),h=r}else if(o<r){let e=s<=r&&s>=o?r-s:0;r-=e,r&&r<t.size&&Cn(t.textBetween(r-1,r+1))&&(r+=e?1:-1),h=r+(h-o),o=r}return{start:r,endA:h,endB:o}}(p.content,f.doc.content,f.from,l,a);if(w&&t.input.domChangeCount++,(We&&t.input.lastIOSEnter>Date.now()-225||He)&&n.some((t=>1==t.nodeType&&!An.test(t.nodeName)))&&(!w||w.endA>=w.endB)&&t.someProp("handleKeyDown",(e=>e(t,De(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(!w){if(!(s&&c instanceof se&&!c.empty&&c.$head.sameParent(c.$anchor))||t.composing||f.sel&&f.sel.anchor!=f.sel.head){if(f.sel){let e=xn(t,t.state.doc,f.sel);if(e&&!e.eq(t.state.selection)){let i=t.state.tr.setSelection(e);r&&i.setMeta("composition",r),t.dispatch(i)}}return}w={start:c.from,endA:c.to,endB:c.to}}t.state.selection.from<t.state.selection.to&&w.start==w.endB&&t.state.selection instanceof se&&(w.start>t.state.selection.from&&w.start<=t.state.selection.from+2&&t.state.selection.from>=f.from?w.start=t.state.selection.from:w.endA<t.state.selection.to&&w.endA>=t.state.selection.to-2&&t.state.selection.to<=f.to&&(w.endB+=t.state.selection.to-w.endA,w.endA=t.state.selection.to)),Be&&Ne<=11&&w.endB==w.start+1&&w.endA==w.start&&w.start>f.from&&"  "==f.doc.textBetween(w.start-f.from-1,w.start-f.from+1)&&(w.start--,w.endA--,w.endB--);let g=f.doc.resolveNoCache(w.start-f.from),m=f.doc.resolveNoCache(w.endB-f.from),y=d.resolve(w.start),v=g.sameParent(m)&&g.parent.inlineContent&&y.end()>=w.endA;if((We&&t.input.lastIOSEnter>Date.now()-225&&(!v||n.some((t=>"DIV"==t.nodeName||"P"==t.nodeName)))||!v&&g.pos<f.doc.content.size&&(!g.sameParent(m)||!g.parent.inlineContent)&&g.pos<m.pos&&!/\S/.test(f.doc.textBetween(g.pos,m.pos,"","")))&&t.someProp("handleKeyDown",(e=>e(t,De(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(t.state.selection.anchor>w.start&&function(t,e,i,s,n){if(i-e<=n.pos-s.pos||Sn(s,!0,!1)<n.pos)return!1;let r=t.resolve(e);if(!s.parent.isTextblock){let t=r.nodeAfter;return null!=t&&i==e+t.nodeSize}if(r.parentOffset<r.parent.content.size||!r.parent.isTextblock)return!1;let h=t.resolve(Sn(r,!0,!0));return!(!h.parent.isTextblock||h.pos>i||Sn(h,!0,!1)<i)&&s.parent.content.cut(s.parentOffset).eq(h.parent.content)}(d,w.start,w.endA,g,m)&&t.someProp("handleKeyDown",(e=>e(t,De(8,"Backspace")))))return void(He&&Le&&t.domObserver.suppressSelectionUpdates());Le&&w.endB==w.start&&(t.input.lastChromeDelete=Date.now()),He&&!v&&g.start()!=m.start()&&0==m.parentOffset&&g.depth==m.depth&&f.sel&&f.sel.anchor==f.sel.head&&f.sel.head==w.endA&&(w.endB-=2,m=f.doc.resolveNoCache(w.endB-f.from),setTimeout((()=>{t.someProp("handleKeyDown",(function(e){return e(t,De(13,"Enter"))}))}),20));let b,M=w.start,k=w.endA,A=e=>{let i=e||t.state.tr.replace(M,k,f.doc.slice(w.start-f.from,w.endB-f.from));if(f.sel){let e=xn(t,i.doc,f.sel);e&&!(Le&&t.composing&&e.empty&&(w.start!=w.endB||t.input.lastChromeDelete<Date.now()-100)&&(e.head==M||e.head==i.mapping.map(k)-1)||Be&&e.empty&&e.head==M)&&i.setSelection(e)}return r&&i.setMeta("composition",r),i.scrollIntoView()};if(v)if(g.pos==m.pos){Be&&Ne<=11&&0==g.parentOffset&&(t.domObserver.suppressSelectionUpdates(),setTimeout((()=>Li(t)),20));let e=A(t.state.tr.delete(M,k)),i=d.resolve(w.start).marksAcross(d.resolve(w.endA));i&&e.ensureMarks(i),t.dispatch(e)}else if(w.endA==w.endB&&(b=function(t,e){let i,s,n,r=t.firstChild.marks,h=e.firstChild.marks,o=r,l=h;for(let t=0;t<h.length;t++)o=h[t].removeFromSet(o);for(let t=0;t<r.length;t++)l=r[t].removeFromSet(l);if(1==o.length&&0==l.length)s=o[0],i="add",n=t=>t.mark(s.addToSet(t.marks));else{if(0!=o.length||1!=l.length)return null;s=l[0],i="remove",n=t=>t.mark(s.removeFromSet(t.marks))}let a=[];for(let t=0;t<e.childCount;t++)a.push(n(e.child(t)));if(u.from(a).eq(t))return{mark:s,type:i}}(g.parent.content.cut(g.parentOffset,m.parentOffset),y.parent.content.cut(y.parentOffset,w.endA-y.start())))){let e=A(t.state.tr);"add"==b.type?e.addMark(M,k,b.mark):e.removeMark(M,k,b.mark),t.dispatch(e)}else if(g.parent.child(g.index()).isText&&g.index()==m.index()-(m.textOffset?0:1)){let e=g.parent.textBetween(g.parentOffset,m.parentOffset),i=()=>A(t.state.tr.insertText(e,M,k));t.someProp("handleTextInput",(s=>s(t,M,k,e,i)))||t.dispatch(i())}else t.dispatch(A());else t.dispatch(A())}(this,t,e,i,s))),this.domObserver.start(),function(t){for(let e in ks){let i=ks[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=e=>{!Ts(t,e)||Es(t,e)||!t.editable&&e.type in As||i(t,e)},xs[e]?{passive:!0}:void 0)}Ye&&t.dom.addEventListener("input",(()=>null)),Os(t)}(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let t=this._props;this._props={};for(let e in t)this._props[e]=t[e];this._props.state=this.state}return this._props}update(t){t.handleDOMEvents!=this._props.handleDOMEvents&&Os(this);let e=this._props;this._props=t,t.plugins&&(t.plugins.forEach(Pn),this.directPlugins=t.plugins),this.updateStateInner(t.state,e)}setProps(t){let e={};for(let t in this._props)e[t]=this._props[t];e.state=this.state;for(let i in t)e[i]=t[i];this.update(e)}updateState(t){this.updateStateInner(t,this._props)}updateStateInner(t,e){var i;let s=this.state,n=!1,r=!1;t.storedMarks&&this.composing&&(Ls(this),r=!0),this.state=t;let h=s.plugins!=t.plugins||this._props.plugins!=e.plugins;if(h||this._props.plugins!=e.plugins||this._props.nodeViews!=e.nodeViews){let t=$n(this);(function(t,e){let i=0,s=0;for(let s in t){if(t[s]!=e[s])return!0;i++}for(let t in e)s++;return i!=s})(t,this.nodeViews)&&(this.nodeViews=t,n=!0)}(h||e.handleDOMEvents!=this._props.handleDOMEvents)&&Os(this),this.editable=Dn(this),Tn(this);let o=dn(this),l=En(this),u=s.plugins==t.plugins||s.doc.eq(t.doc)?t.scrollToSelection>s.scrollToSelection?"to selection":"preserve":"reset",a=n||!this.docView.matchesNode(t.doc,l,o);!a&&t.selection.eq(s.selection)||(r=!0);let c="preserve"==u&&r&&null==this.dom.style.overflowAnchor&&function(t){let e,i,s=t.dom.getBoundingClientRect(),n=Math.max(0,s.top);for(let r=(s.left+s.right)/2,h=n+1;h<Math.min(innerHeight,s.bottom);h+=5){let s=t.root.elementFromPoint(r,h);if(!s||s==t.dom||!t.dom.contains(s))continue;let o=s.getBoundingClientRect();if(o.top>=n-20){e=s,i=o.top;break}}return{refDOM:e,refTop:i,stack:ti(t.dom)}}(this);if(r){this.domObserver.stop();let e=a&&(Be||Le)&&!this.composing&&!s.selection.empty&&!t.selection.empty&&function(t,e){let i=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(i)!=e.$anchor.start(i)}(s.selection,t.selection);if(a){let i=Le?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=function(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let i=function(t,e){for(;;){if(3==t.nodeType&&e)return t;if(1==t.nodeType&&e>0){if("false"==t.contentEditable)return null;e=Oe(t=t.childNodes[e-1])}else{if(!t.parentNode||Ee(t))return null;e=be(t),t=t.parentNode}}}(e.focusNode,e.focusOffset),s=function(t,e){for(;;){if(3==t.nodeType&&e<t.nodeValue.length)return t;if(1==t.nodeType&&e<t.childNodes.length){if("false"==t.contentEditable)return null;t=t.childNodes[e],e=0}else{if(!t.parentNode||Ee(t))return null;e=be(t)+1,t=t.parentNode}}}(e.focusNode,e.focusOffset);if(i&&s&&i!=s){let e=s.pmViewDesc,n=t.domObserver.lastChangedTextNode;if(i==n||s==n)return n;if(!e||!e.isText(s.nodeValue))return s;if(t.input.compositionNode==s){let t=i.pmViewDesc;if(t&&t.isText(i.nodeValue))return s}}return i||s}(this)),!n&&this.docView.update(t.doc,l,o,this)||(this.docView.updateOuterDeco(l),this.docView.destroy(),this.docView=Ai(t.doc,l,o,this.dom,this)),i&&!this.trackWrites&&(e=!0)}e||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&function(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),i=t.domSelectionRange();return xe(e.node,e.offset,i.anchorNode,i.anchorOffset)}(this))?Li(this,e):(Ji(this,t.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),(null===(i=this.dragging)||void 0===i?void 0:i.node)&&!s.doc.eq(t.doc)&&this.updateDraggedNode(this.dragging,s),"reset"==u?this.dom.scrollTop=0:"to selection"==u?this.scrollToSelection():c&&function({refDOM:t,refTop:e,stack:i}){let s=t?t.getBoundingClientRect().top:0;ei(i,0==s?0:s-e)}(c)}scrollToSelection(){let t=this.domSelectionRange().focusNode;if(t&&this.dom.contains(1==t.nodeType?t:t.parentNode))if(this.someProp("handleScrollToSelection",(t=>t(this))));else if(this.state.selection instanceof re){let e=this.docView.domAfterPos(this.state.selection.from);1==e.nodeType&&Ze(this,e.getBoundingClientRect(),t)}else Ze(this,this.coordsAtPos(this.state.selection.head,1),t)}destroyPluginViews(){let t;for(;t=this.pluginViews.pop();)t.destroy&&t.destroy()}updatePluginViews(t){if(t&&t.plugins==this.state.plugins&&this.directPlugins==this.prevDirectPlugins)for(let e=0;e<this.pluginViews.length;e++){let i=this.pluginViews[e];i.update&&i.update(this,t)}else{this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let e=this.directPlugins[t];e.spec.view&&this.pluginViews.push(e.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let e=this.state.plugins[t];e.spec.view&&this.pluginViews.push(e.spec.view(this))}}}updateDraggedNode(t,e){let i=t.node,s=-1;if(this.state.doc.nodeAt(i.from)==i.node)s=i.from;else{let t=i.from+(this.state.doc.content.size-e.doc.content.size);(t>0&&this.state.doc.nodeAt(t))==i.node&&(s=t)}this.dragging=new Js(t.slice,t.move,s<0?void 0:re.create(this.state.doc,s))}someProp(t,e){let i,s=this._props&&this._props[t];if(null!=s&&(i=e?e(s):s))return i;for(let s=0;s<this.directPlugins.length;s++){let n=this.directPlugins[s].props[t];if(null!=n&&(i=e?e(n):n))return i}let n=this.state.plugins;if(n)for(let s=0;s<n.length;s++){let r=n[s].props[t];if(null!=r&&(i=e?e(r):r))return i}}hasFocus(){if(Be){let t=this.root.activeElement;if(t==this.dom)return!0;if(!t||!this.dom.contains(t))return!1;for(;t&&this.dom!=t&&this.dom.contains(t);){if("false"==t.contentEditable)return!1;t=t.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&function(t){if(t.setActive)return t.setActive();if(ii)return t.focus(ii);let e=ti(t);t.focus(null==ii?{get preventScroll(){return ii={preventScroll:!0},!0}}:void 0),ii||(ii=!1,ei(e,0))}(this.dom),Li(this),this.domObserver.start()}get root(){let t=this._root;if(null==t)for(let t=this.dom.parentNode;t;t=t.parentNode)if(9==t.nodeType||11==t.nodeType&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t;return t||document}updateRoot(){this._root=null}posAtCoords(t){return hi(this,t)}coordsAtPos(t,e=1){return ai(this,t,e)}domAtPos(t,e=0){return this.docView.domFromPos(t,e)}nodeDOM(t){let e=this.docView.descAt(t);return e?e.nodeDOM:null}posAtDOM(t,e,i=-1){let s=this.docView.posFromDOM(t,e,i);if(null==s)throw new RangeError("DOM position not inside the editor");return s}endOfTextblock(t,e){return function(t,e,i){return wi==e&&gi==i?mi:(wi=e,gi=i,mi="up"==i||"down"==i?function(t,e,i){let s=e.selection,n="up"==i?s.$from:s.$to;return di(t,e,(()=>{let{node:e}=t.docView.domFromPos(n.pos,"up"==i?-1:1);for(;;){let i=t.docView.nearestDesc(e,!0);if(!i)break;if(i.node.isBlock){e=i.contentDOM||i.dom;break}e=i.dom.parentNode}let s=ai(t,n.pos,1);for(let t=e.firstChild;t;t=t.nextSibling){let e;if(1==t.nodeType)e=t.getClientRects();else{if(3!=t.nodeType)continue;e=Ae(t,0,t.nodeValue.length).getClientRects()}for(let t=0;t<e.length;t++){let n=e[t];if(n.bottom>n.top+1&&("up"==i?s.top-n.top>2*(n.bottom-s.top):n.bottom-s.bottom>2*(s.bottom-n.top)))return!1}}return!0}))}(t,e,i):function(t,e,i){let{$head:s}=e.selection;if(!s.parent.isTextblock)return!1;let n=s.parentOffset,r=!n,h=n==s.parent.content.size,o=t.domSelection();return o?pi.test(s.parent.textContent)&&o.modify?di(t,e,(()=>{let{focusNode:e,focusOffset:n,anchorNode:r,anchorOffset:h}=t.domSelectionRange(),l=o.caretBidiLevel;o.modify("move",i,"character");let u=s.depth?t.docView.domAfterPos(s.before()):t.dom,{focusNode:a,focusOffset:c}=t.domSelectionRange(),f=a&&!u.contains(1==a.nodeType?a:a.parentNode)||e==a&&n==c;try{o.collapse(r,h),e&&(e!=r||n!=h)&&o.extend&&o.extend(e,n)}catch(t){}return null!=l&&(o.caretBidiLevel=l),f})):"left"==i||"backward"==i?r:h:s.pos==s.start()||s.pos==s.end()}(t,e,i))}(this,e||this.state,t)}pasteHTML(t,e){return Ws(this,"",t,!1,e||new ClipboardEvent("paste"))}pasteText(t,e){return Ws(this,t,null,!0,e||new ClipboardEvent("paste"))}serializeForClipboard(t){return as(this,t)}destroy(){this.docView&&(function(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],dn(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,ke=null)}get isDestroyed(){return null==this.docView}dispatchEvent(t){return function(t,e){Es(t,e)||!ks[e.type]||!t.editable&&e.type in As||ks[e.type](t,e)}(this,t)}domSelectionRange(){let t=this.domSelection();return t?Ye&&11===this.root.nodeType&&function(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}(this.dom.ownerDocument)==this.dom&&function(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return bn(t,i)}let i;function s(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",s,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",s,!0),i?bn(t,i):null}(this,t)||t:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function En(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",(i=>{if("function"==typeof i&&(i=i(t.state)),i)for(let t in i)"class"==t?e.class+=" "+i[t]:"style"==t?e.style=(e.style?e.style+";":"")+i[t]:e[t]||"contenteditable"==t||"nodeName"==t||(e[t]=String(i[t]))})),e.translate||(e.translate="no"),[Zs.node(0,t.state.doc.content.size,e)]}function Tn(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:Zs.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Dn(t){return!t.someProp("editable",(e=>!1===e(t.state)))}function $n(t){let e=Object.create(null);function i(t){for(let i in t)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=t[i])}return t.someProp("nodeViews",i),t.someProp("markViews",i),e}function Pn(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}On.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};const Rn=["p",0],In=["blockquote",0],Un=["hr"],jn=["pre",["code",0]],Bn=["br"],Nn={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:()=>Rn},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:()=>In},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>Un},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM:t=>["h"+t.attrs.level,0]},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM:()=>jn},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs:t=>({src:t.getAttribute("src"),title:t.getAttribute("title"),alt:t.getAttribute("alt")})}],toDOM(t){let{src:e,alt:i,title:s}=t.attrs;return["img",{src:e,alt:i,title:s}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM:()=>Bn}},Fn=["em",0],_n=["strong",0],Ln=["code",0],zn={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs:t=>({href:t.getAttribute("href"),title:t.getAttribute("title")})}],toDOM(t){let{href:e,title:i}=t.attrs;return["a",{href:e,title:i},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:t=>"em"==t.type.name}],toDOM:()=>Fn},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:t=>"normal"!=t.style.fontWeight&&null},{style:"font-weight=400",clearMark:t=>"strong"==t.type.name},{style:"font-weight",getAttrs:t=>/^(bold(er)?|[5-9]\d{2,})$/.test(t)&&null}],toDOM:()=>_n},code:{code:!0,parseDOM:[{tag:"code"}],toDOM:()=>Ln}},Yn=new G({nodes:Nn,marks:zn}),Wn=["ol",0],Xn=["ul",0],Jn=["li",0],Hn={attrs:{order:{default:1,validate:"number"}},parseDOM:[{tag:"ol",getAttrs:t=>({order:t.hasAttribute("start")?+t.getAttribute("start"):1})}],toDOM:t=>1==t.attrs.order?Wn:["ol",{start:t.attrs.order},0]},Vn={parseDOM:[{tag:"ul"}],toDOM:()=>Xn},Qn={parseDOM:[{tag:"li"}],toDOM:()=>Jn,defining:!0};function Kn(t,e){let i={};for(let e in t)i[e]=t[e];for(let t in e)i[t]=e[t];return i}function qn(t,e,i){return t.append({ordered_list:Kn(Hn,{content:"list_item+",group:i}),bullet_list:Kn(Vn,{content:"list_item+",group:i}),list_item:Kn(Qn,{content:e})})}for(var Gn={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Zn={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},tr="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),er="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),ir=0;ir<10;ir++)Gn[48+ir]=Gn[96+ir]=String(ir);for(ir=1;ir<=24;ir++)Gn[ir+111]="F"+ir;for(ir=65;ir<=90;ir++)Gn[ir]=String.fromCharCode(ir+32),Zn[ir]=String.fromCharCode(ir);for(var sr in Gn)Zn.hasOwnProperty(sr)||(Zn[sr]=Gn[sr]);const nr="undefined"!=typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),rr="undefined"!=typeof navigator&&/Win/.test(navigator.platform);function hr(t){let e,i,s,n,r=t.split(/-(?!$)/),h=r[r.length-1];"Space"==h&&(h=" ");for(let t=0;t<r.length-1;t++){let h=r[t];if(/^(cmd|meta|m)$/i.test(h))n=!0;else if(/^a(lt)?$/i.test(h))e=!0;else if(/^(c|ctrl|control)$/i.test(h))i=!0;else if(/^s(hift)?$/i.test(h))s=!0;else{if(!/^mod$/i.test(h))throw new Error("Unrecognized modifier name: "+h);nr?n=!0:i=!0}}return e&&(h="Alt-"+h),i&&(h="Ctrl-"+h),n&&(h="Meta-"+h),s&&(h="Shift-"+h),h}function or(t,e,i=!0){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),i&&e.shiftKey&&(t="Shift-"+t),t}function lr(t){return new ye({props:{handleKeyDown:ur(t)}})}function ur(t){let e=function(t){let e=Object.create(null);for(let i in t)e[hr(i)]=t[i];return e}(t);return function(t,i){let s,n=function(t){var e=!(tr&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||er&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?Zn:Gn)[t.keyCode]||t.key||"Unidentified";return"Esc"==e&&(e="Escape"),"Del"==e&&(e="Delete"),"Left"==e&&(e="ArrowLeft"),"Up"==e&&(e="ArrowUp"),"Right"==e&&(e="ArrowRight"),"Down"==e&&(e="ArrowDown"),e}(i),r=e[or(n,i)];if(r&&r(t.state,t.dispatch,t))return!0;if(1==n.length&&" "!=n){if(i.shiftKey){let s=e[or(n,i,!1)];if(s&&s(t.state,t.dispatch,t))return!0}if((i.altKey||i.metaKey||i.ctrlKey)&&!(rr&&i.ctrlKey&&i.altKey)&&(s=Gn[i.keyCode])&&s!=n){let n=e[or(s,i)];if(n&&n(t.state,t.dispatch,t))return!0}}return!1}}const ar=(t,e)=>!t.selection.empty&&(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function cr(t,e,i=!1){for(let s=t;s;s="start"==e?s.firstChild:s.lastChild){if(s.isTextblock)return!0;if(i&&1!=s.childCount)return!1}return!1}function fr(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function dr(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){let i=t.node(e);if(t.index(e)+1<i.childCount)return t.doc.resolve(t.after(e+1));if(i.type.spec.isolating)break}return null}function pr(t){for(let e=0;e<t.edgeCount;e++){let{type:i}=t.edge(e);if(i.isTextblock&&!i.hasRequiredAttrs())return i}return null}function wr(t,e,i,s){let n,r,h=e.nodeBefore,o=e.nodeAfter,l=h.type.spec.isolating||o.type.spec.isolating;if(!l&&function(t,e,i){let s=e.nodeBefore,n=e.nodeAfter,r=e.index();return!(!(s&&n&&s.type.compatibleContent(n.type))||(!s.content.size&&e.parent.canReplace(r-1,r)?(i&&i(t.tr.delete(e.pos-s.nodeSize,e.pos).scrollIntoView()),0):!e.parent.canReplace(r,r+1)||!n.isTextblock&&!Bt(t.doc,e.pos)||(i&&i(t.tr.join(e.pos).scrollIntoView()),0)))}(t,e,i))return!0;let a=!l&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(n=(r=h.contentMatchAt(h.childCount)).findWrapping(o.type))&&r.matchType(n[0]||o.type).validEnd){if(i){let s=e.pos+o.nodeSize,r=u.empty;for(let t=n.length-1;t>=0;t--)r=u.from(n[t].create(null,r));r=u.from(h.copy(r));let l=t.tr.step(new Tt(e.pos-1,s,e.pos,s,new w(r,1,0),n.length,!0)),a=l.doc.resolve(s+2*n.length);a.nodeAfter&&a.nodeAfter.type==h.type&&Bt(l.doc,a.pos)&&l.join(a.pos),i(l.scrollIntoView())}return!0}let c=o.type.spec.isolating||s>0&&l?null:Zt.findFrom(e,1),f=c&&c.$from.blockRange(c.$to),d=f&&Rt(f);if(null!=d&&d>=e.depth)return i&&i(t.tr.lift(f,d).scrollIntoView()),!0;if(a&&cr(o,"start",!0)&&cr(h,"end")){let s=h,n=[];for(;n.push(s),!s.isTextblock;)s=s.lastChild;let r=o,l=1;for(;!r.isTextblock;r=r.firstChild)l++;if(s.canReplace(s.childCount,s.childCount,r.content)){if(i){let s=u.empty;for(let t=n.length-1;t>=0;t--)s=u.from(n[t].copy(s));i(t.tr.step(new Tt(e.pos-n.length,e.pos+o.nodeSize,e.pos+l,e.pos+o.nodeSize-l,new w(s,n.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function gr(t){return function(e,i){let s=e.selection,n=t<0?s.$from:s.$to,r=n.depth;for(;n.node(r).isInline;){if(!r)return!1;r--}return!!n.node(r).isTextblock&&(i&&i(e.tr.setSelection(se.create(e.doc,t<0?n.start(r):n.end(r)))),!0)}}const mr=gr(-1),yr=gr(1);function vr(...t){return function(e,i,s){for(let n=0;n<t.length;n++)if(t[n](e,i,s))return!0;return!1}}let br=vr(ar,((t,e,i)=>{let s=function(t,e){let{$cursor:i}=t.selection;return!i||(e?!e.endOfTextblock("backward",t):i.parentOffset>0)?null:i}(t,i);if(!s)return!1;let n=fr(s);if(!n){let i=s.blockRange(),n=i&&Rt(i);return null!=n&&(e&&e(t.tr.lift(i,n).scrollIntoView()),!0)}let r=n.nodeBefore;if(wr(t,n,e,-1))return!0;if(0==s.parent.content.size&&(cr(r,"end")||re.isSelectable(r)))for(let i=s.depth;;i--){let h=Nt(t.doc,s.before(i),s.after(i),w.empty);if(h&&h.slice.size<h.to-h.from){if(e){let i=t.tr.step(h);i.setSelection(cr(r,"end")?Zt.findFrom(i.doc.resolve(i.mapping.map(n.pos,-1)),-1):re.create(i.doc,n.pos-r.nodeSize)),e(i.scrollIntoView())}return!0}if(1==i||s.node(i-1).childCount>1)break}return!(!r.isAtom||n.depth!=s.depth-1||(e&&e(t.tr.delete(n.pos-r.nodeSize,n.pos).scrollIntoView()),0))}),((t,e,i)=>{let{$head:s,empty:n}=t.selection,r=s;if(!n)return!1;if(s.parent.isTextblock){if(i?!i.endOfTextblock("backward",t):s.parentOffset>0)return!1;r=fr(s)}let h=r&&r.nodeBefore;return!(!h||!re.isSelectable(h)||(e&&e(t.tr.setSelection(re.create(t.doc,r.pos-h.nodeSize)).scrollIntoView()),0))})),Mr=vr(ar,((t,e,i)=>{let s=function(t,e){let{$cursor:i}=t.selection;return!i||(e?!e.endOfTextblock("forward",t):i.parentOffset<i.parent.content.size)?null:i}(t,i);if(!s)return!1;let n=dr(s);if(!n)return!1;let r=n.nodeAfter;if(wr(t,n,e,1))return!0;if(0==s.parent.content.size&&(cr(r,"start")||re.isSelectable(r))){let i=Nt(t.doc,s.before(),s.after(),w.empty);if(i&&i.slice.size<i.to-i.from){if(e){let s=t.tr.step(i);s.setSelection(cr(r,"start")?Zt.findFrom(s.doc.resolve(s.mapping.map(n.pos)),1):re.create(s.doc,s.mapping.map(n.pos))),e(s.scrollIntoView())}return!0}}return!(!r.isAtom||n.depth!=s.depth-1||(e&&e(t.tr.delete(n.pos,n.pos+r.nodeSize).scrollIntoView()),0))}),((t,e,i)=>{let{$head:s,empty:n}=t.selection,r=s;if(!n)return!1;if(s.parent.isTextblock){if(i?!i.endOfTextblock("forward",t):s.parentOffset<s.parent.content.size)return!1;r=dr(s)}let h=r&&r.nodeAfter;return!(!h||!re.isSelectable(h)||(e&&e(t.tr.setSelection(re.create(t.doc,r.pos)).scrollIntoView()),0))}));const kr={Enter:vr(((t,e)=>{let{$head:i,$anchor:s}=t.selection;return!(!i.parent.type.spec.code||!i.sameParent(s)||(e&&e(t.tr.insertText("\n").scrollIntoView()),0))}),((t,e)=>{let i=t.selection,{$from:s,$to:n}=i;if(i instanceof oe||s.parent.inlineContent||n.parent.inlineContent)return!1;let r=pr(n.parent.contentMatchAt(n.indexAfter()));if(!r||!r.isTextblock)return!1;if(e){let i=(!s.parentOffset&&n.index()<n.parent.childCount?s:n).pos,h=t.tr.insert(i,r.createAndFill());h.setSelection(se.create(h.doc,i+1)),e(h.scrollIntoView())}return!0}),((t,e)=>{let{$cursor:i}=t.selection;if(!i||i.parent.content.size)return!1;if(i.depth>1&&i.after()!=i.end(-1)){let s=i.before();if(jt(t.doc,s))return e&&e(t.tr.split(s).scrollIntoView()),!0}let s=i.blockRange(),n=s&&Rt(s);return null!=n&&(e&&e(t.tr.lift(s,n).scrollIntoView()),!0)}),((t,e)=>{let{$from:i}=t.selection;if(t.selection instanceof re&&t.selection.node.isBlock)return!(!i.parentOffset||!jt(t.doc,i.pos)||(e&&e(t.tr.split(i.pos).scrollIntoView()),0));if(!i.depth)return!1;let s,n,r=[],h=!1,o=!1;for(let t=i.depth;;t--){if(i.node(t).isBlock){h=i.end(t)==i.pos+(i.depth-t),o=i.start(t)==i.pos-(i.depth-t),n=pr(i.node(t-1).contentMatchAt(i.indexAfter(t-1))),r.unshift(h&&n?{type:n}:null),s=t;break}if(1==t)return!1;r.unshift(null)}let l=t.tr;(t.selection instanceof se||t.selection instanceof oe)&&l.deleteSelection();let u=l.mapping.map(i.pos),a=jt(l.doc,u,r.length,r);if(a||(r[0]=n?{type:n}:null,a=jt(l.doc,u,r.length,r)),!a)return!1;if(l.split(u,r.length,r),!h&&o&&i.node(s).type!=n){let t=l.mapping.map(i.before(s)),e=l.doc.resolve(t);n&&i.node(s-1).canReplaceWith(e.index(),e.index()+1,n)&&l.setNodeMarkup(l.mapping.map(i.before(s)),n)}return e&&e(l.scrollIntoView()),!0})),"Mod-Enter":(t,e)=>{let{$head:i,$anchor:s}=t.selection;if(!i.parent.type.spec.code||!i.sameParent(s))return!1;let n=i.node(-1),r=i.indexAfter(-1),h=pr(n.contentMatchAt(r));if(!h||!n.canReplaceWith(r,r,h))return!1;if(e){let s=i.after(),n=t.tr.replaceWith(s,s,h.createAndFill());n.setSelection(Zt.near(n.doc.resolve(s),1)),e(n.scrollIntoView())}return!0},Backspace:br,"Mod-Backspace":br,"Shift-Backspace":br,Delete:Mr,"Mod-Delete":Mr,"Mod-a":(t,e)=>(e&&e(t.tr.setSelection(new oe(t.doc))),!0)},Ar={"Ctrl-h":kr.Backspace,"Alt-Backspace":kr["Mod-Backspace"],"Ctrl-d":kr.Delete,"Ctrl-Alt-Backspace":kr["Mod-Delete"],"Alt-Delete":kr["Mod-Delete"],"Alt-d":kr["Mod-Delete"],"Ctrl-a":mr,"Ctrl-e":yr};for(let t in kr)Ar[t]=kr[t];const xr=("undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"undefined"!=typeof os&&os.platform&&"darwin"==os.platform())?Ar:kr;class Sr extends s{__class__="KritzelText";fontFamily="Arial";fontSize=8;fontColor="#000000";initialWidth=1;initialHeight=1;scale=1;scaleFactor=1;isDebugInfoVisible=!0;isEditable=!0;isEditing=!1;editor=null;content=null;_schema=new G({nodes:qn(Yn.spec.nodes,"paragraph block*","block"),marks:Yn.spec.marks});uneditedObject=null;rows=1;get isEmpty(){if(!this.editor)return!0;const t=this.editor.state.doc;return 0===t.content.size||0===t.textContent.trim().length}constructor(t){super(),t&&(this.translateX=t.translateX||0,this.translateY=t.translateY||0,this.fontSize=t.fontSize||8,this.fontFamily=t.fontFamily||"Arial",this.fontColor=t.fontColor||"#000000",this.width=this.initialWidth/(this._core.store.state.scale<0?this._core.store.state.scale:1),this.height=1.2*this.fontSize/(this._core.store.state.scale<0?this._core.store.state.scale:1),this.scale=t.scale||1,this.scaleFactor=t.scaleX??1)}static create(t,e,i){const s=new Sr;return s._core=t,s.id=s.generateId(),s.workspaceId=t.store.state.activeWorkspace.id,s.fontSize=e,s.fontFamily=i,s.translateX=0,s.translateY=0,s.width=s.initialWidth/(s._core.store.state.scale<0?s._core.store.state.scale:1),s.height=1.2*s.fontSize/(s._core.store.state.scale<0?s._core.store.state.scale:1),s.backgroundColor="transparent",s.initialWidth=s.width,s.initialHeight=s.height,s.scaleFactor=1,s.scale=s._core.store.state.scale,s.zIndex=t.store.currentZIndex,s.editor=s.createEditor(),s}mount(t){null!==t&&!1!==this.isInViewport()&&(t.style.fontFamily=this.fontFamily,t.style.fontSize=`${this.fontSize}pt`,t.style.color=this.fontColor,this.isMounted&&this.elementRef===t&&this.editor.dom.parentElement===t||(this.elementRef=t,this.elementRef.style.whiteSpace="pre-wrap",this.elementRef.style.wordWrap="break-word",this.elementRef.innerHTML="",this.elementRef.appendChild(this.editor.dom),this.isMounted=!0),requestAnimationFrame((()=>this.adjustSizeOnInput())))}createEditor(){const t=this._schema.node("doc",null,[this._schema.node("paragraph")]);return new On(null,{state:ge.create({doc:t,plugins:[lr(xr)]}),editable:()=>!1,dispatchTransaction:t=>{const e=this.editor.state.apply(t);this.editor.updateState(e),t.docChanged&&(this.content=e.doc.toJSON(),this.adjustSizeOnInput(),t.getMeta("fromRemote")||this._core.store.state.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const e=this.editor.state.schema.nodeFromJSON(t),i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",!0),this.editor.dispatch(i)}}adjustSizeOnInput(){const t=this.elementRef;if(t&&this.isMounted&&t.scrollWidth>0){const e=this.totalWidth,i=this.totalHeight,s=t.scrollHeight;if(this.width=t.scrollWidth*this.scaleFactor,this.height=s*this.scaleFactor,0!==this.rotation){const t=(this.totalWidth-e)/2/this.scale,s=(this.totalHeight-i)/2/this.scale;if(0!==t||0!==s){const e=Math.cos(this.rotation),i=Math.sin(this.rotation),n=i*t+e*s;this.translateX+=e*t-i*s-t,this.translateY+=n-s}}}}resize(t,e,i,s){if(i<=1||s<=1)return;const n=this.width/this.scaleFactor,r=this.height/this.scaleFactor;this.scaleFactor=Math.min(i/n,s/r),this.width=n*this.scaleFactor,this.height=r*this.scaleFactor,this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this)}focus(t){if(this.editor){const e=this.editor.state.doc;if(t.x&&t.y){const i=this.editor.posAtCoords({left:t.x,top:t.y});if(i)return this.editor.dispatch(this.editor.state.tr.setSelection(se.create(e,i.pos))),this.editor.focus(),void(r.isIOS()&&this.scrollIntoViewOnIOS())}const i=Math.max(1,e.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(se.create(e,i))),this.editor.focus(),r.isIOS()&&this.scrollIntoViewOnIOS()}}scrollIntoViewOnIOS(){setTimeout((()=>{this.editor&&this.editor.dom&&this.editor.dom.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"})}),300)}edit(e){n.disableInteractiveWidget(),this.uneditedObject=this.clone(),this._core.store.setState("activeTool",t.getTool("text")),this.editor.setProps({editable:()=>!0}),this.isEditing=!0,this._core.rerender(),this.adjustSizeOnInput(),this.focus({x:e?.clientX,y:e?.clientY}),n.enableInteractiveWidget()}save(){requestAnimationFrame((()=>this.adjustSizeOnInput())),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:e,_schema:i,element:s,totalWidth:n,totalHeight:r,editor:h,uneditedObject:o,...l}=this,u=structuredClone(l);return s&&"object"==typeof s&&"nodeType"in s&&1===s.nodeType&&(u.element=s.cloneNode(!0)),u}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}}var Cr,Or,Er={},Tr=(Cr||(Cr=1,function(){var t=Object.defineProperty;function e(t,e,i,s=t=>t){return t*s(.5-e*(.5-i))}function i(t,e){return[t[0]+e[0],t[1]+e[1]]}function s(t,e){return[t[0]-e[0],t[1]-e[1]]}function n(t,e){return[t[0]*e,t[1]*e]}function r(t){return[t[1],-t[0]]}function h(t,e){return t[0]*e[0]+t[1]*e[1]}function o(t,e){return t[0]===e[0]&&t[1]===e[1]}function l(t,e){return function(t){return t[0]*t[0]+t[1]*t[1]}(s(t,e))}function u(t){return function(t,e){return[t[0]/e,t[1]/e]}(t,function(t){return Math.hypot(t[0],t[1])}(t))}function a(t,e){return Math.hypot(t[1]-e[1],t[0]-e[0])}function c(t,e,i){let s=Math.sin(i),n=Math.cos(i),r=t[0]-e[0],h=t[1]-e[1];return[r*n-h*s+e[0],r*s+h*n+e[1]]}function f(t,e,r){return i(t,n(s(e,t),r))}function d(t,e,s){return i(t,n(e,s))}((e,i)=>{for(var s in(e=>{t(e,"__esModule",{value:!0})})(e),i)t(e,s,{get:i[s],enumerable:!0})})(Er,{default:()=>M,getStroke:()=>b,getStrokeOutlinePoints:()=>y,getStrokePoints:()=>v});var{min:p,PI:w}=Math,g=.275,m=w+1e-4;function y(t,o={}){let{size:a=16,smoothing:w=.5,thinning:y=.5,simulatePressure:v=!0,easing:b=t=>t,start:M={},end:k={},last:A=!1}=o,{cap:x=!0,easing:S=t=>t*(2-t)}=M,{cap:C=!0,easing:O=t=>--t*t*t+1}=k;if(0===t.length||a<=0)return[];let E,T=t[t.length-1].runningLength,D=!1===M.taper?0:!0===M.taper?Math.max(a,T):M.taper,$=!1===k.taper?0:!0===k.taper?Math.max(a,T):k.taper,P=Math.pow(a*w,2),R=[],I=[],U=t.slice(0,10).reduce(((t,e)=>{let i=e.pressure;if(v){let s=p(1,e.distance/a),n=p(1,1-s);i=p(1,t+s*g*(n-t))}return(t+i)/2}),t[0].pressure),j=e(a,y,t[t.length-1].pressure,b),B=t[0].vector,N=t[0].point,F=N,_=N,L=F,z=!1;for(let o=0;o<t.length;o++){let{pressure:u}=t[o],{point:d,vector:w,distance:M,runningLength:k}=t[o];if(o<t.length-1&&T-k<3)continue;if(y){if(v){let t=p(1,M/a),e=p(1,1-t);u=p(1,U+t*g*(e-U))}j=e(a,y,u,b)}else j=a/2;void 0===E&&(E=j);let A=k<D?S(k/D):1,x=T-k<$?O((T-k)/$):1;j=Math.max(.01,j*Math.min(A,x));let C=(o<t.length-1?t[o+1]:t[o]).vector,Y=o<t.length-1?h(w,C):1,W=null!==Y&&Y<0;if(h(w,B)<0&&!z||W){let t=n(r(B),j);for(let e=1/13,n=0;n<=1;n+=e)_=c(s(d,t),d,m*n),R.push(_),L=c(i(d,t),d,m*-n),I.push(L);N=_,F=L,W&&(z=!0);continue}if(z=!1,o===t.length-1){let t=n(r(w),j);R.push(s(d,t)),I.push(i(d,t));continue}let X=n(r(f(C,w,Y)),j);_=s(d,X),(o<=1||l(N,_)>P)&&(R.push(_),N=_),L=i(d,X),(o<=1||l(F,L)>P)&&(I.push(L),F=L),U=u,B=w}let Y=t[0].point.slice(0,2),W=t.length>1?t[t.length-1].point.slice(0,2):i(t[0].point,[1,1]),X=[],J=[];if(1===t.length){if(!D&&!$||A){let t=d(Y,u(r(s(Y,W))),-(E||j)),e=[];for(let i=1/13,s=i;s<=1;s+=i)e.push(c(t,Y,2*m*s));return e}}else{if(!(D||$&&1===t.length))if(x)for(let t=1/13,e=t;e<=1;e+=t){let t=c(I[0],Y,m*e);X.push(t)}else{let t=s(R[0],I[0]),e=n(t,.5),r=n(t,.51);X.push(s(Y,e),s(Y,r),i(Y,r),i(Y,e))}let e=r(function(t){return[-t[0],-t[1]]}(t[t.length-1].vector));if($||D&&1===t.length)J.push(W);else if(C){let t=d(W,e,j);for(let e=1/29,i=e;i<1;i+=e)J.push(c(t,W,3*m*i))}else J.push(i(W,n(e,j)),i(W,n(e,.99*j)),s(W,n(e,.99*j)),s(W,n(e,j)))}return R.concat(J,I.reverse(),X)}function v(t,e={}){var n;let{streamline:r=.5,size:h=16,last:l=!1}=e;if(0===t.length)return[];let c=.15+.85*(1-r),d=Array.isArray(t[0])?t:t.map((({x:t,y:e,pressure:i=.5})=>[t,e,i]));if(2===d.length){let t=d[1];d=d.slice(0,-1);for(let e=1;e<5;e++)d.push(f(d[0],t,e/4))}1===d.length&&(d=[...d,[...i(d[0],[1,1]),...d[0].slice(2)]]);let p=[{point:[d[0][0],d[0][1]],pressure:d[0][2]>=0?d[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],w=!1,g=0,m=p[0],y=d.length-1;for(let t=1;t<d.length;t++){let e=l&&t===y?d[t].slice(0,2):f(m.point,d[t],c);if(o(m.point,e))continue;let i=a(e,m.point);if(g+=i,t<y&&!w){if(g<h)continue;w=!0}m={point:e,pressure:d[t][2]>=0?d[t][2]:.5,vector:u(s(m.point,e)),distance:i,runningLength:g},p.push(m)}return p[0].vector=(null==(n=p[1])?void 0:n.vector)||[0,0],p}function b(t,e={}){return y(v(t,e),e)}var M=b}()),Er);class Dr{static average(t,e){return(t+e)/2}}class $r extends s{__class__="KritzelPath";points;d;stroke="none";strokeWidth;lineSlack=.5;fill;x=0;y=0;height=0;width=0;scale=1;options;isVisible=!0;isDebugInfoVisible=!0;isCompleted=!1;_adjustedPoints=null;get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t){super(),this.options=t,this.points=t?.points??[],this.translateX=t?.translateX??0,this.translateY=t?.translateY??0,this.scale=t?.scale??1,this.strokeWidth=t?.strokeWidth??8,this.fill=t?.fill??"#000000",this.d=this.generateSvgPath(),this.updateDimensions()}static create(t,e){const i=new $r;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.options=e,i.points=e?.points??[],i.translateX=e?.translateX??0,i.translateY=e?.translateY??0,i.scale=e?.scale??1,i.strokeWidth=e?.strokeWidth??8,i.fill=e?.fill??"#000000",i.opacity=e?.opacity??1,i.zIndex=t.store.currentZIndex,i.d=i.generateSvgPath(),i.updateDimensions(),i}resize(t,e,i,s){if(i<=1||s<=1)return;const n=i/this.width,r=s/this.height;this.width=i,this.height=s,this.points=this.points.map((([t,e])=>[t*n,e*r])),this.d=this.generateSvgPath(),this.width=Math.max(...this.points.map((t=>t[0])))-Math.min(...this.points.map((t=>t[0])))+this.strokeWidth,this.height=Math.max(...this.points.map((t=>t[1])))-Math.min(...this.points.map((t=>t[1])))+this.strokeWidth,this.x=Math.min(...this.points.map((t=>t[0])))-this.strokeWidth/2,this.y=Math.min(...this.points.map((t=>t[1])))-this.strokeWidth/2,this.translateX=t,this.translateY=e,this._adjustedPoints=null,this._core.store.state.objects.update(this)}rotate(t){this.rotation=t,this._adjustedPoints=null,this._core.store.state.objects.update(this)}move(t,e,i,s){const n=(e-s)/this._core.store.state.scale;this.translateX+=(t-i)/this._core.store.state.scale,this.translateY+=n,this._adjustedPoints=null,this._core.store.state.objects.update(this)}hitTest(t,e){const i=this.strokeWidth/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),1===this._adjustedPoints.length){const s=this._adjustedPoints[0];return this.pointToLineSegmentDistance(t,e,s[0],s[1],s[0],s[1])<=i}for(let s=0;s<this._adjustedPoints.length-1;s++){const n=this._adjustedPoints[s],r=this._adjustedPoints[s+1];if(this.pointToLineSegmentDistance(t,e,n[0],n[1],r[0],r[1])<=i)return!0}return!1}hitTestPolygon(t){const e=this.strokeWidth/this.scale/2;null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const s=[{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,e]of this._adjustedPoints)if(i.isPointInPolygon({x:t,y:e},s))return!0;for(const t of s)if(this.hitTest(t.x,t.y))return!0;for(let t=0;t<this._adjustedPoints.length-1;t++){const e={x:this._adjustedPoints[t][0],y:this._adjustedPoints[t][1]},n={x:this._adjustedPoints[t+1][0],y:this._adjustedPoints[t+1][1]};for(let t=0;t<s.length;t++)if(i.intersectLines(e,n,s[t],s[(t+1)%s.length]))return!0}for(let t=0;t<this._adjustedPoints.length-1;t++){const i=this._adjustedPoints[t],n=this._adjustedPoints[t+1];for(let t=0;t<s.length;t++){const r=s[t],h=s[(t+1)%s.length],o=this.pointToLineSegmentDistance(r.x,r.y,i[0],i[1],n[0],n[1]),l=this.pointToLineSegmentDistance(h.x,h.y,i[0],i[1],n[0],n[1]),u=this.pointToLineSegmentDistance(i[0],i[1],r.x,r.y,h.x,h.y),a=this.pointToLineSegmentDistance(n[0],n[1],r.x,r.y,h.x,h.y);if(Math.min(o,l,u,a)<=e)return!0}}return!1}updatePosition(t,e){this.translateX=t,this.translateY=e,this._adjustedPoints=null,this._core.store.state.objects.update(this)}computeAdjustedPoints(){if(!this.points?.length)return[];const t=this.rotation,e=Math.cos(t),i=Math.sin(t),s=this.points.map((t=>t[0])),n=this.points.map((t=>t[1])),r={x:(Math.min(...s)+Math.max(...s))/2,y:(Math.min(...n)+Math.max(...n))/2},{x:h,y:o}=r;return this.points.map((([t,s])=>{const n=t-h,r=s-o;return[h+n*e-r*i,o+n*i+r*e]})).map((([t,e])=>[Math.abs(t-this.x)/this.scale+this.translateX,Math.abs(e-this.y)/this.scale+this.translateY]))}pointToLineSegmentDistance(t,e,i,s,n,r){const h=n-i,o=r-s,l=h*h+o*o;let u,a,c=-1;0!==l&&(c=((t-i)*h+(e-s)*o)/l),c<0?(u=i,a=s):c>1?(u=n,a=r):(u=i+c*h,a=s+c*o);const f=t-u,d=e-a;return Math.sqrt(f*f+d*d)}updateDimensions(){const t=this.points.map((([t,e])=>[t*Math.cos(this.rotation)-e*Math.sin(this.rotation),t*Math.sin(this.rotation)+e*Math.cos(this.rotation)])),e=Math.min(...t.map((t=>t[0]-this.strokeWidth/2))),i=Math.min(...t.map((t=>t[1]-this.strokeWidth/2))),s=Math.max(...t.map((t=>t[0]+this.strokeWidth/2))),n=Math.max(...t.map((t=>t[1]+this.strokeWidth/2)));this.width=s-e+this.lineSlack,this.height=n-i+this.lineSlack,this.x=e,this.y=i,this.translateX=(this.x+this.translateX)/this.scale,this.translateY=(this.y+this.translateY)/this.scale}generateSvgPath(){const t=this.getStrokeFromPoints(this.points,this.strokeWidth);return this.getSvgPathFromStroke(t)}getStrokeFromPoints(t,e){return Tr.getStroke(t,{size:e,thinning:.5,smoothing:.5,streamline:.5,easing:t=>t,simulatePressure:!0,last:!0,start:{cap:!0,taper:0,easing:t=>t},end:{cap:!0,taper:0,easing:t=>t}})}getSvgPathFromStroke(t,e=!0){const i=t.length;if(i<4)return"";let s=t[0],n=t[1];const r=t[2];let h=`M${s[0].toFixed(2)},${s[1].toFixed(2)} Q${n[0].toFixed(2)},${n[1].toFixed(2)} ${Dr.average(n[0],r[0]).toFixed(2)},${Dr.average(n[1],r[1]).toFixed(2)} T`;for(let e=2,r=i-1;e<r;e++)s=t[e],n=t[e+1],h+=`${Dr.average(s[0],n[0]).toFixed(2)},${Dr.average(s[1],n[1]).toFixed(2)} `;return e&&(h+="Z"),h}isLowRes(){if(!this._core)return!1;const t=this._core.store.state.scale;return this.boundingBox.width*t*(this.boundingBox.height*t)<500}getClipPoint(t){const e=this.centerX,i=this.centerY,s=this.strokeWidth/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),this._adjustedPoints.length<1)return null;let n=!0;for(let r=1;r<=32;r++){const h=r/32,o=t.x+(e-t.x)*h,l=t.y+(i-t.y)*h;let u=1/0;if(1===this._adjustedPoints.length){const t=this._adjustedPoints[0],e=o-t[0],i=l-t[1];u=Math.sqrt(e*e+i*i)}else for(let t=0;t<this._adjustedPoints.length-1;t++){const e=this._adjustedPoints[t],i=this._adjustedPoints[t+1],s=this.pointToLineSegmentDistance(o,l,e[0],e[1],i[0],i[1]);s<u&&(u=s)}const a=u<=s;if(n&&a){let n=(r-1)/32,o=h;for(let r=0;r<8;r++){const r=(n+o)/2,h=t.x+(e-t.x)*r,l=t.y+(i-t.y)*r;let u=1/0;if(1===this._adjustedPoints.length){const t=this._adjustedPoints[0],e=h-t[0],i=l-t[1];u=Math.sqrt(e*e+i*i)}else for(let t=0;t<this._adjustedPoints.length-1;t++){const e=this._adjustedPoints[t],i=this._adjustedPoints[t+1],s=this.pointToLineSegmentDistance(h,l,e[0],e[1],i[0],i[1]);s<u&&(u=s)}u<=s?o=r:n=r}const l=(n+o)/2;return{x:t.x+(e-t.x)*l,y:t.y+(i-t.y)*l}}n=!a}return null}}class Pr extends s{__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 e=new Pr;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.x=0,e.y=0,e.translateX=0,e.translateY=0,e.scale=e._core.store.state.scale,e.zIndex=t.store.currentZIndex,e}resize(t,e,i,s){if(i<=1||s<=1)return;const n=s/this.height;this.width=this.width*n,this.height=this.height*n,this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this)}calculateScaledDimensions(t){let e=t.width,i=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const s=Math.min(this.maxWidth/t.width,this.maxHeight/t.height);e=t.width*s,i=t.height*s}return{scaledWidth:e,scaledHeight:i}}}class Rr extends s{__class__="KritzelLine";startX;startY;endX;endY;controlX;controlY;stroke;strokeWidth;scale=1;options;startAnchor;endAnchor;arrows;isVisible=!0;isDebugInfoVisible=!0;isCompleted=!1;_adjustedPoints=null;_clipInfo=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,e){const i=new Rr;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.options=e,i.startX=e?.startX??0,i.startY=e?.startY??0,i.endX=e?.endX??0,i.endY=e?.endY??0,i.controlX=e?.controlX,i.controlY=e?.controlY,i.translateX=e?.translateX??0,i.translateY=e?.translateY??0,i.scale=e?.scale??1,i.strokeWidth=e?.strokeWidth??4,i.stroke=e?.stroke??"#000000",i.opacity=e?.opacity??1,i.startAnchor=e?.startAnchor,i.endAnchor=e?.endAnchor,i.arrows=e?.arrows,i.zIndex=t.store.currentZIndex,i.updateDimensions(),i}resize(t,e,i,s){if(i<=1||s<=1)return;const n=i/this.width,r=s/this.height;this.startX=this.startX*n,this.startY=this.startY*r,this.endX=this.endX*n,this.endY=this.endY*r,void 0!==this.controlX&&void 0!==this.controlY&&(this.controlX=this.controlX*n,this.controlY=this.controlY*r);const{minX:h,minY:o,maxX:l,maxY:u}=this.calculateBoundingBox();this.width=l-h,this.height=u-o,this.x=h,this.y=o,this.translateX=t,this.translateY=e,this._adjustedPoints=null,this._clipInfo=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._clipInfo=null,this._core.store.state.objects.update(this)}move(t,e,i,s){const n=(e-s)/this._core.store.state.scale;this.translateX+=(t-i)/this._core.store.state.scale,this.translateY+=n,this.startAnchor&&this._core.anchorManager.updateAnchorsForObject(this.startAnchor.objectId),this.endAnchor&&this._core.anchorManager.updateAnchorsForObject(this.endAnchor.objectId),this._adjustedPoints=null,this._clipInfo=null,this._core.store.state.objects.update(this)}hitTest(t,e){const i=Math.max(this.strokeWidth,20)/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),void 0!==this.controlX&&void 0!==this.controlY){const s=this.getClipInfo();return this.pointToBezierDistance(t,e,s.start?.t??0,s.end?.t??1)<=i}const s=this.getClipInfo(),n=s.start?[s.start.x,s.start.y]:this._adjustedPoints[0],r=s.end?[s.end.x,s.end.y]:this._adjustedPoints[1];return this.pointToLineSegmentDistance(t,e,n[0],n[1],r[0],r[1])<=i}hitTestPolygon(t){const e=this.strokeWidth/this.scale/2;null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const s=this.getClipInfo(),n=[{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}],r=s.start?[s.start.x,s.start.y]:this._adjustedPoints[0],h=s.end?[s.end.x,s.end.y]:this._adjustedPoints[1],o=[r,h];for(const[t,e]of o)if(i.isPointInPolygon({x:t,y:e},n))return!0;for(const t of n)if(this.hitTest(t.x,t.y))return!0;if(void 0!==this.controlX&&void 0!==this.controlY){const t=this._adjustedPoints[0],r=this._adjustedPoints[1],h=this.computeAdjustedControlPoint(),o=s.start?.t??0,l=s.end?.t??1,u=20;for(let s=0;s<=u;s++){const a=o+s/u*(l-o),c=1-a,f=c*c*t[0]+2*c*a*h[0]+a*a*r[0],d=c*c*t[1]+2*c*a*h[1]+a*a*r[1];if(i.isPointInPolygon({x:f,y:d},n))return!0;for(let t=0;t<n.length;t++){const i=n[t],s=n[(t+1)%n.length];if(this.pointToLineSegmentDistance(f,d,i.x,i.y,s.x,s.y)<=e)return!0}}return!1}const l={x:r[0],y:r[1]},u={x:h[0],y:h[1]};for(let t=0;t<n.length;t++){const s=n[t],r=n[(t+1)%n.length];if(i.intersectLines(l,u,s,r))return!0;const h=this.pointToLineSegmentDistance(s.x,s.y,l.x,l.y,u.x,u.y),o=this.pointToLineSegmentDistance(r.x,r.y,l.x,l.y,u.x,u.y),a=this.pointToLineSegmentDistance(l.x,l.y,s.x,s.y,r.x,r.y),c=this.pointToLineSegmentDistance(u.x,u.y,s.x,s.y,r.x,r.y);if(Math.min(h,o,a,c)<=e)return!0}return!1}updatePosition(t,e){this.translateX=t,this.translateY=e,this._adjustedPoints=null,this._clipInfo=null,this._core.store.state.objects.update(this)}updateEndpoint(t,e,i){"start"===t?(this.startX=e,this.startY=i):(this.endX=e,this.endY=i);const s=this.width,n=this.height,{minX:r,minY:h,maxX:o,maxY:l}=this.calculateBoundingBox(),u=r-this.x,a=h-this.y,c=o-r,f=l-h,d=(c-s)/2,p=(f-n)/2;this.x=r,this.y=h,this.width=c,this.height=f;const w=Math.cos(this.rotation),g=Math.sin(this.rotation),m=u+d,y=a+p,v=m*g+y*w-p;this.translateX+=(m*w-y*g-d)/this.scale,this.translateY+=v/this.scale,this._adjustedPoints=null,this._clipInfo=null,this._core.store.state.objects.update(this)}updateControlPoint(t,e){this.controlX=t,this.controlY=e;const i=this.width,s=this.height,{minX:n,minY:r,maxX:h,maxY:o}=this.calculateBoundingBox(),l=n-this.x,u=r-this.y,a=h-n,c=o-r,f=(a-i)/2,d=(c-s)/2;this.x=n,this.y=r,this.width=a,this.height=c;const p=Math.cos(this.rotation),w=Math.sin(this.rotation),g=l+f,m=u+d,y=g*w+m*p-d;this.translateX+=(g*p-m*w-f)/this.scale,this.translateY+=y/this.scale,this._adjustedPoints=null,this._clipInfo=null,this._core.store.state.objects.update(this)}computeAdjustedPoints(){const t=[[this.startX,this.startY],[this.endX,this.endY]],e=this.rotation,i=Math.cos(e),s=Math.sin(e),n=t.map((t=>t[0])),r=t.map((t=>t[1])),h={x:(Math.min(...n)+Math.max(...n))/2,y:(Math.min(...r)+Math.max(...r))/2},{x:o,y:l}=h;return t.map((([t,e])=>{const n=t-o,r=e-l;return[o+n*i-r*s,l+n*s+r*i]})).map((([t,e])=>[(t-this.x)/this.scale+this.translateX,(e-this.y)/this.scale+this.translateY]))}pointToLineSegmentDistance(t,e,i,s,n,r){const h=n-i,o=r-s,l=h*h+o*o;let u,a,c=-1;0!==l&&(c=((t-i)*h+(e-s)*o)/l),c<0?(u=i,a=s):c>1?(u=n,a=r):(u=i+c*h,a=s+c*o);const f=t-u,d=e-a;return Math.sqrt(f*f+d*d)}pointToBezierDistance(t,e,i=0,s=1){null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const n=this._adjustedPoints[0],r=this._adjustedPoints[1],h=this.computeAdjustedControlPoint();let o=1/0;for(let l=0;l<=20;l++){const u=i+l/20*(s-i),a=1-u,c=t-(a*a*n[0]+2*a*u*h[0]+u*u*r[0]),f=e-(a*a*n[1]+2*a*u*h[1]+u*u*r[1]),d=Math.sqrt(c*c+f*f);d<o&&(o=d)}return o}getClipInfo(){if(this._clipInfo)return this._clipInfo;const t=this.endAnchor,e={};if(this.startAnchor){const t=this._core.anchorManager.findAnchorTarget(this,"start");if(t){const i=this._core.anchorManager.computeAnchorClipInfo(this,"start",t);i&&(e.start={x:i.worldX,y:i.worldY,t:i.t})}}if(t){const t=this._core.anchorManager.findAnchorTarget(this,"end");if(t){const i=this._core.anchorManager.computeAnchorClipInfo(this,"end",t);i&&(e.end={x:i.worldX,y:i.worldY,t:i.t})}}return this._clipInfo=e,e}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,e=Math.cos(t),i=Math.sin(t),s=[this.startX,this.endX],n=[this.startY,this.endY],r={x:(Math.min(...s)+Math.max(...s))/2,y:(Math.min(...n)+Math.max(...n))/2},{x:h,y:o}=r,l=this.controlX-h,u=this.controlY-o;return[(h+l*e-u*i-this.x)/this.scale+this.translateX,(o+l*i+u*e-this.y)/this.scale+this.translateY]}get rotatedPolygon(){const t=this.padding,{minX:e,minY:i,maxX:s,maxY:n}=Rr.calculateBoundingBox(this.startX,this.startY,this.endX,this.endY,this.controlX,this.controlY,this.strokeWidth),r=e-this.x+t,h=i-this.y+t,o=s-this.x+t,l=n-this.y+t,u={x:r,y:h},a={x:o,y:h},c={x:o,y:l},f={x:r,y:l},d=this.totalWidth/2,p=this.totalHeight/2,w=this.rotation,g=Math.cos(w),m=Math.sin(w),y=t=>({x:((t.x-d)*g-(t.y-p)*m+d)/this.scale+this.translateX,y:((t.x-d)*m+(t.y-p)*g+p)/this.scale+this.translateY});return{topLeft:y(u),topRight:y(a),bottomRight:y(c),bottomLeft:y(f)}}static calculateBoundingBox(t,e,i,s,n,r,h){let o=Math.min(t,i),l=Math.min(e,s),u=Math.max(t,i),a=Math.max(e,s);if(void 0!==n&&void 0!==r){const h=t-2*n+i;if(0!==h){const e=(t-n)/h;if(e>0&&e<1){const s=(1-e)*(1-e)*t+2*(1-e)*e*n+e*e*i;o=Math.min(o,s),u=Math.max(u,s)}}const c=e-2*r+s;if(0!==c){const t=(e-r)/c;if(t>0&&t<1){const i=(1-t)*(1-t)*e+2*(1-t)*t*r+t*t*s;l=Math.min(l,i),a=Math.max(a,i)}}}const c=h/2;return{minX:o-c,minY:l-c,maxX:u+c,maxY:a+c}}calculateBoundingBox(){return Rr.calculateBoundingBox(this.startX,this.startY,this.endX,this.endY,this.controlX,this.controlY,this.strokeWidth)}updateDimensions(){const{minX:t,minY:e,maxX:i,maxY:s}=this.calculateBoundingBox();this.width=i-t,this.height=s-e,this.x=t,this.y=e,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 e="start"===t?this.arrows?.start:this.arrows?.end;return e?.size??3*this.strokeWidth}getArrowFill(t){const e="start"===t?this.arrows?.start:this.arrows?.end;return e?.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 Ir extends s{__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 e=this._core.store.state.objects.filter((e=>e.id===t));return e.length>0?e[0]:null})).filter((t=>null!==t))}get length(){return this.childIds.length}static create(t){const e=new Ir;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.scale=t.store.state.scale,e.zIndex=t.store.currentZIndex,e}static createFromObjects(t,e){const i=Ir.create(t);return e.forEach((t=>{i.childIds.push(t.id)})),i.refreshBoundingBox(),i.captureChildSnapshots(),i}static findParentGroup(t,e){const i=t.store.state.objects.filter((t=>"KritzelGroup"===t.__class__));for(const t of i)if(t.childIds.includes(e))return t;return null}addChild(t){this.childIds.includes(t.id)||(this.childIds.push(t.id),this.refreshBoundingBox(),this.captureChildSnapshots())}removeChild(t){const e=this.childIds.indexOf(t);-1!==e&&(this.childIds.splice(e,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,e=Math.cos(-t),i=Math.sin(-t);let s=1/0,n=-1/0,r=1/0,h=-1/0;this.children.forEach((t=>{const o=t.rotatedPolygon;[o.topLeft,o.topRight,o.bottomRight,o.bottomLeft].forEach((t=>{const o=t.x*e-t.y*i,l=t.x*i+t.y*e;o<s&&(s=o),o>n&&(n=o),l<r&&(r=l),l>h&&(h=l)}))}));const o=h-r;this.width=(n-s-this.padding)*this.scale,this.height=(o-this.padding)*this.scale;const l=(s+n)/2,u=(r+h)/2,a=Math.cos(t),c=Math.sin(t),f=l*c+u*a;this.translateX=l*a-u*c-(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,e,i,s){const n=(t-i)/this._core.store.state.scale,r=(e-s)/this._core.store.state.scale;this.translateX+=n,this.translateY+=r,this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.children.forEach((n=>{n.move(t,e,i,s),this._core.anchorManager.updateAnchorsForObject(n.id)}))})),this.unchangedChildSnapshots.forEach((t=>{t.translateX+=n,t.translateY+=r}))}resize(t,e,i,s){const n=i/this.width,r=s/this.height,h=this.translateX+this.totalWidth/2/this.scale,o=this.translateY+this.totalHeight/2/this.scale,l=t+(i+2*this.padding)/2/this.scale,u=e+(s+2*this.padding)/2/this.scale,a=this.rotation,c=Math.cos(-a),f=Math.sin(-a),d=Math.cos(a),p=Math.sin(a);this._core.store.state.objects.transaction((()=>{this.children.forEach((t=>{const e=t.translateX+t.totalWidth/2/t.scale-h,i=t.translateY+t.totalHeight/2/t.scale-o,s=(e*c-i*f)*n,w=(e*f+i*c)*r,g=l+(s*d-w*p),m=u+(s*p+w*d),y=t.rotation-a,v=Math.cos(y),b=Math.sin(y),M=Math.sqrt(Math.pow(n*v,2)+Math.pow(r*b,2)),k=Math.sqrt(Math.pow(n*b,2)+Math.pow(r*v,2)),A=t.width*M,x=t.height*k;t.resize(g-(A+2*t.padding)/2/t.scale,m-(x+2*t.padding)/2/t.scale,A,x),this._core.anchorManager.updateAnchorsForObject(t.id)})),this.refreshBoundingBox(),this.captureChildSnapshots(),this._core.store.state.objects.update(this)}))}rotate(t){this.rotation=t;const e=this.translateX+this.totalWidth/2/this.scale,i=this.translateY+this.totalHeight/2/this.scale,s=t-this.snapshotRotation,n=Math.cos(s),r=Math.sin(s);this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.children.forEach((h=>{const o=this.unchangedChildSnapshots.get(h.id);if(!o)return;const l=this.getOffsetXToCenterFromSnapshot(o),u=this.getOffsetYToCenterFromSnapshot(o),a=r*l+n*u;h.translateX=e+(n*l-r*u)-h.totalWidth/2/h.scale,h.translateY=i+a-h.totalHeight/2/h.scale,h.rotate(1===this.children.length?t:o.rotation+s)}))}))}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,e){return this.children.some((i=>i.hitTest(t,e)))}hitTestPolygon(t){return this.children.some((e=>e.hitTestPolygon(t)))}copy(){const t=Ir.create(this._core),e=[];return this.children.sort(((t,e)=>t.zIndex-e.zIndex)).forEach((i=>{const s=i.copy();e.push(s),t.childIds.push(s.id)})),t._pendingChildren=e,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:e,element:i,totalWidth:s,totalHeight:n,unchangedChildSnapshots:r,...h}=this,o=structuredClone(h);return o.unchangedChildSnapshots=Object.fromEntries(this.unchangedChildSnapshots),o}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((e=>{e.workspaceId=t,e instanceof Ir&&e.updateWorkspaceId(t)}))}}!function(t){t[t.Left=0]="Left",t[t.Middle=1]="Middle",t[t.Right=2]="Right"}(Or||(Or={}));class Ur{static isRightClick(t){return t.button===Or.Right}static isLeftClick(t){return t.button===Or.Left}static isPointerEventOnContextMenu(t){return!!t.composedPath().find((t=>t.classList&&t.classList.contains("context-menu")))}static onLongPress(t,e,i){if("touch"!==t.pointerType)return i?.(),()=>{};const s=t.clientX,n=t.clientY,r=t.target;if(!r)return i?.(),()=>{};const h=setTimeout((()=>{c(),e(t)}),400),o=()=>{clearTimeout(h),c(),i?.()},l=t=>{(Math.abs(t.clientX-s)>10||Math.abs(t.clientY-n)>10)&&o()},u=()=>{o()},a=()=>{o()},c=()=>{r.removeEventListener("pointermove",l),r.removeEventListener("pointerup",u),r.removeEventListener("pointercancel",a)};return r.addEventListener("pointermove",l,{passive:!0}),r.addEventListener("pointerup",u,{once:!0}),r.addEventListener("pointercancel",a,{once:!0}),o}}class jr{__class__=this.constructor.name;name="base-tool";_core;constructor(t){this._core=t}onActivate(){}onDeactivate(){}handlePointerDown(t){}handlePointerMove(t){}handlePointerUp(t){}handleWheel(t){}serialize(){return{__class__:this.__class__,name:this.name}}deserialize(t){return Object.assign(this,t),this}}class Br extends jr{type="pen";color="#000000";size=6;opacity=1;palettes={pen:["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#808080","#C0C0C0","#800000","#008000","#000080","#800080"],highlighter:["#ffff00","#ffb347","#b4ffb4"]};_currentPathId=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&Ur.isLeftClick(t)){this._core.store.state.isDrawing=!0;const e=$r.create(this._core,{points:[[t.clientX-this._core.store.offsetX,t.clientY-this._core.store.offsetY]],translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,fill:this.color,strokeWidth:this.size,opacity:this.opacity});e.isCompleted=!1,this._currentPathId=e.id,this._core.store.state.objects.insert(e)}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){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.isDrawing=!0;const s=$r.create(this._core,{points:[[e,i]],translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,fill:this.color,strokeWidth:this.size,opacity:this.opacity});s.isCompleted=!1,this._currentPathId=s.id,this._core.store.state.objects.insert(s)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&this._currentPathId){const e=this._core.store.state.objects.filter((t=>t.id===this._currentPathId)),i=e.length>0?e[0]:null;if(i){const e=$r.create(this._core,{points:[...i.points,[t.clientX-this._core.store.offsetX,t.clientY-this._core.store.offsetY]],translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,fill:this.color,strokeWidth:this.size,opacity:this.opacity});e.id=i.id,e.workspaceId=i.workspaceId,e.zIndex=i.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&&this._currentPathId){const e=this._core.store.state.objects.filter((t=>t.id===this._currentPathId)),i=e.length>0?e[0]:null;if(i){const e=Math.round(t[0].clientX-this._core.store.offsetX),s=Math.round(t[0].clientY-this._core.store.offsetY),n=$r.create(this._core,{points:[...i.points,[e,s]],translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,fill:this.color,strokeWidth:this.size,opacity:this.opacity});n.id=i.id,n.workspaceId=i.workspaceId,n.zIndex=i.zIndex,n.isCompleted=!1,this._core.store.state.objects.update(n)}}}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentPathId)){const t=this._core.store.state.objects.filter((t=>t.id===this._currentPathId)),e=t.length>0?t[0]:null;e&&(e.isCompleted=!0,this._core.store.state.objects.update(e),this._core.engine.emitObjectsChange()),this._currentPathId=null}if("touch"===t.pointerType&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentPathId)){const t=this._core.store.state.objects.filter((t=>t.id===this._currentPathId)),e=t.length>0?t[0]:null;e&&(e.isCompleted=!0,this._core.store.state.objects.update(e),this._core.engine.emitObjectsChange()),this._currentPathId=null}}}class Nr extends s{__class__="KritzelSelectionGroup";objectIds=[];unchangedObjectSnapshots=new Map;snapshotRotation=0;minX;maxX;minY;maxY;get objects(){return this.objectIds.map((t=>{const e=this._core.store.state.objects.filter((e=>e.id===t));return e.length>0?e[0]:null})).filter((t=>null!==t))}get length(){return this.objectIds.length}static create(t){const e=new Nr;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.scale=t.store.state.scale,e.zIndex=99999,e}addOrRemove(t){const e=this.objectIds.findIndex((e=>e===t.id));-1===e?this.objectIds.push(t.id):this.objectIds.splice(e,1),this.captureUnchangedSnapshots(),this.refreshObjectDimensions()}beginTransform(){this.refreshObjectDimensions(),this.captureUnchangedSnapshots(),this.objects.forEach((t=>{t instanceof Ir&&t.finalize()}))}deselectAllChildren(){this.objects.forEach((t=>t.isSelected=!1))}updateWorkspaceId(t){this.workspaceId=t,this.objects.forEach((e=>e.workspaceId=t))}updateZIndices(t){this.objects.forEach(((e,i)=>{e.zIndex=t+i}))}updatePosition(t,e){this.objects.forEach((i=>{i.updatePosition(t+(i.translateX-this.translateX),e+(i.translateY-this.translateY))})),this.unchangedObjectSnapshots.forEach((i=>{const s=i.translateY-this.translateY;i.translateX=t+(i.translateX-this.translateX),i.translateY=e+s})),this.translateX=t,this.translateY=e,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:e,element:i,totalWidth:s,totalHeight:n,unchangedObjectSnapshots:r,...h}=this,o=structuredClone(h);return i&&"object"==typeof i&&"nodeType"in i&&1===i.nodeType&&(o.element=i.cloneNode(!0)),o.unchangedObjectSnapshots=Object.fromEntries(this.unchangedObjectSnapshots),o}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,e,i,s){const n=(t-i)/this._core.store.state.scale,r=(e-s)/this._core.store.state.scale;this.translateX+=n,this.translateY+=r,this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.objects.forEach((n=>{n.move(t,e,i,s),this._core.anchorManager.updateAnchorsForObject(n.id)}))})),this.unchangedObjectSnapshots.forEach((t=>{t.translateX+=n,t.translateY+=r}))}resize(t,e,i,s){const n=i/this.width,r=s/this.height,h=this.translateX+this.totalWidth/2/this.scale,o=this.translateY+this.totalHeight/2/this.scale,l=t+(i+2*this.padding)/2/this.scale,u=e+(s+2*this.padding)/2/this.scale,a=this.rotation,c=Math.cos(-a),f=Math.sin(-a),d=Math.cos(a),p=Math.sin(a);this._core.store.state.objects.transaction((()=>{this.objects.forEach((t=>{const e=t.translateX+t.totalWidth/2/t.scale-h,i=t.translateY+t.totalHeight/2/t.scale-o,s=(e*c-i*f)*n,w=(e*f+i*c)*r,g=l+(s*d-w*p),m=u+(s*p+w*d),y=t.rotation-a,v=Math.cos(y),b=Math.sin(y),M=Math.sqrt(Math.pow(n*v,2)+Math.pow(r*b,2)),k=Math.sqrt(Math.pow(n*b,2)+Math.pow(r*v,2)),A=t.width*M,x=t.height*k;t.resize(g-(A+2*t.padding)/2/t.scale,m-(x+2*t.padding)/2/t.scale,A,x),this._core.anchorManager.updateAnchorsForObject(t.id)})),this.refreshObjectDimensions(),this.captureUnchangedSnapshots(),this._core.store.state.objects.update(this)}))}rotate(t){this.rotation=t;const e=this.translateX+this.totalWidth/2/this.scale,i=this.translateY+this.totalHeight/2/this.scale,s=t-this.snapshotRotation,n=Math.cos(s),r=Math.sin(s);this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.objects.forEach((h=>{const o=this.unchangedObjectSnapshots.get(h.id);if(!o)return;const l=this.getOffsetXToCenterFromSnapshot(o),u=this.getOffsetYToCenterFromSnapshot(o),a=r*l+n*u;h.translateX=e+(n*l-r*u)-h.totalWidth/2/h.scale,h.translateY=i+a-h.totalHeight/2/h.scale,h.rotate(1===this.objects.length?t:o.rotation+s)}))}))}copy(){const t=Nr.create(this._core);return this.objects.sort(((t,e)=>t.zIndex-e.zIndex)).forEach((e=>{const i=e.copy();t.addOrRemove(i)})),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,e=Math.cos(-t),i=Math.sin(-t);let s=1/0,n=-1/0,r=1/0,h=-1/0;this.objects.forEach((t=>{const o=t.rotatedPolygon;[o.topLeft,o.topRight,o.bottomRight,o.bottomLeft].forEach((t=>{const o=t.x*e-t.y*i,l=t.x*i+t.y*e;o<s&&(s=o),o>n&&(n=o),l<r&&(r=l),l>h&&(h=l)}))}));const o=h-r;this.width=(n-s-this.padding)*this.scale,this.height=(o-this.padding)*this.scale;const l=(s+n)/2,u=(r+h)/2,a=Math.cos(t),c=Math.sin(t),f=l*c+u*a;this.translateX=l*a-u*c-(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,e){if(1===this.objects.length&&"KritzelLine"===this.objects[0].__class__)return this.objects[0].hitTest(t,e);const s=this.rotatedPolygon;return!!i.isPointInPolygon({x:t,y:e},[s.topLeft,s.topRight,s.bottomRight,s.bottomLeft])||this.objects.some((i=>i.hitTest(t,e)))}}class Fr extends jr{color="#000000";size=4;opacity=1;palette=["#000000","#ff5252","#ffbc00","#00c853","#0000FF","#d500f9","#fafafa","#a52714","#ee8100","#558b2f","#01579b","#8e24aa","#90a4ae","#ff4081","#ff6e40","#aeea00","#304ffe","#7c4dff","#cfd8dc","#f8bbd0","#ffccbc","#f0f4c3","#9fa8da","#d1c4e9"];arrows;_startX=0;_startY=0;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&Ur.isLeftClick(t)){this._core.store.state.isDrawing=!0;const e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;this._startX=e,this._startY=i;const s=Rr.create(this._core,{startX:e,startY:i,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,opacity:this.opacity,arrows:this.arrows});s.isCompleted=!1,this._core.store.state.objects.insert(s)}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){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.isDrawing=!0,this._startX=e,this._startY=i;const s=Rr.create(this._core,{startX:e,startY:i,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,opacity:this.opacity,arrows:this.arrows});s.isCompleted=!1,this._core.store.state.objects.insert(s)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing){const e=this._core.store.currentLine;if(e){const i=Rr.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,opacity:this.opacity,arrows:this.arrows});i.id=e.id,i.workspaceId=e.workspaceId,i.zIndex=e.zIndex,i.isCompleted=!1,this._core.store.state.objects.update(i)}}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const e=this._core.store.currentLine;if(e){const i=Math.round(t[0].clientX-this._core.store.offsetX),s=Math.round(t[0].clientY-this._core.store.offsetY),n=Rr.create(this._core,{startX:this._startX,startY:this._startY,endX:i,endY:s,translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});n.id=e.id,n.workspaceId=e.workspaceId,n.zIndex=e.zIndex,n.isCompleted=!1,this._core.store.state.objects.update(n)}}}}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(e){const i=Nr.create(this._core);i.addOrRemove(e),i.isSelected=!0,i.rotation=e.rotation,this._core.addSelectionGroup(i),this._core.store.setState("activeTool",t.getTool("selection")),this._core.rerender()}}class _r extends jr{touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&Ur.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 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()}if("touch"===t.pointerType&&1===this._core.store.state.pointers.size&&this._core.store.state.isErasing){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=this._core.getObjectsFromPointerEvent(t,".object");if(0===i.length)return;const s=this._core.store.state.pointerX,n=this._core.store.state.pointerY;i.forEach((t=>{t.markedForRemoval=t.hitTest(s,n)})),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 Lr(t,e){return new Promise((function(i,s){let n;return zr(t).then((function(t){try{return n=t,i(new Blob([e.slice(0,2),n,e.slice(2)],{type:"image/jpeg"}))}catch(t){return s(t)}}),s)}))}const zr=t=>new Promise(((e,i)=>{const s=new FileReader;s.addEventListener("load",(({target:{result:t}})=>{const s=new DataView(t);let n=0;if(65496!==s.getUint16(n))return i("not a valid JPEG");for(n+=2;;){const r=s.getUint16(n);if(65498===r)break;const h=s.getUint16(n+2);if(65505===r&&1165519206===s.getUint32(n+4)){const r=n+10;let o;switch(s.getUint16(r)){case 18761:o=!0;break;case 19789:o=!1;break;default:return i("TIFF header contains invalid endian")}if(42!==s.getUint16(r+2,o))return i("TIFF header contains invalid version");const l=s.getUint32(r+4,o),u=r+l+2+12*s.getUint16(r+l,o);for(let t=r+l+2;t<u;t+=12)if(274==s.getUint16(t,o)){if(3!==s.getUint16(t+2,o))return i("Orientation data type is invalid");if(1!==s.getUint32(t+4,o))return i("Orientation data count is invalid");s.setUint16(t+8,1,o);break}return e(t.slice(n,n+2+h))}n+=2+h}return e(new Blob)})),s.readAsArrayBuffer(t)}));var Yr={},Wr={get exports(){return Yr},set exports(t){Yr=t}};!function(){var t,e,i={};Wr.exports=i,i.parse=function(t,e){for(var s=i.bin.readUshort,n=i.bin.readUint,r=0,h={},o=new Uint8Array(t),l=o.length-4;101010256!=n(o,l);)l--;r=l,r+=4;var u=s(o,r+=4);s(o,r+=2);var a=n(o,r+=2),c=n(o,r+=4);r+=4,r=c;for(var f=0;f<u;f++){n(o,r),r+=4,r+=4,r+=4,n(o,r+=4),a=n(o,r+=4);var d=n(o,r+=4),p=s(o,r+=4),w=s(o,r+2),g=s(o,r+4);r+=6;var m=n(o,r+=8);r+=4,r+=p+w+g,i._readLocal(o,m,h,a,d,e)}return h},i._readLocal=function(t,e,s,n,r,h){var o=i.bin.readUshort,l=i.bin.readUint;l(t,e),o(t,e+=4),o(t,e+=2);var u=o(t,e+=2);l(t,e+=2),l(t,e+=4),e+=4;var a=o(t,e+=8),c=o(t,e+=2),f=i.bin.readUTF8(t,e+=2,a);if(e+=a,e+=c,h)s[f]={size:r,csize:n};else{var d=new Uint8Array(t.buffer,e);if(0==u)s[f]=new Uint8Array(d.buffer.slice(e,e+n));else{if(8!=u)throw"unknown compression method: "+u;var p=new Uint8Array(r);i.inflateRaw(d,p),s[f]=p}}},i.inflateRaw=function(t,e){return i.F.inflate(t,e)},i.inflate=function(t,e){return i.inflateRaw(new Uint8Array(t.buffer,t.byteOffset+2,t.length-6),e)},i.deflate=function(t,e){null==e&&(e={level:6});var s=0,n=new Uint8Array(50+Math.floor(1.1*t.length));n[s]=120,n[s+1]=156,s=i.F.deflateRaw(t,n,s+=2,e.level);var r=i.adler(t,0,t.length);return n[s+0]=r>>>24&255,n[s+1]=r>>>16&255,n[s+2]=r>>>8&255,n[s+3]=r>>>0&255,new Uint8Array(n.buffer,0,s+4)},i.deflateRaw=function(t,e){null==e&&(e={level:6});var s=new Uint8Array(50+Math.floor(1.1*t.length)),n=i.F.deflateRaw(t,s,n,e.level);return new Uint8Array(s.buffer,0,n)},i.encode=function(t,e){null==e&&(e=!1);var s=0,n=i.bin.writeUint,r=i.bin.writeUshort,h={};for(var o in t){var l=!i._noNeed(o)&&!e,u=t[o],a=i.crc.crc(u,0,u.length);h[o]={cpr:l,usize:u.length,crc:a,file:l?i.deflateRaw(u):u}}for(var o in h)s+=h[o].file.length+30+46+2*i.bin.sizeUTF8(o);s+=22;var c=new Uint8Array(s),f=0,d=[];for(var o in h){var p=h[o];d.push(f),f=i._writeHeader(c,f,o,p,0)}var w=0,g=f;for(var o in h)p=h[o],d.push(f),f=i._writeHeader(c,f,o,p,1,d[w++]);var m=f-g;return n(c,f,101010256),f+=4,r(c,f+=4,w),r(c,f+=2,w),n(c,f+=2,m),n(c,f+=4,g),f+=4,f+=2,c.buffer},i._noNeed=function(t){var e=t.split(".").pop().toLowerCase();return-1!="png,jpg,jpeg,zip".indexOf(e)},i._writeHeader=function(t,e,s,n,r,h){var o=i.bin.writeUint,l=i.bin.writeUshort,u=n.file;return o(t,e,0==r?67324752:33639248),e+=4,1==r&&(e+=2),l(t,e,20),l(t,e+=2,0),l(t,e+=2,n.cpr?8:0),o(t,e+=2,0),o(t,e+=4,n.crc),o(t,e+=4,u.length),o(t,e+=4,n.usize),l(t,e+=4,i.bin.sizeUTF8(s)),l(t,e+=2,0),e+=2,1==r&&(e+=2,e+=2,o(t,e+=6,h),e+=4),e+=i.bin.writeUTF8(t,e,s),0==r&&(t.set(u,e),e+=u.length),e},i.crc={table:function(){for(var t=new Uint32Array(256),e=0;e<256;e++){for(var i=e,s=0;s<8;s++)1&i?i=3988292384^i>>>1:i>>>=1;t[e]=i}return t}(),update:function(t,e,s,n){for(var r=0;r<n;r++)t=i.crc.table[255&(t^e[s+r])]^t>>>8;return t},crc:function(t,e,s){return 4294967295^i.crc.update(4294967295,t,e,s)}},i.adler=function(t,e,i){for(var s=1,n=0,r=e,h=e+i;r<h;){for(var o=Math.min(r+5552,h);r<o;)n+=s+=t[r++];s%=65521,n%=65521}return n<<16|s},i.bin={readUshort:function(t,e){return t[e]|t[e+1]<<8},writeUshort:function(t,e,i){t[e]=255&i,t[e+1]=i>>8&255},readUint:function(t,e){return 16777216*t[e+3]+(t[e+2]<<16|t[e+1]<<8|t[e])},writeUint:function(t,e,i){t[e]=255&i,t[e+1]=i>>8&255,t[e+2]=i>>16&255,t[e+3]=i>>24&255},readASCII:function(t,e,i){for(var s="",n=0;n<i;n++)s+=String.fromCharCode(t[e+n]);return s},writeASCII:function(t,e,i){for(var s=0;s<i.length;s++)t[e+s]=i.charCodeAt(s)},pad:function(t){return t.length<2?"0"+t:t},readUTF8:function(t,e,s){for(var n,r="",h=0;h<s;h++)r+="%"+i.bin.pad(t[e+h].toString(16));try{n=decodeURIComponent(r)}catch(n){return i.bin.readASCII(t,e,s)}return n},writeUTF8:function(t,e,i){for(var s=i.length,n=0,r=0;r<s;r++){var h=i.charCodeAt(r);if(4294967168&h)if(4294965248&h)if(4294901760&h){if(4292870144&h)throw"e";t[e+n]=240|h>>18,t[e+n+1]=128|h>>12&63,t[e+n+2]=128|h>>6&63,t[e+n+3]=128|63&h,n+=4}else t[e+n]=224|h>>12,t[e+n+1]=128|h>>6&63,t[e+n+2]=128|63&h,n+=3;else t[e+n]=192|h>>6,t[e+n+1]=128|63&h,n+=2;else t[e+n]=h,n++}return n},sizeUTF8:function(t){for(var e=t.length,i=0,s=0;s<e;s++){var n=t.charCodeAt(s);if(4294967168&n)if(4294965248&n)if(4294901760&n){if(4292870144&n)throw"e";i+=4}else i+=3;else i+=2;else i++}return i}},i.F={},i.F.deflateRaw=function(t,e,s,n){var r=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]][n],h=i.F.U,o=i.F._goodIndex,l=i.F._putsE,u=0,a=s<<3,c=0,f=t.length;if(0==n){for(;u<f;)l(e,a,u+(x=Math.min(65535,f-u))==f?1:0),a=i.F._copyExact(t,u,x,e,a+8),u+=x;return a>>>3}var d=h.lits,p=h.strt,w=h.prev,g=0,m=0,y=0,v=0,b=0,M=0;for(f>2&&(p[M=i.F._hash(t,0)]=0),u=0;u<f;u++){if(b=M,u+1<f-2){M=i.F._hash(t,u+1);var k=u+1&32767;w[k]=p[M],p[M]=k}if(c<=u){(g>14e3||m>26697)&&f-u>100&&(c<u&&(d[g]=u-c,g+=2,c=u),a=i.F._writeBlock(u==f-1||c==f?1:0,d,g,v,t,y,u-y,e,a),g=m=v=0,y=u);var A=0;u<f-2&&(A=i.F._bestMatch(t,u,w,b,Math.min(r[2],f-u),r[3]));var x=A>>>16,S=65535&A;if(0!=A){S=65535&A;var C=o(x=A>>>16,h.of0);h.lhst[257+C]++;var O=o(S,h.df0);h.dhst[O]++,v+=h.exb[C]+h.dxb[O],d[g]=x<<23|u-c,d[g+1]=S<<16|C<<8|O,g+=2,c=u+x}else h.lhst[t[u]]++;m++}}for(y==u&&0!=t.length||(c<u&&(d[g]=u-c,g+=2,c=u),a=i.F._writeBlock(1,d,g,v,t,y,u-y,e,a),g=0,m=0,g=m=v=0,y=u);7&a;)a++;return a>>>3},i.F._bestMatch=function(t,e,s,n,r,h){var o=32767&e,l=s[o],u=o-l+32768&32767;if(l==o||n!=i.F._hash(t,e-u))return 0;for(var a=0,c=0,f=Math.min(32767,e);u<=f&&0!=--h&&l!=o;){if(0==a||t[e+a]==t[e+a-u]){var d=i.F._howLong(t,e,u);if(d>a){if(c=u,(a=d)>=r)break;u+2<d&&(d=u+2);for(var p=0,w=0;w<d-2;w++){var g=e-u+w+32768&32767,m=g-s[g]+32768&32767;m>p&&(p=m,l=g)}}}u+=(o=l)-(l=s[o])+32768&32767}return a<<16|c},i.F._howLong=function(t,e,i){if(t[e]!=t[e-i]||t[e+1]!=t[e+1-i]||t[e+2]!=t[e+2-i])return 0;var s=e,n=Math.min(t.length,e+258);for(e+=3;e<n&&t[e]==t[e-i];)e++;return e-s},i.F._hash=function(t,e){return(t[e]<<8|t[e+1])+(t[e+2]<<4)&65535},i.saved=0,i.F._writeBlock=function(t,e,s,n,r,h,o,l,u){var a,c,f,d,p,w,g,m,y,v=i.F.U,b=i.F._putsF,M=i.F._putsE;v.lhst[256]++,c=(a=i.F.getTrees())[0],f=a[1],d=a[2],p=a[3],w=a[4],g=a[5],m=a[6],y=a[7];var k=32+(u+3&7?8-(u+3&7):0)+(o<<3),A=n+i.F.contSize(v.fltree,v.lhst)+i.F.contSize(v.fdtree,v.dhst),x=n+i.F.contSize(v.ltree,v.lhst)+i.F.contSize(v.dtree,v.dhst);x+=14+3*g+i.F.contSize(v.itree,v.ihst)+(2*v.ihst[16]+3*v.ihst[17]+7*v.ihst[18]);for(var S=0;S<286;S++)v.lhst[S]=0;for(S=0;S<30;S++)v.dhst[S]=0;for(S=0;S<19;S++)v.ihst[S]=0;var C=k<A&&k<x?0:A<x?1:2;if(b(l,u,t),b(l,u+1,C),u+=3,0==C){for(;7&u;)u++;u=i.F._copyExact(r,h,o,l,u)}else{var O,E;if(1==C&&(O=v.fltree,E=v.fdtree),2==C){i.F.makeCodes(v.ltree,c),i.F.revCodes(v.ltree,c),i.F.makeCodes(v.dtree,f),i.F.revCodes(v.dtree,f),i.F.makeCodes(v.itree,d),i.F.revCodes(v.itree,d),O=v.ltree,E=v.dtree,M(l,u,p-257),M(l,u+=5,w-1),M(l,u+=5,g-4),u+=4;for(var T=0;T<g;T++)M(l,u+3*T,v.itree[1+(v.ordr[T]<<1)]);u=i.F._codeTiny(m,v.itree,l,u+=3*g),u=i.F._codeTiny(y,v.itree,l,u)}for(var D=h,$=0;$<s;$+=2){for(var P=e[$],R=P>>>23,I=D+(8388607&P);D<I;)u=i.F._writeLit(r[D++],O,l,u);if(0!=R){var U=e[$+1],j=U>>16,B=U>>8&255,N=255&U;M(l,u=i.F._writeLit(257+B,O,l,u),R-v.of0[B]),b(l,u=i.F._writeLit(N,E,l,u+=v.exb[B]),j-v.df0[N]),u+=v.dxb[N],D+=R}}u=i.F._writeLit(256,O,l,u)}return u},i.F._copyExact=function(t,e,i,s,n){var r=n>>>3;return s[r]=i,s[r+1]=i>>>8,s[r+2]=255-s[r],s[r+3]=255-s[r+1],r+=4,s.set(new Uint8Array(t.buffer,e,i),r),n+(i+4<<3)},i.F.getTrees=function(){for(var t=i.F.U,e=i.F._hufTree(t.lhst,t.ltree,15),s=i.F._hufTree(t.dhst,t.dtree,15),n=[],r=i.F._lenCodes(t.ltree,n),h=[],o=i.F._lenCodes(t.dtree,h),l=0;l<n.length;l+=2)t.ihst[n[l]]++;for(l=0;l<h.length;l+=2)t.ihst[h[l]]++;for(var u=i.F._hufTree(t.ihst,t.itree,7),a=19;a>4&&0==t.itree[1+(t.ordr[a-1]<<1)];)a--;return[e,s,u,r,o,a,n,h]},i.F.getSecond=function(t){for(var e=[],i=0;i<t.length;i+=2)e.push(t[i+1]);return e},i.F.nonZero=function(t){for(var e="",i=0;i<t.length;i+=2)0!=t[i+1]&&(e+=(i>>1)+",");return e},i.F.contSize=function(t,e){for(var i=0,s=0;s<e.length;s++)i+=e[s]*t[1+(s<<1)];return i},i.F._codeTiny=function(t,e,s,n){for(var r=0;r<t.length;r+=2){var h=t[r],o=t[r+1];n=i.F._writeLit(h,e,s,n);var l=16==h?2:17==h?3:7;h>15&&(i.F._putsE(s,n,o,l),n+=l)}return n},i.F._lenCodes=function(t,e){for(var i=t.length;2!=i&&0==t[i-1];)i-=2;for(var s=0;s<i;s+=2){var n=t[s+1],r=s+3<i?t[s+3]:-1,h=s+5<i?t[s+5]:-1,o=0==s?-1:t[s-1];if(0==n&&r==n&&h==n){for(var l=s+5;l+2<i&&t[l+2]==n;)l+=2;(u=Math.min(l+1-s>>>1,138))<11?e.push(17,u-3):e.push(18,u-11),s+=2*u-2}else if(n==o&&r==n&&h==n){for(l=s+5;l+2<i&&t[l+2]==n;)l+=2;var u=Math.min(l+1-s>>>1,6);e.push(16,u-3),s+=2*u-2}else e.push(n,0)}return i>>>1},i.F._hufTree=function(t,e,s){var n=[],r=t.length,h=e.length,o=0;for(o=0;o<h;o+=2)e[o]=0,e[o+1]=0;for(o=0;o<r;o++)0!=t[o]&&n.push({lit:o,f:t[o]});var l=n.length,u=n.slice(0);if(0==l)return 0;if(1==l){var a=n[0].lit;return u=0==a?1:0,e[1+(a<<1)]=1,e[1+(u<<1)]=1,1}n.sort((function(t,e){return t.f-e.f}));var c=n[0],f=n[1],d=0,p=1,w=2;for(n[0]={lit:-1,f:c.f+f.f,l:c,r:f,d:0};p!=l-1;)c=d!=p&&(w==l||n[d].f<n[w].f)?n[d++]:n[w++],f=d!=p&&(w==l||n[d].f<n[w].f)?n[d++]:n[w++],n[p++]={lit:-1,f:c.f+f.f,l:c,r:f};var g=i.F.setDepth(n[p-1],0);for(g>s&&(i.F.restrictDepth(u,s,g),g=s),o=0;o<l;o++)e[1+(u[o].lit<<1)]=u[o].d;return g},i.F.setDepth=function(t,e){return-1!=t.lit?(t.d=e,e):Math.max(i.F.setDepth(t.l,e+1),i.F.setDepth(t.r,e+1))},i.F.restrictDepth=function(t,e,i){var s=0,n=1<<i-e,r=0;for(t.sort((function(t,e){return e.d==t.d?t.f-e.f:e.d-t.d})),s=0;s<t.length&&t[s].d>e;s++){var h=t[s].d;t[s].d=e,r+=n-(1<<i-h)}for(r>>>=i-e;r>0;)(h=t[s].d)<e?(t[s].d++,r-=1<<e-h-1):s++;for(;s>=0;s--)t[s].d==e&&r<0&&(t[s].d--,r++);0!=r&&console.log("debt left")},i.F._goodIndex=function(t,e){var i=0;return e[16|i]<=t&&(i|=16),e[8|i]<=t&&(i|=8),e[4|i]<=t&&(i|=4),e[2|i]<=t&&(i|=2),e[1|i]<=t&&(i|=1),i},i.F._writeLit=function(t,e,s,n){return i.F._putsF(s,n,e[t<<1]),n+e[1+(t<<1)]},i.F.inflate=function(t,e){var s=Uint8Array;if(3==t[0]&&0==t[1])return e||new s(0);var n=i.F,r=n._bitsF,h=n._bitsE,o=n._decodeTiny,l=n.makeCodes,u=n.codes2map,a=n._get17,c=n.U,f=null==e;f&&(e=new s(t.length>>>2<<3));for(var d,p,w=0,g=0,m=0,y=0,v=0,b=0,M=0,k=0,A=0;0==w;)if(w=r(t,A,1),g=r(t,A+1,2),A+=3,0!=g){if(f&&(e=i.F._check(e,k+(1<<17))),1==g&&(d=c.flmap,p=c.fdmap,b=511,M=31),2==g){m=h(t,A,5)+257,y=h(t,A+5,5)+1,v=h(t,A+10,4)+4,A+=14;for(var x=0;x<38;x+=2)c.itree[x]=0,c.itree[x+1]=0;var S=1;for(x=0;x<v;x++){var C=h(t,A+3*x,3);c.itree[1+(c.ordr[x]<<1)]=C,C>S&&(S=C)}A+=3*v,l(c.itree,S),u(c.itree,S,c.imap),d=c.lmap,p=c.dmap,A=o(c.imap,(1<<S)-1,m+y,t,A,c.ttree);var O=n._copyOut(c.ttree,0,m,c.ltree);b=(1<<O)-1;var E=n._copyOut(c.ttree,m,y,c.dtree);M=(1<<E)-1,l(c.ltree,O),u(c.ltree,O,d),l(c.dtree,E),u(c.dtree,E,p)}for(;;){var T=d[a(t,A)&b];A+=15&T;var D=T>>>4;if(D>>>8==0)e[k++]=D;else{if(256==D)break;var $=k+D-254;if(D>264){var P=c.ldef[D-257];$=k+(P>>>3)+h(t,A,7&P),A+=7&P}var R=p[a(t,A)&M],I=c.ddef[R>>>4],U=(I>>>4)+r(t,A+=15&R,15&I);for(A+=15&I,f&&(e=i.F._check(e,k+(1<<17)));k<$;)e[k]=e[k++-U],e[k]=e[k++-U],e[k]=e[k++-U],e[k]=e[k++-U];k=$}}}else{7&A&&(A+=8-(7&A));var j=4+(A>>>3),B=t[j-4]|t[j-3]<<8;f&&(e=i.F._check(e,k+B)),e.set(new s(t.buffer,t.byteOffset+j,B),k),A=j+B<<3,k+=B}return e.length==k?e:e.slice(0,k)},i.F._check=function(t,e){var i=t.length;if(e<=i)return t;var s=new Uint8Array(Math.max(i<<1,e));return s.set(t,0),s},i.F._decodeTiny=function(t,e,s,n,r,h){for(var o=i.F._bitsE,l=i.F._get17,u=0;u<s;){var a=t[l(n,r)&e];r+=15&a;var c=a>>>4;if(c<=15)h[u]=c,u++;else{var f=0,d=0;16==c?(d=3+o(n,r,2),r+=2,f=h[u-1]):17==c?(d=3+o(n,r,3),r+=3):18==c&&(d=11+o(n,r,7),r+=7);for(var p=u+d;u<p;)h[u]=f,u++}}return r},i.F._copyOut=function(t,e,i,s){for(var n=0,r=0,h=s.length>>>1;r<i;){var o=t[r+e];s[r<<1]=0,s[1+(r<<1)]=o,o>n&&(n=o),r++}for(;r<h;)s[r<<1]=0,s[1+(r<<1)]=0,r++;return n},i.F.makeCodes=function(t,e){for(var s,n,r,h,o=i.F.U,l=t.length,u=o.bl_count,a=0;a<=e;a++)u[a]=0;for(a=1;a<l;a+=2)u[t[a]]++;var c=o.next_code;for(s=0,u[0]=0,n=1;n<=e;n++)c[n]=s=s+u[n-1]<<1;for(r=0;r<l;r+=2)0!=(h=t[r+1])&&(t[r]=c[h],c[h]++)},i.F.codes2map=function(t,e,s){for(var n=t.length,r=i.F.U.rev15,h=0;h<n;h+=2)if(0!=t[h+1])for(var o=t[h+1],l=h>>1<<4|o,u=e-o,a=t[h]<<u,c=a+(1<<u);a!=c;)s[r[a]>>>15-e]=l,a++},i.F.revCodes=function(t,e){for(var s=i.F.U.rev15,n=15-e,r=0;r<t.length;r+=2)t[r]=s[t[r]<<e-t[r+1]]>>>n},i.F._putsE=function(t,e,i){var s=e>>>3;t[s]|=i<<=7&e,t[s+1]|=i>>>8},i.F._putsF=function(t,e,i){var s=e>>>3;t[s]|=i<<=7&e,t[s+1]|=i>>>8,t[s+2]|=i>>>16},i.F._bitsE=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<i)-1},i.F._bitsF=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<i)-1},i.F._get17=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},i.F._get25=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},i.F.U=(t=Uint16Array,e=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 e(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 e(286),dhst:new e(30),ihst:new e(19),lits:new e(15e3),strt:new t(65536),prev:new t(32768)}),function(){for(var t=i.F.U,e=0;e<32768;e++){var s=e;s=(4278255360&(s=(4042322160&(s=(3435973836&(s=(2863311530&s)>>>1|(1431655765&s)<<1))>>>2|(858993459&s)<<2))>>>4|(252645135&s)<<4))>>>8|(16711935&s)<<8,t.rev15[e]=(s>>>16|s<<16)>>>17}function n(t,e,i){for(;0!=e--;)t.push(0,i)}for(e=0;e<32;e++)t.ldef[e]=t.of0[e]<<3|t.exb[e],t.ddef[e]=t.df0[e]<<4|t.dxb[e];n(t.fltree,144,8),n(t.fltree,112,9),n(t.fltree,24,7),n(t.fltree,8,8),i.F.makeCodes(t.fltree,9),i.F.codes2map(t.fltree,9,t.flmap),i.F.revCodes(t.fltree,9),n(t.fdtree,32,5),i.F.makeCodes(t.fdtree,5),i.F.codes2map(t.fdtree,5,t.fdmap),i.F.revCodes(t.fdtree,5),n(t.itree,19,0),n(t.ltree,286,0),n(t.dtree,30,0),n(t.ttree,320,0)}()}();var Xr=function(t,e){return e.forEach((function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach((function(i){if("default"!==i&&!(i in t)){var s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return e[i]}})}}))})),Object.freeze(t)}({__proto__:null,default:Yr},[Yr]);const Jr=function(){var t={nextZero(t,e){for(;0!=t[e];)e++;return e},readUshort:(t,e)=>t[e]<<8|t[e+1],writeUshort(t,e,i){t[e]=i>>8&255,t[e+1]=255&i},readUint:(t,e)=>16777216*t[e]+(t[e+1]<<16|t[e+2]<<8|t[e+3]),writeUint(t,e,i){t[e]=i>>24&255,t[e+1]=i>>16&255,t[e+2]=i>>8&255,t[e+3]=255&i},readASCII(t,e,i){let s="";for(let n=0;n<i;n++)s+=String.fromCharCode(t[e+n]);return s},writeASCII(t,e,i){for(let s=0;s<i.length;s++)t[e+s]=i.charCodeAt(s)},readBytes(t,e,i){const s=[];for(let n=0;n<i;n++)s.push(t[e+n]);return s},pad:t=>t.length<2?`0${t}`:t,readUTF8(e,i,s){let n,r="";for(let n=0;n<s;n++)r+=`%${t.pad(e[i+n].toString(16))}`;try{n=decodeURIComponent(r)}catch(n){return t.readASCII(e,i,s)}return n}};function e(e,i,s,n){const h=i*s,o=r(n),l=Math.ceil(i*o/8),u=new Uint8Array(4*h),a=new Uint32Array(u.buffer),{ctype:c}=n,{depth:f}=n,d=t.readUshort;if(6==c){const t=h<<2;if(8==f)for(var p=0;p<t;p+=4)u[p]=e[p],u[p+1]=e[p+1],u[p+2]=e[p+2],u[p+3]=e[p+3];if(16==f)for(p=0;p<t;p++)u[p]=e[p<<1]}else if(2==c){const t=n.tabs.tRNS;if(null==t){if(8==f)for(p=0;p<h;p++){var w=3*p;a[p]=255<<24|e[w+2]<<16|e[w+1]<<8|e[w]}if(16==f)for(p=0;p<h;p++)a[p]=255<<24|e[4+(w=6*p)]<<16|e[w+2]<<8|e[w]}else{var g=t[0];const i=t[1],s=t[2];if(8==f)for(p=0;p<h;p++){var m=p<<2;a[p]=255<<24|e[2+(w=3*p)]<<16|e[w+1]<<8|e[w],e[w]==g&&e[w+1]==i&&e[w+2]==s&&(u[m+3]=0)}if(16==f)for(p=0;p<h;p++)m=p<<2,a[p]=255<<24|e[4+(w=6*p)]<<16|e[w+2]<<8|e[w],d(e,w)==g&&d(e,w+2)==i&&d(e,w+4)==s&&(u[m+3]=0)}}else if(3==c){const t=n.tabs.PLTE,r=n.tabs.tRNS,o=r?r.length:0;if(1==f)for(var y=0;y<s;y++){var v=y*l,b=y*i;for(p=0;p<i;p++){var M=3*(k=e[v+(p>>3)]>>7-(7&p)&1);u[m=b+p<<2]=t[M],u[m+1]=t[M+1],u[m+2]=t[M+2],u[m+3]=k<o?r[k]:255}}if(2==f)for(y=0;y<s;y++)for(v=y*l,b=y*i,p=0;p<i;p++)M=3*(k=e[v+(p>>2)]>>6-((3&p)<<1)&3),u[m=b+p<<2]=t[M],u[m+1]=t[M+1],u[m+2]=t[M+2],u[m+3]=k<o?r[k]:255;if(4==f)for(y=0;y<s;y++)for(v=y*l,b=y*i,p=0;p<i;p++)M=3*(k=e[v+(p>>1)]>>4-((1&p)<<2)&15),u[m=b+p<<2]=t[M],u[m+1]=t[M+1],u[m+2]=t[M+2],u[m+3]=k<o?r[k]:255;if(8==f)for(p=0;p<h;p++){var k;M=3*(k=e[p]),u[m=p<<2]=t[M],u[m+1]=t[M+1],u[m+2]=t[M+2],u[m+3]=k<o?r[k]:255}}else if(4==c){if(8==f)for(p=0;p<h;p++){var A=e[x=p<<1];u[m=p<<2]=A,u[m+1]=A,u[m+2]=A,u[m+3]=e[x+1]}if(16==f)for(p=0;p<h;p++){var x;A=e[x=p<<2],u[m=p<<2]=A,u[m+1]=A,u[m+2]=A,u[m+3]=e[x+2]}}else if(0==c)for(g=n.tabs.tRNS?n.tabs.tRNS:-1,y=0;y<s;y++){const t=y*l,s=y*i;if(1==f)for(var S=0;S<i;S++){var C=(A=255*(e[t+(S>>>3)]>>>7-(7&S)&1))==255*g?0:255;a[s+S]=C<<24|A<<16|A<<8|A}else if(2==f)for(S=0;S<i;S++)C=(A=85*(e[t+(S>>>2)]>>>6-((3&S)<<1)&3))==85*g?0:255,a[s+S]=C<<24|A<<16|A<<8|A;else if(4==f)for(S=0;S<i;S++)C=(A=17*(e[t+(S>>>1)]>>>4-((1&S)<<2)&15))==17*g?0:255,a[s+S]=C<<24|A<<16|A<<8|A;else if(8==f)for(S=0;S<i;S++)C=(A=e[t+S])==g?0:255,a[s+S]=C<<24|A<<16|A<<8|A;else if(16==f)for(S=0;S<i;S++)A=e[t+(S<<1)],C=d(e,t+(S<<1))==g?0:255,a[s+S]=C<<24|A<<16|A<<8|A}return u}function i(t,e,i,o){const l=r(t),u=Math.ceil(i*l/8),a=new Uint8Array((u+1+t.interlace)*o);return e=t.tabs.CgBI?n(e,a):s(e,a),0==t.interlace?e=h(e,t,0,i,o):1==t.interlace&&(e=function(t,e){const i=e.width,s=e.height,n=r(e),o=n>>3,l=Math.ceil(i*n/8),u=new Uint8Array(s*l);let a=0;const c=[0,0,4,0,2,0,1],f=[0,4,0,2,0,1,0],d=[8,8,8,4,4,2,2],p=[8,8,4,4,2,2,1];let w=0;for(;w<7;){const r=d[w],m=p[w];let y=0,v=0,b=c[w];for(;b<s;)b+=r,v++;let M=f[w];for(;M<i;)M+=m,y++;const k=Math.ceil(y*n/8);h(t,e,a,y,v);let A=0,x=c[w];for(;x<s;){let e=f[w],s=a+A*k<<3;for(;e<i;){var g;if(1==n&&(g=(g=t[s>>3])>>7-(7&s)&1,u[x*l+(e>>3)]|=g<<7-(7&e)),2==n&&(g=(g=t[s>>3])>>6-(7&s)&3,u[x*l+(e>>2)]|=g<<6-((3&e)<<1)),4==n&&(g=(g=t[s>>3])>>4-(7&s)&15,u[x*l+(e>>1)]|=g<<4-((1&e)<<2)),n>=8){const i=x*l+e*o;for(let e=0;e<o;e++)u[i+e]=t[(s>>3)+e]}s+=n,e+=m}A++,x+=r}y*v!=0&&(a+=v*(1+k)),w+=1}return u}(e,t)),e}function s(t,e){return n(new Uint8Array(t.buffer,2,t.length-6),e)}var n=function(){const t={H:{}};return t.H.N=function(e,i){const s=Uint8Array;let n,r,h=0,o=0,l=0,u=0,a=0,c=0,f=0,d=0,p=0;if(3==e[0]&&0==e[1])return i||new s(0);const w=t.H,g=w.b,m=w.e,y=w.R,v=w.n,b=w.A,M=w.Z,k=w.m,A=null==i;for(A&&(i=new s(e.length>>>2<<5));0==h;)if(h=g(e,p,1),o=g(e,p+1,2),p+=3,0!=o){if(A&&(i=t.H.W(i,d+(1<<17))),1==o&&(n=k.J,r=k.h,c=511,f=31),2==o){l=m(e,p,5)+257,u=m(e,p+5,5)+1,a=m(e,p+10,4)+4,p+=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 i=m(e,p+3*x,3);k.Q[1+(k.X[x]<<1)]=i,i>t&&(t=i)}p+=3*a,v(k.Q,t),b(k.Q,t,k.u),n=k.w,r=k.d,p=y(k.u,(1<<t)-1,l+u,e,p,k.v);const i=w.V(k.v,0,l,k.C);c=(1<<i)-1;const s=w.V(k.v,l,u,k.D);f=(1<<s)-1,v(k.C,i),b(k.C,i,n),v(k.D,s),b(k.D,s,r)}for(;;){const t=n[M(e,p)&c];p+=15&t;const s=t>>>4;if(s>>>8==0)i[d++]=s;else{if(256==s)break;{let t=d+s-254;if(s>264){const i=k.q[s-257];t=d+(i>>>3)+m(e,p,7&i),p+=7&i}const n=r[M(e,p)&f];p+=15&n;const h=k.c[n>>>4],o=(h>>>4)+g(e,p,15&h);for(p+=15&h;d<t;)i[d]=i[d++-o],i[d]=i[d++-o],i[d]=i[d++-o],i[d]=i[d++-o];d=t}}}}else{7&p&&(p+=8-(7&p));const n=4+(p>>>3),r=e[n-4]|e[n-3]<<8;A&&(i=t.H.W(i,d+r)),i.set(new s(e.buffer,e.byteOffset+n,r),d),p=n+r<<3,d+=r}return i.length==d?i:i.slice(0,d)},t.H.W=function(t,e){const i=t.length;if(e<=i)return t;const s=new Uint8Array(i<<1);return s.set(t,0),s},t.H.R=function(e,i,s,n,r,h){const o=t.H.e,l=t.H.Z;let u=0;for(;u<s;){const t=e[l(n,r)&i];r+=15&t;const s=t>>>4;if(s<=15)h[u]=s,u++;else{let t=0,e=0;16==s?(e=3+o(n,r,2),r+=2,t=h[u-1]):17==s?(e=3+o(n,r,3),r+=3):18==s&&(e=11+o(n,r,7),r+=7);const i=u+e;for(;u<i;)h[u]=t,u++}}return r},t.H.V=function(t,e,i,s){let n=0,r=0;const h=s.length>>>1;for(;r<i;){const i=t[r+e];s[r<<1]=0,s[1+(r<<1)]=i,i>n&&(n=i),r++}for(;r<h;)s[r<<1]=0,s[1+(r<<1)]=0,r++;return n},t.H.n=function(e,i){const s=t.H.m,n=e.length;let r,h,o,l;const u=s.j;for(var a=0;a<=i;a++)u[a]=0;for(a=1;a<n;a+=2)u[e[a]]++;const c=s.K;for(r=0,u[0]=0,h=1;h<=i;h++)r=r+u[h-1]<<1,c[h]=r;for(o=0;o<n;o+=2)l=e[o+1],0!=l&&(e[o]=c[l],c[l]++)},t.H.A=function(e,i,s){const n=e.length,r=t.H.m.r;for(let t=0;t<n;t+=2)if(0!=e[t+1]){const n=e[t+1],h=t>>1<<4|n,o=i-n;let l=e[t]<<o;const u=l+(1<<o);for(;l!=u;)s[r[l]>>>15-i]=h,l++}},t.H.l=function(e,i){const s=t.H.m.r,n=15-i;for(let t=0;t<e.length;t+=2)e[t]=s[e[t]<<i-e[t+1]]>>>n},t.H.M=function(t,e,i){const s=e>>>3;t[s]|=i<<=7&e,t[s+1]|=i>>>8},t.H.I=function(t,e,i){const s=e>>>3;t[s]|=i<<=7&e,t[s+1]|=i>>>8,t[s+2]|=i>>>16},t.H.e=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<i)-1},t.H.b=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<i)-1},t.H.Z=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},t.H.i=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},t.H.m=function(){const t=Uint16Array,e=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 e(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 e(286),Y:new e(30),a:new e(19),t:new e(15e3),k:new t(65536),g:new t(32768)}}(),function(){const e=t.H.m;for(var i=0;i<32768;i++){let t=i;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,e.r[i]=(t>>>16|t<<16)>>>17}function s(t,e,i){for(;0!=e--;)t.push(0,i)}for(i=0;i<32;i++)e.q[i]=e.S[i]<<3|e.T[i],e.c[i]=e.p[i]<<4|e.z[i];s(e._,144,8),s(e._,112,9),s(e._,24,7),s(e._,8,8),t.H.n(e._,9),t.H.A(e._,9,e.J),t.H.l(e._,9),s(e.$,32,5),t.H.n(e.$,5),t.H.A(e.$,5,e.h),t.H.l(e.$,5),s(e.Q,19,0),s(e.C,286,0),s(e.D,30,0),s(e.v,320,0)}(),t.H.N}();function r(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function h(t,e,i,s,n){let h=r(e);const l=Math.ceil(s*h/8);let u,a;h=Math.ceil(h/8);let c=t[i],f=0;if(c>1&&(t[i]=[0,0,1][c-2]),3==c)for(f=h;f<l;f++)t[f+1]=t[f+1]+(t[f+1-h]>>>1)&255;for(let e=0;e<n;e++)if(u=i+e*l,a=u+e+1,c=t[a-1],f=0,0==c)for(;f<l;f++)t[u+f]=t[a+f];else if(1==c){for(;f<h;f++)t[u+f]=t[a+f];for(;f<l;f++)t[u+f]=t[a+f]+t[u+f-h]}else if(2==c)for(;f<l;f++)t[u+f]=t[a+f]+t[u+f-l];else if(3==c){for(;f<h;f++)t[u+f]=t[a+f]+(t[u+f-l]>>>1);for(;f<l;f++)t[u+f]=t[a+f]+(t[u+f-l]+t[u+f-h]>>>1)}else{for(;f<h;f++)t[u+f]=t[a+f]+o(0,t[u+f-l],0);for(;f<l;f++)t[u+f]=t[a+f]+o(t[u+f-h],t[u+f-l],t[u+f-h-l])}return t}function o(t,e,i){const s=t+e-i,n=s-t,r=s-e,h=s-i;return n*n<=r*r&&n*n<=h*h?t:r*r<=h*h?e:i}function l(e,i,s){s.width=t.readUint(e,i),s.height=t.readUint(e,i+=4),s.depth=e[i+=4],i++,s.ctype=e[i],i++,s.compress=e[i],i++,s.filter=e[i],i++,s.interlace=e[i],i++}function u(t,e,i,s,n,r,h,o,l){const u=Math.min(e,n),a=Math.min(i,r);let c=0,f=0;for(let i=0;i<a;i++)for(let r=0;r<u;r++)if(h>=0&&o>=0?(c=i*e+r<<2,f=(o+i)*n+h+r<<2):(c=(-o+i)*e-h+r<<2,f=i*n+r<<2),0==l)s[f]=t[c],s[f+1]=t[c+1],s[f+2]=t[c+2],s[f+3]=t[c+3];else if(1==l){var d=t[c+3]*(1/255),p=t[c]*d,w=t[c+1]*d,g=t[c+2]*d,m=s[f+3]*(1/255),y=s[f]*m,v=s[f+1]*m,b=s[f+2]*m;const e=1-d,i=d+m*e,n=0==i?0:1/i;s[f+3]=255*i,s[f+0]=(p+y*e)*n,s[f+1]=(w+v*e)*n,s[f+2]=(g+b*e)*n}else if(2==l)p=t[c],w=t[c+1],g=t[c+2],y=s[f],v=s[f+1],b=s[f+2],(d=t[c+3])==(m=s[f+3])&&p==y&&w==v&&g==b?(s[f]=0,s[f+1]=0,s[f+2]=0,s[f+3]=0):(s[f]=p,s[f+1]=w,s[f+2]=g,s[f+3]=d);else if(3==l){if(p=t[c],w=t[c+1],g=t[c+2],y=s[f],v=s[f+1],b=s[f+2],(d=t[c+3])==(m=s[f+3])&&p==y&&w==v&&g==b)continue;if(d<220&&m>20)return!1}return!0}return{decode:function(e){const r=new Uint8Array(e);let h=8;const o=t,u=o.readUshort,a=o.readUint,c={tabs:{},frames:[]},f=new Uint8Array(r.length);let d,p=0,w=0;const g=[137,80,78,71,13,10,26,10];for(var m=0;m<8;m++)if(r[m]!=g[m])throw"The input is not a PNG file!";for(;h<r.length;){const t=o.readUint(r,h);h+=4;const e=o.readASCII(r,h,4);if(h+=4,"IHDR"==e)l(r,h,c);else if("iCCP"==e){for(var y=h;0!=r[y];)y++;o.readASCII(r,h,y-h);const i=r.slice(y+2,h+t);let l=null;try{l=s(i)}catch(t){l=n(i)}c.tabs[e]=l}else if("CgBI"==e)c.tabs[e]=r.slice(h,h+4);else if("IDAT"==e){for(m=0;m<t;m++)f[p+m]=r[h+m];p+=t}else if("acTL"==e)c.tabs[e]={num_frames:a(r,h),num_plays:a(r,h+4)},d=new Uint8Array(r.length);else if("fcTL"==e){0!=w&&((x=c.frames[c.frames.length-1]).data=i(c,d.slice(0,w),x.rect.width,x.rect.height),w=0);const t={x:a(r,h+12),y:a(r,h+16),width:a(r,h+4),height:a(r,h+8)};let e=u(r,h+22);e=u(r,h+20)/(0==e?100:e);const s={rect:t,delay:Math.round(1e3*e),dispose:r[h+24],blend:r[h+25]};c.frames.push(s)}else if("fdAT"==e){for(m=0;m<t-4;m++)d[w+m]=r[h+m+4];w+=t-4}else if("pHYs"==e)c.tabs[e]=[o.readUint(r,h),o.readUint(r,h+4),r[h+8]];else if("cHRM"==e)for(c.tabs[e]=[],m=0;m<8;m++)c.tabs[e].push(o.readUint(r,h+4*m));else if("tEXt"==e||"zTXt"==e){null==c.tabs[e]&&(c.tabs[e]={});var v=o.nextZero(r,h),b=o.readASCII(r,h,v-h),M=h+t-v-1;if("tEXt"==e)A=o.readASCII(r,v+1,M);else{var k=s(r.slice(v+2,v+2+M));A=o.readUTF8(k,0,k.length)}c.tabs[e][b]=A}else if("iTXt"==e){null==c.tabs[e]&&(c.tabs[e]={}),v=0,v=o.nextZero(r,y=h),b=o.readASCII(r,y,v-y);const i=r[y=v+1];var A;v=o.nextZero(r,y+=2),o.readASCII(r,y,v-y),v=o.nextZero(r,y=v+1),o.readUTF8(r,y,v-y),M=t-((y=v+1)-h),0==i?A=o.readUTF8(r,y,M):(k=s(r.slice(y,y+M)),A=o.readUTF8(k,0,k.length)),c.tabs[e][b]=A}else if("PLTE"==e)c.tabs[e]=o.readBytes(r,h,t);else if("hIST"==e){const t=c.tabs.PLTE.length/3;for(c.tabs[e]=[],m=0;m<t;m++)c.tabs[e].push(u(r,h+2*m))}else if("tRNS"==e)3==c.ctype?c.tabs[e]=o.readBytes(r,h,t):0==c.ctype?c.tabs[e]=u(r,h):2==c.ctype&&(c.tabs[e]=[u(r,h),u(r,h+2),u(r,h+4)]);else if("gAMA"==e)c.tabs[e]=o.readUint(r,h)/1e5;else if("sRGB"==e)c.tabs[e]=r[h];else if("bKGD"==e)0==c.ctype||4==c.ctype?c.tabs[e]=[u(r,h)]:2==c.ctype||6==c.ctype?c.tabs[e]=[u(r,h),u(r,h+2),u(r,h+4)]:3==c.ctype&&(c.tabs[e]=r[h]);else if("IEND"==e)break;h+=t,o.readUint(r,h),h+=4}var x;return 0!=w&&((x=c.frames[c.frames.length-1]).data=i(c,d.slice(0,w),x.rect.width,x.rect.height)),c.data=i(c,f,c.width,c.height),delete c.compress,delete c.interlace,delete c.filter,c},toRGBA8:function(t){const i=t.width,s=t.height;if(null==t.tabs.acTL)return[e(t.data,i,s,t).buffer];const n=[];null==t.frames[0].data&&(t.frames[0].data=t.data);const r=i*s*4,h=new Uint8Array(r),o=new Uint8Array(r),l=new Uint8Array(r);for(let c=0;c<t.frames.length;c++){const f=t.frames[c],d=f.rect.x,p=f.rect.y,w=f.rect.width,g=f.rect.height,m=e(f.data,w,g,t);if(0!=c)for(var a=0;a<r;a++)l[a]=h[a];if(0==f.blend?u(m,w,g,h,i,s,d,p,0):1==f.blend&&u(m,w,g,h,i,s,d,p,1),n.push(h.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)u(o,w,g,h,i,s,d,p,0);else if(2==f.dispose)for(a=0;a<r;a++)h[a]=l[a]}return n},_paeth:o,_copyTile:u,_bin:t}}();!function(){const{_copyTile:t}=Jr,{_bin:e}=Jr,i=Jr._paeth;var s={table:function(){const t=new Uint32Array(256);for(let e=0;e<256;e++){let i=e;for(let t=0;t<8;t++)1&i?i=3988292384^i>>>1:i>>>=1;t[e]=i}return t}(),update(t,e,i,n){for(let r=0;r<n;r++)t=s.table[255&(t^e[i+r])]^t>>>8;return t},crc:(t,e,i)=>4294967295^s.update(4294967295,t,e,i)};function n(t,e,i,s){e[i]+=t[0]*s>>4,e[i+1]+=t[1]*s>>4,e[i+2]+=t[2]*s>>4,e[i+3]+=t[3]*s>>4}function r(t){return Math.max(0,Math.min(255,t))}function h(t,e){const i=t[0]-e[0],s=t[1]-e[1],n=t[2]-e[2],r=t[3]-e[3];return i*i+s*s+n*n+r*r}function o(t,e,i,s,o,l,u){null==u&&(u=1);const a=s.length,c=[];for(var f=0;f<a;f++){const t=s[f];c.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,p=0;p<a;p++){var w=h(c[f],c[p]);p!=f&&w<t&&(t=w,d=p)}}const g=new Uint32Array(o.buffer),m=new Int16Array(e*i*4),y=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(f=0;f<y.length;f++)y[f]=255*((y[f]+.5)/16-.5);for(let o=0;o<i;o++)for(let b=0;b<e;b++){var v;f=4*(o*e+b),v=2!=u?[r(t[f]+m[f]),r(t[f+1]+m[f+1]),r(t[f+2]+m[f+2]),r(t[f+3]+m[f+3])]:[r(t[f]+(w=y[4*(3&o)+(3&b)])),r(t[f+1]+w),r(t[f+2]+w),r(t[f+3]+w)],d=0;let M=16777215;for(p=0;p<a;p++){const t=h(v,c[p]);t<M&&(M=t,d=p)}const k=c[d],A=[v[0]-k[0],v[1]-k[1],v[2]-k[2],v[3]-k[3]];1==u&&(b!=e-1&&n(A,m,f+4,7),o!=i-1&&(0!=b&&n(A,m,f+4*e-4,3),n(A,m,f+4*e,5),b!=e-1&&n(A,m,f+4*e+4,1))),l[f>>2]=d,g[f>>2]=s[d]}}function l(t,i,n,r,h){null==h&&(h={});const{crc:o}=s,l=e.writeUint,u=e.writeUshort,a=e.writeASCII;let c=8;const f=t.frames.length>1;let d,p=!1,w=33+(f?20:0);if(null!=h.sRGB&&(w+=13),null!=h.pHYs&&(w+=21),null!=h.iCCP&&(d=pako.deflate(h.iCCP),w+=21+d.length+4),3==t.ctype){for(var g=t.plte.length,m=0;m<g;m++)t.plte[m]>>>24!=255&&(p=!0);w+=8+3*g+4+(p?8+1*g+4:0)}for(var y=0;y<t.frames.length;y++)f&&(w+=38),w+=(k=t.frames[y]).cimg.length+12,0!=y&&(w+=4);w+=12;const v=new Uint8Array(w),b=[137,80,78,71,13,10,26,10];for(m=0;m<8;m++)v[m]=b[m];if(l(v,c,13),c+=4,a(v,c,"IHDR"),c+=4,l(v,c,i),c+=4,l(v,c,n),c+=4,v[c]=t.depth,c++,v[c]=t.ctype,c++,v[c]=0,c++,v[c]=0,c++,v[c]=0,c++,l(v,c,o(v,c-17,17)),c+=4,null!=h.sRGB&&(l(v,c,1),c+=4,a(v,c,"sRGB"),c+=4,v[c]=h.sRGB,c++,l(v,c,o(v,c-5,5)),c+=4),null!=h.iCCP){const t=13+d.length;l(v,c,t),c+=4,a(v,c,"iCCP"),c+=4,a(v,c,"ICC profile"),c+=11,c+=2,v.set(d,c),c+=d.length,l(v,c,o(v,c-(t+4),t+4)),c+=4}if(null!=h.pHYs&&(l(v,c,9),c+=4,a(v,c,"pHYs"),c+=4,l(v,c,h.pHYs[0]),c+=4,l(v,c,h.pHYs[1]),c+=4,v[c]=h.pHYs[2],c++,l(v,c,o(v,c-13,13)),c+=4),f&&(l(v,c,8),c+=4,a(v,c,"acTL"),c+=4,l(v,c,t.frames.length),c+=4,l(v,c,null!=h.loop?h.loop:0),c+=4,l(v,c,o(v,c-12,12)),c+=4),3==t.ctype){for(l(v,c,3*(g=t.plte.length)),c+=4,a(v,c,"PLTE"),c+=4,m=0;m<g;m++){const e=3*m,i=t.plte[m],s=i>>>8&255,n=i>>>16&255;v[c+e+0]=255&i,v[c+e+1]=s,v[c+e+2]=n}if(c+=3*g,l(v,c,o(v,c-3*g-4,3*g+4)),c+=4,p){for(l(v,c,g),c+=4,a(v,c,"tRNS"),c+=4,m=0;m<g;m++)v[c+m]=t.plte[m]>>>24&255;c+=g,l(v,c,o(v,c-g-4,g+4)),c+=4}}let M=0;for(y=0;y<t.frames.length;y++){var k=t.frames[y];f&&(l(v,c,26),c+=4,a(v,c,"fcTL"),c+=4,l(v,c,M++),c+=4,l(v,c,k.rect.width),c+=4,l(v,c,k.rect.height),c+=4,l(v,c,k.rect.x),c+=4,l(v,c,k.rect.y),c+=4,u(v,c,r[y]),c+=2,u(v,c,1e3),c+=2,v[c]=k.dispose,c++,v[c]=k.blend,c++,l(v,c,o(v,c-30,30)),c+=4);const e=k.cimg;l(v,c,(g=e.length)+(0==y?0:4)),c+=4;const i=c;a(v,c,0==y?"IDAT":"fdAT"),c+=4,0!=y&&(l(v,c,M++),c+=4),v.set(e,c),c+=g,l(v,c,o(v,i,c-i)),c+=4}return l(v,c,0),c+=4,a(v,c,"IEND"),c+=4,l(v,c,o(v,c-4,4)),c+=4,v.buffer}function u(t,e,i){for(let s=0;s<t.frames.length;s++){const n=t.frames[s],r=n.rect.height,h=new Uint8Array(r*n.bpl+r);n.cimg=d(n.img,r,n.bpp,n.bpl,h,e,i)}}function a(e,i,s,n,r){const h=r[0],l=r[1],u=r[2],a=r[3],d=r[4],p=r[5];let g=6,m=8,y=255;for(var v=0;v<e.length;v++){const t=new Uint8Array(e[v]);for(var b=t.length,M=0;M<b;M+=4)y&=t[M+3]}const k=255!=y,A=function(e,i,s,n,r,h){const o=[];for(var l=0;l<e.length;l++){const c=new Uint8Array(e[l]),d=new Uint32Array(c.buffer);var u;let w=0,g=0,m=i,y=s,v=n?1:0;if(0!=l){const b=h||n||1==l||0!=o[l-2].dispose?1:2;let M=0,k=1e9;for(let t=0;t<b;t++){var a=new Uint8Array(e[l-1-t]);const n=new Uint32Array(e[l-1-t]);let h=i,o=s,u=-1,c=-1;for(let t=0;t<s;t++)for(let e=0;e<i;e++)d[p=t*i+e]!=n[p]&&(e<h&&(h=e),e>u&&(u=e),t<o&&(o=t),t>c&&(c=t));-1==u&&(h=o=u=c=0),r&&(!(1&~h)&&h--,!(1&~o)&&o--);const f=(u-h+1)*(c-o+1);f<k&&(k=f,M=t,w=h,g=o,m=u-h+1,y=c-o+1)}a=new Uint8Array(e[l-1-M]),1==M&&(o[l-1].dispose=2),u=new Uint8Array(m*y*4),t(a,i,s,u,m,y,-w,-g,0),v=t(c,i,s,u,m,y,-w,-g,3)?1:0,1==v?f(c,i,s,u,{x:w,y:g,width:m,height:y}):t(c,i,s,u,m,y,-w,-g,0)}else u=c.slice(0);o.push({rect:{x:w,y:g,width:m,height:y},img:u,blend:v,dispose:0})}if(n)for(l=0;l<o.length;l++){if(1==(w=o[l]).blend)continue;const t=w.rect,n=o[l-1].rect,h=Math.min(t.x,n.x),u=Math.min(t.y,n.y),a={x:h,y:u,width:Math.max(t.x+t.width,n.x+n.width)-h,height:Math.max(t.y+t.height,n.y+n.height)-u};o[l-1].dispose=1,l-1!=0&&c(e,i,s,o,l-1,a,r),c(e,i,s,o,l,a,r)}let d=0;if(1!=e.length)for(var p=0;p<o.length;p++){var w;d+=(w=o[p]).rect.width*w.rect.height}return o}(e,i,s,h,l,u),x={},S=[],C=[];if(0!=n){const t=[];for(M=0;M<A.length;M++)t.push(A[M].img.buffer);const e=function(t){let e=0;for(var i=0;i<t.length;i++)e+=t[i].byteLength;const s=new Uint8Array(e);let n=0;for(i=0;i<t.length;i++){const e=new Uint8Array(t[i]),r=e.length;for(let t=0;t<r;t+=4){let i=e[t],r=e[t+1],h=e[t+2];const o=e[t+3];0==o&&(i=r=h=0),s[n+t]=i,s[n+t+1]=r,s[n+t+2]=h,s[n+t+3]=o}n+=r}return s.buffer}(t),i=w(e,n);for(M=0;M<i.plte.length;M++)S.push(i.plte[M].est.rgba);let s=0;for(M=0;M<A.length;M++){const t=(E=A[M]).img.length;var O=new Uint8Array(i.inds.buffer,s>>2,t>>2);C.push(O);const e=new Uint8Array(i.abuf,s,t);p&&o(E.img,E.rect.width,E.rect.height,S,e,O),E.img.set(e),s+=t}}else for(v=0;v<A.length;v++){var E=A[v];const t=new Uint32Array(E.img.buffer);var T=E.rect.width;for(b=t.length,O=new Uint8Array(b),C.push(O),M=0;M<b;M++){const e=t[M];if(0!=M&&e==t[M-1])O[M]=O[M-1];else if(M>T&&e==t[M-T])O[M]=O[M-T];else{let t=x[e];if(null==t&&(x[e]=t=S.length,S.push(e),S.length>=300))break;O[M]=t}}}const D=S.length;for(D<=256&&0==d&&(m=D<=2?1:D<=4?2:D<=16?4:8,m=Math.max(m,a)),v=0;v<A.length;v++){const t=(E=A[v]).rect.height;let e=E.img,i=4*(T=E.rect.width),s=4;if(D<=256&&0==d){i=Math.ceil(m*T/8);var $=new Uint8Array(i*t);const n=C[v];for(let e=0;e<t;e++){M=e*i;const t=e*T;if(8==m)for(var P=0;P<T;P++)$[M+P]=n[t+P];else if(4==m)for(P=0;P<T;P++)$[M+(P>>1)]|=n[t+P]<<4-4*(1&P);else if(2==m)for(P=0;P<T;P++)$[M+(P>>2)]|=n[t+P]<<6-2*(3&P);else if(1==m)for(P=0;P<T;P++)$[M+(P>>3)]|=n[t+P]<<7-1*(7&P)}e=$,g=3,s=1}else if(0==k&&1==A.length){$=new Uint8Array(T*t*3);const n=T*t;for(M=0;M<n;M++){const t=3*M,i=4*M;$[t]=e[i],$[t+1]=e[i+1],$[t+2]=e[i+2]}e=$,g=2,s=3,i=3*T}E.img=e,E.bpl=i,E.bpp=s}return{ctype:g,depth:m,plte:S,frames:A}}function c(e,i,s,n,r,h,o){const l=Uint8Array,u=Uint32Array,a=new l(e[r-1]),c=new u(e[r-1]),d=r+1<e.length?new l(e[r+1]):null,p=new l(e[r]),w=new u(p.buffer);let g=i,m=s,y=-1,v=-1;for(let t=0;t<h.height;t++)for(let e=0;e<h.width;e++){const s=h.x+e,o=h.y+t,l=o*i+s,u=w[l];0==u||0==n[r-1].dispose&&c[l]==u&&(null==d||0!=d[4*l+3])||(s<g&&(g=s),s>y&&(y=s),o<m&&(m=o),o>v&&(v=o))}-1==y&&(g=m=y=v=0),o&&(!(1&~g)&&g--,!(1&~m)&&m--);const b=n[r];b.rect=h={x:g,y:m,width:y-g+1,height:v-m+1},b.blend=1,b.img=new Uint8Array(h.width*h.height*4),0==n[r-1].dispose?(t(a,i,s,b.img,h.width,h.height,-h.x,-h.y,0),f(p,i,s,b.img,h)):t(p,i,s,b.img,h.width,h.height,-h.x,-h.y,0)}function f(e,i,s,n,r){t(e,i,s,n,r.width,r.height,-r.x,-r.y,2)}function d(t,e,i,s,n,r,h){const o=[];let l,u=[0,1,2,3,4];-1!=r?u=[r]:(e*s>5e5||1==i)&&(u=[0]),h&&(l={level:0});const a=Xr;for(var c=0;c<u.length;c++){for(let r=0;r<e;r++)p(n,t,r,s,i,u[c]);o.push(a.deflate(n,l))}let f,d=1e9;for(c=0;c<o.length;c++)o[c].length<d&&(f=c,d=o[c].length);return o[f]}function p(t,e,s,n,r,h){const o=s*n;let l=o+s;if(t[l]=h,l++,0==h)if(n<500)for(var u=0;u<n;u++)t[l+u]=e[o+u];else t.set(new Uint8Array(e.buffer,o,n),l);else if(1==h){for(u=0;u<r;u++)t[l+u]=e[o+u];for(u=r;u<n;u++)t[l+u]=e[o+u]-e[o+u-r]+256&255}else if(0==s){for(u=0;u<r;u++)t[l+u]=e[o+u];if(2==h)for(u=r;u<n;u++)t[l+u]=e[o+u];if(3==h)for(u=r;u<n;u++)t[l+u]=e[o+u]-(e[o+u-r]>>1)+256&255;if(4==h)for(u=r;u<n;u++)t[l+u]=e[o+u]-i(e[o+u-r],0,0)+256&255}else{if(2==h)for(u=0;u<n;u++)t[l+u]=e[o+u]+256-e[o+u-n]&255;if(3==h){for(u=0;u<r;u++)t[l+u]=e[o+u]+256-(e[o+u-n]>>1)&255;for(u=r;u<n;u++)t[l+u]=e[o+u]+256-(e[o+u-n]+e[o+u-r]>>1)&255}if(4==h){for(u=0;u<r;u++)t[l+u]=e[o+u]+256-i(0,e[o+u-n],0)&255;for(u=r;u<n;u++)t[l+u]=e[o+u]+256-i(e[o+u-r],e[o+u-n],e[o+u-r-n])&255}}}function w(t,e){const i=new Uint8Array(t),s=i.slice(0),n=new Uint32Array(s.buffer),r=g(s,e),h=r[0],o=r[1],l=i.length,u=new Uint8Array(l>>2);let a;if(i.length<2e7)for(var c=0;c<l;c+=4)a=m(h,f=i[c]*(1/255),d=i[c+1]*(1/255),p=i[c+2]*(1/255),w=i[c+3]*(1/255)),u[c>>2]=a.ind,n[c>>2]=a.est.rgba;else for(c=0;c<l;c+=4){var f=i[c]*(1/255),d=i[c+1]*(1/255),p=i[c+2]*(1/255),w=i[c+3]*(1/255);for(a=h;a.left;)a=y(a.est,f,d,p,w)<=0?a.left:a.right;u[c>>2]=a.ind,n[c>>2]=a.est.rgba}return{abuf:s.buffer,inds:u,plte:o}}function g(t,e,i){null==i&&(i=1e-4);const s=new Uint32Array(t.buffer),n={i0:0,i1:t.length,bst:null,est:null,tdst:0,left:null,right:null};n.bst=M(t,n.i0,n.i1),n.est=k(n.bst);const r=[n];for(;r.length<e;){let e=0,n=0;for(var h=0;h<r.length;h++)r[h].est.L>e&&(e=r[h].est.L,n=h);if(e<i)break;const o=r[n],l=v(t,s,o.i0,o.i1,o.est.e,o.est.eMq255);if(o.i0>=l||o.i1<=l){o.est.L=0;continue}const u={i0:o.i0,i1:l,bst:null,est:null,tdst:0,left:null,right:null};u.bst=M(t,u.i0,u.i1),u.est=k(u.bst);const a={i0:l,i1:o.i1,bst:null,est:null,tdst:0,left:null,right:null};for(a.bst={R:[],m:[],N:o.bst.N-u.bst.N},h=0;h<16;h++)a.bst.R[h]=o.bst.R[h]-u.bst.R[h];for(h=0;h<4;h++)a.bst.m[h]=o.bst.m[h]-u.bst.m[h];a.est=k(a.bst),o.left=u,o.right=a,r[n]=u,r.push(a)}for(r.sort(((t,e)=>e.bst.N-t.bst.N)),h=0;h<r.length;h++)r[h].ind=h;return[n,r]}function m(t,e,i,s,n){if(null==t.left)return t.tdst=function(t,e,i,s,n){const r=e-t[0],h=i-t[1],o=s-t[2],l=n-t[3];return r*r+h*h+o*o+l*l}(t.est.q,e,i,s,n),t;const r=y(t.est,e,i,s,n);let h=t.left,o=t.right;r>0&&(h=t.right,o=t.left);const l=m(h,e,i,s,n);if(l.tdst<=r*r)return l;const u=m(o,e,i,s,n);return u.tdst<l.tdst?u:l}function y(t,e,i,s,n){const{e:r}=t;return r[0]*e+r[1]*i+r[2]*s+r[3]*n-t.eMq}function v(t,e,i,s,n,r){for(s-=4;i<s;){for(;b(t,i,n)<=r;)i+=4;for(;b(t,s,n)>r;)s-=4;if(i>=s)break;const h=e[i>>2];e[i>>2]=e[s>>2],e[s>>2]=h,i+=4,s-=4}for(;b(t,i,n)>r;)i-=4;return i+4}function b(t,e,i){return t[e]*i[0]+t[e+1]*i[1]+t[e+2]*i[2]+t[e+3]*i[3]}function M(t,e,i){const s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=[0,0,0,0],r=i-e>>2;for(let r=e;r<i;r+=4){const e=t[r]*(1/255),i=t[r+1]*(1/255),h=t[r+2]*(1/255),o=t[r+3]*(1/255);n[0]+=e,n[1]+=i,n[2]+=h,n[3]+=o,s[0]+=e*e,s[1]+=e*i,s[2]+=e*h,s[3]+=e*o,s[5]+=i*i,s[6]+=i*h,s[7]+=i*o,s[10]+=h*h,s[11]+=h*o,s[15]+=o*o}return s[4]=s[1],s[8]=s[2],s[9]=s[6],s[12]=s[3],s[13]=s[7],s[14]=s[11],{R:s,m:n,N:r}}function k(t){const{R:e}=t,{m:i}=t,{N:s}=t,n=i[0],r=i[1],h=i[2],o=i[3],l=0==s?0:1/s,u=[e[0]-n*n*l,e[1]-n*r*l,e[2]-n*h*l,e[3]-n*o*l,e[4]-r*n*l,e[5]-r*r*l,e[6]-r*h*l,e[7]-r*o*l,e[8]-h*n*l,e[9]-h*r*l,e[10]-h*h*l,e[11]-h*o*l,e[12]-o*n*l,e[13]-o*r*l,e[14]-o*h*l,e[15]-o*o*l],a=u,c=A;let f=[Math.random(),Math.random(),Math.random(),Math.random()],d=0,p=0;if(0!=s)for(let t=0;t<16&&(f=c.multVec(a,f),p=Math.sqrt(c.dot(f,f)),f=c.sml(1/p,f),!(0!=t&&Math.abs(p-d)<1e-9));t++)d=p;const w=[n*l,r*l,h*l,o*l];return{Cov:u,q:w,e:f,L:d,eMq255:c.dot(c.sml(255,w),f),eMq:c.dot(f,w),rgba:(Math.round(255*w[3])<<24|Math.round(255*w[2])<<16|Math.round(255*w[1])<<8|Math.round(255*w[0]))>>>0}}var A={multVec:(t,e)=>[t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3],t[4]*e[0]+t[5]*e[1]+t[6]*e[2]+t[7]*e[3],t[8]*e[0]+t[9]*e[1]+t[10]*e[2]+t[11]*e[3],t[12]*e[0]+t[13]*e[1]+t[14]*e[2]+t[15]*e[3]],dot:(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3],sml:(t,e)=>[t*e[0],t*e[1],t*e[2],t*e[3]]};Jr.encode=function(t,e,i,s,n,r,h){null==s&&(s=0),null==h&&(h=!1);const o=a(t,e,i,s,[!1,!1,!1,0,h,!1]);return u(o,-1),l(o,e,i,n,r)},Jr.encodeLL=function(t,e,i,s,n,r,h,o){const a={ctype:0+(1==s?0:2)+(0==n?0:4),depth:r,frames:[]},c=(s+n)*r,f=c*e;for(let s=0;s<t.length;s++)a.frames.push({rect:{x:0,y:0,width:e,height:i},img:new Uint8Array(t[s]),blend:0,dispose:1,bpp:Math.ceil(c/8),bpl:Math.ceil(f/8)});return u(a,0,!0),l(a,e,i,h,o)},Jr.encode.compress=a,Jr.encode.dither=o,Jr.quantize=w,Jr.quantize.getKDtree=g,Jr.quantize.getNearest=m}();const Hr={toArrayBuffer(t,e){const i=t.width,s=t.height,n=i<<2,r=t.getContext("2d").getImageData(0,0,i,s),h=new Uint32Array(r.data.buffer),o=(32*i+31)/32<<2,l=o*s,u=122+l,a=new ArrayBuffer(u),c=new DataView(a),f=1<<20;let d,p,w,g,m=f,y=0,v=0,b=0;function M(t){c.setUint16(v,t,!0),v+=2}function k(t){c.setUint32(v,t,!0),v+=4}function A(t){v+=t}M(19778),k(u),A(4),k(122),k(108),k(i),k(-s>>>0),M(1),M(32),k(3),k(l),k(2835),k(2835),A(8),k(16711680),k(65280),k(255),k(4278190080),k(1466527264),function t(){for(;y<s&&m>0;){for(g=122+y*o,d=0;d<n;)m--,p=h[b++],w=p>>>24,c.setUint32(g+d,p<<8|w),d+=4;y++}b<h.length?(m=f,setTimeout(t,Hr._dly)):e(a)}()},toBlob(t,e){this.toArrayBuffer(t,(t=>{e(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var Vr={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},Qr={[Vr.CHROME]:16384,[Vr.FIREFOX]:11180,[Vr.DESKTOP_SAFARI]:16384,[Vr.IE]:8192,[Vr.IOS]:4096,[Vr.ETC]:8192};const Kr="undefined"!=typeof window,qr="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,Gr=Kr&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),Zr=(Kr||qr)&&(Gr&&Gr.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),th=(Kr||qr)&&(Gr&&Gr.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function eh(t,e,i=Date.now()){return new Promise((s=>{const n=t.split(","),r=n[0].match(/:(.*?);/)[1],h=globalThis.atob(n[1]);let o=h.length;const l=new Uint8Array(o);for(;o--;)l[o]=h.charCodeAt(o);const u=new Blob([l],{type:r});u.name=e,u.lastModified=i,s(u)}))}function ih(t){return new Promise(((e,i)=>{const s=new th;s.onload=()=>e(s.result),s.onerror=t=>i(t),s.readAsDataURL(t)}))}function sh(t){return new Promise(((e,i)=>{const s=new Image;s.onload=()=>e(s),s.onerror=t=>i(t),s.src=t}))}function nh(){if(void 0!==nh.cachedResult)return nh.cachedResult;let t=Vr.ETC;const{userAgent:e}=navigator;return/Chrom(e|ium)/i.test(e)?t=Vr.CHROME:/iP(ad|od|hone)/i.test(e)&&/WebKit/i.test(e)?t=Vr.IOS:/Safari/i.test(e)?t=Vr.DESKTOP_SAFARI:/Firefox/i.test(e)?t=Vr.FIREFOX:(/MSIE/i.test(e)||1==!!document.documentMode)&&(t=Vr.IE),nh.cachedResult=t}function rh(t,e){const i=nh(),s=Qr[i];let n=t,r=e,h=n*r;const o=n>r?r/n:n/r;for(;h>s*s;){const t=(s+n)/2,e=(s+r)/2;t<e?(r=e,n=e*o):(r=t*o,n=t),h=n*r}return{width:n,height:r}}function hh(t,e){let i,s;try{if(i=new OffscreenCanvas(t,e),s=i.getContext("2d"),null===s)throw new Error("getContext of OffscreenCanvas returns null")}catch(t){i=document.createElement("canvas"),s=i.getContext("2d")}return i.width=t,i.height=e,[i,s]}function oh(t,e){const{width:i,height:s}=rh(t.width,t.height),[n,r]=hh(i,s);return e&&/jpe?g/.test(e)&&(r.fillStyle="white",r.fillRect(0,0,n.width,n.height)),r.drawImage(t,0,0,n.width,n.height),n}function lh(){return void 0!==lh.cachedResult||(lh.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),lh.cachedResult}function uh(t,e={}){return new Promise((function(i,s){let n,r;var h=function(){try{return r=oh(n,e.fileType||t.type),i([n,r])}catch(t){return s(t)}},o=function(){try{var e=function(t){try{throw t}catch(t){return s(t)}};try{let i;return ih(t).then((function(t){try{return i=t,sh(i).then((function(t){try{return n=t,function(){try{return h()}catch(t){return s(t)}}()}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){e(t)}}catch(t){return s(t)}};try{if(lh()||[Vr.DESKTOP_SAFARI,Vr.MOBILE_SAFARI].includes(nh()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return n=t,h()}catch(t){return o()}}),o)}catch(t){o()}}))}function ah(t,e,i,s,n=1){return new Promise((function(r,h){let o;if("image/png"===e){let u,a,c;return u=t.getContext("2d"),({data:a}=u.getImageData(0,0,t.width,t.height)),c=Jr.encode([a.buffer],t.width,t.height,4096*n),o=new Blob([c],{type:e}),o.name=i,o.lastModified=s,l.call(this)}{if("image/bmp"===e)return new Promise((e=>Hr.toBlob(t,e))).then(function(t){try{return o=t,o.name=i,o.lastModified=s,f.call(this)}catch(t){return h(t)}}.bind(this),h);{if("function"==typeof OffscreenCanvas&&t instanceof OffscreenCanvas)return t.convertToBlob({type:e,quality:n}).then(function(t){try{return o=t,o.name=i,o.lastModified=s,d.call(this)}catch(t){return h(t)}}.bind(this),h);{let p;return p=t.toDataURL(e,n),eh(p,i,s).then(function(t){try{return o=t,d.call(this)}catch(t){return h(t)}}.bind(this),h)}function d(){return f.call(this)}}function f(){return l.call(this)}}function l(){return r(o)}}))}function ch(t){t.width=0,t.height=0}function fh(){return new Promise((function(t,e){let i,s,n,r;return void 0!==fh.cachedResult?t(fh.cachedResult):eh("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(h){try{return i=h,uh(i).then((function(h){try{return s=h[1],ah(s,i.type,i.name,i.lastModified).then((function(i){try{return n=i,ch(s),uh(n).then((function(i){try{return r=i[0],t(fh.cachedResult=1===r.width&&2===r.height)}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}))}function dh(t){return new Promise(((e,i)=>{const s=new th;s.onload=t=>{const i=new DataView(t.target.result);if(65496!=i.getUint16(0,!1))return e(-2);const s=i.byteLength;let n=2;for(;n<s;){if(i.getUint16(n+2,!1)<=8)return e(-1);const t=i.getUint16(n,!1);if(n+=2,65505==t){if(1165519206!=i.getUint32(n+=2,!1))return e(-1);const t=18761==i.getUint16(n+=6,!1);n+=i.getUint32(n+4,t);const s=i.getUint16(n,t);n+=2;for(let r=0;r<s;r++)if(274==i.getUint16(n+12*r,t))return e(i.getUint16(n+12*r+8,t))}else{if(65280&~t)break;n+=i.getUint16(n,!1)}}return e(-1)},s.onerror=t=>i(t),s.readAsArrayBuffer(t)}))}function ph(t,e){const{width:i}=t,{height:s}=t,{maxWidthOrHeight:n}=e;let r,h=t;return isFinite(n)&&(i>n||s>n)&&([h,r]=hh(i,s),i>s?(h.width=n,h.height=s/i*n):(h.width=i/s*n,h.height=n),r.drawImage(t,0,0,h.width,h.height),ch(t)),h}function wh(t,e){const{width:i}=t,{height:s}=t,[n,r]=hh(i,s);switch(e>4&&e<9?(n.width=s,n.height=i):(n.width=i,n.height=s),e){case 2:r.transform(-1,0,0,1,i,0);break;case 3:r.transform(-1,0,0,-1,i,s);break;case 4:r.transform(1,0,0,-1,0,s);break;case 5:r.transform(0,1,1,0,0,0);break;case 6:r.transform(0,1,-1,0,s,0);break;case 7:r.transform(0,-1,-1,0,s,i);break;case 8:r.transform(0,-1,1,0,0,i)}return r.drawImage(t,0,0,i,s),ch(t),n}function gh(t,e,i=0){return new Promise((function(s,n){let r,h,o,l,u,a,c,f,d,p,w,g,m,y,v,b,M,k,A,x;function S(t=5){if(e.signal&&e.signal.aborted)throw e.signal.reason;r+=t,e.onProgress(Math.min(r,100))}function C(t){if(e.signal&&e.signal.aborted)throw e.signal.reason;r=Math.min(Math.max(t,r),100),e.onProgress(r)}return r=i,h=e.maxIteration||10,o=1024*e.maxSizeMB*1024,S(),uh(t,e).then(function(i){try{return[,l]=i,S(),u=ph(l,e),S(),new Promise((function(i,s){var n;if(!(n=e.exifOrientation))return dh(t).then(function(t){try{return n=t,r.call(this)}catch(t){return s(t)}}.bind(this),s);function r(){return i(n)}return r.call(this)})).then(function(i){try{return a=i,S(),fh().then(function(i){try{return c=i?u:wh(u,a),S(),f=e.initialQuality||1,d=e.fileType||t.type,ah(c,d,t.name,t.lastModified,f).then(function(i){try{{if(p=i,S(),w=p.size>o,g=p.size>t.size,!w&&!g)return C(100),s(p);var r;function a(){if(h--&&(v>o||v>m)){let e,i;return e=x?.95*A.width:A.width,i=x?.95*A.height:A.height,[M,k]=hh(e,i),k.drawImage(A,0,0,e,i),f*="image/png"===d?.85:.95,ah(M,d,t.name,t.lastModified,f).then((function(t){try{return b=t,ch(A),A=M,v=b.size,C(Math.min(99,Math.floor((y-v)/(y-o)*100))),a}catch(t){return n(t)}}),n)}return[1]}return m=t.size,y=p.size,v=y,A=c,x=!e.alwaysKeepResolution&&w,(r=function(t){for(;t;){if(t.then)return void t.then(r,n);try{if(t.pop){if(t.length)return t.pop()?O.call(this):t;t=a}else t=t.call(this)}catch(t){return n(t)}}}.bind(this))(a);function O(){return ch(A),ch(M),ch(u),ch(c),ch(l),C(100),s(b)}}}catch(E){return n(E)}}.bind(this),n)}catch(t){return n(t)}}.bind(this),n)}catch(t){return n(t)}}.bind(this),n)}catch(t){return n(t)}}.bind(this),n)}))}let mh;function yh(t,e){return new Promise(((i,s)=>{mh||(mh=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 n=new Worker(mh);n.addEventListener("message",(function(t){if(e.signal&&e.signal.aborted)n.terminate();else if(void 0===t.data.progress){if(t.data.error)return s(new Error(t.data.error)),void n.terminate();i(t.data.file),n.terminate()}else e.onProgress(t.data.progress)})),n.addEventListener("error",s),e.signal&&e.signal.addEventListener("abort",(()=>{s(e.signal.reason),n.terminate()})),n.postMessage({file:t,imageCompressionLibUrl:e.libURL,options:{...e,onProgress:void 0,signal:void 0}})}))}function vh(t,e){return new Promise((function(i,s){let n,r,h,o,l,u;if(n={...e},h=0,({onProgress:o}=n),n.maxSizeMB=n.maxSizeMB||Number.POSITIVE_INFINITY,l="boolean"!=typeof n.useWebWorker||n.useWebWorker,delete n.useWebWorker,n.onProgress=t=>{h=t,"function"==typeof o&&o(h)},!(t instanceof Blob||t instanceof Zr))return s(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(t.type))return s(new Error("The file given is not an image"));if(u="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!l||"function"!=typeof Worker||u)return gh(t,n).then(function(t){try{return r=t,f.call(this)}catch(t){return s(t)}}.bind(this),s);var a=function(){try{return f.call(this)}catch(t){return s(t)}}.bind(this),c=function(){try{return gh(t,n).then((function(t){try{return r=t,a()}catch(t){return s(t)}}),s)}catch(t){return s(t)}};try{return n.libURL=n.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",yh(t,n).then((function(t){try{return r=t,a()}catch(t){return c()}}),c)}catch(t){c()}function f(){try{r.name=t.name,r.lastModified=t.lastModified}catch(t){}try{n.preserveExif&&"image/jpeg"===t.type&&(!n.fileType||n.fileType&&n.fileType===t.type)&&(r=Lr(t,r))}catch(t){}return i(r)}}))}vh.getDataUrlFromFile=ih,vh.getFilefromDataUrl=eh,vh.loadImage=sh,vh.drawImageInCanvas=oh,vh.drawFileInCanvas=uh,vh.canvasToFile=ah,vh.getExifOrientation=dh,vh.handleMaxWidthOrHeight=ph,vh.followExifOrientation=wh,vh.cleanupCanvasMemory=ch,vh.isAutoOrientationInBrowser=fh,vh.approximateBelowMaximumCanvasSizeOfBrowser=rh,vh.copyExifWithoutOrientation=Lr,vh.getBrowserName=nh,vh.version="2.0.2";class bh extends jr{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 e=t.target;e.files&&e.files[0]?vh(e.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()),e&&(e.value="")}readFile(t){const e=new FileReader;e.onload=t=>{const e=new Image;e.src=t.target?.result,e.onload=()=>this.createKritzelImage(e)},e.readAsDataURL(t)}createKritzelImage(t){const e=Pr.create(this._core),{scaledWidth:i,scaledHeight:s}=e.calculateScaledDimensions(t);return e.src=t.src,e.width=i,e.height=s,e.zIndex=this._core.store.currentZIndex,e.centerInViewport(),this.addImageToStore(e),e}addImageToStore(e){this._core.addObject(e),this._core.store.setState("activeTool",t.getTool("selection")),this._core.selectObjects([e]),this._core.engine.emitObjectsChange()}handleCancel(){this._core.store.setState("activeTool",t.getTool("selection"))}}class Mh extends jr{fontFamily="Arial";fontSize=16;fontColor="#000000";opacity=1;palette=["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#808080","#C0C0C0","#800000","#008000","#000080","#808000","#800080"];constructor(t){super(t)}handlePointerDown(e){if(e.cancelable&&e.preventDefault(),"mouse"===e.pointerType){const i=e.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),s=this._core.findObjectById(i?.id),n=this._core.store.activeText;if(null===n&&s instanceof Sr)return void s.edit(e);if(null!==n&&s instanceof Sr)return n.save(),void s.edit(e);if(null!==n&&s instanceof Sr==0)return this._core.resetActiveText(),void this._core.store.setState("activeTool",t.getTool("selection"));if(!1===Ur.isLeftClick(e))return;const r=e.clientX-this._core.store.offsetX,h=e.clientY-this._core.store.offsetY,o=Sr.create(this._core,this.fontSize,this.fontFamily);o.fontColor=this.fontColor,o.opacity=this.opacity,o.translateX=(r-this._core.store.state.translateX)/this._core.store.state.scale,o.translateY=(h-this._core.store.state.translateY)/this._core.store.state.scale,o.zIndex=this._core.store.currentZIndex,this._core.store.state.objects.insert(o),this._core.rerender(),o.edit(e)}if("touch"===e.pointerType){const i=Array.from(this._core.store.state.pointers.values()),s=e.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),n=this._core.findObjectById(s?.id),r=this._core.store.activeText;if(null===r&&n instanceof Sr)return void n.edit(e);if(null!==r&&n instanceof Sr)return r.save(),void n.edit(e);if(null!==r&&n instanceof Sr==0)return this._core.resetActiveText(),void this._core.store.setState("activeTool",t.getTool("selection"));if(i.length>1)return;const h=Math.round(i[0].clientX-this._core.store.offsetX),o=Math.round(i[0].clientY-this._core.store.offsetY),l=Sr.create(this._core,this.fontSize,this.fontFamily);l.fontColor=this.fontColor,l.opacity=this.opacity,l.translateX=(h-this._core.store.state.translateX)/this._core.store.state.scale,l.translateY=(o-this._core.store.state.translateY)/this._core.store.state.scale,l.zIndex=this._core.store.currentZIndex,this._core.store.state.objects.insert(l),this._core.rerender(),l.edit(e)}}handlePointerUp(t){t.cancelable&&t.preventDefault(),this._core.store.activeText?.edit(t)}}class kh{static registry=new Map;static register(t,e){this.registry.has(t)&&console.warn(`[IconRegistry] Icon "${t}" is already registered. It will be overwritten.`),this.registry.set(t,e)}static get(t){return this.registry.get(t)}static registerIcons(t){for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&this.register(e,t[e])}static has(t){return this.registry.has(t)}}kh.registerIcons({cursor:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z"/></svg>',pen:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/></svg>',arrow:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="19" x2="19" y2="5"/><path d="M15 5h4v4"/></svg>',highlighter:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-highlighter-icon lucide-highlighter"><path d="m9 11-6 6v3h9l3-3"/><path d="m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"/></svg>',eraser:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21"/><path d="M22 21H7"/><path d="m5 11 9 9"/></svg>',type:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 7 4 4 20 4 20 7"/><line x1="9" x2="15" y1="20" y2="20"/><line x1="12" x2="12" y1="4" y2="20"/></svg>',shapes:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z"/><rect x="3" y="14" width="7" height="7" rx="1"/><circle cx="17.5" cy="17.5" r="3.5"/></svg>',"shape-rectangle":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/></svg>',"shape-ellipse":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="12" rx="10" ry="8"/></svg>',"shape-triangle":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3L22 21H2L12 3Z"/></svg>',image:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>',"chevron-down":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>',"chevron-up":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m18 15-6-6-6 6"/></svg>',copy:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy-icon lucide-copy"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>',paste:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-clipboard-paste-icon lucide-clipboard-paste"><path d="M11 14h10"/><path d="M16 4h2a2 2 0 0 1 2 2v1.344"/><path d="m17 18 4-4-4-4"/><path d="M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113"/><rect x="8" y="2" width="8" height="4" rx="1"/></svg>',cut:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-scissors-icon lucide-scissors"><circle cx="6" cy="6" r="3"/><path d="M8.12 8.12 12 12"/><path d="M20 4 8.12 15.88"/><circle cx="6" cy="18" r="3"/><path d="M14.8 14.8 20 20"/></svg>',delete:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trash2-icon lucide-trash-2"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" x2="10" y1="11" y2="17"/><line x1="14" x2="14" y1="11" y2="17"/></svg>',"bring-to-front":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-up-to-line-icon lucide-arrow-up-to-line"><path d="M5 3h14"/><path d="m18 13-6-6-6 6"/><path d="M12 7v14"/></svg>',"send-to-back":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-down-to-line-icon lucide-arrow-down-to-line"><path d="M12 17V3"/><path d="m6 11 6 6 6-6"/><path d="M19 21H5"/></svg>',"select-all":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-square-mouse-pointer-icon lucide-square-mouse-pointer"><path d="M12.034 12.681a.498.498 0 0 1 .647-.647l9 3.5a.5.5 0 0 1-.033.943l-3.444 1.068a1 1 0 0 0-.66.66l-1.067 3.443a.5.5 0 0 1-.943.033z"/><path d="M21 11V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h6"/></svg>',download:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-download-icon lucide-download"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" x2="12" y1="15" y2="3"/></svg>',undo:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-undo-icon lucide-undo"><path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/></svg>',redo:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-redo-icon lucide-redo"><path d="M21 7v6h-6"/><path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7"/></svg>',plus:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-plus-icon lucide-plus"><path d="M5 12h14"/><path d="M12 5v14"/></svg>',"ellipsis-vertical":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-ellipsis-vertical-icon lucide-ellipsis-vertical"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>',x:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-x-icon lucide-x"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',check:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-check-icon lucide-check"><path d="M20 6 9 17l-5-5"/></svg>',group:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-group-icon lucide-group"><path d="M3 7V5c0-1.1.9-2 2-2h2"/><path d="M17 3h2c1.1 0 2 .9 2 2v2"/><path d="M21 17v2c0 1.1-.9 2-2 2h-2"/><path d="M7 21H5c-1.1 0-2-.9-2-2v-2"/><rect width="7" height="5" x="7" y="7" rx="1"/><rect width="7" height="5" x="10" y="12" rx="1"/></svg>',ungroup:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-ungroup-icon lucide-ungroup"><rect width="8" height="6" x="5" y="4" rx="1"/><rect width="8" height="6" x="11" y="14" rx="1"/></svg>',"move-vertical":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-move-vertical-icon lucide-move-vertical" version="1.1" id="svg3"> <defs id="defs3" /> <path d="M12 2v20" id="path1" /> <path style="fill:#ffffff;stroke-width:2.5;stroke-dasharray:none;stroke-linejoin:round;paint-order:stroke fill markers" d="m 11.735575,22.661865 c -0.09259,-0.02798 -0.204674,-0.07661 -0.249076,-0.108068 -0.04441,-0.03147 -1.167275,-0.979853 -2.4952713,-2.10755 -1.8557024,-1.57581 -2.4300904,-2.079639 -2.4817336,-2.17687 -0.086514,-0.162885 -0.089504,-0.422449 -0.00664,-0.576334 0.1483053,-0.275409 0.437667,-0.436207 0.7830634,-0.435147 0.3692925,0.0011 0.3517326,-0.01122 2.168748,1.525599 L 11.12348,20.194964 V 11.999996 3.8050256 L 9.4546663,5.2164943 C 7.6376509,6.7533118 7.6552109,6.7409594 7.2859184,6.7420935 6.6681409,6.7439906 6.253658,6.1955854 6.5159903,5.723396 6.5738626,5.6192278 7.1368766,5.1267427 9.0629381,3.4955044 11.738128,1.2298067 11.640395,1.3026868 12.00355,1.3026868 c 0.363154,0 0.265421,-0.07288 2.940611,2.1928176 1.926062,1.6312383 2.489076,2.1237234 2.546948,2.2278916 0.262332,0.4721894 -0.15215,1.0205946 -0.769928,1.0186975 -0.369293,-0.00114 -0.351733,0.011218 -2.168748,-1.5255992 L 12.88362,3.8050256 v 8.1949704 8.194968 l 1.668813,-1.411469 c 1.817015,-1.536817 1.799455,-1.524464 2.168748,-1.525599 0.617772,-0.0019 1.032269,0.546521 0.769928,1.018687 -0.103474,0.18623 -4.919006,4.273935 -5.130582,4.355136 -0.20796,0.07981 -0.425829,0.09033 -0.624952,0.03014 z" id="path4" /> </svg>',hand:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-hand-icon lucide-hand" version="1.1" id="svg4"> <defs id="defs4" /> <path d="M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2" id="path1" /> <path d="M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2" id="path2" /> <path d="M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8" id="path3" /> <path d="M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15" id="path4" /> <path style="fill:#ffffff;stroke-width:0.0423032" d="M 11.478261,21.222477 C 9.6854059,21.139331 8.3341788,20.647346 7.1297169,19.639159 6.9698298,19.505327 5.949644,18.508708 4.8626374,17.42445 3.0780314,15.644357 2.8775851,15.435367 2.7968392,15.270602 2.5896561,14.847836 2.616354,14.436649 2.8771894,14.033085 c 0.136522,-0.211226 0.3837159,-0.398688 0.6367632,-0.482897 0.1529977,-0.05091 0.2326803,-0.05992 0.4470908,-0.05054 0.2250407,0.0098 0.2876577,0.02439 0.4554568,0.105827 0.1747854,0.08483 0.2933718,0.192702 1.1675186,1.062064 0.7182021,0.714271 1.0062041,0.982633 1.0998825,1.024878 0.1680197,0.07577 0.4756439,0.07817 0.6368269,0.005 0.1370772,-0.06226 0.2976691,-0.220818 0.3691296,-0.364463 0.072561,-0.145855 0.071573,-0.543545 -0.00169,-0.681911 -0.028747,-0.05429 -0.2476439,-0.296131 -0.4864385,-0.537426 l -0.4341716,-0.438718 0.00753,-3.989014 0.00753,-3.9890137 0.089246,-0.1883791 c 0.244787,-0.516692 0.7711718,-0.809716 1.3059705,-0.7269981 0.3973687,0.061462 0.7569953,0.3284904 0.9363122,0.6952277 l 0.093853,0.1919473 0.014101,2.4958872 0.014101,2.4958877 0.067385,0.149123 c 0.1186861,0.262654 0.4140438,0.457222 0.6940724,0.457222 0.2764172,0 0.5690532,-0.187563 0.6965992,-0.446482 l 0.06486,-0.131661 0.0141,-3.4970626 0.0141,-3.4970623 0.08982,-0.1896121 C 11.096301,3.0422103 11.506844,2.7755634 12,2.7755634 c 0.493156,0 0.903699,0.2666469 1.122868,0.7293016 l 0.08982,0.1896121 0.0141,3.2432432 c 0.01405,3.2315947 0.01432,3.2437077 0.07397,3.3726737 0.124721,0.269649 0.355908,0.424566 0.661411,0.443206 0.237954,0.01452 0.429018,-0.0627 0.591626,-0.239109 0.223655,-0.242637 0.208338,-0.06565 0.224113,-2.5896966 l 0.0141,-2.2561693 0.09385,-0.1919473 c 0.179317,-0.3667373 0.538944,-0.6337662 0.936313,-0.6952277 0.609359,-0.09425 1.208067,0.3054956 1.370981,0.9153772 0.03013,0.1127929 0.03773,0.6662436 0.038,2.7657391 3.74e-4,2.9328416 -0.008,2.8034316 0.197044,3.0364016 0.234927,0.266892 0.603828,0.337117 0.920407,0.175213 0.181933,-0.09304 0.329759,-0.261686 0.376309,-0.4293 0.01848,-0.06654 0.02929,-0.683932 0.0295,-1.684364 1.78e-4,-0.8783075 0.01239,-1.6530128 0.02751,-1.745346 0.08579,-0.5238478 0.505382,-0.9420803 1.039546,-1.0361716 0.607538,-0.1070155 1.25615,0.3485846 1.385876,0.973471 0.02211,0.1064847 0.02843,1.1397236 0.02169,3.5455556 -0.0093,3.324725 -0.01078,3.403075 -0.07062,3.770606 -0.126399,0.776213 -0.328814,1.41352 -0.669031,2.106456 -0.36657,0.746612 -0.72118,1.250303 -1.297841,1.843464 -1.185731,1.21966 -2.604527,1.933174 -4.300822,2.162889 -0.38234,0.05178 -2.604621,0.0785 -3.412456,0.04104 z" id="path16" /> </svg>',"hand-grab":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-hand-grab-icon lucide-hand-grab" version="1.1" id="svg5"> <defs id="defs5" /> <path d="M18 11.5V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1.4" id="path1" /> <path d="M14 10V8a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2" id="path2" /> <path d="M10 9.9V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v5" id="path3" /> <path d="M6 14a2 2 0 0 0-2-2a2 2 0 0 0-2 2" id="path4" /> <path d="M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-4a8 8 0 0 1-8-8 2 2 0 1 1 4 0" id="path5" /> <path style="fill:#ffffff;stroke-width:0.0423032" d="M 9.5887192,21.221364 C 8.0526856,21.128375 6.6533474,20.587008 5.4571093,19.622953 5.3019976,19.497947 5.0101058,19.225967 4.8084606,19.018552 4.2300382,18.423579 3.8474097,17.879011 3.4960953,17.150756 3.1017715,16.333345 2.9014937,15.633198 2.8052391,14.735605 c -0.097577,-0.909922 -0.019834,-1.263323 0.3569794,-1.622742 0.753018,-0.718257 1.9463784,-0.256949 2.0619296,0.797066 0.037839,0.345154 0.089701,0.477674 0.2472582,0.631806 0.2464521,0.241095 0.5958008,0.287445 0.9036474,0.119894 0.1478567,-0.08047 0.2303871,-0.16866 0.3266699,-0.349056 0.050118,-0.0939 0.05337,-0.2326 0.066784,-2.848413 L 6.7826087,8.7144536 6.8458627,8.559342 C 6.9736603,8.2459558 7.2463773,7.9734987 7.5581669,7.8477164 c 0.1253804,-0.050581 0.2118709,-0.062705 0.4512338,-0.063254 0.275392,-6.312e-4 0.3094658,0.00564 0.4867271,0.089609 0.264676,0.1253746 0.4771417,0.334346 0.6070085,0.5970252 l 0.1048543,0.212087 0.017338,0.7488899 c 0.019395,0.8377165 0.026343,0.8713745 0.2242006,1.0860245 0.1591067,0.172611 0.3522021,0.249908 0.5883018,0.235502 0.305503,-0.01864 0.53669,-0.173557 0.661411,-0.443206 0.05734,-0.123963 0.0605,-0.181852 0.07486,-1.3703236 0.01626,-1.3456629 0.0141,-1.3267758 0.182667,-1.5938092 0.257891,-0.4085268 0.77099,-0.6442307 1.228943,-0.5645435 0.471012,0.08196 0.850379,0.4102836 0.989676,0.8565175 0.04663,0.149383 0.0514,0.2860903 0.0514,1.4721724 0,0.8344844 0.01108,1.3591794 0.03064,1.4503554 0.04109,0.191585 0.179844,0.390224 0.342505,0.490321 0.27721,0.170587 0.693425,0.126085 0.92529,-0.09893 0.228986,-0.222224 0.234357,-0.25046 0.251582,-1.3227071 l 0.0152,-0.9463484 0.104855,-0.2120434 c 0.129872,-0.2626357 0.342372,-0.471626 0.607008,-0.5969817 0.177262,-0.083967 0.211335,-0.09024 0.486727,-0.089609 0.239363,5.486e-4 0.325854,0.012673 0.451234,0.063254 0.31179,0.1257823 0.584507,0.3982394 0.712304,0.7116256 0.0621,0.1522783 0.06351,0.1824139 0.07736,1.649824 0.01408,1.492435 0.0142,1.494914 0.07947,1.627432 0.0771,0.156535 0.2216,0.291061 0.395058,0.367789 0.09695,0.04289 0.169789,0.05275 0.325757,0.04411 0.230544,-0.01277 0.363779,-0.06826 0.506411,-0.21089 0.177062,-0.177061 0.198302,-0.25307 0.219359,-0.784959 0.02002,-0.505773 0.05012,-0.6549 0.175297,-0.868492 0.498409,-0.850471 1.728484,-0.8041941 2.173478,0.08177 0.131751,0.262312 0.134447,0.313526 0.122615,2.328965 -0.0104,1.771638 -0.01517,1.923481 -0.0714,2.273746 -0.123689,0.770512 -0.327108,1.411813 -0.668163,2.106456 -0.36657,0.746612 -0.72118,1.250303 -1.297841,1.843464 -1.180268,1.214041 -2.600612,1.930754 -4.287083,2.163284 -0.28697,0.03957 -0.685446,0.04782 -2.636536,0.05459 -1.26416,0.0044 -2.4698005,-0.0024 -2.6792012,-0.01507 z" id="path6" /> </svg>',"mouse-pointer":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-mouse-pointer2-icon lucide-mouse-pointer-2" version="1.1" id="svg1"> <defs id="defs1" /> <path d="M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z" id="path1" /> <path style="fill:#ffffff;stroke-width:0.0972651;stroke-linejoin:round;paint-order:stroke fill markers" d="M 7.8509196,12.314844 C 6.127071,8.1920568 4.7235325,4.8125504 4.7319449,4.8048299 c 0.01847,-0.016951 15.4787861,6.0801241 15.4610371,6.0973581 -0.0069,0.0067 -1.32633,0.341226 -2.93219,0.743509 -1.858829,0.465652 -3.011462,0.772855 -3.172161,0.845453 -0.688426,0.310999 -1.245788,0.879167 -1.498145,1.527185 -0.06251,0.160512 -0.440389,1.529576 -0.839733,3.042364 -0.399346,1.512788 -0.734966,2.750433 -0.745822,2.750322 -0.01086,-1.09e-4 -1.430163,-3.373391 -3.1540114,-7.496177 z" id="path2" /> <path style="fill:#ffffff;stroke-width:0.0705053;stroke-linejoin:round;paint-order:stroke fill markers" d="M 10.777831,19.240865 C 9.3899089,15.977493 4.7567738,4.8648478 4.7760705,4.8455511 c 0.013084,-0.013084 4.7618079,1.8507077 10.7773965,4.2299406 4.467495,1.7669453 4.558837,1.8037523 4.533848,1.8269883 -0.01183,0.011 -0.96064,0.257045 -2.108467,0.546768 -3.445281,0.869623 -3.777157,0.960825 -4.075205,1.119907 -0.597122,0.31871 -1.103666,0.864485 -1.309236,1.410635 -0.09642,0.256167 -0.312339,1.032806 -0.943226,3.392713 -0.641066,2.39798 -0.629171,2.354884 -0.649929,2.354849 -0.0091,-1.5e-5 -0.10963,-0.218934 -0.223421,-0.486487 z" id="path6" /> </svg>',pointer:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-pointer-icon lucide-pointer" version="1.1" id="svg5"> <defs id="defs5" /> <path d="M22 14a8 8 0 0 1-8 8" id="path1" /> <path d="M18 11v-1a2 2 0 0 0-2-2a2 2 0 0 0-2 2" id="path2" /> <path d="M14 10V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1" id="path3" /> <path d="M10 9.5V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v10" id="path4" /> <path d="M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15" id="path5" /> <path style="fill:#ffffff;stroke-width:0.0930233;stroke-linejoin:round;paint-order:stroke fill markers" d="M 11.2,21.203517 C 9.5092536,21.041493 8.4838422,20.667261 7.3116279,19.784423 7.1888372,19.691945 6.139155,18.670017 4.9790008,17.513473 2.5649891,15.106974 2.6562686,15.220427 2.6869266,14.664621 c 0.020277,-0.367608 0.1272548,-0.601802 0.3822766,-0.836873 0.2609241,-0.240511 0.4631523,-0.319555 0.8191689,-0.320185 0.509345,-9.02e-4 0.5815472,0.04845 1.7102825,1.168976 0.532833,0.528958 1.0223742,0.98871 1.0878697,1.021671 0.1699959,0.08555 0.4741793,0.07658 0.6733897,-0.01985 0.303161,-0.146758 0.4720469,-0.543298 0.3791811,-0.890307 -0.036373,-0.135913 -0.1250717,-0.246717 -0.506083,-0.632208 l -0.4619807,-0.467411 0.00983,-5.002356 0.00983,-5.0023561 0.080405,-0.1739784 C 6.9849846,3.2633288 7.2288893,3.0140593 7.4738043,2.8937849 7.6531903,2.8056908 7.7297209,2.7906977 8,2.7906977 c 0.2702791,0 0.3468097,0.014993 0.5261957,0.1030872 0.244915,0.1202744 0.4888197,0.3695439 0.6027014,0.6159576 0.079998,0.1730976 0.080499,0.1905559 0.09901,3.448397 0.020472,3.6031325 0.00418,3.3665775 0.2478407,3.5980265 0.2810043,0.266918 0.6822132,0.283308 1.0083162,0.04119 0.232339,-0.172501 0.25913,-0.280173 0.275933,-1.1089849 0.01456,-0.7180841 0.01869,-0.7520168 0.117805,-0.9674419 0.454637,-0.9881395 1.789759,-0.9881395 2.244396,0 0.09912,0.2154251 0.103248,0.2493578 0.117805,0.9674419 0.0168,0.8288119 0.04359,0.9364839 0.275933,1.1089849 0.326103,0.242117 0.727312,0.225727 1.008316,-0.04119 0.160426,-0.152384 0.218977,-0.294978 0.250819,-0.610832 C 14.845142,9.2502593 15.336916,8.7840275 16,8.7840275 c 0.478554,0 0.847992,0.2240614 1.082489,0.6565225 l 0.126813,0.2338686 0.01869,0.7813954 c 0.02069,0.865066 0.03258,0.913549 0.276595,1.127795 0.239244,0.210059 0.56665,0.239738 0.88018,0.07979 0.219744,-0.112104 0.324993,-0.301479 0.383515,-0.690054 0.06437,-0.427406 0.125794,-0.56694 0.357358,-0.811785 C 19.38604,9.8862229 19.614832,9.7882106 20,9.7869898 c 0.380153,-0.0012 0.636641,0.1145641 0.905451,0.4086842 0.318537,0.348531 0.317259,0.340596 0.332734,2.064791 0.02055,2.290001 -0.04576,2.983129 -0.383655,4.009983 -0.878739,2.670467 -3.284504,4.613238 -6.090273,4.918188 -0.322415,0.03504 -3.227312,0.04717 -3.564257,0.01488 z" id="path6" /> <path style="fill:#ffffff;stroke-width:0.0705053;stroke-linejoin:round;paint-order:stroke fill markers" d="m 11.942854,21.190957 c -1.015003,-0.01704 -1.131723,-0.02688 -1.806535,-0.1522 C 9.5352183,20.927122 8.8225664,20.681951 8.319624,20.413766 7.7570149,20.113766 7.3758537,19.827607 6.7836127,19.260598 5.774345,18.294328 3.1746828,15.68636 2.994305,15.459184 2.7288345,15.124838 2.6970674,15.049109 2.7026798,14.763988 c 0.00827,-0.420163 0.1162058,-0.679868 0.3844475,-0.925026 0.2382303,-0.217729 0.416008,-0.293073 0.7303102,-0.309513 0.5101451,-0.02668 0.6329728,0.04799 1.5378542,0.934977 0.8479274,0.831158 1.2429087,1.199656 1.342282,1.252283 0.11819,0.06259 0.4442817,0.06081 0.6122724,-0.0033 0.1482348,-0.05661 0.3410696,-0.248342 0.4107195,-0.408368 0.063024,-0.144802 0.06179,-0.498 -0.00216,-0.618376 C 7.6917315,14.63641 7.4736023,14.388937 7.2336742,14.136678 L 6.797441,13.678026 6.7970753,8.6903755 6.7967098,3.7027253 6.9021002,3.502167 C 7.0320375,3.2548956 7.2343175,3.0487286 7.4743519,2.9189189 c 0.1797064,-0.097185 0.1877434,-0.098707 0.5209477,-0.098707 0.3169743,0 0.349151,0.00524 0.5076381,0.082665 0.2190605,0.1070166 0.4871239,0.3748528 0.5931342,0.592632 l 0.081613,0.1676584 0.019992,1.3834579 c 0.010995,0.7609018 0.021403,2.0560783 0.023128,2.87817 0.00341,1.6233162 0.028863,2.2876938 0.093598,2.4426258 0.089047,0.213119 0.4255042,0.419889 0.683247,0.419889 0.1563141,0 0.3731941,-0.08265 0.5187231,-0.197689 0.205546,-0.162474 0.225694,-0.250142 0.256177,-1.1146856 C 10.79418,8.8613623 10.8052,8.7492253 10.85668,8.6186115 11.053264,8.1198873 11.50183,7.7978848 12,7.7978848 c 0.49817,0 0.946736,0.3220025 1.143315,0.8207259 0.05148,0.1306138 0.0625,0.2427508 0.08413,0.8563239 0.02897,0.8216044 0.05497,0.9507864 0.218548,1.0859664 0.341252,0.282005 0.756809,0.293493 1.057036,0.02922 0.169206,-0.148941 0.234219,-0.2921 0.288276,-0.6347773 0.103115,-0.6536616 0.472737,-1.0621772 1.030077,-1.1384664 0.547738,-0.074975 0.986339,0.1608863 1.276145,0.6862578 l 0.105758,0.1917223 7.68e-4,0.3699606 c 0.0011,0.553623 0.04553,1.179579 0.09141,1.289176 0.04428,0.105777 0.219161,0.276182 0.364423,0.355092 0.06913,0.03755 0.155512,0.05067 0.333059,0.05055 0.204058,-1.3e-4 0.260695,-0.01118 0.380729,-0.07426 0.239564,-0.12591 0.320531,-0.265583 0.407786,-0.703455 0.08382,-0.420648 0.125337,-0.527172 0.279883,-0.718174 0.321102,-0.3968443 0.77117,-0.5469022 1.259123,-0.4198065 0.21344,0.055594 0.39756,0.1739295 0.578279,0.3716645 0.286251,0.313205 0.299377,0.389392 0.324444,1.883099 0.02888,1.721047 -0.03379,2.808669 -0.20314,3.525265 -0.307591,1.301561 -0.970113,2.493177 -1.91312,3.440943 -1.060413,1.065767 -2.34115,1.742909 -3.849589,2.035329 -0.348478,0.06755 -0.462014,0.07524 -1.340342,0.09078 -0.527787,0.0093 -1.416154,0.0093 -1.974148,-6.4e-5 z" id="path7" /> </svg>'});class Ah{static _pointerCursor=null;static getPointerCursor(){return this._pointerCursor||(this._pointerCursor=this.getCursor({iconName:"pointer"})),this._pointerCursor}static getCursor(t){const e="default"===t.iconName?"mouse-pointer":t.iconName,i=kh.get(e);if(!i)return console.warn(`Icon "${e}" not found in registry.`),"auto";const s=t.size||24,n=t.rotation||0,r=t.color||"black",h=t.hotspot||("default"===t.iconName?{x:4,y:4}:{x:s/2,y:s/2});let o=i.replace(/width="\d+"/,`width="${s}"`).replace(/height="\d+"/,`height="${s}"`).replace(/currentColor/g,r);const l=s/2;return`url('data:image/svg+xml;charset=utf-8,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${s}" viewBox="0 0 ${s} ${s}">\n <g transform="rotate(${n} ${l} ${l})">\n ${o}\n </g>\n </svg>\n `.replace(/\s+/g," ").trim()).replace(/'/g,"%27").replace(/"/g,"%22")}') ${h.x} ${h.y}, auto`}}class xh{_core;constructor(t){this._core=t}}class Sh extends xh{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(Ur.isLeftClick(t)){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=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;this._core.store.state.isDragging=!0,this.dragStartX=e,this.dragStartY=i,this.startX=this.dragStartX,this.startY=this.dragStartY,this.initialDragX=e,this.initialDragY=i,this.disconnectedLineIds.clear(),this.trackedPointerId=t.pointerId}}else this.trackedPointerId=null;if("touch"===t.pointerType){const e=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 i=this._core.store.selectionGroup;if(!i?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected)this.trackedPointerId=null;else{const i=Math.round(e[0].clientX-this._core.store.offsetX),s=Math.round(e[0].clientY-this._core.store.offsetY);this.dragStartX=i,this.dragStartY=s,this.startX=i,this.startY=s,this.initialDragX=i,this.initialDragY=s,this.disconnectedLineIds.clear(),this.trackedPointerId=t.pointerId}}}}handlePointerMove(t){if(null!==this.trackedPointerId&&this.trackedPointerId===t.pointerId){if("mouse"===t.pointerType){const e=this._core.store.selectionGroup;if(this._core.store.state.isDragging&&e){const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this.endX=i,this.endY=s;const n=Math.abs(i-this.startX),r=Math.abs(s-this.startY),h=5;(n>h||r>h)&&(this.checkAndDisconnectAnchors(i,s),e.move(i,s,this.dragStartX,this.dragStartY),this.dragStartX=i,this.dragStartY=s,this.hasMoved=!0)}}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),e=this._core.store.selectionGroup;if(1===this._core.store.state.pointers.size&&e&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected&&!this._core.store.state.isScaling){const i=Math.round(t[0].clientX-this._core.store.offsetX),s=Math.round(t[0].clientY-this._core.store.offsetY);this._core.store.state.isDragging=!0,this.endX=i,this.endY=s;const n=Math.abs(i-this.startX),r=Math.abs(s-this.startY),h=5;(n>h||r>h)&&(clearTimeout(this._core.store.state.longTouchTimeout),this.checkAndDisconnectAnchors(i,s),e.move(i,s,this.dragStartX,this.dragStartY),this.dragStartX=i,this.dragStartY=s,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,e){const i=t-this.initialDragX,s=e-this.initialDragY;if(Math.sqrt(i*i+s*s)<30)return;const n=this._core.store.selectionGroup;if(n&&n.objects.every((t=>t instanceof Rr)))for(const t of n.objects)if(!this.disconnectedLineIds.has(t.id)&&t instanceof Rr){const e=t;(e.startAnchor||e.endAnchor)&&(e.startAnchor&&this._core.anchorManager.removeAnchor(e.id,"start"),e.endAnchor&&this._core.anchorManager.removeAnchor(e.id,"end"),this.disconnectedLineIds.add(e.id),this._core.store.state.objects.update(e))}}}var Ch,Oh;!function(t){t.TopLeft="top-left",t.TopRight="top-right",t.BottomLeft="bottom-left",t.BottomRight="bottom-right"}(Ch||(Ch={}));class Eh extends xh{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&&Ur.isLeftClick(t)){const e=this._core.store.selectionGroup;if(e&&this._core.store.state.isResizeHandleSelected){const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isResizing=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialSize.width=e.width,this.initialSize.height=e.height,this.initialSize.x=e.translateX,this.initialSize.y=e.translateY}}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),e=t[0];if(!e)return;if(1===t.length){const t=this._core.store.selectionGroup;if(t&&this._core.store.state.isResizeHandleSelected){const i=Math.round(e.clientX-this._core.store.offsetX),s=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isResizing=!0,this.initialMouseX=i,this.initialMouseY=s,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 e=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&e){const i=t.clientX-this._core.store.offsetX-this.initialMouseX,s=t.clientY-this._core.store.offsetY-this.initialMouseY,n=Math.abs(i),r=Math.abs(s),h=5;if((n>h||r>h)&&(this.hasResized=!0),!this.hasResized)return;const o=e.rotation,l=Math.sin(o),u=Math.cos(o),a=e.scale||1,c=this._core.store.state.scale,f=(i*u+s*l)/c,d=(-i*l+s*u)/c,p=this.initialSize.x+this.initialSize.width/a/2+i/c/2,w=this.initialSize.y+this.initialSize.height/a/2+s/c/2;switch(this._core.store.state.resizeHandleType){case Ch.TopLeft:this.newSize.width=this.initialSize.width-f*a,this.newSize.height=this.initialSize.height-d*a;break;case Ch.TopRight:this.newSize.width=this.initialSize.width+f*a,this.newSize.height=this.initialSize.height-d*a;break;case Ch.BottomLeft:this.newSize.width=this.initialSize.width-f*a,this.newSize.height=this.initialSize.height+d*a;break;case Ch.BottomRight:this.newSize.width=this.initialSize.width+f*a,this.newSize.height=this.initialSize.height+d*a}this.newSize.x=p-this.newSize.width/a/2,this.newSize.y=w-this.newSize.height/a/2,e.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 e=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&e){const i=Math.round(t.clientX-this._core.store.offsetX),s=Math.round(t.clientY-this._core.store.offsetY),n=i-this.initialMouseX,r=s-this.initialMouseY,h=Math.abs(n),o=Math.abs(r),l=5;if((h>l||o>l)&&(clearTimeout(this._core.store.state.longTouchTimeout),this.hasResized=!0),!this.hasResized)return;const u=e.rotation,a=Math.sin(u),c=Math.cos(u),f=e.scale||1,d=this._core.store.state.scale,p=(n*c+r*a)/d,w=(-n*a+r*c)/d,g=this.initialSize.x+this.initialSize.width/f/2+n/d/2,m=this.initialSize.y+this.initialSize.height/f/2+r/d/2;switch(this._core.store.state.resizeHandleType){case Ch.TopLeft:this.newSize.width=this.initialSize.width-p*f,this.newSize.height=this.initialSize.height-w*f;break;case Ch.TopRight:this.newSize.width=this.initialSize.width+p*f,this.newSize.height=this.initialSize.height-w*f;break;case Ch.BottomLeft:this.newSize.width=this.initialSize.width-p*f,this.newSize.height=this.initialSize.height+w*f;break;case Ch.BottomRight:this.newSize.width=this.initialSize.width+p*f,this.newSize.height=this.initialSize.height+w*f}this.newSize.x=g-this.newSize.width/f/2,this.newSize.y=m-this.newSize.height/f/2,e.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 Th extends xh{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&&Ur.isLeftClick(t)){const e=this._core.store.selectionGroup;if(e&&this._core.store.state.isRotationHandleSelected){e.beginTransform();const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isRotating=!0;const n=e.scale||1,r=e.translateX+e.width/2/n,h=e.translateY+e.height/2/n,o=(i-this._core.store.state.translateX)/this._core.store.state.scale,l=(s-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=e.rotation,this.initialRotation=Math.atan2(h-l,r-o)-e.rotation,this.unchangedObjects=e.objects.map((t=>t.clone()))}}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values()),e=t[0];if(!e)return;if(1===t.length){const t=this._core.store.selectionGroup;if(t&&this._core.store.state.isRotationHandleSelected){t.beginTransform();const i=Math.round(e.clientX-this._core.store.offsetX),s=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isRotating=!0;const n=t.scale||1,r=t.translateX+t.width/2/n,h=t.translateY+t.height/2/n,o=(i-this._core.store.state.translateX)/this._core.store.state.scale,l=(s-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=t.rotation,this.initialRotation=Math.atan2(h-l,r-o)-t.rotation,this.unchangedObjects=t.objects.map((t=>t.clone())),clearTimeout(this._core.store.state.longTouchTimeout)}}}}handlePointerMove(t){if("mouse"===t.pointerType){const e=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&e){const i=e.scale||1,s=Math.atan2(e.translateY+e.height/2/i-(t.clientY-this._core.store.offsetY-this._core.store.state.translateY)/this._core.store.state.scale,e.translateX+e.width/2/i-(t.clientX-this._core.store.offsetX-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=s-this.initialRotation,e.rotate(this.rotation)}}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values())[0];if(!t)return;const e=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&e){const i=Math.round(t.clientX-this._core.store.offsetX),s=Math.round(t.clientY-this._core.store.offsetY),n=e.scale||1,r=Math.atan2(e.translateY+e.height/2/n-(s-this._core.store.state.translateY)/this._core.store.state.scale,e.translateX+e.width/2/n-(i-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=r-this.initialRotation,e.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 Dh extends s{__class__="KritzelSelectionBox";static create(t){const e=new Dh;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.scale=t.store.state.scale,e.zIndex=99999,e.backgroundColor="var(--kritzel-selection-box-background-color, rgba(0, 122, 255, 0.2))",e.borderColor="var(--kritzel-selection-box-border-color, rgba(0, 122, 255, 0.5))",e.borderWidth=2,e.height=0,e.width=0,e}}class $h extends xh{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&&Ur.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()),e=Math.round(t[0].clientX-this._core.store.offsetX),i=Math.round(t[0].clientY-this._core.store.offsetY),s=Math.abs(e-this.touchStartX),n=Math.abs(i-this.touchStartY),r=5;(s>r||n>r)&&this._core.store.state.isSelecting&&(this.updateTouchSelection(),clearTimeout(this._core.store.state.longTouchTimeout))}}handlePointerUp(t){if("mouse"===t.pointerType&&Ur.isLeftClick(t)){const e=this._core.store.state.hasObjectsChanged,i=this._core.store.selectionGroup;1===i?.objects.length&&!1===e&&i.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 e=this._core.store.state.hasObjectsChanged,i=this._core.store.selectionGroup;1===i?.objects.length&&!1===e&&i.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 Dh))}startMouseSelection(t){let e,i;e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;const s=Dh.create(this._core);this.startX=(e-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(i-this._core.store.state.translateY)/this._core.store.state.scale,s.translateX=this.startX,s.translateY=this.startY,this._core.store.state.isSelecting=!0,this._core.store.state.objects.remove((t=>t instanceof Dh||t instanceof Nr)),this._core.store.state.objects.insert(s)}startTouchSelection(){const t=Array.from(this._core.store.state.pointers.values())[0];if(!t)return;let e,i;e=Math.round(t.clientX-this._core.store.offsetX),i=Math.round(t.clientY-this._core.store.offsetY),this.touchStartX=e,this.touchStartY=i;const s=Dh.create(this._core);this.startX=(e-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(i-this._core.store.state.translateY)/this._core.store.state.scale,s.translateX=this.startX,s.translateY=this.startY,this._core.store.state.isSelecting=!0,this._core.store.state.objects.remove((t=>t instanceof Dh||t instanceof Nr)),this._core.store.state.objects.insert(s)}updateMouseSelection(t){let e,i;e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;const s=this._core.store.selectionBox;if(s){const t=(e-this._core.store.state.translateX)/s.scale,n=(i-this._core.store.state.translateY)/s.scale,r=Math.abs(t-this.startX)*s.scale,h=Math.abs(n-this.startY)*s.scale;s.width=r,s.height=h,s.translateX=Math.min(t,this.startX),s.translateY=Math.min(n,this.startY),r>0||h>0?this.updateSelectedObjects():this.clearSelectionPreview()}}updateTouchSelection(){const t=Array.from(this._core.store.state.pointers.values())[0];if(!t)return;let e,i;e=Math.round(t.clientX-this._core.store.offsetX),i=Math.round(t.clientY-this._core.store.offsetY);const s=this._core.store.selectionBox;if(s){const t=(e-this._core.store.state.translateX)/s.scale,n=(i-this._core.store.state.translateY)/s.scale,r=Math.abs(t-this.startX)*s.scale,h=Math.abs(n-this.startY)*s.scale;s.width=r,s.height=h,s.translateX=Math.min(t,this.startX),s.translateY=Math.min(n,this.startY),r>0||h>0?this.updateSelectedObjects():this.clearSelectionPreview()}}updateSelectedObjects(){const t=this._core.store.selectionBox;t&&this._core.store.allObjects.filter((t=>!(t instanceof Dh))).forEach((e=>e.isSelected=e.hitTestPolygon(t.rotatedPolygon)))}handleSelectionClick(t){const e=this.getTopmostHitObject(t);this.clearSelectionPreview(),this.addObjectToSelectionGroup(e),this.removeSelectionBox()}getTopmostHitObject(t){const e=this._core.store.state.pointerX,i=this._core.store.state.pointerY,s=this._core.getObjectsFromPointerEvent(t,".object");for(const t of s)if(t.hitTest(e,i))return t;return null}clearSelectionPreview(){this._core.store.allNonSelectionObjects.forEach((t=>{t.isSelected=!1}))}addObjectToSelectionGroup(t){if(!t)return;const e=Ir.findParentGroup(this._core,t.id)||t;e.isSelected=!1;const i=Nr.create(this._core);i.addOrRemove(e),i.isSelected=!0,i.rotation=e.rotation,this._core.addSelectionGroup(i),this._core.rerender()}addSelectedObjectsToSelectionGroup(){const t=this._core.store.selectedObjects;if(0===t.length)return;const e=new Map;t.forEach((t=>{const i=Ir.findParentGroup(this._core,t.id);i?e.set(i.id,i):e.set(t.id,t),t.isSelected=!1}));const i=Nr.create(this._core);e.forEach((t=>{i.addOrRemove(t)})),i.isSelected=!0,1===i.length&&(i.rotation=i.objects[0].rotation),this._core.addSelectionGroup(i),this._core.rerender()}}class Ph extends xh{constructor(t){super(t)}handlePointerMove(t){if("mouse"===t.pointerType){const e=this._core.getObjectFromPointerEvent(t,".object");if(!e)return;e.isHovered=e.hitTest(this._core.store.state.pointerX,this._core.store.state.pointerY)}}}class Rh extends xh{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&&Ur.isLeftClick(t)&&this.startHandleDrag(t),"touch"===t.pointerType&&1===Array.from(this._core.store.state.pointers.values()).length&&this.startHandleDrag(t)}startHandleDrag(t){const e=this.getSelectedLine();if(!e||!this._core.store.state.isLineHandleSelected)return;const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isLineHandleDragging=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialStartX=e.startX,this.initialStartY=e.startY,this.initialEndX=e.endX,this.initialEndY=e.endY,this.initialControlX=e.controlX,this.initialControlY=e.controlY,this.initialTranslateX=e.translateX,this.initialTranslateY=e.translateY;const n=this._core.store.state.lineHandleType;"start"!==n&&"end"!==n||this._core.anchorManager.removeAnchor(e.id,n),clearTimeout(this._core.store.state.longTouchTimeout)}handlePointerMove(t){const e=this.getSelectedLine();if(!e||!this._core.store.state.isLineHandleDragging)return;const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY,n=i-this.initialMouseX,r=s-this.initialMouseY;if((Math.abs(n)>3||Math.abs(r)>3)&&(this.hasMoved=!0),!this.hasMoved)return;const h=this._core.store.state.scale,o=e.scale||1,l=e.rotation,u=n/h,a=r/h,c=Math.cos(-l),f=Math.sin(-l),d=(u*c-a*f)*o,p=(u*f+a*c)*o,w=this._core.store.state.lineHandleType;if("start"===w){const t=(i-this._core.store.state.translateX)/h,n=(s-this._core.store.state.translateY)/h,r=e.endAnchor?.objectId,o=this._core.anchorManager.findSnapTarget(t,n,e.id,r);if(this.currentSnapTarget=o,o){const t=this.worldToLineLocal(e,o.centerX,o.centerY);this.updateLineEndpoint(e,t.x,t.y,this.initialEndX,this.initialEndY);const i=this.lineLocalToWorld(e,this.initialEndX,this.initialEndY),s=this._core.store.allNonSelectionObjects.find((t=>t.id===o.objectId));let n,r,h,l;if(s){const t=this._core.anchorManager.computeAnchorClipInfo(e,"start",s);t&&(n=t.worldX,r=t.worldY,h=t.t)}void 0!==e.controlX&&void 0!==e.controlY&&(l=this.lineLocalToWorld(e,e.controlX,e.controlY)),this._core.anchorManager.setSnapCandidate({objectId:o.objectId,endpoint:"start",centerX:o.centerX,centerY:o.centerY,lineEndpointX:i.x,lineEndpointY:i.y,controlX:l?.x,controlY:l?.y,t:h,edgeX:n,edgeY:r,lineStroke:e.stroke,lineStrokeWidth:e.strokeWidth/e.scale,arrowOffset:e.hasStartArrow?e.getArrowSize("start")/e.scale:void 0,arrowStyle:e.hasStartArrow?e.arrows?.start?.style:void 0,arrowFill:e.hasStartArrow?e.getArrowFill("start"):void 0})}else this.updateLineEndpoint(e,this.initialStartX+d,this.initialStartY+p,this.initialEndX,this.initialEndY),this._core.anchorManager.clearSnapCandidate()}else if("end"===w){const t=(i-this._core.store.state.translateX)/h,n=(s-this._core.store.state.translateY)/h,r=e.startAnchor?.objectId,o=this._core.anchorManager.findSnapTarget(t,n,e.id,r);if(this.currentSnapTarget=o,o){const t=this.worldToLineLocal(e,o.centerX,o.centerY);this.updateLineEndpoint(e,this.initialStartX,this.initialStartY,t.x,t.y);const i=this.lineLocalToWorld(e,this.initialStartX,this.initialStartY),s=this._core.store.allNonSelectionObjects.find((t=>t.id===o.objectId));let n,r,h,l;if(s){const t=this._core.anchorManager.computeAnchorClipInfo(e,"end",s);t&&(n=t.worldX,r=t.worldY,h=t.t)}void 0!==e.controlX&&void 0!==e.controlY&&(l=this.lineLocalToWorld(e,e.controlX,e.controlY)),this._core.anchorManager.setSnapCandidate({objectId:o.objectId,endpoint:"end",centerX:o.centerX,centerY:o.centerY,lineEndpointX:i.x,lineEndpointY:i.y,controlX:l?.x,controlY:l?.y,t:h,edgeX:n,edgeY:r,lineStroke:e.stroke,lineStrokeWidth:e.strokeWidth/e.scale,arrowOffset:e.hasEndArrow?e.getArrowSize("end")/e.scale:void 0,arrowStyle:e.hasEndArrow?e.arrows?.end?.style:void 0,arrowFill:e.hasEndArrow?e.getArrowFill("end"):void 0})}else this.updateLineEndpoint(e,this.initialStartX,this.initialStartY,this.initialEndX+d,this.initialEndY+p),this._core.anchorManager.clearSnapCandidate()}else if("center"===w){const t=(this.initialControlX??(this.initialStartX+this.initialEndX)/2)+2*d,i=(this.initialControlY??(this.initialStartY+this.initialEndY)/2)+2*p,s=e.startX,n=e.startY,r=e.endX,h=e.endY,o=r-s,l=h-n,u=o*o+l*l;let a,c,f=-1;0!==u&&(f=((t-s)*o+(i-n)*l)/u),f<0?(a=s,c=n):f>1?(a=r,c=h):(a=s+f*o,c=n+f*l);const w=t-a,g=i-c;Math.sqrt(w*w+g*g)<15?e.updateControlPoint(void 0,void 0):e.updateControlPoint(t,i)}this._core.rerender()}worldToLineLocal(t,e,i){const s=(e-t.translateX)*t.scale,n=(i-t.translateY)*t.scale,r=t.totalWidth/2,h=t.totalHeight/2,o=Math.cos(-t.rotation),l=Math.sin(-t.rotation);return{x:(s-r)*o-(n-h)*l+r+t.x,y:(s-r)*l+(n-h)*o+h+t.y}}lineLocalToWorld(t,e,i){const s=e-t.x,n=i-t.y,r=t.totalWidth/2,h=t.totalHeight/2,o=Math.cos(t.rotation),l=Math.sin(t.rotation);return{x:((s-r)*o-(n-h)*l+r)/t.scale+t.translateX,y:((s-r)*l+(n-h)*o+h)/t.scale+t.translateY}}updateLineEndpoint(t,e,i,s,n){const{minX:r,minY:h,maxX:o,maxY:l}=Rr.calculateBoundingBox(e,i,s,n,t.controlX,t.controlY,t.strokeWidth),u=o-r,a=l-h,{minX:c,minY:f,maxX:d,maxY:p}=Rr.calculateBoundingBox(this.initialStartX,this.initialStartY,this.initialEndX,this.initialEndY,this.initialControlX,this.initialControlY,t.strokeWidth),w=d-c,g=p-f,m=r-c+(u-w)/2,y=h-f+(a-g)/2,v=t.rotation,b=Math.cos(v),M=Math.sin(v),k=1/t.scale,A=this.initialTranslateX+k*(w-u)/2+k*(m*b-y*M),x=this.initialTranslateY+k*(g-a)/2+k*(m*M+y*b);t.startX=e,t.startY=i,t.endX=s,t.endY=n,t.x=r,t.y=h,t.width=u,t.height=a,t.translateX=A,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(),e=this._core.store.state.lineHandleType;if(t&&this.hasMoved){!this.currentSnapTarget||"start"!==e&&"end"!==e||this._core.anchorManager.setAnchor(t.id,e,this.currentSnapTarget.objectId);const i=this._core.store.selectionGroup;i&&(i.refreshObjectDimensions(),i.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 e=t.objects[0];return e instanceof Rr?e:null}}!function(t){t.Rectangle="rectangle",t.Ellipse="ellipse",t.Triangle="triangle"}(Oh||(Oh={}));class Ih extends s{__class__="KritzelShape";shapeType=Oh.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 G({nodes:qn(Yn.spec.nodes,"paragraph block*","block"),marks:Yn.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??Oh.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,e){const i=new Ih;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.x=e?.x??0,i.y=e?.y??0,i.translateX=e?.translateX??0,i.translateY=e?.translateY??0,i.width=e?.width??100,i.height=e?.height??100,i.shapeType=e?.shapeType??Oh.Rectangle,i.fillColor=e?.fillColor??"transparent",i.strokeColor=e?.strokeColor??"#000000",i.strokeWidth=e?.strokeWidth??4,i.opacity=e?.opacity??1,i.fontSize=e?.fontSize??16,i.fontFamily=e?.fontFamily??"Arial",i.fontColor=e?.fontColor??"#000000",i.backgroundColor="transparent",i.scaleFactor=1,i.scale=t.store.state.scale,i.zIndex=t.store.currentZIndex,i.editor=i.createEditor(),i.updateDimensions(),i}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 On(null,{state:ge.create({doc:t,plugins:[lr(xr)]}),editable:()=>!1,dispatchTransaction:t=>{const e=this.editor.state.apply(t);this.editor.updateState(e),t.docChanged&&(this.content=e.doc.toJSON(),t.getMeta("fromRemote")||this._core.store.state.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const e=this.editor.state.schema.nodeFromJSON(t),i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",!0),this.editor.dispatch(i)}}resize(t,e,i,s){i<=1||s<=1||(this.width=i,this.height=s,this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this))}focus(t){if(this.editor){const e=this.editor.state.doc;if(t?.x&&t?.y){const i=this.editor.posAtCoords({left:t.x,top:t.y});if(i)return this.editor.dispatch(this.editor.state.tr.setSelection(se.create(e,i.pos))),this.editor.focus(),void(r.isIOS()&&this.scrollIntoViewOnIOS())}const i=Math.max(1,e.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(se.create(e,i))),this.editor.focus(),r.isIOS()&&this.scrollIntoViewOnIOS()}}scrollIntoViewOnIOS(){setTimeout((()=>{this.editor&&this.editor.dom&&this.editor.dom.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"})}),300)}edit(e){n.disableInteractiveWidget(),this.uneditedObject=this.clone(),this._core.store.setState("activeTool",t.getTool("shape")),this.editor.setProps({editable:()=>!0}),this.isEditing=!0,this._core.rerender(),this.focus({x:e?.clientX,y:e?.clientY}),n.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:e,_schema:i,element:s,totalWidth:n,totalHeight:r,editor:h,uneditedObject:o,...l}=this,u=structuredClone(l);return s&&"object"==typeof s&&"nodeType"in s&&1===s.nodeType&&(u.element=s.cloneNode(!0)),u}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}getClipPolygon(){const t=this.totalWidth/this.scale,e=this.totalHeight/this.scale,s=this.translateX+t/2,n=this.translateY+e/2,r=this.strokeWidth/this.scale/2;switch(this.shapeType){case Oh.Ellipse:return i.getEllipsePolygonApproximation(s,n,t/2+r,e/2+r,32,this.rotation);case Oh.Triangle:const h=(t,e)=>{const i=t-s,h=e-n,o=Math.sqrt(i*i+h*h);if(0===o)return{x:t,y:e};const l=(o+r)/o;return{x:s+i*l,y:n+h*l}},o=this.translateX,l=this.translateY+e,u=this.translateX+t,a=this.translateY+e,c=h(this.translateX+t/2,this.translateY),f=h(u,a),d=h(o,l);if(0!==this.rotation){const t=Math.cos(this.rotation),e=Math.sin(this.rotation),i=i=>{const r=i.x-s,h=i.y-n;return{x:s+r*t-h*e,y:n+r*e+h*t}};return[i(c),i(f),i(d)]}return[c,f,d];default:return null}}getSvgPath(){const t=this.width,e=this.height;switch(this.shapeType){case Oh.Rectangle:return`M ${this.x} ${this.y} L ${this.x+t} ${this.y} L ${this.x+t} ${this.y+e} L ${this.x} ${this.y+e} Z`;case Oh.Ellipse:const i=this.x+t/2,s=this.y+e/2,n=t/2,r=e/2;return`M ${i-n} ${s} A ${n} ${r} 0 1 0 ${i+n} ${s} A ${n} ${r} 0 1 0 ${i-n} ${s}`;case Oh.Triangle:return`M ${this.x+t/2} ${this.y} L ${this.x+t} ${this.y+e} L ${this.x} ${this.y+e} Z`;default:return`M ${this.x} ${this.y} L ${this.x+t} ${this.y} L ${this.x+t} ${this.y+e} L ${this.x} ${this.y+e} Z`}}}const Uh=["#000000","#ff5252","#ffbc00","#00c853","#0000FF","#d500f9","#fafafa","#a52714","#ee8100","#558b2f","#01579b","#8e24aa","#90a4ae","#ff4081","#ff6e40","#aeea00","#304ffe","#7c4dff","#cfd8dc","#f8bbd0","#ffccbc","#f0f4c3","#9fa8da","#d1c4e9"];class jh extends jr{selectionHandler;moveHandler;hoverHandler;resizeHandler;rotationHandler;lineHandleHandler;palette=[...Uh];hasSelection(){return!!this._core.store.selectionGroup&&this._core.store.selectionGroup.objects.length>0}getSelectedObjects(){return this._core.store.selectionGroup?.objects??[]}flattenObjects(t){let e=[];for(const i of t)i instanceof Ir?e=e.concat(this.flattenObjects(i.children)):e.push(i);return e}get color(){const t=this.flattenObjects(this.getSelectedObjects());if(0===t.length)return"#000000";for(const e of t){if(e instanceof $r)return e.fill;if(e instanceof Rr)return e.stroke;if(e instanceof Sr)return e.fontColor;if(e instanceof Ih)return e.strokeColor}return"#000000"}set color(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof $r&&this._core.updateObject(e,{fill:t}),e instanceof Rr&&this._core.updateObject(e,{stroke:t}),e instanceof Sr&&this._core.updateObject(e,{fontColor:t}),e instanceof Ih&&this._core.updateObject(e,{strokeColor:t})})),this._core.rerender()}get opacity(){const t=this.flattenObjects(this.getSelectedObjects());return 0===t.length?1:t[0].opacity}set opacity(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>this._core.updateObject(e,{opacity:t}))),this._core.rerender()}get size(){const t=this.flattenObjects(this.getSelectedObjects());if(0===t.length)return 1;for(const e of t){if(e instanceof $r)return e.strokeWidth;if(e instanceof Rr)return e.strokeWidth;if(e instanceof Sr)return e.fontSize;if(e instanceof Ih)return e.strokeWidth}return 1}set size(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof $r&&this._core.updateObject(e,{strokeWidth:t}),e instanceof Rr&&this._core.updateObject(e,{strokeWidth:t}),e instanceof Sr&&this._core.updateObject(e,{fontSize:t}),e instanceof Ih&&this._core.updateObject(e,{strokeWidth:t})})),this._core.rerender()}get fillColor(){const t=this.flattenObjects(this.getSelectedObjects());for(const e of t)if(e instanceof Ih)return e.fillColor;return"transparent"}set fillColor(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Ih&&(this._core.updateObject(e,{fillColor:t}),"transparent"!==t&&this._core.updateObject(e,{strokeColor:t}))})),this._core.rerender()}get fontFamily(){const t=this.flattenObjects(this.getSelectedObjects());for(const e of t){if(e instanceof Sr)return e.fontFamily;if(e instanceof Ih)return e.fontFamily}return"Arial"}set fontFamily(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Sr&&this._core.updateObject(e,{fontFamily:t}),e instanceof Ih&&this._core.updateObject(e,{fontFamily:t})})),this._core.rerender()}get arrows(){const t=this.flattenObjects(this.getSelectedObjects());for(const e of t)if(e instanceof Rr)return e.arrows;return{start:{enabled:!1},end:{enabled:!1}}}set arrows(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Rr&&this._core.updateObject(e,{arrows:t})})),this._core.rerender()}getToolConfig(){if(!this.hasSelection())return null;const t=this.flattenObjects(this.getSelectedObjects()),e=[],i=t.some((t=>t instanceof Ih)),s=t.some((t=>t instanceof Sr)),n=t.some((t=>t instanceof Rr)),r=t.some((t=>t instanceof $r||t instanceof Rr||t instanceof Ih));return s&&!r?(e.push({type:"font-size",propertyName:"size"}),e.push({type:"font-family",propertyName:"fontFamily"})):r&&!s?e.push({type:"stroke-size",propertyName:"size"}):(r&&e.push({type:"stroke-size",propertyName:"size"}),s&&e.push({type:"font-family",propertyName:"fontFamily"})),n&&e.push({type:"line-endings",propertyName:"arrows"}),i&&e.push({type:"shape-fill",propertyName:"fillColor"}),{type:"selection",colorProperty:"color",sizeProperty:"size",opacityProperty:"opacity",paletteSource:"palette",controls:e}}constructor(t){super(t),this.selectionHandler=new $h(this._core),this.moveHandler=new Sh(this._core),this.hoverHandler=new Ph(this._core),this.resizeHandler=new Eh(this._core),this.rotationHandler=new Th(this._core),this.lineHandleHandler=new Rh(this._core)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){if(Ur.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 e=this.getSelectedObject(t),i=this._core.store.selectionGroup;if(null!==e&&!(e&&i&&e.id!==i.id)||!i||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||(this._core.removeSelectionGroup(),this._core.rerender()),e&&!1===e.isSelected&&1===e?.objects.length&&e.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 e=this.getSelectedObject(t),i=this._core.store.selectionGroup,s=e&&i&&e.id!==i.id;!i&&e&&(this._core.store.state.skipContextMenu=!0),null!==e&&!s||!i||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 e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),i=this._core.findObjectById(e?.id);if(!i)return null;const{x:s,y:n}=this._core.getCanvasPoint(t);if(!i.hitTest(s,n))return null;if(i instanceof Nr)return i;{const t=Nr.create(this._core);return t.translateX=0,t.translateY=0,t.addOrRemove(i),t}}getHandleType(t){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=e.elementsFromPoint(t.clientX,t.clientY).find((t=>t.classList.contains("resize-handle-overlay")));return i?.classList[1]}isHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;return!!e&&e.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("resize-handle-overlay")))}isRotationHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;return!!e&&e.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("rotation-handle-overlay")))}isLineHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;return!!e&&e.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("selection-line-handle-overlay")))}getLineHandleType(t){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=e.elementsFromPoint(t.clientX,t.clientY).find((t=>t.classList.contains("selection-line-handle-overlay")));return i?.classList[1]}}const Bh=()=>new Map,Nh=t=>{const e=Bh();return t.forEach(((t,i)=>{e.set(i,t)})),e},Fh=(t,e,i)=>{let s=t.get(e);return void 0===s&&t.set(e,s=i()),s},_h=()=>new Set,Lh=t=>t[t.length-1],zh=(t,e)=>{for(let i=0;i<e.length;i++)t.push(e[i])},Yh=Array.from,Wh=(t,e)=>{for(let i=0;i<t.length;i++)if(!e(t[i],i,t))return!1;return!0},Xh=(t,e)=>{for(let i=0;i<t.length;i++)if(e(t[i],i,t))return!0;return!1},Jh=Array.isArray;class Hh{constructor(){this._observers=Bh()}on(t,e){return Fh(this._observers,t,_h).add(e),e}once(t,e){const i=(...s)=>{this.off(t,i),e(...s)};this.on(t,i)}off(t,e){const i=this._observers.get(t);void 0!==i&&(i.delete(e),0===i.size&&this._observers.delete(t))}emit(t,e){return Yh((this._observers.get(t)||Bh()).values()).forEach((t=>t(...e)))}destroy(){this._observers=Bh()}}let Vh=class{constructor(){this._observers=Bh()}on(t,e){Fh(this._observers,t,_h).add(e)}once(t,e){const i=(...s)=>{this.off(t,i),e(...s)};this.on(t,i)}off(t,e){const i=this._observers.get(t);void 0!==i&&(i.delete(e),0===i.size&&this._observers.delete(t))}emit(t,e){return Yh((this._observers.get(t)||Bh()).values()).forEach((t=>t(...e)))}destroy(){this._observers=Bh()}};const Qh=Math.floor,Kh=Math.abs,qh=(t,e)=>t<e?t:e,Gh=(t,e)=>t>e?t:e,Zh=Math.pow,to=t=>0!==t?t<0:1/t<0,eo=64,io=128,so=127,no=Number.MAX_SAFE_INTEGER,ro=Number.MIN_SAFE_INTEGER,ho=Number.isInteger||(t=>"number"==typeof t&&isFinite(t)&&Qh(t)===t),oo=String.fromCharCode,lo=/^\s*/g,uo=/([A-Z])/g,ao=(t,e)=>(t=>t.replace(lo,""))(t.replace(uo,(t=>`${e}${(t=>t.toLowerCase())(t)}`))),co="undefined"!=typeof TextEncoder?new TextEncoder:null,fo=co?t=>co.encode(t):t=>{const e=unescape(encodeURIComponent(t)),i=e.length,s=new Uint8Array(i);for(let t=0;t<i;t++)s[t]=e.codePointAt(t);return s};let po="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});po&&1===po.decode(new Uint8Array).length&&(po=null);let wo=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}};const go=()=>new wo,mo=t=>{let e=t.cpos;for(let i=0;i<t.bufs.length;i++)e+=t.bufs[i].length;return e},yo=t=>{const e=new Uint8Array(mo(t));let i=0;for(let s=0;s<t.bufs.length;s++){const n=t.bufs[s];e.set(n,i),i+=n.length}return e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),i),e},vo=(t,e)=>{const i=t.cbuf.length;t.cpos===i&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*i),t.cpos=0),t.cbuf[t.cpos++]=e},bo=vo,Mo=(t,e)=>{for(;e>so;)vo(t,io|so&e),e=Qh(e/128);vo(t,so&e)},ko=(t,e)=>{const i=to(e);for(i&&(e=-e),vo(t,(e>63?io:0)|(i?eo:0)|63&e),e=Qh(e/64);e>0;)vo(t,(e>so?io:0)|so&e),e=Qh(e/128)},Ao=new Uint8Array(3e4),xo=Ao.length/3,So=co&&co.encodeInto?(t,e)=>{if(e.length<xo){const i=co.encodeInto(e,Ao).written||0;Mo(t,i);for(let e=0;e<i;e++)vo(t,Ao[e])}else Oo(t,fo(e))}:(t,e)=>{const i=unescape(encodeURIComponent(e)),s=i.length;Mo(t,s);for(let e=0;e<s;e++)vo(t,i.codePointAt(e))},Co=(t,e)=>{const i=t.cbuf.length,s=t.cpos,n=qh(i-s,e.length),r=e.length-n;t.cbuf.set(e.subarray(0,n),s),t.cpos+=n,r>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(Gh(2*i,r)),t.cbuf.set(e.subarray(n)),t.cpos=r)},Oo=(t,e)=>{Mo(t,e.byteLength),Co(t,e)},Eo=(t,e)=>{((t,e)=>{const i=t.cbuf.length;i-t.cpos<e&&(t.bufs.push(new Uint8Array(t.cbuf.buffer,0,t.cpos)),t.cbuf=new Uint8Array(2*Gh(i,e)),t.cpos=0)})(t,e);const i=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,i},To=new DataView(new ArrayBuffer(4)),Do=(t,e)=>{switch(typeof e){case"string":vo(t,119),So(t,e);break;case"number":ho(e)&&Kh(e)<=2147483647?(vo(t,125),ko(t,e)):(To.setFloat32(0,i=e),To.getFloat32(0)===i?(vo(t,124),((t,e)=>{Eo(t,4).setFloat32(0,e,!1)})(t,e)):(vo(t,123),((t,e)=>{Eo(t,8).setFloat64(0,e,!1)})(t,e)));break;case"bigint":vo(t,122),((t,e)=>{Eo(t,8).setBigInt64(0,e,!1)})(t,e);break;case"object":if(null===e)vo(t,126);else if(Jh(e)){vo(t,117),Mo(t,e.length);for(let i=0;i<e.length;i++)Do(t,e[i])}else if(e instanceof Uint8Array)vo(t,116),Oo(t,e);else{vo(t,118);const i=Object.keys(e);Mo(t,i.length);for(let s=0;s<i.length;s++){const n=i[s];So(t,n),Do(t,e[n])}}break;case"boolean":vo(t,e?120:121);break;default:vo(t,127)}var i};class $o extends wo{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&Mo(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const Po=t=>{t.count>0&&(ko(t.encoder,1===t.count?t.s:-t.s),t.count>1&&Mo(t.encoder,t.count-2))};class Ro{constructor(){this.encoder=new wo,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Po(this),this.count=1,this.s=t)}toUint8Array(){return Po(this),yo(this.encoder)}}const Io=t=>{t.count>0&&(ko(t.encoder,2*t.diff+(1===t.count?0:1)),t.count>1&&Mo(t.encoder,t.count-2))};class Uo{constructor(){this.encoder=new wo,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Io(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Io(this),yo(this.encoder)}}class jo{constructor(){this.sarr=[],this.s="",this.lensE=new Ro}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 wo;return this.sarr.push(this.s),this.s="",So(t,this.sarr.join("")),Co(t,this.lensE.toUint8Array()),yo(t)}}const Bo=t=>new Error(t),No=()=>{throw Bo("Method unimplemented")},Fo=()=>{throw Bo("Unexpected case")},_o=Bo("Unexpected end of array"),Lo=Bo("Integer out of Range");let zo=class{constructor(t){this.arr=t,this.pos=0}};const Yo=t=>new zo(t),Wo=t=>((t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,i})(t,Jo(t)),Xo=t=>t.arr[t.pos++],Jo=t=>{let e=0,i=1;const s=t.arr.length;for(;t.pos<s;){const s=t.arr[t.pos++];if(e+=(s&so)*i,i*=128,s<io)return e;if(e>no)throw Lo}throw _o},Ho=t=>{let e=t.arr[t.pos++],i=63&e,s=64;const n=(e&eo)>0?-1:1;if(!(e&io))return n*i;const r=t.arr.length;for(;t.pos<r;){if(e=t.arr[t.pos++],i+=(e&so)*s,s*=128,e<io)return n*i;if(i>no)throw Lo}throw _o},Vo=po?t=>po.decode(Wo(t)):t=>{let e=Jo(t);if(0===e)return"";{let i=String.fromCodePoint(Xo(t));if(--e<100)for(;e--;)i+=String.fromCodePoint(Xo(t));else for(;e>0;){const s=e<1e4?e:1e4,n=t.arr.subarray(t.pos,t.pos+s);t.pos+=s,i+=String.fromCodePoint.apply(null,n),e-=s}return decodeURIComponent(escape(i))}},Qo=(t,e)=>{const i=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,i},Ko=[()=>{},()=>null,Ho,t=>Qo(t,4).getFloat32(0,!1),t=>Qo(t,8).getFloat64(0,!1),t=>Qo(t,8).getBigInt64(0,!1),()=>!1,()=>!0,Vo,t=>{const e=Jo(t),i={};for(let s=0;s<e;s++)i[Vo(t)]=qo(t);return i},t=>{const e=Jo(t),i=[];for(let s=0;s<e;s++)i.push(qo(t));return i},Wo],qo=t=>Ko[127-Xo(t)](t);class Go extends zo{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return 0===this.count&&(this.s=this.reader(this),this.count=this.pos!==this.arr.length?Jo(this)+1:-1),this.count--,this.s}}class Zo extends zo{constructor(t){super(t),this.s=0,this.count=0}read(){if(0===this.count){this.s=Ho(this);const t=to(this.s);this.count=1,t&&(this.s=-this.s,this.count=Jo(this)+2)}return this.count--,this.s}}class tl extends zo{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const t=Ho(this),e=1&t;this.diff=Qh(t/2),this.count=1,e&&(this.count=Jo(this)+2)}return this.s+=this.diff,this.count--,this.s}}class el{constructor(t){this.decoder=new Zo(t),this.str=Vo(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),e=this.str.slice(this.spos,t);return this.spos=t,e}}const il=crypto.getRandomValues.bind(crypto),sl=()=>il(new Uint32Array(1))[0],nl=[1e7]+-1e3+-4e3+-8e3+-1e11,rl=()=>nl.replace(/[018]/g,(t=>(t^sl()&15>>t/4).toString(16))),hl=Date.now,ol=t=>new Promise(t);Promise.all.bind(Promise);let ll=new class{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}},ul=!0;try{"undefined"!=typeof localStorage&&localStorage&&(ll=localStorage,ul=!1)}catch(Yr){}const al=ll,cl=t=>ul||addEventListener("storage",t),fl=t=>ul||removeEventListener("storage",t),dl=Symbol("Equality"),pl=(t,e)=>t===e||!!t?.[dl]?.(e)||!1,wl=Object.assign,gl=Object.keys,ml=(t,e)=>{const i=[];for(const s in t)i.push(e(t[s],s));return i},yl=t=>gl(t).length,vl=(t,e)=>{for(const i in t)if(!e(t[i],i))return!1;return!0},bl=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Ml=Object.freeze,kl=t=>{for(const e in t){const i=t[e];"object"!=typeof i&&"function"!=typeof i||kl(t[e])}return Ml(t)},Al=(t,e,i=0)=>{try{for(;i<t.length;i++)t[i](...e)}finally{i<t.length&&Al(t,e,i+1)}},xl=t=>t,Sl=(t,e)=>{if(t===e)return!0;if(null==t||null==e||t.constructor!==e.constructor&&(t.constructor||Object)!==(e.constructor||Object))return!1;if(null!=t[dl])return t[dl](e);switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),e=new Uint8Array(e);case Uint8Array:if(t.byteLength!==e.byteLength)return!1;for(let i=0;i<t.length;i++)if(t[i]!==e[i])return!1;break;case Set:if(t.size!==e.size)return!1;for(const i of t)if(!e.has(i))return!1;break;case Map:if(t.size!==e.size)return!1;for(const i of t.keys())if(!e.has(i)||!Sl(t.get(i),e.get(i)))return!1;break;case void 0:case Object:if(yl(t)!==yl(e))return!1;for(const i in t)if(!bl(t,i)||!Sl(t[i],e[i]))return!1;break;case Array:if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!Sl(t[i],e[i]))return!1;break;default:return!1}return!0},Cl="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),Ol="undefined"!=typeof window&&"undefined"!=typeof document&&!Cl;let El;const Tl=t=>(()=>{if(void 0===El)if(Cl){El=Bh();const t=process.argv;let e=null;for(let i=0;i<t.length;i++){const s=t[i];"-"===s[0]?(null!==e&&El.set(e,""),e=s):null!==e&&(El.set(e,s),e=null)}null!==e&&El.set(e,"")}else"object"==typeof location?(El=Bh(),(location.search||"?").slice(1).split("&").forEach((t=>{if(0!==t.length){const[e,i]=t.split("=");El.set(`--${ao(e,"-")}`,i),El.set(`-${ao(e,"-")}`,i)}}))):El=Bh();return El})().has(t),Dl=t=>{return void 0===(e=Cl?process.env[t.toUpperCase().replaceAll("-","_")]:al.getItem(t))?null:e;var e},$l=t=>Tl("--"+t)||null!==Dl(t),Pl=$l("production");var Rl;const Il=Cl&&(Rl=process.env.FORCE_COLOR,["true","1","2"].includes(Rl))||!Tl("--no-colors")&&!$l("no-color")&&(!Cl||process.stdout.isTTY)&&(!Cl||Tl("--color")||null!==Dl("COLORTERM")||(Dl("TERM")||"").includes("color")),Ul=t=>new Uint8Array(t),jl=t=>new Uint8Array(t),Bl=Ol?t=>{let e="";for(let i=0;i<t.byteLength;i++)e+=oo(t[i]);return btoa(e)}:t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),Nl=Ol?t=>{const e=atob(t),i=Ul(e.length);for(let t=0;t<e.length;t++)i[t]=e.charCodeAt(t);return i}:t=>{const e=Buffer.from(t,"base64");return((t,e,i)=>new Uint8Array(t,e,i))(e.buffer,e.byteOffset,e.byteLength)};class Fl{constructor(t,e){this.left=t,this.right=e}}const _l=(t,e)=>new Fl(t,e),Ll=t=>t.next()>=.5,zl=(t,e,i)=>Qh(t.next()*(i+1-e)+e),Yl=(t,e,i)=>Qh(t.next()*(i+1-e)+e),Wl=(t,e,i)=>Yl(t,e,i),Xl=t=>oo(Wl(t,97,122)),Jl=(t,e)=>e[Wl(t,0,e.length-1)],Hl=Symbol("0schema");class Vl{constructor(){this._rerrs=[]}extend(t,e,i,s=null){this._rerrs.push({path:t,expected:e,has:i,message:s})}toString(){const t=[];for(let i=this._rerrs.length-1;i>0;i--){const s=this._rerrs[i];t.push((e=" ",(t=>{const i=new Array(t);for(let s=0;s<t;s++)i[s]=e;return i})(2*(this._rerrs.length-i)).join("")+`${null!=s.path?`[${s.path}] `:""}${s.has} doesn't match ${s.expected}. ${s.message}`))}var e;return t.join("\n")}}const Ql=(t,e)=>t===e||null!=t&&null!=e&&t.constructor===e.constructor&&(t[dl]?pl(t,e):Jh(t)?Wh(t,(t=>Xh(e,(e=>Ql(t,e))))):!!(t=>"object"==typeof t)(t)&&vl(t,((t,i)=>Ql(t,e[i]))));class Kl{static _dilutes=!1;extends(t){let[e,i]=[this.shape,t.shape];return this.constructor._dilutes&&([i,e]=[e,i]),Ql(e,i)}equals(t){return this.constructor===t.constructor&&Sl(this.shape,t.shape)}[Hl](){return!0}[dl](t){return this.equals(t)}validate(t){return this.check(t)}check(t,e){No()}get nullable(){return Su(this,_u)}get optional(){return new ou(this)}cast(t){return Wu(t,this),t}expect(t){return Wu(t,this),t}}class ql extends Kl{constructor(t,e){super(),this.shape=t,this._c=e}check(t,e){const i=t?.constructor===this.shape&&(null==this._c||this._c(t));return!i&&e?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),i}}const Gl=(t,e=null)=>new ql(t,e);Gl(ql);class Zl extends Kl{constructor(t){super(),this.shape=t}check(t,e){const i=this.shape(t);return!i&&e?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),i}}const tu=t=>new Zl(t);Gl(Zl);class eu extends Kl{constructor(t){super(),this.shape=t}check(t,e){const i=this.shape.some((e=>e===t));return!i&&e?.extend(null,this.shape.join(" | "),t.toString()),i}}const iu=(...t)=>new eu(t),su=Gl(eu),nu=RegExp.escape||(t=>t.replace(/[().|&,$^[\]]/g,(t=>"\\"+t))),ru=t=>Uu.check(t)?[nu(t)]:su.check(t)?t.shape.map((t=>t+"")):Iu.check(t)?["[+-]?\\d+.?\\d*"]:ju.check(t)?[".*"]:Cu.check(t)?t.shape.map(ru).flat(1):void Fo();Gl(class extends Kl{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(ru).map((t=>`(${t.join("|")})`)).join("")+"$")}check(t,e){const i=null!=this._r.exec(t);return!i&&e?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),i}});const hu=Symbol("optional");class ou extends Kl{constructor(t){super(),this.shape=t}check(t,e){const i=void 0===t||this.shape.check(t);return!i&&e?.extend(null,"undefined (optional)","()"),i}get[hu](){return!0}}const lu=Gl(ou);Gl(class extends Kl{check(t,e){return e?.extend(null,"never",typeof t),!1}});class uu extends Kl{constructor(t,e=!1){super(),this.shape=t,this._isPartial=e}static _dilutes=!0;get partial(){return new uu(this.shape,!0)}check(t,e){return null==t?(e?.extend(null,"object","null"),!1):vl(this.shape,((i,s)=>{const n=this._isPartial&&!bl(t,s)||i.check(t[s],e);return!n&&e?.extend(s.toString(),i.toString(),typeof t[s],"Object property does not match"),n}))}}const au=Gl(uu),cu=tu((t=>null!=t&&(t.constructor===Object||null==t.constructor)));class fu extends Kl{constructor(t,e){super(),this.shape={keys:t,values:e}}check(t,e){return null!=t&&vl(t,((i,s)=>{const n=this.shape.keys.check(s,e);return!n&&e?.extend(s+"","Record",typeof t,n?"Key doesn't match schema":"Value doesn't match value"),n&&this.shape.values.check(i,e)}))}}const du=(t,e)=>new fu(t,e),pu=Gl(fu);class wu extends Kl{constructor(t){super(),this.shape=t}check(t,e){return null!=t&&vl(this.shape,((i,s)=>{const n=i.check(t[s],e);return!n&&e?.extend(s.toString(),"Tuple",typeof i),n}))}}Gl(wu);class gu extends Kl{constructor(t){super(),this.shape=1===t.length?t[0]:new xu(t)}check(t,e){const i=Jh(t)&&Wh(t,(t=>this.shape.check(t)));return!i&&e?.extend(null,"Array",""),i}}const mu=(...t)=>new gu(t),yu=Gl(gu),vu=tu((t=>Jh(t)));class bu extends Kl{constructor(t,e){super(),this.shape=t,this._c=e}check(t,e){const i=t instanceof this.shape&&(null==this._c||this._c(t));return!i&&e?.extend(null,this.shape.name,t?.constructor.name),i}}Gl(bu);const Mu=((t,e=null)=>new bu(Kl,e))(),ku=Gl(class extends Kl{constructor(t){super(),this.len=t.length-1,this.args=((...t)=>new wu(t))(...t.slice(-1)),this.res=t[this.len]}check(t,e){const i=t.constructor===Function&&t.length<=this.len;return!i&&e?.extend(null,"function",typeof t),i}}),Au=tu((t=>"function"==typeof t));Gl(class extends Kl{constructor(t){super(),this.shape=t}check(t,e){const i=Wh(this.shape,(i=>i.check(t,e)));return!i&&e?.extend(null,"Intersectinon",typeof t),i}},(t=>t.shape.length>0));class xu extends Kl{static _dilutes=!0;constructor(t){super(),this.shape=t}check(t,e){const i=Xh(this.shape,(i=>i.check(t,e)));return e?.extend(null,"Union",typeof t),i}}const Su=(...t)=>t.findIndex((t=>Cu.check(t)))>=0?Su(...t.map((t=>Yu(t))).map((t=>Cu.check(t)?t.shape:[t])).flat(1)):1===t.length?t[0]:new xu(t),Cu=Gl(xu),Ou=()=>!0,Eu=tu(Ou),Tu=Gl(Zl,(t=>t.shape===Ou)),Du=tu((t=>"bigint"==typeof t)),$u=tu((t=>t===Du)),Pu=tu((t=>"symbol"==typeof t));tu((t=>t===Pu));const Ru=tu((t=>"number"==typeof t)),Iu=tu((t=>t===Ru)),Uu=tu((t=>"string"==typeof t)),ju=tu((t=>t===Uu)),Bu=tu((t=>"boolean"==typeof t)),Nu=tu((t=>t===Bu)),Fu=iu(void 0);Gl(eu,(t=>1===t.shape.length&&void 0===t.shape[0])),iu(void 0);const _u=iu(null),Lu=Gl(eu,(t=>1===t.shape.length&&null===t.shape[0]));Gl(Uint8Array),Gl(ql,(t=>t.shape===Uint8Array));const zu=Su(Ru,Uu,_u,Fu,Du,Bu,Pu);(()=>{const t=mu(Eu),e=du(Uu,Eu),i=Su(Ru,Uu,_u,Bu,t,e);t.shape=i,e.shape.values=i})();const Yu=t=>{if(Mu.check(t))return t;if(cu.check(t)){const e={};for(const i in t)e[i]=Yu(t[i]);return new uu(e)}return vu.check(t)?Su(...t.map(Yu)):zu.check(t)?iu(t):Au.check(t)?Gl(t):void Fo()},Wu=Pl?()=>{}:(t,e)=>{const i=new Vl;if(!e.check(t,i))throw Bo(`Expected value to be of type ${e.constructor.name}.\n${i.toString()}`)};const Xu=(Ju=Eu,new class{constructor(t){this.patterns=[],this.$state=t}if(t,e){return this.patterns.push({if:Yu(t),h:e}),this}else(t){return this.if(Eu,t)}done(){return(t,e)=>{for(let i=0;i<this.patterns.length;i++){const s=this.patterns[i];if(s.if.check(t))return s.h(t,e)}throw Bo("Unhandled pattern")}}}(Ju)).if(Iu,((t,e)=>zl(e,ro,no))).if(ju,((t,e)=>((t,e=0,i=20)=>{const s=Wl(t,e,i);let n="";for(let e=0;e<s;e++)n+=Xl(t);return n})(e))).if(Nu,((t,e)=>Ll(e))).if($u,((t,e)=>BigInt(zl(e,ro,no)))).if(Cu,((t,e)=>Hu(e,Jl(e,t.shape)))).if(au,((t,e)=>{const i={};for(const s in t.shape){let n=t.shape[s];if(lu.check(n)){if(Ll(e))continue;n=n.shape}i[s]=Xu(n,e)}return i})).if(yu,((t,e)=>{const i=[],s=Yl(e,0,42);for(let n=0;n<s;n++)i.push(Hu(e,t.shape));return i})).if(su,((t,e)=>Jl(e,t.shape))).if(Lu,(()=>null)).if(ku,((t,e)=>{const i=Hu(e,t.res);return()=>i})).if(Tu,((t,e)=>Hu(e,Jl(e,[Ru,Uu,_u,Fu,Du,Bu,mu(Ru),du(Su("a","b","c"),Ru)])))).if(pu,((t,e)=>{const i={},s=zl(e,0,3);for(let n=0;n<s;n++){const s=Hu(e,t.shape.keys),n=Hu(e,t.shape.values);i[s]=n}return i})).done();var Ju;const Hu=(t,e)=>Xu(Yu(e),t),Vu="undefined"!=typeof document?document:{};tu((t=>t.nodeType===Gu)),"undefined"!=typeof DOMParser&&new DOMParser,tu((t=>t.nodeType===Qu)),tu((t=>t.nodeType===Ku));const Qu=Vu.ELEMENT_NODE,Ku=Vu.TEXT_NODE,qu=Vu.DOCUMENT_NODE,Gu=Vu.DOCUMENT_FRAGMENT_NODE;tu((t=>t.nodeType===qu));const Zu=Symbol,ta=Zu(),ea=Zu(),ia=Zu(),sa=Zu(),na=Zu(),ra=Zu(),ha=Zu(),oa=Zu(),la=Zu(),ua={[ta]:_l("font-weight","bold"),[ea]:_l("font-weight","normal"),[ia]:_l("color","blue"),[na]:_l("color","green"),[sa]:_l("color","grey"),[ra]:_l("color","red"),[ha]:_l("color","purple"),[oa]:_l("color","orange"),[la]:_l("color","black")},aa=Il?t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const e=[],i=[],s=Bh();let n=[],r=0;for(;r<t.length;r++){const n=t[r],h=ua[n];if(void 0!==h)s.set(h.left,h.right);else{if(void 0===n)break;if(n.constructor!==String&&n.constructor!==Number)break;{const t=((t,e)=>{const i=[];for(const[s,n]of t)i.push(e(n,s));return i})(s,((t,e)=>`${e}:${t};`)).join("");r>0||t.length>0?(e.push("%c"+n),i.push(t)):e.push(n)}}}for(r>0&&(n=i,n.unshift(e.join("")));r<t.length;r++){const e=t[r];e instanceof Symbol||n.push(e)}return n}:t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const e=[],i=[];let s=0;for(;s<t.length;s++){const i=t[s];if(void 0===i)break;if(i.constructor===String||i.constructor===Number)e.push(i);else if(i.constructor===Object)break}for(s>0&&i.push(e.join(""));s<t.length;s++){const e=t[s];e instanceof Symbol||i.push(e)}return i},ca=(...t)=>{console.warn(...aa(t)),t.unshift(oa),fa.forEach((e=>e.print(t)))},fa=_h(),da=t=>({[Symbol.iterator](){return this},next:t}),pa=(t,e)=>da((()=>{const{done:i,value:s}=t.next();return{done:i,value:i?void 0:e(s)}}));class wa{constructor(t,e){this.clock=t,this.len=e}}class ga{constructor(){this.clients=new Map}}const ma=(t,e,i)=>e.clients.forEach(((e,s)=>{const n=t.doc.store.clients.get(s);if(null!=n){const s=n[n.length-1],r=s.id.clock+s.length;for(let s=0,h=e[s];s<e.length&&h.clock<r;h=e[++s])uc(t,n,h.clock,h.len,i)}})),ya=(t,e)=>{const i=t.clients.get(e.client);return void 0!==i&&null!==((t,e)=>{let i=0,s=t.length-1;for(;i<=s;){const n=Qh((i+s)/2),r=t[n],h=r.clock;if(h<=e){if(e<h+r.len)return n;i=n+1}else s=n-1}return null})(i,e.clock)},va=t=>{t.clients.forEach((t=>{let e,i;for(t.sort(((t,e)=>t.clock-e.clock)),e=1,i=1;e<t.length;e++){const s=t[i-1],n=t[e];s.clock+s.len>=n.clock?s.len=Gh(s.len,n.clock+n.len-s.clock):(i<e&&(t[i]=n),i++)}t.length=i}))},ba=t=>{const e=new ga;for(let i=0;i<t.length;i++)t[i].clients.forEach(((s,n)=>{if(!e.clients.has(n)){const r=s.slice();for(let e=i+1;e<t.length;e++)zh(r,t[e].clients.get(n)||[]);e.clients.set(n,r)}}));return va(e),e},Ma=(t,e,i,s)=>{Fh(t.clients,e,(()=>[])).push(new wa(i,s))},ka=(t,e)=>{Mo(t.restEncoder,e.clients.size),Yh(e.clients.entries()).sort(((t,e)=>e[0]-t[0])).forEach((([e,i])=>{t.resetDsCurVal(),Mo(t.restEncoder,e);const s=i.length;Mo(t.restEncoder,s);for(let e=0;e<s;e++){const s=i[e];t.writeDsClock(s.clock),t.writeDsLen(s.len)}}))},Aa=t=>{const e=new ga,i=Jo(t.restDecoder);for(let s=0;s<i;s++){t.resetDsCurVal();const i=Jo(t.restDecoder),s=Jo(t.restDecoder);if(s>0){const n=Fh(e.clients,i,(()=>[]));for(let e=0;e<s;e++)n.push(new wa(t.readDsClock(),t.readDsLen()))}}return e},xa=(t,e,i)=>{const s=new ga,n=Jo(t.restDecoder);for(let r=0;r<n;r++){t.resetDsCurVal();const n=Jo(t.restDecoder),r=Jo(t.restDecoder),h=i.clients.get(n)||[],o=ic(i,n);for(let i=0;i<r;i++){const i=t.readDsClock(),r=i+t.readDsLen();if(i<o){o<r&&Ma(s,n,o,r-o);let t=nc(h,i),l=h[t];for(!l.deleted&&l.id.clock<i&&(h.splice(t+1,0,Zf(e,l,i-l.id.clock)),t++);t<h.length&&(l=h[t++],l.id.clock<r);)l.deleted||(r<l.id.clock+l.length&&h.splice(t,0,Zf(e,l,r-l.id.clock)),l.delete(e))}else Ma(s,n,i,r-i)}}if(s.clients.size>0){const t=new Ia;return Mo(t.restEncoder,0),ka(t,s),t.toUint8Array()}return null},Sa=sl;class Ca extends Hh{constructor({guid:t=rl(),collectionid:e=null,gc:i=!0,gcFilter:s=()=>!0,meta:n=null,autoLoad:r=!1,shouldLoad:h=!0}={}){super(),this.gc=i,this.gcFilter=s,this.clientID=Sa(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new tc,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=h,this.autoLoad=r,this.meta=n,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=ol((t=>{this.on("load",(()=>{this.isLoaded=!0,t(this)}))}));const o=()=>ol((t=>{const e=i=>{void 0!==i&&!0!==i||(this.off("sync",e),t())};this.on("sync",e)}));this.on("sync",(t=>{!1===t&&this.isSynced&&(this.whenSynced=o()),this.isSynced=void 0===t||!0===t,this.isSynced&&!this.isLoaded&&this.emit("load",[this])})),this.whenSynced=o()}load(){const t=this._item;null===t||this.shouldLoad||wc(t.parent.doc,(t=>{t.subdocsLoaded.add(this)}),null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Yh(this.subdocs).map((t=>t.guid)))}transact(t,e=null){return wc(this,t,e)}get(t,e=_c){const i=Fh(this.share,t,(()=>{const t=new e;return t._integrate(this,null),t})),s=i.constructor;if(e!==_c&&s!==e){if(s===_c){const s=new e;s._map=i._map,i._map.forEach((t=>{for(;null!==t;t=t.left)t.parent=s})),s._start=i._start;for(let t=s._start;null!==t;t=t.right)t.parent=s;return s._length=i._length,this.share.set(t,s),s._integrate(this,null),s}throw new Error(`Type with the name ${t} has already been defined with a different constructor`)}return i}getArray(t=""){return this.get(t,rf)}getText(t=""){return this.get(t,Af)}getMap(t=""){return this.get(t,of)}getXmlElement(t=""){return this.get(t,Cf)}getXmlFragment(t=""){return this.get(t,Sf)}toJSON(){const t={};return this.share.forEach(((e,i)=>{t[i]=e.toJSON()})),t}destroy(){this.isDestroyed=!0,Yh(this.subdocs).forEach((t=>t.destroy()));const t=this._item;if(null!==t){this._item=null;const e=t.content;e.doc=new Ca({guid:this.guid,...e.opts,shouldLoad:!1}),e.doc._item=t,wc(t.parent.doc,(i=>{t.deleted||i.subdocsAdded.add(e.doc),i.subdocsRemoved.add(this)}),null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Oa{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return Jo(this.restDecoder)}readDsLen(){return Jo(this.restDecoder)}}class Ea extends Oa{readLeftID(){return Ka(Jo(this.restDecoder),Jo(this.restDecoder))}readRightID(){return Ka(Jo(this.restDecoder),Jo(this.restDecoder))}readClient(){return Jo(this.restDecoder)}readInfo(){return Xo(this.restDecoder)}readString(){return Vo(this.restDecoder)}readParentInfo(){return 1===Jo(this.restDecoder)}readTypeRef(){return Jo(this.restDecoder)}readLen(){return Jo(this.restDecoder)}readAny(){return qo(this.restDecoder)}readBuf(){return(t=>{const e=Ul(t.byteLength);return e.set(t),e})(Wo(this.restDecoder))}readJSON(){return JSON.parse(Vo(this.restDecoder))}readKey(){return Vo(this.restDecoder)}}class Ta{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Jo(this.restDecoder),this.dsCurrVal}readDsLen(){const t=Jo(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Da extends Ta{constructor(t){super(t),this.keys=[],Jo(t),this.keyClockDecoder=new tl(Wo(t)),this.clientDecoder=new Zo(Wo(t)),this.leftClockDecoder=new tl(Wo(t)),this.rightClockDecoder=new tl(Wo(t)),this.infoDecoder=new Go(Wo(t),Xo),this.stringDecoder=new el(Wo(t)),this.parentInfoDecoder=new Go(Wo(t),Xo),this.typeRefDecoder=new Zo(Wo(t)),this.lenDecoder=new Zo(Wo(t))}readLeftID(){return new Va(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Va(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 qo(this.restDecoder)}readBuf(){return Wo(this.restDecoder)}readJSON(){return qo(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 $a{constructor(){this.restEncoder=go()}toUint8Array(){return yo(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){Mo(this.restEncoder,t)}writeDsLen(t){Mo(this.restEncoder,t)}}class Pa extends $a{writeLeftID(t){Mo(this.restEncoder,t.client),Mo(this.restEncoder,t.clock)}writeRightID(t){Mo(this.restEncoder,t.client),Mo(this.restEncoder,t.clock)}writeClient(t){Mo(this.restEncoder,t)}writeInfo(t){bo(this.restEncoder,t)}writeString(t){So(this.restEncoder,t)}writeParentInfo(t){Mo(this.restEncoder,t?1:0)}writeTypeRef(t){Mo(this.restEncoder,t)}writeLen(t){Mo(this.restEncoder,t)}writeAny(t){Do(this.restEncoder,t)}writeBuf(t){Oo(this.restEncoder,t)}writeJSON(t){So(this.restEncoder,JSON.stringify(t))}writeKey(t){So(this.restEncoder,t)}}class Ra{constructor(){this.restEncoder=go(),this.dsCurrVal=0}toUint8Array(){return yo(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const e=t-this.dsCurrVal;this.dsCurrVal=t,Mo(this.restEncoder,e)}writeDsLen(t){0===t&&Fo(),Mo(this.restEncoder,t-1),this.dsCurrVal+=t}}class Ia extends Ra{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Uo,this.clientEncoder=new Ro,this.leftClockEncoder=new Uo,this.rightClockEncoder=new Uo,this.infoEncoder=new $o(bo),this.stringEncoder=new jo,this.parentInfoEncoder=new $o(bo),this.typeRefEncoder=new Ro,this.lenEncoder=new Ro}toUint8Array(){const t=go();return Mo(t,0),Oo(t,this.keyClockEncoder.toUint8Array()),Oo(t,this.clientEncoder.toUint8Array()),Oo(t,this.leftClockEncoder.toUint8Array()),Oo(t,this.rightClockEncoder.toUint8Array()),Oo(t,yo(this.infoEncoder)),Oo(t,this.stringEncoder.toUint8Array()),Oo(t,yo(this.parentInfoEncoder)),Oo(t,this.typeRefEncoder.toUint8Array()),Oo(t,this.lenEncoder.toUint8Array()),Co(t,yo(this.restEncoder)),yo(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){Do(this.restEncoder,t)}writeBuf(t){Oo(this.restEncoder,t)}writeJSON(t){Do(this.restEncoder,t)}writeKey(t){const e=this.keyMap.get(t);void 0===e?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(e)}}const Ua=(t,e,i)=>{const s=new Map;i.forEach(((t,i)=>{ic(e,i)>t&&s.set(i,t)})),ec(e).forEach(((t,e)=>{i.has(e)||s.set(e,0)})),Mo(t.restEncoder,s.size),Yh(s.entries()).sort(((t,e)=>e[0]-t[0])).forEach((([i,s])=>{((t,e,i,s)=>{s=Gh(s,e[0].id.clock);const n=nc(e,s);Mo(t.restEncoder,e.length-n),t.writeClient(i),Mo(t.restEncoder,s);const r=e[n];r.write(t,s-r.id.clock);for(let i=n+1;i<e.length;i++)e[i].write(t,0)})(t,e.clients.get(i),i,s)}))},ja=(t,e,i,s=Da)=>{const n=Yo(e);((t,e,i,s=new Da(t))=>{wc(e,(t=>{t.local=!1;let e=!1;const i=t.doc,n=i.store,r=((t,e)=>{const i=Bh(),s=Jo(t.restDecoder);for(let n=0;n<s;n++){const s=Jo(t.restDecoder),n=new Array(s),r=t.readClient();let h=Jo(t.restDecoder);i.set(r,{i:0,refs:n});for(let i=0;i<s;i++){const s=t.readInfo();switch(31&s){case 0:{const e=t.readLen();n[i]=new $f(Ka(r,h),e),h+=e;break}case 10:{const e=Jo(t.restDecoder);n[i]=new rd(Ka(r,h),e),h+=e;break}default:{const o=!(192&s),l=new id(Ka(r,h),null,(s&io)===io?t.readLeftID():null,null,(s&eo)===eo?t.readRightID():null,o?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,!o||32&~s?null:t.readString(),sd(t,s));n[i]=l,h+=l.length}}}}return i})(s,i),h=((t,e,i)=>{const s=[];let n=Yh(i.keys()).sort(((t,e)=>t-e));if(0===n.length)return null;const r=()=>{if(0===n.length)return null;let t=i.get(n[n.length-1]);for(;t.refs.length===t.i;){if(n.pop(),!(n.length>0))return null;t=i.get(n[n.length-1])}return t};let h=r();if(null===h)return null;const o=new tc,l=new Map,u=(t,e)=>{const i=l.get(t);(null==i||i>e)&&l.set(t,e)};let a=h.refs[h.i++];const c=new Map,f=()=>{for(const t of s){const e=t.id.client,s=i.get(e);s?(s.i--,o.clients.set(e,s.refs.slice(s.i)),i.delete(e),s.i=0,s.refs=[]):o.clients.set(e,[t]),n=n.filter((t=>t!==e))}s.length=0};for(;;){if(a.constructor!==rd){const n=Fh(c,a.id.client,(()=>ic(e,a.id.client)))-a.id.clock;if(n<0)s.push(a),u(a.id.client,a.id.clock-1),f();else{const r=a.getMissing(t,e);if(null!==r){s.push(a);const t=i.get(r)||{refs:[],i:0};if(t.refs.length!==t.i){a=t.refs[t.i++];continue}u(r,ic(e,r)),f()}else(0===n||n<a.length)&&(a.integrate(t,n),c.set(a.id.client,a.id.clock+a.length))}}if(s.length>0)a=s.pop();else if(null!==h&&h.i<h.refs.length)a=h.refs[h.i++];else{if(h=r(),null===h)break;a=h.refs[h.i++]}}if(o.clients.size>0){const t=new Ia;return Ua(t,o,new Map),Mo(t.restEncoder,0),{missing:l,update:t.toUint8Array()}}return null})(t,n,r),o=n.pendingStructs;if(o){for(const[t,i]of o.missing)if(i<ic(n,t)){e=!0;break}if(h){for(const[t,e]of h.missing){const i=o.missing.get(t);(null==i||i>e)&&o.missing.set(t,e)}o.update=xc([o.update,h.update])}}else n.pendingStructs=h;const l=xa(s,t,n);if(n.pendingDs){const e=new Da(Yo(n.pendingDs));Jo(e.restDecoder);const i=xa(e,t,n);n.pendingDs=l&&i?xc([l,i]):l||i}else n.pendingDs=l;if(e){const e=n.pendingStructs.update;n.pendingStructs=null,ja(t.doc,e)}}),i,!1)})(n,t,i,new s(n))},Ba=(t,e,i)=>ja(t,e,i,Ea),Na=(t,e=new Uint8Array([0]),i=new Ia)=>{((t,e,i=new Map)=>{Ua(t,e.store,i),ka(t,(t=>{const e=new ga;return t.clients.forEach(((t,i)=>{const s=[];for(let e=0;e<t.length;e++){const i=t[e];if(i.deleted){const n=i.id.clock;let r=i.length;if(e+1<t.length)for(let i=t[e+1];e+1<t.length&&i.deleted;i=t[1+ ++e])r+=i.length;s.push(new wa(n,r))}}s.length>0&&e.clients.set(i,s)})),e})(e.store))})(i,t,_a(e));const s=[i.toUint8Array()];if(t.store.pendingDs&&s.push(t.store.pendingDs),t.store.pendingStructs&&s.push(Sc(t.store.pendingStructs.update,e)),s.length>1){if(i.constructor===Pa)return kc(s.map(((t,e)=>0===e?t:Tc(t))));if(i.constructor===Ia)return xc(s)}return s[0]},Fa=(t,e)=>Na(t,e,new Pa),_a=t=>(t=>{const e=new Map,i=Jo(t.restDecoder);for(let s=0;s<i;s++){const i=Jo(t.restDecoder),s=Jo(t.restDecoder);e.set(i,s)}return e})(new Oa(Yo(t))),La=(t,e)=>(Mo(t.restEncoder,e.size),Yh(e.entries()).sort(((t,e)=>e[0]-t[0])).forEach((([e,i])=>{Mo(t.restEncoder,e),Mo(t.restEncoder,i)})),t),za=t=>((t,e=new Ra)=>(t instanceof Map?La(e,t):((t,e)=>{La(t,ec(e.store))})(e,t),e.toUint8Array()))(t,new $a);class Ya{constructor(){this.l=[]}}const Wa=()=>new Ya,Xa=(t,e)=>t.l.push(e),Ja=(t,e)=>{const i=t.l,s=i.length;t.l=i.filter((t=>e!==t)),s===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Ha=(t,e,i)=>Al(t.l,[e,i]);class Va{constructor(t,e){this.client=t,this.clock=e}}const Qa=(t,e)=>t===e||null!==t&&null!==e&&t.client===e.client&&t.clock===e.clock,Ka=(t,e)=>new Va(t,e),qa=(t,e)=>{for(;null!==e;){if(e.parent===t)return!0;e=e.parent._item}return!1},Ga=(t,e)=>void 0===e?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!ya(e.ds,t.id),Za=(t,e)=>{const i=Fh(t.meta,Za,_h),s=t.doc.store;i.has(e)||(e.sv.forEach(((e,i)=>{e<ic(s,i)&&oc(t,Ka(i,e))})),ma(t,e.ds,(()=>{})),i.add(e))};class tc{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const ec=t=>{const e=new Map;return t.clients.forEach(((t,i)=>{const s=t[t.length-1];e.set(i,s.id.clock+s.length)})),e},ic=(t,e)=>{const i=t.clients.get(e);if(void 0===i)return 0;const s=i[i.length-1];return s.id.clock+s.length},sc=(t,e)=>{let i=t.clients.get(e.id.client);if(void 0===i)i=[],t.clients.set(e.id.client,i);else{const t=i[i.length-1];if(t.id.clock+t.length!==e.id.clock)throw Fo()}i.push(e)},nc=(t,e)=>{let i=0,s=t.length-1,n=t[s],r=n.id.clock;if(r===e)return s;let h=Qh(e/(r+n.length-1)*s);for(;i<=s;){if(n=t[h],r=n.id.clock,r<=e){if(e<r+n.length)return h;i=h+1}else s=h-1;h=Qh((i+s)/2)}throw Fo()},rc=(t,e)=>{const i=t.clients.get(e.client);return i[nc(i,e.clock)]},hc=(t,e,i)=>{const s=nc(e,i),n=e[s];return n.id.clock<i&&n instanceof id?(e.splice(s+1,0,Zf(t,n,i-n.id.clock)),s+1):s},oc=(t,e)=>{const i=t.doc.store.clients.get(e.client);return i[hc(t,i,e.clock)]},lc=(t,e,i)=>{const s=e.clients.get(i.client),n=nc(s,i.clock),r=s[n];return i.clock!==r.id.clock+r.length-1&&r.constructor!==$f&&s.splice(n+1,0,Zf(t,r,i.clock-r.id.clock+1)),r},uc=(t,e,i,s,n)=>{if(0===s)return;const r=i+s;let h,o=hc(t,e,i);do{h=e[o++],r<h.id.clock+h.length&&hc(t,e,r),n(h)}while(o<e.length&&e[o].id.clock<r)};class ac{constructor(t,e,i){this.doc=t,this.deleteSet=new ga,this.beforeState=ec(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=e,this.meta=new Map,this.local=i,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const cc=(t,e)=>!(0===e.deleteSet.clients.size&&!(t=>{for(const[s,n]of t)if(i=n,e.beforeState.get(s)!==i)return!0;var i;return!1})(e.afterState)||(va(e.deleteSet),((t,e)=>{Ua(t,e.doc.store,e.beforeState)})(t,e),ka(t,e.deleteSet),0)),fc=(t,e,i)=>{const s=e._item;(null===s||s.id.clock<(t.beforeState.get(s.id.client)||0)&&!s.deleted)&&Fh(t.changed,e,_h).add(i)},dc=(t,e)=>{let i=t[e],s=t[e-1],n=e;for(;n>0&&s.deleted===i.deleted&&s.constructor===i.constructor&&s.mergeWith(i);i=s,s=t[--n-1])i instanceof id&&null!==i.parentSub&&i.parent._map.get(i.parentSub)===i&&i.parent._map.set(i.parentSub,s);const r=e-n;return r&&t.splice(e+1-r,r),r},pc=(t,e)=>{if(e<t.length){const i=t[e],s=i.doc,n=s.store,r=i.deleteSet,h=i._mergeStructs;try{va(r),i.afterState=ec(i.doc.store),s.emit("beforeObserverCalls",[i,s]);const t=[];i.changed.forEach(((e,s)=>t.push((()=>{null!==s._item&&s._item.deleted||s._callObserver(i,e)})))),t.push((()=>{i.changedParentTypes.forEach(((t,e)=>{e._dEH.l.length>0&&(null===e._item||!e._item.deleted)&&((t=t.filter((t=>null===t.target._item||!t.target._item.deleted))).forEach((t=>{t.currentTarget=e,t._path=null})),t.sort(((t,e)=>t.path.length-e.path.length)),Ha(e._dEH,t,i))}))})),t.push((()=>s.emit("afterTransaction",[i,s]))),Al(t,[]),i._needFormattingCleanup&&bf(i)}finally{s.gc&&((t,e,i)=>{for(const[s,n]of t.clients.entries()){const t=e.clients.get(s);for(let s=n.length-1;s>=0;s--){const r=n[s],h=r.clock+r.len;for(let s=nc(t,r.clock),n=t[s];s<t.length&&n.id.clock<h;n=t[++s]){const n=t[s];if(r.clock+r.len<=n.id.clock)break;n instanceof id&&n.deleted&&!n.keep&&i(n)&&n.gc(e,!1)}}}})(r,n,s.gcFilter),((t,e)=>{t.clients.forEach(((t,i)=>{const s=e.clients.get(i);for(let e=t.length-1;e>=0;e--){const i=t[e];for(let t=qh(s.length-1,1+nc(s,i.clock+i.len-1)),e=s[t];t>0&&e.id.clock>=i.clock;e=s[t])t-=1+dc(s,t)}}))})(r,n),i.afterState.forEach(((t,e)=>{const s=i.beforeState.get(e)||0;if(s!==t){const t=n.clients.get(e),i=Gh(nc(t,s),1);for(let e=t.length-1;e>=i;)e-=1+dc(t,e)}}));for(let t=h.length-1;t>=0;t--){const{client:e,clock:i}=h[t].id,s=n.clients.get(e),r=nc(s,i);r+1<s.length&&dc(s,r+1)>1||r>0&&dc(s,r)}if(i.local||i.afterState.get(s.clientID)===i.beforeState.get(s.clientID)||(((...t)=>{console.log(...aa(t)),fa.forEach((e=>e.print(t)))})(oa,ta,"[yjs] ",ea,ra,"Changed the client-id because another client seems to be using it."),s.clientID=Sa()),s.emit("afterTransactionCleanup",[i,s]),s._observers.has("update")){const t=new Pa;cc(t,i)&&s.emit("update",[t.toUint8Array(),i.origin,s,i])}if(s._observers.has("updateV2")){const t=new Ia;cc(t,i)&&s.emit("updateV2",[t.toUint8Array(),i.origin,s,i])}const{subdocsAdded:o,subdocsLoaded:l,subdocsRemoved:u}=i;(o.size>0||u.size>0||l.size>0)&&(o.forEach((t=>{t.clientID=s.clientID,null==t.collectionid&&(t.collectionid=s.collectionid),s.subdocs.add(t)})),u.forEach((t=>s.subdocs.delete(t))),s.emit("subdocs",[{loaded:l,added:o,removed:u},s,i]),u.forEach((t=>t.destroy()))),t.length<=e+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,t])):pc(t,e+1)}}},wc=(t,e,i=null,s=!0)=>{const n=t._transactionCleanups;let r=!1,h=null;null===t._transaction&&(r=!0,t._transaction=new ac(t,i,s),n.push(t._transaction),1===n.length&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{h=e(t._transaction)}finally{if(r){const e=t._transaction===n[0];t._transaction=null,e&&pc(n,0)}}return h};class gc{constructor(t,e){this.insertions=e,this.deletions=t,this.meta=new Map}}const mc=(t,e,i)=>{ma(t,i.deletions,(i=>{i instanceof id&&e.scope.some((e=>e===t.doc||qa(e,i)))&&Gf(i,!1)}))},yc=(t,e,i)=>{let s=null;const n=t.doc,r=t.scope;wc(n,(i=>{for(;e.length>0&&null===t.currStackItem;){const s=n.store,h=e.pop(),o=new Set,l=[];let u=!1;ma(i,h.insertions,(t=>{if(t instanceof id){if(null!==t.redone){let{item:e,diff:n}=qf(s,t.id);n>0&&(e=oc(i,Ka(e.id.client,e.id.clock+n))),t=e}!t.deleted&&r.some((e=>e===i.doc||qa(e,t)))&&l.push(t)}})),ma(i,h.deletions,(t=>{t instanceof id&&r.some((e=>e===i.doc||qa(e,t)))&&!ya(h.insertions,t.id)&&o.add(t)})),o.forEach((e=>{u=null!==ed(i,e,o,h.insertions,t.ignoreRemoteMapChanges,t)||u}));for(let e=l.length-1;e>=0;e--){const s=l[e];t.deleteFilter(s)&&(s.delete(i),u=!0)}t.currStackItem=u?h:null}i.changed.forEach(((t,e)=>{t.has(null)&&e._searchMarker&&(e._searchMarker.length=0)})),s=i}),t);const h=t.currStackItem;return null!=h&&(t.emit("stack-item-popped",[{stackItem:h,type:i,changedParentTypes:s.changedParentTypes,origin:t},t]),t.currStackItem=null),h};class vc extends Hh{constructor(t,{captureTimeout:e=500,captureTransaction:i=()=>!0,deleteFilter:s=()=>!0,trackedOrigins:n=new Set([null]),ignoreRemoteMapChanges:r=!1,doc:h=(Jh(t)?t[0].doc:t instanceof Ca?t:t.doc)}={}){super(),this.scope=[],this.doc=h,this.addToScope(t),this.deleteFilter=s,n.add(this),this.trackedOrigins=n,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=r,this.captureTimeout=e,this.afterTransactionHandler=t=>{if(!(this.captureTransaction(t)&&this.scope.some((e=>t.changedParentTypes.has(e)||e===this.doc))&&(this.trackedOrigins.has(t.origin)||t.origin&&this.trackedOrigins.has(t.origin.constructor))))return;const e=this.undoing,i=this.redoing,s=e?this.redoStack:this.undoStack;e?this.stopCapturing():i||this.clear(!1,!0);const n=new ga;t.afterState.forEach(((e,i)=>{const s=t.beforeState.get(i)||0,r=e-s;r>0&&Ma(n,i,s,r)}));const r=hl();let h=!1;if(this.lastChange>0&&r-this.lastChange<this.captureTimeout&&s.length>0&&!e&&!i){const e=s[s.length-1];e.deletions=ba([e.deletions,t.deleteSet]),e.insertions=ba([e.insertions,n])}else s.push(new gc(t.deleteSet,n)),h=!0;e||i||(this.lastChange=r),ma(t,t.deleteSet,(e=>{e instanceof id&&this.scope.some((i=>i===t.doc||qa(i,e)))&&Gf(e,!0)}));this.emit(h?"stack-item-added":"stack-item-updated",[{stackItem:s[s.length-1],origin:t.origin,type:e?"redo":"undo",changedParentTypes:t.changedParentTypes},this])},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",(()=>{this.destroy()}))}addToScope(t){const e=new Set(this.scope);(t=Jh(t)?t:[t]).forEach((t=>{e.has(t)||(e.add(t),(t instanceof _c?t.doc!==this.doc:t!==this.doc)&&ca("[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,e=!0){(t&&this.canUndo()||e&&this.canRedo())&&this.doc.transact((i=>{t&&(this.undoStack.forEach((t=>mc(i,this,t))),this.undoStack=[]),e&&(this.redoStack.forEach((t=>mc(i,this,t))),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:e}])}))}stopCapturing(){this.lastChange=0}undo(){let t;this.undoing=!0;try{t=yc(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){let t;this.redoing=!0;try{t=yc(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 bc{constructor(t,e){this.gen=function*(t){const e=Jo(t.restDecoder);for(let i=0;i<e;i++){const e=Jo(t.restDecoder),i=t.readClient();let s=Jo(t.restDecoder);for(let n=0;n<e;n++){const e=t.readInfo();if(10===e){const e=Jo(t.restDecoder);yield new rd(Ka(i,s),e),s+=e}else if(31&e){const n=!(192&e),r=new id(Ka(i,s),null,(e&io)===io?t.readLeftID():null,null,(e&eo)===eo?t.readRightID():null,n?t.readParentInfo()?t.readString():t.readLeftID():null,!n||32&~e?null:t.readString(),sd(t,e));yield r,s+=r.length}else{const e=t.readLen();yield new $f(Ka(i,s),e),s+=e}}}}(t),this.curr=null,this.done=!1,this.filterSkips=e,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===rd);return this.curr}}class Mc{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const kc=t=>xc(t,Ea,Pa),Ac=(t,e)=>{if(t.constructor===$f){const{client:i,clock:s}=t.id;return new $f(Ka(i,s+e),t.length-e)}if(t.constructor===rd){const{client:i,clock:s}=t.id;return new rd(Ka(i,s+e),t.length-e)}{const i=t,{client:s,clock:n}=i.id;return new id(Ka(s,n+e),null,Ka(s,n+e-1),null,i.rightOrigin,i.parent,i.parentSub,i.content.splice(e))}},xc=(t,e=Da,i=Ia)=>{if(1===t.length)return t[0];const s=t.map((t=>new e(Yo(t))));let n=s.map((t=>new bc(t,!0))),r=null;const h=new i,o=new Mc(h);for(;n=n.filter((t=>null!==t.curr)),n.sort(((t,e)=>{if(t.curr.id.client===e.curr.id.client){const i=t.curr.id.clock-e.curr.id.clock;return 0===i?t.curr.constructor===e.curr.constructor?0:t.curr.constructor===rd?1:-1:i}return e.curr.id.client-t.curr.id.client})),0!==n.length;){const t=n[0],e=t.curr.id.client;if(null!==r){let i=t.curr,s=!1;for(;null!==i&&i.id.clock+i.length<=r.struct.id.clock+r.struct.length&&i.id.client>=r.struct.id.client;)i=t.next(),s=!0;if(null===i||i.id.client!==e||s&&i.id.clock>r.struct.id.clock+r.struct.length)continue;if(e!==r.struct.id.client)Oc(o,r.struct,r.offset),r={struct:i,offset:0},t.next();else if(r.struct.id.clock+r.struct.length<i.id.clock)if(r.struct.constructor===rd)r.struct.length=i.id.clock+i.length-r.struct.id.clock;else{Oc(o,r.struct,r.offset);const t=i.id.clock-r.struct.id.clock-r.struct.length;r={struct:new rd(Ka(e,r.struct.id.clock+r.struct.length),t),offset:0}}else{const e=r.struct.id.clock+r.struct.length-i.id.clock;e>0&&(r.struct.constructor===rd?r.struct.length-=e:i=Ac(i,e)),r.struct.mergeWith(i)||(Oc(o,r.struct,r.offset),r={struct:i,offset:0},t.next())}}else r={struct:t.curr,offset:0},t.next();for(let i=t.curr;null!==i&&i.id.client===e&&i.id.clock===r.struct.id.clock+r.struct.length&&i.constructor!==rd;i=t.next())Oc(o,r.struct,r.offset),r={struct:i,offset:0}}null!==r&&(Oc(o,r.struct,r.offset),r=null),Ec(o);const l=s.map((t=>Aa(t))),u=ba(l);return ka(h,u),h.toUint8Array()},Sc=(t,e,i=Da,s=Ia)=>{const n=_a(e),r=new s,h=new Mc(r),o=new i(Yo(t)),l=new bc(o,!1);for(;l.curr;){const t=l.curr,e=t.id.client,i=n.get(e)||0;if(l.curr.constructor!==rd)if(t.id.clock+t.length>i)for(Oc(h,t,Gh(i-t.id.clock,0)),l.next();l.curr&&l.curr.id.client===e;)Oc(h,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===e&&l.curr.id.clock+l.curr.length<=i;)l.next();else l.next()}Ec(h);const u=Aa(o);return ka(r,u),r.toUint8Array()},Cc=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:yo(t.encoder.restEncoder)}),t.encoder.restEncoder=go(),t.written=0)},Oc=(t,e,i)=>{t.written>0&&t.currClient!==e.id.client&&Cc(t),0===t.written&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),Mo(t.encoder.restEncoder,e.id.clock+i)),e.write(t.encoder,i),t.written++},Ec=t=>{Cc(t);const e=t.encoder.restEncoder;Mo(e,t.clientStructs.length);for(let i=0;i<t.clientStructs.length;i++){const s=t.clientStructs[i];Mo(e,s.written),Co(e,s.restEncoder)}},Tc=t=>((t,e,i,s)=>{const n=new Da(Yo(t)),r=new bc(n,!1),h=new s,o=new Mc(h);for(let t=r.curr;null!==t;t=r.next())Oc(o,e(t),0);Ec(o);const l=Aa(n);return ka(h,l),h.toUint8Array()})(t,xl,0,Pa),Dc="You must not compute changes after the event-handler fired.";class $c{constructor(t,e){this.target=t,this.currentTarget=t,this.transaction=e,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Pc(this.currentTarget,this.target))}deletes(t){return ya(this.transaction.deleteSet,t.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw Bo(Dc);const t=new Map,e=this.target;this.transaction.changed.get(e).forEach((i=>{if(null!==i){const s=e._map.get(i);let n,r;if(this.adds(s)){let t=s.left;for(;null!==t&&this.adds(t);)t=t.left;if(this.deletes(s)){if(null===t||!this.deletes(t))return;n="delete",r=Lh(t.content.getContent())}else null!==t&&this.deletes(t)?(n="update",r=Lh(t.content.getContent())):(n="add",r=void 0)}else{if(!this.deletes(s))return;n="delete",r=Lh(s.content.getContent())}t.set(i,{action:n,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 Bo(Dc);const e=this.target,i=_h(),s=_h(),n=[];if(t={added:i,deleted:s,delta:n,keys:this.keys},this.transaction.changed.get(e).has(null)){let t=null;const r=()=>{t&&n.push(t)};for(let n=e._start;null!==n;n=n.right)n.deleted?this.deletes(n)&&!this.adds(n)&&(null!==t&&void 0!==t.delete||(r(),t={delete:0}),t.delete+=n.length,s.add(n)):this.adds(n)?(null!==t&&void 0!==t.insert||(r(),t={insert:[]}),t.insert=t.insert.concat(n.content.getContent()),i.add(n)):(null!==t&&void 0!==t.retain||(r(),t={retain:0}),t.retain+=n.length);null!==t&&void 0===t.retain&&r()}this._changes=t}return t}}const Pc=(t,e)=>{const i=[];for(;null!==e._item&&e!==t;){if(null!==e._item.parentSub)i.unshift(e._item.parentSub);else{let t=0,s=e._item.parent._start;for(;s!==e._item&&null!==s;)!s.deleted&&s.countable&&(t+=s.length),s=s.right;i.unshift(t)}e=e._item.parent}return i},Rc=()=>{ca("Invalid access: Add Yjs type to a document before reading data.")};let Ic=0;class Uc{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=Ic++}}const jc=(t,e,i)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=i,t.timestamp=Ic++},Bc=(t,e)=>{if(null===t._start||0===e||null===t._searchMarker)return null;const i=0===t._searchMarker.length?null:t._searchMarker.reduce(((t,i)=>Kh(e-t.index)<Kh(e-i.index)?t:i));let s=t._start,n=0;for(null!==i&&(s=i.p,n=i.index,(t=>{t.timestamp=Ic++})(i));null!==s.right&&n<e;){if(!s.deleted&&s.countable){if(e<n+s.length)break;n+=s.length}s=s.right}for(;null!==s.left&&n>e;)s=s.left,!s.deleted&&s.countable&&(n-=s.length);for(;null!==s.left&&s.left.id.client===s.id.client&&s.left.id.clock+s.left.length===s.id.clock;)s=s.left,!s.deleted&&s.countable&&(n-=s.length);return null!==i&&Kh(i.index-n)<s.parent.length/80?(jc(i,s,n),i):((t,e,i)=>{if(t.length>=80){const s=t.reduce(((t,e)=>t.timestamp<e.timestamp?t:e));return jc(s,e,i),s}{const s=new Uc(e,i);return t.push(s),s}})(t._searchMarker,s,n)},Nc=(t,e,i)=>{for(let s=t.length-1;s>=0;s--){const n=t[s];if(i>0){let e=n.p;for(e.marker=!1;e&&(e.deleted||!e.countable);)e=e.left,e&&!e.deleted&&e.countable&&(n.index-=e.length);if(null===e||!0===e.marker){t.splice(s,1);continue}n.p=e,e.marker=!0}(e<n.index||i>0&&e===n.index)&&(n.index=Gh(e,n.index+i))}},Fc=(t,e,i)=>{const s=t,n=e.changedParentTypes;for(;Fh(n,t,(()=>[])).push(i),null!==t._item;)t=t._item.parent;Ha(s._eH,i,e)};class _c{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Wa(),this._dEH=Wa(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t,this._item=e}_copy(){throw No()}clone(){throw No()}_write(t){}get _first(){let t=this._start;for(;null!==t&&t.deleted;)t=t.right;return t}_callObserver(t,e){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Xa(this._eH,t)}observeDeep(t){Xa(this._dEH,t)}unobserve(t){Ja(this._eH,t)}unobserveDeep(t){Ja(this._dEH,t)}toJSON(){}}const Lc=(t,e,i)=>{t.doc??Rc(),e<0&&(e=t._length+e),i<0&&(i=t._length+i);let s=i-e;const n=[];let r=t._start;for(;null!==r&&s>0;){if(r.countable&&!r.deleted){const t=r.content.getContent();if(t.length<=e)e-=t.length;else{for(let i=e;i<t.length&&s>0;i++)n.push(t[i]),s--;e=0}}r=r.right}return n},zc=t=>{t.doc??Rc();const e=[];let i=t._start;for(;null!==i;){if(i.countable&&!i.deleted){const t=i.content.getContent();for(let i=0;i<t.length;i++)e.push(t[i])}i=i.right}return e},Yc=(t,e)=>{let i=0,s=t._start;for(t.doc??Rc();null!==s;){if(s.countable&&!s.deleted){const n=s.content.getContent();for(let s=0;s<n.length;s++)e(n[s],i++,t)}s=s.right}},Wc=(t,e)=>{const i=[];return Yc(t,((s,n)=>{i.push(e(s,n,t))})),i},Xc=t=>{let e=t._start,i=null,s=0;return{[Symbol.iterator](){return this},next:()=>{if(null===i){for(;null!==e&&e.deleted;)e=e.right;if(null===e)return{done:!0,value:void 0};i=e.content.getContent(),s=0,e=e.right}const t=i[s++];return i.length<=s&&(i=null),{done:!1,value:t}}}},Jc=(t,e)=>{t.doc??Rc();const i=Bc(t,e);let s=t._start;for(null!==i&&(s=i.p,e-=i.index);null!==s;s=s.right)if(!s.deleted&&s.countable){if(e<s.length)return s.content.getContent()[e];e-=s.length}},Hc=(t,e,i,s)=>{let n=i;const r=t.doc,h=r.clientID,o=r.store,l=null===i?e._start:i.right;let u=[];const a=()=>{u.length>0&&(n=new id(Ka(h,ic(o,h)),n,n&&n.lastId,l,l&&l.id,e,null,new _f(u)),n.integrate(t,0),u=[])};s.forEach((i=>{if(null===i)u.push(i);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:u.push(i);break;default:switch(a(),i.constructor){case Uint8Array:case ArrayBuffer:n=new id(Ka(h,ic(o,h)),n,n&&n.lastId,l,l&&l.id,e,null,new Pf(new Uint8Array(i))),n.integrate(t,0);break;case Ca:n=new id(Ka(h,ic(o,h)),n,n&&n.lastId,l,l&&l.id,e,null,new Uf(i)),n.integrate(t,0);break;default:if(!(i instanceof _c))throw new Error("Unexpected content type in insert operation");n=new id(Ka(h,ic(o,h)),n,n&&n.lastId,l,l&&l.id,e,null,new Kf(i)),n.integrate(t,0)}}})),a()},Vc=()=>Bo("Length exceeded!"),Qc=(t,e,i,s)=>{if(i>e._length)throw Vc();if(0===i)return e._searchMarker&&Nc(e._searchMarker,i,s.length),Hc(t,e,null,s);const n=i,r=Bc(e,i);let h=e._start;for(null!==r&&(h=r.p,0==(i-=r.index)&&(h=h.prev,i+=h&&h.countable&&!h.deleted?h.length:0));null!==h;h=h.right)if(!h.deleted&&h.countable){if(i<=h.length){i<h.length&&oc(t,Ka(h.id.client,h.id.clock+i));break}i-=h.length}return e._searchMarker&&Nc(e._searchMarker,n,s.length),Hc(t,e,h,s)},Kc=(t,e,i,s)=>{if(0===s)return;const n=i,r=s,h=Bc(e,i);let o=e._start;for(null!==h&&(o=h.p,i-=h.index);null!==o&&i>0;o=o.right)!o.deleted&&o.countable&&(i<o.length&&oc(t,Ka(o.id.client,o.id.clock+i)),i-=o.length);for(;s>0&&null!==o;)o.deleted||(s<o.length&&oc(t,Ka(o.id.client,o.id.clock+s)),o.delete(t),s-=o.length),o=o.right;if(s>0)throw Vc();e._searchMarker&&Nc(e._searchMarker,n,-r+s)},qc=(t,e,i)=>{const s=e._map.get(i);void 0!==s&&s.delete(t)},Gc=(t,e,i,s)=>{const n=e._map.get(i)||null,r=t.doc,h=r.clientID;let o;if(null==s)o=new _f([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:o=new _f([s]);break;case Uint8Array:o=new Pf(s);break;case Ca:o=new Uf(s);break;default:if(!(s instanceof _c))throw new Error("Unexpected content type");o=new Kf(s)}new id(Ka(h,ic(r.store,h)),n,n&&n.lastId,null,null,e,i,o).integrate(t,0)},Zc=(t,e)=>{t.doc??Rc();const i=t._map.get(e);return void 0===i||i.deleted?void 0:i.content.getContent()[i.length-1]},tf=t=>{const e={};return t.doc??Rc(),t._map.forEach(((t,i)=>{t.deleted||(e[i]=t.content.getContent()[t.length-1])})),e},ef=(t,e)=>{t.doc??Rc();const i=t._map.get(e);return void 0!==i&&!i.deleted},sf=t=>{return t.doc??Rc(),e=t._map.entries(),i=t=>!t[1].deleted,da((()=>{let t;do{t=e.next()}while(!t.done&&!i(t.value));return t}));var e,i};class nf extends $c{}class rf extends _c{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const e=new rf;return e.push(t),e}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new rf}clone(){const t=new rf;return t.insert(0,this.toArray().map((t=>t instanceof _c?t.clone():t))),t}get length(){return this.doc??Rc(),this._length}_callObserver(t,e){super._callObserver(t,e),Fc(this,t,new nf(this,t))}insert(t,e){null!==this.doc?wc(this.doc,(i=>{Qc(i,this,t,e)})):this._prelimContent.splice(t,0,...e)}push(t){null!==this.doc?wc(this.doc,(e=>{((t,e,i)=>{let s=(e._searchMarker||[]).reduce(((t,e)=>e.index>t.index?e:t),{index:0,p:e._start}).p;if(s)for(;s.right;)s=s.right;Hc(t,e,s,i)})(e,this,t)})):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){null!==this.doc?wc(this.doc,(i=>{Kc(i,this,t,e)})):this._prelimContent.splice(t,e)}get(t){return Jc(this,t)}toArray(){return zc(this)}slice(t=0,e=this.length){return Lc(this,t,e)}toJSON(){return this.map((t=>t instanceof _c?t.toJSON():t))}map(t){return Wc(this,t)}forEach(t){Yc(this,t)}[Symbol.iterator](){return Xc(this)}_write(t){t.writeTypeRef(Yf)}}class hf extends $c{constructor(t,e,i){super(t,e),this.keysChanged=i}}class of extends _c{constructor(t){super(),this._prelimContent=null,this._prelimContent=void 0===t?new Map:new Map(t)}_integrate(t,e){super._integrate(t,e),this._prelimContent.forEach(((t,e)=>{this.set(e,t)})),this._prelimContent=null}_copy(){return new of}clone(){const t=new of;return this.forEach(((e,i)=>{t.set(i,e instanceof _c?e.clone():e)})),t}_callObserver(t,e){Fc(this,t,new hf(this,t,e))}toJSON(){this.doc??Rc();const t={};return this._map.forEach(((e,i)=>{if(!e.deleted){const s=e.content.getContent()[e.length-1];t[i]=s instanceof _c?s.toJSON():s}})),t}get size(){return[...sf(this)].length}keys(){return pa(sf(this),(t=>t[0]))}values(){return pa(sf(this),(t=>t[1].content.getContent()[t[1].length-1]))}entries(){return pa(sf(this),(t=>[t[0],t[1].content.getContent()[t[1].length-1]]))}forEach(t){this.doc??Rc(),this._map.forEach(((e,i)=>{e.deleted||t(e.content.getContent()[e.length-1],i,this)}))}[Symbol.iterator](){return this.entries()}delete(t){null!==this.doc?wc(this.doc,(e=>{qc(e,this,t)})):this._prelimContent.delete(t)}set(t,e){return null!==this.doc?wc(this.doc,(i=>{Gc(i,this,t,e)})):this._prelimContent.set(t,e),e}get(t){return Zc(this,t)}has(t){return ef(this,t)}clear(){null!==this.doc?wc(this.doc,(t=>{this.forEach((function(e,i,s){qc(t,s,i)}))})):this._prelimContent.clear()}_write(t){t.writeTypeRef(Wf)}}const lf=(t,e)=>t===e||"object"==typeof t&&"object"==typeof e&&t&&e&&((t,e)=>t===e||yl(t)===yl(e)&&vl(t,((t,i)=>(void 0!==t||bl(e,i))&&pl(e[i],t))))(t,e);class uf{constructor(t,e,i,s){this.left=t,this.right=e,this.index=i,this.currentAttributes=s}forward(){null===this.right&&Fo(),this.right.content.constructor===Bf?this.right.deleted||df(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const af=(t,e,i)=>{for(;null!==e.right&&i>0;)e.right.content.constructor===Bf?e.right.deleted||df(e.currentAttributes,e.right.content):e.right.deleted||(i<e.right.length&&oc(t,Ka(e.right.id.client,e.right.id.clock+i)),e.index+=e.right.length,i-=e.right.length),e.left=e.right,e.right=e.right.right;return e},cf=(t,e,i,s)=>{const n=new Map,r=s?Bc(e,i):null;if(r){const e=new uf(r.p.left,r.p,r.index,n);return af(t,e,i-r.index)}{const s=new uf(null,e._start,0,n);return af(t,s,i)}},ff=(t,e,i,s)=>{for(;null!==i.right&&(!0===i.right.deleted||i.right.content.constructor===Bf&&lf(s.get(i.right.content.key),i.right.content.value));)i.right.deleted||s.delete(i.right.content.key),i.forward();const n=t.doc,r=n.clientID;s.forEach(((s,h)=>{const o=i.left,l=i.right,u=new id(Ka(r,ic(n.store,r)),o,o&&o.lastId,l,l&&l.id,e,null,new Bf(h,s));u.integrate(t,0),i.right=u,i.forward()}))},df=(t,e)=>{const{key:i,value:s}=e;null===s?t.delete(i):t.set(i,s)},pf=(t,e)=>{for(;null!==t.right&&(t.right.deleted||t.right.content.constructor===Bf&&lf(e[t.right.content.key]??null,t.right.content.value));)t.forward()},wf=(t,e,i,s)=>{const n=t.doc,r=n.clientID,h=new Map;for(const o in s){const l=s[o],u=i.currentAttributes.get(o)??null;if(!lf(u,l)){h.set(o,u);const{left:s,right:a}=i;i.right=new id(Ka(r,ic(n.store,r)),s,s&&s.lastId,a,a&&a.id,e,null,new Bf(o,l)),i.right.integrate(t,0),i.forward()}}return h},gf=(t,e,i,s,n)=>{i.currentAttributes.forEach(((t,e)=>{void 0===n[e]&&(n[e]=null)}));const r=t.doc,h=r.clientID;pf(i,n);const o=wf(t,e,i,n),l=s.constructor===String?new Lf(s):s instanceof _c?new Kf(s):new jf(s);let{left:u,right:a,index:c}=i;e._searchMarker&&Nc(e._searchMarker,i.index,l.getLength()),a=new id(Ka(h,ic(r.store,h)),u,u&&u.lastId,a,a&&a.id,e,null,l),a.integrate(t,0),i.right=a,i.index=c,i.forward(),ff(t,e,i,o)},mf=(t,e,i,s,n)=>{const r=t.doc,h=r.clientID;pf(i,n);const o=wf(t,e,i,n);t:for(;null!==i.right&&(s>0||o.size>0&&(i.right.deleted||i.right.content.constructor===Bf));){if(!i.right.deleted)switch(i.right.content.constructor){case Bf:{const{key:e,value:r}=i.right.content,h=n[e];if(void 0!==h){if(lf(h,r))o.delete(e);else{if(0===s)break t;o.set(e,r)}i.right.delete(t)}else i.currentAttributes.set(e,r);break}default:s<i.right.length&&oc(t,Ka(i.right.id.client,i.right.id.clock+s)),s-=i.right.length}i.forward()}if(s>0){let n="";for(;s>0;s--)n+="\n";i.right=new id(Ka(h,ic(r.store,h)),i.left,i.left&&i.left.lastId,i.right,i.right&&i.right.id,e,null,new Lf(n)),i.right.integrate(t,0),i.forward()}ff(t,e,i,o)},yf=(t,e,i,s,n)=>{let r=e;const h=Bh();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===Bf){const t=r.content;h.set(t.key,t)}r=r.right}let o=0,l=!1;for(;e!==r;){if(i===e&&(l=!0),!e.deleted){const i=e.content;switch(i.constructor){case Bf:{const{key:r,value:u}=i,a=s.get(r)??null;h.get(r)===i&&a!==u||(e.delete(t),o++,l||(n.get(r)??null)!==u||a===u||(null===a?n.delete(r):n.set(r,a))),l||e.deleted||df(n,i);break}}}e=e.right}return o},vf=t=>{let e=0;return wc(t.doc,(i=>{let s=t._start,n=t._start,r=Bh();const h=Nh(r);for(;n;)!1===n.deleted&&(n.content.constructor===Bf?df(h,n.content):(e+=yf(i,s,n,r,h),r=Nh(h),s=n)),n=n.right})),e},bf=t=>{const e=new Set,i=t.doc;for(const[s,n]of t.afterState.entries()){const r=t.beforeState.get(s)||0;n!==r&&uc(t,i.store.clients.get(s),r,n,(t=>{t.deleted||t.content.constructor!==Bf||t.constructor===$f||e.add(t.parent)}))}wc(i,(i=>{ma(t,t.deleteSet,(t=>{t instanceof $f||!t.parent._hasFormatting||e.has(t.parent)||(t.content.constructor===Bf?e.add(t.parent):((t,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const i=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===Bf){const s=e.content.key;i.has(s)?e.delete(t):i.add(s)}e=e.left}})(i,t))}));for(const t of e)vf(t)}))},Mf=(t,e,i)=>{const s=i,n=Nh(e.currentAttributes),r=e.right;for(;i>0&&null!==e.right;){if(!1===e.right.deleted)switch(e.right.content.constructor){case Kf:case jf:case Lf:i<e.right.length&&oc(t,Ka(e.right.id.client,e.right.id.clock+i)),i-=e.right.length,e.right.delete(t)}e.forward()}r&&yf(t,r,e.right,n,e.currentAttributes);const h=(e.left||e.right).parent;return h._searchMarker&&Nc(h._searchMarker,e.index,-s+i),e};class kf extends $c{constructor(t,e,i){super(t,e),this.childListChanged=!1,this.keysChanged=new Set,i.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=[];wc(this.target.doc,(e=>{const i=new Map,s=new Map;let n=this.target._start,r=null;const h={};let o="",l=0,u=0;const a=()=>{if(null!==r){let e=null;switch(r){case"delete":u>0&&(e={delete:u}),u=0;break;case"insert":("object"==typeof o||o.length>0)&&(e={insert:o},i.size>0&&(e.attributes={},i.forEach(((t,i)=>{null!==t&&(e.attributes[i]=t)})))),o="";break;case"retain":l>0&&(e={retain:l},(t=>{for(const e in t)return!1;return!0})(h)||(e.attributes=wl({},h))),l=0}e&&t.push(e),r=null}};for(;null!==n;){switch(n.content.constructor){case Kf:case jf:this.adds(n)?this.deletes(n)||(a(),r="insert",o=n.content.getContent()[0],a()):this.deletes(n)?("delete"!==r&&(a(),r="delete"),u+=1):n.deleted||("retain"!==r&&(a(),r="retain"),l+=1);break;case Lf:this.adds(n)?this.deletes(n)||("insert"!==r&&(a(),r="insert"),o+=n.content.str):this.deletes(n)?("delete"!==r&&(a(),r="delete"),u+=n.length):n.deleted||("retain"!==r&&(a(),r="retain"),l+=n.length);break;case Bf:{const{key:t,value:o}=n.content;if(this.adds(n)){if(!this.deletes(n)){const l=i.get(t)??null;lf(l,o)?null!==o&&n.delete(e):("retain"===r&&a(),lf(o,s.get(t)??null)?delete h[t]:h[t]=o)}}else if(this.deletes(n)){s.set(t,o);const e=i.get(t)??null;lf(e,o)||("retain"===r&&a(),h[t]=e)}else if(!n.deleted){s.set(t,o);const i=h[t];void 0!==i&&(lf(i,o)?null!==i&&n.delete(e):("retain"===r&&a(),null===o?delete h[t]:h[t]=o))}n.deleted||("insert"===r&&a(),df(i,n.content));break}}n=n.right}for(a();t.length>0;){const e=t[t.length-1];if(void 0===e.retain||void 0!==e.attributes)break;t.pop()}})),this._delta=t}return this._delta}}class Af extends _c{constructor(t){super(),this._pending=void 0!==t?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Rc(),this._length}_integrate(t,e){super._integrate(t,e);try{this._pending.forEach((t=>t()))}catch(t){console.error(t)}this._pending=null}_copy(){return new Af}clone(){const t=new Af;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);const i=new kf(this,t,e);Fc(this,t,i),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??Rc();let t="",e=this._start;for(;null!==e;)!e.deleted&&e.countable&&e.content.constructor===Lf&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){null!==this.doc?wc(this.doc,(i=>{const s=new uf(null,this._start,0,new Map);for(let n=0;n<t.length;n++){const r=t[n];if(void 0!==r.insert){const h=e||"string"!=typeof r.insert||n!==t.length-1||null!==s.right||"\n"!==r.insert.slice(-1)?r.insert:r.insert.slice(0,-1);("string"!=typeof h||h.length>0)&&gf(i,this,s,h,r.attributes||{})}else void 0!==r.retain?mf(i,this,s,r.retain,r.attributes||{}):void 0!==r.delete&&Mf(i,s,r.delete)}})):this._pending.push((()=>this.applyDelta(t)))}toDelta(t,e,i){this.doc??Rc();const s=[],n=new Map;let r="",h=this._start;function o(){if(r.length>0){const t={};let e=!1;n.forEach(((i,s)=>{e=!0,t[s]=i}));const i={insert:r};e&&(i.attributes=t),s.push(i),r=""}}const l=()=>{for(;null!==h;){if(Ga(h,t)||void 0!==e&&Ga(h,e))switch(h.content.constructor){case Lf:{const s=n.get("ychange");void 0===t||Ga(h,t)?void 0===e||Ga(h,e)?void 0!==s&&(o(),n.delete("ychange")):void 0!==s&&s.user===h.id.client&&"added"===s.type||(o(),n.set("ychange",i?i("added",h.id):{type:"added"})):void 0!==s&&s.user===h.id.client&&"removed"===s.type||(o(),n.set("ychange",i?i("removed",h.id):{type:"removed"})),r+=h.content.str;break}case Kf:case jf:{o();const t={insert:h.content.getContent()[0]};if(n.size>0){const e={};t.attributes=e,n.forEach(((t,i)=>{e[i]=t}))}s.push(t);break}case Bf:Ga(h,t)&&(o(),df(n,h.content))}h=h.right}o()};return t||e?wc(this.doc,(i=>{t&&Za(i,t),e&&Za(i,e),l()}),"cleanup"):l(),s}insert(t,e,i){if(e.length<=0)return;const s=this.doc;null!==s?wc(s,(s=>{const n=cf(s,this,t,!i);i||(i={},n.currentAttributes.forEach(((t,e)=>{i[e]=t}))),gf(s,this,n,e,i)})):this._pending.push((()=>this.insert(t,e,i)))}insertEmbed(t,e,i){const s=this.doc;null!==s?wc(s,(s=>{const n=cf(s,this,t,!i);gf(s,this,n,e,i||{})})):this._pending.push((()=>this.insertEmbed(t,e,i||{})))}delete(t,e){if(0===e)return;const i=this.doc;null!==i?wc(i,(i=>{Mf(i,cf(i,this,t,!0),e)})):this._pending.push((()=>this.delete(t,e)))}format(t,e,i){if(0===e)return;const s=this.doc;null!==s?wc(s,(s=>{const n=cf(s,this,t,!1);null!==n.right&&mf(s,this,n,e,i)})):this._pending.push((()=>this.format(t,e,i)))}removeAttribute(t){null!==this.doc?wc(this.doc,(e=>{qc(e,this,t)})):this._pending.push((()=>this.removeAttribute(t)))}setAttribute(t,e){null!==this.doc?wc(this.doc,(i=>{Gc(i,this,t,e)})):this._pending.push((()=>this.setAttribute(t,e)))}getAttribute(t){return Zc(this,t)}getAttributes(){return tf(this)}_write(t){t.writeTypeRef(Xf)}}class xf{constructor(t,e=()=>!0){this._filter=e,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??Rc()}[Symbol.iterator](){return this}next(){let t=this._currentNode,e=t&&t.content&&t.content.type;if(null!==t&&(!this._firstCall||t.deleted||!this._filter(e)))do{if(e=t.content.type,t.deleted||e.constructor!==Cf&&e.constructor!==Sf||null===e._start)for(;null!==t;){const e=t.next;if(null!==e){t=e;break}t=t.parent===this._root?null:t.parent._item}else t=e._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 Sf extends _c{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Sf}clone(){const t=new Sf;return t.insert(0,this.toArray().map((t=>t instanceof _c?t.clone():t))),t}get length(){return this.doc??Rc(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(t){return new xf(this,t)}querySelector(t){t=t.toUpperCase();const e=new xf(this,(e=>e.nodeName&&e.nodeName.toUpperCase()===t)).next();return e.done?null:e.value}querySelectorAll(t){return t=t.toUpperCase(),Yh(new xf(this,(e=>e.nodeName&&e.nodeName.toUpperCase()===t)))}_callObserver(t,e){Fc(this,t,new Of(this,e,t))}toString(){return Wc(this,(t=>t.toString())).join("")}toJSON(){return this.toString()}toDOM(t=document,e={},i){const s=t.createDocumentFragment();return void 0!==i&&i._createAssociation(s,this),Yc(this,(n=>{s.insertBefore(n.toDOM(t,e,i),null)})),s}insert(t,e){null!==this.doc?wc(this.doc,(i=>{Qc(i,this,t,e)})):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(null!==this.doc)wc(this.doc,(i=>{Hc(i,this,t&&t instanceof _c?t._item:t,e)}));else{const i=this._prelimContent,s=null===t?0:i.findIndex((e=>e===t))+1;if(0===s&&null!==t)throw Bo("Reference item not found");i.splice(s,0,...e)}}delete(t,e=1){null!==this.doc?wc(this.doc,(i=>{Kc(i,this,t,e)})):this._prelimContent.splice(t,e)}toArray(){return zc(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Jc(this,t)}slice(t=0,e=this.length){return Lc(this,t,e)}forEach(t){Yc(this,t)}_write(t){t.writeTypeRef(Hf)}}class Cf extends Sf{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,e){super._integrate(t,e),this._prelimAttrs.forEach(((t,e)=>{this.setAttribute(e,t)})),this._prelimAttrs=null}_copy(){return new Cf(this.nodeName)}clone(){const t=new Cf(this.nodeName);return((t,e)=>{for(const i in t)e(t[i],i)})(this.getAttributes(),((e,i)=>{t.setAttribute(i,e)})),t.insert(0,this.toArray().map((t=>t instanceof _c?t.clone():t))),t}toString(){const t=this.getAttributes(),e=[],i=[];for(const e in t)i.push(e);i.sort();const s=i.length;for(let n=0;n<s;n++){const s=i[n];e.push(s+'="'+t[s]+'"')}const n=this.nodeName.toLocaleLowerCase();return`<${n}${e.length>0?" "+e.join(" "):""}>${super.toString()}</${n}>`}removeAttribute(t){null!==this.doc?wc(this.doc,(e=>{qc(e,this,t)})):this._prelimAttrs.delete(t)}setAttribute(t,e){null!==this.doc?wc(this.doc,(i=>{Gc(i,this,t,e)})):this._prelimAttrs.set(t,e)}getAttribute(t){return Zc(this,t)}hasAttribute(t){return ef(this,t)}getAttributes(t){return t?((t,e)=>{const i={};return this._map.forEach(((t,s)=>{let n=t;for(;null!==n&&(!e.sv.has(n.id.client)||n.id.clock>=(e.sv.get(n.id.client)||0));)n=n.left;null!==n&&Ga(n,e)&&(i[s]=n.content.getContent()[n.length-1])})),i})(0,t):tf(this)}toDOM(t=document,e={},i){const s=t.createElement(this.nodeName),n=this.getAttributes();for(const t in n){const e=n[t];"string"==typeof e&&s.setAttribute(t,e)}return Yc(this,(n=>{s.appendChild(n.toDOM(t,e,i))})),void 0!==i&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(Jf),t.writeKey(this.nodeName)}}class Of extends $c{constructor(t,e,i){super(t,i),this.childListChanged=!1,this.attributesChanged=new Set,e.forEach((t=>{null===t?this.childListChanged=!0:this.attributesChanged.add(t)}))}}class Ef extends of{constructor(t){super(),this.hookName=t}_copy(){return new Ef(this.hookName)}clone(){const t=new Ef(this.hookName);return this.forEach(((e,i)=>{t.set(i,e)})),t}toDOM(t=document,e={},i){const s=e[this.hookName];let n;return n=void 0!==s?s.createDom(this):document.createElement(this.hookName),n.setAttribute("data-yjs-hook",this.hookName),void 0!==i&&i._createAssociation(n,this),n}_write(t){t.writeTypeRef(Vf),t.writeKey(this.hookName)}}class Tf extends Af{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 Tf}clone(){const t=new Tf;return t.applyDelta(this.toDelta()),t}toDOM(t=document,e,i){const s=t.createTextNode(this.toString());return void 0!==i&&i._createAssociation(s,this),s}toString(){return this.toDelta().map((t=>{const e=[];for(const i in t.attributes){const s=[];for(const e in t.attributes[i])s.push({key:e,value:t.attributes[i][e]});s.sort(((t,e)=>t.key<e.key?-1:1)),e.push({nodeName:i,attrs:s})}e.sort(((t,e)=>t.nodeName<e.nodeName?-1:1));let i="";for(let t=0;t<e.length;t++){const s=e[t];i+=`<${s.nodeName}`;for(let t=0;t<s.attrs.length;t++){const e=s.attrs[t];i+=` ${e.key}="${e.value}"`}i+=">"}i+=t.insert;for(let t=e.length-1;t>=0;t--)i+=`</${e[t].nodeName}>`;return i})).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Qf)}}class Df{constructor(t,e){this.id=t,this.length=e}get deleted(){throw No()}mergeWith(t){return!1}write(t,e,i){throw No()}integrate(t,e){throw No()}}class $f extends Df{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,e){e>0&&(this.id.clock+=e,this.length-=e),sc(t.doc.store,this)}write(t,e){t.writeInfo(0),t.writeLen(this.length-e)}getMissing(t,e){return null}}class Pf{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Pf(this.content)}splice(t){throw No()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeBuf(this.content)}getRef(){return 3}}class Rf{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Rf(this.len)}splice(t){const e=new Rf(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){Ma(t.deleteSet,e.id.client,e.id.clock,this.len),e.markDeleted()}delete(t){}gc(t){}write(t,e){t.writeLen(this.len-e)}getRef(){return 1}}const If=(t,e)=>new Ca({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class Uf{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 e={};this.opts=e,t.gc||(e.gc=!1),t.autoLoad&&(e.autoLoad=!0),null!==t.meta&&(e.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Uf(If(this.doc.guid,this.opts))}splice(t){throw No()}mergeWith(t){return!1}integrate(t,e){this.doc._item=e,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,e){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}class jf{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new jf(this.embed)}splice(t){throw No()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeJSON(this.embed)}getRef(){return 5}}class Bf{constructor(t,e){this.key=t,this.value=e}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new Bf(this.key,this.value)}splice(t){throw No()}mergeWith(t){return!1}integrate(t,e){const i=e.parent;i._searchMarker=null,i._hasFormatting=!0}delete(t){}gc(t){}write(t,e){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}class Nf{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Nf(this.arr)}splice(t){const e=new Nf(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const i=this.arr.length;t.writeLen(i-e);for(let s=e;s<i;s++){const e=this.arr[s];t.writeString(void 0===e?"undefined":JSON.stringify(e))}}getRef(){return 2}}const Ff="development"===Dl("node_env");class _f{constructor(t){this.arr=t,Ff&&kl(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new _f(this.arr)}splice(t){const e=new _f(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const i=this.arr.length;t.writeLen(i-e);for(let s=e;s<i;s++)t.writeAny(this.arr[s])}getRef(){return 8}}class Lf{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Lf(this.str)}splice(t){const e=new Lf(this.str.slice(t));this.str=this.str.slice(0,t);const i=this.str.charCodeAt(t-1);return i>=55296&&i<=56319&&(this.str=this.str.slice(0,t-1)+"�",e.str="�"+e.str.slice(1)),e}mergeWith(t){return this.str+=t.str,!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeString(0===e?this.str:this.str.slice(e))}getRef(){return 4}}const zf=[()=>new rf,()=>new of,()=>new Af,t=>new Cf(t.readKey()),()=>new Sf,t=>new Ef(t.readKey()),()=>new Tf],Yf=0,Wf=1,Xf=2,Jf=3,Hf=4,Vf=5,Qf=6;class Kf{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Kf(this.type._copy())}splice(t){throw No()}mergeWith(t){return!1}integrate(t,e){this.type._integrate(t.doc,e)}delete(t){let e=this.type._start;for(;null!==e;)e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t),e=e.right;this.type._map.forEach((e=>{e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t)})),t.changed.delete(this.type)}gc(t){let e=this.type._start;for(;null!==e;)e.gc(t,!0),e=e.right;this.type._start=null,this.type._map.forEach((e=>{for(;null!==e;)e.gc(t,!0),e=e.left})),this.type._map=new Map}write(t,e){this.type._write(t)}getRef(){return 7}}const qf=(t,e)=>{let i,s=e,n=0;do{n>0&&(s=Ka(s.client,s.clock+n)),i=rc(t,s),n=s.clock-i.id.clock,s=i.redone}while(null!==s&&i instanceof id);return{item:i,diff:n}},Gf=(t,e)=>{for(;null!==t&&t.keep!==e;)t.keep=e,t=t.parent._item},Zf=(t,e,i)=>{const{client:s,clock:n}=e.id,r=new id(Ka(s,n+i),e,Ka(s,n+i-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(i));return e.deleted&&r.markDeleted(),e.keep&&(r.keep=!0),null!==e.redone&&(r.redone=Ka(e.redone.client,e.redone.clock+i)),e.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),e.length=i,r},td=(t,e)=>Xh(t,(t=>ya(t.deletions,e))),ed=(t,e,i,s,n,r)=>{const h=t.doc,o=h.store,l=h.clientID,u=e.redone;if(null!==u)return oc(t,u);let a,c=e.parent._item,f=null;if(null!==c&&!0===c.deleted){if(null===c.redone&&(!i.has(c)||null===ed(t,c,i,s,n,r)))return null;for(;null!==c.redone;)c=oc(t,c.redone)}const d=null===c?e.parent:c.content.type;if(null===e.parentSub){for(f=e.left,a=e;null!==f;){let e=f;for(;null!==e&&e.parent._item!==c;)e=null===e.redone?null:oc(t,e.redone);if(null!==e&&e.parent._item===c){f=e;break}f=f.left}for(;null!==a;){let e=a;for(;null!==e&&e.parent._item!==c;)e=null===e.redone?null:oc(t,e.redone);if(null!==e&&e.parent._item===c){a=e;break}a=a.right}}else if(a=null,e.right&&!n){for(f=e;null!==f&&null!==f.right&&(f.right.redone||ya(s,f.right.id)||td(r.undoStack,f.right.id)||td(r.redoStack,f.right.id));)for(f=f.right;f.redone;)f=oc(t,f.redone);if(f&&null!==f.right)return null}else f=d._map.get(e.parentSub)||null;const p=ic(o,l),w=Ka(l,p),g=new id(w,f,f&&f.lastId,a,a&&a.id,d,e.parentSub,e.content.copy());return e.redone=w,Gf(g,!0),g.integrate(t,0),g};class id extends Df{constructor(t,e,i,s,n,r,h,o){super(t,o.getLength()),this.origin=i,this.left=e,this.right=s,this.rightOrigin=n,this.parent=r,this.parentSub=h,this.redone=null,this.content=o,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,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=ic(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=ic(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Va&&this.id.client!==this.parent.client&&this.parent.clock>=ic(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=lc(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=oc(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===$f||this.right&&this.right.constructor===$f)this.parent=null;else if(this.parent){if(this.parent.constructor===Va){const t=rc(e,this.parent);this.parent=t.constructor===$f?null:t.content.type}}else this.left&&this.left.constructor===id?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===id&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=lc(t,t.doc.store,Ka(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(e),this.length-=e),this.parent){if(!this.left&&(!this.right||null!==this.right.left)||this.left&&this.left.right!==this.right){let e,i=this.left;if(null!==i)e=i.right;else if(null!==this.parentSub)for(e=this.parent._map.get(this.parentSub)||null;null!==e&&null!==e.left;)e=e.left;else e=this.parent._start;const s=new Set,n=new Set;for(;null!==e&&e!==this.right;){if(n.add(e),s.add(e),Qa(this.origin,e.origin)){if(e.id.client<this.id.client)i=e,s.clear();else if(Qa(this.rightOrigin,e.rightOrigin))break}else{if(null===e.origin||!n.has(rc(t.doc.store,e.origin)))break;s.has(rc(t.doc.store,e.origin))||(i=e,s.clear())}e=e.right}this.left=i}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),sc(t.doc.store,this),this.content.integrate(t,this),fc(t,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(t)}else new $f(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:Ka(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Qa(t.origin,this.lastId)&&this.right===t&&Qa(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 e=this.parent._searchMarker;return e&&e.forEach((e=>{e.p===t&&(e.p=this,!this.deleted&&this.countable&&(e.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 e=this.parent;this.countable&&null===this.parentSub&&(e._length-=this.length),this.markDeleted(),Ma(t.deleteSet,this.id.client,this.id.clock,this.length),fc(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw Fo();this.content.gc(t),e?((t,e,i)=>{const s=t.clients.get(e.id.client);s[nc(s,e.id.clock)]=i})(t,this,new $f(this.id,this.length)):this.content=new Rf(this.length)}write(t,e){const i=e>0?Ka(this.id.client,this.id.clock+e-1):this.origin,s=this.rightOrigin,n=this.parentSub,r=31&this.content.getRef()|(null===i?0:io)|(null===s?0:eo)|(null===n?0:32);if(t.writeInfo(r),null!==i&&t.writeLeftID(i),null!==s&&t.writeRightID(s),null===i&&null===s){const e=this.parent;if(void 0!==e._item){const i=e._item;if(null===i){const i=(t=>{for(const[e,i]of t.doc.share.entries())if(i===t)return e;throw Fo()})(e);t.writeParentInfo(!0),t.writeString(i)}else t.writeParentInfo(!1),t.writeLeftID(i.id)}else e.constructor===String?(t.writeParentInfo(!0),t.writeString(e)):e.constructor===Va?(t.writeParentInfo(!1),t.writeLeftID(e)):Fo();null!==n&&t.writeString(n)}this.content.write(t,e)}}const sd=(t,e)=>nd[31&e](t),nd=[()=>{Fo()},t=>new Rf(t.readLen()),t=>{const e=t.readLen(),i=[];for(let s=0;s<e;s++){const e=t.readString();i.push("undefined"===e?void 0:JSON.parse(e))}return new Nf(i)},t=>new Pf(t.readBuf()),t=>new Lf(t.readString()),t=>new jf(t.readJSON()),t=>new Bf(t.readKey(),t.readJSON()),t=>new Kf(zf[t.readTypeRef()](t)),t=>{const e=t.readLen(),i=[];for(let s=0;s<e;s++)i.push(t.readAny());return new _f(i)},t=>new Uf(If(t.readString(),t.readAny())),()=>{Fo()}];class rd extends Df{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,e){Fo()}write(t,e){t.writeInfo(10),Mo(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const hd="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},od="__ $YJS$ __";!0===hd[od]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),hd[od]=!0;const ld=t=>ol(((e,i)=>{t.onerror=t=>i(new Error(t.target.error)),t.onsuccess=t=>e(t.target.result)})),ud=(t,e,i="readwrite")=>{const s=t.transaction(e,i);return e.map((t=>pd(s,t)))},ad=(t,e)=>ld(t.count(e)),cd=(t,e)=>ld(t.delete(e)),fd=(t,e)=>ld(t.add(e)),dd=(t,e,i,s="next")=>((t,e)=>ol(((i,s)=>{t.onerror=s,t.onsuccess=async t=>{const s=t.target.result;if(null===s||!1===await e(s))return i();s.continue()}})))(t.openKeyCursor(e,s),(t=>i(t.key))),pd=(t,e)=>t.objectStore(e),wd="custom",gd="updates",md=(t,e=()=>{},i=()=>{})=>{const[s]=ud(t.db,[gd]);return(n=s,h=t._dbref,r=IDBKeyRange.lowerBound(h,false),ld(n.getAll(r,undefined))).then((n=>{t._destroyed||(e(s),wc(t.doc,(()=>{n.forEach((e=>Ba(t.doc,e)))}),t,!1),i(s))})).then((()=>((t,e=null)=>((t,e)=>{let i=null;return dd(t,e,(t=>(i=t,!1)),"prev").then((()=>i))})(t,e))(s).then((e=>{t._dbref=e+1})))).then((()=>ad(s).then((e=>{t._dbsize=e})))).then((()=>s));var n,r,h};class yd extends Vh{constructor(t,e){super(),this.doc=e,this.name=t,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=(t=>ol(((e,i)=>{const s=indexedDB.open(t);s.onupgradeneeded=t=>(t=>[["updates",{autoIncrement:!0}],["custom"]].forEach((e=>t.createObjectStore.apply(t,e))))(t.target.result),s.onerror=t=>i(Bo(t.target.error)),s.onsuccess=t=>{const i=t.target.result;i.onversionchange=()=>{i.close()},e(i)}})))(t),this.whenSynced=ol((t=>this.on("synced",(()=>t(this))))),this._db.then((t=>{this.db=t,md(this,(t=>fd(t,Fa(e))),(()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])}))})),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(t,e)=>{if(this.db&&e!==this){const[e]=ud(this.db,[gd]);fd(e,t),++this._dbsize>=500&&(null!==this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout((()=>{((t,e=!0)=>{md(t).then((i=>{(e||t._dbsize>=500)&&fd(i,Fa(t.doc)).then((()=>cd(i,IDBKeyRange.upperBound(t._dbref,!0)))).then((()=>ad(i).then((e=>{t._dbsize=e}))))}))})(this,!1),this._storeTimeoutId=null}),this._storeTimeout))}},e.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),e.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((()=>{ld(indexedDB.deleteDatabase(this.name))}))}get(t){return this._db.then((e=>{const[i]=ud(e,[wd],"readonly");return((t,e)=>ld(t.get(e)))(i,t)}))}set(t,e){return this._db.then((i=>{const[s]=ud(i,[wd]);return((t,e,i)=>ld(t.put(e,i)))(s,e,t)}))}del(t){return this._db.then((e=>{const[i]=ud(e,[wd]);return cd(i,t)}))}}class vd{provider;isConnected=!1;constructor(t,e,i){this.provider=new yd(i?.name||t,e)}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 bd=Math.floor,Md=127,kd=Number.MAX_SAFE_INTEGER,Ad="undefined"!=typeof TextEncoder?new TextEncoder:null,xd=Ad?t=>Ad.encode(t):t=>{const e=unescape(encodeURIComponent(t)),i=e.length,s=new Uint8Array(i);for(let t=0;t<i;t++)s[t]=e.codePointAt(t);return s};let Sd="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Sd&&1===Sd.decode(new Uint8Array).length&&(Sd=null);const Cd=(t,e)=>{const i=t.cbuf.length;t.cpos===i&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*i),t.cpos=0),t.cbuf[t.cpos++]=e},Od=(t,e)=>{for(;e>Md;)Cd(t,128|Md&e),e=bd(e/128);Cd(t,Md&e)},Ed=new Uint8Array(3e4),Td=Ed.length/3,Dd=Ad&&Ad.encodeInto?(t,e)=>{if(e.length<Td){const i=Ad.encodeInto(e,Ed).written||0;Od(t,i);for(let e=0;e<i;e++)Cd(t,Ed[e])}else $d(t,xd(e))}:(t,e)=>{const i=unescape(encodeURIComponent(e)),s=i.length;Od(t,s);for(let e=0;e<s;e++)Cd(t,i.codePointAt(e))},$d=(t,e)=>{Od(t,e.byteLength),((t,e)=>{const i=t.cbuf.length,s=t.cpos,n=((t,e)=>t<e?t:e)(i-s,e.length),r=e.length-n;t.cbuf.set(e.subarray(0,n),s),t.cpos+=n,r>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(((t,e)=>t>e?t:e)(2*i,r)),t.cbuf.set(e.subarray(n)),t.cpos=r)})(t,e)},Pd=t=>new Error(t),Rd=Pd("Unexpected end of array"),Id=Pd("Integer out of Range"),Ud=t=>t.arr[t.pos++],jd=t=>{let e=0,i=1;const s=t.arr.length;for(;t.pos<s;){const s=t.arr[t.pos++];if(e+=(s&Md)*i,i*=128,s<128)return e;if(e>kd)throw Id}throw Rd},Bd=Sd?t=>Sd.decode((t=>((t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,i})(t,jd(t)))(t)):t=>{let e=jd(t);if(0===e)return"";{let i=String.fromCodePoint(Ud(t));if(--e<100)for(;e--;)i+=String.fromCodePoint(Ud(t));else for(;e>0;){const s=e<1e4?e:1e4,n=t.arr.subarray(t.pos,t.pos+s);t.pos+=s,i+=String.fromCodePoint.apply(null,n),e-=s}return decodeURIComponent(escape(i))}};var Nd;!function(t){t[t.Token=0]="Token",t[t.PermissionDenied=1]="PermissionDenied",t[t.Authenticated=2]="Authenticated"}(Nd||(Nd={}));const Fd=t=>Array.from(t.entries()).map((([t,e])=>({clientId:t,...e})));var _d;async function Ld(t){return new Promise((e=>setTimeout(e,t)))}function zd(t,e){let i=e.delay;if(0===i)return 0;if(e.factor&&(i*=Math.pow(e.factor,t.attemptNum-1),0!==e.maxDelay&&(i=Math.min(i,e.maxDelay))),e.jitter){const t=Math.ceil(e.minDelay),s=Math.floor(i);i=Math.floor(Math.random()*(s-t+1))+t}return Math.round(i)}!function(t){t[t.Connecting=0]="Connecting",t[t.Open=1]="Open",t[t.Closing=2]="Closing",t[t.Closed=3]="Closed"}(_d||(_d={}));const Yd=Math.floor,Wd=128,Xd=127,Jd=Number.MAX_SAFE_INTEGER,Hd=()=>new Set,Vd=Array.from,Qd="undefined"!=typeof TextEncoder?new TextEncoder:null,Kd=Qd?t=>Qd.encode(t):t=>{const e=unescape(encodeURIComponent(t)),i=e.length,s=new Uint8Array(i);for(let t=0;t<i;t++)s[t]=e.codePointAt(t);return s};let qd="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});qd&&1===qd.decode(new Uint8Array).length&&(qd=null);class Gd{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Zd=()=>new Gd,tp=t=>{let e=t.cpos;for(let i=0;i<t.bufs.length;i++)e+=t.bufs[i].length;return e},ep=t=>{const e=new Uint8Array(tp(t));let i=0;for(let s=0;s<t.bufs.length;s++){const n=t.bufs[s];e.set(n,i),i+=n.length}return e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),i),e},ip=(t,e)=>{const i=t.cbuf.length;t.cpos===i&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*i),t.cpos=0),t.cbuf[t.cpos++]=e},sp=(t,e)=>{for(;e>Xd;)ip(t,Wd|Xd&e),e=Yd(e/128);ip(t,Xd&e)},np=new Uint8Array(3e4),rp=np.length/3,hp=Qd&&Qd.encodeInto?(t,e)=>{if(e.length<rp){const i=Qd.encodeInto(e,np).written||0;sp(t,i);for(let e=0;e<i;e++)ip(t,np[e])}else op(t,Kd(e))}:(t,e)=>{const i=unescape(encodeURIComponent(e)),s=i.length;sp(t,s);for(let e=0;e<s;e++)ip(t,i.codePointAt(e))},op=(t,e)=>{sp(t,e.byteLength),((t,e)=>{const i=t.cbuf.length,s=t.cpos,n=((t,e)=>t<e?t:e)(i-s,e.length),r=e.length-n;t.cbuf.set(e.subarray(0,n),s),t.cpos+=n,r>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(((t,e)=>t>e?t:e)(2*i,r)),t.cbuf.set(e.subarray(n)),t.cpos=r)})(t,e)},lp=t=>new Error(t),up=lp("Unexpected end of array"),ap=lp("Integer out of Range");class cp{constructor(t){this.arr=t,this.pos=0}}const fp=t=>new cp(t),dp=t=>((t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,i})(t,wp(t)),pp=t=>t.arr[t.pos++],wp=t=>{let e=0,i=1;const s=t.arr.length;for(;t.pos<s;){const s=t.arr[t.pos++];if(e+=(s&Xd)*i,i*=128,s<Wd)return e;if(e>Jd)throw ap}throw up},gp=qd?t=>qd.decode(dp(t)):t=>{let e=wp(t);if(0===e)return"";{let i=String.fromCodePoint(pp(t));if(--e<100)for(;e--;)i+=String.fromCodePoint(pp(t));else for(;e>0;){const s=e<1e4?e:1e4,n=t.arr.subarray(t.pos,t.pos+s);t.pos+=s,i+=String.fromCodePoint.apply(null,n),e-=s}return decodeURIComponent(escape(i))}},mp=Date.now,yp=()=>new Map;class vp{constructor(){this._observers=yp()}on(t,e){((t,e,i)=>{let s=t.get(e);return void 0===s&&t.set(e,s=i()),s})(this._observers,t,Hd).add(e)}once(t,e){const i=(...s)=>{this.off(t,i),e(...s)};this.on(t,i)}off(t,e){const i=this._observers.get(t);void 0!==i&&(i.delete(e),0===i.size&&this._observers.delete(t))}emit(t,e){return Vd((this._observers.get(t)||yp()).values()).forEach((t=>t(...e)))}destroy(){this._observers=yp()}}const bp=Object.keys,Mp=t=>bp(t).length,kp=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Ap=(t,e)=>{if(null==t||null==e)return((t,e)=>t===e)(t,e);if(t.constructor!==e.constructor)return!1;if(t===e)return!0;switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),e=new Uint8Array(e);case Uint8Array:if(t.byteLength!==e.byteLength)return!1;for(let i=0;i<t.length;i++)if(t[i]!==e[i])return!1;break;case Set:if(t.size!==e.size)return!1;for(const i of t)if(!e.has(i))return!1;break;case Map:if(t.size!==e.size)return!1;for(const i of t.keys())if(!e.has(i)||!Ap(t.get(i),e.get(i)))return!1;break;case Object:if(Mp(t)!==Mp(e))return!1;for(const i in t)if(!kp(t,i)||!Ap(t[i],e[i]))return!1;break;case Array:if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!Ap(t[i],e[i]))return!1;break;default:return!1}return!0};class xp extends vp{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const t=mp();null!==this.getLocalState()&&15e3<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const e=[];this.meta.forEach(((i,s)=>{s!==this.clientID&&3e4<=t-i.lastUpdated&&this.states.has(s)&&e.push(s)})),e.length>0&&Sp(this,e,"timeout")}),Yd(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 e=this.clientID,i=this.meta.get(e),s=void 0===i?0:i.clock+1,n=this.states.get(e);null===t?this.states.delete(e):this.states.set(e,t),this.meta.set(e,{clock:s,lastUpdated:mp()});const r=[],h=[],o=[],l=[];null===t?l.push(e):null==n?null!=t&&r.push(e):(h.push(e),Ap(n,t)||o.push(e)),(r.length>0||o.length>0||l.length>0)&&this.emit("change",[{added:r,updated:o,removed:l},"local"]),this.emit("update",[{added:r,updated:h,removed:l},"local"])}setLocalStateField(t,e){const i=this.getLocalState();null!==i&&this.setLocalState({...i,[t]:e})}getStates(){return this.states}}const Sp=(t,e,i)=>{const s=[];for(let i=0;i<e.length;i++){const n=e[i];if(t.states.has(n)){if(t.states.delete(n),n===t.clientID){const e=t.meta.get(n);t.meta.set(n,{clock:e.clock+1,lastUpdated:mp()})}s.push(n)}}s.length>0&&(t.emit("change",[{added:[],updated:[],removed:s},i]),t.emit("update",[{added:[],updated:[],removed:s},i]))},Cp=(t,e,i=t.states)=>{const s=e.length,n=Zd();sp(n,s);for(let r=0;r<s;r++){const s=e[r],h=i.get(s)||null,o=t.meta.get(s).clock;sp(n,s),sp(n,o),hp(n,JSON.stringify(h))}return ep(n)};class Op{constructor(){this.callbacks={}}on(t,e){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(e),this}emit(t,...e){const i=this.callbacks[t];return i&&i.forEach((t=>t.apply(this,e))),this}off(t,e){const i=this.callbacks[t];return i&&(e?this.callbacks[t]=i.filter((t=>t!==e)):delete this.callbacks[t]),this}removeAllListeners(){this.callbacks={}}}class Ep{constructor(t){this.data=t,this.encoder=Zd(),this.decoder=fp(new Uint8Array(this.data))}peekVarString(){return(t=>{const e=t.pos,i=gp(t);return t.pos=e,i})(this.decoder)}readVarUint(){return wp(this.decoder)}readVarString(){return gp(this.decoder)}readVarUint8Array(){return dp(this.decoder)}writeVarUint(t){return sp(this.encoder,t)}writeVarString(t){return hp(this.encoder,t)}writeVarUint8Array(t){return op(this.encoder,t)}length(){return tp(this.encoder)}}var Tp,Dp;!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"}(Tp||(Tp={})),function(t){t.Connecting="connecting",t.Connected="connected",t.Disconnected="disconnected"}(Dp||(Dp={}));class $p{constructor(){this.encoder=Zd()}get(t){return t.encoder}toUint8Array(){return ep(this.encoder)}}class Pp extends $p{constructor(){super(...arguments),this.type=Tp.CLOSE,this.description="Ask the server to close the connection"}get(t){return hp(this.encoder,t.documentName),sp(this.encoder,this.type),this.encoder}}class Rp extends Op{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=Dp.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=Dp.Connected,this.emit("status",{status:Dp.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=t}attach(t){this.configuration.providerMap.set(t.configuration.name,t),this.status===Dp.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===Dp.Connected&&t.onOpen(this.receivedOnOpenPayload)}detach(t){this.configuration.providerMap.has(t.configuration.name)&&(t.send(Pp,{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===Dp.Connected)return;this.cancelWebsocketRetry&&(this.cancelWebsocketRetry(),this.cancelWebsocketRetry=void 0),this.receivedOnOpenPayload=void 0,this.shouldConnect=!0;const{retryPromise:t,cancelFunc:e}=(()=>{let t=!1;const e=async function(t,e){const i=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}}(e);for(const t of["delay","initialDelay","minDelay","maxDelay","maxAttempts","timeout"]){const e=i[t];if(!Number.isInteger(e)||e<0)throw new Error(`Value for ${t} must be an integer greater than or equal to 0`)}if(i.factor.constructor!==Number||i.factor<0)throw new Error("Value for factor must be a number greater than or equal to 0");if(i.delay<i.minDelay)throw new Error(`delay cannot be less than minDelay (delay: ${i.delay}, minDelay: ${i.minDelay}`);const s={attemptNum:0,attemptsRemaining:i.maxAttempts?i.maxAttempts:-1,aborted:!1,abort(){s.aborted=!0}},n=i.calculateDelay||zd,r=i.calculateDelay?i.calculateDelay(s,i):i.initialDelay;if(r&&await Ld(r),s.attemptNum<1&&i.initialJitter){const t=n(s,i);t&&await Ld(t)}return async function e(){if(i.beforeAttempt&&i.beforeAttempt(s,i),s.aborted){const t=new Error("Attempt aborted");throw t.code="ATTEMPT_ABORTED",t}const r=async t=>{if(i.handleError&&await i.handleError(t,s,i),s.aborted||0===s.attemptsRemaining)throw t;s.attemptNum++;const r=n(s,i);return r&&await Ld(r),e()};return s.attemptsRemaining>0&&s.attemptsRemaining--,i.timeout?new Promise(((e,n)=>{const h=setTimeout((()=>{if(i.handleTimeout)try{e(i.handleTimeout(s,i))}catch(t){n(t)}else{const t=new Error(`Retry timeout (attemptNum: ${s.attemptNum}, timeout: ${i.timeout})`);t.code="ATTEMPT_TIMEOUT",n(t)}}),i.timeout);t(s,i).then((t=>{clearTimeout(h),e(t)})).catch((t=>{clearTimeout(h),r(t).then(e).catch(n)}))})):t(s,i).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:e=>{this.shouldConnect&&!t||e.abort()}}).catch((t=>{if(t&&"ATTEMPT_ABORTED"!==t.code)throw t}));return{retryPromise:e,cancelFunc:()=>{t=!0}}})();return this.cancelWebsocketRetry=e,t}attachWebSocketListeners(t,e){const{identifier:i}=t;this.webSocketHandlers[i]={message:t=>this.emit("message",t),close:t=>this.emit("close",{event:t}),open:t=>this.emit("open",t),error:t=>{e(t)}};const s=this.webSocketHandlers[t.identifier];Object.keys(s).forEach((e=>{t.addEventListener(e,s[e])}))}cleanupWebSocket(){if(!this.webSocket)return;const{identifier:t}=this.webSocket,e=this.webSocketHandlers[t];Object.keys(e).forEach((i=>{var s;null===(s=this.webSocket)||void 0===s||s.removeEventListener(i,e[i]),delete this.webSocketHandlers[t]})),this.webSocket.close(),this.webSocket=null}createWebSocketConnection(){return new Promise(((t,e)=>{this.webSocket&&(this.messageQueue=[],this.cleanupWebSocket()),this.lastMessageReceived=0,this.identifier+=1;const i=new this.configuration.WebSocketPolyfill(this.url);i.binaryType="arraybuffer",i.identifier=this.identifier,this.attachWebSocketListeners(i,e),this.webSocket=i,this.status=Dp.Connecting,this.emit("status",{status:Dp.Connecting}),this.connectionAttempt={resolve:t,reject:e}}))}onMessage(t){var e;this.resolveConnectionAttempt(),this.lastMessageReceived=mp();const i=new Ep(t.data).peekVarString();null===(e=this.configuration.providerMap.get(i))||void 0===e||e.onMessage(t)}resolveConnectionAttempt(){this.connectionAttempt&&(this.connectionAttempt.resolve(),this.connectionAttempt=null,this.status=Dp.Connected,this.emit("status",{status:Dp.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===Dp.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=mp()-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 e;(null===(e=this.webSocket)||void 0===e?void 0:e.readyState)===_d.Open?this.webSocket.send(t):this.messageQueue.push(t)}onClose({event:t}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=Dp.Disconnected,this.emit("status",{status:Dp.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 Ip=(t,e,i)=>{try{Ba(e,dp(t),i)}catch(t){console.error("Caught error while handling a Yjs update",t)}},Up=Ip;class jp{constructor(t){this.message=t}apply(t,e){const{message:i}=this,s=i.readVarUint(),n=i.length();switch(s){case Tp.Sync:this.applySyncMessage(t,e);break;case Tp.Awareness:this.applyAwarenessMessage(t);break;case Tp.Auth:this.applyAuthMessage(t);break;case Tp.QueryAwareness:this.applyQueryAwarenessMessage(t);break;case Tp.Stateless:t.receiveStateless(gp(i.decoder));break;case Tp.SyncStatus:this.applySyncStatusMessage(t,1===(t=>{let e=t.arr[t.pos++],i=63&e,s=64;const n=(64&e)>0?-1:1;if(!(e&Wd))return n*i;const r=t.arr.length;for(;t.pos<r;){if(e=t.arr[t.pos++],i+=(e&Xd)*s,s*=128,e<Wd)return n*i;if(i>Jd)throw ap}throw up})(i.decoder));break;case Tp.CLOSE:const n={code:1e3,reason:gp(i.decoder),target:t.configuration.websocketProvider.webSocket,type:"close"};t.onClose(),t.configuration.onClose({event:n}),t.forwardClose(n);break;default:throw new Error(`Can’t apply message of unknown type: ${s}`)}i.length()>n+1&&t.send($p,{encoder:i.encoder})}applySyncMessage(t,e){const{message:i}=this;i.writeVarUint(Tp.Sync);const s=((t,e,i,s)=>{const n=wp(t);switch(n){case 0:((t,e,i)=>{((t,e,i)=>{sp(t,1),op(t,Fa(e,i))})(e,i,dp(t))})(t,e,i);break;case 1:Ip(t,i,s);break;case 2:Up(t,i,s);break;default:throw new Error("Unknown message type")}return n})(i.decoder,i.encoder,t.document,t);e&&1===s&&(t.synced=!0)}applySyncStatusMessage(t,e){e&&t.decrementUnsyncedChanges()}applyAwarenessMessage(t){if(!t.awareness)return;const{message:e}=this;((t,e,i)=>{const s=fp(e),n=mp(),r=[],h=[],o=[],l=[],u=wp(s);for(let e=0;e<u;e++){const e=wp(s);let i=wp(s);const u=JSON.parse(gp(s)),a=t.meta.get(e),c=t.states.get(e),f=void 0===a?0:a.clock;(f<i||f===i&&null===u&&t.states.has(e))&&(null===u?e===t.clientID&&null!=t.getLocalState()?i++:t.states.delete(e):t.states.set(e,u),t.meta.set(e,{clock:i,lastUpdated:n}),void 0===a&&null!==u?r.push(e):void 0!==a&&null===u?l.push(e):null!==u&&(Ap(u,c)||o.push(e),h.push(e)))}(r.length>0||o.length>0||l.length>0)&&t.emit("change",[{added:r,updated:o,removed:l},i]),(r.length>0||h.length>0||l.length>0)&&t.emit("update",[{added:r,updated:h,removed:l},i])})(t.awareness,e.readVarUint8Array(),t)}applyAuthMessage(t){const{message:e}=this;((t,e,i,s)=>{switch(jd(t)){case Nd.Token:e();break;case Nd.PermissionDenied:i(Bd(t));break;case Nd.Authenticated:s(Bd(t))}})(e.decoder,t.sendToken.bind(t),t.permissionDeniedHandler.bind(t),t.authenticatedHandler.bind(t))}applyQueryAwarenessMessage(t){if(!t.awareness)return;const{message:e}=this;e.writeVarUint(Tp.Awareness),e.writeVarUint8Array(Cp(t.awareness,Array.from(t.awareness.getStates().keys())))}}class Bp{constructor(t,e={}){this.message=new t,this.encoder=this.message.get(e)}create(){return ep(this.encoder)}send(t){null==t||t.send(this.create())}}class Np extends $p{constructor(){super(...arguments),this.type=Tp.Auth,this.description="Authentication"}get(t){if(void 0===t.token)throw new Error("The authentication message requires `token` as an argument.");var e,i;return hp(this.encoder,t.documentName),sp(this.encoder,this.type),i=t.token,Od(e=this.encoder,Nd.Token),Dd(e,i),this.encoder}}class Fp extends $p{constructor(){super(...arguments),this.type=Tp.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 e;return hp(this.encoder,t.documentName),sp(this.encoder,this.type),e=void 0===t.states?Cp(t.awareness,t.clients):Cp(t.awareness,t.clients,t.states),op(this.encoder,e),this.encoder}}class _p extends $p{constructor(){super(...arguments),this.type=Tp.Stateless,this.description="A stateless message"}get(t){var e;return hp(this.encoder,t.documentName),sp(this.encoder,this.type),hp(this.encoder,null!==(e=t.payload)&&void 0!==e?e:""),this.encoder}}class Lp extends $p{constructor(){super(...arguments),this.type=Tp.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 hp(this.encoder,t.documentName),sp(this.encoder,this.type),((t,e)=>{sp(t,0);const i=za(e);op(t,i)})(this.encoder,t.document),this.encoder}}class zp extends $p{constructor(){super(...arguments),this.type=Tp.Sync,this.description="A document update"}get(t){var e,i;return hp(this.encoder,t.documentName),sp(this.encoder,this.type),i=t.update,sp(e=this.encoder,2),op(e,i),this.encoder}}class Yp extends Error{constructor(){super(...arguments),this.code=1001}}class Wp extends Op{constructor(t){var e,i,s;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 Ca,this.configuration.awareness=void 0!==t.awareness?t.awareness:new xp(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===(e=this.awareness)||void 0===e||e.on("update",(()=>{this.emit("awarenessUpdate",{states:Fd(this.awareness.getStates())})})),null===(i=this.awareness)||void 0===i||i.on("change",(()=>{this.emit("awarenessChange",{states:Fd(this.awareness.getStates())})})),this.document.on("update",this.boundDocumentUpdateHandler),null===(s=this.awareness)||void 0===s||s.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 e=t;this.manageSocket=!0,this.configuration.websocketProvider=new Rp({url:e.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(Lp,{document:this.document,documentName:this.configuration.name})}pageHide(){this.awareness&&Sp(this.awareness,[this.document.clientID],"page hide")}registerEventListeners(){"undefined"!=typeof window&&"addEventListener"in window&&window.addEventListener("pagehide",this.boundPageHide)}sendStateless(t){this.send(_p,{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(Np,{token:null!=t?t:"",documentName:this.configuration.name})}documentUpdateHandler(t,e){e!==this&&(this.incrementUnsyncedChanges(),this.send(zp,{update:t,documentName:this.configuration.name}))}awarenessUpdateHandler({added:t,updated:e,removed:i},s){const n=t.concat(e).concat(i);this.send(Fp,{awareness:this.awareness,clients:n,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(Lp,{document:this.document,documentName:this.configuration.name}),this.awareness&&null!==this.awareness.getLocalState()&&this.send(Fp,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.configuration.name})}send(t,e){if(!this._isAttached)return;const i=new Bp(t,e);this.emit("outgoingMessage",{message:i.message}),i.send(this.configuration.websocketProvider)}onMessage(t){const e=new Ep(t.data),i=e.readVarString();e.writeVarString(i),this.emit("message",{event:t,message:new Ep(t.data)}),new jp(e).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&Sp(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&&(Sp(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,e){if(!this.awareness)throw new Yp(`Cannot set awareness field "${t}" to ${JSON.stringify(e)}. You have disabled Awareness for this provider by explicitly passing awareness: null in the provider configuration.`);this.awareness.setLocalStateField(t,e)}}class Xp{__class__="KritzelWorkspace";id;name;createdAt;updatedAt;viewport;_core;constructor(t,e,i={translateX:0,translateY:0,scale:1}){this.id=t,this.name=e,this.createdAt=new Date,this.updatedAt=new Date,this.viewport=i}static create(t,e){const i=new Xp(e.id,e.name,e.viewport);return i._core=t,i}addObject(t){this._core.engine.addObject(t)}serialize(){return{__class__:this.__class__,id:this.id,name:this.name,createdAt:this.createdAt.toISOString(),updatedAt:this.updatedAt.toISOString(),viewport:this.viewport}}deserialize(t){return Object.assign(this,t),this.createdAt=new Date(t.createdAt),this.updatedAt=new Date(t.updatedAt),this}}const Jp={providers:[vd]};class Hp{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,e){this._core=t,this._ydoc=new Ca,this._workspacesMap=this._ydoc.getMap("workspaces");const i="kritzel-app-state",s=e??Jp;for(const t of s.providers){let e;e="function"==typeof t?new t(i,this._ydoc):t.create(i,this._ydoc),this._providers.push(e)}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 e=Array.from(t.keysChanged),i=[],s=[];e.forEach((e=>{const n=t.changes.keys.get(e);if(n&&"delete"===n.action)s.push(e);else{const t=this._workspacesMap.get(e);if(t){const e=this.reviveWorkspace(t);i.push(e)}}})),s.forEach((t=>{this.map.delete(t)})),i.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 e=new Xp(t.id,t.name,t.viewport);return e._core=this._core,e.createdAt=new Date(t.createdAt),e.updatedAt=new Date(t.updatedAt),e}transaction(t){this._ydoc&&this._ydoc.transact(t,"local")}loadFromYjs(){this._workspacesMap&&(this.map.clear(),this._workspacesMap.forEach(((t,e)=>{const i=this.reviveWorkspace(t);this.map.set(e,i)})))}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 e=t.serialize();this._ydoc.transact((()=>{this._workspacesMap.set(t.id,e)}),"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 e=t.serialize();this._ydoc.transact((()=>{this._workspacesMap.set(t.id,e)}),"local")}return!0}remove(t){const e=Array.from(this.map.values()).find(t);return!!e&&(this.map.delete(e.id),this._workspacesMap&&this._ydoc.transact((()=>{this._workspacesMap.delete(e.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 Vp{static isInstanceOf(t,e){return!!t&&t.__class__===e}}class Qp{_core;_anchorIndex=new Map;constructor(t){this._core=t}setAnchor(t,e,i){const s=this.getLineById(t);if(!s)return;if("start"===e&&s.endAnchor?.objectId===i)return;if("end"===e&&s.startAnchor?.objectId===i)return;this.removeAnchor(t,e);const n={objectId:i};"start"===e?s.startAnchor=n:s.endAnchor=n,this.addToIndex(i,t,e),this.snapEndpointToObject(s,e,i),this._core.store.state.objects.update(s)}removeAnchor(t,e){const i=this.getLineById(t);if(!i)return;const s="start"===e?i.startAnchor:i.endAnchor;s&&(this.removeFromIndex(s.objectId,t,e),"start"===e?i.startAnchor=void 0:i.endAnchor=void 0)}getAnchor(t,e){const i=this.getLineById(t);return i?("start"===e?i.startAnchor:i.endAnchor)??null:null}getLinesAnchoredTo(t){const e=this._anchorIndex.get(t);return e?Array.from(e):[]}updateAnchorsForObject(t){const e=this.getLinesAnchoredTo(t);if(0!==e.length&&this.getObjectById(t))for(const i of e){const e=this.getLineById(i.lineId);e&&this.snapEndpointToObject(e,i.endpoint,t)}}snapEndpointToObject(t,e,i){const s=this.getObjectById(i);if(!s)return;const n=this.worldToLineLocal(t,s.centerX,s.centerY);t.updateEndpoint(e,n.x,n.y)}worldToLineLocal(t,e,i){const s=e-t.centerX,n=i-t.centerY,r=Math.cos(-t.rotation),h=Math.sin(-t.rotation);return{x:(s*r-n*h+t.totalWidth/2/t.scale)*t.scale+t.x,y:(s*h+n*r+t.totalHeight/2/t.scale)*t.scale+t.y}}findSnapTarget(t,e,s,n){let r=null,h=-1/0;const o=this._core.store.allNonSelectionObjects;for(const l of o){if(l.id===s)continue;if(n&&l.id===n)continue;if(!this.isAnchorable(l))continue;const o=l.rotatedPolygon;i.isPointInPolygon({x:t,y:e},[o.topLeft,o.topRight,o.bottomRight,o.bottomLeft])&&l.zIndex>h&&(h=l.zIndex,r={objectId:l.id,centerX:l.centerX,centerY:l.centerY})}return r}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 e=t.objects[0];if(!Vp.isInstanceOf(e,"KritzelLine"))return null;const i=e,s=this.computeAnchorVisualization(i,"start"),n=this.computeAnchorVisualization(i,"end");if(!s&&!n)return null;const r=this._core.store.state.scale,h=i.strokeWidth/i.scale,o=""+2/r,l=Math.max(2*h,4/r);return{lineStrokeWidth:h,indicatorStrokeWidth:o,dashArray:`${l} ${l}`,indicatorRadius:8/r,startAnchorViz:s,endAnchorViz:n}}getSnapIndicatorRenderData(){const t=this.getSnapCandidate();if(!t)return null;const e=this._core.store.state.scale,i=8/e,s=""+2/e,n=t.lineStrokeWidth?`${t.lineStrokeWidth}`:""+4/e,r=Math.max(2*(t.lineStrokeWidth||4/e),4/e),h=`${r} ${r}`,o=t.lineStroke||"#000000";let l,u=t.edgeX,a=t.edgeY;if(t.arrowOffset&&void 0!==t.edgeX&&void 0!==t.edgeY){const e=t.lineEndpointX-t.edgeX,i=t.lineEndpointY-t.edgeY,s=Math.sqrt(e*e+i*i);s>t.arrowOffset&&(u=t.edgeX+e/s*t.arrowOffset,a=t.edgeY+i/s*t.arrowOffset);const n=t.edgeX-t.lineEndpointX,r=t.edgeY-t.lineEndpointY,h=Math.sqrt(n*n+r*r);if(h>0){const e=n/h,i=r/h,s=-i,o=t.arrowOffset,u=t.edgeX,a=t.edgeY,c=u-e*o,f=a-i*o;l=`${u},${a} ${c+s*o/2},${f+e*o/2} ${c-s*o/2},${f-e*o/2}`}}return{indicatorRadius:i,indicatorStrokeWidth:s,lineStrokeWidth:n,dashArray:h,lineStroke:o,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:l,snapLinePath:(()=>{if(void 0!==t.controlX&&void 0!==t.controlY&&void 0!==t.t){const e="start"===t.endpoint?1-t.t:t.t;if(e>=1)return;const i=this.extractQuadraticSegment({x:t.lineEndpointX,y:t.lineEndpointY},{x:t.controlX,y:t.controlY},{x:t.centerX,y:t.centerY},e,1);return`M ${i.start.x} ${i.start.y} Q ${i.control.x} ${i.control.y} ${i.end.x} ${i.end.y}`}})()}}handleObjectDeleted(t){const e=this.getLinesAnchoredTo(t);for(const t of e){this.removeAnchor(t.lineId,t.endpoint);const e=this.getLineById(t.lineId);e&&this._core.store.state.objects.update(e)}this._anchorIndex.delete(t)}handleLineDeleted(t){const e=this.getLineById(t);e&&(e.startAnchor&&this.removeFromIndex(e.startAnchor.objectId,t,"start"),e.endAnchor&&this.removeFromIndex(e.endAnchor.objectId,t,"end"))}rebuildIndex(){this._anchorIndex.clear();const t=this._core.store.allObjects;for(const e of t)e instanceof Rr&&(e.startAnchor&&this.addToIndex(e.startAnchor.objectId,e.id,"start"),e.endAnchor&&this.addToIndex(e.endAnchor.objectId,e.id,"end"))}addToIndex(t,e,i){this._anchorIndex.has(t)||this._anchorIndex.set(t,new Set);const s=this._anchorIndex.get(t);for(const t of s)if(t.lineId===e&&t.endpoint===i)return;s.add({lineId:e,endpoint:i})}removeFromIndex(t,e,i){const s=this._anchorIndex.get(t);if(s){for(const t of s)if(t.lineId===e&&t.endpoint===i){s.delete(t);break}0===s.size&&this._anchorIndex.delete(t)}}getLineById(t){const e=this._core.store.state.objects.filter((e=>e.id===t));if(0===e.length)return null;const i=e[0];return i instanceof Rr?i:null}getObjectById(t){const e=this._core.store.state.objects.filter((e=>e.id===t));return e.length>0?e[0]:null}findAnchorTarget(t,e){const i="start"===e?t.startAnchor:t.endAnchor;return i?this._core.store.allNonSelectionObjects.find((t=>t.id===i.objectId))??null:null}computeAnchorVisualization(t,e){if(!("start"===e?t.startAnchor:t.endAnchor))return null;const i=this.findAnchorTarget(t,e);if(!i)return null;const s=this.computeAnchorClipInfo(t,e,i);return s?{edgeX:s.worldX,edgeY:s.worldY,centerX:i.centerX,centerY:i.centerY,pathD:this.buildAnchorPath(t,e,s,i)??void 0}:null}computeClippedLinePath(t,e=!1){const i=this.getSnapCandidate(),s=this._core.store.selectionGroup,n=i&&s&&1===s.objects.length&&s.objects[0].id===t.id;if(!t.startAnchor&&!t.endAnchor&&!n)return e?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,h=t.endAnchor?this.findAnchorTarget(t,"end"):null;let o=r?this.computeAnchorClipInfo(t,"start",r):null,l=h?this.computeAnchorClipInfo(t,"end",h):null;if(n&&void 0!==i.edgeX&&void 0!==i.edgeY){const e=this.lineWorldToLocal(t,i.edgeX,i.edgeY),s={worldX:i.edgeX,worldY:i.edgeY,localX:e.x,localY:e.y,t:i.t};"start"===i.endpoint?o=s:l=s}const u=e?t.x:0,a=e?t.y:0;if(void 0!==t.controlX&&void 0!==t.controlY){let e=o?.t??0,i=l?.t??1;if(o&&t.hasStartArrow){const i=t.getArrowSize("start"),s=this.evaluateDerivativeSpeedAtT(t,e);s>0&&(e+=i/s)}if(l&&t.hasEndArrow){const e=t.getArrowSize("end"),s=this.evaluateDerivativeSpeedAtT(t,i);s>0&&(i-=e/s)}if(e<0&&(e=0),i>1&&(i=1),i<=e){const t=(e+i)/2;e=t,i=t}const s=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},e,i);return`M ${s.start.x-u} ${s.start.y-a} Q ${s.control.x-u} ${s.control.y-a} ${s.end.x-u} ${s.end.y-a}`}let c=o?.localX??t.startX,f=o?.localY??t.startY,d=l?.localX??t.endX,p=l?.localY??t.endY;if(o&&t.hasStartArrow){const e=t.getArrowSize("start"),i=d-c,s=p-f,n=Math.sqrt(i*i+s*s);n>e&&(c+=i/n*e,f+=s/n*e)}if(l&&t.hasEndArrow){const e=t.getArrowSize("end"),i=c-d,s=f-p,n=Math.sqrt(i*i+s*s);n>e&&(d+=i/n*e,p+=s/n*e)}return`M ${c-u} ${f-a} L ${d-u} ${p-a}`}computeAnchorClipInfo(t,e,i){return void 0!==t.controlX&&void 0!==t.controlY?this.computeCurvedClipInfo(t,e,i):this.computeStraightClipInfo(t,e,i)}computeStraightClipInfo(t,e,s){const n="start"===e?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY),r=this.getPathClipPoint(s,n);if(r){const i=this.lineWorldToLocal(t,r.x,r.y),s=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),n=Math.sqrt(Math.pow(i.x-t.startX,2)+Math.pow(i.y-t.startY,2));return{localX:i.x,localY:i.y,worldX:r.x,worldY:r.y,t:s>0?n/s:"start"===e?0:1}}const h=this.getClipPolygonForObject(s);let o;if(o=h?i.getLinePointsArrayIntersection(n,{x:s.centerX,y:s.centerY},h):i.getLinePolygonIntersection(n,{x:s.centerX,y:s.centerY},s.rotatedPolygon),!o)return null;const l=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(l.x-t.startX,2)+Math.pow(l.y-t.startY,2));return{localX:l.x,localY:l.y,worldX:o.x,worldY:o.y,t:u>0?a/u:"start"===e?0:1}}computeCurvedClipInfo(t,e,s){if(Vp.isInstanceOf(s,"KritzelPath"))return this.findCurveExitPointForPath(t,e,s);const n=this.getClipPolygonForObject(s),r=n??this.getPolygonPoints(s.rotatedPolygon),h=this.findCurveExitPoint(t,e,r);if(h)return h;const o="start"===e?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY);let l;if(l=n?i.getLinePointsArrayIntersection(o,{x:s.centerX,y:s.centerY},n):i.getLinePolygonIntersection(o,{x:s.centerX,y:s.centerY},s.rotatedPolygon),!l)return null;const u=this.lineWorldToLocal(t,l.x,l.y),a=this.approximateParameterForWorldPoint(t,l);return{localX:u.x,localY:u.y,worldX:l.x,worldY:l.y,t:a}}findCurveExitPoint(t,e,s){const n="start"===e?0:1,r=this.evaluateLineAtT(t,n);let h=i.isPointInPolygon({x:r.worldX,y:r.worldY},s),o=n;for(let n=1;n<=64;n++){const r="start"===e?n/64:1-n/64,l=this.evaluateLineAtT(t,r),u=i.isPointInPolygon({x:l.worldX,y:l.worldY},s);if(h&&!u){const e=this.refineCurveExitParameter(t,s,o,r),i=this.evaluateLineAtT(t,e);return{localX:i.localX,localY:i.localY,worldX:i.worldX,worldY:i.worldY,t:e}}h=u,o=r}return null}findCurveExitPointForPath(t,e,i){const s="start"===e?0:1,n=i.strokeWidth/i.scale/2,r=this.getPathAdjustedPoints(i);if(r.length<1)return null;const h=this.evaluateLineAtT(t,s);let o=this.isPointInPathStroke(h.worldX,h.worldY,r,n),l=s;for(let i=1;i<=64;i++){const s="start"===e?i/64:1-i/64,h=this.evaluateLineAtT(t,s),u=this.isPointInPathStroke(h.worldX,h.worldY,r,n);if(o&&!u){const e=this.refineCurveExitParameterForPath(t,r,n,l,s),i=this.evaluateLineAtT(t,e);return{localX:i.localX,localY:i.localY,worldX:i.worldX,worldY:i.worldY,t:e}}o=u,l=s}return null}refineCurveExitParameterForPath(t,e,i,s,n){let r=s,h=n;for(let s=0;s<8;s++){const s=(r+h)/2,n=this.evaluateLineAtT(t,s);this.isPointInPathStroke(n.worldX,n.worldY,e,i)?r=s:h=s}return(r+h)/2}getPathAdjustedPoints(t){return this.computePathAdjustedPoints(t)}computePathAdjustedPoints(t){if(!t.points?.length)return[];const e=t.rotation,i=Math.cos(e),s=Math.sin(e),n=t.points.map((t=>t[0])),r=t.points.map((t=>t[1])),h={x:(Math.min(...n)+Math.max(...n))/2,y:(Math.min(...r)+Math.max(...r))/2},{x:o,y:l}=h;return t.points.map((([t,e])=>{const n=t-o,r=e-l;return[o+n*i-r*s,l+n*s+r*i]})).map((([e,i])=>[Math.abs(e-t.x)/t.scale+t.translateX,Math.abs(i-t.y)/t.scale+t.translateY]))}isPointInPathStroke(t,e,i,s){if(1===i.length){const n=i[0],r=t-n[0],h=e-n[1];return Math.sqrt(r*r+h*h)<=s}for(let n=0;n<i.length-1;n++){const r=i[n],h=i[n+1];if(this.pointToSegmentDistance(t,e,r[0],r[1],h[0],h[1])<=s)return!0}return!1}pointToSegmentDistance(t,e,i,s,n,r){const h=n-i,o=r-s,l=h*h+o*o;if(0===l)return Math.sqrt((t-i)*(t-i)+(e-s)*(e-s));let u=((t-i)*h+(e-s)*o)/l;u=Math.max(0,Math.min(1,u));const a=i+u*h,c=s+u*o;return Math.sqrt((t-a)*(t-a)+(e-c)*(e-c))}refineCurveExitParameter(t,e,s,n){let r=s,h=n;for(let s=0;s<8;s++){const s=(r+h)/2,n=this.evaluateLineAtT(t,s);i.isPointInPolygon({x:n.worldX,y:n.worldY},e)?r=s:h=s}return(r+h)/2}approximateParameterForWorldPoint(t,e){let i=0,s=1/0;for(let n=0;n<=80;n++){const r=n/80,h=this.evaluateLineAtT(t,r),o=Math.hypot(h.worldX-e.x,h.worldY-e.y);o<s&&(s=o,i=r)}return i}evaluateLineAtT(t,e){const i=Math.max(0,Math.min(1,e));let s,n;if(void 0!==t.controlX&&void 0!==t.controlY){const e=1-i;s=e*e*t.startX+2*e*i*t.controlX+i*i*t.endX,n=e*e*t.startY+2*e*i*t.controlY+i*i*t.endY}else s=t.startX+(t.endX-t.startX)*i,n=t.startY+(t.endY-t.startY)*i;const r=this.lineLocalToWorld(t,s,n);return{t:i,localX:s,localY:n,worldX:r.x,worldY:r.y}}evaluateDerivativeSpeedAtT(t,e){const i=Math.max(0,Math.min(1,e));if(void 0!==t.controlX&&void 0!==t.controlY){const e=t.controlX,s=t.controlY,n=2*(1-i)*(e-t.startX)+2*i*(t.endX-e),r=2*(1-i)*(s-t.startY)+2*i*(t.endY-s);return Math.sqrt(n*n+r*r)}{const e=t.endX-t.startX,i=t.endY-t.startY;return Math.sqrt(e*e+i*i)}}extractQuadraticSegment(t,e,i,s,n){let r=Math.max(0,Math.min(1,s)),h=Math.max(0,Math.min(1,n));if(h<r){const t=r;r=h,h=t}let o={start:t,control:e,end:i};if(r>0){o=this.splitQuadraticSegment(o,r).right;const t=1-r;h=t>0?(h-r)/t:1}return h<1&&(o=this.splitQuadraticSegment(o,h).left),o}splitQuadraticSegment(t,e){const i=Math.max(0,Math.min(1,e)),s=t.start,n=t.control,r=t.end,h=this.lerpPoint(s,n,i),o=this.lerpPoint(n,r,i),l=this.lerpPoint(h,o,i);return{left:{start:s,control:h,end:l},right:{start:l,control:o,end:r}}}lerpPoint(t,e,i){return{x:t.x+(e.x-t.x)*i,y:t.y+(e.y-t.y)*i}}buildAnchorPath(t,e,i,s){if(void 0===t.controlX||void 0===t.controlY||void 0===i.t)return`M ${i.worldX} ${i.worldY} L ${s.centerX} ${s.centerY}`;const n="start"===e?0:i.t,r="start"===e?i.t:1;if(r<=n)return`M ${i.worldX} ${i.worldY} L ${s.centerX} ${s.centerY}`;const h=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},n,r);return this.buildWorldQuadraticPath(t,h,"start"===e)}buildWorldQuadraticPath(t,e,i=!1){const s=i?e.end:e.start,n=i?e.start:e.end,r=e.control,h=this.lineLocalToWorld(t,s.x,s.y),o=this.lineLocalToWorld(t,r.x,r.y),l=this.lineLocalToWorld(t,n.x,n.y);return`M ${h.x} ${h.y} Q ${o.x} ${o.y} ${l.x} ${l.y}`}getPolygonPoints(t){return[t.topLeft,t.topRight,t.bottomRight,t.bottomLeft]}getClipPolygonForObject(t){return Vp.isInstanceOf(t,"KritzelShape")?t.getClipPolygon():null}getPathClipPoint(t,e){return Vp.isInstanceOf(t,"KritzelPath")?t.getClipPoint(e):null}lineLocalToWorld(t,e,i){const s=e-t.x,n=i-t.y,r=t.totalWidth/2,h=t.totalHeight/2,o=Math.cos(t.rotation),l=Math.sin(t.rotation);return{x:((s-r)*o-(n-h)*l+r)/t.scale+t.translateX,y:((s-r)*l+(n-h)*o+h)/t.scale+t.translateY}}lineWorldToLocal(t,e,i){const s=(e-t.translateX)*t.scale,n=(i-t.translateY)*t.scale,r=t.totalWidth/2,h=t.totalHeight/2,o=Math.cos(-t.rotation),l=Math.sin(-t.rotation);return{x:(s-r)*o-(n-h)*l+r+t.x,y:(s-r)*l+(n-h)*o+h+t.y}}isAnchorable(t){return!(t instanceof Dh||t instanceof Nr)&&!(t instanceof Rr)&&t.isVisible}}const Kp={type:"pen",color:"#000000",size:16,palettes:{pen:[...Uh]}},qp={color:"#000000",size:8,fontFamily:"Arial",palette:[...Uh]},Gp={color:"#000000",size:4,palette:[...Uh],arrows:{end:{enabled:!0,style:"triangle"}}};export{Ih as $,Cl as A,qh as B,Zh as C,Rp as D,$r as E,Pr as F,Rr as G,Wp as H,Ir as I,Br as J,Sr as K,Fr as L,_r as M,bh as N,Vh as O,Mh as P,Ah as Q,jh as R,vd as S,Hp as T,Xp as U,Qp as V,Kp as W,qp as X,Gp as Y,jr as Z,Oh as _,Oo as a,t as a0,Ur as a1,r as a2,Or as a3,Uh as a4,kh as a5,n as a6,xh as a7,Dh as a8,Nr as a9,s as aa,Ca as ab,Jp as ac,vc as ad,e as ae,Vp as af,Wo as b,Ba as c,za as d,Fa as e,go as f,Yo as g,_h as h,Nl as i,Bl as j,jl as k,fl as l,Vo as m,Qh as n,cl as o,hl as p,Sl as q,Jo as r,Fh as s,yo as t,So as u,al as v,Mo as w,ml as x,Hh as y,mo as z}