kritzel-stencil 0.1.76 → 0.1.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{index-Dc7LOVhs.js → index-BRZ6e6oa.js} +1 -1
- package/dist/cjs/index.cjs.js +2 -330
- package/dist/cjs/kritzel-active-users_42.cjs.entry.js +88 -50
- package/dist/cjs/kritzel-brush-style.cjs.entry.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stencil.cjs.js +2 -2
- package/dist/cjs/{workspace.migrations-DkmVO6dE.js → workspace.migrations-sUPrO23c.js} +378 -13
- package/dist/collection/classes/objects/selection-group.class.js +2 -0
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/core/kritzel-awareness-cursors/kritzel-awareness-cursors.css +6 -1
- package/dist/collection/components/core/kritzel-awareness-cursors/kritzel-awareness-cursors.js +5 -2
- package/dist/collection/components/core/kritzel-editor/kritzel-editor.css +2 -0
- package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +16 -6
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.css +21 -0
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +24 -10
- package/dist/collection/components/ui/kritzel-login-dialog/kritzel-login-dialog.css +3 -0
- package/dist/collection/components/ui/kritzel-utility-panel/kritzel-utility-panel.css +1 -0
- package/dist/collection/configs/default-engine-config.js +1 -0
- package/dist/collection/constants/version.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/kritzel-active-users.js +1 -1
- package/dist/components/kritzel-avatar.js +1 -1
- package/dist/components/kritzel-awareness-cursors.js +1 -1
- package/dist/components/kritzel-back-to-content.js +1 -1
- package/dist/components/kritzel-brush-style.js +1 -1
- package/dist/components/kritzel-button.js +1 -1
- package/dist/components/kritzel-color-palette.js +1 -1
- package/dist/components/kritzel-color.js +1 -1
- package/dist/components/kritzel-context-menu.js +1 -1
- package/dist/components/kritzel-controls.js +1 -1
- package/dist/components/kritzel-current-user-dialog.js +1 -1
- package/dist/components/kritzel-current-user.js +1 -1
- package/dist/components/kritzel-cursor-trail.js +1 -1
- package/dist/components/kritzel-dialog.js +1 -1
- package/dist/components/kritzel-dropdown.js +1 -1
- package/dist/components/kritzel-editor.js +1 -1
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/kritzel-export.js +1 -1
- package/dist/components/kritzel-font-family.js +1 -1
- package/dist/components/kritzel-font-size.js +1 -1
- package/dist/components/kritzel-font.js +1 -1
- package/dist/components/kritzel-icon.js +1 -1
- package/dist/components/kritzel-input.js +1 -1
- package/dist/components/kritzel-line-endings.js +1 -1
- package/dist/components/kritzel-login-dialog.js +1 -1
- package/dist/components/kritzel-master-detail.js +1 -1
- package/dist/components/kritzel-menu-item.js +1 -1
- package/dist/components/kritzel-menu.js +1 -1
- package/dist/components/kritzel-more-menu.js +1 -1
- package/dist/components/kritzel-numeric-input.js +1 -1
- package/dist/components/kritzel-opacity-slider.js +1 -1
- package/dist/components/kritzel-pill-tabs.js +1 -1
- package/dist/components/kritzel-portal.js +1 -1
- package/dist/components/kritzel-settings.js +1 -1
- package/dist/components/kritzel-shape-fill.js +1 -1
- package/dist/components/kritzel-share-dialog.js +1 -1
- package/dist/components/kritzel-slide-toggle.js +1 -1
- package/dist/components/kritzel-split-button.js +1 -1
- package/dist/components/kritzel-stroke-size.js +1 -1
- package/dist/components/kritzel-tool-config.js +1 -1
- package/dist/components/kritzel-tooltip.js +1 -1
- package/dist/components/kritzel-utility-panel.js +1 -1
- package/dist/components/kritzel-workspace-manager.js +1 -1
- package/dist/components/{p-Dt-J69xt.js → p-53di1Zko.js} +1 -1
- package/dist/components/{p-DS0xx1eT.js → p-6NFl6EB2.js} +1 -1
- package/dist/components/{p-DSzQ6H2j.js → p-76W5pG2O.js} +1 -1
- package/dist/components/{p-DRbG92F9.js → p-BLsH_Oi0.js} +1 -1
- package/dist/components/p-Ban3OlgZ.js +9 -0
- package/dist/components/{p-CUkKKbnu.js → p-BrZ_gL8Q.js} +1 -1
- package/dist/components/{p-kj9wbLY8.js → p-BuI6Gkzg.js} +1 -1
- package/dist/components/{p-BeFUNGEI.js → p-BueaqfA2.js} +1 -1
- package/dist/components/{p-BiByyU2C.js → p-C2l9mZ1P.js} +1 -1
- package/dist/components/{p-CsR4owzk.js → p-C4fKLlrd.js} +1 -1
- package/dist/components/{p-BA0ayKqO.js → p-CBslLN3-.js} +1 -1
- package/dist/components/p-CHY71o5B.js +1 -0
- package/dist/components/{p-KQzWumjB.js → p-CI9Nbh-x.js} +1 -1
- package/dist/components/{p-CsoDfhD5.js → p-CN8IxBlU.js} +1 -1
- package/dist/components/{p-2OYw6GJ7.js → p-CWMFGEe0.js} +1 -1
- package/dist/components/{p-Dj_Qjga5.js → p-CYh7yV-K.js} +1 -1
- package/dist/components/{p-xM-_OeRO.js → p-Ck1dhpUQ.js} +1 -1
- package/dist/components/{p-b4gyXoju.js → p-Cns7qSKS.js} +1 -1
- package/dist/components/{p-C69Stayh.js → p-D14QNK3X.js} +1 -1
- package/dist/components/{p-iRL0wQHQ.js → p-D3pNw-SV.js} +1 -1
- package/dist/components/{p-BEJQ2kP7.js → p-D5IhryUR.js} +1 -1
- package/dist/components/{p-CZhyKp-f.js → p-D7yzmu1l.js} +1 -1
- package/dist/components/{p-HLbqRJGs.js → p-DDKjsXCe.js} +1 -1
- package/dist/components/{p-TyR-YTXm.js → p-DV7Z_qfa.js} +1 -1
- package/dist/components/{p-ByR0VXeU.js → p-DWsCbu01.js} +1 -1
- package/dist/components/{p-31FVoNWR.js → p-DaGZEV0R.js} +1 -1
- package/dist/components/{p-Da46jw3N.js → p-DkWWzVg8.js} +1 -1
- package/dist/components/{p-D1O7DxL4.js → p-Dr3-pKVg.js} +1 -1
- package/dist/components/{p-JdNoaqqb.js → p-Dte67BWd.js} +1 -1
- package/dist/components/{p-CHmi1QWx.js → p-DxzDda_J.js} +1 -1
- package/dist/components/{p-CAIGuV2J.js → p-KJ4dHzrS.js} +1 -1
- package/dist/components/{p-BiouZo1q.js → p-Lhyh6KeB.js} +1 -1
- package/dist/components/{p-CFhp1W9F.js → p-Md9Y-b3d.js} +1 -1
- package/dist/components/{p-C1uR_ZNW.js → p-ZC5YELQJ.js} +1 -1
- package/dist/components/{p-C7SBI_0T.js → p-ZQ2bKafG.js} +1 -1
- package/dist/components/{p-0kShCfeb.js → p-_QEHfsIk.js} +1 -1
- package/dist/components/{p-DXjuuVq9.js → p-gtQlsorg.js} +1 -1
- package/dist/components/{p-GYI7sDxr.js → p-l_YGO7RB.js} +1 -1
- package/dist/components/{p-DvIEvoZu.js → p-m1nVDC3G.js} +1 -1
- package/dist/components/{p-7o2FWtFx.js → p-pCC6t6BH.js} +1 -1
- package/dist/components/p-pGzF7PUB.js +1 -0
- package/dist/esm/{index-MV-81ybv.js → index-BbOHefEf.js} +1 -1
- package/dist/esm/index.js +2 -331
- package/dist/esm/kritzel-active-users_42.entry.js +88 -50
- package/dist/esm/kritzel-brush-style.entry.js +1 -1
- package/dist/esm/loader.js +2 -2
- package/dist/esm/stencil.js +3 -3
- package/dist/esm/{workspace.migrations-D48_Bqvh.js → workspace.migrations-NhRgr2_H.js} +378 -12
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/p-4a4b38e4.entry.js +9 -0
- package/dist/stencil/{p-fc21e29c.entry.js → p-98238bf9.entry.js} +1 -1
- package/dist/stencil/p-NhRgr2_H.js +1 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/types/classes/objects/selection-group.class.d.ts +1 -0
- package/dist/types/components.d.ts +4 -2
- package/dist/types/constants/version.d.ts +1 -1
- package/dist/types/interfaces/engine-state.interface.d.ts +1 -0
- package/package.json +2 -2
- package/dist/components/p-CJ2eHeoV.js +0 -1
- package/dist/components/p-jdYmu4SA.js +0 -9
- package/dist/components/p-xNwOWoiT.js +0 -1
- package/dist/stencil/p-775a7246.entry.js +0 -9
- package/dist/stencil/p-D48_Bqvh.js +0 -1
- /package/dist/components/{p-pebXO4LU.js → p-CGGiwvWZ.js} +0 -0
- /package/dist/stencil/{p-MV-81ybv.js → p-BbOHefEf.js} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{IndexeddbPersistence as t}from"y-indexeddb";import*as e from"yjs";class i{static registry={};static registerTool(t,e,i){const r=new e(i);return r.name=t,this.registry[t]=r,r}static getTool(t){return this.registry[t]||(console.warn(`Unknown tool: ${t}`),null)}static getToolByIndex(t){return Object.values(this.registry)[t]??null}}class r{static generateUUID(t=16){const e=crypto.getRandomValues(new Uint8Array(t));return Array.from(e).map((t=>"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"[t%62])).join("")}static isEmpty(t){return null==t||0===Object?.keys(t).length&&t?.constructor===Object}}class s{static doPolygonsIntersect(t,e){const i=[t.bottomLeft,t.bottomRight,t.topRight,t.topLeft],r=[e.bottomLeft,e.bottomRight,e.topRight,e.topLeft];for(const t of i)if(this.isPointInPolygon(t,r))return!0;for(const t of r)if(this.isPointInPolygon(t,i))return!0;for(let t=0;t<i.length;t++){const e=i[t],s=i[(t+1)%i.length];for(let t=0;t<r.length;t++)if(this.intersectLines(e,s,r[t],r[(t+1)%r.length]))return!0}return!1}static isPointInPolygon(t,e){let i=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){const n=e[r].x,o=e[r].y,h=e[s].y;o>t.y!=h>t.y&&t.x<(e[s].x-n)*(t.y-o)/(h-o)+n&&(i=!i)}return i}static intersectLines(t,e,i,r){const s=(e.x-t.x)*(r.y-i.y)-(e.y-t.y)*(r.x-i.x);if(0===s)return!1;const n=((i.x-t.x)*(r.y-i.y)-(i.y-t.y)*(r.x-i.x))/s,o=-((t.x-i.x)*(e.y-t.y)-(t.y-i.y)*(e.x-t.x))/s;return n>=0&&n<=1&&o>=0&&o<=1}static getLineIntersectionPoint(t,e,i,r){const s=(e.x-t.x)*(r.y-i.y)-(e.y-t.y)*(r.x-i.x);if(0===s)return null;const n=((i.x-t.x)*(r.y-i.y)-(i.y-t.y)*(r.x-i.x))/s,o=-((t.x-i.x)*(e.y-t.y)-(t.y-i.y)*(e.x-t.x))/s;return n>=0&&n<=1&&o>=0&&o<=1?{x:t.x+n*(e.x-t.x),y:t.y+n*(e.y-t.y)}:null}static getLinePolygonIntersection(t,e,i){const r=[i.topLeft,i.topRight,i.bottomRight,i.bottomLeft];let s=null,n=1/0;for(let i=0;i<r.length;i++){const o=this.getLineIntersectionPoint(t,e,r[i],r[(i+1)%r.length]);if(o){const e=Math.sqrt(Math.pow(o.x-t.x,2)+Math.pow(o.y-t.y,2));e<n&&(n=e,s=o)}}return s}static getEllipsePolygonApproximation(t,e,i,r,s=32,n=0){const o=[],h=Math.cos(n),l=Math.sin(n);for(let n=0;n<s;n++){const a=2*Math.PI*n/s,u=i*Math.cos(a),c=r*Math.sin(a);o.push({x:t+u*h-c*l,y:e+u*l+c*h})}return o}static getLinePointsArrayIntersection(t,e,i){let r=null,s=1/0;for(let n=0;n<i.length;n++){const o=this.getLineIntersectionPoint(t,e,i[n],i[(n+1)%i.length]);if(o){const e=Math.sqrt(Math.pow(o.x-t.x,2)+Math.pow(o.y-t.y,2));e<s&&(s=e,r=o)}}return r}static isPointInPolygonPoints(t,e){return this.isPointInPolygon(t,e)}}class n{__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;userId;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(){const t=this.rotatedPolygon,e=[t.topLeft.x,t.topRight.x,t.bottomRight.x,t.bottomLeft.x],i=[t.topLeft.y,t.topRight.y,t.bottomRight.y,t.bottomLeft.y],r=Math.min(...e),s=Math.max(...e),n=Math.min(...i),o=Math.max(...i);return{x:r,y:n,z:this.scale,width:s-r,height:o-n}}get rotatedPolygon(){const t=this.translateX+this.totalWidth/2/this.scale,e=this.translateY+this.totalHeight/2/this.scale,i=this.rotation,r=Math.cos(i),s=Math.sin(i),n=this.translateX,o=this.translateY,h=n+this.totalWidth/this.scale,l=o+this.totalHeight/this.scale,a=(i,n)=>({x:r*(i-t)-s*(n-e)+t,y:s*(i-t)+r*(n-e)+e});return{topLeft:a(n,o),topRight:a(h,o),bottomRight:a(h,l),bottomLeft:a(n,l)}}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 n;return e._core=t,e.zIndex=t.store.currentZIndex,e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e}mount(t){this.isMounted||(this.elementRef=t,this.isMounted=!0)}generateId(){return r.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:r,scale:s}=this._core.store.state,{x:n,y:o,width:h,height:l}=this.rotatedBoundingBox;this.updatePosition(this.translateX+((t/2-i)/s-(n+h/2)),this.translateY+((e/2-r)/s-(o+l/2)))}update(){this._core.store.state.objects.update(this)}move(t,e,i,r){const s=(e-r)/this._core.store.state.scale;this.translateX+=(t-i)/this._core.store.state.scale,this.translateY+=s,this._core.store.state.objects.update(this)}resize(t,e,i,r){i<=1||r<=1||(this.width=i,this.height=r,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:r,totalHeight:s,...n}=this,o=structuredClone(n);return i&&"object"==typeof i&&"nodeType"in i&&1===i.nodeType&&(o.element=i.cloneNode(!0)),o}deserialize(t){return Object.assign(this,t),this}isClass(t){return this.__class__===t}edit(t){}onAfterUpdate(t){}hitTest(t,e){return!0}hitTestPolygon(t){return s.doPolygonsIntersect(this.rotatedPolygon,t)}updatePosition(t,e){this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this)}}class o{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 isMobile(){return this.isIOS()||this.isAndroid()}static isFirefox(){return/firefox/i.test(navigator.userAgent)}}class h{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 r=i.target,s=o.isMobile(),n=r.height*r.scale/window.screen.height<e;t(s&&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."),()=>{}}}function l(t){this.content=t}function a(t,e,i){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:i;let s=t.child(r),n=e.child(r);if(s!=n){if(!s.sameMarkup(n))return i;if(s.isText&&s.text!=n.text){for(let t=0;s.text[t]==n.text[t];t++)i++;return i}if(s.content.size||n.content.size){let t=a(s.content,n.content,i+1);if(null!=t)return t}i+=s.nodeSize}else i+=s.nodeSize}}function u(t,e,i,r){for(let s=t.childCount,n=e.childCount;;){if(0==s||0==n)return s==n?null:{a:i,b:r};let o=t.child(--s),h=e.child(--n),l=o.nodeSize;if(o!=h){if(!o.sameMarkup(h))return{a:i,b:r};if(o.isText&&o.text!=h.text){let t=0,e=Math.min(o.text.length,h.text.length);for(;t<e&&o.text[o.text.length-t-1]==h.text[h.text.length-t-1];)t++,i--,r--;return{a:i,b:r}}if(o.content.size||h.content.size){let t=u(o.content,h.content,i-1,r-1);if(t)return t}i-=l,r-=l}else i-=l,r-=l}}l.prototype={constructor:l,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 r=i&&i!=t?this.remove(i):this,s=r.find(t),n=r.content.slice();return-1==s?n.push(i||t,e):(n[s+1]=e,i&&(n[s]=i)),new l(n)},remove:function(t){var e=this.find(t);if(-1==e)return this;var i=this.content.slice();return i.splice(e,2),new l(i)},addToStart:function(t,e){return new l([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var i=this.remove(t).content.slice();return i.push(t,e),new l(i)},addBefore:function(t,e,i){var r=this.remove(e),s=r.content.slice(),n=r.find(t);return s.splice(-1==n?s.length:n,0,e,i),new l(s)},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=l.from(t)).size?new l(t.content.concat(this.subtract(t).content)):this},append:function(t){return(t=l.from(t)).size?new l(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=l.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}},l.from=function(t){if(t instanceof l)return t;var e=[];if(t)for(var i in t)e.push(i,t[i]);return new l(e)};class c{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,r=0,s){for(let n=0,o=0;o<e;n++){let h=this.content[n],l=o+h.nodeSize;if(l>t&&!1!==i(h,r+o,s||null,n)&&h.content.size){let s=o+1;h.nodesBetween(Math.max(0,t-s),Math.min(h.content.size,e-s),i,r+s)}o=l}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,e,i,r){let s="",n=!0;return this.nodesBetween(t,e,((o,h)=>{let l=o.isText?o.text.slice(Math.max(t,h)-h,e-h):o.isLeaf?r?"function"==typeof r?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&l||o.isTextblock)&&i&&(n?n=!1:s+=i),s+=l}),0),s}append(t){if(!t.size)return this;if(!this.size)return t;let e=this.lastChild,i=t.firstChild,r=this.content.slice(),s=0;for(e.isText&&e.sameMarkup(i)&&(r[r.length-1]=e.withText(e.text+i.text),s=1);s<t.content.length;s++)r.push(t.content[s]);return new c(r,this.size+t.size)}cut(t,e=this.size){if(0==t&&e==this.size)return this;let i=[],r=0;if(e>t)for(let s=0,n=0;n<e;s++){let o=this.content[s],h=n+o.nodeSize;h>t&&((n<t||h>e)&&(o=o.isText?o.cut(Math.max(0,t-n),Math.min(o.text.length,e-n)):o.cut(Math.max(0,t-n-1),Math.min(o.content.size,e-n-1))),i.push(o),r+=o.nodeSize),n=h}return new c(i,r)}cutByIndex(t,e){return t==e?c.empty:0==t&&e==this.content.length?this:new c(this.content.slice(t,e))}replaceChild(t,e){let i=this.content[t];if(i==e)return this;let r=this.content.slice(),s=this.size+e.nodeSize-i.nodeSize;return r[t]=e,new c(r,s)}addToStart(t){return new c([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new c(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 r=this.content[e];t(r,i,e),i+=r.nodeSize}}findDiffStart(t,e=0){return a(this,t,e)}findDiffEnd(t,e=this.size,i=t.size){return u(this,t,e,i)}findIndex(t){if(0==t)return d(0,t);if(t==this.size)return d(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 r=i+this.child(e).nodeSize;if(r>=t)return r==t?d(e+1,r):d(e,i);i=r}}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 c.empty;if(!Array.isArray(e))throw new RangeError("Invalid input for Fragment.fromJSON");return new c(e.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return c.empty;let e,i=0;for(let r=0;r<t.length;r++){let s=t[r];i+=s.nodeSize,r&&s.isText&&t[r-1].sameMarkup(s)?(e||(e=t.slice(0,r)),e[e.length-1]=s.withText(e[e.length-1].text+s.text)):e&&e.push(s)}return new c(e||t,i)}static from(t){if(!t)return c.empty;if(t instanceof c)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new c([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}c.empty=new c([],0);const f={index:0,offset:0};function d(t,e){return f.index=t,f.offset=e,f}function p(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(!p(t[i],e[i]))return!1}else{for(let i in t)if(!(i in e)||!p(t[i],e[i]))return!1;for(let i in e)if(!(i in t))return!1}return!0}class g{constructor(t,e){this.type=t,this.attrs=e}addToSet(t){let e,i=!1;for(let r=0;r<t.length;r++){let s=t[r];if(this.eq(s))return t;if(this.type.excludes(s.type))e||(e=t.slice(0,r));else{if(s.type.excludes(this.type))return t;!i&&s.type.rank>this.type.rank&&(e||(e=t.slice(0,r)),e.push(this),i=!0),e&&e.push(s)}}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&&p(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 r=i.create(e.attrs);return i.checkAttrs(r.attrs),r}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 g.none;if(t instanceof g)return[t];let e=t.slice();return e.sort(((t,e)=>t.type.rank-e.type.rank)),e}}g.none=[];class w extends Error{}class m{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=y(this.content,t+this.openStart,e);return i&&new m(i,this.openStart,this.openEnd)}removeBetween(t,e){return new m(v(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 m.empty;let i=e.openStart||0,r=e.openEnd||0;if("number"!=typeof i||"number"!=typeof r)throw new RangeError("Invalid input for Slice.fromJSON");return new m(c.fromJSON(t,e.content),i,r)}static maxOpen(t,e=!0){let i=0,r=0;for(let r=t.firstChild;r&&!r.isLeaf&&(e||!r.type.spec.isolating);r=r.firstChild)i++;for(let i=t.lastChild;i&&!i.isLeaf&&(e||!i.type.spec.isolating);i=i.lastChild)r++;return new m(t,i,r)}}function v(t,e,i){let{index:r,offset:s}=t.findIndex(e),n=t.maybeChild(r),{index:o,offset:h}=t.findIndex(i);if(s==e||n.isText){if(h!=i&&!t.child(o).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(i))}if(r!=o)throw new RangeError("Removing non-flat range");return t.replaceChild(r,n.copy(v(n.content,e-s-1,i-s-1)))}function y(t,e,i,r){let{index:s,offset:n}=t.findIndex(e),o=t.maybeChild(s);if(n==e||o.isText)return r&&!r.canReplace(s,s,i)?null:t.cut(0,e).append(i).append(t.cut(e));let h=y(o.content,e-n-1,i,o);return h&&t.replaceChild(s,o.copy(h))}function k(t,e,i){if(i.openStart>t.depth)throw new w("Inserted content deeper than insertion position");if(t.depth-i.openStart!=e.depth-i.openEnd)throw new w("Inconsistent open depths");return b(t,e,i,0)}function b(t,e,i,r){let s=t.index(r),n=t.node(r);if(s==e.index(r)&&r<t.depth-i.openStart){let o=b(t,e,i,r+1);return n.copy(n.content.replaceChild(s,o))}if(i.content.size){if(i.openStart||i.openEnd||t.depth!=r||e.depth!=r){let{start:s,end:o}=function(t,e){let i=e.depth-t.openStart,r=e.node(i).copy(t.content);for(let t=i-1;t>=0;t--)r=e.node(t).copy(c.from(r));return{start:r.resolveNoCache(t.openStart+i),end:r.resolveNoCache(r.content.size-t.openEnd-i)}}(i,t);return S(n,B(t,s,o,e,r))}{let r=t.parent,s=r.content;return S(r,s.cut(0,t.parentOffset).append(i.content).append(s.cut(e.parentOffset)))}}return S(n,T(t,e,r))}function M(t,e){if(!e.type.compatibleContent(t.type))throw new w("Cannot join "+e.type.name+" onto "+t.type.name)}function x(t,e,i){let r=t.node(i);return M(r,e.node(i)),r}function C(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,r){let s=(e||t).node(i),n=0,o=e?e.index(i):s.childCount;t&&(n=t.index(i),t.depth>i?n++:t.textOffset&&(C(t.nodeAfter,r),n++));for(let t=n;t<o;t++)C(s.child(t),r);e&&e.depth==i&&e.textOffset&&C(e.nodeBefore,r)}function S(t,e){return t.type.checkContent(e),t.copy(e)}function B(t,e,i,r,s){let n=t.depth>s&&x(t,e,s+1),o=r.depth>s&&x(i,r,s+1),h=[];return A(null,t,s,h),n&&o&&e.index(s)==i.index(s)?(M(n,o),C(S(n,B(t,e,i,r,s+1)),h)):(n&&C(S(n,T(t,e,s+1)),h),A(e,i,s,h),o&&C(S(o,T(i,r,s+1)),h)),A(r,null,s,h),new c(h)}function T(t,e,i){let r=[];return A(null,t,i,r),t.depth>i&&C(S(x(t,e,i+1),T(t,e,i+1)),r),A(e,null,i,r),new c(r)}m.empty=new m(c.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],r=t.child(e);return i?t.child(e).cut(i):r}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],r=0==e?0:this.path[3*e-1]+1;for(let e=0;e<t;e++)r+=i.child(e).nodeSize;return r}marks(){let t=this.parent,e=this.index();if(0==t.content.size)return g.none;if(this.textOffset)return t.child(e).marks;let i=t.maybeChild(e-1),r=t.maybeChild(e);if(!i){let t=i;i=r,r=t}let s=i.marks;for(var n=0;n<s.length;n++)!1!==s[n].type.spec.inclusive||r&&s[n].isInSet(r.marks)||(s=s[n--].removeFromSet(s));return s}marksAcross(t){let e=this.parent.maybeChild(this.index());if(!e||!e.isInline)return null;let i=e.marks,r=t.parent.maybeChild(t.index());for(var s=0;s<i.length;s++)!1!==i[s].type.spec.inclusive||r&&i[s].isInSet(r.marks)||(i=i[s--].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 P(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=[],r=0,s=e;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(s),o=s-n;if(i.push(e,t,r+n),!o)break;if(e=e.child(t),e.isText)break;s=o-1,r+=n+1}return new O(e,i,s)}static resolveCached(t,e){let i=D.get(t);if(i)for(let t=0;t<i.elts.length;t++){let r=i.elts[t];if(r.pos==e)return r}else D.set(t,i=new E);let r=i.elts[i.i]=O.resolve(t,e);return i.i=(i.i+1)%I,r}}class E{constructor(){this.elts=[],this.i=0}}const I=12,D=new WeakMap;class P{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 $=Object.create(null);class R{constructor(t,e,i,r=g.none){this.type=t,this.attrs=e,this.marks=r,this.content=i||c.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,r=0){this.content.nodesBetween(t,e,i,r,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,r){return this.content.textBetween(t,e,i,r)}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&&p(this.attrs,e||t.defaultAttrs||$)&&g.sameSet(this.marks,i||g.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 m.empty;let r=this.resolve(t),s=this.resolve(e),n=i?0:r.sharedDepth(e),o=r.start(n),h=r.node(n).content.cut(r.pos-o,s.pos-o);return new m(h,r.depth-n,s.depth-n)}replace(t,e,i){return k(this.resolve(t),this.resolve(e),i)}nodeAt(t){for(let e=this;;){let{index:i,offset:r}=e.content.findIndex(t);if(e=e.maybeChild(i),!e)return null;if(r==t||e.isText)return e;t-=r+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 r=this.content.child(e-1);return{node:r,index:e-1,offset:i-r.nodeSize}}resolve(t){return O.resolveCached(this,t)}resolveNoCache(t){return O.resolve(this,t)}rangeHasMark(t,e,i){let r=!1;return e>t&&this.nodesBetween(t,e,(t=>(i.isInSet(t.marks)&&(r=!0),!r))),r}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()+")"),F(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=c.empty,r=0,s=i.childCount){let n=this.contentMatchAt(t).matchFragment(i,r,s),o=n&&n.matchFragment(this.content,e);if(!o||!o.validEnd)return!1;for(let t=r;t<s;t++)if(!this.type.allowsMarks(i.child(t).marks))return!1;return!0}canReplaceWith(t,e,i,r){if(r&&!this.type.allowsMarks(r))return!1;let s=this.contentMatchAt(t).matchType(i),n=s&&s.matchFragment(this.content,e);return!!n&&n.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=g.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(!g.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 r=c.fromJSON(t,e.content),s=t.nodeType(e.type).create(e.attrs,r,i);return s.type.checkAttrs(s.attrs),s}}R.prototype.text=void 0;class j extends R{constructor(t,e,i,r){if(super(t,e,null,r),!i)throw new RangeError("Empty text nodes are not allowed");this.text=i}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):F(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 j(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new j(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 F(t,e){for(let i=t.length-1;i>=0;i--)e=t[i].type.name+"("+e+")";return e}class N{constructor(t){this.validEnd=t,this.next=[],this.wrapCache=[]}static parse(t,e){let i=new U(t,e);if(null==i.next)return N.empty;let r=z(i);i.next&&i.err("Unexpected trailing text");let s=function(t){let e=Object.create(null);return function i(r){let s=[];r.forEach((e=>{t[e].forEach((({term:e,to:i})=>{if(!e)return;let r;for(let t=0;t<s.length;t++)s[t][0]==e&&(r=s[t][1]);W(t,i).forEach((t=>{r||s.push([e,r=[]]),-1==r.indexOf(t)&&r.push(t)}))}))}));let n=e[r.join(",")]=new N(r.indexOf(t.length-1)>-1);for(let t=0;t<s.length;t++){let r=s[t][1].sort(Y);n.next.push({type:s[t][0],next:e[r.join(",")]||i(r)})}return n}(W(t,0))}(function(t){let e=[[]];return s(function t(e,n){if("choice"==e.type)return e.exprs.reduce(((e,i)=>e.concat(t(i,n))),[]);if("seq"!=e.type){if("star"==e.type){let o=i();return r(n,o),s(t(e.expr,o),o),[r(o)]}if("plus"==e.type){let o=i();return s(t(e.expr,n),o),s(t(e.expr,o),o),[r(o)]}if("opt"==e.type)return[r(n)].concat(t(e.expr,n));if("range"==e.type){let o=n;for(let r=0;r<e.min;r++){let r=i();s(t(e.expr,o),r),o=r}if(-1==e.max)s(t(e.expr,o),o);else for(let n=e.min;n<e.max;n++){let n=i();r(o,n),s(t(e.expr,o),n),o=n}return[r(o)]}if("name"==e.type)return[r(n,void 0,e.value)];throw new Error("Unknown expr type")}for(let r=0;;r++){let o=t(e.exprs[r],n);if(r==e.exprs.length-1)return o;s(o,n=i())}}(t,0),i()),e;function i(){return e.push([])-1}function r(t,i,r){let s={term:r,to:i};return e[t].push(s),s}function s(t,e){t.forEach((t=>t.to=e))}}(r));return function(t,e){for(let i=0,r=[t];i<r.length;i++){let t=r[i],s=!t.validEnd,n=[];for(let e=0;e<t.next.length;e++){let{type:i,next:o}=t.next[e];n.push(i.name),!s||i.isText||i.hasRequiredAttrs()||(s=!1),-1==r.indexOf(o)&&r.push(o)}s&&e.err("Only non-generatable nodes ("+n.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(s,i),s}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 r=this;for(let s=e;r&&s<i;s++)r=r.matchType(t.child(s).type);return r}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 r=[this];return function s(n,o){let h=n.matchFragment(t,i);if(h&&(!e||h.validEnd))return c.from(o.map((t=>t.createAndFill())));for(let t=0;t<n.next.length;t++){let{type:e,next:i}=n.next[t];if(!e.isText&&!e.hasRequiredAttrs()&&-1==r.indexOf(i)){r.push(i);let t=s(i,o.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 r=i.shift(),s=r.match;if(s.matchType(t)){let t=[];for(let e=r;e.type;e=e.via)t.push(e.type);return t.reverse()}for(let t=0;t<s.next.length;t++){let{type:n,next:o}=s.next[t];n.isLeaf||n.hasRequiredAttrs()||n.name in e||r.type&&!o.validEnd||(i.push({match:n.contentMatch,type:n,via:r}),e[n.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 r=0;r<i.next.length;r++)-1==t.indexOf(i.next[r].next)&&e(i.next[r].next)}(this),t.map(((e,i)=>{let r=i+(e.validEnd?"*":" ")+" ";for(let i=0;i<e.next.length;i++)r+=(i?", ":"")+e.next[i].type.name+"->"+t.indexOf(e.next[i].next);return r})).join("\n")}}N.empty=new N(!0);class U{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 z(t){let e=[];do{e.push(L(t))}while(t.eat("|"));return 1==e.length?e[0]:{type:"choice",exprs:e}}function L(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=z(t);return t.eat(")")||t.err("Missing closing paren"),e}if(!/\W/.test(t.next)){let e=function(t,e){let i=t.nodeTypes,r=i[e];if(r)return[r];let s=[];for(let t in i){let r=i[t];r.isInGroup(e)&&s.push(r)}return 0==s.length&&t.err("No node type or group '"+e+"' found"),s}(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=X(t,e)}return e}function H(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function X(t,e){let i=H(t),r=i;return t.eat(",")&&(r="}"!=t.next?H(t):-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:i,max:r,expr:e}}function Y(t,e){return e-t}function W(t,e){let i=[];return function e(r){let s=t[r];if(1==s.length&&!s[0].term)return e(s[0].to);i.push(r);for(let t=0;t<s.length;t++){let{term:r,to:n}=s[t];r||-1!=i.indexOf(n)||e(n)}}(e),i.sort(Y)}function V(t){let e=Object.create(null);for(let i in t){let r=t[i];if(!r.hasDefault)return null;e[i]=r.default}return e}function J(t,e){let i=Object.create(null);for(let r in t){let s=e&&e[r];if(void 0===s){let e=t[r];if(!e.hasDefault)throw new RangeError("No value supplied for attribute "+r);s=e.default}i[r]=s}return i}function Q(t,e,i){for(let r in e)if(!(r in t))throw new RangeError(`Unsupported attribute ${r} for ${i} of type ${r}`);for(let i in t){let r=t[i];r.validate&&r.validate(e[i])}}function K(t,e){let i=Object.create(null);if(e)for(let r in e)i[r]=new G(t,r,e[r]);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=K(t,i.attrs),this.defaultAttrs=V(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==N.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),c.from(e),g.setFrom(i))}createChecked(t=null,e,i){return e=c.from(e),this.checkContent(e),new R(this,this.computeAttrs(t),e,g.setFrom(i))}createAndFill(t=null,e,i){if(t=this.computeAttrs(t),(e=c.from(e)).size){let t=this.contentMatch.fillBefore(e);if(!t)return null;e=t.append(e)}let r=this.contentMatch.matchFragment(e),s=r&&r.fillBefore(c.empty,!0);return s?new R(this,t,e.append(s),g.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){Q(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:g.none:t}static compile(e,i){let r=Object.create(null);e.forEach(((e,s)=>r[e]=new t(e,i,s)));let s=i.spec.topNode||"doc";if(!r[s])throw new RangeError("Schema is missing its top node type ('"+s+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let t in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};class G{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 r=i.split("|");return i=>{let s=null===i?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${s}`)}}(t,e,i.validate):i.validate}get isRequired(){return!this.hasDefault}}class Z{constructor(t,e,i,r){this.name=t,this.rank=e,this.schema=i,this.spec=r,this.attrs=K(t,r.attrs),this.excluded=null;let s=V(this.attrs);this.instance=s?new g(this,s):null}create(t=null){return!t&&this.instance?this.instance:new g(this,J(this.attrs,t))}static compile(t,e){let i=Object.create(null),r=0;return t.forEach(((t,s)=>i[t]=new Z(t,r++,e,s))),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){Q(this.attrs,t,"mark")}excludes(t){return this.excluded.indexOf(t)>-1}}class tt{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=l.from(t.nodes),e.marks=l.from(t.marks||{}),this.nodes=q.compile(this.spec.nodes,this),this.marks=Z.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],r=e.spec.content||"",s=e.spec.marks;if(e.contentMatch=i[r]||(i[r]=N.parse(r,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="_"==s?null:s?et(this,s.split(" ")):""!=s&&e.inlineContent?null:[]}for(let t in this.marks){let e=this.marks[t],i=e.spec.excludes;e.excluded=null==i?[e]:""==i?[]:et(this,i.split(" "))}this.nodeFromJSON=t=>R.fromJSON(this,t),this.markFromJSON=t=>g.fromJSON(this,t),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(t,e=null,i,r){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,r)}text(t,e){let i=this.nodes.text;return new j(i,i.defaultAttrs,t,g.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 et(t,e){let i=[];for(let r=0;r<e.length;r++){let s=e[r],n=t.marks[s],o=n;if(n)i.push(n);else for(let e in t.marks){let r=t.marks[e];("_"==s||r.spec.group&&r.spec.group.split(" ").indexOf(s)>-1)&&i.push(o=r)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return i}class it{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 lt(this,e,!1);return i.addAll(t,g.none,e.from,e.to),i.finish()}parseSlice(t,e={}){let i=new lt(this,e,!0);return i.addAll(t,g.none,e.from,e.to),m.maxOpen(i.finish())}matchTag(t,e,i){for(let r=i?this.tags.indexOf(i)+1:0;r<this.tags.length;r++){let i=this.tags[r];if(at(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,r){for(let s=r?this.styles.indexOf(r)+1:0;s<this.styles.length;s++){let r=this.styles[s],n=r.style;if(!(0!=n.indexOf(t)||r.context&&!i.matchesContext(r.context)||n.length>t.length&&(61!=n.charCodeAt(t.length)||n.slice(t.length+1)!=e))){if(r.getAttrs){let t=r.getAttrs(e);if(!1===t)continue;r.attrs=t||void 0}return r}}}static schemaRules(t){let e=[];function i(t){let i=null==t.priority?50:t.priority,r=0;for(;r<e.length;r++){let t=e[r];if((null==t.priority?50:t.priority)<i)break}e.splice(r,0,t)}for(let e in t.marks){let r=t.marks[e].spec.parseDOM;r&&r.forEach((t=>{i(t=ut(t)),t.mark||t.ignore||t.clearMark||(t.mark=e)}))}for(let e in t.nodes){let r=t.nodes[e].spec.parseDOM;r&&r.forEach((t=>{i(t=ut(t)),t.node||t.ignore||t.mark||(t.node=e)}))}return e}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new it(t,it.schemaRules(t)))}}const rt={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},st={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},nt={ol:!0,ul:!0};function ot(t,e,i){return null!=e?(e?1:0)|("full"===e?2:0):t&&"pre"==t.whitespace?3:-5&i}class ht{constructor(t,e,i,r,s,n){this.type=t,this.attrs=e,this.marks=i,this.solid=r,this.options=n,this.content=[],this.activeMarks=g.none,this.match=s||(4&n?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let e=this.type.contentMatch.fillBefore(c.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=c.from(this.content);return!t&&this.match&&(e=e.append(this.match.fillBefore(c.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&&!rt.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class lt{constructor(t,e,i){this.parser=t,this.options=e,this.isOpen=i,this.open=0,this.localPreserveWS=!1;let r,s=e.topNode,n=ot(null,e.preserveWhitespace,0)|(i?4:0);r=s?new ht(s.type,s.attrs,g.none,!0,e.topMatch||s.type.contentMatch,n):new ht(i?null:t.schema.topNodeType,null,g.none,!0,null,n),this.nodes=[r],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,r=this.top,s=2&r.options?"full":this.localPreserveWS||(1&r.options)>0,{schema:n}=this.parser;if("full"===s||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(i)){if(s)if("full"===s)i=i.replace(/\r\n?/g,"\n");else if(n.linebreakReplacement&&/[\r\n]/.test(i)&&this.top.findWrapping(n.linebreakReplacement.create())){let t=i.split(/\r?\n|\r/);for(let i=0;i<t.length;i++)i&&this.insertNode(n.linebreakReplacement.create(),e,!0),t[i]&&this.insertNode(n.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=r.content[r.content.length-1],s=t.previousSibling;(!e||s&&"BR"==s.nodeName||e.isText&&/[ \t\r\n\u000c]$/.test(e.text))&&(i=i.slice(1))}i&&this.insertNode(n.text(i),e,!/\S/.test(i)),this.findInText(t)}else this.findInside(t)}addElement(t,e,i){let r=this.localPreserveWS,s=this.top;("PRE"==t.tagName||/pre/.test(t.style&&t.style.whiteSpace))&&(this.localPreserveWS=!0);let n,o=t.nodeName.toLowerCase();nt.hasOwnProperty(o)&&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&&nt.hasOwnProperty(t)&&i?(i.appendChild(e),e=i):"li"==t?i=e:t&&(i=null)}}(t);let h=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(n=this.parser.matchTag(t,this,i));t:if(h?h.ignore:st.hasOwnProperty(o))this.findInside(t),this.ignoreFallback(t,e);else if(!h||h.skip||h.closeParent){h&&h.closeParent?this.open=Math.max(0,this.open-1):h&&h.skip.nodeType&&(t=h.skip);let i,r=this.needsBlock;if(rt.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),i=!0,s.type||(this.needsBlock=!0);else if(!t.firstChild){this.leafFallback(t,e);break t}let n=h&&h.skip?e:this.readStyles(t,e);n&&this.addAll(t,n),i&&this.sync(s),this.needsBlock=r}else{let i=this.readStyles(t,e);i&&this.addElementByRule(t,h,i,!1===h.consuming?n:void 0)}this.localPreserveWS=r}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 r=this.parser.matchedStyles[t],s=i.getPropertyValue(r);if(s)for(let t;;){let i=this.parser.matchStyle(r,s,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,r){let s,n;if(e.node)if(n=this.parser.schema.nodes[e.node],n.isLeaf)this.insertNode(n.create(e.attrs),i,"BR"==t.nodeName)||this.leafFallback(t,i);else{let t=this.enter(n,e.attrs||null,i,e.preserveWhitespace);t&&(s=!0,i=t)}else i=i.concat(this.parser.schema.marks[e.mark].create(e.attrs));let o=this.top;if(n&&n.isLeaf)this.findInside(t);else if(r)this.addElement(t,i,r);else if(e.getContent)this.findInside(t),e.getContent(t,this.parser.schema).forEach((t=>this.insertNode(t,i,!1)));else{let r=t;"string"==typeof e.contentElement?r=t.querySelector(e.contentElement):"function"==typeof e.contentElement?r=e.contentElement(t):e.contentElement&&(r=e.contentElement),this.findAround(t,r,!0),this.addAll(r,i),this.findAround(t,r,!1)}s&&this.sync(o)&&this.open--}addAll(t,e,i,r){let s=i||0;for(let n=i?t.childNodes[i]:t.firstChild,o=null==r?null:t.childNodes[r];n!=o;n=n.nextSibling,++s)this.findAtPoint(t,s),this.addDOM(n,e);this.findAtPoint(t,s)}findPlace(t,e,i){let r,s;for(let e=this.open,n=0;e>=0;e--){let o=this.nodes[e],h=o.findWrapping(t);if(h&&(!r||r.length>h.length+n)&&(r=h,s=o,!h.length))break;if(o.solid){if(i)break;n+=2}}if(!r)return null;this.sync(s);for(let t=0;t<r.length;t++)e=this.enterInner(r[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 r=this.findPlace(t,e,i);if(r){this.closeExtra();let e=this.top;e.match&&(e.match=e.match.matchType(t.type));let i=g.none;for(let s of r.concat(t.marks))(e.type?e.type.allowsMarkType(s.type):ct(s.type,t.type))&&(i=s.addToSet(i));return e.content.push(t.mark(i)),!0}return!1}enter(t,e,i,r){let s=this.findPlace(t.create(e),i,!1);return s&&(s=this.enterInner(t,e,i,!0,r)),s}enterInner(t,e,i,r=!1,s){this.closeExtra();let n=this.top;n.match=n.match&&n.match.matchType(t);let o=ot(t,s,n.options);4&n.options&&0==n.content.length&&(o|=4);let h=g.none;return i=i.filter((e=>!(n.type?n.type.allowsMarkType(e.type):ct(e.type,t))||(h=e.addToSet(h),!1))),this.nodes.push(new ht(t,e,h,r,null,o)),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 r=0;r<this.find.length;r++)null==this.find[r].pos&&1==t.nodeType&&t.contains(this.find[r].node)&&e.compareDocumentPosition(this.find[r].node)&(i?2:4)&&(this.find[r].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,r=!(this.isOpen||i&&i.parent.type!=this.nodes[0].type),s=(r?0:1)-(i?i.depth+1:0),n=(t,o)=>{for(;t>=0;t--){let h=e[t];if(""==h){if(t==e.length-1||0==t)continue;for(;o>=s;o--)if(n(t-1,o))return!0;return!1}{let t=o>0||0==o&&r?this.nodes[o].type:i&&o>=s?i.node(o-s).type:null;if(!t||t.name!=h&&!t.isInGroup(h))return!1;o--}}return!0};return n(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 at(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function ut(t){let e={};for(let i in t)e[i]=t[i];return e}function ct(t,e){let i=e.schema.nodes;for(let r in i){let s=i[r];if(!s.allowsMarkType(t))continue;let n=[],o=t=>{n.push(t);for(let i=0;i<t.edgeCount;i++){let{type:r,next:s}=t.edge(i);if(r==e)return!0;if(n.indexOf(s)<0&&o(s))return!0}};if(o(s.contentMatch))return!0}}class ft{constructor(t,e){this.nodes=t,this.marks=e}serializeFragment(t,e={},i){i||(i=pt(e).createDocumentFragment());let r=i,s=[];return t.forEach((t=>{if(s.length||t.marks.length){let i=0,n=0;for(;i<s.length&&n<t.marks.length;){let e=t.marks[n];if(this.marks[e.type.name]){if(!e.eq(s[i][0])||!1===e.type.spec.spanning)break;i++,n++}else n++}for(;i<s.length;)r=s.pop()[1];for(;n<t.marks.length;){let i=t.marks[n++],o=this.serializeMark(i,t.isInline,e);o&&(s.push([i,r]),r.appendChild(o.dom),r=o.contentDOM||o.dom)}}r.appendChild(this.serializeNodeInner(t,e))})),i}serializeNodeInner(t,e){let{dom:i,contentDOM:r}=wt(pt(e),this.nodes[t.type.name](t),null,t.attrs);if(r){if(t.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(t.content,e,r)}return i}serializeNode(t,e={}){let i=this.serializeNodeInner(t,e);for(let r=t.marks.length-1;r>=0;r--){let s=this.serializeMark(t.marks[r],t.isInline,e);s&&((s.contentDOM||s.dom).appendChild(i),i=s.dom)}return i}serializeMark(t,e,i={}){let r=this.marks[t.type.name];return r&&wt(pt(i),r(t,e),null,t.attrs)}static renderSpec(t,e,i=null,r){return wt(t,e,i,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new ft(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(t){let e=dt(t.nodes);return e.text||(e.text=t=>t.text),e}static marksFromSchema(t){return dt(t.marks)}}function dt(t){let e={};for(let i in t){let r=t[i].spec.toDOM;r&&(e[i]=r)}return e}function pt(t){return t.document||window.document}const gt=new WeakMap;function wt(t,e,i,r){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 s,n=e[0];if("string"!=typeof n)throw new RangeError("Invalid array passed to renderSpec");if(r&&(s=function(t){let e=gt.get(t);return void 0===e&>.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}(r))&&s.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 o,h=n.indexOf(" ");h>0&&(i=n.slice(0,h),n=n.slice(h+1));let l=i?t.createElementNS(i,n):t.createElement(n),a=e[1],u=1;if(a&&"object"==typeof a&&null==a.nodeType&&!Array.isArray(a)){u=2;for(let t in a)if(null!=a[t]){let e=t.indexOf(" ");e>0?l.setAttributeNS(t.slice(0,e),t.slice(e+1),a[t]):"style"==t&&l.style?l.style.cssText=a[t]:l.setAttribute(t,a[t])}}for(let s=u;s<e.length;s++){let n=e[s];if(0===n){if(s<e.length-1||s>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}{let{dom:e,contentDOM:s}=wt(t,n,i,r);if(l.appendChild(e),s){if(o)throw new RangeError("Multiple content holes");o=s}}}return{dom:l,contentDOM:o}}const mt=Math.pow(2,16);function vt(t){return 65535&t}class yt{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 kt{constructor(t,e=!1){if(this.ranges=t,this.inverted=e,!t.length&&kt.empty)return kt.empty}recover(t){let e=0,i=vt(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))/mt}(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 r=0,s=this.inverted?2:1,n=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let h=this.ranges[o]-(this.inverted?r:0);if(h>t)break;let l=this.ranges[o+s],a=this.ranges[o+n],u=h+l;if(t<=u){let s=h+r+((l?t==h?-1:t==u?1:e:e)<0?0:a);if(i)return s;let n=t==h?2:t==u?1:4;return(e<0?t!=h:t!=u)&&(n|=8),new yt(s,n,t==(e<0?h:u)?null:o/3+(t-h)*mt)}r+=a-l}return i?t+r:new yt(t+r,0,null)}touches(t,e){let i=0,r=vt(e),s=this.inverted?2:1,n=this.inverted?1:2;for(let e=0;e<this.ranges.length;e+=3){let o=this.ranges[e]-(this.inverted?i:0);if(o>t)break;let h=this.ranges[e+s];if(t<=o+h&&e==3*r)return!0;i+=this.ranges[e+n]-h}return!1}forEach(t){let e=this.inverted?2:1,i=this.inverted?1:2;for(let r=0,s=0;r<this.ranges.length;r+=3){let n=this.ranges[r],o=n-(this.inverted?s:0),h=n+(this.inverted?0:s),l=this.ranges[r+e],a=this.ranges[r+i];t(o,o+l,h,h+a),s+=a-l}}invert(){return new kt(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return 0==t?kt.empty:new kt(t<0?[0,-t,0]:[0,0,t])}}kt.empty=new kt([]);class bt{constructor(t,e,i=0,r=(t?t.length:0)){this.mirror=e,this.from=i,this.to=r,this._maps=t||[],this.ownData=!(t||e)}get maps(){return this._maps}slice(t=0,e=this.maps.length){return new bt(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 r=t.getMirror(e);this.appendMap(t._maps[e],null!=r&&r<e?i+r: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 r=t.getMirror(e);this.appendMap(t._maps[e].invert(),null!=r&&r>e?i-r-1:void 0)}}invert(){let t=new bt;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 r=0;for(let i=this.from;i<this.to;i++){let s=this._maps[i].mapResult(t,e);if(null!=s.recover){let e=this.getMirror(i);if(null!=e&&e>i&&e<this.to){i=e,t=this._maps[e].recover(s.recover);continue}}r|=s.delInfo,t=s.pos}return i?t:new yt(t,r,null)}}const Mt=Object.create(null);class xt{getMap(){return kt.empty}merge(t){return null}static fromJSON(t,e){if(!e||!e.stepType)throw new RangeError("Invalid input for Step.fromJSON");let i=Mt[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 Mt)throw new RangeError("Duplicate use of step JSON ID "+t);return Mt[t]=e,e.prototype.jsonID=t,e}}class Ct{constructor(t,e){this.doc=t,this.failed=e}static ok(t){return new Ct(t,null)}static fail(t){return new Ct(null,t)}static fromReplace(t,e,i,r){try{return Ct.ok(t.replace(e,i,r))}catch(t){if(t instanceof w)return Ct.fail(t.message);throw t}}}function At(t,e,i){let r=[];for(let s=0;s<t.childCount;s++){let n=t.child(s);n.content.size&&(n=n.copy(At(n.content,e,n))),n.isInline&&(n=e(n,i,s)),r.push(n)}return c.fromArray(r)}class St extends xt{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),r=i.node(i.sharedDepth(this.to)),s=new m(At(e.content,((t,e)=>t.isAtom&&e.type.allowsMarkType(this.mark.type)?t.mark(this.mark.addToSet(t.marks)):t),r),e.openStart,e.openEnd);return Ct.fromReplace(t,this.from,this.to,s)}invert(){return new Bt(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:"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 St(e.from,e.to,t.markFromJSON(e.mark))}}xt.jsonID("addMark",St);class Bt extends xt{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 m(At(e.content,(t=>t.mark(this.mark.removeFromSet(t.marks))),t),e.openStart,e.openEnd);return Ct.fromReplace(t,this.from,this.to,i)}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 Bt(e.pos,i.pos,this.mark)}merge(t){return t instanceof Bt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Bt(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 Bt(e.from,e.to,t.markFromJSON(e.mark))}}xt.jsonID("removeMark",Bt);class Tt extends xt{constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return Ct.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.addToSet(e.marks));return Ct.fromReplace(t,this.pos,this.pos+1,new m(c.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 Tt(this.pos,e.marks[i]);return new Tt(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 Tt(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 Tt(e.pos,t.markFromJSON(e.mark))}}xt.jsonID("addNodeMark",Tt);class Ot extends xt{constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return Ct.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.removeFromSet(e.marks));return Ct.fromReplace(t,this.pos,this.pos+1,new m(c.from(i),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);return e&&this.mark.isInSet(e.marks)?new Tt(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))}}xt.jsonID("removeNodeMark",Ot);class Et extends xt{constructor(t,e,i,r=!1){super(),this.from=t,this.to=e,this.slice=i,this.structure=r}apply(t){return this.structure&&Dt(t,this.from,this.to)?Ct.fail("Structure replace would overwrite content"):Ct.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new kt([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?m.empty:new m(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?m.empty:new m(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,m.fromJSON(t,e.slice),!!e.structure)}}xt.jsonID("replace",Et);class It extends xt{constructor(t,e,i,r,s,n,o=!1){super(),this.from=t,this.to=e,this.gapFrom=i,this.gapTo=r,this.slice=s,this.insert=n,this.structure=o}apply(t){if(this.structure&&(Dt(t,this.from,this.gapFrom)||Dt(t,this.gapTo,this.to)))return Ct.fail("Structure gap-replace would overwrite content");let e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return Ct.fail("Gap is not a flat range");let i=this.slice.insertAt(this.insert,e.content);return i?Ct.fromReplace(t,this.from,this.to,i):Ct.fail("Content does not fit in gap")}getMap(){return new kt([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 It(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),r=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1),s=this.to==this.gapTo?i.pos:t.map(this.gapTo,1);return e.deletedAcross&&i.deletedAcross||r<e.pos||s>i.pos?null:new It(e.pos,i.pos,r,s,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 It(e.from,e.to,e.gapFrom,e.gapTo,m.fromJSON(t,e.slice),e.insert,!!e.structure)}}function Dt(t,e,i){let r=t.resolve(e),s=i-e,n=r.depth;for(;s>0&&n>0&&r.indexAfter(n)==r.node(n).childCount;)n--,s--;if(s>0){let t=r.node(n).maybeChild(r.indexAfter(n));for(;s>0;){if(!t||t.isLeaf)return!0;t=t.firstChild,s--}}return!1}function Pt(t,e,i,r=i.contentMatch,s=!0){let n=t.doc.nodeAt(e),o=[],h=e+1;for(let e=0;e<n.childCount;e++){let l=n.child(e),a=h+l.nodeSize,u=r.matchType(l.type);if(u){r=u;for(let e=0;e<l.marks.length;e++)i.allowsMarkType(l.marks[e].type)||t.step(new Bt(h,a,l.marks[e]));if(s&&l.isText&&"pre"!=i.whitespace){let t,e,r=/\r?\n|\r/g;for(;t=r.exec(l.text);)e||(e=new m(c.from(i.schema.text(" ",i.allowedMarks(l.marks))),0,0)),o.push(new Et(h+t.index,h+t.index+t[0].length,e))}}else o.push(new Et(h,a,m.empty));h=a}if(!r.validEnd){let e=r.fillBefore(c.empty,!0);t.replace(h,h,new m(e,0,0))}for(let e=o.length-1;e>=0;e--)t.step(o[e])}function $t(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,r=0,s=0;;--i){let n=t.$from.node(i),o=t.$from.index(i)+r,h=t.$to.indexAfter(i)-s;if(i<t.depth&&n.canReplace(o,h,e))return i;if(0==i||n.type.spec.isolating||!$t(n,o,h))break;o&&(r=1),h<n.childCount&&(s=1)}return null}function jt(t,e,i,r){e.forEach(((s,n)=>{if(s.isText){let o,h=/\r?\n|\r/g;for(;o=h.exec(s.text);){let s=t.mapping.slice(r).map(i+1+n+o.index);t.replaceWith(s,s+1,e.type.schema.linebreakReplacement.create())}}}))}function Ft(t,e,i,r){e.forEach(((s,n)=>{if(s.type==s.type.schema.linebreakReplacement){let s=t.mapping.slice(r).map(i+1+n);t.replaceWith(s,s+1,e.type.schema.text("\n"))}}))}function Nt(t,e,i=1,r){let s=t.resolve(e),n=s.depth-i,o=r&&r[r.length-1]||s.parent;if(n<0||s.parent.type.spec.isolating||!s.parent.canReplace(s.index(),s.parent.childCount)||!o.type.validContent(s.parent.content.cutByIndex(s.index(),s.parent.childCount)))return!1;for(let t=s.depth-1,e=i-2;t>n;t--,e--){let i=s.node(t),n=s.index(t);if(i.type.spec.isolating)return!1;let o=i.content.cutByIndex(n,i.childCount),h=r&&r[e+1];h&&(o=o.replaceChild(0,h.type.create(h.attrs)));let l=r&&r[e]||i;if(!i.canReplace(n+1,i.childCount)||!l.type.validContent(o))return!1}let h=s.indexAfter(n),l=r&&r[0];return s.node(n).canReplaceWith(h,h,l?l.type:s.node(n+1).type)}function Ut(t,e){let i=t.resolve(e),r=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:r}=t.type.schema;for(let s=0;s<e.childCount;s++){let n=e.child(s);if(i=i.matchType(n.type==r?t.type.schema.nodes.text:n.type),!i)return!1;if(!t.type.allowsMarks(n.marks))return!1}return i.validEnd}(t,e))}(i.nodeBefore,i.nodeAfter)&&i.parent.canReplace(r,r+1)}function zt(t,e,i=e,r=m.empty){if(e==i&&!r.size)return null;let s=t.resolve(e),n=t.resolve(i);return Lt(s,n,r)?new Et(e,i,r):new _t(s,n,r).fit()}function Lt(t,e,i){return!i.openStart&&!i.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),i.content)}xt.jsonID("replaceAround",It);class _t{constructor(t,e,i){this.$from=t,this.$to=e,this.unplaced=i,this.frontier=[],this.placed=c.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=c.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,r=this.close(t<0?this.$to:i.doc.resolve(t));if(!r)return null;let s=this.placed,n=i.depth,o=r.depth;for(;n&&o&&1==s.childCount;)s=s.firstChild.content,n--,o--;let h=new m(s,n,o);return t>-1?new It(i.pos,t,this.$to.pos,this.$to.end(),h,e):h.size||i.pos!=this.$to.pos?new Et(i.pos,r.pos,h):null}findFittable(){let t=this.unplaced.openStart;for(let e=this.unplaced.content,i=0,r=this.unplaced.openEnd;i<t;i++){let s=e.firstChild;if(e.childCount>1&&(r=0),s.type.spec.isolating&&r<=i){t=i;break}e=s.content}for(let e=1;e<=2;e++)for(let i=1==e?t:this.unplaced.openStart;i>=0;i--){let t,r=null;i?(r=Yt(this.unplaced.content,i-1).firstChild,t=r.content):t=this.unplaced.content;let s=t.firstChild;for(let t=this.depth;t>=0;t--){let n,{type:o,match:h}=this.frontier[t],l=null;if(1==e&&(s?h.matchType(s.type)||(l=h.fillBefore(c.from(s),!1)):r&&o.compatibleContent(r.type)))return{sliceDepth:i,frontierDepth:t,parent:r,inject:l};if(2==e&&s&&(n=h.findWrapping(s.type)))return{sliceDepth:i,frontierDepth:t,parent:r,wrap:n};if(r&&h.matchType(r.type))break}}}openMore(){let{content:t,openStart:e,openEnd:i}=this.unplaced,r=Yt(t,e);return!(!r.childCount||r.firstChild.isLeaf||(this.unplaced=new m(t,e+1,Math.max(i,r.size+e>=t.size-i?e+1:0)),0))}dropNode(){let{content:t,openStart:e,openEnd:i}=this.unplaced,r=Yt(t,e);if(r.childCount<=1&&e>0){let s=t.size-e<=e+r.size;this.unplaced=new m(Ht(t,e-1,1),e-1,s?e-1:i)}else this.unplaced=new m(Ht(t,e,1),e,i)}placeNodes({sliceDepth:t,frontierDepth:e,parent:i,inject:r,wrap:s}){for(;this.depth>e;)this.closeFrontierNode();if(s)for(let t=0;t<s.length;t++)this.openFrontierNode(s[t]);let n=this.unplaced,o=i?i.content:n.content,h=n.openStart-t,l=0,a=[],{match:u,type:f}=this.frontier[e];if(r){for(let t=0;t<r.childCount;t++)a.push(r.child(t));u=u.matchFragment(r)}let d=o.size+t-(n.content.size-n.openEnd);for(;l<o.childCount;){let t=o.child(l),e=u.matchType(t.type);if(!e)break;l++,(l>1||0==h||t.content.size)&&(u=e,a.push(Wt(t.mark(f.allowedMarks(t.marks)),1==l?h:0,l==o.childCount?d:-1)))}let p=l==o.childCount;p||(d=-1),this.placed=Xt(this.placed,e,c.from(a)),this.frontier[e].match=u,p&&d<0&&i&&i.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let t=0,e=o;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?m.empty:new m(Ht(n.content,t-1,1),t-1,d<0?n.openEnd:t-1):new m(Ht(n.content,t,l),n.openStart,n.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let t,e=this.frontier[this.depth];if(!e.type.isTextblock||!Vt(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,r=this.$to.after(i);for(;i>1&&r==this.$to.end(--i);)++r;return r}findCloseLevel(t){t:for(let e=Math.min(this.depth,t.depth);e>=0;e--){let{match:i,type:r}=this.frontier[e],s=e<t.depth&&t.end(e+1)==t.pos+(t.depth-(e+1)),n=Vt(t,e,r,i,s);if(n){for(let i=e-1;i>=0;i--){let{match:e,type:r}=this.frontier[i],s=Vt(t,i,r,e,!0);if(!s||s.childCount)continue t}return{depth:e,fit:n,move:s?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=Xt(this.placed,e.depth,e.fit)),t=e.move;for(let i=e.depth+1;i<=t.depth;i++){let e=t.node(i),r=e.type.contentMatch.fillBefore(e.content,!0,t.index(i));this.openFrontierNode(e.type,e.attrs,r)}return t}openFrontierNode(t,e=null,i){let r=this.frontier[this.depth];r.match=r.match.matchType(t),this.placed=Xt(this.placed,this.depth,c.from(t.create(e,i))),this.frontier.push({type:t,match:t.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(c.empty,!0);t.childCount&&(this.placed=Xt(this.placed,this.frontier.length,t))}}function Ht(t,e,i){return 0==e?t.cutByIndex(i,t.childCount):t.replaceChild(0,t.firstChild.copy(Ht(t.firstChild.content,e-1,i)))}function Xt(t,e,i){return 0==e?t.append(i):t.replaceChild(t.childCount-1,t.lastChild.copy(Xt(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 r=t.content;return e>1&&(r=r.replaceChild(0,Wt(r.firstChild,e-1,1==r.childCount?i-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),i<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(c.empty,!0)))),t.copy(r)}function Vt(t,e,i,r,s){let n=t.node(e),o=s?t.indexAfter(e):t.index(e);if(o==n.childCount&&!i.compatibleContent(n.type))return null;let h=r.fillBefore(n.content,!0,o);return h&&!function(t,e,i){for(let r=i;r<e.childCount;r++)if(!t.allowsMarks(e.child(r).marks))return!0;return!1}(i,n.content,o)?h:null}function Jt(t,e,i,r,s){if(e<i){let s=t.firstChild;t=t.replaceChild(0,s.copy(Jt(s.content,e+1,i,r,s)))}if(e>r){let e=s.contentMatchAt(0),i=e.fillBefore(t).append(t);t=i.append(e.matchFragment(i).fillBefore(c.empty,!0))}return t}function Qt(t,e){let i=[];for(let r=Math.min(t.depth,e.depth);r>=0;r--){let s=t.start(r);if(s<t.pos-(t.depth-r)||e.end(r)>e.pos+(e.depth-r)||t.node(r).type.spec.isolating||e.node(r).type.spec.isolating)break;(s==e.start(r)||r==t.depth&&r==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&r&&e.start(r-1)==s-1)&&i.push(r)}return i}class Kt extends xt{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 Ct.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 r=e.type.create(i,null,e.marks);return Ct.fromReplace(t,this.pos,this.pos+1,new m(c.from(r),0,e.isLeaf?0:1))}getMap(){return kt.empty}invert(t){return new Kt(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 Kt(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 Kt(e.pos,e.attr,e.value)}}xt.jsonID("attr",Kt);class qt extends xt{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 Ct.ok(i)}getMap(){return kt.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)}}xt.jsonID("docAttr",qt);let Gt=class extends Error{};Gt=function t(e){let i=Error.call(this,e);return i.__proto__=t.prototype,i},(Gt.prototype=Object.create(Error.prototype)).constructor=Gt,Gt.prototype.name="TransformError";class Zt{constructor(t){this.doc=t,this.steps=[],this.docs=[],this.mapping=new bt}get before(){return this.docs.length?this.docs[0]:this.doc}step(t){let e=this.maybeStep(t);if(e.failed)throw new Gt(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}changedRange(){let t=1e9,e=-1e9;for(let i=0;i<this.mapping.maps.length;i++){let r=this.mapping.maps[i];i&&(t=r.map(t,1),e=r.map(e,-1)),r.forEach(((i,r,s,n)=>{t=Math.min(t,s),e=Math.max(e,n)}))}return 1e9==t?null:{from:t,to:e}}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=m.empty){let r=zt(this.doc,t,e,i);return r&&this.step(r),this}replaceWith(t,e,i){return this.replace(t,e,new m(c.from(i),0,0))}delete(t,e){return this.replace(t,e,m.empty)}insert(t,e){return this.replaceWith(t,t,e)}replaceRange(t,e,i){return function(t,e,i,r){if(!r.size)return t.deleteRange(e,i);let s=t.doc.resolve(e),n=t.doc.resolve(i);if(Lt(s,n,r))return t.step(new Et(e,i,r));let o=Qt(s,n);0==o[o.length-1]&&o.pop();let h=-(s.depth+1);o.unshift(h);for(let t=s.depth,e=s.pos-1;t>0;t--,e--){let i=s.node(t).type.spec;if(i.defining||i.definingAsContext||i.isolating)break;o.indexOf(t)>-1?h=t:s.before(t)==e&&o.splice(1,0,-t)}let l=o.indexOf(h),a=[],u=r.openStart;for(let t=r.content,e=0;;e++){let i=t.firstChild;if(a.push(i),e==r.openStart)break;t=i.content}for(let t=u-1;t>=0;t--){let e=a[t],i=(c=e.type).spec.defining||c.spec.definingForContent;if(i&&!e.sameMarkup(s.node(Math.abs(h)-1)))u=t;else if(i||!e.type.isTextblock)break}var c;for(let e=r.openStart;e>=0;e--){let h=(e+u+1)%(r.openStart+1),c=a[h];if(c)for(let e=0;e<o.length;e++){let a=o[(e+l)%o.length],u=!0;a<0&&(u=!1,a=-a);let f=s.node(a-1),d=s.index(a-1);if(f.canReplaceWith(d,d,c.type,c.marks))return t.replace(s.before(a),u?n.after(a):i,new m(Jt(r.content,0,r.openStart,h),h,r.openEnd))}}let f=t.steps.length;for(let h=o.length-1;h>=0&&(t.replace(e,i,r),!(t.steps.length>f));h--){let t=o[h];t<0||(e=s.before(t),i=n.after(t))}}(this,t,e,i),this}replaceRangeWith(t,e,i){return function(t,e,i,r){if(!r.isInline&&e==i&&t.doc.resolve(e).parent.content.size){let s=function(t,e,i){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),i))return e;if(0==r.parentOffset)for(let t=r.depth-1;t>=0;t--){let e=r.index(t);if(r.node(t).canReplaceWith(e,e,i))return r.before(t+1);if(e>0)return null}if(r.parentOffset==r.parent.content.size)for(let t=r.depth-1;t>=0;t--){let e=r.indexAfter(t);if(r.node(t).canReplaceWith(e,e,i))return r.after(t+1);if(e<r.node(t).childCount)return null}return null}(t.doc,e,r.type);null!=s&&(e=i=s)}t.replaceRange(e,i,new m(c.from(r),0,0))}(this,t,e,i),this}deleteRange(t,e){return function(t,e,i){let r=t.doc.resolve(e),s=t.doc.resolve(i),n=Qt(r,s);for(let e=0;e<n.length;e++){let i=n[e],o=e==n.length-1;if(o&&0==i||r.node(i).type.contentMatch.validEnd)return t.delete(r.start(i),s.end(i));if(i>0&&(o||r.node(i-1).canReplace(r.index(i-1),s.indexAfter(i-1))))return t.delete(r.before(i),s.after(i))}for(let n=1;n<=r.depth&&n<=s.depth;n++)if(e-r.start(n)==r.depth-n&&i>r.end(n)&&s.end(n)-i!=s.depth-n&&r.start(n-1)==s.start(n-1)&&r.node(n-1).canReplace(r.index(n-1),s.index(n-1)))return t.delete(r.before(n),i);t.delete(e,i)}(this,t,e),this}lift(t,e){return function(t,e,i){let{$from:r,$to:s,depth:n}=e,o=r.before(n+1),h=s.after(n+1),l=o,a=h,u=c.empty,f=0;for(let t=n,e=!1;t>i;t--)e||r.index(t)>0?(e=!0,u=c.from(r.node(t).copy(u)),f++):l--;let d=c.empty,p=0;for(let t=n,e=!1;t>i;t--)e||s.after(t+1)<s.end(t)?(e=!0,d=c.from(s.node(t).copy(d)),p++):a++;t.step(new It(l,a,o,h,new m(u.append(d),f,p),u.size-f,!0))}(this,t,e),this}join(t,e=1){return function(t,e,i){let r=null,{linebreakReplacement:s}=t.doc.type.schema,n=t.doc.resolve(e-i),o=n.node().type;if(s&&o.inlineContent){let t="pre"==o.whitespace,e=!!o.contentMatch.matchType(s);t&&!e?r=!1:!t&&e&&(r=!0)}let h=t.steps.length;if(!1===r){let r=t.doc.resolve(e+i);Ft(t,r.node(),r.before(),h)}o.inlineContent&&Pt(t,e+i-1,o,n.node().contentMatchAt(n.index()),null==r);let l=t.mapping.slice(h),a=l.map(e-i);if(t.step(new Et(a,l.map(e+i,-1),m.empty,!0)),!0===r){let e=t.doc.resolve(a);jt(t,e.node(),e.before(),t.steps.length)}}(this,t,e),this}wrap(t,e){return function(t,e,i){let r=c.empty;for(let t=i.length-1;t>=0;t--){if(r.size){let e=i[t].type.contentMatch.matchFragment(r);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=c.from(i[t].type.create(i[t].attrs,r))}let s=e.start,n=e.end;t.step(new It(s,n,s,n,new m(r,0,0),i.length,!0))}(this,t,e),this}setBlockType(t,e=t,i,r=null){return function(t,e,i,r,s){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let n=t.steps.length;t.doc.nodesBetween(e,i,((e,i)=>{let o="function"==typeof s?s(e):s;if(e.isTextblock&&!e.hasMarkup(r,o)&&function(t,e,i){let r=t.resolve(e),s=r.index();return r.parent.canReplaceWith(s,s+1,i)}(t.doc,t.mapping.slice(n).map(i),r)){let s=null;if(r.schema.linebreakReplacement){let t="pre"==r.whitespace,e=!!r.contentMatch.matchType(r.schema.linebreakReplacement);t&&!e?s=!1:!t&&e&&(s=!0)}!1===s&&Ft(t,e,i,n),Pt(t,t.mapping.slice(n).map(i,1),r,void 0,null===s);let h=t.mapping.slice(n),l=h.map(i,1),a=h.map(i+e.nodeSize,1);return t.step(new It(l,a,l+1,a-1,new m(c.from(r.create(o,null,e.marks)),0,0),1,!0)),!0===s&&jt(t,e,i,n),!1}}))}(this,t,e,i,r),this}setNodeMarkup(t,e,i=null,r){return function(t,e,i,r,s){let n=t.doc.nodeAt(e);if(!n)throw new RangeError("No node at given position");i||(i=n.type);let o=i.create(r,null,s||n.marks);if(n.isLeaf)return t.replaceWith(e,e+n.nodeSize,o);if(!i.validContent(n.content))throw new RangeError("Invalid content for node type "+i.name);t.step(new It(e,e+n.nodeSize,e+1,e+n.nodeSize-1,new m(c.from(o),0,0),1,!0))}(this,t,e,i,r),this}setNodeAttribute(t,e,i){return this.step(new Kt(t,e,i)),this}setDocAttribute(t,e){return this.step(new qt(t,e)),this}addNodeMark(t,e){return this.step(new Tt(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 g)e.isInSet(i.marks)&&this.step(new Ot(t,e));else{let r,s=i.marks,n=[];for(;r=e.isInSet(s);)n.push(new Ot(t,r)),s=r.removeFromSet(s);for(let t=n.length-1;t>=0;t--)this.step(n[t])}return this}split(t,e=1,i){return function(t,e,i=1,r){let s=t.doc.resolve(e),n=c.empty,o=c.empty;for(let t=s.depth,e=s.depth-i,h=i-1;t>e;t--,h--){n=c.from(s.node(t).copy(n));let e=r&&r[h];o=c.from(e?e.type.create(e.attrs,o):s.node(t).copy(o))}t.step(new Et(e,e,new m(n.append(o),i,i),!0))}(this,t,e,i),this}addMark(t,e,i){return function(t,e,i,r){let s,n,o=[],h=[];t.doc.nodesBetween(e,i,((t,l,a)=>{if(!t.isInline)return;let u=t.marks;if(!r.isInSet(u)&&a.type.allowsMarkType(r.type)){let a=Math.max(l,e),c=Math.min(l+t.nodeSize,i),f=r.addToSet(u);for(let t=0;t<u.length;t++)u[t].isInSet(f)||(s&&s.to==a&&s.mark.eq(u[t])?s.to=c:o.push(s=new Bt(a,c,u[t])));n&&n.to==a?n.to=c:h.push(n=new St(a,c,r))}})),o.forEach((e=>t.step(e))),h.forEach((e=>t.step(e)))}(this,t,e,i),this}removeMark(t,e,i){return function(t,e,i,r){let s=[],n=0;t.doc.nodesBetween(e,i,((t,o)=>{if(!t.isInline)return;n++;let h=null;if(r instanceof Z){let e,i=t.marks;for(;e=r.isInSet(i);)(h||(h=[])).push(e),i=e.removeFromSet(i)}else r?r.isInSet(t.marks)&&(h=[r]):h=t.marks;if(h&&h.length){let r=Math.min(o+t.nodeSize,i);for(let t=0;t<h.length;t++){let i,l=h[t];for(let t=0;t<s.length;t++){let e=s[t];e.step==n-1&&l.eq(s[t].style)&&(i=e)}i?(i.to=r,i.step=n):s.push({style:l,from:Math.max(o,e),to:r,step:n})}}})),s.forEach((e=>t.step(new Bt(e.from,e.to,e.style))))}(this,t,e,i),this}clearIncompatible(t,e,i){return Pt(this,t,e,i),this}}const te=Object.create(null);class ee{constructor(t,e,i){this.$anchor=t,this.$head=e,this.ranges=i||[new ie(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=m.empty){let i=e.content.lastChild,r=null;for(let t=0;t<e.openEnd;t++)r=i,i=i.lastChild;let s=t.steps.length,n=this.ranges;for(let o=0;o<n.length;o++){let{$from:h,$to:l}=n[o],a=t.mapping.slice(s);t.replaceRange(a.map(h.pos),a.map(l.pos),o?m.empty:e),0==o&&fe(t,s,(i?i.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(t,e){let i=t.steps.length,r=this.ranges;for(let s=0;s<r.length;s++){let{$from:n,$to:o}=r[s],h=t.mapping.slice(i),l=h.map(n.pos),a=h.map(o.pos);s?t.deleteRange(l,a):(t.replaceRangeWith(l,a,e),fe(t,i,e.isInline?-1:1))}}static findFrom(t,e,i=!1){let r=t.parent.inlineContent?new ne(t):ce(t.node(0),t.parent,t.pos,t.index(),e,i);if(r)return r;for(let r=t.depth-1;r>=0;r--){let s=e<0?ce(t.node(0),t.node(r),t.before(r+1),t.index(r),e,i):ce(t.node(0),t.node(r),t.after(r+1),t.index(r)+1,e,i);if(s)return s}return null}static near(t,e=1){return this.findFrom(t,e)||this.findFrom(t,-e)||new ae(t.node(0))}static atStart(t){return ce(t,t,0,0,1)||new ae(t)}static atEnd(t){return ce(t,t,t.content.size,t.childCount,-1)||new ae(t)}static fromJSON(t,e){if(!e||!e.type)throw new RangeError("Invalid input for Selection.fromJSON");let i=te[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 te)throw new RangeError("Duplicate use of selection JSON ID "+t);return te[t]=e,e.prototype.jsonID=t,e}getBookmark(){return ne.between(this.$anchor,this.$head).getBookmark()}}ee.prototype.visible=!0;class ie{constructor(t,e){this.$from=t,this.$to=e}}let re=!1;function se(t){re||t.parent.inlineContent||(re=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class ne extends ee{constructor(t,e=t){se(t),se(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 ee.near(i);let r=t.resolve(e.map(this.anchor));return new ne(r.parent.inlineContent?r:i,i)}replace(t,e=m.empty){if(super.replace(t,e),e==m.empty){let e=this.$from.marksAcross(this.$to);e&&t.ensureMarks(e)}}eq(t){return t instanceof ne&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new oe(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 ne(t.resolve(e.anchor),t.resolve(e.head))}static create(t,e,i=e){let r=t.resolve(e);return new this(r,i==e?r:t.resolve(i))}static between(t,e,i){let r=t.pos-e.pos;if(i&&!r||(i=r>=0?1:-1),!e.parent.inlineContent){let t=ee.findFrom(e,i,!0)||ee.findFrom(e,-i,!0);if(!t)return ee.near(e,i);e=t.$head}return t.parent.inlineContent||(0==r||(t=(ee.findFrom(t,-i,!0)||ee.findFrom(t,i,!0)).$anchor).pos<e.pos!=r<0)&&(t=e),new ne(t,e)}}ee.jsonID("text",ne);class oe{constructor(t,e){this.anchor=t,this.head=e}map(t){return new oe(t.map(this.anchor),t.map(this.head))}resolve(t){return ne.between(t.resolve(this.anchor),t.resolve(this.head))}}class he extends ee{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:r}=e.mapResult(this.anchor),s=t.resolve(r);return i?ee.near(s):new he(s)}content(){return new m(c.from(this.node),0,0)}eq(t){return t instanceof he&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new le(this.anchor)}static fromJSON(t,e){if("number"!=typeof e.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new he(t.resolve(e.anchor))}static create(t,e){return new he(t.resolve(e))}static isSelectable(t){return!t.isText&&!1!==t.type.spec.selectable}}he.prototype.visible=!1,ee.jsonID("node",he);class le{constructor(t){this.anchor=t}map(t){let{deleted:e,pos:i}=t.mapResult(this.anchor);return e?new oe(i,i):new le(i)}resolve(t){let e=t.resolve(this.anchor),i=e.nodeAfter;return i&&he.isSelectable(i)?new he(e):ee.near(e)}}class ae extends ee{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,e=m.empty){if(e==m.empty){t.delete(0,t.doc.content.size);let e=ee.atStart(t.doc);e.eq(t.selection)||t.setSelection(e)}else super.replace(t,e)}toJSON(){return{type:"all"}}static fromJSON(t){return new ae(t)}map(t){return new ae(t)}eq(t){return t instanceof ae}getBookmark(){return ue}}ee.jsonID("all",ae);const ue={map(){return this},resolve:t=>new ae(t)};function ce(t,e,i,r,s,n=!1){if(e.inlineContent)return ne.create(t,i);for(let o=r-(s>0?0:1);s>0?o<e.childCount:o>=0;o+=s){let r=e.child(o);if(r.isAtom){if(!n&&he.isSelectable(r))return he.create(t,i-(s<0?r.nodeSize:0))}else{let e=ce(t,r,i+s,s<0?r.childCount:0,s,n);if(e)return e}i+=r.nodeSize*s}return null}function fe(t,e,i){let r=t.steps.length-1;if(r<e)return;let s,n=t.steps[r];(n instanceof Et||n instanceof It)&&(t.mapping.maps[r].forEach(((t,e,i,r)=>{null==s&&(s=r)})),t.setSelection(ee.near(t.doc.resolve(s),i)))}class de extends Zt{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 g.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)||g.none))),i.replaceWith(this,t),this}deleteSelection(){return this.selection.replace(this),this}insertText(t,e,i){let r=this.doc.type.schema;if(null==e)return t?this.replaceSelectionWith(r.text(t),!0):this.deleteSelection();{if(null==i&&(i=e),!t)return this.deleteRange(e,i);let s=this.storedMarks;if(!s){let t=this.doc.resolve(e);s=i==e?t.marks():t.marksAcross(this.doc.resolve(i))}return this.replaceRangeWith(e,i,r.text(t,s)),this.selection.empty||this.selection.to!=e+t.length||this.setSelection(ee.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 pe(t,e){return e&&t?t.bind(e):t}class ge{constructor(t,e,i){this.name=t,this.init=pe(e.init,i),this.apply=pe(e.apply,i)}}const we=[new ge("doc",{init:t=>t.doc||t.schema.topNodeType.createAndFill(),apply:t=>t.doc}),new ge("selection",{init:(t,e)=>t.selection||ee.atStart(e.doc),apply:t=>t.selection}),new ge("storedMarks",{init:t=>t.storedMarks||null,apply:(t,e,i,r)=>r.selection.$cursor?t.storedMarks:null}),new ge("scrollToSelection",{init:()=>0,apply:(t,e)=>t.scrolledIntoView?e+1:e})];class me{constructor(t,e){this.schema=t,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=we.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 ge(t.key,t.spec.state,t))}))}}class ve{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),r=null;for(;;){let s=!1;for(let n=0;n<this.config.plugins.length;n++){let o=this.config.plugins[n];if(o.spec.appendTransaction){let h=r?r[n].n:0,l=r?r[n].state:this,a=h<e.length&&o.spec.appendTransaction.call(o,h?e.slice(h):e,l,i);if(a&&i.filterTransaction(a,n)){if(a.setMeta("appendedTransaction",t),!r){r=[];for(let t=0;t<this.config.plugins.length;t++)r.push(t<n?{state:i,n:e.length}:{state:this,n:0})}e.push(a),i=i.applyInner(a),s=!0}r&&(r[n]={state:i,n:e.length})}}if(!s)return{state:i,transactions:e}}}applyInner(t){if(!t.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let e=new ve(this.config),i=this.config.fields;for(let r=0;r<i.length;r++){let s=i[r];e[s.name]=s.apply(t,this[s.name],this,e)}return e}get tr(){return new de(this)}static create(t){let e=new me(t.doc?t.doc.type.schema:t.schema,t.plugins),i=new ve(e);for(let r=0;r<e.fields.length;r++)i[e.fields[r].name]=e.fields[r].init(t,i);return i}reconfigure(t){let e=new me(this.schema,t.plugins),i=e.fields,r=new ve(e);for(let e=0;e<i.length;e++){let s=i[e].name;r[s]=this.hasOwnProperty(s)?this[s]:i[e].init(t,r)}return r}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 r=t[i],s=r.spec.state;s&&s.toJSON&&(e[i]=s.toJSON.call(r,this[r.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 r=new me(t.schema,t.plugins),s=new ve(r);return r.fields.forEach((r=>{if("doc"==r.name)s.doc=R.fromJSON(t.schema,e.doc);else if("selection"==r.name)s.selection=ee.fromJSON(s.doc,e.selection);else if("storedMarks"==r.name)e.storedMarks&&(s.storedMarks=e.storedMarks.map(t.schema.markFromJSON));else{if(i)for(let n in i){let o=i[n],h=o.spec.state;if(o.key==r.name&&h&&h.fromJSON&&Object.prototype.hasOwnProperty.call(e,n))return void(s[r.name]=h.fromJSON.call(o,t,e[n],s))}s[r.name]=r.init(t,s)}})),s}}function ye(t,e,i){for(let r in t){let s=t[r];s instanceof Function?s=s.bind(e):"handleDOMEvents"==r&&(s=ye(s,e,{})),i[r]=s}return i}class ke{constructor(t){var e;this.spec=t,this.props={},t.props&&ye(t.props,this,this.props),this.key=t.key?t.key.key:(e="plugin")in be?e+"$"+ ++be[e]:(be[e]=0,e+"$")}getState(t){return t[this.key]}}const be=Object.create(null),Me=function(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e},xe=function(t){let e=t.assignedSlot||t.parentNode;return e&&11==e.nodeType?e.host:e};let Ce=null;const Ae=function(t,e,i){let r=Ce||(Ce=document.createRange());return r.setEnd(t,null==i?t.nodeValue.length:i),r.setStart(t,e||0),r},Se=function(t,e,i,r){return i&&(Te(t,e,i,r,-1)||Te(t,e,i,r,1))},Be=/^(img|br|input|textarea|hr)$/i;function Te(t,e,i,r,s){for(var n;;){if(t==i&&e==r)return!0;if(e==(s<0?0:Oe(t))){let i=t.parentNode;if(!i||1!=i.nodeType||Ee(t)||Be.test(t.nodeName)||"false"==t.contentEditable)return!1;e=Me(t)+(s<0?0:1),t=i}else{if(1!=t.nodeType)return!1;{let i=t.childNodes[e+(s<0?-1:0)];if(1==i.nodeType&&"false"==i.contentEditable){if(!(null===(n=i.pmViewDesc)||void 0===n?void 0:n.ignoreForSelection))return!1;e+=s}else t=i,e=s<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 Ie=function(t){return t.focusNode&&Se(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 Pe="undefined"!=typeof navigator?navigator:null,$e="undefined"!=typeof document?document:null,Re=Pe&&Pe.userAgent||"",je=/Edge\/(\d+)/.exec(Re),Fe=/MSIE \d/.exec(Re),Ne=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Re),Ue=!!(Fe||Ne||je),ze=Fe?document.documentMode:Ne?+Ne[1]:je?+je[1]:0,Le=!Ue&&/gecko\/(\d+)/i.test(Re),_e=!Ue&&/Chrome\/(\d+)/.exec(Re),He=!!_e,Xe=_e?+_e[1]:0,Ye=!Ue&&!!Pe&&/Apple Computer/.test(Pe.vendor),We=Ye&&(/Mobile\/\w+/.test(Re)||!!Pe&&Pe.maxTouchPoints>2),Ve=We||!!Pe&&/Mac/.test(Pe.platform),Je=!!Pe&&/Win/.test(Pe.platform),Qe=/Android \d/.test(Re),Ke=!!$e&&"webkitFontSmoothing"in $e.documentElement.style,qe=Ke?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Ge(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 Ze(t,e){return"number"==typeof t?t:t[e]}function ti(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 ei(t,e,i){let r=t.someProp("scrollThreshold")||0,s=t.someProp("scrollMargin")||5,n=t.dom.ownerDocument;for(let o=i||t.dom;o;){if(1!=o.nodeType){o=xe(o);continue}let t=o,i=t==n.body,h=i?Ge(n):ti(t),l=0,a=0;if(e.top<h.top+Ze(r,"top")?a=-(h.top-e.top+Ze(s,"top")):e.bottom>h.bottom-Ze(r,"bottom")&&(a=e.bottom-e.top>h.bottom-h.top?e.top+Ze(s,"top")-h.top:e.bottom-h.bottom+Ze(s,"bottom")),e.left<h.left+Ze(r,"left")?l=-(h.left-e.left+Ze(s,"left")):e.right>h.right-Ze(r,"right")&&(l=e.right-h.right+Ze(s,"right")),l||a)if(i)n.defaultView.scrollBy(l,a);else{let i=t.scrollLeft,r=t.scrollTop;a&&(t.scrollTop+=a),l&&(t.scrollLeft+=l);let s=t.scrollLeft-i,n=t.scrollTop-r;e={left:e.left-s,top:e.top-n,right:e.right-s,bottom:e.bottom-n}}let u=i?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(u))break;o="absolute"==u?o.offsetParent:xe(o)}}function ii(t){let e=[],i=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=i);r=xe(r));return e}function ri(t,e){for(let i=0;i<t.length;i++){let{dom:r,top:s,left:n}=t[i];r.scrollTop!=s+e&&(r.scrollTop=s+e),r.scrollLeft!=n&&(r.scrollLeft=n)}}let si=null;function ni(t,e){let i,r,s,n,o=2e8,h=0,l=e.top,a=e.top;for(let u=t.firstChild,c=0;u;u=u.nextSibling,c++){let t;if(1==u.nodeType)t=u.getClientRects();else{if(3!=u.nodeType)continue;t=Ae(u).getClientRects()}for(let f=0;f<t.length;f++){let d=t[f];if(d.top<=l&&d.bottom>=a){l=Math.max(d.bottom,l),a=Math.min(d.top,a);let t=d.left>e.left?d.left-e.left:d.right<e.left?e.left-d.right:0;if(t<o){i=u,o=t,r=t&&3==i.nodeType?{left:d.right<e.left?d.right:d.left,top:e.top}:e,1==u.nodeType&&t&&(h=c+(e.left>=(d.left+d.right)/2?1:0));continue}}else d.top>e.top&&!s&&d.left<=e.left&&d.right>=e.left&&(s=u,n={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)&&(h=c+1)}}return!i&&s&&(i=s,r=n,o=0),i&&3==i.nodeType?function(t,e){let i,r=t.nodeValue.length,s=document.createRange();for(let n=0;n<r;n++){s.setEnd(t,n+1),s.setStart(t,n);let r=ui(s,1);if(r.top!=r.bottom&&oi(e,r)){i={node:t,offset:n+(e.left>=(r.left+r.right)/2?1:0)};break}}return s.detach(),i||{node:t,offset:0}}(i,r):!i||o&&1==i.nodeType?{node:t,offset:h}:ni(i,r)}function oi(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function hi(t,e,i){let r=t.childNodes.length;if(r&&i.top<i.bottom)for(let s=Math.max(0,Math.min(r-1,Math.floor(r*(e.top-i.top)/(i.bottom-i.top))-2)),n=s;;){let i=t.childNodes[n];if(1==i.nodeType){let t=i.getClientRects();for(let r=0;r<t.length;r++){let s=t[r];if(oi(e,s))return hi(i,e,s)}}if((n=(n+1)%r)==s)break}return t}function li(t,e){let i,r=t.dom.ownerDocument,s=0,n=function(t,e,i){if(t.caretPositionFromPoint)try{let r=t.caretPositionFromPoint(e,i);if(r)return{node:r.offsetNode,offset:Math.min(Oe(r.offsetNode),r.offset)}}catch(t){}if(t.caretRangeFromPoint){let r=t.caretRangeFromPoint(e,i);if(r)return{node:r.startContainer,offset:Math.min(Oe(r.startContainer),r.startOffset)}}}(r,e.left,e.top);n&&({node:i,offset:s}=n);let o,h=(t.root.elementFromPoint?t.root:r).elementFromPoint(e.left,e.top);if(!h||!t.dom.contains(1!=h.nodeType?h.parentNode:h)){let i=t.dom.getBoundingClientRect();if(!oi(e,i))return null;if(h=hi(t.dom,e,i),!h)return null}if(Ye)for(let t=h;i&&t;t=xe(t))t.draggable&&(i=void 0);if(h=function(t,e){let i=t.parentNode;return i&&/^li$/i.test(i.nodeName)&&e.left<t.getBoundingClientRect().left?i:t}(h,e),i){if(Le&&1==i.nodeType&&(s=Math.min(s,i.childNodes.length),s<i.childNodes.length)){let t,r=i.childNodes[s];"IMG"==r.nodeName&&(t=r.getBoundingClientRect()).right<=e.left&&t.bottom>e.top&&s++}let r;Ke&&s&&1==i.nodeType&&1==(r=i.childNodes[s-1]).nodeType&&"false"==r.contentEditable&&r.getBoundingClientRect().top>=e.top&&s--,i==t.dom&&s==i.childNodes.length-1&&1==i.lastChild.nodeType&&e.top>i.lastChild.getBoundingClientRect().bottom?o=t.state.doc.content.size:0!=s&&1==i.nodeType&&"BR"==i.childNodes[s-1].nodeName||(o=function(t,e,i,r){let s=-1;for(let i=e,n=!1;i!=t.dom;){let e,o=t.docView.nearestDesc(i,!0);if(!o)return null;if(1==o.dom.nodeType&&(o.node.isBlock&&o.parent||!o.contentDOM)&&((e=o.dom.getBoundingClientRect()).width||e.height)&&(o.node.isBlock&&o.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(o.dom.nodeName)&&(!n&&e.left>r.left||e.top>r.top?s=o.posBefore:(!n&&e.right<r.left||e.bottom<r.top)&&(s=o.posAfter),n=!0),!o.contentDOM&&s<0&&!o.node.isText))return(o.node.isBlock?r.top<(e.top+e.bottom)/2:r.left<(e.left+e.right)/2)?o.posBefore:o.posAfter;i=o.dom.parentNode}return s>-1?s:t.docView.posFromDOM(e,i,-1)}(t,i,s,e))}null==o&&(o=function(t,e,i){let{node:r,offset:s}=ni(e,i),n=-1;if(1==r.nodeType&&!r.firstChild){let t=r.getBoundingClientRect();n=t.left!=t.right&&i.left>(t.left+t.right)/2?1:-1}return t.docView.posFromDOM(r,s,n)}(t,h,e));let l=t.docView.nearestDesc(h,!0);return{pos:o,inside:l?l.posAtStart-l.border:-1}}function ai(t){return t.top<t.bottom||t.left<t.right}function ui(t,e){let i=t.getClientRects();if(i.length){let t=i[e<0?0:i.length-1];if(ai(t))return t}return Array.prototype.find.call(i,ai)||t.getBoundingClientRect()}const ci=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function fi(t,e,i){let{node:r,offset:s,atom:n}=t.docView.domFromPos(e,i<0?-1:1),o=Ke||Le;if(3==r.nodeType){if(!o||!ci.test(r.nodeValue)&&(i<0?s:s!=r.nodeValue.length)){let t=s,e=s,n=i<0?1:-1;return i<0&&!s?(e++,n=-1):i>=0&&s==r.nodeValue.length?(t--,n=1):i<0?t--:e++,di(ui(Ae(r,t,e),n),n<0)}{let t=ui(Ae(r,s,s),i);if(Le&&s&&/\s/.test(r.nodeValue[s-1])&&s<r.nodeValue.length){let e=ui(Ae(r,s-1,s-1),-1);if(e.top==t.top){let i=ui(Ae(r,s,s+1),-1);if(i.top!=t.top)return di(i,i.left<e.left)}}return t}}if(!t.state.doc.resolve(e-(n||0)).parent.inlineContent){if(null==n&&s&&(i<0||s==Oe(r))){let t=r.childNodes[s-1];if(1==t.nodeType)return pi(t.getBoundingClientRect(),!1)}if(null==n&&s<Oe(r)){let t=r.childNodes[s];if(1==t.nodeType)return pi(t.getBoundingClientRect(),!0)}return pi(r.getBoundingClientRect(),i>=0)}if(null==n&&s&&(i<0||s==Oe(r))){let t=r.childNodes[s-1],e=3==t.nodeType?Ae(t,Oe(t)-(o?0:1)):1!=t.nodeType||"BR"==t.nodeName&&t.nextSibling?null:t;if(e)return di(ui(e,1),!1)}if(null==n&&s<Oe(r)){let t=r.childNodes[s];for(;t.pmViewDesc&&t.pmViewDesc.ignoreForCoords;)t=t.nextSibling;let e=t?3==t.nodeType?Ae(t,0,o?0:1):1==t.nodeType?t:null:null;if(e)return di(ui(e,-1),!0)}return di(ui(3==r.nodeType?Ae(r):r,-i),i>=0)}function di(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 pi(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 gi(t,e,i){let r=t.state,s=t.root.activeElement;r!=e&&t.updateState(e),s!=t.dom&&t.focus();try{return i()}finally{r!=e&&t.updateState(r),s!=t.dom&&s&&s.focus()}}const wi=/[\u0590-\u08ac]/;let mi=null,vi=null,yi=!1;class ki{constructor(t,e,i,r){this.parent=t,this.children=e,this.dom=i,this.contentDOM=r,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 r=this.children[e];if(r==t)return i;i+=r.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,r;if(t==this.contentDOM)i=t.childNodes[e-1];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.previousSibling}for(;i&&(!(r=i.pmViewDesc)||r.parent!=this);)i=i.previousSibling;return i?this.posBeforeChild(r)+r.size:this.posAtStart}{let i,r;if(t==this.contentDOM)i=t.childNodes[e];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.nextSibling}for(;i&&(!(r=i.pmViewDesc)||r.parent!=this);)i=i.nextSibling;return i?this.posBeforeChild(r):this.posAtEnd}}let r;if(t==this.dom&&this.contentDOM)r=e>Me(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=2&t.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==e)for(let e=t;;e=e.parentNode){if(e==this.dom){r=!1;break}if(e.previousSibling)break}if(null==r&&e==t.childNodes.length)for(let e=t;;e=e.parentNode){if(e==this.dom){r=!0;break}if(e.nextSibling)break}}return(null==r?i>0:r)?this.posAtEnd:this.posAtStart}nearestDesc(t,e=!1){for(let i=!0,r=t;r;r=r.parentNode){let s,n=this.getDesc(r);if(n&&(!e||n.node)){if(!i||!(s=n.nodeDOM)||(1==s.nodeType?s.contains(1==t.nodeType?t:t.parentNode):s==t))return n;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 r=t;r;r=r.parentNode){let s=this.getDesc(r);if(s)return s.localPosFromDOM(t,e,i)}return-1}descAt(t){for(let e=0,i=0;e<this.children.length;e++){let r=this.children[e],s=i+r.size;if(i==t&&s!=i){for(;!r.border&&r.children.length;)for(let t=0;t<r.children.length;t++){let e=r.children[t];if(e.size){r=e;break}}return r}if(t<s)return r.descAt(t-i-r.border);i=s}}domFromPos(t,e){if(!this.contentDOM)return{node:this.dom,offset:0,atom:t+1};let i=0,r=0;for(let e=0;i<this.children.length;i++){let s=this.children[i],n=e+s.size;if(n>t||s instanceof Bi){r=t-e;break}e=n}if(r)return this.children[i].domFromPos(r-this.children[i].border,e);for(let t;i&&!(t=this.children[i-1]).size&&t instanceof bi&&t.side>=0;i--);if(e<=0){let t,r=!0;for(;t=i?this.children[i-1]:null,t&&t.dom.parentNode!=this.contentDOM;i--,r=!1);return t&&e&&r&&!t.border&&!t.domAtom?t.domFromPos(t.size,e):{node:this.contentDOM,offset:t?Me(t.dom)+1:0}}{let t,r=!0;for(;t=i<this.children.length?this.children[i]:null,t&&t.dom.parentNode!=this.contentDOM;i++,r=!1);return t&&r&&!t.border&&!t.domAtom?t.domFromPos(0,e):{node:this.contentDOM,offset:t?Me(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 r=-1,s=-1;for(let n=i,o=0;;o++){let i=this.children[o],h=n+i.size;if(-1==r&&t<=h){let s=n+i.border;if(t>=s&&e<=h-i.border&&i.node&&i.contentDOM&&this.contentDOM.contains(i.contentDOM))return i.parseRange(t,e,s);t=n;for(let e=o;e>0;e--){let i=this.children[e-1];if(i.size&&i.dom.parentNode==this.contentDOM&&!i.emptyChildAt(1)){r=Me(i.dom)+1;break}t-=i.size}-1==r&&(r=0)}if(r>-1&&(h>e||o==this.children.length-1)){e=h;for(let t=o+1;t<this.children.length;t++){let i=this.children[t];if(i.size&&i.dom.parentNode==this.contentDOM&&!i.emptyChildAt(-1)){s=Me(i.dom);break}e+=i.size}-1==s&&(s=this.contentDOM.childNodes.length);break}n=h}return{node:this.contentDOM,from:t,to:e,fromOffset:r,toOffset:s}}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,r=!1){let s=Math.min(t,e),n=Math.max(t,e);for(let o=0,h=0;o<this.children.length;o++){let l=this.children[o],a=h+l.size;if(s>h&&n<a)return l.setSelection(t-h-l.border,e-h-l.border,i,r);h=a}let o=this.domFromPos(t,t?-1:1),h=e==t?o:this.domFromPos(e,e?-1:1),l=i.root.getSelection(),a=i.domSelectionRange(),u=!1;if((Le||Ye)&&t==e){let{node:t,offset:e}=o;if(3==t.nodeType){if(u=!(!e||"\n"!=t.nodeValue[e-1]),u&&e==t.nodeValue.length)for(let e,i=t;i;i=i.parentNode){if(e=i.nextSibling){"BR"==e.nodeName&&(o=h={node:e.parentNode,offset:Me(e)+1});break}let t=i.pmViewDesc;if(t&&t.node&&t.node.isBlock)break}}else{let i=t.childNodes[e-1];u=i&&("BR"==i.nodeName||"false"==i.contentEditable)}}if(Le&&a.focusNode&&a.focusNode!=h.node&&1==a.focusNode.nodeType){let t=a.focusNode.childNodes[a.focusOffset];t&&"false"==t.contentEditable&&(r=!0)}if(!(r||u&&Ye)&&Se(o.node,o.offset,a.anchorNode,a.anchorOffset)&&Se(h.node,h.offset,a.focusNode,a.focusOffset))return;let c=!1;if((l.extend||t==e)&&(!u||!Le)){l.collapse(o.node,o.offset);try{t!=e&&l.extend(h.node,h.offset),c=!0}catch(t){}}if(!c){if(t>e){let t=o;o=h,h=t}let i=document.createRange();i.setEnd(h.node,h.offset),i.setStart(o.node,o.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,r=0;r<this.children.length;r++){let s=this.children[r],n=i+s.size;if(i==n?t<=n&&e>=i:t<n&&e>i){let r=i+s.border,o=n-s.border;if(t>=r&&e<=o)return this.dirty=t==i||e==n?2:1,void(t!=r||e!=o||!s.contentLost&&s.dom.parentNode==this.contentDOM?s.markDirty(t-r,e-r):s.dirty=3);s.dirty=s.dom!=s.contentDOM||s.dom.parentNode!=this.contentDOM||s.children.length?3:2}i=n}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 bi extends ki{constructor(t,e,i,r){let s,n=e.type.toDOM;if("function"==typeof n&&(n=n(i,(()=>s?s.parent?s.parent.posBeforeChild(s):void 0:r))),!e.type.spec.raw){if(1!=n.nodeType){let t=document.createElement("span");t.appendChild(n),n=t}n.contentEditable="false",n.classList.add("ProseMirror-widget")}super(t,[],n,null),this.widget=e,this.widget=e,s=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 Mi extends ki{constructor(t,e,i,r){super(t,[],e,null),this.textDOM=i,this.text=r}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 xi extends ki{constructor(t,e,i,r,s){super(t,[],i,r),this.mark=e,this.spec=s}static create(t,e,i,r){let s=r.nodeViews[e.type.name],n=s&&s(e,r,i);return n&&n.dom||(n=ft.renderSpec(document,e.type.spec.toDOM(e,i),null,e.attrs)),new xi(t,e,n.dom,n.contentDOM||n.dom,n)}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 r=xi.create(this.parent,this.mark,!0,i),s=this.children,n=this.size;e<n&&(s=zi(s,e,n,i)),t>0&&(s=zi(s,0,t,i));for(let t=0;t<s.length;t++)s[t].parent=r;return r.children=s,r}ignoreMutation(t){return this.spec.ignoreMutation?this.spec.ignoreMutation(t):super.ignoreMutation(t)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Ci extends ki{constructor(t,e,i,r,s,n,o,h,l){super(t,[],s,n),this.node=e,this.outerDeco=i,this.innerDeco=r,this.nodeDOM=o}static create(t,e,i,r,s,n){let o,h=s.nodeViews[e.type.name],l=h&&h(e,s,(()=>o?o.parent?o.parent.posBeforeChild(o):void 0:n),i,r),a=l&&l.dom,u=l&&l.contentDOM;if(e.isText)if(a){if(3!=a.nodeType)throw new RangeError("Text must be rendered as a DOM text node")}else a=document.createTextNode(e.text);else if(!a){let t=ft.renderSpec(document,e.type.spec.toDOM(e),null,e.attrs);({dom:a,contentDOM:u}=t)}u||e.isText||"BR"==a.nodeName||(a.hasAttribute("contenteditable")||(a.contentEditable="false"),e.type.spec.draggable&&(a.draggable=!0));let c=a;return a=Ri(a,i,e),l?o=new Ti(t,e,i,r,a,u||null,c,l,s,n+1):e.isText?new Si(t,e,i,r,a,c,s):new Ci(t,e,i,r,a,u||null,c,s,n+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=()=>c.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)&&ji(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,r=e,s=t.composing?this.localCompositionInfo(t,e):null,n=s&&s.pos>-1?s:null,o=s&&s.pos<0,h=new Ni(this,n&&n.node,t);!function(t,e,i,r){let s=e.locals(t),n=0;if(0==s.length){for(let i=0;i<t.childCount;i++){let o=t.child(i);r(o,s,e.forChild(n,o),i),n+=o.nodeSize}return}let o=0,h=[],l=null;for(let a=0;;){let u,c,f,d;for(;o<s.length&&s[o].to==n;){let t=s[o++];t.widget&&(u?(c||(c=[u])).push(t):u=t)}if(u)if(c){c.sort(Ui);for(let t=0;t<c.length;t++)i(c[t],a,!!l)}else i(u,a,!!l);if(l)d=-1,f=l,l=null;else{if(!(a<t.childCount))break;d=a,f=t.child(a++)}for(let t=0;t<h.length;t++)h[t].to<=n&&h.splice(t--,1);for(;o<s.length&&s[o].from<=n&&s[o].to>n;)h.push(s[o++]);let p=n+f.nodeSize;if(f.isText){let t=p;o<s.length&&s[o].from<t&&(t=s[o].from);for(let e=0;e<h.length;e++)h[e].to<t&&(t=h[e].to);t<p&&(l=f.cut(t-n),f=f.cut(0,t-n),p=t,d=-1)}else for(;o<s.length&&s[o].to<p;)o++;r(f,f.isInline&&!f.isLeaf?h.filter((t=>!t.inline)):h.slice(),e.forChild(n,f),d),n=p}}(this.node,this.innerDeco,((e,s,n)=>{e.spec.marks?h.syncToMarks(e.spec.marks,i,t,s):e.type.side>=0&&!n&&h.syncToMarks(s==this.node.childCount?g.none:this.node.child(s).marks,i,t,s),h.placeWidget(e,t,r)}),((e,n,l,a)=>{let u;h.syncToMarks(e.marks,i,t,a),h.findNodeMatch(e,n,l,a)||o&&t.state.selection.from>r&&t.state.selection.to<r+e.nodeSize&&(u=h.findIndexWithChild(s.node))>-1&&h.updateNodeAt(e,n,l,u,t)||h.updateNextNode(e,n,l,t,a,r)||h.addNode(e,n,l,t,r),r+=e.nodeSize})),h.syncToMarks([],i,t,0),this.node.isTextblock&&h.addTextblockHacks(),h.destroyRest(),(h.changed||2==this.dirty)&&(n&&this.protectLocalComposition(t,n),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:r}=t.state.selection;if(!(t.state.selection instanceof ne)||i<e||r>e+this.node.content.size)return null;let s=t.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let t=s.nodeValue,n=function(t,e,i,r){for(let s=0,n=0;s<t.childCount&&n<=r;){let o=t.child(s++),h=n;if(n+=o.nodeSize,!o.isText)continue;let l=o.text;for(;s<t.childCount;){let e=t.child(s++);if(n+=e.nodeSize,!e.isText)break;l+=e.text}if(n>=i){if(n>=r&&l.slice(r-e.length-h,r-h)==e)return r-e.length;let t=h<r?l.lastIndexOf(e,r-h-1):-1;if(t>=0&&t+e.length+h>=i)return h+t;if(i==r&&l.length>=r+e.length-h&&l.slice(r-h,r-h+e.length)==e)return r}}return-1}(this.node.content,t,i-e,r-e);return n<0?null:{node:s,pos:n,text:t}}return{node:s,pos:-1,text:""}}protectLocalComposition(t,{node:e,pos:i,text:r}){if(this.getDesc(e))return;let s=e;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let n=new Mi(this,s,e,r);t.input.compositionNodes.push(n),this.children=zi(this.children,i,i+r.length,t,n)}update(t,e,i,r){return!(3==this.dirty||!t.sameMarkup(this.node)||(this.updateInner(t,e,i,r),0))}updateInner(t,e,i,r){this.updateOuterDeco(e),this.node=t,this.innerDeco=i,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=0}updateOuterDeco(t){if(ji(t,this.outerDeco))return;let e=1!=this.nodeDOM.nodeType,i=this.dom;this.dom=Pi(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,r,s){Ri(r,e,t);let n=new Ci(void 0,t,e,i,r,r,r,s,0);return n.contentDOM&&n.updateChildren(s,0),n}class Si extends Ci{constructor(t,e,i,r,s,n,o){super(t,e,i,r,s,null,n,o,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,r){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,r.trackWrites==this.nodeDOM&&(r.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 r=this.node.cut(t,e),s=document.createTextNode(r.text);return new Si(this.parent,r,this.outerDeco,this.innerDeco,s,s,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 Bi extends ki{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 Ti extends Ci{constructor(t,e,i,r,s,n,o,h,l,a){super(t,e,i,r,s,n,o,l,a),this.spec=h}update(t,e,i,r){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==t.type||this.spec.multiType)){let s=this.spec.update(t,e,i);return s&&this.updateInner(t,e,i,r),s}return!(!this.contentDOM&&!t.isLeaf)&&super.update(t,e,i,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(t,e,i,r){this.spec.setSelection?this.spec.setSelection(t,e,i.root):super.setSelection(t,e,i,r)}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 r=t.firstChild,s=!1;for(let n=0;n<e.length;n++){let o=e[n],h=o.dom;if(h.parentNode==t){for(;h!=r;)r=Fi(r),s=!0;r=r.nextSibling}else s=!0,t.insertBefore(h,r);if(o instanceof xi){let e=r?r.previousSibling:t.lastChild;Oi(o.contentDOM,o.children,i),r=e?e.nextSibling:t.firstChild}}for(;r;)r=Fi(r),s=!0;s&&i.trackWrites==t&&(i.trackWrites=null)}const Ei=function(t){t&&(this.nodeName=t)};Ei.prototype=Object.create(null);const Ii=[new Ei];function Di(t,e,i){if(0==t.length)return Ii;let r=i?Ii[0]:new Ei,s=[r];for(let n=0;n<t.length;n++){let o=t[n].type.attrs;if(o){o.nodeName&&s.push(r=new Ei(o.nodeName));for(let t in o){let n=o[t];null!=n&&(i&&1==s.length&&s.push(r=new Ei(e.isInline?"span":"div")),"class"==t?r.class=(r.class?r.class+" ":"")+n:"style"==t?r.style=(r.style?r.style+";":"")+n:"nodeName"!=t&&(r[t]=n))}}}return s}function Pi(t,e,i,r){if(i==Ii&&r==Ii)return e;let s=e;for(let e=0;e<r.length;e++){let n=r[e],o=i[e];if(e){let e;o&&o.nodeName==n.nodeName&&s!=t&&(e=s.parentNode)&&e.nodeName.toLowerCase()==n.nodeName||(e=document.createElement(n.nodeName),e.pmIsDeco=!0,e.appendChild(s),o=Ii[0]),s=e}$i(s,o||Ii[0],n)}return s}function $i(t,e,i){for(let r in e)"class"==r||"style"==r||"nodeName"==r||r in i||t.removeAttribute(r);for(let r in i)"class"!=r&&"style"!=r&&"nodeName"!=r&&i[r]!=e[r]&&t.setAttribute(r,i[r]);if(e.class!=i.class){let r=e.class?e.class.split(" ").filter(Boolean):[],s=i.class?i.class.split(" ").filter(Boolean):[];for(let e=0;e<r.length;e++)-1==s.indexOf(r[e])&&t.classList.remove(r[e]);for(let e=0;e<s.length;e++)-1==r.indexOf(s[e])&&t.classList.add(s[e]);0==t.classList.length&&t.removeAttribute("class")}if(e.style!=i.style){if(e.style){let i,r=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;i=r.exec(e.style);)t.style.removeProperty(i[1])}i.style&&(t.style.cssText+=i.style)}}function Ri(t,e,i){return Pi(t,t,Ii,Di(e,i,1!=t.nodeType))}function ji(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 Fi(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}class Ni{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,r=i.children.length,s=t.childCount,n=new Map,o=[];t:for(;s>0;){let h;for(;;)if(r){let t=i.children[r-1];if(!(t instanceof xi)){h=t,r--;break}i=t,r=t.children.length}else{if(i==e)break t;r=i.parent.children.indexOf(i),i=i.parent}let l=h.node;if(l){if(l!=t.child(s-1))break;--s,n.set(h,s),o.push(h)}}return{index:s,matched:n,matches:o.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,r){let s=0,n=this.stack.length>>1,o=Math.min(n,t.length);for(;s<o&&(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,o=this.top.children.length;r<this.preMatch.index&&(o=Math.min(this.index+3,o));for(let e=this.index;e<o;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 r=xi.create(this.top,t[n],e,i);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,n++}}findNodeMatch(t,e,i,r){let s,n=-1;if(r>=this.preMatch.index&&(s=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&s.matchesNode(t,e,i))n=this.top.children.indexOf(s,this.index);else for(let r=this.index,s=Math.min(this.top.children.length,r+5);r<s;r++){let s=this.top.children[r];if(s.matchesNode(t,e,i)&&!this.preMatch.matched.has(s)){n=r;break}}return!(n<0||(this.destroyBetween(this.index,n),this.index++,0))}updateNodeAt(t,e,i,r,s){let n=this.top.children[r];return 3==n.dirty&&n.dom==n.contentDOM&&(n.dirty=2),!!n.update(t,e,i,s)&&(this.destroyBetween(this.index,r),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,r,s,n){for(let o=this.index;o<this.top.children.length;o++){let h=this.top.children[o];if(h instanceof Ci){let l=this.preMatch.matched.get(h);if(null!=l&&l!=s)return!1;let a,u=h.dom,c=this.isLocked(u)&&!(t.isText&&h.node&&h.node.isText&&h.nodeDOM.nodeValue==t.text&&3!=h.dirty&&ji(e,h.outerDeco));if(!c&&h.update(t,e,i,r))return this.destroyBetween(this.index,o),h.dom!=u&&(this.changed=!0),this.index++,!0;if(!c&&(a=this.recreateWrapper(h,t,e,i,r,n)))return this.destroyBetween(this.index,o),this.top.children[this.index]=a,a.contentDOM&&(a.dirty=2,a.updateChildren(r,n+1),a.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(t,e,i,r,s,n){if(t.dirty||e.isAtom||!t.children.length||!t.node.content.eq(e.content)||!ji(i,t.outerDeco)||!r.eq(t.innerDeco))return null;let o=Ci.create(this.top,e,i,r,s,n);if(o.contentDOM){o.children=t.children,t.children=[];for(let t of o.children)t.parent=o}return t.destroy(),o}addNode(t,e,i,r,s){let n=Ci.create(this.top,t,e,i,r,s);n.contentDOM&&n.updateChildren(r,s+1),this.top.children.splice(this.index++,0,n),this.changed=!0}placeWidget(t,e,i){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(!r||!r.matchesWidget(t)||t!=r.widget&&r.widget.type.toDOM.parentNode){let r=new bi(this.top,t,e,i);this.top.children.splice(this.index++,0,r),this.changed=!0}else this.index++}addTextblockHacks(){let t=this.top.children[this.index-1],e=this.top;for(;t instanceof xi;)e=t,t=e.children[e.children.length-1];(!t||!(t instanceof Si)||/\n$/.test(t.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(t.node.text))&&((Ye||He)&&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 r=new Bi(this.top,[],i,null);e!=this.top?e.children.push(r):e.children.splice(this.index++,0,r),this.changed=!0}}isLocked(t){return this.lock&&(t==this.lock||1==t.nodeType&&t.contains(this.lock.parentNode))}}function Ui(t,e){return t.type.side-e.type.side}function zi(t,e,i,r,s){let n=[];for(let o=0,h=0;o<t.length;o++){let l=t[o],a=h,u=h+=l.size;a>=i||u<=e?n.push(l):(a<e&&n.push(l.slice(0,e-a,r)),s&&(n.push(s),s=void 0),u>i&&n.push(l.slice(i-a,l.size,r)))}return n}function Li(t,e=null){let i=t.domSelectionRange(),r=t.state.doc;if(!i.focusNode)return null;let s=t.docView.nearestDesc(i.focusNode),n=s&&0==s.size,o=t.docView.posFromDOM(i.focusNode,i.focusOffset,1);if(o<0)return null;let h,l,a=r.resolve(o);if(Ie(i)){for(h=o;s&&!s.node;)s=s.parent;let t=s.node;if(s&&t.isAtom&&he.isSelectable(t)&&s.parent&&(!t.isInline||!function(t,e,i){for(let r=0==e,s=e==Oe(t);r||s;){if(t==i)return!0;let e=Me(t);if(!(t=t.parentNode))return!1;r=r&&0==e,s=s&&e==Oe(t)}}(i.focusNode,i.focusOffset,s.dom))){let t=s.posBefore;l=new he(o==t?a:r.resolve(t))}}else{if(i instanceof t.dom.ownerDocument.defaultView.Selection&&i.rangeCount>1){let e=o,s=o;for(let r=0;r<i.rangeCount;r++){let n=i.getRangeAt(r);e=Math.min(e,t.docView.posFromDOM(n.startContainer,n.startOffset,1)),s=Math.max(s,t.docView.posFromDOM(n.endContainer,n.endOffset,-1))}if(e<0)return null;[h,o]=s==t.state.selection.anchor?[s,e]:[e,s],a=r.resolve(o)}else h=t.docView.posFromDOM(i.anchorNode,i.anchorOffset,1);if(h<0)return null}let u=r.resolve(h);return l||(l=Ki(t,u,a,"pointer"==e||t.state.selection.head<a.pos&&!n?1:-1)),l}function _i(t){return t.editable?t.hasFocus():Gi(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function Hi(t,e=!1){let i=t.state.selection;if(Ji(t,i),_i(t)){if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&He){let e=t.domSelectionRange(),i=t.domObserver.currentSelection;if(e.anchorNode&&i.anchorNode&&Se(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,r="IMG"==i.nodeName;r?e.collapse(i.parentNode,Me(i)+1):e.collapse(i,0),!r&&!t.state.selection.visible&&Ue&&ze<=11&&(i.disabled=!0,i.disabled=!1)}(t);else{let r,s,{anchor:n,head:o}=i;!Xi||i instanceof ne||(i.$from.parent.inlineContent||(r=Yi(t,i.from)),i.empty||i.$from.parent.inlineContent||(s=Yi(t,i.to))),t.docView.setSelection(n,o,t,e),Xi&&(r&&Vi(r),s&&Vi(s)),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(),r=i.anchorNode,s=i.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{i.anchorNode==r&&i.anchorOffset==s||(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 Xi=Ye||He&&Xe<63;function Yi(t,e){let{node:i,offset:r}=t.docView.domFromPos(e,0),s=r<i.childNodes.length?i.childNodes[r]:null,n=r?i.childNodes[r-1]:null;if(Ye&&s&&"false"==s.contentEditable)return Wi(s);if(!(s&&"false"!=s.contentEditable||n&&"false"!=n.contentEditable)){if(s)return Wi(s);if(n)return Wi(n)}}function Wi(t){return t.contentEditable="true",Ye&&t.draggable&&(t.draggable=!1,t.wasDraggable=!0),t}function Vi(t){t.contentEditable="false",t.wasDraggable&&(t.draggable=!0,t.wasDraggable=null)}function Ji(t,e){if(e instanceof he){let i=t.docView.descAt(e.from);i!=t.lastSelectedViewDesc&&(Qi(t),i&&i.selectNode(),t.lastSelectedViewDesc=i)}else Qi(t)}function Qi(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Ki(t,e,i,r){return t.someProp("createSelectionBetween",(r=>r(t,e,i)))||ne.between(e,i,r)}function qi(t){return!(t.editable&&!t.hasFocus())&&Gi(t)}function Gi(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 Zi(t,e){let{$anchor:i,$head:r}=t.selection,s=e>0?i.max(r):i.min(r),n=s.parent.inlineContent?s.depth?t.doc.resolve(e>0?s.after():s.before()):null:s;return n&&ee.findFrom(n,e)}function tr(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function er(t,e,i){let r=t.state.selection;if(!(r instanceof ne)){if(r instanceof he&&r.node.isInline)return tr(t,new ne(e>0?r.$to:r.$from));{let i=Zi(t.state,e);return!!i&&tr(t,i)}}if(i.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let n=t.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return tr(t,new ne(r.$anchor,n))}if(!r.empty)return!1;if(t.endOfTextblock(e>0?"forward":"backward")){let i=Zi(t.state,e);return!!(i&&i instanceof he)&&tr(t,i)}if(!(Ve&&i.indexOf("m")>-1)){let i,s=r.$head,n=s.textOffset?null:e<0?s.nodeBefore:s.nodeAfter;if(!n||n.isText)return!1;let o=e<0?s.pos-n.nodeSize:s.pos;return!!(n.isAtom||(i=t.docView.descAt(o))&&!i.contentDOM)&&(he.isSelectable(n)?tr(t,new he(e<0?t.state.doc.resolve(s.pos-n.nodeSize):s)):!!Ke&&tr(t,new ne(t.state.doc.resolve(e<0?o:o+n.nodeSize))))}}function ir(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function rr(t,e){let i=t.pmViewDesc;return i&&0==i.size&&(e<0||t.nextSibling||"BR"!=t.nodeName)}function sr(t,e){return e<0?function(t){let e=t.domSelectionRange(),i=e.focusNode,r=e.focusOffset;if(!i)return;let s,n,o=!1;for(Le&&1==i.nodeType&&r<ir(i)&&rr(i.childNodes[r],-1)&&(o=!0);;)if(r>0){if(1!=i.nodeType)break;{let t=i.childNodes[r-1];if(rr(t,-1))s=i,n=--r;else{if(3!=t.nodeType)break;i=t,r=i.nodeValue.length}}}else{if(nr(i))break;{let e=i.previousSibling;for(;e&&rr(e,-1);)s=i.parentNode,n=Me(e),e=e.previousSibling;if(e)i=e,r=ir(i);else{if(i=i.parentNode,i==t.dom)break;r=0}}}o?or(t,i,r):s&&or(t,s,n)}(t):function(t){let e=t.domSelectionRange(),i=e.focusNode,r=e.focusOffset;if(!i)return;let s,n,o=ir(i);for(;;)if(r<o){if(1!=i.nodeType)break;if(!rr(i.childNodes[r],1))break;s=i,n=++r}else{if(nr(i))break;{let e=i.nextSibling;for(;e&&rr(e,1);)s=e.parentNode,n=Me(e)+1,e=e.nextSibling;if(e)i=e,r=0,o=ir(i);else{if(i=i.parentNode,i==t.dom)break;r=o=0}}}s&&or(t,s,n)}(t)}function nr(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function or(t,e,i){if(3!=e.nodeType){let t,r;(r=function(t,e){for(;t&&e==t.childNodes.length&&!Ee(t);)e=Me(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=r,i=0):(t=function(t,e){for(;t&&!e&&!Ee(t);)e=Me(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 r=t.domSelection();if(!r)return;if(Ie(r)){let t=document.createRange();t.setEnd(e,i),t.setStart(e,i),r.removeAllRanges(),r.addRange(t)}else r.extend&&r.extend(e,i);t.domObserver.setCurSelection();let{state:s}=t;setTimeout((()=>{t.state==s&&Hi(t)}),50)}function hr(t,e){let i=t.state.doc.resolve(e);if(!He&&!Je&&i.parent.inlineContent){let r=t.coordsAtPos(e);if(e>i.start()){let i=t.coordsAtPos(e-1),s=(i.top+i.bottom)/2;if(s>r.top&&s<r.bottom&&Math.abs(i.left-r.left)>1)return i.left<r.left?"ltr":"rtl"}if(e<i.end()){let i=t.coordsAtPos(e+1),s=(i.top+i.bottom)/2;if(s>r.top&&s<r.bottom&&Math.abs(i.left-r.left)>1)return i.left>r.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(t.dom).direction?"rtl":"ltr"}function lr(t,e,i){let r=t.state.selection;if(r instanceof ne&&!r.empty||i.indexOf("s")>-1)return!1;if(Ve&&i.indexOf("m")>-1)return!1;let{$from:s,$to:n}=r;if(!s.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let i=Zi(t.state,e);if(i&&i instanceof he)return tr(t,i)}if(!s.parent.inlineContent){let i=e<0?s:n,o=r instanceof ae?ee.near(i,e):ee.findFrom(i,e);return!!o&&tr(t,o)}return!1}function ar(t,e){if(!(t.state.selection instanceof ne))return!0;let{$head:i,$anchor:r,empty:s}=t.state.selection;if(!i.sameParent(r))return!0;if(!s)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let n=!i.textOffset&&(e<0?i.nodeBefore:i.nodeAfter);if(n&&!n.isText){let r=t.state.tr;return e<0?r.delete(i.pos-n.nodeSize,i.pos):r.delete(i.pos,i.pos+n.nodeSize),t.dispatch(r),!0}return!1}function ur(t,e,i){t.domObserver.stop(),e.contentEditable=i,t.domObserver.start()}function cr(t,e){t.someProp("transformCopied",(i=>{e=i(e,t)}));let i=[],{content:r,openStart:s,openEnd:n}=e;for(;s>1&&n>1&&1==r.childCount&&1==r.firstChild.childCount;){s--,n--;let t=r.firstChild;i.push(t.type.name,t.attrs!=t.type.defaultAttrs?t.attrs:null),r=t.content}let o=t.someProp("clipboardSerializer")||ft.fromSchema(t.state.schema),h=br(),l=h.createElement("div");l.appendChild(o.serializeFragment(r,{document:h}));let a,u=l.firstChild,c=0;for(;u&&1==u.nodeType&&(a=yr[u.nodeName.toLowerCase()]);){for(let t=a.length-1;t>=0;t--){let e=h.createElement(a[t]);for(;l.firstChild;)e.appendChild(l.firstChild);l.appendChild(e),c++}u=l.firstChild}u&&1==u.nodeType&&u.setAttribute("data-pm-slice",`${s} ${n}${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 fr(t,e,i,r,s){let n,o,h=s.parent.type.spec.code;if(!i&&!e)return null;let l=!!e&&(r||h||!i);if(l){if(t.someProp("transformPastedText",(i=>{e=i(e,h||r,t)})),h)return o=new m(c.from(t.state.schema.text(e.replace(/\r\n?/g,"\n"))),0,0),t.someProp("transformPasted",(e=>{o=e(o,t,!0)})),o;let i=t.someProp("clipboardTextParser",(i=>i(e,s,r,t)));if(i)o=i;else{let i=s.marks(),{schema:r}=t.state,o=ft.fromSchema(r);n=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach((t=>{let e=n.appendChild(document.createElement("p"));t&&e.appendChild(o.serializeNode(r.text(t,i)))}))}}else t.someProp("transformPastedHTML",(e=>{i=e(i,t)})),n=function(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let i,r=br().createElement("div"),s=/<([a-z][^>\s]+)/i.exec(t);if((i=s&&yr[s[1].toLowerCase()])&&(t=i.map((t=>"<"+t+">")).join("")+t+i.map((t=>"</"+t+">")).reverse().join("")),r.innerHTML=function(t){let e=window.trustedTypes;return e?(Mr||(Mr=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),Mr.createHTML(t)):t}(t),i)for(let t=0;t<i.length;t++)r=r.querySelector(i[t])||r;return r}(i),Ke&&function(t){let e=t.querySelectorAll(He?"span:not([class]):not([style])":"span.Apple-converted-space");for(let i=0;i<e.length;i++){let r=e[i];1==r.childNodes.length&&" "==r.textContent&&r.parentNode&&r.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),r)}}(n);let a=n&&n.querySelector("[data-pm-slice]"),u=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let t=+u[3];t>0;t--){let t=n.firstChild;for(;t&&1!=t.nodeType;)t=t.nextSibling;if(!t)break;n=t}if(!o){let e=t.someProp("clipboardParser")||t.someProp("domParser")||it.fromSchema(t.state.schema);o=e.parseSlice(n,{preserveWhitespace:!(!l&&!u),context:s,ruleFromNode:t=>"BR"!=t.nodeName||t.nextSibling||!t.parentNode||dr.test(t.parentNode.nodeName)?null:{ignore:!0}})}if(u)o=function(t,e){if(!t.size)return t;let i,r=t.content.firstChild.type.schema;try{i=JSON.parse(e)}catch(e){return t}let{content:s,openStart:n,openEnd:o}=t;for(let t=i.length-2;t>=0;t-=2){let e=r.nodes[i[t]];if(!e||e.hasRequiredAttrs())break;s=c.from(e.create(i[t+1],s)),n++,o++}return new m(s,n,o)}(vr(o,+u[1],+u[2]),u[4]);else if(o=m.maxOpen(function(t,e){if(t.childCount<2)return t;for(let i=e.depth;i>=0;i--){let r,s=e.node(i).contentMatchAt(e.index(i)),n=[];if(t.forEach((t=>{if(!n)return;let e,i=s.findWrapping(t.type);if(!i)return n=null;if(e=n.length&&r.length&&gr(i,r,t,n[n.length-1],0))n[n.length-1]=e;else{n.length&&(n[n.length-1]=wr(n[n.length-1],r.length));let e=pr(t,i);n.push(e),s=s.matchType(e.type),r=i}})),n)return c.from(n)}return t}(o.content,s),!0),o.openStart||o.openEnd){let t=0,e=0;for(let e=o.content.firstChild;t<o.openStart&&!e.type.spec.isolating;t++,e=e.firstChild);for(let t=o.content.lastChild;e<o.openEnd&&!t.type.spec.isolating;e++,t=t.lastChild);o=vr(o,t,e)}return t.someProp("transformPasted",(e=>{o=e(o,t,l)})),o}const dr=/^(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 pr(t,e,i=0){for(let r=e.length-1;r>=i;r--)t=e[r].create(null,c.from(t));return t}function gr(t,e,i,r,s){if(s<t.length&&s<e.length&&t[s]==e[s]){let n=gr(t,e,i,r.lastChild,s+1);if(n)return r.copy(r.content.replaceChild(r.childCount-1,n));if(r.contentMatchAt(r.childCount).matchType(s==t.length-1?i.type:t[s+1]))return r.copy(r.content.append(c.from(pr(i,t,s+1))))}}function wr(t,e){if(0==e)return t;let i=t.content.replaceChild(t.childCount-1,wr(t.lastChild,e-1)),r=t.contentMatchAt(t.childCount).fillBefore(c.empty,!0);return t.copy(i.append(r))}function mr(t,e,i,r,s,n){let o=e<0?t.firstChild:t.lastChild,h=o.content;return t.childCount>1&&(n=0),s<r-1&&(h=mr(h,e,i,r,s+1,n)),s>=i&&(h=e<0?o.contentMatchAt(0).fillBefore(h,n<=s).append(h):h.append(o.contentMatchAt(o.childCount).fillBefore(c.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,o.copy(h))}function vr(t,e,i){return e<t.openStart&&(t=new m(mr(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),i<t.openEnd&&(t=new m(mr(t.content,1,i,t.openEnd,0,0),t.openStart,i)),t}const yr={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 kr=null;function br(){return kr||(kr=document.implementation.createHTMLDocument("title"))}let Mr=null;const xr={},Cr={},Ar={touchstart:!0,touchmove:!0};class Sr{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.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Br(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function Tr(t){t.someProp("handleDOMEvents",(e=>{for(let i in e)t.input.eventHandlers[i]||t.dom.addEventListener(i,t.input.eventHandlers[i]=e=>Or(t,e))}))}function Or(t,e){return t.someProp("handleDOMEvents",(i=>{let r=i[e.type];return!!r&&(r(t,e)||e.defaultPrevented)}))}function Er(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 Ir(t){return{left:t.clientX,top:t.clientY}}function Dr(t,e,i,r,s){if(-1==r)return!1;let n=t.state.doc.resolve(r);for(let r=n.depth+1;r>0;r--)if(t.someProp(e,(e=>r>n.depth?e(t,i,n.nodeAfter,n.before(r),s,!0):e(t,i,n.node(r),n.before(r),s,!1))))return!0;return!1}function Pr(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 $r(t,e,i,r){return Dr(t,"handleDoubleClickOn",e,i,r)||t.someProp("handleDoubleClick",(i=>i(t,e,r)))}function Rr(t,e,i,r){return Dr(t,"handleTripleClickOn",e,i,r)||t.someProp("handleTripleClick",(i=>i(t,e,r)))||function(t,e,i){if(0!=i.button)return!1;let r=t.state.doc;if(-1==e)return!!r.inlineContent&&(Pr(t,ne.create(r,0,r.content.size)),!0);let s=r.resolve(e);for(let e=s.depth+1;e>0;e--){let i=e>s.depth?s.nodeAfter:s.node(e),n=s.before(e);if(i.inlineContent)Pr(t,ne.create(r,n+1,n+1+i.content.size));else{if(!he.isSelectable(i))continue;Pr(t,he.create(r,n))}return!0}}(t,i,r)}function jr(t){return Hr(t)}Cr.keydown=(t,e)=>{let i=e;if(t.input.shiftKey=16==i.keyCode||i.shiftKey,!Ur(t,i)&&(t.input.lastKeyCode=i.keyCode,t.input.lastKeyCodeTime=Date.now(),!Qe||!He||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,r=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||Ve&&72==i&&"c"==r)return ar(t,-1)||sr(t,-1);if(46==i&&!e.shiftKey||Ve&&68==i&&"c"==r)return ar(t,1)||sr(t,1);if(13==i||27==i)return!0;if(37==i||Ve&&66==i&&"c"==r){let e=37==i?"ltr"==hr(t,t.state.selection.from)?-1:1:-1;return er(t,e,r)||sr(t,e)}if(39==i||Ve&&70==i&&"c"==r){let e=39==i?"ltr"==hr(t,t.state.selection.from)?1:-1:1;return er(t,e,r)||sr(t,e)}return 38==i||Ve&&80==i&&"c"==r?lr(t,-1,r)||sr(t,-1):40==i||Ve&&78==i&&"c"==r?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;ur(t,i,"true"),setTimeout((()=>ur(t,i,"false")),20)}return!1}(t)||lr(t,1,r)||sr(t,1):r==(Ve?"m":"c")&&(66==i||73==i||89==i||90==i)}(t,i)?i.preventDefault():Br(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)}},Cr.keyup=(t,e)=>{16==e.keyCode&&(t.input.shiftKey=!1)},Cr.keypress=(t,e)=>{let i=e;if(Ur(t,i)||!i.charCode||i.ctrlKey&&!i.altKey||Ve&&i.metaKey)return;if(t.someProp("handleKeyPress",(e=>e(t,i))))return void i.preventDefault();let r=t.state.selection;if(!(r instanceof ne&&r.$from.sameParent(r.$to))){let e=String.fromCharCode(i.charCode),s=()=>t.state.tr.insertText(e).scrollIntoView();/[\r\n]/.test(e)||t.someProp("handleTextInput",(i=>i(t,r.$from.pos,r.$to.pos,e,s)))||t.dispatch(s()),i.preventDefault()}};const Fr=Ve?"metaKey":"ctrlKey";xr.mousedown=(t,e)=>{let i=e;t.input.shiftKey=i.shiftKey;let r=jr(t),s=Date.now(),n="singleClick";s-t.input.lastClick.time<500&&function(t,e){let i=e.x-t.clientX,r=e.y-t.clientY;return i*i+r*r<100}(i,t.input.lastClick)&&!i[Fr]&&t.input.lastClick.button==i.button&&("singleClick"==t.input.lastClick.type?n="doubleClick":"doubleClick"==t.input.lastClick.type&&(n="tripleClick")),t.input.lastClick={time:s,x:i.clientX,y:i.clientY,type:n,button:i.button};let o=t.posAtCoords(Ir(i));o&&("singleClick"==n?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new Nr(t,o,i,!!r)):("doubleClick"==n?$r:Rr)(t,o.pos,o.inside,i)?i.preventDefault():Br(t,"pointer"))};class Nr{constructor(t,e,i,r){let s,n;if(this.view=t,this.pos=e,this.event=i,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=t.state.doc,this.selectNode=!!i[Fr],this.allowDefault=i.shiftKey,e.inside>-1)s=t.state.doc.nodeAt(e.inside),n=e.inside;else{let i=t.state.doc.resolve(e.pos);s=i.parent,n=i.depth?i.before():0}const o=r?null:i.target,h=o?t.docView.nearestDesc(o,!0):null;this.target=h&&1==h.nodeDOM.nodeType?h.nodeDOM:null;let{selection:l}=t.state;(0==i.button&&s.type.spec.draggable&&!1!==s.type.spec.selectable||l instanceof he&&l.from<=n&&l.to>n)&&(this.mightDrag={node:s,pos:n,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!Le||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)),Br(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((()=>Hi(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(Ir(t))),this.updateAllowDefault(t),this.allowDefault||!e?Br(this.view,"pointer"):function(t,e,i,r,s){return Dr(t,"handleClickOn",e,i,r)||t.someProp("handleClick",(i=>i(t,e,r)))||(s?function(t,e){if(-1==e)return!1;let i,r,s=t.state.selection;s instanceof he&&(i=s.node);let n=t.state.doc.resolve(e);for(let t=n.depth+1;t>0;t--){let e=t>n.depth?n.nodeAfter:n.node(t);if(he.isSelectable(e)){r=i&&s.$from.depth>0&&t>=s.$from.depth&&n.before(s.$from.depth+1)==s.$from.pos?n.before(s.$from.depth):n.before(t);break}}return null!=r&&(Pr(t,he.create(t.state.doc,r)),!0)}(t,i):function(t,e){if(-1==e)return!1;let i=t.state.doc.resolve(e),r=i.nodeAfter;return!!(r&&r.isAtom&&he.isSelectable(r))&&(Pr(t,new he(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||He&&!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)?(Pr(this.view,ee.near(this.view.state.doc.resolve(e.pos))),t.preventDefault()):Br(this.view,"pointer")}move(t){this.updateAllowDefault(t),Br(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 Ur(t,e){return!!t.composing||!!(Ye&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500)&&(t.input.compositionEndedAt=-2e8,!0)}xr.touchstart=t=>{t.input.lastTouch=Date.now(),jr(t),Br(t,"pointer")},xr.touchmove=t=>{t.input.lastTouch=Date.now(),Br(t,"pointer")},xr.contextmenu=t=>jr(t);const zr=Qe?5e3:-1;function Lr(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout((()=>Hr(t)),e))}function _r(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 Hr(t,e=!1){if(!(Qe&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),_r(t),e||t.docView&&t.docView.dirty){let i=Li(t),r=t.state.selection;return i&&!i.eq(r)?t.dispatch(t.state.tr.setSelection(i)):!t.markCursor&&!e||r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?t.updateState(t.state):t.dispatch(t.state.tr.deleteSelection()),!0}return!1}}Cr.compositionstart=Cr.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,i=e.selection.$to;if(e.selection instanceof ne&&(e.storedMarks||!i.textOffset&&i.parentOffset&&i.nodeBefore.marks.some((t=>!1===t.type.spec.inclusive))||He&&Je&&function(t){let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(!e||1!=e.nodeType||i>=e.childNodes.length)return!1;let r=e.childNodes[i];return 1==r.nodeType&&"false"==r.contentEditable}(t)))t.markCursor=t.state.storedMarks||i.marks(),Hr(t,!0),t.markCursor=null;else if(Hr(t,!e.selection.empty),Le&&e.selection.empty&&i.parentOffset&&!i.textOffset&&i.nodeBefore.marks.length){let e=t.domSelectionRange();for(let i=e.focusNode,r=e.focusOffset;i&&1==i.nodeType&&0!=r;){let e=r<0?i.lastChild:i.childNodes[r-1];if(!e)break;if(3==e.nodeType){let i=t.domSelection();i&&i.collapse(e,e.nodeValue.length);break}i=e,r=-1}}t.input.composing=!0}Lr(t,zr)},Cr.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.badSafariComposition?t.domObserver.forceFlush():t.input.compositionPendingChanges&&Promise.resolve().then((()=>t.domObserver.flush())),t.input.compositionID++,Lr(t,20))};const Xr=Ue&&ze<15||We&&qe<604;function Yr(t,e,i,r,s){let n=fr(t,e,i,r,t.state.selection.$from);if(t.someProp("handlePaste",(e=>e(t,s,n||m.empty))))return!0;if(!n)return!1;let o=function(t){return 0==t.openStart&&0==t.openEnd&&1==t.content.childCount?t.content.firstChild:null}(n),h=o?t.state.tr.replaceSelectionWith(o,r):t.state.tr.replaceSelection(n);return t.dispatch(h.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Wr(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," "):""}xr.copy=Cr.cut=(t,e)=>{let i=e,r=t.state.selection,s="cut"==i.type;if(r.empty)return;let n=Xr?null:i.clipboardData,o=r.content(),{dom:h,text:l}=cr(t,o);n?(i.preventDefault(),n.clearData(),n.setData("text/html",h.innerHTML),n.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 r=getSelection(),s=document.createRange();s.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(s),setTimeout((()=>{i.parentNode&&i.parentNode.removeChild(i),t.focus()}),50)}(t,h),s&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},Cr.paste=(t,e)=>{let i=e;if(t.composing&&!Qe)return;let r=Xr?null:i.clipboardData,s=t.input.shiftKey&&45!=t.input.lastKeyCode;r&&Yr(t,Wr(r),r.getData("text/html"),s,i)?i.preventDefault():function(t,e){if(!t.dom.parentNode)return;let i=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.dom.parentNode.appendChild(document.createElement(i?"textarea":"div"));i||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let s=t.input.shiftKey&&45!=t.input.lastKeyCode;setTimeout((()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),i?Yr(t,r.value,null,s,e):Yr(t,r.textContent,r.innerHTML,s,e)}),50)}(t,i)};class Vr{constructor(t,e,i){this.slice=t,this.move=e,this.node=i}}const Jr=Ve?"altKey":"ctrlKey";function Qr(t,e){let i=t.someProp("dragCopies",(t=>!t(e)));return null!=i?i:!e[Jr]}xr.dragstart=(t,e)=>{let i=e,r=t.input.mouseDown;if(r&&r.done(),!i.dataTransfer)return;let s,n=t.state.selection,o=n.empty?null:t.posAtCoords(Ir(i));if(o&&o.pos>=n.from&&o.pos<=(n instanceof he?n.to-1:n.to));else if(r&&r.mightDrag)s=he.create(t.state.doc,r.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&&(s=he.create(t.state.doc,e.posBefore))}let h=(s||t.state.selection).content(),{dom:l,text:a,slice:u}=cr(t,h);(!i.dataTransfer.files.length||!He||Xe>120)&&i.dataTransfer.clearData(),i.dataTransfer.setData(Xr?"Text":"text/html",l.innerHTML),i.dataTransfer.effectAllowed="copyMove",Xr||i.dataTransfer.setData("text/plain",a),t.dragging=new Vr(u,Qr(t,i),s)},xr.dragend=t=>{let e=t.dragging;window.setTimeout((()=>{t.dragging==e&&(t.dragging=null)}),50)},Cr.dragover=Cr.dragenter=(t,e)=>e.preventDefault(),Cr.drop=(t,e)=>{try{!function(t,e,i){if(!e.dataTransfer)return;let r=t.posAtCoords(Ir(e));if(!r)return;let s=t.state.doc.resolve(r.pos),n=i&&i.slice;n?t.someProp("transformPasted",(e=>{n=e(n,t,!1)})):n=fr(t,Wr(e.dataTransfer),Xr?null:e.dataTransfer.getData("text/html"),!1,s);let o=!(!i||!Qr(t,e));if(t.someProp("handleDrop",(i=>i(t,e,n||m.empty,o))))return void e.preventDefault();if(!n)return;e.preventDefault();let h=n?function(t,e,i){let r=t.resolve(e);if(!i.content.size)return e;let s=i.content;for(let t=0;t<i.openStart;t++)s=s.firstChild.content;for(let t=1;t<=(0==i.openStart&&i.size?2:1);t++)for(let e=r.depth;e>=0;e--){let i=e==r.depth?0:r.pos<=(r.start(e+1)+r.end(e+1))/2?-1:1,n=r.index(e)+(i>0?1:0),o=r.node(e),h=!1;if(1==t)h=o.canReplace(n,n,s);else{let t=o.contentMatchAt(n).findWrapping(s.firstChild.type);h=t&&o.canReplaceWith(n,n,t[0])}if(h)return 0==i?r.pos:i<0?r.before(e+1):r.after(e+1)}return null}(t.state.doc,s.pos,n):s.pos;null==h&&(h=s.pos);let l=t.state.tr;if(o){let{node:t}=i;t?t.replace(l):l.deleteSelection()}let a=l.mapping.map(h),u=0==n.openStart&&0==n.openEnd&&1==n.content.childCount,c=l.doc;if(u?l.replaceRangeWith(a,a,n.content.firstChild):l.replaceRange(a,a,n),l.doc.eq(c))return;let f=l.doc.resolve(a);if(u&&he.isSelectable(n.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(n.content.firstChild))l.setSelection(new he(f));else{let e=l.mapping.map(h);l.mapping.maps[l.mapping.maps.length-1].forEach(((t,i,r,s)=>e=s)),l.setSelection(Ki(t,f,l.doc.resolve(e)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}(t,e,t.dragging)}finally{t.dragging=null}},xr.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())&&Hi(t)}),20))},xr.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)},xr.beforeinput=(t,e)=>{if(He&&Qe&&"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 Cr)xr[t]=Cr[t];function Kr(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 qr{constructor(t,e){this.toDOM=t,this.spec=e||is,this.side=this.spec.side||0}map(t,e,i,r){let{pos:s,deleted:n}=t.mapResult(e.from+r,this.side<0?-1:1);return n?null:new ts(s-i,s-i,this)}valid(){return!0}eq(t){return this==t||t instanceof qr&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&Kr(this.spec,t.spec))}destroy(t){this.spec.destroy&&this.spec.destroy(t)}}class Gr{constructor(t,e){this.attrs=t,this.spec=e||is}map(t,e,i,r){let s=t.map(e.from+r,this.spec.inclusiveStart?-1:1)-i,n=t.map(e.to+r,this.spec.inclusiveEnd?1:-1)-i;return s>=n?null:new ts(s,n,this)}valid(t,e){return e.from<e.to}eq(t){return this==t||t instanceof Gr&&Kr(this.attrs,t.attrs)&&Kr(this.spec,t.spec)}static is(t){return t.type instanceof Gr}destroy(){}}class Zr{constructor(t,e){this.attrs=t,this.spec=e||is}map(t,e,i,r){let s=t.mapResult(e.from+r,1);if(s.deleted)return null;let n=t.mapResult(e.to+r,-1);return n.deleted||n.pos<=s.pos?null:new ts(s.pos-i,n.pos-i,this)}valid(t,e){let i,{index:r,offset:s}=t.content.findIndex(e.from);return s==e.from&&!(i=t.child(r)).isText&&s+i.nodeSize==e.to}eq(t){return this==t||t instanceof Zr&&Kr(this.attrs,t.attrs)&&Kr(this.spec,t.spec)}destroy(){}}class ts{constructor(t,e,i){this.from=t,this.to=e,this.type=i}copy(t,e){return new ts(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 ts(t,t,new qr(e,i))}static inline(t,e,i,r){return new ts(t,e,new Gr(i,r))}static node(t,e,i,r){return new ts(t,e,new Zr(i,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof Gr}get widget(){return this.type instanceof qr}}const es=[],is={};class rs{constructor(t,e){this.local=t.length?t:es,this.children=e.length?e:es}static create(t,e){return e.length?us(e,t,0,is):ss}find(t,e,i){let r=[];return this.findInner(null==t?0:t,null==e?1e9:e,r,0,i),r}findInner(t,e,i,r,s){for(let n=0;n<this.local.length;n++){let o=this.local[n];o.from<=e&&o.to>=t&&(!s||s(o.spec))&&i.push(o.copy(o.from+r,o.to+r))}for(let n=0;n<this.children.length;n+=3)if(this.children[n]<e&&this.children[n+1]>t){let o=this.children[n]+1;this.children[n+2].findInner(t-o,e-o,i,r+o,s)}}map(t,e,i){return this==ss||0==t.maps.length?this:this.mapInner(t,e,0,0,i||is)}mapInner(t,e,i,r,s){let n;for(let o=0;o<this.local.length;o++){let h=this.local[o].map(t,i,r);h&&h.type.valid(e,h)?(n||(n=[])).push(h):s.onRemove&&s.onRemove(this.local[o].spec)}return this.children.length?function(t,e,i,r,s,n,o){let h=t.slice();for(let t=0,e=n;t<i.maps.length;t++){let r=0;i.maps[t].forEach(((t,i,s,n)=>{let o=n-s-(i-t);for(let s=0;s<h.length;s+=3){let n=h[s+1];if(n<0||t>n+e-r)continue;let l=h[s]+e-r;i>=l?h[s+1]=t<=l?-2:-1:t>=e&&o&&(h[s]+=o,h[s+1]+=o)}r+=o})),e=i.maps[t].map(e,-1)}let l=!1;for(let e=0;e<h.length;e+=3)if(h[e+1]<0){if(-2==h[e+1]){l=!0,h[e+1]=-1;continue}let a=i.map(t[e]+n),u=a-s;if(u<0||u>=r.content.size){l=!0;continue}let c=i.map(t[e+1]+n,-1)-s,{index:f,offset:d}=r.content.findIndex(u),p=r.maybeChild(f);if(p&&d==u&&d+p.nodeSize==c){let r=h[e+2].mapInner(i,p,a+1,t[e]+n+1,o);r!=ss?(h[e]=u,h[e+1]=c,h[e+2]=r):(h[e+1]=-2,l=!0)}else l=!0}if(l){let l=function(t,e,i,r,s,n,o){function h(t,e){for(let n=0;n<t.local.length;n++){let h=t.local[n].map(r,s,e);h?i.push(h):o.onRemove&&o.onRemove(t.local[n].spec)}for(let i=0;i<t.children.length;i+=3)h(t.children[i+2],t.children[i]+e+1)}for(let i=0;i<t.length;i+=3)-1==t[i+1]&&h(t[i+2],e[i]+n+1);return i}(h,t,e,i,s,n,o),a=us(l,r,0,o);e=a.local;for(let t=0;t<h.length;t+=3)h[t+1]<0&&(h.splice(t,3),t-=3);for(let t=0,e=0;t<a.children.length;t+=3){let i=a.children[t];for(;e<h.length&&h[e]<i;)e+=3;h.splice(e,0,a.children[t],a.children[t+1],a.children[t+2])}}return new rs(e.sort(cs),h)}(this.children,n||[],t,e,i,r,s):n?new rs(n.sort(cs),es):ss}add(t,e){return e.length?this==ss?rs.create(t,e):this.addInner(t,e,0):this}addInner(t,e,i){let r,s=0;t.forEach(((t,n)=>{let o,h=n+i;if(o=ls(e,t,h)){for(r||(r=this.children.slice());s<r.length&&r[s]<n;)s+=3;r[s]==n?r[s+2]=r[s+2].addInner(t,o,h+1):r.splice(s,0,n,n+t.nodeSize,us(o,t,h+1,is)),s+=3}}));let n=hs(s?as(e):e,-i);for(let e=0;e<n.length;e++)n[e].type.valid(t,n[e])||n.splice(e--,1);return new rs(n.length?this.local.concat(n).sort(cs):this.local,r||this.children)}remove(t){return 0==t.length||this==ss?this:this.removeInner(t,0)}removeInner(t,e){let i=this.children,r=this.local;for(let r=0;r<i.length;r+=3){let s,n=i[r]+e,o=i[r+1]+e;for(let e,i=0;i<t.length;i++)(e=t[i])&&e.from>n&&e.to<o&&(t[i]=null,(s||(s=[])).push(e));if(!s)continue;i==this.children&&(i=this.children.slice());let h=i[r+2].removeInner(s,n+1);h!=ss?i[r+2]=h:(i.splice(r,3),r-=3)}if(r.length)for(let i,s=0;s<t.length;s++)if(i=t[s])for(let t=0;t<r.length;t++)r[t].eq(i,e)&&(r==this.local&&(r=this.local.slice()),r.splice(t--,1));return i==this.children&&r==this.local?this:r.length||i.length?new rs(r,i):ss}forChild(t,e){if(this==ss)return this;if(e.isLeaf)return rs.empty;let i,r;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 s=t+1,n=s+e.content.size;for(let t=0;t<this.local.length;t++){let e=this.local[t];if(e.from<n&&e.to>s&&e.type instanceof Gr){let t=Math.max(s,e.from)-s,i=Math.min(n,e.to)-s;t<i&&(r||(r=[])).push(e.copy(t,i))}}if(r){let t=new rs(r.sort(cs),es);return i?new ns([t,i]):t}return i||ss}eq(t){if(this==t)return!0;if(!(t instanceof rs)||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 fs(this.localsInner(t))}localsInner(t){if(this==ss)return es;if(t.inlineContent||!this.local.some(Gr.is))return this.local;let e=[];for(let t=0;t<this.local.length;t++)this.local[t].type instanceof Gr||e.push(this.local[t]);return e}forEachSet(t){t(this)}}rs.empty=new rs([],[]),rs.removeOverlap=fs;const ss=rs.empty;class ns{constructor(t){this.members=t}map(t,e){const i=this.members.map((i=>i.map(t,e,is)));return ns.from(i)}forChild(t,e){if(e.isLeaf)return rs.empty;let i=[];for(let r=0;r<this.members.length;r++){let s=this.members[r].forChild(t,e);s!=ss&&(s instanceof ns?i=i.concat(s.members):i.push(s))}return ns.from(i)}eq(t){if(!(t instanceof ns)||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 r=0;r<this.members.length;r++){let s=this.members[r].localsInner(t);if(s.length)if(e){i&&(e=e.slice(),i=!1);for(let t=0;t<s.length;t++)e.push(s[t])}else e=s}return e?fs(i?e:e.sort(cs)):es}static from(t){switch(t.length){case 0:return ss;case 1:return t[0];default:return new ns(t.every((t=>t instanceof rs))?t:t.reduce(((t,e)=>t.concat(e instanceof rs?e:e.members)),[]))}}forEachSet(t){for(let e=0;e<this.members.length;e++)this.members[e].forEachSet(t)}}function hs(t,e){if(!e||!t.length)return t;let i=[];for(let r=0;r<t.length;r++){let s=t[r];i.push(new ts(s.from+e,s.to+e,s.type))}return i}function ls(t,e,i){if(e.isLeaf)return null;let r=i+e.nodeSize,s=null;for(let e,n=0;n<t.length;n++)(e=t[n])&&e.from>i&&e.to<r&&((s||(s=[])).push(e),t[n]=null);return s}function as(t){let e=[];for(let i=0;i<t.length;i++)null!=t[i]&&e.push(t[i]);return e}function us(t,e,i,r){let s=[],n=!1;e.forEach(((e,o)=>{let h=ls(t,e,o+i);if(h){n=!0;let t=us(h,e,i+o+1,r);t!=ss&&s.push(o,o+e.nodeSize,t)}}));let o=hs(n?as(t):t,-i).sort(cs);for(let t=0;t<o.length;t++)o[t].type.valid(e,o[t])||(r.onRemove&&r.onRemove(o[t].spec),o.splice(t--,1));return o.length||s.length?new rs(o,s):ss}function cs(t,e){return t.from-e.from||t.to-e.to}function fs(t){let e=t;for(let i=0;i<e.length-1;i++){let r=e[i];if(r.from!=r.to)for(let s=i+1;s<e.length;s++){let n=e[s];if(n.from!=r.from){n.from<r.to&&(e==t&&(e=t.slice()),e[i]=r.copy(r.from,n.from),ds(e,s,r.copy(n.from,r.to)));break}n.to!=r.to&&(e==t&&(e=t.slice()),e[s]=n.copy(n.from,r.to),ds(e,s+1,n.copy(r.to,n.to)))}}return e}function ds(t,e,i){for(;e<t.length&&cs(i,t[e])>0;)e++;t.splice(e,0,i)}function ps(t){let e=[];return t.someProp("decorations",(i=>{let r=i(t.state);r&&r!=ss&&e.push(r)})),t.cursorWrapper&&e.push(rs.create(t.state.doc,[t.cursorWrapper.deco])),ns.from(e)}const gs={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},ws=Ue&&ze<=11;class ms{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 vs{constructor(t,e){this.view=t,this.handleDOMChange=e,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new ms,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver((e=>{for(let t=0;t<e.length;t++)this.queue.push(e[t]);Ue&&ze<=11&&e.some((t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length))?this.flushSoon():Ye&&t.composing&&e.some((t=>"childList"==t.type&&"TR"==t.target.nodeName))?(t.input.badSafariComposition=!0,this.flushSoon()):this.flush()})),ws&&(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,gs)),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 Hi(this.view);if(Ue&&ze<=11&&!this.view.state.selection.empty){let t=this.view.domSelectionRange();if(t.focusNode&&Se(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=xe(e))i.add(e);for(let r=t.anchorNode;r;r=xe(r))if(i.has(r)){e=r;break}let r=e&&this.view.docView.nearestDesc(e);return r&&r.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(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(i)&&qi(t)&&!this.ignoreSelectionChange(i),s=-1,n=-1,o=!1,h=[];if(t.editable)for(let t=0;t<e.length;t++){let i=this.registerMutation(e[t],h);i&&(s=s<0?i.from:Math.min(i.from,s),n=n<0?i.to:Math.max(i.to,n),i.typeOver&&(o=!0))}if(!h.some((t=>"BR"==t.nodeName))||8!=t.input.lastKeyCode&&46!=t.input.lastKeyCode){if(Le&&h.length){let e=h.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 r of e){let e=r.parentNode;!e||"LI"!=e.nodeName||i&&Ms(t,i)==e||r.remove()}}}}else for(let t of h)if("BR"==t.nodeName&&t.parentNode){let e=t.nextSibling;e&&1==e.nodeType&&"false"==e.contentEditable&&t.parentNode.removeChild(t)}let l=null;s<0&&r&&t.input.lastFocus>Date.now()-200&&Math.max(t.input.lastTouch,t.input.lastClick.time)<Date.now()-300&&Ie(i)&&(l=Li(t))&&l.eq(ee.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,Hi(t),this.currentSelection.set(i),t.scrollToSelection()):(s>-1||r)&&(s>-1&&(t.docView.markDirty(s,n),function(t){if(!ys.has(t)&&(ys.set(t,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace))){if(t.requiresGeckoHackNode=Le,ks)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."),ks=!0}}(t)),t.input.badSafariComposition&&(t.input.badSafariComposition=!1,function(t,e){var i;let{focusNode:r,focusOffset:s}=t.domSelectionRange();for(let n of e)if("TR"==(null===(i=n.parentNode)||void 0===i?void 0:i.nodeName)){let e=n.nextSibling;for(;e&&"TD"!=e.nodeName&&"TH"!=e.nodeName;)e=e.nextSibling;if(e){let i=e;for(;;){let t=i.firstChild;if(!t||1!=t.nodeType||"false"==t.contentEditable||/^(BR|IMG)$/.test(t.nodeName))break;i=t}i.insertBefore(n,i.firstChild),r==n&&t.domSelection().collapse(n,s)}else n.parentNode.removeChild(n)}}(t,h)),this.handleDOMChange(s,n,o,h),t.docView&&t.docView.dirty?t.updateState(t.state):this.currentSelection.eq(i)||Hi(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 r=t.addedNodes[i];e.push(r),3==r.nodeType&&(this.lastChangedTextNode=r)}if(i.contentDOM&&i.contentDOM!=i.dom&&!i.contentDOM.contains(t.target))return{from:i.posBefore,to:i.posAfter};let r=t.previousSibling,s=t.nextSibling;if(Ue&&ze<=11&&t.addedNodes.length)for(let e=0;e<t.addedNodes.length;e++){let{previousSibling:i,nextSibling:n}=t.addedNodes[e];(!i||Array.prototype.indexOf.call(t.addedNodes,i)<0)&&(r=i),(!n||Array.prototype.indexOf.call(t.addedNodes,n)<0)&&(s=n)}let n=r&&r.parentNode==t.target?Me(r)+1:0,o=i.localPosFromDOM(t.target,n,-1),h=s&&s.parentNode==t.target?Me(s):t.target.childNodes.length;return{from:o,to:i.localPosFromDOM(t.target,h,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 ys=new WeakMap,ks=!1;function bs(t,e){let i=e.startContainer,r=e.startOffset,s=e.endContainer,n=e.endOffset,o=t.domAtPos(t.state.selection.anchor);return Se(o.node,o.offset,s,n)&&([i,r,s,n]=[s,n,i,r]),{anchorNode:i,anchorOffset:r,focusNode:s,focusOffset:n}}function Ms(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 xs(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 Cs=/^(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 As(t,e,i){return Math.max(i.anchor,i.head)>e.content.size?null:Ki(t,e.resolve(i.anchor),e.resolve(i.head))}function Ss(t,e,i){let r=t.depth,s=e?t.end():t.pos;for(;r>0&&(e||t.indexAfter(r)==t.node(r).childCount);)r--,s++,e=!1;if(i){let e=t.node(r).maybeChild(t.indexAfter(r));for(;e&&!e.isLeaf;)e=e.firstChild,s++}return s}function Bs(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 Ts{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 Sr,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=e,this.state=e.state,this.directPlugins=e.plugins||[],this.directPlugins.forEach(Ps),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=Is(this),Es(this),this.nodeViews=Ds(this),this.docView=Ai(this.state.doc,Os(this),ps(this),this.dom,this),this.domObserver=new vs(this,((t,e,i,r)=>function(t,e,i,r,s){let n=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=Li(t,e);if(i&&!t.state.selection.eq(i)){if(He&&Qe&&13===t.input.lastKeyCode&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",(e=>e(t,De(13,"Enter")))))return;let r=t.state.tr.setSelection(i);"pointer"==e?r.setMeta("pointer",!0):"key"==e&&r.scrollIntoView(),n&&r.setMeta("composition",n),t.dispatch(r)}return}let o=t.state.doc.resolve(e),h=o.sharedDepth(i);e=o.before(h+1),i=t.state.doc.resolve(i).after(h+1);let l,a,u=t.state.selection,f=function(t,e,i){let r,{node:s,fromOffset:n,toOffset:o,from:h,to:l}=t.docView.parseRange(e,i),a=t.domSelectionRange(),u=a.anchorNode;if(u&&t.dom.contains(1==u.nodeType?u:u.parentNode)&&(r=[{node:u,offset:a.anchorOffset}],Ie(a)||r.push({node:a.focusNode,offset:a.focusOffset})),He&&8===t.input.lastKeyCode)for(let t=o;t>n;t--){let e=s.childNodes[t-1],i=e.pmViewDesc;if("BR"==e.nodeName&&!i){o=t;break}if(!i||i.size)break}let c=t.state.doc,f=t.someProp("domParser")||it.fromSchema(t.state.schema),d=c.resolve(h),p=null,g=f.parse(s,{topNode:d.parent,topMatch:d.parent.contentMatchAt(d.index()),topOpen:!0,from:n,to:o,preserveWhitespace:"pre"!=d.parent.type.whitespace||"full",findPositions:r,ruleFromNode:xs,context:d});if(r&&null!=r[0].pos){let t=r[0].pos,e=r[1]&&r[1].pos;null==e&&(e=t),p={anchor:t+h,head:e+h}}return{doc:g,sel:p,from:h,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 g=function(t,e,i,r,s){let n=t.findDiffStart(e,i);if(null==n)return null;let{a:o,b:h}=t.findDiffEnd(e,i+t.size,i+e.size);if("end"==s&&(r-=o+Math.max(0,n-Math.min(o,h))-n),o<n&&t.size<e.size){let t=r<=n&&r>=o?n-r:0;n-=t,n&&n<e.size&&Bs(e.textBetween(n-1,n+1))&&(n+=t?1:-1),h=n+(h-o),o=n}else if(h<n){let e=r<=n&&r>=h?n-r:0;n-=e,n&&n<t.size&&Bs(t.textBetween(n-1,n+1))&&(n+=e?1:-1),o=n+(o-h),h=n}return{start:n,endA:o,endB:h}}(p.content,f.doc.content,f.from,l,a);if(g&&t.input.domChangeCount++,(We&&t.input.lastIOSEnter>Date.now()-225||Qe)&&s.some((t=>1==t.nodeType&&!Cs.test(t.nodeName)))&&(!g||g.endA>=g.endB)&&t.someProp("handleKeyDown",(e=>e(t,De(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(!g){if(!(r&&u instanceof ne&&!u.empty&&u.$head.sameParent(u.$anchor))||t.composing||f.sel&&f.sel.anchor!=f.sel.head){if(f.sel){let e=As(t,t.state.doc,f.sel);if(e&&!e.eq(t.state.selection)){let i=t.state.tr.setSelection(e);n&&i.setMeta("composition",n),t.dispatch(i)}}return}g={start:u.from,endA:u.to,endB:u.to}}t.state.selection.from<t.state.selection.to&&g.start==g.endB&&t.state.selection instanceof ne&&(g.start>t.state.selection.from&&g.start<=t.state.selection.from+2&&t.state.selection.from>=f.from?g.start=t.state.selection.from:g.endA<t.state.selection.to&&g.endA>=t.state.selection.to-2&&t.state.selection.to<=f.to&&(g.endB+=t.state.selection.to-g.endA,g.endA=t.state.selection.to)),Ue&&ze<=11&&g.endB==g.start+1&&g.endA==g.start&&g.start>f.from&&" "==f.doc.textBetween(g.start-f.from-1,g.start-f.from+1)&&(g.start--,g.endA--,g.endB--);let w=f.doc.resolveNoCache(g.start-f.from),m=f.doc.resolveNoCache(g.endB-f.from),v=d.resolve(g.start),y=w.sameParent(m)&&w.parent.inlineContent&&v.end()>=g.endA;if((We&&t.input.lastIOSEnter>Date.now()-225&&(!y||s.some((t=>"DIV"==t.nodeName||"P"==t.nodeName)))||!y&&w.pos<f.doc.content.size&&(!w.sameParent(m)||!w.parent.inlineContent)&&w.pos<m.pos&&!/\S/.test(f.doc.textBetween(w.pos,m.pos,"","")))&&t.someProp("handleKeyDown",(e=>e(t,De(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(t.state.selection.anchor>g.start&&function(t,e,i,r,s){if(i-e<=s.pos-r.pos||Ss(r,!0,!1)<s.pos)return!1;let n=t.resolve(e);if(!r.parent.isTextblock){let t=n.nodeAfter;return null!=t&&i==e+t.nodeSize}if(n.parentOffset<n.parent.content.size||!n.parent.isTextblock)return!1;let o=t.resolve(Ss(n,!0,!0));return!(!o.parent.isTextblock||o.pos>i||Ss(o,!0,!1)<i)&&r.parent.content.cut(r.parentOffset).eq(o.parent.content)}(d,g.start,g.endA,w,m)&&t.someProp("handleKeyDown",(e=>e(t,De(8,"Backspace")))))return void(Qe&&He&&t.domObserver.suppressSelectionUpdates());He&&g.endB==g.start&&(t.input.lastChromeDelete=Date.now()),Qe&&!y&&w.start()!=m.start()&&0==m.parentOffset&&w.depth==m.depth&&f.sel&&f.sel.anchor==f.sel.head&&f.sel.head==g.endA&&(g.endB-=2,m=f.doc.resolveNoCache(g.endB-f.from),setTimeout((()=>{t.someProp("handleKeyDown",(function(e){return e(t,De(13,"Enter"))}))}),20));let k,b=g.start,M=g.endA,x=e=>{let i=e||t.state.tr.replace(b,M,f.doc.slice(g.start-f.from,g.endB-f.from));if(f.sel){let e=As(t,i.doc,f.sel);e&&!(He&&t.composing&&e.empty&&(g.start!=g.endB||t.input.lastChromeDelete<Date.now()-100)&&(e.head==b||e.head==i.mapping.map(M)-1)||Ue&&e.empty&&e.head==b)&&i.setSelection(e)}return n&&i.setMeta("composition",n),i.scrollIntoView()};if(y)if(w.pos==m.pos){Ue&&ze<=11&&0==w.parentOffset&&(t.domObserver.suppressSelectionUpdates(),setTimeout((()=>Hi(t)),20));let e=x(t.state.tr.delete(b,M)),i=d.resolve(g.start).marksAcross(d.resolve(g.endA));i&&e.ensureMarks(i),t.dispatch(e)}else if(g.endA==g.endB&&(k=function(t,e){let i,r,s,n=t.firstChild.marks,o=e.firstChild.marks,h=n,l=o;for(let t=0;t<o.length;t++)h=o[t].removeFromSet(h);for(let t=0;t<n.length;t++)l=n[t].removeFromSet(l);if(1==h.length&&0==l.length)r=h[0],i="add",s=t=>t.mark(r.addToSet(t.marks));else{if(0!=h.length||1!=l.length)return null;r=l[0],i="remove",s=t=>t.mark(r.removeFromSet(t.marks))}let a=[];for(let t=0;t<e.childCount;t++)a.push(s(e.child(t)));if(c.from(a).eq(t))return{mark:r,type:i}}(w.parent.content.cut(w.parentOffset,m.parentOffset),v.parent.content.cut(v.parentOffset,g.endA-v.start())))){let e=x(t.state.tr);"add"==k.type?e.addMark(b,M,k.mark):e.removeMark(b,M,k.mark),t.dispatch(e)}else if(w.parent.child(w.index()).isText&&w.index()==m.index()-(m.textOffset?0:1)){let e=w.parent.textBetween(w.parentOffset,m.parentOffset),i=()=>x(t.state.tr.insertText(e,b,M));t.someProp("handleTextInput",(r=>r(t,b,M,e,i)))||t.dispatch(i())}else t.dispatch(x());else t.dispatch(x())}(this,t,e,i,r))),this.domObserver.start(),function(t){for(let e in xr){let i=xr[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=e=>{!Er(t,e)||Or(t,e)||!t.editable&&e.type in Cr||i(t,e)},Ar[e]?{passive:!0}:void 0)}Ye&&t.dom.addEventListener("input",(()=>null)),Tr(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&&Tr(this);let e=this._props;this._props=t,t.plugins&&(t.plugins.forEach(Ps),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 r=this.state,s=!1,n=!1;t.storedMarks&&this.composing&&(_r(this),n=!0),this.state=t;let o=r.plugins!=t.plugins||this._props.plugins!=e.plugins;if(o||this._props.plugins!=e.plugins||this._props.nodeViews!=e.nodeViews){let t=Ds(this);(function(t,e){let i=0,r=0;for(let r in t){if(t[r]!=e[r])return!0;i++}for(let t in e)r++;return i!=r})(t,this.nodeViews)&&(this.nodeViews=t,s=!0)}(o||e.handleDOMEvents!=this._props.handleDOMEvents)&&Tr(this),this.editable=Is(this),Es(this);let h=ps(this),l=Os(this),a=r.plugins==t.plugins||r.doc.eq(t.doc)?t.scrollToSelection>r.scrollToSelection?"to selection":"preserve":"reset",u=s||!this.docView.matchesNode(t.doc,l,h);!u&&t.selection.eq(r.selection)||(n=!0);let c="preserve"==a&&n&&null==this.dom.style.overflowAnchor&&function(t){let e,i,r=t.dom.getBoundingClientRect(),s=Math.max(0,r.top);for(let n=(r.left+r.right)/2,o=s+1;o<Math.min(innerHeight,r.bottom);o+=5){let r=t.root.elementFromPoint(n,o);if(!r||r==t.dom||!t.dom.contains(r))continue;let h=r.getBoundingClientRect();if(h.top>=s-20){e=r,i=h.top;break}}return{refDOM:e,refTop:i,stack:ii(t.dom)}}(this);if(n){this.domObserver.stop();let e=u&&(Ue||He)&&!this.composing&&!r.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)}(r.selection,t.selection);if(u){let i=He?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=Me(t),t=t.parentNode}}}(e.focusNode,e.focusOffset),r=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=Me(t)+1,t=t.parentNode}}}(e.focusNode,e.focusOffset);if(i&&r&&i!=r){let e=r.pmViewDesc,s=t.domObserver.lastChangedTextNode;if(i==s||r==s)return s;if(!e||!e.isText(r.nodeValue))return r;if(t.input.compositionNode==r){let t=i.pmViewDesc;if(t&&t.isText(i.nodeValue))return r}}return i||r}(this)),!s&&this.docView.update(t.doc,l,h,this)||(this.docView.updateOuterDeco(l),this.docView.destroy(),this.docView=Ai(t.doc,l,h,this.dom,this)),!i||this.trackWrites&&this.dom.contains(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 Se(e.node,e.offset,i.anchorNode,i.anchorOffset)}(this))?Hi(this,e):(Ji(this,t.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(r),(null===(i=this.dragging)||void 0===i?void 0:i.node)&&!r.doc.eq(t.doc)&&this.updateDraggedNode(this.dragging,r),"reset"==a?this.dom.scrollTop=0:"to selection"==a?this.scrollToSelection():c&&function({refDOM:t,refTop:e,stack:i}){let r=t?t.getBoundingClientRect().top:0;ri(i,0==r?0:r-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 he){let e=this.docView.domAfterPos(this.state.selection.from);1==e.nodeType&&ei(this,e.getBoundingClientRect(),t)}else ei(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,r=-1;if(this.state.doc.nodeAt(i.from)==i.node)r=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&&(r=t)}this.dragging=new Vr(t.slice,t.move,r<0?void 0:he.create(this.state.doc,r))}someProp(t,e){let i,r=this._props&&this._props[t];if(null!=r&&(i=e?e(r):r))return i;for(let r=0;r<this.directPlugins.length;r++){let s=this.directPlugins[r].props[t];if(null!=s&&(i=e?e(s):s))return i}let s=this.state.plugins;if(s)for(let r=0;r<s.length;r++){let n=s[r].props[t];if(null!=n&&(i=e?e(n):n))return i}}hasFocus(){if(Ue){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(si)return t.focus(si);let e=ii(t);t.focus(null==si?{get preventScroll(){return si={preventScroll:!0},!0}}:void 0),si||(si=!1,ri(e,0))}(this.dom),Hi(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 li(this,t)}coordsAtPos(t,e=1){return fi(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 r=this.docView.posFromDOM(t,e,i);if(null==r)throw new RangeError("DOM position not inside the editor");return r}endOfTextblock(t,e){return function(t,e,i){return mi==e&&vi==i?yi:(mi=e,vi=i,yi="up"==i||"down"==i?function(t,e,i){let r=e.selection,s="up"==i?r.$from:r.$to;return gi(t,e,(()=>{let{node:e}=t.docView.domFromPos(s.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 r=fi(t,s.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 s=e[t];if(s.bottom>s.top+1&&("up"==i?r.top-s.top>2*(s.bottom-r.top):s.bottom-r.bottom>2*(r.bottom-s.top)))return!1}}return!0}))}(t,e,i):function(t,e,i){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let s=r.parentOffset,n=!s,o=s==r.parent.content.size,h=t.domSelection();return h?wi.test(r.parent.textContent)&&h.modify?gi(t,e,(()=>{let{focusNode:e,focusOffset:s,anchorNode:n,anchorOffset:o}=t.domSelectionRange(),l=h.caretBidiLevel;h.modify("move",i,"character");let a=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:u,focusOffset:c}=t.domSelectionRange(),f=u&&!a.contains(1==u.nodeType?u:u.parentNode)||e==u&&s==c;try{h.collapse(n,o),e&&(e!=n||s!=o)&&h.extend&&h.extend(e,s)}catch(t){}return null!=l&&(h.caretBidiLevel=l),f})):"left"==i||"backward"==i?n:o:r.pos==r.start()||r.pos==r.end()}(t,e,i))}(this,e||this.state,t)}pasteHTML(t,e){return Yr(this,"",t,!1,e||new ClipboardEvent("paste"))}pasteText(t,e){return Yr(this,t,null,!0,e||new ClipboardEvent("paste"))}serializeForClipboard(t){return cr(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,[],ps(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Ce=null)}get isDestroyed(){return null==this.docView}dispatchEvent(t){return function(t,e){Or(t,e)||!xr[e.type]||!t.editable&&e.type in Cr||xr[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 bs(t,i)}let i;function r(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",r,!0),i?bs(t,i):null}(this,t)||t:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function Os(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"),[ts.node(0,t.state.doc.content.size,e)]}function Es(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:ts.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Is(t){return!t.someProp("editable",(e=>!1===e(t.state)))}function Ds(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 Ps(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")}Ts.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};const $s=["p",0],Rs=["blockquote",0],js=["hr"],Fs=["pre",["code",0]],Ns=["br"],Us=["em",0],zs=["strong",0],Ls=["code",0],_s=new tt({nodes:{doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:()=>$s},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:()=>Rs},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>js},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:()=>Fs},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:r}=t.attrs;return["img",{src:e,alt:i,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM:()=>Ns}},marks:{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:()=>Us},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:()=>zs},code:{code:!0,parseDOM:[{tag:"code"}],toDOM:()=>Ls}}}),Hs=["ol",0],Xs=["ul",0],Ys=["li",0],Ws={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?Hs:["ol",{start:t.attrs.order},0]},Vs={parseDOM:[{tag:"ul"}],toDOM:()=>Xs},Js={parseDOM:[{tag:"li"}],toDOM:()=>Ys,defining:!0};function Qs(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 Ks(t,e,i){return t.append({ordered_list:Qs(Ws,{content:"list_item+",group:i}),bullet_list:Qs(Vs,{content:"list_item+",group:i}),list_item:Qs(Js,{content:e})})}for(var qs={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:"'"},Gs={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Zs="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),tn="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),en=0;en<10;en++)qs[48+en]=qs[96+en]=String(en);for(en=1;en<=24;en++)qs[en+111]="F"+en;for(en=65;en<=90;en++)qs[en]=String.fromCharCode(en+32),Gs[en]=String.fromCharCode(en);for(var rn in qs)Gs.hasOwnProperty(rn)||(Gs[rn]=qs[rn]);const sn="undefined"!=typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),nn="undefined"!=typeof navigator&&/Win/.test(navigator.platform);function on(t){let e,i,r,s,n=t.split(/-(?!$)/),o=n[n.length-1];"Space"==o&&(o=" ");for(let t=0;t<n.length-1;t++){let o=n[t];if(/^(cmd|meta|m)$/i.test(o))s=!0;else if(/^a(lt)?$/i.test(o))e=!0;else if(/^(c|ctrl|control)$/i.test(o))i=!0;else if(/^s(hift)?$/i.test(o))r=!0;else{if(!/^mod$/i.test(o))throw new Error("Unrecognized modifier name: "+o);sn?s=!0:i=!0}}return e&&(o="Alt-"+o),i&&(o="Ctrl-"+o),s&&(o="Meta-"+o),r&&(o="Shift-"+o),o}function hn(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 ln(t){return new ke({props:{handleKeyDown:an(t)}})}function an(t){let e=function(t){let e=Object.create(null);for(let i in t)e[on(i)]=t[i];return e}(t);return function(t,i){let r,s=function(t){var e=!(Zs&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||tn&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?Gs:qs)[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),n=e[hn(s,i)];if(n&&n(t.state,t.dispatch,t))return!0;if(1==s.length&&" "!=s){if(i.shiftKey){let r=e[hn(s,i,!1)];if(r&&r(t.state,t.dispatch,t))return!0}if((i.altKey||i.metaKey||i.ctrlKey)&&!(nn&&i.ctrlKey&&i.altKey)&&(r=qs[i.keyCode])&&r!=s){let s=e[hn(r,i)];if(s&&s(t.state,t.dispatch,t))return!0}}return!1}}const un=(t,e)=>!t.selection.empty&&(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function cn(t,e,i=!1){for(let r=t;r;r="start"==e?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(i&&1!=r.childCount)return!1}return!1}function fn(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 dn(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 pn(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 gn(t,e,i,r){let s,n,o=e.nodeBefore,h=e.nodeAfter,l=o.type.spec.isolating||h.type.spec.isolating;if(!l&&function(t,e,i){let r=e.nodeBefore,s=e.nodeAfter,n=e.index();return!(!(r&&s&&r.type.compatibleContent(s.type))||(!r.content.size&&e.parent.canReplace(n-1,n)?(i&&i(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),0):!e.parent.canReplace(n,n+1)||!s.isTextblock&&!Ut(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&&(s=(n=o.contentMatchAt(o.childCount)).findWrapping(h.type))&&n.matchType(s[0]||h.type).validEnd){if(i){let r=e.pos+h.nodeSize,n=c.empty;for(let t=s.length-1;t>=0;t--)n=c.from(s[t].create(null,n));n=c.from(o.copy(n));let l=t.tr.step(new It(e.pos-1,r,e.pos,r,new m(n,1,0),s.length,!0)),a=l.doc.resolve(r+2*s.length);a.nodeAfter&&a.nodeAfter.type==o.type&&Ut(l.doc,a.pos)&&l.join(a.pos),i(l.scrollIntoView())}return!0}let u=h.type.spec.isolating||r>0&&l?null:ee.findFrom(e,1),f=u&&u.$from.blockRange(u.$to),d=f&&Rt(f);if(null!=d&&d>=e.depth)return i&&i(t.tr.lift(f,d).scrollIntoView()),!0;if(a&&cn(h,"start",!0)&&cn(o,"end")){let r=o,s=[];for(;s.push(r),!r.isTextblock;)r=r.lastChild;let n=h,l=1;for(;!n.isTextblock;n=n.firstChild)l++;if(r.canReplace(r.childCount,r.childCount,n.content)){if(i){let r=c.empty;for(let t=s.length-1;t>=0;t--)r=c.from(s[t].copy(r));i(t.tr.step(new It(e.pos-s.length,e.pos+h.nodeSize,e.pos+l,e.pos+h.nodeSize-l,new m(r,s.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function wn(t){return function(e,i){let r=e.selection,s=t<0?r.$from:r.$to,n=s.depth;for(;s.node(n).isInline;){if(!n)return!1;n--}return!!s.node(n).isTextblock&&(i&&i(e.tr.setSelection(ne.create(e.doc,t<0?s.start(n):s.end(n)))),!0)}}const mn=wn(-1),vn=wn(1);function yn(...t){return function(e,i,r){for(let s=0;s<t.length;s++)if(t[s](e,i,r))return!0;return!1}}let kn=yn(un,((t,e,i)=>{let r=function(t,e){let{$cursor:i}=t.selection;return!i||(e?!e.endOfTextblock("backward",t):i.parentOffset>0)?null:i}(t,i);if(!r)return!1;let s=fn(r);if(!s){let i=r.blockRange(),s=i&&Rt(i);return null!=s&&(e&&e(t.tr.lift(i,s).scrollIntoView()),!0)}let n=s.nodeBefore;if(gn(t,s,e,-1))return!0;if(0==r.parent.content.size&&(cn(n,"end")||he.isSelectable(n)))for(let i=r.depth;;i--){let o=zt(t.doc,r.before(i),r.after(i),m.empty);if(o&&o.slice.size<o.to-o.from){if(e){let i=t.tr.step(o);i.setSelection(cn(n,"end")?ee.findFrom(i.doc.resolve(i.mapping.map(s.pos,-1)),-1):he.create(i.doc,s.pos-n.nodeSize)),e(i.scrollIntoView())}return!0}if(1==i||r.node(i-1).childCount>1)break}return!(!n.isAtom||s.depth!=r.depth-1||(e&&e(t.tr.delete(s.pos-n.nodeSize,s.pos).scrollIntoView()),0))}),((t,e,i)=>{let{$head:r,empty:s}=t.selection,n=r;if(!s)return!1;if(r.parent.isTextblock){if(i?!i.endOfTextblock("backward",t):r.parentOffset>0)return!1;n=fn(r)}let o=n&&n.nodeBefore;return!(!o||!he.isSelectable(o)||(e&&e(t.tr.setSelection(he.create(t.doc,n.pos-o.nodeSize)).scrollIntoView()),0))})),bn=yn(un,((t,e,i)=>{let r=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(!r)return!1;let s=dn(r);if(!s)return!1;let n=s.nodeAfter;if(gn(t,s,e,1))return!0;if(0==r.parent.content.size&&(cn(n,"start")||he.isSelectable(n))){let i=zt(t.doc,r.before(),r.after(),m.empty);if(i&&i.slice.size<i.to-i.from){if(e){let r=t.tr.step(i);r.setSelection(cn(n,"start")?ee.findFrom(r.doc.resolve(r.mapping.map(s.pos)),1):he.create(r.doc,r.mapping.map(s.pos))),e(r.scrollIntoView())}return!0}}return!(!n.isAtom||s.depth!=r.depth-1||(e&&e(t.tr.delete(s.pos,s.pos+n.nodeSize).scrollIntoView()),0))}),((t,e,i)=>{let{$head:r,empty:s}=t.selection,n=r;if(!s)return!1;if(r.parent.isTextblock){if(i?!i.endOfTextblock("forward",t):r.parentOffset<r.parent.content.size)return!1;n=dn(r)}let o=n&&n.nodeAfter;return!(!o||!he.isSelectable(o)||(e&&e(t.tr.setSelection(he.create(t.doc,n.pos)).scrollIntoView()),0))}));const Mn={Enter:yn(((t,e)=>{let{$head:i,$anchor:r}=t.selection;return!(!i.parent.type.spec.code||!i.sameParent(r)||(e&&e(t.tr.insertText("\n").scrollIntoView()),0))}),((t,e)=>{let i=t.selection,{$from:r,$to:s}=i;if(i instanceof ae||r.parent.inlineContent||s.parent.inlineContent)return!1;let n=pn(s.parent.contentMatchAt(s.indexAfter()));if(!n||!n.isTextblock)return!1;if(e){let i=(!r.parentOffset&&s.index()<s.parent.childCount?r:s).pos,o=t.tr.insert(i,n.createAndFill());o.setSelection(ne.create(o.doc,i+1)),e(o.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 r=i.before();if(Nt(t.doc,r))return e&&e(t.tr.split(r).scrollIntoView()),!0}let r=i.blockRange(),s=r&&Rt(r);return null!=s&&(e&&e(t.tr.lift(r,s).scrollIntoView()),!0)}),((t,e)=>{let{$from:i}=t.selection;if(t.selection instanceof he&&t.selection.node.isBlock)return!(!i.parentOffset||!Nt(t.doc,i.pos)||(e&&e(t.tr.split(i.pos).scrollIntoView()),0));if(!i.depth)return!1;let r,s,n=[],o=!1,h=!1;for(let t=i.depth;;t--){if(i.node(t).isBlock){o=i.end(t)==i.pos+(i.depth-t),h=i.start(t)==i.pos-(i.depth-t),s=pn(i.node(t-1).contentMatchAt(i.indexAfter(t-1))),n.unshift(o&&s?{type:s}:null),r=t;break}if(1==t)return!1;n.unshift(null)}let l=t.tr;(t.selection instanceof ne||t.selection instanceof ae)&&l.deleteSelection();let a=l.mapping.map(i.pos),u=Nt(l.doc,a,n.length,n);if(u||(n[0]=s?{type:s}:null,u=Nt(l.doc,a,n.length,n)),!u)return!1;if(l.split(a,n.length,n),!o&&h&&i.node(r).type!=s){let t=l.mapping.map(i.before(r)),e=l.doc.resolve(t);s&&i.node(r-1).canReplaceWith(e.index(),e.index()+1,s)&&l.setNodeMarkup(l.mapping.map(i.before(r)),s)}return e&&e(l.scrollIntoView()),!0})),"Mod-Enter":(t,e)=>{let{$head:i,$anchor:r}=t.selection;if(!i.parent.type.spec.code||!i.sameParent(r))return!1;let s=i.node(-1),n=i.indexAfter(-1),o=pn(s.contentMatchAt(n));if(!o||!s.canReplaceWith(n,n,o))return!1;if(e){let r=i.after(),s=t.tr.replaceWith(r,r,o.createAndFill());s.setSelection(ee.near(s.doc.resolve(r),1)),e(s.scrollIntoView())}return!0},Backspace:kn,"Mod-Backspace":kn,"Shift-Backspace":kn,Delete:bn,"Mod-Delete":bn,"Mod-a":(t,e)=>(e&&e(t.tr.setSelection(new ae(t.doc))),!0)},xn={"Ctrl-h":Mn.Backspace,"Alt-Backspace":Mn["Mod-Backspace"],"Ctrl-d":Mn.Delete,"Ctrl-Alt-Backspace":Mn["Mod-Delete"],"Alt-Delete":Mn["Mod-Delete"],"Alt-d":Mn["Mod-Delete"],"Ctrl-a":mn,"Ctrl-e":vn};for(let t in Mn)xn[t]=Mn[t];const Cn=("undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"undefined"!=typeof os&&os.platform&&"darwin"==os.platform())?xn:Mn,An=[{light:"#000000",dark:"#ffffff",label:"Primary"},{light:"#ff5252",dark:"#ff5252"},{light:"#ffbc00",dark:"#ffbc00"},{light:"#00c853",dark:"#00c853"},{light:"#0000FF",dark:"#0000FF"},{light:"#d500f9",dark:"#d500f9"},{light:"#fafafa",dark:"#212121",label:"Background"},{light:"#a52714",dark:"#a52714"},{light:"#ee8100",dark:"#ee8100"},{light:"#558b2f",dark:"#558b2f"},{light:"#01579b",dark:"#01579b"},{light:"#8e24aa",dark:"#8e24aa"},{light:"#90a4ae",dark:"#607d8b",label:"Neutral"},{light:"#ff4081",dark:"#ff4081"},{light:"#ff6e40",dark:"#ff6e40"},{light:"#aeea00",dark:"#aeea00"},{light:"#304ffe",dark:"#304ffe"},{light:"#7c4dff",dark:"#7c4dff"},{light:"#cfd8dc",dark:"#455a64"},{light:"#f8bbd0",dark:"#ec407a"},{light:"#ffccbc",dark:"#ff7043"},{light:"#f0f4c3",dark:"#c0ca33"},{light:"#9fa8da",dark:"#5c6bc0"},{light:"#d1c4e9",dark:"#9575cd"}],Sn={name:"light",global:{borderColor:"#ebebeb",dividerColor:"#e0e0e0",focusColor:"#333333",focusRingColor:"#333333",iconColor:"currentColor",scrollbarThumbColor:"#ebebeb",textPrimary:"#000000",textSecondary:"#333333"},pillTabs:{background:"#f0f0f0",tabBackground:"transparent",tabBackgroundHover:"rgba(0, 0, 0, 0.05)",tabBackgroundSelected:"#ffffff",tabShadowSelected:"0 1px 3px rgba(0, 0, 0, 0.1)",tabTextColor:"#666666",tabTextColorSelected:"#000000"},textInput:{background:"#ffffff",borderColor:"#dbdbdb",focusBorderColor:"#333333",hoverBorderColor:"#cccccc",labelColor:"#333333",placeholderColor:"#999999",selectionBackground:"#007AFF",selectionColor:"#ffffff",suffixBackground:"#f5f5f5",suffixColor:"#666666",textColor:"#333333"},selection:{borderColor:"#007AFF",handleColor:"#ffffff"},checkerboard:{colorDark:"#cccccc",colorLight:"#ffffff"},backToContent:{activeBackgroundColor:"hsl(0, 0%, 0%, 8.6%)",backgroundColor:"#ffffff",border:"1px solid #ebebeb",boxShadow:"0 0 3px rgba(0, 0, 0, 0.08)",color:"#000000",hoverBackgroundColor:"hsl(0, 0%, 0%, 4.3%)"},colorPalette:{circleBorderColor:"#dddcdc",hoverBackgroundColor:"#ebebeb",selectedBackgroundColor:"#ebebeb"},contextMenu:{backgroundColor:"#ffffff",border:"1px solid #ebebeb",boxShadow:"0 1px 6px rgba(0, 0, 0, 0.12)",dividerColor:"rgba(0, 0, 0, 0.1)",itemActiveBackgroundColor:"hsl(0, 0%, 0%, 8.6%)",itemColor:"#333333",itemDisabledColor:"#aaaaaa",itemHoverBackgroundColor:"hsl(0, 0%, 0%, 4.3%)"},controls:{backgroundColor:"#ffffff",border:"1px solid #ebebeb",boxShadow:"0 0 3px rgba(0, 0, 0, 0.08)",controlActiveBackgroundColor:"hsl(0, 0%, 0%, 8.6%)",controlColor:"#000000",controlHoverBackgroundColor:"hsl(0, 0%, 0%, 4.3%)",controlSelectedBackgroundColor:"#007AFF",controlSelectedColor:"#ffffff"},currentUserDialog:{emailColor:"#666666",nameColor:"#333333"},dialog:{backdropColor:"rgba(0, 0, 0, 0.4)",backgroundColor:"#ffffff",border:"1px solid #ebebeb",boxShadow:"0 4px 24px rgba(0, 0, 0, 0.15)",closeButtonActiveBackground:"hsl(0, 0%, 0%, 8.6%)",closeButtonBackground:"transparent",closeButtonColor:"#333333",closeButtonHoverBackground:"hsl(0, 0%, 0%, 4.3%)",closeButtonHoverColor:"#000000",fontFamily:"inherit",footerBorder:"1px solid #ebebeb",headerBorder:"1px solid #ebebeb",titleColor:"#000000"},loginDialog:{buttonActiveBackground:"#ebebeb",buttonBackground:"#ffffff",buttonBorderColor:"#e0e0e0",buttonHoverBackground:"#f5f5f5",buttonHoverBorderColor:"#cccccc",buttonTextColor:"#333333",spinnerActiveColor:"#333333",spinnerColor:"#cccccc",subtitleColor:"#666666"},dropdown:{accentColor:"#007bff",background:"#ffffff",borderColor:"#dbdbdb",hoverBorderColor:"#cccccc",hoverBackgroundColor:"#f0f0f0",selectedBackgroundColor:"#007bff1a",textColor:"#333333"},engine:{backgroundColor:"#ffffff"},fontSize:{hoverBackgroundColor:"#ebebeb",selectedBackgroundColor:"#ebebeb",textColor:"#333333"},lineEndings:{hoverBackgroundColor:"#ebebeb",labelColor:"#666666",optionBackground:"#ffffff",selectedBackgroundColor:"#ebebeb"},masterDetail:{backButtonColor:"#333333",backgroundColor:"#ffffff",detailBackgroundColor:"#ffffff",detailFocusOutline:"2px solid #333333",menuBackgroundColor:"#ffffff",menuBorderRight:"1px solid #ebebeb",menuItemActiveBackgroundColor:"hsl(0, 0%, 0%, 8.6%)",menuItemBackgroundColor:"transparent",menuItemChevronColor:"#aaaaaa",menuItemColor:"#333333",menuItemDisabledColor:"#aaaaaa",menuItemFocusOutline:"2px solid #333333",menuItemHoverBackgroundColor:"hsl(0, 0%, 0%, 4.3%)",menuItemSelectedBackgroundColor:"#007AFF",menuItemSelectedColor:"#ffffff",menuItemSelectedHoverBackgroundColor:"#007AFF"},menu:{backgroundColor:"#ffffff",border:"1px solid #ebebeb",boxShadow:"0 0 3px rgba(0, 0, 0, 0.08)",itemButtonHoverBackgroundColor:"hsl(0, 0%, 0%, 4.3%)",itemChildOpenBackgroundColor:"hsl(0, 0%, 0%, 3%)",itemColor:"#333333",itemEditingBackgroundColor:"#f0f0f0",itemInputBorder:"1px solid #333333",itemInputBorderColorOnSelected:"#ffffff",itemInputCaretColor:"#333333",itemInputCaretColorOnSelected:"#ffffff",itemInputSelectionColor:"#007aff",itemInputSelectionColorOnSelected:"rgba(255, 255, 255, 0.55)",itemInputSelectionTextColor:"#ffffff",itemInputSelectionTextColorOnSelected:"#ffffff",itemOverlayBackgroundColor:"hsl(0, 0%, 0%, 4.3%)",itemSelectedBackgroundColor:"#007aff",itemSelectedColor:"#ffffff"},moreMenu:{backgroundColor:"#ffffff",border:"1px solid #ebebeb",borderRadius:"12px",boxShadow:"0 0 3px rgba(0, 0, 0, 0.08)",buttonActiveBackgroundColor:"hsl(0, 0%, 0%, 8.6%)",buttonColor:"#000000",buttonHoverBackgroundColor:"hsl(0, 0%, 0%, 4.3%)",innerBorderRadius:"12px"},numericInput:{focusBorderColor:"#333333",borderColor:"#dbdbdb",hoverBorderColor:"#cccccc",inputBackground:"#ffffff",labelColor:"#666666",selectionBackground:"#007AFF",selectionColor:"#ffffff",spinnerActiveBackground:"hsl(0, 0%, 0%, 8.6%)",spinnerBackground:"transparent",spinnerColor:"#333333",spinnerHoverBackground:"hsl(0, 0%, 0%, 4.3%)",textColor:"#333333"},opacitySlider:{activeColor:"#007AFF",thumbBorderColor:"#007AFF",thumbColor:"#ffffff",trackColor:"#e0e0e0"},settings:{contentHeadingColor:"#000000",contentTextColor:"#333333",descriptionColor:"#666666",labelColor:"#333333",shortcutItemBg:"#f8f8f8",shortcutKeyBg:"#ffffff",shortcutKeyBorder:"#e0e0e0",shortcutKeyColor:"#555555"},shapeFill:{hoverBackgroundColor:"#ebebeb",optionBackground:"#ffffff",selectedBackgroundColor:"#ebebeb"},shareDialog:{borderColor:"#e5e5e5",copyButtonBackground:"#ffffff",copyButtonColor:"#666666",copyButtonHoverBackground:"#e8e8e8",copyButtonHoverColor:"#333333",copySuccessBackground:"#d4edda",copySuccessColor:"#28a745",descriptionColor:"#666666",inputBackground:"#f5f5f5",inputBorderColor:"#e0e0e0",inputTextColor:"#333333",labelColor:"#333333",revokeButtonBorderColor:"#dc3545",revokeButtonColor:"#dc3545",revokeButtonHoverBackground:"#dc3545",revokeButtonHoverColor:"#ffffff",selectionColor:"#cce5ff"},slideToggle:{thumbColor:"#fff",thumbSize:"18px",trackCheckedColor:"#007AFF",trackColor:"#ccc"},splitButton:{backgroundColor:"#ffffff",border:"1px solid #ebebeb",boxShadow:"0 0 3px rgba(0, 0, 0, 0.08)",color:"#000000",dividerBackgroundColor:"#ebebeb",hoverBackgroundColor:"hsl(0, 0%, 0%, 4.3%)"},strokeSize:{hoverBackgroundColor:"#ebebeb",selectedBackgroundColor:"#ebebeb"},tooltip:{backgroundColor:"#ffffff",border:"1px solid #ebebeb",boxShadow:"0 1px 6px rgba(0, 0, 0, 0.12)",color:"#000000"},utilityPanel:{backgroundColor:"#e2e2e2",buttonColor:"#333333",buttonHoverBackgroundColor:"hsl(0, 0%, 0%, 4.3%)",separatorColor:"hsl(0, 0%, 0%, 8%)"}},Bn={name:"dark",global:{borderColor:"#3a3a3a",dividerColor:"#3a3a3a",focusColor:"#ffffff",focusRingColor:"#ffffff",iconColor:"currentColor",scrollbarThumbColor:"#555555",textPrimary:"#ffffff",textSecondary:"#e0e0e0"},pillTabs:{background:"#3a3a3a",tabBackground:"transparent",tabBackgroundHover:"rgba(255, 255, 255, 0.08)",tabBackgroundSelected:"#2a2a2a",tabShadowSelected:"0 1px 3px rgba(0, 0, 0, 0.3)",tabTextColor:"#999999",tabTextColorSelected:"#ffffff"},textInput:{background:"#1a1a1a",borderColor:"#4a4a4a",focusBorderColor:"#ffffff",hoverBorderColor:"#5a5a5a",labelColor:"#e0e0e0",placeholderColor:"#777777",selectionBackground:"#0A84FF",selectionColor:"#ffffff",suffixBackground:"#3a3a3a",suffixColor:"#aaaaaa",textColor:"#e0e0e0"},selection:{borderColor:"#0A84FF",handleColor:"#1a1a1a"},checkerboard:{colorDark:"#4a4a4a",colorLight:"#3a3a3a"},backToContent:{activeBackgroundColor:"hsl(0, 0%, 100%, 12%)",backgroundColor:"#2a2a2a",border:"1px solid #3a3a3a",boxShadow:"0 0 6px rgba(0, 0, 0, 0.3)",color:"#ffffff",hoverBackgroundColor:"hsl(0, 0%, 100%, 8%)"},colorPalette:{circleBorderColor:"#4a4a4a",hoverBackgroundColor:"#3a3a3a",selectedBackgroundColor:"#3a3a3a"},contextMenu:{backgroundColor:"#2a2a2a",border:"1px solid #3a3a3a",boxShadow:"0 1px 8px rgba(0, 0, 0, 0.4)",dividerColor:"rgba(255, 255, 255, 0.1)",itemActiveBackgroundColor:"hsl(0, 0%, 100%, 12%)",itemColor:"#e0e0e0",itemDisabledColor:"#666666",itemHoverBackgroundColor:"hsl(0, 0%, 100%, 8%)"},controls:{backgroundColor:"#2a2a2a",border:"1px solid #3a3a3a",boxShadow:"0 0 6px rgba(0, 0, 0, 0.3)",controlActiveBackgroundColor:"hsl(0, 0%, 100%, 12%)",controlColor:"#ffffff",controlHoverBackgroundColor:"hsl(0, 0%, 100%, 8%)",controlSelectedBackgroundColor:"#0A84FF",controlSelectedColor:"#ffffff"},currentUserDialog:{emailColor:"#999999",nameColor:"#ffffff"},dialog:{backdropColor:"rgba(0, 0, 0, 0.6)",backgroundColor:"#2a2a2a",border:"1px solid #3a3a3a",boxShadow:"0 4px 24px rgba(0, 0, 0, 0.5)",closeButtonActiveBackground:"hsl(0, 0%, 100%, 12%)",closeButtonBackground:"transparent",closeButtonColor:"#e0e0e0",closeButtonHoverBackground:"hsl(0, 0%, 100%, 8%)",closeButtonHoverColor:"#ffffff",footerBorder:"1px solid #3a3a3a",headerBorder:"1px solid #3a3a3a",titleColor:"#ffffff"},loginDialog:{buttonActiveBackground:"#444444",buttonBackground:"#2a2a2a",buttonBorderColor:"#4a4a4a",buttonHoverBackground:"#3a3a3a",buttonHoverBorderColor:"#5a5a5a",buttonTextColor:"#e0e0e0",spinnerActiveColor:"#ffffff",spinnerColor:"#555555",subtitleColor:"#999999"},dropdown:{accentColor:"#0A84FF",borderColor:"#4a4a4a",hoverBorderColor:"#5a5a5a",background:"#1a1a1a",hoverBackgroundColor:"#3a3a3a",selectedBackgroundColor:"rgba(10, 132, 255, 0.2)",textColor:"#e0e0e0"},engine:{backgroundColor:"#1a1a1a"},fontSize:{hoverBackgroundColor:"#3a3a3a",selectedBackgroundColor:"#3a3a3a",textColor:"#e0e0e0"},lineEndings:{hoverBackgroundColor:"#3a3a3a",labelColor:"#999999",optionBackground:"#2a2a2a",selectedBackgroundColor:"#3a3a3a"},masterDetail:{backButtonColor:"#e0e0e0",backgroundColor:"#2a2a2a",detailBackgroundColor:"#2a2a2a",detailFocusOutline:"2px solid #ffffff",menuBackgroundColor:"#2a2a2a",menuBorderRight:"1px solid #3a3a3a",menuItemActiveBackgroundColor:"hsl(0, 0%, 100%, 12%)",menuItemBackgroundColor:"transparent",menuItemChevronColor:"#666666",menuItemColor:"#e0e0e0",menuItemDisabledColor:"#666666",menuItemFocusOutline:"2px solid #ffffff",menuItemHoverBackgroundColor:"hsl(0, 0%, 100%, 8%)",menuItemSelectedBackgroundColor:"#0A84FF",menuItemSelectedColor:"#ffffff",menuItemSelectedHoverBackgroundColor:"#0A84FF"},menu:{backgroundColor:"#2a2a2a",border:"1px solid #3a3a3a",boxShadow:"0 0 6px rgba(0, 0, 0, 0.3)",itemButtonHoverBackgroundColor:"hsl(0, 0%, 100%, 8%)",itemChildOpenBackgroundColor:"hsl(0, 0%, 100%, 6%)",itemColor:"#e0e0e0",itemEditingBackgroundColor:"#3a3a3a",itemInputBorder:"1px solid #ffffff",itemInputBorderColorOnSelected:"#ffffff",itemInputCaretColor:"#e0e0e0",itemInputCaretColorOnSelected:"#ffffff",itemInputSelectionColor:"#b0b0b0",itemInputSelectionColorOnSelected:"rgba(255, 255, 255, 0.35)",itemInputSelectionTextColor:"#ffffff",itemInputSelectionTextColorOnSelected:"#ffffff",itemOverlayBackgroundColor:"hsl(0, 0%, 100%, 8%)",itemSelectedBackgroundColor:"#0A84FF",itemSelectedColor:"#ffffff"},moreMenu:{backgroundColor:"#2a2a2a",border:"1px solid #3a3a3a",borderRadius:"12px",boxShadow:"0 0 6px rgba(0, 0, 0, 0.3)",buttonActiveBackgroundColor:"hsl(0, 0%, 100%, 12%)",buttonColor:"#ffffff",buttonHoverBackgroundColor:"hsl(0, 0%, 100%, 8%)",innerBorderRadius:"12px"},numericInput:{borderColor:"#4a4a4a",focusBorderColor:"#ffffff",hoverBorderColor:"#5a5a5a",inputBackground:"#1a1a1a",labelColor:"#999999",selectionBackground:"#0A84FF",selectionColor:"#ffffff",spinnerActiveBackground:"hsl(0, 0%, 100%, 12%)",spinnerBackground:"transparent",spinnerColor:"#e0e0e0",spinnerHoverBackground:"hsl(0, 0%, 100%, 8%)",textColor:"#e0e0e0"},opacitySlider:{activeColor:"#0A84FF",thumbBorderColor:"#0A84FF",thumbColor:"#ffffff",trackColor:"#4a4a4a"},settings:{contentHeadingColor:"#ffffff",contentTextColor:"#e0e0e0",descriptionColor:"#999999",labelColor:"#e0e0e0",shortcutItemBg:"#3a3a3a",shortcutKeyBg:"#2a2a2a",shortcutKeyBorder:"#4a4a4a",shortcutKeyColor:"#e0e0e0"},shapeFill:{hoverBackgroundColor:"#3a3a3a",optionBackground:"#2a2a2a",selectedBackgroundColor:"#3a3a3a"},shareDialog:{labelColor:"#e0e0e0",descriptionColor:"#e0e0e0",inputBackground:"#1a1a1a",inputBorderColor:"#4a4a4a",inputTextColor:"#e0e0e0",selectionColor:"#0A84FF",copyButtonBackground:"#2a2a2a",copyButtonColor:"#e0e0e0",copyButtonHoverBackground:"#3a3a3a",copyButtonHoverColor:"#ffffff",copySuccessBackground:"#28a745",copySuccessColor:"#ffffff"},slideToggle:{thumbColor:"#ffffff",trackCheckedColor:"#0A84FF",trackColor:"#4a4a4a",transitionDuration:"0.2s"},splitButton:{backgroundColor:"#2a2a2a",border:"1px solid #3a3a3a",boxShadow:"0 0 6px rgba(0, 0, 0, 0.3)",color:"#ffffff",dividerBackgroundColor:"#3a3a3a",hoverBackgroundColor:"hsl(0, 0%, 100%, 8%)"},strokeSize:{hoverBackgroundColor:"#3a3a3a",selectedBackgroundColor:"#3a3a3a"},tooltip:{backgroundColor:"#2a2a2a",border:"1px solid #3a3a3a",boxShadow:"0 1px 8px rgba(0, 0, 0, 0.4)",color:"#ffffff"},utilityPanel:{backgroundColor:"#3a3a3a",buttonColor:"#e0e0e0",buttonHoverBackgroundColor:"hsl(0, 0%, 100%, 8%)",separatorColor:"hsl(0, 0%, 100%, 12%)"}};class Tn{static camelToKebab(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}static flattenThemeToVariables(t,e="--kritzel"){const i=new Map,r=(t,e,s=!1)=>{for(const[n,o]of Object.entries(t)){if(s&&"name"===n)continue;const t=`${e}-${Tn.camelToKebab(n)}`;"object"==typeof o&&null!==o?r(o,t):"string"==typeof o&&i.set(t,o)}};return r(t,e,!0),i}static applyVariablesToElement(t,e){for(const[i,r]of e)t.style.setProperty(i,r)}static applyThemeToElement(t,e){const i=Tn.flattenThemeToVariables(e);Tn.applyVariablesToElement(t,i)}}const On="kritzel-theme",En="light";class In{_core;_currentTheme=En;_targetElement=null;_storageKey;constructor(t){this._core=t,this._storageKey=t.editorId?`${On}-${t.editorId}`:On,this._currentTheme=this.getStoredTheme()}get currentTheme(){return this._currentTheme}setTargetElement(t){this._targetElement=t,this._targetElement&&this.applyTheme(this._currentTheme)}getTargetElement(){return this._targetElement}getThemeByName(t){return"dark"===t?Bn:Sn}getStoredTheme(){if("undefined"==typeof localStorage)return En;const t=localStorage.getItem(this._storageKey);return"dark"===t||"light"===t?t:En}static getStoredTheme(){if("undefined"==typeof localStorage)return En;const t=localStorage.getItem(On);return"dark"===t||"light"===t?t:En}saveTheme(t){"undefined"!=typeof localStorage&&localStorage.setItem(this._storageKey,t)}setTheme(t){this._currentTheme=t,this.saveTheme(t),this._targetElement&&this.applyTheme(t)}isDarkTheme(){return"dark"===this._currentTheme}applyTheme(t){if(!this._targetElement)return;const e=this.getThemeByName(t);Tn.applyThemeToElement(this._targetElement,e)}cleanup(){this._targetElement=null}}class Dn{static resolveThemeColor(t,e){return t?function(t,e){return t[e]}(t,e??In.getStoredTheme()):""}static applyOpacity(t,e,i){const r=this.resolveThemeColor(t,i);if(!r||e>=1)return r;const s=r.startsWith("#")?r.slice(1):r;let n,o,h;if(3===s.length)n=parseInt(s[0]+s[0],16),o=parseInt(s[1]+s[1],16),h=parseInt(s[2]+s[2],16);else{if(6!==s.length)return r;n=parseInt(s.substring(0,2),16),o=parseInt(s.substring(2,4),16),h=parseInt(s.substring(4,6),16)}return isNaN(n)||isNaN(o)||isNaN(h)?r:`rgba(${n}, ${o}, ${h}, ${e})`}static getContrastColor(t){const e=t.startsWith("#")?t.slice(1):t;let i,r,s;if(3===e.length)i=parseInt(e[0]+e[0],16),r=parseInt(e[1]+e[1],16),s=parseInt(e[2]+e[2],16);else{if(6!==e.length)return"#000000";i=parseInt(e.substring(0,2),16),r=parseInt(e.substring(2,4),16),s=parseInt(e.substring(4,6),16)}return isNaN(i)||isNaN(r)||isNaN(s)||.299*i+.587*r+.114*s>150?"#000000":"#ffffff"}static determineTextColor(t){const e="transparent"===t.light,i="transparent"===t.dark;return e&&i?{light:"#000000",dark:"#ffffff"}:{light:e?"#000000":this.getContrastColor(t.light),dark:i?"#ffffff":this.getContrastColor(t.dark)}}}class Pn extends n{__class__="KritzelText";fontFamily="Arial";fontSize=8;fontColor={light:"#000000",dark:"#ffffff"};initialWidth=1;initialHeight=1;scale=1;scaleFactor=1;isDebugInfoVisible=!0;isEditable=!0;isEditing=!1;editor=null;content=null;_schema=new tt({nodes:Ks(_s.spec.nodes,"paragraph block*","block"),marks:_s.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){if(super(),this.editor=this.createEditor(),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||{light:"#000000",dark:"#ffffff"};const e=this._core?.store?.state?.scale,i=null!=e&&e<0?e:1;this.width=this.initialWidth/i,this.height=1.2*this.fontSize/i,this.scale=t.scale||1,this.scaleFactor=t.scaleX??1,t.text&&this.setContent({type:"doc",content:[{type:"paragraph",content:[{type:"text",text:t.text}]}]})}}static create(t,e,i,r){const s=new Pn;s._core=t,s.id=s.generateId(),s.workspaceId=t.store.state.activeWorkspace.id,s.userId=t.user?.id,s.fontSize=e,s.fontFamily=i,s.translateX=0,s.translateY=0;const n=t.store.state.scale,o=n<0?n:1;return s.width=s.initialWidth/o,s.height=1.2*s.fontSize/o,s.backgroundColor={light:"transparent",dark:"transparent"},s.initialWidth=s.width,s.initialHeight=s.height,s.scaleFactor=1,s.scale=r??n,s.zIndex=t.store.currentZIndex,s}mount(t){null!==t&&!1!==this.isInViewport()&&(t.style.fontFamily=this.fontFamily,t.style.fontSize=`${this.fontSize}pt`,t.style.color=Dn.resolveThemeColor(this.fontColor),this.isMounted&&this.elementRef===t&&this.editor.dom.parentElement===t?this._core.store.state.isScaling||this._core.store.state.isPanning||requestAnimationFrame((()=>this.adjustSizeOnInput())):(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 Ts(null,{state:ve.create({doc:t,plugins:[ln(Cn)]}),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,r=t.scrollHeight;if(this.width=t.scrollWidth*this.scaleFactor,this.height=r*this.scaleFactor,0!==this.rotation){const t=(this.totalWidth-e)/2/this.scale,r=(this.totalHeight-i)/2/this.scale;if(0!==t||0!==r){const e=Math.cos(this.rotation),i=Math.sin(this.rotation),s=i*t+e*r;this.translateX+=e*t-i*r-t,this.translateY+=s-r}}}}resize(t,e,i,r){if(i<=1||r<=1)return;const s=this.width/this.scaleFactor,n=this.height/this.scaleFactor;this.scaleFactor=Math.min(i/s,r/n),this.width=s*this.scaleFactor,this.height=n*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&&!this.isEmpty){const i=this.editor.posAtCoords({left:t.x,top:t.y});if(i)return this.editor.dispatch(this.editor.state.tr.setSelection(ne.create(e,i.pos))),this.editor.focus(),void(o.isIOS()&&this.scrollIntoViewOnIOS())}const i=Math.max(1,e.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(ne.create(e,i))),this.editor.focus(),o.isIOS()&&this.scrollIntoViewOnIOS()}}scrollIntoViewOnIOS(){setTimeout((()=>{this.editor&&this.editor.dom&&this.editor.dom.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"})}),300)}edit(t){h.disableInteractiveWidget(),this.uneditedObject=this.clone(),this._core.store.setState("activeTool",i.getTool("text")),this.editor.setProps({editable:()=>!0}),this.isEditing=!0,this._core.rerender(),this.adjustSizeOnInput(),this.focus({x:t?.clientX,y:t?.clientY}),h.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&&(this._core.store.state.pointers.has(t.pointerId)||t.stopPropagation())}handlePointerUp(t){this.isEditing&&(this._core.store.state.pointers.has(t.pointerId)||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:r,totalWidth:s,totalHeight:n,editor:o,uneditedObject:h,...l}=this,a=structuredClone(l);return r&&"object"==typeof r&&"nodeType"in r&&1===r.nodeType&&(a.element=r.cloneNode(!0)),a}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}}var $n,Rn,jn,Fn={},Nn=($n||($n=1,function(t){Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const{PI:e}=Math,i=e+1e-4,r=[1,1];function s(t,e,i,r=t=>t){return t*r(.5-e*(.5-i))}const{min:n}=Math;function o(t,e,i){let r=n(1,e/i);return n(1,t+(n(1,1-r)-t)*(.275*r))}function h(t,e){return[t[0]+e[0],t[1]+e[1]]}function l(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t}function a(t,e){return[t[0]-e[0],t[1]-e[1]]}function u(t,e,i){return t[0]=e[0]-i[0],t[1]=e[1]-i[1],t}function c(t,e){return[t[0]*e,t[1]*e]}function f(t,e,i){return t[0]=e[0]*i,t[1]=e[1]*i,t}function d(t){return[t[1],-t[0]]}function p(t,e){let i=e[0];return t[0]=e[1],t[1]=-i,t}function g(t,e){return t[0]*e[0]+t[1]*e[1]}function w(t,e){return t[0]===e[0]&&t[1]===e[1]}function m(t,e){let i=t[0]-e[0],r=t[1]-e[1];return i*i+r*r}function v(t){return function(t,e){return[t[0]/e,t[1]/e]}(t,function(t){return Math.hypot(t[0],t[1])}(t))}function y(t,e){return Math.hypot(t[1]-e[1],t[0]-e[0])}function k(t,e,i){let r=Math.sin(i),s=Math.cos(i),n=t[0]-e[0],o=t[1]-e[1];return[n*s-o*r+e[0],n*r+o*s+e[1]]}function b(t,e,i,r){let s=Math.sin(r),n=Math.cos(r),o=e[0]-i[0],h=e[1]-i[1],l=o*s+h*n;return t[0]=o*n-h*s+i[0],t[1]=l+i[1],t}function M(t,e,i){return h(t,c(a(e,t),i))}function x(t,e,i,r){let s=i[1]-e[1];return t[0]=e[0]+(i[0]-e[0])*r,t[1]=e[1]+s*r,t}function C(t,e,i){return h(t,c(e,i))}const A=[0,0],S=[0,0],B=[0,0];function T(t,e){let r=C(t,v(d(a(t,h(t,[1,1])))),-e),s=[],n=1/13;for(let e=n;e<=1;e+=n)s.push(k(r,t,2*i*e));return s}function O(t,e,r){let s=[],n=1/r;for(let r=n;r<=1;r+=n)s.push(k(e,t,i*r));return s}function E(t,e,i){let r=a(e,i),s=c(r,.5),n=c(r,.51);return[a(t,s),a(t,n),h(t,n),h(t,s)]}function I(t,e,r,s){let n=[],o=C(t,e,r),h=1/s;for(let e=h;e<1;e+=h)n.push(k(o,t,3*i*e));return n}function D(t,e,i){return[h(t,c(e,i)),h(t,c(e,.99*i)),a(t,c(e,.99*i)),a(t,c(e,i))]}function P(t,e,i){return!1===t||void 0===t?0:!0===t?Math.max(e,i):t}function $(t,e={}){let{size:r=16,smoothing:n=.5,thinning:c=.5,simulatePressure:w=!0,easing:v=t=>t,start:y={},end:k={},last:M=!1}=e,{cap:C=!0,easing:$=t=>t*(2-t)}=y,{cap:R=!0,easing:j=t=>--t*t*t+1}=k;if(0===t.length||r<=0)return[];let F,N=t[t.length-1].runningLength,U=P(y.taper,r,N),z=P(k.taper,r,N),L=(r*n)**2,_=[],H=[],X=function(t,e,i){return t.slice(0,10).reduce(((t,r)=>{let s=r.pressure;return e&&(s=o(t,r.distance,i)),(t+s)/2}),t[0].pressure)}(t,w,r),Y=s(r,c,t[t.length-1].pressure,v),W=t[0].vector,V=t[0].point,J=V,Q=V,K=J,q=!1;for(let e=0;e<t.length;e++){let{pressure:n}=t[e],{point:d,vector:y,distance:k,runningLength:M}=t[e],C=e===t.length-1;if(!C&&N-M<3)continue;c?(w&&(n=o(X,k,r)),Y=s(r,c,n,v)):Y=r/2,void 0===F&&(F=Y);let T=M<U?$(M/U):1,O=N-M<z?j((N-M)/z):1;Y=Math.max(.01,Y*Math.min(T,O));let E=(C?t[e]:t[e+1]).vector,I=C?1:g(y,E),D=null!==I&&I<0;if(g(y,W)<0&&!q||D){p(A,W),f(A,A,Y);for(let t=0;t<=1;t+=.07692307692307693)u(S,d,A),b(S,S,d,i*t),Q=[S[0],S[1]],_.push(Q),l(B,d,A),b(B,B,d,i*-t),K=[B[0],B[1]],H.push(K);V=Q,J=K,D&&(q=!0)}else q=!1,C?(p(A,y),f(A,A,Y),_.push(a(d,A)),H.push(h(d,A))):(x(A,E,y,I),p(A,A),f(A,A,Y),u(S,d,A),Q=[S[0],S[1]],(e<=1||m(V,Q)>L)&&(_.push(Q),V=Q),l(B,d,A),K=[B[0],B[1]],(e<=1||m(J,K)>L)&&(H.push(K),J=K),X=n,W=y)}let G=[t[0].point[0],t[0].point[1]],Z=t.length>1?[t[t.length-1].point[0],t[t.length-1].point[1]]:h(t[0].point,[1,1]),tt=[],et=[];if(1===t.length){if(!U&&!z||M)return T(G,F||Y)}else{U||z&&1===t.length||(C?tt.push(...O(G,H[0],13)):tt.push(...E(G,_[0],H[0])));let e=d(function(t){return[-t[0],-t[1]]}(t[t.length-1].vector));z||U&&1===t.length?et.push(Z):R?et.push(...I(Z,e,Y,29)):et.push(...D(Z,e,Y))}return _.concat(et,H.reverse(),tt)}const R=[0,0];function j(t){return null!=t&&t>=0}function F(t,e={}){let{streamline:i=.5,size:s=16,last:n=!1}=e;if(0===t.length)return[];let o=.15+.85*(1-i),l=Array.isArray(t[0])?t:t.map((({x:t,y:e,pressure:i=.5})=>[t,e,i]));if(2===l.length){let t=l[1];l=l.slice(0,-1);for(let e=1;e<5;e++)l.push(M(l[0],t,e/4))}1===l.length&&(l=[...l,[...h(l[0],r),...l[0].slice(2)]]);let a=[{point:[l[0][0],l[0][1]],pressure:j(l[0][2])?l[0][2]:.25,vector:[...r],distance:0,runningLength:0}],c=!1,f=0,d=a[0],p=l.length-1;for(let t=1;t<l.length;t++){let e=n&&t===p?[l[t][0],l[t][1]]:M(d.point,l[t],o);if(w(d.point,e))continue;let i=y(e,d.point);if(f+=i,t<p&&!c){if(f<s)continue;c=!0}u(R,d.point,e),d={point:e,pressure:j(l[t][2])?l[t][2]:.5,vector:v(R),distance:i,runningLength:f},a.push(d)}return a[0].vector=a[1]?.vector||[0,0],a}function N(t,e={}){return $(F(t,e),e)}t.default=N,t.getStroke=N,t.getStrokeOutlinePoints=$,t.getStrokePoints=F}(Fn)),Fn);class Un{static average(t,e){return(t+e)/2}}class zn extends n{__class__="KritzelPath";points;d;stroke={light:"none",dark:"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??{light:"#000000",dark:"#ffffff"},this.d=this.generateSvgPath(),this.updateDimensions()}static create(t,e){const i=new zn;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.userId=t.user?.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??{light:"#000000",dark:"#ffffff"},i.opacity=e?.opacity??1,i.zIndex=t.store.currentZIndex,i.d=i.generateSvgPath(),i.updateDimensions(),i}copy(){const t=super.copy();return this.points&&(t.points=this.points.map((t=>[...t]))),t}resize(t,e,i,r){if(i<=1||r<=1)return;const s=i/this.width,n=r/this.height;if(this.width=i,this.height=r,1===this.points.length){const t=this.points[0],e=Math.max(0,i-this.strokeWidth)/s,o=Math.max(0,r-this.strokeWidth)/n;this.points.push([t[0]+e,t[1]+o])}this.points=this.points.map((([t,e])=>[t*s,e*n])),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,r){const s=(e-r)/this._core.store.state.scale;this.translateX+=(t-i)/this._core.store.state.scale,this.translateY+=s,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 r=this._adjustedPoints[0];return this.pointToLineSegmentDistance(t,e,r[0],r[1],r[0],r[1])<=i}for(let r=0;r<this._adjustedPoints.length-1;r++){const s=this._adjustedPoints[r],n=this._adjustedPoints[r+1];if(this.pointToLineSegmentDistance(t,e,s[0],s[1],n[0],n[1])<=i)return!0}return!1}hitTestPolygon(t){const e=this.strokeWidth/this.scale/2;null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const i=[{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(s.isPointInPolygon({x:t,y:e},i))return!0;for(const t of i)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]},r={x:this._adjustedPoints[t+1][0],y:this._adjustedPoints[t+1][1]};for(let t=0;t<i.length;t++)if(s.intersectLines(e,r,i[t],i[(t+1)%i.length]))return!0}for(let t=0;t<this._adjustedPoints.length-1;t++){const r=this._adjustedPoints[t],s=this._adjustedPoints[t+1];for(let t=0;t<i.length;t++){const n=i[t],o=i[(t+1)%i.length],h=this.pointToLineSegmentDistance(n.x,n.y,r[0],r[1],s[0],s[1]),l=this.pointToLineSegmentDistance(o.x,o.y,r[0],r[1],s[0],s[1]),a=this.pointToLineSegmentDistance(r[0],r[1],n.x,n.y,o.x,o.y),u=this.pointToLineSegmentDistance(s[0],s[1],n.x,n.y,o.x,o.y);if(Math.min(h,l,a,u)<=e)return!0}}return!1}updatePosition(t,e){this.translateX=t,this.translateY=e,this._adjustedPoints=null,this._core.store.state.objects.update(this)}onAfterUpdate(t){t.includes("strokeWidth")&&(this.d=this.generateSvgPath(),this.updateBoundingBox(),this._adjustedPoints=null)}computeAdjustedPoints(){if(!this.points?.length)return[];const t=this.rotation,e=Math.cos(t),i=Math.sin(t),r=this.points.map((t=>t[0])),s=this.points.map((t=>t[1])),n={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...s)+Math.max(...s))/2},{x:o,y:h}=n;return this.points.map((([t,r])=>{const s=t-o,n=r-h;return[o+s*e-n*i,h+s*i+n*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,r,s,n){const o=s-i,h=n-r,l=o*o+h*h;let a,u,c=-1;0!==l&&(c=((t-i)*o+(e-r)*h)/l),c<0?(a=i,u=r):c>1?(a=s,u=n):(a=i+c*o,u=r+c*h);const f=t-a,d=e-u;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))),r=Math.max(...t.map((t=>t[0]+this.strokeWidth/2))),s=Math.max(...t.map((t=>t[1]+this.strokeWidth/2)));this.width=r-e+this.lineSlack,this.height=s-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}updateBoundingBox(){const t=Math.min(...this.points.map((t=>t[0])))-this.strokeWidth/2,e=Math.min(...this.points.map((t=>t[1])))-this.strokeWidth/2,i=Math.max(...this.points.map((t=>t[0])))+this.strokeWidth/2,r=Math.max(...this.points.map((t=>t[1])))+this.strokeWidth/2;this.width=i-t+this.lineSlack,this.height=r-e+this.lineSlack,this.x=t,this.y=e}generateSvgPath(){const t=this.getStrokeFromPoints(this.points,this.strokeWidth);return this.getSvgPathFromStroke(t)}getStrokeFromPoints(t,e){return Nn.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 r=t[0],s=t[1];const n=t[2];let o=`M${r[0].toFixed(2)},${r[1].toFixed(2)} Q${s[0].toFixed(2)},${s[1].toFixed(2)} ${Un.average(s[0],n[0]).toFixed(2)},${Un.average(s[1],n[1]).toFixed(2)} T`;for(let e=2,n=i-1;e<n;e++)r=t[e],s=t[e+1],o+=`${Un.average(r[0],s[0]).toFixed(2)},${Un.average(r[1],s[1]).toFixed(2)} `;return e&&(o+="Z"),o}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,r=this.strokeWidth/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),this._adjustedPoints.length<1)return null;let s=!0;for(let n=1;n<=32;n++){const o=n/32,h=t.x+(e-t.x)*o,l=t.y+(i-t.y)*o;let a=1/0;if(1===this._adjustedPoints.length){const t=this._adjustedPoints[0],e=h-t[0],i=l-t[1];a=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],r=this.pointToLineSegmentDistance(h,l,e[0],e[1],i[0],i[1]);r<a&&(a=r)}const u=a<=r;if(s&&u){let s=(n-1)/32,h=o;for(let n=0;n<8;n++){const n=(s+h)/2,o=t.x+(e-t.x)*n,l=t.y+(i-t.y)*n;let a=1/0;if(1===this._adjustedPoints.length){const t=this._adjustedPoints[0],e=o-t[0],i=l-t[1];a=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],r=this.pointToLineSegmentDistance(o,l,e[0],e[1],i[0],i[1]);r<a&&(a=r)}a<=r?h=n:s=n}const l=(s+h)/2;return{x:t.x+(e-t.x)*l,y:t.y+(i-t.y)*l}}s=!u}return null}}class Ln extends n{__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,this.width=t?.width||0,this.height=t?.height||0,this.maxWidth=t?.maxWidth??300,this.maxHeight=t?.maxHeight??300}static create(t){const e=new Ln;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.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,r){if(i<=1||r<=1)return;const s=r/this.height;this.width=this.width*s,this.height=this.height*s,this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this)}static fromUrl(t,e){return new Promise(((i,r)=>{const s=new Image;s.onload=()=>{const r=new Ln({...e,src:t}),{scaledWidth:n,scaledHeight:o}=r.calculateScaledDimensions(s);r.width=n,r.height=o,i(r)},s.onerror=t=>r(t),s.src=t}))}calculateScaledDimensions(t){let e=t.width,i=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const r=Math.min(this.maxWidth/t.width,this.maxHeight/t.height);e=t.width*r,i=t.height*r}return{scaledWidth:e,scaledHeight:i}}}class _n extends n{__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??{light:"#000000",dark:"#ffffff"},this.startAnchor=t?.startAnchor,this.endAnchor=t?.endAnchor,this.arrows=t?.arrows,this.updateDimensions()}static create(t,e){const i=new _n;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.userId=t.user?.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??{light:"#000000",dark:"#ffffff"},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,r){if(i<=1||r<=1)return;const s=i/this.width,n=r/this.height;this.startX=this.startX*s,this.startY=this.startY*n,this.endX=this.endX*s,this.endY=this.endY*n,void 0!==this.controlX&&void 0!==this.controlY&&(this.controlX=this.controlX*s,this.controlY=this.controlY*n);const{minX:o,minY:h,maxX:l,maxY:a}=this.calculateBoundingBox();this.width=l-o,this.height=a-h,this.x=o,this.y=h,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,r){const s=(e-r)/this._core.store.state.scale;this.translateX+=(t-i)/this._core.store.state.scale,this.translateY+=s,this.startAnchor&&this._core.anchorManager.updateAnchorsForObject(this.startAnchor.objectId),this.endAnchor&&this._core.anchorManager.updateAnchorsForObject(this.endAnchor.objectId),this._adjustedPoints=null,this._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 r=this.getClipInfo();return this.pointToBezierDistance(t,e,r.start?.t??0,r.end?.t??1)<=i}const r=this.getClipInfo(),s=r.start?[r.start.x,r.start.y]:this._adjustedPoints[0],n=r.end?[r.end.x,r.end.y]:this._adjustedPoints[1];return this.pointToLineSegmentDistance(t,e,s[0],s[1],n[0],n[1])<=i}hitTestPolygon(t){const e=this.strokeWidth/this.scale/2;null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const i=this.getClipInfo(),r=[{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}],n=i.start?[i.start.x,i.start.y]:this._adjustedPoints[0],o=i.end?[i.end.x,i.end.y]:this._adjustedPoints[1],h=[n,o];for(const[t,e]of h)if(s.isPointInPolygon({x:t,y:e},r))return!0;for(const t of r)if(this.hitTest(t.x,t.y))return!0;if(void 0!==this.controlX&&void 0!==this.controlY){const t=this._adjustedPoints[0],n=this._adjustedPoints[1],o=this.computeAdjustedControlPoint(),h=i.start?.t??0,l=i.end?.t??1,a=20;for(let i=0;i<=a;i++){const u=h+i/a*(l-h),c=1-u,f=c*c*t[0]+2*c*u*o[0]+u*u*n[0],d=c*c*t[1]+2*c*u*o[1]+u*u*n[1];if(s.isPointInPolygon({x:f,y:d},r))return!0;for(let t=0;t<r.length;t++){const i=r[t],s=r[(t+1)%r.length];if(this.pointToLineSegmentDistance(f,d,i.x,i.y,s.x,s.y)<=e)return!0}}return!1}const l={x:n[0],y:n[1]},a={x:o[0],y:o[1]};for(let t=0;t<r.length;t++){const i=r[t],n=r[(t+1)%r.length];if(s.intersectLines(l,a,i,n))return!0;const o=this.pointToLineSegmentDistance(i.x,i.y,l.x,l.y,a.x,a.y),h=this.pointToLineSegmentDistance(n.x,n.y,l.x,l.y,a.x,a.y),u=this.pointToLineSegmentDistance(l.x,l.y,i.x,i.y,n.x,n.y),c=this.pointToLineSegmentDistance(a.x,a.y,i.x,i.y,n.x,n.y);if(Math.min(o,h,u,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 r=this.width,s=this.height,{minX:n,minY:o,maxX:h,maxY:l}=this.calculateBoundingBox(),a=n-this.x,u=o-this.y,c=h-n,f=l-o,d=(c-r)/2,p=(f-s)/2;this.x=n,this.y=o,this.width=c,this.height=f;const g=Math.cos(this.rotation),w=Math.sin(this.rotation),m=a+d,v=u+p,y=m*w+v*g-p;this.translateX+=(m*g-v*w-d)/this.scale,this.translateY+=y/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,r=this.height,{minX:s,minY:n,maxX:o,maxY:h}=this.calculateBoundingBox(),l=s-this.x,a=n-this.y,u=o-s,c=h-n,f=(u-i)/2,d=(c-r)/2;this.x=s,this.y=n,this.width=u,this.height=c;const p=Math.cos(this.rotation),g=Math.sin(this.rotation),w=l+f,m=a+d,v=w*g+m*p-d;this.translateX+=(w*p-m*g-f)/this.scale,this.translateY+=v/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),r=Math.sin(e),s=t.map((t=>t[0])),n=t.map((t=>t[1])),o={x:(Math.min(...s)+Math.max(...s))/2,y:(Math.min(...n)+Math.max(...n))/2},{x:h,y:l}=o;return t.map((([t,e])=>{const s=t-h,n=e-l;return[h+s*i-n*r,l+s*r+n*i]})).map((([t,e])=>[(t-this.x)/this.scale+this.translateX,(e-this.y)/this.scale+this.translateY]))}pointToLineSegmentDistance(t,e,i,r,s,n){const o=s-i,h=n-r,l=o*o+h*h;let a,u,c=-1;0!==l&&(c=((t-i)*o+(e-r)*h)/l),c<0?(a=i,u=r):c>1?(a=s,u=n):(a=i+c*o,u=r+c*h);const f=t-a,d=e-u;return Math.sqrt(f*f+d*d)}pointToBezierDistance(t,e,i=0,r=1){null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const s=this._adjustedPoints[0],n=this._adjustedPoints[1],o=this.computeAdjustedControlPoint();let h=1/0;for(let l=0;l<=20;l++){const a=i+l/20*(r-i),u=1-a,c=t-(u*u*s[0]+2*u*a*o[0]+a*a*n[0]),f=e-(u*u*s[1]+2*u*a*o[1]+a*a*n[1]),d=Math.sqrt(c*c+f*f);d<h&&(h=d)}return h}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),r=[this.startX,this.endX],s=[this.startY,this.endY],n={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...s)+Math.max(...s))/2},{x:o,y:h}=n,l=this.controlX-o,a=this.controlY-h;return[(o+l*e-a*i-this.x)/this.scale+this.translateX,(h+l*i+a*e-this.y)/this.scale+this.translateY]}get rotatedPolygon(){const t=this.padding,{minX:e,minY:i,maxX:r,maxY:s}=_n.calculateBoundingBox(this.startX,this.startY,this.endX,this.endY,this.controlX,this.controlY,this.strokeWidth),n=e-this.x+t,o=i-this.y+t,h=r-this.x+t,l=s-this.y+t,a={x:n,y:o},u={x:h,y:o},c={x:h,y:l},f={x:n,y:l},d=this.totalWidth/2,p=this.totalHeight/2,g=this.rotation,w=Math.cos(g),m=Math.sin(g),v=t=>({x:((t.x-d)*w-(t.y-p)*m+d)/this.scale+this.translateX,y:((t.x-d)*m+(t.y-p)*w+p)/this.scale+this.translateY});return{topLeft:v(a),topRight:v(u),bottomRight:v(c),bottomLeft:v(f)}}static calculateBoundingBox(t,e,i,r,s,n,o){let h=Math.min(t,i),l=Math.min(e,r),a=Math.max(t,i),u=Math.max(e,r);if(void 0!==s&&void 0!==n){const o=t-2*s+i;if(0!==o){const e=(t-s)/o;if(e>0&&e<1){const r=(1-e)*(1-e)*t+2*(1-e)*e*s+e*e*i;h=Math.min(h,r),a=Math.max(a,r)}}const c=e-2*n+r;if(0!==c){const t=(e-n)/c;if(t>0&&t<1){const i=(1-t)*(1-t)*e+2*(1-t)*t*n+t*t*r;l=Math.min(l,i),u=Math.max(u,i)}}}const c=o/2;return{minX:h-c,minY:l-c,maxX:a+c,maxY:u+c}}calculateBoundingBox(){return _n.calculateBoundingBox(this.startX,this.startY,this.endX,this.endY,this.controlX,this.controlY,this.strokeWidth)}updateDimensions(){const{minX:t,minY:e,maxX:i,maxY:r}=this.calculateBoundingBox();this.width=i-t,this.height=r-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 Dn.resolveThemeColor(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 Hn{static isInstanceOf(t,e){return!!t&&t.__class__===e}}class Xn extends n{__class__="KritzelGroup";childIds=[];_pendingChildren=[];unchangedChildSnapshots=new Map;snapshotRotation=0;snapshotTranslateX=0;snapshotTranslateY=0;snapshotTotalWidth=0;snapshotTotalHeight=0;snapshotScale=1;get children(){return this._core?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)):this._pendingChildren}get length(){return this.childIds.length}static create(t){const e=new Xn;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.scale=t.store.state.scale,e.zIndex=t.store.currentZIndex,e}static createFromObjects(t,e){const i=Xn.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){if(!this.childIds.includes(t.id)){if(this.childIds.push(t.id),!this._core)return void this._pendingChildren.push(t);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()}centerInViewport(){const{viewportWidth:t,viewportHeight:e,translateX:i,translateY:r,scale:s}=this._core.store.state,{x:n,y:o,width:h,height:l}=this.rotatedBoundingBox,a=(t/2-i)/s-(n+h/2),u=(e/2-r)/s-(o+l/2);this.translateX+=a,this.translateY+=u,this.children.forEach((t=>{t.translateX+=a,t.translateY+=u})),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 r=1/0,s=-1/0,n=1/0,o=-1/0;this.children.forEach((t=>{const h=t.rotatedPolygon;[h.topLeft,h.topRight,h.bottomRight,h.bottomLeft].forEach((t=>{const h=t.x*e-t.y*i,l=t.x*i+t.y*e;h<r&&(r=h),h>s&&(s=h),l<n&&(n=l),l>o&&(o=l)}))}));const h=o-n;this.width=(s-r-this.padding)*this.scale,this.height=(h-this.padding)*this.scale;const l=(r+s)/2,a=(n+o)/2,u=Math.cos(t),c=Math.sin(t),f=l*c+a*u;this.translateX=l*u-a*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,r){const s=(t-i)/this._core.store.state.scale,n=(e-r)/this._core.store.state.scale;this.translateX+=s,this.translateY+=n,this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.children.forEach((s=>{s.move(t,e,i,r),this._core.anchorManager.updateAnchorsForObject(s.id)}))})),this.unchangedChildSnapshots.forEach((t=>{t.translateX+=s,t.translateY+=n}))}resize(t,e,i,r){const s=i/this.width,n=r/this.height,o=this.translateX+this.totalWidth/2/this.scale,h=this.translateY+this.totalHeight/2/this.scale,l=t+(i+2*this.padding)/2/this.scale,a=e+(r+2*this.padding)/2/this.scale,u=this.rotation,c=Math.cos(-u),f=Math.sin(-u),d=Math.cos(u),p=Math.sin(u);this._core.store.state.objects.transaction((()=>{this.children.forEach((t=>{const e=t.translateX+t.totalWidth/2/t.scale-o,i=t.translateY+t.totalHeight/2/t.scale-h,r=(e*c-i*f)*s,g=(e*f+i*c)*n,w=l+(r*d-g*p),m=a+(r*p+g*d),v=t.rotation-u,y=Math.cos(v),k=Math.sin(v),b=Math.sqrt(Math.pow(s*y,2)+Math.pow(n*k,2)),M=Math.sqrt(Math.pow(s*k,2)+Math.pow(n*y,2)),x=t.width*b,C=t.height*M;t.resize(w-(x+2*t.padding)/2/t.scale,m-(C+2*t.padding)/2/t.scale,x,C),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,r=t-this.snapshotRotation,s=Math.cos(r),n=Math.sin(r);this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.children.forEach((o=>{const h=this.unchangedChildSnapshots.get(o.id);if(!h)return;const l=this.getOffsetXToCenterFromSnapshot(h),a=this.getOffsetYToCenterFromSnapshot(h),u=n*l+s*a;o.translateX=e+(s*l-n*a)-o.totalWidth/2/o.scale,o.translateY=i+u-o.totalHeight/2/o.scale,o.rotate(1===this.children.length?t:h.rotation+r)}))}))}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=Xn.create(this._core),e=[];return this.children.sort(((t,e)=>t.zIndex-e.zIndex)).forEach((i=>{const r=i.copy();e.push(r),t.childIds.push(r.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:r,totalHeight:s,unchangedChildSnapshots:n,_pendingChildren:o,...h}=this,l=structuredClone(h);return l.unchangedChildSnapshots=Object.fromEntries(this.unchangedChildSnapshots),l}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,Hn.isInstanceOf(e,"KritzelGroup")&&e.updateWorkspaceId(t)}))}}!function(t){t.Rectangle="rectangle",t.Ellipse="ellipse",t.Triangle="triangle"}(Rn||(Rn={}));class Yn extends n{__class__="KritzelShape";shapeType=Rn.Rectangle;fillColor={light:"transparent",dark:"transparent"};strokeColor={light:"#000000",dark:"#ffffff"};strokeWidth=4;fontFamily="Arial";fontSize=16;fontColor={light:"#000000",dark:"#ffffff"};x=0;y=0;scale=1;scaleFactor=1;isDebugInfoVisible=!0;isEditable=!0;isEditing=!1;editor=null;content=null;_schema=new tt({nodes:Ks(_s.spec.nodes,"paragraph block*","block"),marks:_s.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??Rn.Rectangle,this.fillColor=t.fillColor??{light:"transparent",dark:"transparent"},this.strokeColor=t.strokeColor??t.fillColor??{light:"#000000",dark:"#ffffff"},this.strokeWidth=t.strokeWidth??4,this.fontSize=t.fontSize??16,this.fontFamily=t.fontFamily??"Arial",this.fontColor=t.fontColor??Dn.determineTextColor(this.fillColor),this.scale=t.scale??1,this.scaleFactor=t.scaleX??1)}static create(t,e){const i=new Yn;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.userId=t.user?.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??Rn.Rectangle,i.fillColor=e?.fillColor??{light:"transparent",dark:"transparent"},i.strokeColor=e?.strokeColor??e?.fillColor??{light:"#000000",dark:"#ffffff"},i.strokeWidth=e?.strokeWidth??4,i.opacity=e?.opacity??1,i.fontSize=e?.fontSize??16,i.fontFamily=e?.fontFamily??"Arial",i.fontColor=e?.fontColor??Dn.determineTextColor(i.fillColor),i.backgroundColor={light:"transparent",dark:"transparent"},i.scaleFactor=1,i.scale=e?.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&&(t.style.fontFamily=this.fontFamily,t.style.fontSize=`${this.fontSize}pt`,t.style.color=Dn.resolveThemeColor(this.fontColor),t.style.whiteSpace="pre-wrap",t.style.wordWrap="break-word",this.editor.dom.parentElement!==t&&(t.innerHTML="",t.appendChild(this.editor.dom)))}createEditor(){const t=this._schema.node("doc",null,[this._schema.node("paragraph")]);return new Ts(null,{state:ve.create({doc:t,plugins:[ln(Cn)]}),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,r){i<=1||r<=1||(this.width=i,this.height=r,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(ne.create(e,i.pos))),this.editor.focus(),void(o.isIOS()&&this.scrollIntoViewOnIOS())}const i=Math.max(1,e.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(ne.create(e,i))),this.editor.focus(),o.isIOS()&&this.scrollIntoViewOnIOS()}}scrollIntoViewOnIOS(){setTimeout((()=>{this.editor&&this.editor.dom&&this.editor.dom.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"})}),300)}edit(t){h.disableInteractiveWidget(),this.uneditedObject=this.clone(),this._core.store.setState("activeTool",i.getTool("shape")),this.editor.setProps({editable:()=>!0}),this.isEditing=!0,this._core.rerender(),this.focus({x:t?.clientX,y:t?.clientY}),h.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&&(this._core.store.state.pointers.has(t.pointerId)||t.stopPropagation())}handlePointerMove(t){this.isEditing&&(this._core.store.state.pointers.has(t.pointerId)||t.stopPropagation())}handlePointerUp(t){this.isEditing&&(this._core.store.state.pointers.has(t.pointerId)||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:r,totalWidth:s,totalHeight:n,editor:o,uneditedObject:h,...l}=this,a=structuredClone(l);return r&&"object"==typeof r&&"nodeType"in r&&1===r.nodeType&&(a.element=r.cloneNode(!0)),a}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}onAfterUpdate(t){t.includes("fillColor")?(this.fontColor=Dn.determineTextColor(this.fillColor),this.editor?.dom?.parentElement&&(this.editor.dom.parentElement.style.color=Dn.resolveThemeColor(this.fontColor))):t.includes("fontColor")&&this.editor?.dom?.parentElement&&(this.editor.dom.parentElement.style.color=Dn.resolveThemeColor(this.fontColor))}getClipPolygon(){const t=this.totalWidth/this.scale,e=this.totalHeight/this.scale,i=this.translateX+t/2,r=this.translateY+e/2,n=this.strokeWidth/this.scale/2;switch(this.shapeType){case Rn.Ellipse:return s.getEllipsePolygonApproximation(i,r,t/2+n,e/2+n,32,this.rotation);case Rn.Triangle:const o=(t,e)=>{const s=t-i,o=e-r,h=Math.sqrt(s*s+o*o);if(0===h)return{x:t,y:e};const l=(h+n)/h;return{x:i+s*l,y:r+o*l}},h=this.translateX,l=this.translateY+e,a=this.translateX+t,u=this.translateY+e,c=o(this.translateX+t/2,this.translateY),f=o(a,u),d=o(h,l);if(0!==this.rotation){const t=Math.cos(this.rotation),e=Math.sin(this.rotation),s=s=>{const n=s.x-i,o=s.y-r;return{x:i+n*t-o*e,y:r+n*e+o*t}};return[s(c),s(f),s(d)]}return[c,f,d];default:return null}}getSvgPath(){const t=this.width,e=this.height;switch(this.shapeType){case Rn.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 Rn.Ellipse:const i=this.x+t/2,r=this.y+e/2,s=t/2,n=e/2;return`M ${i-s} ${r} A ${s} ${n} 0 1 0 ${i+s} ${r} A ${s} ${n} 0 1 0 ${i-s} ${r}`;case Rn.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`}}}!function(t){t[t.Left=0]="Left",t[t.Middle=1]="Middle",t[t.Right=2]="Right"}(jn||(jn={}));class Wn{static isRightClick(t){return t.button===jn.Right}static isLeftClick(t){return t.button===jn.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 r=t.clientX,s=t.clientY,n=t.target;if(!n)return i?.(),()=>{};const o=setTimeout((()=>{c(),e(t)}),400),h=()=>{clearTimeout(o),c(),i?.()},l=t=>{(Math.abs(t.clientX-r)>10||Math.abs(t.clientY-s)>10)&&h()},a=()=>{h()},u=()=>{h()},c=()=>{n.removeEventListener("pointermove",l),n.removeEventListener("pointerup",a),n.removeEventListener("pointercancel",u)};return n.addEventListener("pointermove",l,{passive:!0}),n.addEventListener("pointerup",a,{once:!0}),n.addEventListener("pointercancel",u,{once:!0}),h}}class Vn{__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 Jn extends Vn{color=An[0];size=6;opacity=1;palette=[...An];_currentPathId=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&Wn.isLeftClick(t)){this._core.store.state.isDrawing=!0;const e=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?e:1,s=zn.create(this._core,{points:[[(t.clientX-this._core.store.offsetX)/r,(t.clientY-this._core.store.offsetY)/r]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:i?1:e,fill:this.color,strokeWidth:this.size,opacity:this.opacity});s.isCompleted=!1,this._currentPathId=s.id,this._core.store.state.objects.insert(s),this._core.store.state.objects?.setActiveDrawingObject(s.id)}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const e=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?e:1,s=Math.round((t[0].clientX-this._core.store.offsetX)/r),n=Math.round((t[0].clientY-this._core.store.offsetY)/r);this._core.store.state.isDrawing=!0;const o=zn.create(this._core,{points:[[s,n]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:i?1:e,fill:this.color,strokeWidth:this.size,opacity:this.opacity});o.isCompleted=!1,this._currentPathId=o.id,this._core.store.state.objects.insert(o),this._core.store.state.objects?.setActiveDrawingObject(o.id)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&this._currentPathId){const e=this._core.store.state.objects.findById(this._currentPathId);if(e){const i=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,s=r?i:1,n=zn.create(this._core,{points:[...e.points,[(t.clientX-this._core.store.offsetX)/s,(t.clientY-this._core.store.offsetY)/s]],translateX:-this._core.store.state.translateX/s,translateY:-this._core.store.state.translateY/s,scale:r?1:i,fill:this.color,strokeWidth:this.size,opacity:this.opacity});n.id=e.id,n.workspaceId=e.workspaceId,n.zIndex=e.zIndex,n.isCompleted=!1,this._core.store.state.objects.update(n)}}if("touch"===t.pointerType||"pen"===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.findById(this._currentPathId);if(e){const i=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,s=r?i:1,n=Math.round((t[0].clientX-this._core.store.offsetX)/s),o=Math.round((t[0].clientY-this._core.store.offsetY)/s),h=zn.create(this._core,{points:[...e.points,[n,o]],translateX:-this._core.store.state.translateX/s,translateY:-this._core.store.state.translateY/s,scale:r?1:i,fill:this.color,strokeWidth:this.size,opacity:this.opacity});h.id=e.id,h.workspaceId=e.workspaceId,h.zIndex=e.zIndex,h.isCompleted=!1,this._core.store.state.objects.update(h)}}}}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.findById(this._currentPathId);t&&(t.isCompleted=!0,this._core.store.state.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])),this._core.store.state.objects?.setActiveDrawingObject(null),this._currentPathId=null}if(("touch"===t.pointerType||"pen"===t.pointerType)&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentPathId)){const t=this._core.store.state.objects.findById(this._currentPathId);t&&(t.isCompleted=!0,this._core.store.state.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])),this._core.store.state.objects?.setActiveDrawingObject(null),this._currentPathId=null}}}class Qn extends n{__class__="KritzelSelectionGroup";_objectIds=[];_cachedObjects=null;_cachedObjectIdsHash="";unchangedObjectSnapshots=new Map;snapshotRotation=0;snapshotWidth=0;snapshotHeight=0;snapshotTranslateX=0;snapshotTranslateY=0;minX;maxX;minY;maxY;handleColor;handleStrokeColor;handleSize=6;get objectIds(){return this._objectIds}set objectIds(t){this._objectIds=t,this._cachedObjects=null}invalidateObjectsCache(){this._cachedObjects=null}get objects(){const t=this._objectIds.join(",");if(null!==this._cachedObjects&&this._cachedObjectIdsHash===t)return this._cachedObjects;const e=new Set(this._objectIds),i=this._core.store.state.objects.filter((t=>e.has(t.id))),r=new Map(i.map((t=>[t.id,t])));return this._cachedObjects=this._objectIds.map((t=>r.get(t))).filter((t=>void 0!==t)),this._cachedObjectIdsHash=t,this._cachedObjects}get length(){return this.objectIds.length}static create(t){const e=new Qn;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.scale=t.store.state.scale,e.zIndex=99999,e.borderColor={light:"#007AFF",dark:"#0A84FF"},e.borderWidth=2,e.handleColor={light:"#ffffff",dark:"#1a1a1a"},e.handleStrokeColor={light:"#007AFF",dark:"#0A84FF"},e.handleSize=6,e}addObjects(t){let e=!1;for(const i of t)this._objectIds.includes(i.id)||(this._objectIds.push(i.id),e=!0);if(e){this._cachedObjects=null;const t=this.objects;1===t.length?this.rotation=t[0].rotation:t.length>1&&(this.rotation=0),this.captureUnchangedSnapshots(t),this.refreshObjectDimensions(t)}}addOrRemove(t){const e=this._objectIds.findIndex((e=>e===t.id));-1===e?this._objectIds.push(t.id):this._objectIds.splice(e,1),this._cachedObjects=null;const i=this.objects;1===i.length?this.rotation=i[0].rotation:i.length>1&&(this.rotation=0),this.captureUnchangedSnapshots(i),this.refreshObjectDimensions(i)}beginTransform(){const t=this.objects;this.refreshObjectDimensions(t),this.captureUnchangedSnapshots(t);for(const e of t)Hn.isInstanceOf(e,"KritzelGroup")&&e.finalize()}deselectAllChildren(){const t=this.objects;for(const e of t)e.isSelected=!1}updateWorkspaceId(t){this.workspaceId=t;const e=this.objects;for(const i of e)i.workspaceId=t}updateZIndices(t){const e=this.objects;for(let i=0;i<e.length;i++)e[i].zIndex=t+i}updatePosition(t,e){const i=this.objects;for(const r of i)r.updatePosition(t+(r.translateX-this.translateX),e+(r.translateY-this.translateY));this.unchangedObjectSnapshots.forEach((i=>{const r=i.translateY-this.translateY;i.translateX=t+(i.translateX-this.translateX),i.translateY=e+r})),this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this)}captureUnchangedSnapshots(t){this.unchangedObjectSnapshots.clear(),this.snapshotRotation=this.rotation,this.snapshotWidth=this.width,this.snapshotHeight=this.height,this.snapshotTranslateX=this.translateX,this.snapshotTranslateY=this.translateY,(t??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:r,totalHeight:s,unchangedObjectSnapshots:n,_cachedObjects:o,_cachedObjectIdsHash:h,snapshotWidth:l,snapshotHeight:a,snapshotTranslateX:u,snapshotTranslateY:c,snapshotRotation:f,...d}=this,p=structuredClone(d);return p.objectIds=this.objectIds,delete p._objectIds,i&&"object"==typeof i&&"nodeType"in i&&1===i.nodeType&&(p.element=i.cloneNode(!0)),p.unchangedObjectSnapshots=Object.fromEntries(this.unchangedObjectSnapshots),p}deserialize(t){return super.deserialize(t),t.objectIds&&(this.objectIds=t.objectIds),t.unchangedObjectSnapshots&&(this.unchangedObjectSnapshots=new Map(Object.entries(t.unchangedObjectSnapshots))),this}update(){this._core.store.state.objects.update(this)}move(t,e,i,r){const s=(t-i)/this._core.store.state.scale,n=(e-r)/this._core.store.state.scale;this.translateX+=s,this.translateY+=n,this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this);const s=this.objects;for(const n of s)n.move(t,e,i,r),this._core.anchorManager.updateAnchorsForObject(n.id)})),this.unchangedObjectSnapshots.forEach((t=>{t.translateX+=s,t.translateY+=n}))}resize(t,e,i,r){const s=i/this.snapshotWidth,n=r/this.snapshotHeight,o=this.snapshotTranslateX+(this.snapshotWidth+2*this.padding)/2/this.scale,h=this.snapshotTranslateY+(this.snapshotHeight+2*this.padding)/2/this.scale,l=t+(i+2*this.padding)/2/this.scale,a=e+(r+2*this.padding)/2/this.scale,u=this.rotation,c=Math.cos(-u),f=Math.sin(-u),d=Math.cos(u),p=Math.sin(u);this._core.store.state.objects.transaction((()=>{const t=this.objects;t.forEach((t=>{const e=this.unchangedObjectSnapshots.get(t.id);if(!e)return;const i=e.translateX+e.totalWidth/2/e.scale-o,r=e.translateY+e.totalHeight/2/e.scale-h,g=(i*c-r*f)*s,w=(i*f+r*c)*n,m=l+(g*d-w*p),v=a+(g*p+w*d),y=e.rotation-u,k=Math.cos(y),b=Math.sin(y),M=Math.sqrt(Math.pow(s*k,2)+Math.pow(n*b,2)),x=Math.sqrt(Math.pow(s*b,2)+Math.pow(n*k,2)),C=e.width*M,A=e.height*x;t.resize(m-(C+2*t.padding)/2/t.scale,v-(A+2*t.padding)/2/t.scale,C,A),this._core.anchorManager.updateAnchorsForObject(t.id)})),this.refreshObjectDimensions(t),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,r=t-this.snapshotRotation,s=Math.cos(r),n=Math.sin(r),o=this.objects;this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this);const h=o.length;for(const l of o){const o=this.unchangedObjectSnapshots.get(l.id);if(!o)continue;const a=this.getOffsetXToCenterFromSnapshot(o),u=this.getOffsetYToCenterFromSnapshot(o),c=n*a+s*u;l.translateX=e+(s*a-n*u)-l.totalWidth/2/l.scale,l.translateY=i+c-l.totalHeight/2/l.scale,l.rotate(1===h?t:o.rotation+r)}}))}copy(){const t=Qn.create(this._core),e=this.objects,i=[...e].sort(((t,e)=>t.zIndex-e.zIndex));for(const e of i){const i=e.copy();t.addOrRemove(i)}return t.captureUnchangedSnapshots(),1===e.length&&(t.rotation=e[0].rotation),t}refreshObjectDimensions(t,e=!1){const i=t??this.objects;if(1===i.length){const t=i[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),r=Math.sin(-t);let s=1/0,n=-1/0,o=1/0,h=-1/0;i.forEach((t=>{const i=t.rotatedPolygon;[i.topLeft,i.topRight,i.bottomRight,i.bottomLeft].forEach((t=>{const i=t.x*e-t.y*r,l=t.x*r+t.y*e;i<s&&(s=i),i>n&&(n=i),l<o&&(o=l),l>h&&(h=l)}))}));const l=h-o;this.width=(n-s-this.padding)*this.scale,this.height=(l-this.padding)*this.scale;const a=(s+n)/2,u=(o+h)/2,c=Math.cos(t),f=Math.sin(t),d=a*f+u*c;this.translateX=a*c-u*f-(this.width/this.scale+2*this.padding)/2,this.translateY=d-(this.height/this.scale+2*this.padding)/2}e||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){const i=this.objects;if(1===i.length&&"KritzelLine"===i[0].__class__)return i[0].hitTest(t,e);const r=this.rotatedPolygon;if(s.isPointInPolygon({x:t,y:e},[r.topLeft,r.topRight,r.bottomRight,r.bottomLeft]))return!0;for(const r of i)if(r.hitTest(t,e))return!0;return!1}}class Kn extends Vn{color=An[0];size=4;opacity=1;palette=[...An];arrows;_startX=0;_startY=0;_currentLineId=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&Wn.isLeftClick(t)){this._core.store.state.isDrawing=!0;const e=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?e:1,s=(t.clientX-this._core.store.offsetX)/r,n=(t.clientY-this._core.store.offsetY)/r;this._startX=s,this._startY=n;const o=_n.create(this._core,{startX:s,startY:n,endX:s,endY:n,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:i?1:e,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});o.isCompleted=!1,this._currentLineId=o.id,this._core.store.state.objects.insert(o),this._core.store.state.objects?.setActiveDrawingObject(o.id)}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const e=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,r=i?e:1,s=Math.round((t[0].clientX-this._core.store.offsetX)/r),n=Math.round((t[0].clientY-this._core.store.offsetY)/r);this._core.store.state.isDrawing=!0,this._startX=s,this._startY=n;const o=_n.create(this._core,{startX:s,startY:n,endX:s,endY:n,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:i?1:e,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});o.isCompleted=!1,this._currentLineId=o.id,this._core.store.state.objects.insert(o),this._core.store.state.objects?.setActiveDrawingObject(o.id)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&this._currentLineId){const e=this._core.store.state.objects.findById(this._currentLineId);if(e){const i=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,s=r?i:1,n=_n.create(this._core,{startX:this._startX,startY:this._startY,endX:(t.clientX-this._core.store.offsetX)/s,endY:(t.clientY-this._core.store.offsetY)/s,translateX:-this._core.store.state.translateX/s,translateY:-this._core.store.state.translateY/s,scale:r?1:i,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)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length&&this._currentLineId){const e=this._core.store.state.objects.findById(this._currentLineId);if(e){const i=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,s=r?i:1,n=Math.round((t[0].clientX-this._core.store.offsetX)/s),o=Math.round((t[0].clientY-this._core.store.offsetY)/s),h=_n.create(this._core,{startX:this._startX,startY:this._startY,endX:n,endY:o,translateX:-this._core.store.state.translateX/s,translateY:-this._core.store.state.translateY/s,scale:r?1:i,stroke:this.color,strokeWidth:this.size,opacity:this.opacity,arrows:this.arrows});h.id=e.id,h.workspaceId=e.workspaceId,h.zIndex=e.zIndex,h.isCompleted=!1,this._core.store.state.objects.update(h)}}}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentLineId)){const t=this._core.store.state.objects.findById(this._currentLineId);t&&(t.isCompleted=!0,this._core.store.state.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t]),this.selectLineAndSwitchTool(t)),this._core.store.state.objects?.setActiveDrawingObject(null),this._currentLineId=null}if(("touch"===t.pointerType||"pen"===t.pointerType)&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentLineId)){const t=this._core.store.state.objects.findById(this._currentLineId);t&&(t.isCompleted=!0,this._core.store.state.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t]),this.selectLineAndSwitchTool(t)),this._core.store.state.objects?.setActiveDrawingObject(null),this._currentLineId=null}}selectLineAndSwitchTool(t){const e=Qn.create(this._core);e.addOrRemove(t),e.isSelected=!0,e.rotation=t.rotation,this._core.addSelectionGroup(e),this._core.store.setState("activeTool",i.getTool("selection")),this._core.rerender()}}class qn extends Vn{touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&Wn.isLeftClick(t)&&(this._core.store.state.isErasing=!0),"touch"!==t.pointerType&&"pen"!==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,r=this._core.store.state.pointerY;e.forEach((t=>{t.markedForRemoval=t.hitTest(i,r)})),this._core.rerender()}if(("touch"===t.pointerType||"pen"===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 r=this._core.store.state.pointerX,s=this._core.store.state.pointerY;i.forEach((t=>{t.markedForRemoval=t.hitTest(r,s)})),this._core.rerender()}}handlePointerUp(t){if("mouse"===t.pointerType&&this._core.store.state.isErasing){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)})),t.length>0&&this._core.rerender(),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange(),t.length>0&&this._core.engine.emitObjectsRemoved(t)}if(("touch"===t.pointerType||"pen"===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(),t.length>0&&this._core.engine.emitObjectsRemoved(t)}}}function Gn(t,e){return new Promise((function(i,r){let s;return Zn(t).then((function(t){try{return s=t,i(new Blob([e.slice(0,2),s,e.slice(2)],{type:"image/jpeg"}))}catch(t){return r(t)}}),r)}))}const Zn=t=>new Promise(((e,i)=>{const r=new FileReader;r.addEventListener("load",(({target:{result:t}})=>{const r=new DataView(t);let s=0;if(65496!==r.getUint16(s))return i("not a valid JPEG");for(s+=2;;){const n=r.getUint16(s);if(65498===n)break;const o=r.getUint16(s+2);if(65505===n&&1165519206===r.getUint32(s+4)){const n=s+10;let h;switch(r.getUint16(n)){case 18761:h=!0;break;case 19789:h=!1;break;default:return i("TIFF header contains invalid endian")}if(42!==r.getUint16(n+2,h))return i("TIFF header contains invalid version");const l=r.getUint32(n+4,h),a=n+l+2+12*r.getUint16(n+l,h);for(let t=n+l+2;t<a;t+=12)if(274==r.getUint16(t,h)){if(3!==r.getUint16(t+2,h))return i("Orientation data type is invalid");if(1!==r.getUint32(t+4,h))return i("Orientation data count is invalid");r.setUint16(t+8,1,h);break}return e(t.slice(s,s+2+o))}s+=2+o}return e(new Blob)})),r.readAsArrayBuffer(t)}));var to={},eo={get exports(){return to},set exports(t){to=t}};!function(){var t,e,i={};eo.exports=i,i.parse=function(t,e){for(var r=i.bin.readUshort,s=i.bin.readUint,n=0,o={},h=new Uint8Array(t),l=h.length-4;101010256!=s(h,l);)l--;n=l,n+=4;var a=r(h,n+=4);r(h,n+=2);var u=s(h,n+=2),c=s(h,n+=4);n+=4,n=c;for(var f=0;f<a;f++){s(h,n),n+=4,n+=4,n+=4,s(h,n+=4),u=s(h,n+=4);var d=s(h,n+=4),p=r(h,n+=4),g=r(h,n+2),w=r(h,n+4);n+=6;var m=s(h,n+=8);n+=4,n+=p+g+w,i._readLocal(h,m,o,u,d,e)}return o},i._readLocal=function(t,e,r,s,n,o){var h=i.bin.readUshort,l=i.bin.readUint;l(t,e),h(t,e+=4),h(t,e+=2);var a=h(t,e+=2);l(t,e+=2),l(t,e+=4),e+=4;var u=h(t,e+=8),c=h(t,e+=2),f=i.bin.readUTF8(t,e+=2,u);if(e+=u,e+=c,o)r[f]={size:n,csize:s};else{var d=new Uint8Array(t.buffer,e);if(0==a)r[f]=new Uint8Array(d.buffer.slice(e,e+s));else{if(8!=a)throw"unknown compression method: "+a;var p=new Uint8Array(n);i.inflateRaw(d,p),r[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 r=0,s=new Uint8Array(50+Math.floor(1.1*t.length));s[r]=120,s[r+1]=156,r=i.F.deflateRaw(t,s,r+=2,e.level);var n=i.adler(t,0,t.length);return s[r+0]=n>>>24&255,s[r+1]=n>>>16&255,s[r+2]=n>>>8&255,s[r+3]=n>>>0&255,new Uint8Array(s.buffer,0,r+4)},i.deflateRaw=function(t,e){null==e&&(e={level:6});var r=new Uint8Array(50+Math.floor(1.1*t.length)),s=i.F.deflateRaw(t,r,s,e.level);return new Uint8Array(r.buffer,0,s)},i.encode=function(t,e){null==e&&(e=!1);var r=0,s=i.bin.writeUint,n=i.bin.writeUshort,o={};for(var h in t){var l=!i._noNeed(h)&&!e,a=t[h],u=i.crc.crc(a,0,a.length);o[h]={cpr:l,usize:a.length,crc:u,file:l?i.deflateRaw(a):a}}for(var h in o)r+=o[h].file.length+30+46+2*i.bin.sizeUTF8(h);r+=22;var c=new Uint8Array(r),f=0,d=[];for(var h in o){var p=o[h];d.push(f),f=i._writeHeader(c,f,h,p,0)}var g=0,w=f;for(var h in o)p=o[h],d.push(f),f=i._writeHeader(c,f,h,p,1,d[g++]);var m=f-w;return s(c,f,101010256),f+=4,n(c,f+=4,g),n(c,f+=2,g),s(c,f+=2,m),s(c,f+=4,w),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,r,s,n,o){var h=i.bin.writeUint,l=i.bin.writeUshort,a=s.file;return h(t,e,0==n?67324752:33639248),e+=4,1==n&&(e+=2),l(t,e,20),l(t,e+=2,0),l(t,e+=2,s.cpr?8:0),h(t,e+=2,0),h(t,e+=4,s.crc),h(t,e+=4,a.length),h(t,e+=4,s.usize),l(t,e+=4,i.bin.sizeUTF8(r)),l(t,e+=2,0),e+=2,1==n&&(e+=2,e+=2,h(t,e+=6,o),e+=4),e+=i.bin.writeUTF8(t,e,r),0==n&&(t.set(a,e),e+=a.length),e},i.crc={table:function(){for(var t=new Uint32Array(256),e=0;e<256;e++){for(var i=e,r=0;r<8;r++)1&i?i=3988292384^i>>>1:i>>>=1;t[e]=i}return t}(),update:function(t,e,r,s){for(var n=0;n<s;n++)t=i.crc.table[255&(t^e[r+n])]^t>>>8;return t},crc:function(t,e,r){return 4294967295^i.crc.update(4294967295,t,e,r)}},i.adler=function(t,e,i){for(var r=1,s=0,n=e,o=e+i;n<o;){for(var h=Math.min(n+5552,o);n<h;)s+=r+=t[n++];r%=65521,s%=65521}return s<<16|r},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 r="",s=0;s<i;s++)r+=String.fromCharCode(t[e+s]);return r},writeASCII:function(t,e,i){for(var r=0;r<i.length;r++)t[e+r]=i.charCodeAt(r)},pad:function(t){return t.length<2?"0"+t:t},readUTF8:function(t,e,r){for(var s,n="",o=0;o<r;o++)n+="%"+i.bin.pad(t[e+o].toString(16));try{s=decodeURIComponent(n)}catch(s){return i.bin.readASCII(t,e,r)}return s},writeUTF8:function(t,e,i){for(var r=i.length,s=0,n=0;n<r;n++){var o=i.charCodeAt(n);if(4294967168&o)if(4294965248&o)if(4294901760&o){if(4292870144&o)throw"e";t[e+s]=240|o>>18,t[e+s+1]=128|o>>12&63,t[e+s+2]=128|o>>6&63,t[e+s+3]=128|63&o,s+=4}else t[e+s]=224|o>>12,t[e+s+1]=128|o>>6&63,t[e+s+2]=128|63&o,s+=3;else t[e+s]=192|o>>6,t[e+s+1]=128|63&o,s+=2;else t[e+s]=o,s++}return s},sizeUTF8:function(t){for(var e=t.length,i=0,r=0;r<e;r++){var s=t.charCodeAt(r);if(4294967168&s)if(4294965248&s)if(4294901760&s){if(4292870144&s)throw"e";i+=4}else i+=3;else i+=2;else i++}return i}},i.F={},i.F.deflateRaw=function(t,e,r,s){var n=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]][s],o=i.F.U,h=i.F._goodIndex,l=i.F._putsE,a=0,u=r<<3,c=0,f=t.length;if(0==s){for(;a<f;)l(e,u,a+(C=Math.min(65535,f-a))==f?1:0),u=i.F._copyExact(t,a,C,e,u+8),a+=C;return u>>>3}var d=o.lits,p=o.strt,g=o.prev,w=0,m=0,v=0,y=0,k=0,b=0;for(f>2&&(p[b=i.F._hash(t,0)]=0),a=0;a<f;a++){if(k=b,a+1<f-2){b=i.F._hash(t,a+1);var M=a+1&32767;g[M]=p[b],p[b]=M}if(c<=a){(w>14e3||m>26697)&&f-a>100&&(c<a&&(d[w]=a-c,w+=2,c=a),u=i.F._writeBlock(a==f-1||c==f?1:0,d,w,y,t,v,a-v,e,u),w=m=y=0,v=a);var x=0;a<f-2&&(x=i.F._bestMatch(t,a,g,k,Math.min(n[2],f-a),n[3]));var C=x>>>16,A=65535&x;if(0!=x){A=65535&x;var S=h(C=x>>>16,o.of0);o.lhst[257+S]++;var B=h(A,o.df0);o.dhst[B]++,y+=o.exb[S]+o.dxb[B],d[w]=C<<23|a-c,d[w+1]=A<<16|S<<8|B,w+=2,c=a+C}else o.lhst[t[a]]++;m++}}for(v==a&&0!=t.length||(c<a&&(d[w]=a-c,w+=2,c=a),u=i.F._writeBlock(1,d,w,y,t,v,a-v,e,u),w=0,m=0,w=m=y=0,v=a);7&u;)u++;return u>>>3},i.F._bestMatch=function(t,e,r,s,n,o){var h=32767&e,l=r[h],a=h-l+32768&32767;if(l==h||s!=i.F._hash(t,e-a))return 0;for(var u=0,c=0,f=Math.min(32767,e);a<=f&&0!=--o&&l!=h;){if(0==u||t[e+u]==t[e+u-a]){var d=i.F._howLong(t,e,a);if(d>u){if(c=a,(u=d)>=n)break;a+2<d&&(d=a+2);for(var p=0,g=0;g<d-2;g++){var w=e-a+g+32768&32767,m=w-r[w]+32768&32767;m>p&&(p=m,l=w)}}}a+=(h=l)-(l=r[h])+32768&32767}return u<<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 r=e,s=Math.min(t.length,e+258);for(e+=3;e<s&&t[e]==t[e-i];)e++;return e-r},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,r,s,n,o,h,l,a){var u,c,f,d,p,g,w,m,v,y=i.F.U,k=i.F._putsF,b=i.F._putsE;y.lhst[256]++,c=(u=i.F.getTrees())[0],f=u[1],d=u[2],p=u[3],g=u[4],w=u[5],m=u[6],v=u[7];var M=32+(a+3&7?8-(a+3&7):0)+(h<<3),x=s+i.F.contSize(y.fltree,y.lhst)+i.F.contSize(y.fdtree,y.dhst),C=s+i.F.contSize(y.ltree,y.lhst)+i.F.contSize(y.dtree,y.dhst);C+=14+3*w+i.F.contSize(y.itree,y.ihst)+(2*y.ihst[16]+3*y.ihst[17]+7*y.ihst[18]);for(var A=0;A<286;A++)y.lhst[A]=0;for(A=0;A<30;A++)y.dhst[A]=0;for(A=0;A<19;A++)y.ihst[A]=0;var S=M<x&&M<C?0:x<C?1:2;if(k(l,a,t),k(l,a+1,S),a+=3,0==S){for(;7&a;)a++;a=i.F._copyExact(n,o,h,l,a)}else{var B,T;if(1==S&&(B=y.fltree,T=y.fdtree),2==S){i.F.makeCodes(y.ltree,c),i.F.revCodes(y.ltree,c),i.F.makeCodes(y.dtree,f),i.F.revCodes(y.dtree,f),i.F.makeCodes(y.itree,d),i.F.revCodes(y.itree,d),B=y.ltree,T=y.dtree,b(l,a,p-257),b(l,a+=5,g-1),b(l,a+=5,w-4),a+=4;for(var O=0;O<w;O++)b(l,a+3*O,y.itree[1+(y.ordr[O]<<1)]);a=i.F._codeTiny(m,y.itree,l,a+=3*w),a=i.F._codeTiny(v,y.itree,l,a)}for(var E=o,I=0;I<r;I+=2){for(var D=e[I],P=D>>>23,$=E+(8388607&D);E<$;)a=i.F._writeLit(n[E++],B,l,a);if(0!=P){var R=e[I+1],j=R>>16,F=R>>8&255,N=255&R;b(l,a=i.F._writeLit(257+F,B,l,a),P-y.of0[F]),k(l,a=i.F._writeLit(N,T,l,a+=y.exb[F]),j-y.df0[N]),a+=y.dxb[N],E+=P}}a=i.F._writeLit(256,B,l,a)}return a},i.F._copyExact=function(t,e,i,r,s){var n=s>>>3;return r[n]=i,r[n+1]=i>>>8,r[n+2]=255-r[n],r[n+3]=255-r[n+1],n+=4,r.set(new Uint8Array(t.buffer,e,i),n),s+(i+4<<3)},i.F.getTrees=function(){for(var t=i.F.U,e=i.F._hufTree(t.lhst,t.ltree,15),r=i.F._hufTree(t.dhst,t.dtree,15),s=[],n=i.F._lenCodes(t.ltree,s),o=[],h=i.F._lenCodes(t.dtree,o),l=0;l<s.length;l+=2)t.ihst[s[l]]++;for(l=0;l<o.length;l+=2)t.ihst[o[l]]++;for(var a=i.F._hufTree(t.ihst,t.itree,7),u=19;u>4&&0==t.itree[1+(t.ordr[u-1]<<1)];)u--;return[e,r,a,n,h,u,s,o]},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,r=0;r<e.length;r++)i+=e[r]*t[1+(r<<1)];return i},i.F._codeTiny=function(t,e,r,s){for(var n=0;n<t.length;n+=2){var o=t[n],h=t[n+1];s=i.F._writeLit(o,e,r,s);var l=16==o?2:17==o?3:7;o>15&&(i.F._putsE(r,s,h,l),s+=l)}return s},i.F._lenCodes=function(t,e){for(var i=t.length;2!=i&&0==t[i-1];)i-=2;for(var r=0;r<i;r+=2){var s=t[r+1],n=r+3<i?t[r+3]:-1,o=r+5<i?t[r+5]:-1,h=0==r?-1:t[r-1];if(0==s&&n==s&&o==s){for(var l=r+5;l+2<i&&t[l+2]==s;)l+=2;(a=Math.min(l+1-r>>>1,138))<11?e.push(17,a-3):e.push(18,a-11),r+=2*a-2}else if(s==h&&n==s&&o==s){for(l=r+5;l+2<i&&t[l+2]==s;)l+=2;var a=Math.min(l+1-r>>>1,6);e.push(16,a-3),r+=2*a-2}else e.push(s,0)}return i>>>1},i.F._hufTree=function(t,e,r){var s=[],n=t.length,o=e.length,h=0;for(h=0;h<o;h+=2)e[h]=0,e[h+1]=0;for(h=0;h<n;h++)0!=t[h]&&s.push({lit:h,f:t[h]});var l=s.length,a=s.slice(0);if(0==l)return 0;if(1==l){var u=s[0].lit;return a=0==u?1:0,e[1+(u<<1)]=1,e[1+(a<<1)]=1,1}s.sort((function(t,e){return t.f-e.f}));var c=s[0],f=s[1],d=0,p=1,g=2;for(s[0]={lit:-1,f:c.f+f.f,l:c,r:f,d:0};p!=l-1;)c=d!=p&&(g==l||s[d].f<s[g].f)?s[d++]:s[g++],f=d!=p&&(g==l||s[d].f<s[g].f)?s[d++]:s[g++],s[p++]={lit:-1,f:c.f+f.f,l:c,r:f};var w=i.F.setDepth(s[p-1],0);for(w>r&&(i.F.restrictDepth(a,r,w),w=r),h=0;h<l;h++)e[1+(a[h].lit<<1)]=a[h].d;return w},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 r=0,s=1<<i-e,n=0;for(t.sort((function(t,e){return e.d==t.d?t.f-e.f:e.d-t.d})),r=0;r<t.length&&t[r].d>e;r++){var o=t[r].d;t[r].d=e,n+=s-(1<<i-o)}for(n>>>=i-e;n>0;)(o=t[r].d)<e?(t[r].d++,n-=1<<e-o-1):r++;for(;r>=0;r--)t[r].d==e&&n<0&&(t[r].d--,n++);0!=n&&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,r,s){return i.F._putsF(r,s,e[t<<1]),s+e[1+(t<<1)]},i.F.inflate=function(t,e){var r=Uint8Array;if(3==t[0]&&0==t[1])return e||new r(0);var s=i.F,n=s._bitsF,o=s._bitsE,h=s._decodeTiny,l=s.makeCodes,a=s.codes2map,u=s._get17,c=s.U,f=null==e;f&&(e=new r(t.length>>>2<<3));for(var d,p,g=0,w=0,m=0,v=0,y=0,k=0,b=0,M=0,x=0;0==g;)if(g=n(t,x,1),w=n(t,x+1,2),x+=3,0!=w){if(f&&(e=i.F._check(e,M+(1<<17))),1==w&&(d=c.flmap,p=c.fdmap,k=511,b=31),2==w){m=o(t,x,5)+257,v=o(t,x+5,5)+1,y=o(t,x+10,4)+4,x+=14;for(var C=0;C<38;C+=2)c.itree[C]=0,c.itree[C+1]=0;var A=1;for(C=0;C<y;C++){var S=o(t,x+3*C,3);c.itree[1+(c.ordr[C]<<1)]=S,S>A&&(A=S)}x+=3*y,l(c.itree,A),a(c.itree,A,c.imap),d=c.lmap,p=c.dmap,x=h(c.imap,(1<<A)-1,m+v,t,x,c.ttree);var B=s._copyOut(c.ttree,0,m,c.ltree);k=(1<<B)-1;var T=s._copyOut(c.ttree,m,v,c.dtree);b=(1<<T)-1,l(c.ltree,B),a(c.ltree,B,d),l(c.dtree,T),a(c.dtree,T,p)}for(;;){var O=d[u(t,x)&k];x+=15&O;var E=O>>>4;if(E>>>8==0)e[M++]=E;else{if(256==E)break;var I=M+E-254;if(E>264){var D=c.ldef[E-257];I=M+(D>>>3)+o(t,x,7&D),x+=7&D}var P=p[u(t,x)&b],$=c.ddef[P>>>4],R=($>>>4)+n(t,x+=15&P,15&$);for(x+=15&$,f&&(e=i.F._check(e,M+(1<<17)));M<I;)e[M]=e[M++-R],e[M]=e[M++-R],e[M]=e[M++-R],e[M]=e[M++-R];M=I}}}else{7&x&&(x+=8-(7&x));var j=4+(x>>>3),F=t[j-4]|t[j-3]<<8;f&&(e=i.F._check(e,M+F)),e.set(new r(t.buffer,t.byteOffset+j,F),M),x=j+F<<3,M+=F}return e.length==M?e:e.slice(0,M)},i.F._check=function(t,e){var i=t.length;if(e<=i)return t;var r=new Uint8Array(Math.max(i<<1,e));return r.set(t,0),r},i.F._decodeTiny=function(t,e,r,s,n,o){for(var h=i.F._bitsE,l=i.F._get17,a=0;a<r;){var u=t[l(s,n)&e];n+=15&u;var c=u>>>4;if(c<=15)o[a]=c,a++;else{var f=0,d=0;16==c?(d=3+h(s,n,2),n+=2,f=o[a-1]):17==c?(d=3+h(s,n,3),n+=3):18==c&&(d=11+h(s,n,7),n+=7);for(var p=a+d;a<p;)o[a]=f,a++}}return n},i.F._copyOut=function(t,e,i,r){for(var s=0,n=0,o=r.length>>>1;n<i;){var h=t[n+e];r[n<<1]=0,r[1+(n<<1)]=h,h>s&&(s=h),n++}for(;n<o;)r[n<<1]=0,r[1+(n<<1)]=0,n++;return s},i.F.makeCodes=function(t,e){for(var r,s,n,o,h=i.F.U,l=t.length,a=h.bl_count,u=0;u<=e;u++)a[u]=0;for(u=1;u<l;u+=2)a[t[u]]++;var c=h.next_code;for(r=0,a[0]=0,s=1;s<=e;s++)c[s]=r=r+a[s-1]<<1;for(n=0;n<l;n+=2)0!=(o=t[n+1])&&(t[n]=c[o],c[o]++)},i.F.codes2map=function(t,e,r){for(var s=t.length,n=i.F.U.rev15,o=0;o<s;o+=2)if(0!=t[o+1])for(var h=t[o+1],l=o>>1<<4|h,a=e-h,u=t[o]<<a,c=u+(1<<a);u!=c;)r[n[u]>>>15-e]=l,u++},i.F.revCodes=function(t,e){for(var r=i.F.U.rev15,s=15-e,n=0;n<t.length;n+=2)t[n]=r[t[n]<<e-t[n+1]]>>>s},i.F._putsE=function(t,e,i){var r=e>>>3;t[r]|=i<<=7&e,t[r+1]|=i>>>8},i.F._putsF=function(t,e,i){var r=e>>>3;t[r]|=i<<=7&e,t[r+1]|=i>>>8,t[r+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 r=e;r=(4278255360&(r=(4042322160&(r=(3435973836&(r=(2863311530&r)>>>1|(1431655765&r)<<1))>>>2|(858993459&r)<<2))>>>4|(252645135&r)<<4))>>>8|(16711935&r)<<8,t.rev15[e]=(r>>>16|r<<16)>>>17}function s(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];s(t.fltree,144,8),s(t.fltree,112,9),s(t.fltree,24,7),s(t.fltree,8,8),i.F.makeCodes(t.fltree,9),i.F.codes2map(t.fltree,9,t.flmap),i.F.revCodes(t.fltree,9),s(t.fdtree,32,5),i.F.makeCodes(t.fdtree,5),i.F.codes2map(t.fdtree,5,t.fdmap),i.F.revCodes(t.fdtree,5),s(t.itree,19,0),s(t.ltree,286,0),s(t.dtree,30,0),s(t.ttree,320,0)}()}();var io=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 r=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,r.get?r:{enumerable:!0,get:function(){return e[i]}})}}))})),Object.freeze(t)}({__proto__:null,default:to},[to]);const ro=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 r="";for(let s=0;s<i;s++)r+=String.fromCharCode(t[e+s]);return r},writeASCII(t,e,i){for(let r=0;r<i.length;r++)t[e+r]=i.charCodeAt(r)},readBytes(t,e,i){const r=[];for(let s=0;s<i;s++)r.push(t[e+s]);return r},pad:t=>t.length<2?`0${t}`:t,readUTF8(e,i,r){let s,n="";for(let s=0;s<r;s++)n+=`%${t.pad(e[i+s].toString(16))}`;try{s=decodeURIComponent(n)}catch(s){return t.readASCII(e,i,r)}return s}};function e(e,i,r,s){const o=i*r,h=n(s),l=Math.ceil(i*h/8),a=new Uint8Array(4*o),u=new Uint32Array(a.buffer),{ctype:c}=s,{depth:f}=s,d=t.readUshort;if(6==c){const t=o<<2;if(8==f)for(var p=0;p<t;p+=4)a[p]=e[p],a[p+1]=e[p+1],a[p+2]=e[p+2],a[p+3]=e[p+3];if(16==f)for(p=0;p<t;p++)a[p]=e[p<<1]}else if(2==c){const t=s.tabs.tRNS;if(null==t){if(8==f)for(p=0;p<o;p++){var g=3*p;u[p]=255<<24|e[g+2]<<16|e[g+1]<<8|e[g]}if(16==f)for(p=0;p<o;p++)u[p]=255<<24|e[4+(g=6*p)]<<16|e[g+2]<<8|e[g]}else{var w=t[0];const i=t[1],r=t[2];if(8==f)for(p=0;p<o;p++){var m=p<<2;u[p]=255<<24|e[2+(g=3*p)]<<16|e[g+1]<<8|e[g],e[g]==w&&e[g+1]==i&&e[g+2]==r&&(a[m+3]=0)}if(16==f)for(p=0;p<o;p++)m=p<<2,u[p]=255<<24|e[4+(g=6*p)]<<16|e[g+2]<<8|e[g],d(e,g)==w&&d(e,g+2)==i&&d(e,g+4)==r&&(a[m+3]=0)}}else if(3==c){const t=s.tabs.PLTE,n=s.tabs.tRNS,h=n?n.length:0;if(1==f)for(var v=0;v<r;v++){var y=v*l,k=v*i;for(p=0;p<i;p++){var b=3*(M=e[y+(p>>3)]>>7-(7&p)&1);a[m=k+p<<2]=t[b],a[m+1]=t[b+1],a[m+2]=t[b+2],a[m+3]=M<h?n[M]:255}}if(2==f)for(v=0;v<r;v++)for(y=v*l,k=v*i,p=0;p<i;p++)b=3*(M=e[y+(p>>2)]>>6-((3&p)<<1)&3),a[m=k+p<<2]=t[b],a[m+1]=t[b+1],a[m+2]=t[b+2],a[m+3]=M<h?n[M]:255;if(4==f)for(v=0;v<r;v++)for(y=v*l,k=v*i,p=0;p<i;p++)b=3*(M=e[y+(p>>1)]>>4-((1&p)<<2)&15),a[m=k+p<<2]=t[b],a[m+1]=t[b+1],a[m+2]=t[b+2],a[m+3]=M<h?n[M]:255;if(8==f)for(p=0;p<o;p++){var M;b=3*(M=e[p]),a[m=p<<2]=t[b],a[m+1]=t[b+1],a[m+2]=t[b+2],a[m+3]=M<h?n[M]:255}}else if(4==c){if(8==f)for(p=0;p<o;p++){var x=e[C=p<<1];a[m=p<<2]=x,a[m+1]=x,a[m+2]=x,a[m+3]=e[C+1]}if(16==f)for(p=0;p<o;p++){var C;x=e[C=p<<2],a[m=p<<2]=x,a[m+1]=x,a[m+2]=x,a[m+3]=e[C+2]}}else if(0==c)for(w=s.tabs.tRNS?s.tabs.tRNS:-1,v=0;v<r;v++){const t=v*l,r=v*i;if(1==f)for(var A=0;A<i;A++){var S=(x=255*(e[t+(A>>>3)]>>>7-(7&A)&1))==255*w?0:255;u[r+A]=S<<24|x<<16|x<<8|x}else if(2==f)for(A=0;A<i;A++)S=(x=85*(e[t+(A>>>2)]>>>6-((3&A)<<1)&3))==85*w?0:255,u[r+A]=S<<24|x<<16|x<<8|x;else if(4==f)for(A=0;A<i;A++)S=(x=17*(e[t+(A>>>1)]>>>4-((1&A)<<2)&15))==17*w?0:255,u[r+A]=S<<24|x<<16|x<<8|x;else if(8==f)for(A=0;A<i;A++)S=(x=e[t+A])==w?0:255,u[r+A]=S<<24|x<<16|x<<8|x;else if(16==f)for(A=0;A<i;A++)x=e[t+(A<<1)],S=d(e,t+(A<<1))==w?0:255,u[r+A]=S<<24|x<<16|x<<8|x}return a}function i(t,e,i,h){const l=n(t),a=Math.ceil(i*l/8),u=new Uint8Array((a+1+t.interlace)*h);return e=t.tabs.CgBI?s(e,u):r(e,u),0==t.interlace?e=o(e,t,0,i,h):1==t.interlace&&(e=function(t,e){const i=e.width,r=e.height,s=n(e),h=s>>3,l=Math.ceil(i*s/8),a=new Uint8Array(r*l);let u=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 g=0;for(;g<7;){const n=d[g],m=p[g];let v=0,y=0,k=c[g];for(;k<r;)k+=n,y++;let b=f[g];for(;b<i;)b+=m,v++;const M=Math.ceil(v*s/8);o(t,e,u,v,y);let x=0,C=c[g];for(;C<r;){let e=f[g],r=u+x*M<<3;for(;e<i;){var w;if(1==s&&(w=(w=t[r>>3])>>7-(7&r)&1,a[C*l+(e>>3)]|=w<<7-(7&e)),2==s&&(w=(w=t[r>>3])>>6-(7&r)&3,a[C*l+(e>>2)]|=w<<6-((3&e)<<1)),4==s&&(w=(w=t[r>>3])>>4-(7&r)&15,a[C*l+(e>>1)]|=w<<4-((1&e)<<2)),s>=8){const i=C*l+e*h;for(let e=0;e<h;e++)a[i+e]=t[(r>>3)+e]}r+=s,e+=m}x++,C+=n}v*y!=0&&(u+=y*(1+M)),g+=1}return a}(e,t)),e}function r(t,e){return s(new Uint8Array(t.buffer,2,t.length-6),e)}var s=function(){const t={H:{}};return t.H.N=function(e,i){const r=Uint8Array;let s,n,o=0,h=0,l=0,a=0,u=0,c=0,f=0,d=0,p=0;if(3==e[0]&&0==e[1])return i||new r(0);const g=t.H,w=g.b,m=g.e,v=g.R,y=g.n,k=g.A,b=g.Z,M=g.m,x=null==i;for(x&&(i=new r(e.length>>>2<<5));0==o;)if(o=w(e,p,1),h=w(e,p+1,2),p+=3,0!=h){if(x&&(i=t.H.W(i,d+(1<<17))),1==h&&(s=M.J,n=M.h,c=511,f=31),2==h){l=m(e,p,5)+257,a=m(e,p+5,5)+1,u=m(e,p+10,4)+4,p+=14;let t=1;for(var C=0;C<38;C+=2)M.Q[C]=0,M.Q[C+1]=0;for(C=0;C<u;C++){const i=m(e,p+3*C,3);M.Q[1+(M.X[C]<<1)]=i,i>t&&(t=i)}p+=3*u,y(M.Q,t),k(M.Q,t,M.u),s=M.w,n=M.d,p=v(M.u,(1<<t)-1,l+a,e,p,M.v);const i=g.V(M.v,0,l,M.C);c=(1<<i)-1;const r=g.V(M.v,l,a,M.D);f=(1<<r)-1,y(M.C,i),k(M.C,i,s),y(M.D,r),k(M.D,r,n)}for(;;){const t=s[b(e,p)&c];p+=15&t;const r=t>>>4;if(r>>>8==0)i[d++]=r;else{if(256==r)break;{let t=d+r-254;if(r>264){const i=M.q[r-257];t=d+(i>>>3)+m(e,p,7&i),p+=7&i}const s=n[b(e,p)&f];p+=15&s;const o=M.c[s>>>4],h=(o>>>4)+w(e,p,15&o);for(p+=15&o;d<t;)i[d]=i[d++-h],i[d]=i[d++-h],i[d]=i[d++-h],i[d]=i[d++-h];d=t}}}}else{7&p&&(p+=8-(7&p));const s=4+(p>>>3),n=e[s-4]|e[s-3]<<8;x&&(i=t.H.W(i,d+n)),i.set(new r(e.buffer,e.byteOffset+s,n),d),p=s+n<<3,d+=n}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 r=new Uint8Array(i<<1);return r.set(t,0),r},t.H.R=function(e,i,r,s,n,o){const h=t.H.e,l=t.H.Z;let a=0;for(;a<r;){const t=e[l(s,n)&i];n+=15&t;const r=t>>>4;if(r<=15)o[a]=r,a++;else{let t=0,e=0;16==r?(e=3+h(s,n,2),n+=2,t=o[a-1]):17==r?(e=3+h(s,n,3),n+=3):18==r&&(e=11+h(s,n,7),n+=7);const i=a+e;for(;a<i;)o[a]=t,a++}}return n},t.H.V=function(t,e,i,r){let s=0,n=0;const o=r.length>>>1;for(;n<i;){const i=t[n+e];r[n<<1]=0,r[1+(n<<1)]=i,i>s&&(s=i),n++}for(;n<o;)r[n<<1]=0,r[1+(n<<1)]=0,n++;return s},t.H.n=function(e,i){const r=t.H.m,s=e.length;let n,o,h,l;const a=r.j;for(var u=0;u<=i;u++)a[u]=0;for(u=1;u<s;u+=2)a[e[u]]++;const c=r.K;for(n=0,a[0]=0,o=1;o<=i;o++)n=n+a[o-1]<<1,c[o]=n;for(h=0;h<s;h+=2)l=e[h+1],0!=l&&(e[h]=c[l],c[l]++)},t.H.A=function(e,i,r){const s=e.length,n=t.H.m.r;for(let t=0;t<s;t+=2)if(0!=e[t+1]){const s=e[t+1],o=t>>1<<4|s,h=i-s;let l=e[t]<<h;const a=l+(1<<h);for(;l!=a;)r[n[l]>>>15-i]=o,l++}},t.H.l=function(e,i){const r=t.H.m.r,s=15-i;for(let t=0;t<e.length;t+=2)e[t]=r[e[t]<<i-e[t+1]]>>>s},t.H.M=function(t,e,i){const r=e>>>3;t[r]|=i<<=7&e,t[r+1]|=i>>>8},t.H.I=function(t,e,i){const r=e>>>3;t[r]|=i<<=7&e,t[r+1]|=i>>>8,t[r+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 r(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];r(e._,144,8),r(e._,112,9),r(e._,24,7),r(e._,8,8),t.H.n(e._,9),t.H.A(e._,9,e.J),t.H.l(e._,9),r(e.$,32,5),t.H.n(e.$,5),t.H.A(e.$,5,e.h),t.H.l(e.$,5),r(e.Q,19,0),r(e.C,286,0),r(e.D,30,0),r(e.v,320,0)}(),t.H.N}();function n(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function o(t,e,i,r,s){let o=n(e);const l=Math.ceil(r*o/8);let a,u;o=Math.ceil(o/8);let c=t[i],f=0;if(c>1&&(t[i]=[0,0,1][c-2]),3==c)for(f=o;f<l;f++)t[f+1]=t[f+1]+(t[f+1-o]>>>1)&255;for(let e=0;e<s;e++)if(a=i+e*l,u=a+e+1,c=t[u-1],f=0,0==c)for(;f<l;f++)t[a+f]=t[u+f];else if(1==c){for(;f<o;f++)t[a+f]=t[u+f];for(;f<l;f++)t[a+f]=t[u+f]+t[a+f-o]}else if(2==c)for(;f<l;f++)t[a+f]=t[u+f]+t[a+f-l];else if(3==c){for(;f<o;f++)t[a+f]=t[u+f]+(t[a+f-l]>>>1);for(;f<l;f++)t[a+f]=t[u+f]+(t[a+f-l]+t[a+f-o]>>>1)}else{for(;f<o;f++)t[a+f]=t[u+f]+h(0,t[a+f-l],0);for(;f<l;f++)t[a+f]=t[u+f]+h(t[a+f-o],t[a+f-l],t[a+f-o-l])}return t}function h(t,e,i){const r=t+e-i,s=r-t,n=r-e,o=r-i;return s*s<=n*n&&s*s<=o*o?t:n*n<=o*o?e:i}function l(e,i,r){r.width=t.readUint(e,i),r.height=t.readUint(e,i+=4),r.depth=e[i+=4],i++,r.ctype=e[i],i++,r.compress=e[i],i++,r.filter=e[i],i++,r.interlace=e[i],i++}function a(t,e,i,r,s,n,o,h,l){const a=Math.min(e,s),u=Math.min(i,n);let c=0,f=0;for(let i=0;i<u;i++)for(let n=0;n<a;n++)if(o>=0&&h>=0?(c=i*e+n<<2,f=(h+i)*s+o+n<<2):(c=(-h+i)*e-o+n<<2,f=i*s+n<<2),0==l)r[f]=t[c],r[f+1]=t[c+1],r[f+2]=t[c+2],r[f+3]=t[c+3];else if(1==l){var d=t[c+3]*(1/255),p=t[c]*d,g=t[c+1]*d,w=t[c+2]*d,m=r[f+3]*(1/255),v=r[f]*m,y=r[f+1]*m,k=r[f+2]*m;const e=1-d,i=d+m*e,s=0==i?0:1/i;r[f+3]=255*i,r[f+0]=(p+v*e)*s,r[f+1]=(g+y*e)*s,r[f+2]=(w+k*e)*s}else if(2==l)p=t[c],g=t[c+1],w=t[c+2],v=r[f],y=r[f+1],k=r[f+2],(d=t[c+3])==(m=r[f+3])&&p==v&&g==y&&w==k?(r[f]=0,r[f+1]=0,r[f+2]=0,r[f+3]=0):(r[f]=p,r[f+1]=g,r[f+2]=w,r[f+3]=d);else if(3==l){if(p=t[c],g=t[c+1],w=t[c+2],v=r[f],y=r[f+1],k=r[f+2],(d=t[c+3])==(m=r[f+3])&&p==v&&g==y&&w==k)continue;if(d<220&&m>20)return!1}return!0}return{decode:function(e){const n=new Uint8Array(e);let o=8;const h=t,a=h.readUshort,u=h.readUint,c={tabs:{},frames:[]},f=new Uint8Array(n.length);let d,p=0,g=0;const w=[137,80,78,71,13,10,26,10];for(var m=0;m<8;m++)if(n[m]!=w[m])throw"The input is not a PNG file!";for(;o<n.length;){const t=h.readUint(n,o);o+=4;const e=h.readASCII(n,o,4);if(o+=4,"IHDR"==e)l(n,o,c);else if("iCCP"==e){for(var v=o;0!=n[v];)v++;h.readASCII(n,o,v-o);const i=n.slice(v+2,o+t);let l=null;try{l=r(i)}catch(t){l=s(i)}c.tabs[e]=l}else if("CgBI"==e)c.tabs[e]=n.slice(o,o+4);else if("IDAT"==e){for(m=0;m<t;m++)f[p+m]=n[o+m];p+=t}else if("acTL"==e)c.tabs[e]={num_frames:u(n,o),num_plays:u(n,o+4)},d=new Uint8Array(n.length);else if("fcTL"==e){0!=g&&((C=c.frames[c.frames.length-1]).data=i(c,d.slice(0,g),C.rect.width,C.rect.height),g=0);const t={x:u(n,o+12),y:u(n,o+16),width:u(n,o+4),height:u(n,o+8)};let e=a(n,o+22);e=a(n,o+20)/(0==e?100:e);const r={rect:t,delay:Math.round(1e3*e),dispose:n[o+24],blend:n[o+25]};c.frames.push(r)}else if("fdAT"==e){for(m=0;m<t-4;m++)d[g+m]=n[o+m+4];g+=t-4}else if("pHYs"==e)c.tabs[e]=[h.readUint(n,o),h.readUint(n,o+4),n[o+8]];else if("cHRM"==e)for(c.tabs[e]=[],m=0;m<8;m++)c.tabs[e].push(h.readUint(n,o+4*m));else if("tEXt"==e||"zTXt"==e){null==c.tabs[e]&&(c.tabs[e]={});var y=h.nextZero(n,o),k=h.readASCII(n,o,y-o),b=o+t-y-1;if("tEXt"==e)x=h.readASCII(n,y+1,b);else{var M=r(n.slice(y+2,y+2+b));x=h.readUTF8(M,0,M.length)}c.tabs[e][k]=x}else if("iTXt"==e){null==c.tabs[e]&&(c.tabs[e]={}),y=0,y=h.nextZero(n,v=o),k=h.readASCII(n,v,y-v);const i=n[v=y+1];var x;y=h.nextZero(n,v+=2),h.readASCII(n,v,y-v),y=h.nextZero(n,v=y+1),h.readUTF8(n,v,y-v),b=t-((v=y+1)-o),0==i?x=h.readUTF8(n,v,b):(M=r(n.slice(v,v+b)),x=h.readUTF8(M,0,M.length)),c.tabs[e][k]=x}else if("PLTE"==e)c.tabs[e]=h.readBytes(n,o,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(a(n,o+2*m))}else if("tRNS"==e)3==c.ctype?c.tabs[e]=h.readBytes(n,o,t):0==c.ctype?c.tabs[e]=a(n,o):2==c.ctype&&(c.tabs[e]=[a(n,o),a(n,o+2),a(n,o+4)]);else if("gAMA"==e)c.tabs[e]=h.readUint(n,o)/1e5;else if("sRGB"==e)c.tabs[e]=n[o];else if("bKGD"==e)0==c.ctype||4==c.ctype?c.tabs[e]=[a(n,o)]:2==c.ctype||6==c.ctype?c.tabs[e]=[a(n,o),a(n,o+2),a(n,o+4)]:3==c.ctype&&(c.tabs[e]=n[o]);else if("IEND"==e)break;o+=t,h.readUint(n,o),o+=4}var C;return 0!=g&&((C=c.frames[c.frames.length-1]).data=i(c,d.slice(0,g),C.rect.width,C.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,r=t.height;if(null==t.tabs.acTL)return[e(t.data,i,r,t).buffer];const s=[];null==t.frames[0].data&&(t.frames[0].data=t.data);const n=i*r*4,o=new Uint8Array(n),h=new Uint8Array(n),l=new Uint8Array(n);for(let c=0;c<t.frames.length;c++){const f=t.frames[c],d=f.rect.x,p=f.rect.y,g=f.rect.width,w=f.rect.height,m=e(f.data,g,w,t);if(0!=c)for(var u=0;u<n;u++)l[u]=o[u];if(0==f.blend?a(m,g,w,o,i,r,d,p,0):1==f.blend&&a(m,g,w,o,i,r,d,p,1),s.push(o.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)a(h,g,w,o,i,r,d,p,0);else if(2==f.dispose)for(u=0;u<n;u++)o[u]=l[u]}return s},_paeth:h,_copyTile:a,_bin:t}}();!function(){const{_copyTile:t}=ro,{_bin:e}=ro,i=ro._paeth;var r={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,s){for(let n=0;n<s;n++)t=r.table[255&(t^e[i+n])]^t>>>8;return t},crc:(t,e,i)=>4294967295^r.update(4294967295,t,e,i)};function s(t,e,i,r){e[i]+=t[0]*r>>4,e[i+1]+=t[1]*r>>4,e[i+2]+=t[2]*r>>4,e[i+3]+=t[3]*r>>4}function n(t){return Math.max(0,Math.min(255,t))}function o(t,e){const i=t[0]-e[0],r=t[1]-e[1],s=t[2]-e[2],n=t[3]-e[3];return i*i+r*r+s*s+n*n}function h(t,e,i,r,h,l,a){null==a&&(a=1);const u=r.length,c=[];for(var f=0;f<u;f++){const t=r[f];c.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(f=0;f<u;f++){let t=4294967295;for(var d=0,p=0;p<u;p++){var g=o(c[f],c[p]);p!=f&&g<t&&(t=g,d=p)}}const w=new Uint32Array(h.buffer),m=new Int16Array(e*i*4),v=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(f=0;f<v.length;f++)v[f]=255*((v[f]+.5)/16-.5);for(let h=0;h<i;h++)for(let k=0;k<e;k++){var y;f=4*(h*e+k),y=2!=a?[n(t[f]+m[f]),n(t[f+1]+m[f+1]),n(t[f+2]+m[f+2]),n(t[f+3]+m[f+3])]:[n(t[f]+(g=v[4*(3&h)+(3&k)])),n(t[f+1]+g),n(t[f+2]+g),n(t[f+3]+g)],d=0;let b=16777215;for(p=0;p<u;p++){const t=o(y,c[p]);t<b&&(b=t,d=p)}const M=c[d],x=[y[0]-M[0],y[1]-M[1],y[2]-M[2],y[3]-M[3]];1==a&&(k!=e-1&&s(x,m,f+4,7),h!=i-1&&(0!=k&&s(x,m,f+4*e-4,3),s(x,m,f+4*e,5),k!=e-1&&s(x,m,f+4*e+4,1))),l[f>>2]=d,w[f>>2]=r[d]}}function l(t,i,s,n,o){null==o&&(o={});const{crc:h}=r,l=e.writeUint,a=e.writeUshort,u=e.writeASCII;let c=8;const f=t.frames.length>1;let d,p=!1,g=33+(f?20:0);if(null!=o.sRGB&&(g+=13),null!=o.pHYs&&(g+=21),null!=o.iCCP&&(d=pako.deflate(o.iCCP),g+=21+d.length+4),3==t.ctype){for(var w=t.plte.length,m=0;m<w;m++)t.plte[m]>>>24!=255&&(p=!0);g+=8+3*w+4+(p?8+1*w+4:0)}for(var v=0;v<t.frames.length;v++)f&&(g+=38),g+=(M=t.frames[v]).cimg.length+12,0!=v&&(g+=4);g+=12;const y=new Uint8Array(g),k=[137,80,78,71,13,10,26,10];for(m=0;m<8;m++)y[m]=k[m];if(l(y,c,13),c+=4,u(y,c,"IHDR"),c+=4,l(y,c,i),c+=4,l(y,c,s),c+=4,y[c]=t.depth,c++,y[c]=t.ctype,c++,y[c]=0,c++,y[c]=0,c++,y[c]=0,c++,l(y,c,h(y,c-17,17)),c+=4,null!=o.sRGB&&(l(y,c,1),c+=4,u(y,c,"sRGB"),c+=4,y[c]=o.sRGB,c++,l(y,c,h(y,c-5,5)),c+=4),null!=o.iCCP){const t=13+d.length;l(y,c,t),c+=4,u(y,c,"iCCP"),c+=4,u(y,c,"ICC profile"),c+=11,c+=2,y.set(d,c),c+=d.length,l(y,c,h(y,c-(t+4),t+4)),c+=4}if(null!=o.pHYs&&(l(y,c,9),c+=4,u(y,c,"pHYs"),c+=4,l(y,c,o.pHYs[0]),c+=4,l(y,c,o.pHYs[1]),c+=4,y[c]=o.pHYs[2],c++,l(y,c,h(y,c-13,13)),c+=4),f&&(l(y,c,8),c+=4,u(y,c,"acTL"),c+=4,l(y,c,t.frames.length),c+=4,l(y,c,null!=o.loop?o.loop:0),c+=4,l(y,c,h(y,c-12,12)),c+=4),3==t.ctype){for(l(y,c,3*(w=t.plte.length)),c+=4,u(y,c,"PLTE"),c+=4,m=0;m<w;m++){const e=3*m,i=t.plte[m],r=i>>>8&255,s=i>>>16&255;y[c+e+0]=255&i,y[c+e+1]=r,y[c+e+2]=s}if(c+=3*w,l(y,c,h(y,c-3*w-4,3*w+4)),c+=4,p){for(l(y,c,w),c+=4,u(y,c,"tRNS"),c+=4,m=0;m<w;m++)y[c+m]=t.plte[m]>>>24&255;c+=w,l(y,c,h(y,c-w-4,w+4)),c+=4}}let b=0;for(v=0;v<t.frames.length;v++){var M=t.frames[v];f&&(l(y,c,26),c+=4,u(y,c,"fcTL"),c+=4,l(y,c,b++),c+=4,l(y,c,M.rect.width),c+=4,l(y,c,M.rect.height),c+=4,l(y,c,M.rect.x),c+=4,l(y,c,M.rect.y),c+=4,a(y,c,n[v]),c+=2,a(y,c,1e3),c+=2,y[c]=M.dispose,c++,y[c]=M.blend,c++,l(y,c,h(y,c-30,30)),c+=4);const e=M.cimg;l(y,c,(w=e.length)+(0==v?0:4)),c+=4;const i=c;u(y,c,0==v?"IDAT":"fdAT"),c+=4,0!=v&&(l(y,c,b++),c+=4),y.set(e,c),c+=w,l(y,c,h(y,i,c-i)),c+=4}return l(y,c,0),c+=4,u(y,c,"IEND"),c+=4,l(y,c,h(y,c-4,4)),c+=4,y.buffer}function a(t,e,i){for(let r=0;r<t.frames.length;r++){const s=t.frames[r],n=s.rect.height,o=new Uint8Array(n*s.bpl+n);s.cimg=d(s.img,n,s.bpp,s.bpl,o,e,i)}}function u(e,i,r,s,n){const o=n[0],l=n[1],a=n[2],u=n[3],d=n[4],p=n[5];let w=6,m=8,v=255;for(var y=0;y<e.length;y++){const t=new Uint8Array(e[y]);for(var k=t.length,b=0;b<k;b+=4)v&=t[b+3]}const M=255!=v,x=function(e,i,r,s,n,o){const h=[];for(var l=0;l<e.length;l++){const c=new Uint8Array(e[l]),d=new Uint32Array(c.buffer);var a;let g=0,w=0,m=i,v=r,y=s?1:0;if(0!=l){const k=o||s||1==l||0!=h[l-2].dispose?1:2;let b=0,M=1e9;for(let t=0;t<k;t++){var u=new Uint8Array(e[l-1-t]);const s=new Uint32Array(e[l-1-t]);let o=i,h=r,a=-1,c=-1;for(let t=0;t<r;t++)for(let e=0;e<i;e++)d[p=t*i+e]!=s[p]&&(e<o&&(o=e),e>a&&(a=e),t<h&&(h=t),t>c&&(c=t));-1==a&&(o=h=a=c=0),n&&(!(1&~o)&&o--,!(1&~h)&&h--);const f=(a-o+1)*(c-h+1);f<M&&(M=f,b=t,g=o,w=h,m=a-o+1,v=c-h+1)}u=new Uint8Array(e[l-1-b]),1==b&&(h[l-1].dispose=2),a=new Uint8Array(m*v*4),t(u,i,r,a,m,v,-g,-w,0),y=t(c,i,r,a,m,v,-g,-w,3)?1:0,1==y?f(c,i,r,a,{x:g,y:w,width:m,height:v}):t(c,i,r,a,m,v,-g,-w,0)}else a=c.slice(0);h.push({rect:{x:g,y:w,width:m,height:v},img:a,blend:y,dispose:0})}if(s)for(l=0;l<h.length;l++){if(1==(g=h[l]).blend)continue;const t=g.rect,s=h[l-1].rect,o=Math.min(t.x,s.x),a=Math.min(t.y,s.y),u={x:o,y:a,width:Math.max(t.x+t.width,s.x+s.width)-o,height:Math.max(t.y+t.height,s.y+s.height)-a};h[l-1].dispose=1,l-1!=0&&c(e,i,r,h,l-1,u,n),c(e,i,r,h,l,u,n)}let d=0;if(1!=e.length)for(var p=0;p<h.length;p++){var g;d+=(g=h[p]).rect.width*g.rect.height}return h}(e,i,r,o,l,a),C={},A=[],S=[];if(0!=s){const t=[];for(b=0;b<x.length;b++)t.push(x[b].img.buffer);const e=function(t){let e=0;for(var i=0;i<t.length;i++)e+=t[i].byteLength;const r=new Uint8Array(e);let s=0;for(i=0;i<t.length;i++){const e=new Uint8Array(t[i]),n=e.length;for(let t=0;t<n;t+=4){let i=e[t],n=e[t+1],o=e[t+2];const h=e[t+3];0==h&&(i=n=o=0),r[s+t]=i,r[s+t+1]=n,r[s+t+2]=o,r[s+t+3]=h}s+=n}return r.buffer}(t),i=g(e,s);for(b=0;b<i.plte.length;b++)A.push(i.plte[b].est.rgba);let r=0;for(b=0;b<x.length;b++){const t=(T=x[b]).img.length;var B=new Uint8Array(i.inds.buffer,r>>2,t>>2);S.push(B);const e=new Uint8Array(i.abuf,r,t);p&&h(T.img,T.rect.width,T.rect.height,A,e,B),T.img.set(e),r+=t}}else for(y=0;y<x.length;y++){var T=x[y];const t=new Uint32Array(T.img.buffer);var O=T.rect.width;for(k=t.length,B=new Uint8Array(k),S.push(B),b=0;b<k;b++){const e=t[b];if(0!=b&&e==t[b-1])B[b]=B[b-1];else if(b>O&&e==t[b-O])B[b]=B[b-O];else{let t=C[e];if(null==t&&(C[e]=t=A.length,A.push(e),A.length>=300))break;B[b]=t}}}const E=A.length;for(E<=256&&0==d&&(m=E<=2?1:E<=4?2:E<=16?4:8,m=Math.max(m,u)),y=0;y<x.length;y++){const t=(T=x[y]).rect.height;let e=T.img,i=4*(O=T.rect.width),r=4;if(E<=256&&0==d){i=Math.ceil(m*O/8);var I=new Uint8Array(i*t);const s=S[y];for(let e=0;e<t;e++){b=e*i;const t=e*O;if(8==m)for(var D=0;D<O;D++)I[b+D]=s[t+D];else if(4==m)for(D=0;D<O;D++)I[b+(D>>1)]|=s[t+D]<<4-4*(1&D);else if(2==m)for(D=0;D<O;D++)I[b+(D>>2)]|=s[t+D]<<6-2*(3&D);else if(1==m)for(D=0;D<O;D++)I[b+(D>>3)]|=s[t+D]<<7-1*(7&D)}e=I,w=3,r=1}else if(0==M&&1==x.length){I=new Uint8Array(O*t*3);const s=O*t;for(b=0;b<s;b++){const t=3*b,i=4*b;I[t]=e[i],I[t+1]=e[i+1],I[t+2]=e[i+2]}e=I,w=2,r=3,i=3*O}T.img=e,T.bpl=i,T.bpp=r}return{ctype:w,depth:m,plte:A,frames:x}}function c(e,i,r,s,n,o,h){const l=Uint8Array,a=Uint32Array,u=new l(e[n-1]),c=new a(e[n-1]),d=n+1<e.length?new l(e[n+1]):null,p=new l(e[n]),g=new a(p.buffer);let w=i,m=r,v=-1,y=-1;for(let t=0;t<o.height;t++)for(let e=0;e<o.width;e++){const r=o.x+e,h=o.y+t,l=h*i+r,a=g[l];0==a||0==s[n-1].dispose&&c[l]==a&&(null==d||0!=d[4*l+3])||(r<w&&(w=r),r>v&&(v=r),h<m&&(m=h),h>y&&(y=h))}-1==v&&(w=m=v=y=0),h&&(!(1&~w)&&w--,!(1&~m)&&m--);const k=s[n];k.rect=o={x:w,y:m,width:v-w+1,height:y-m+1},k.blend=1,k.img=new Uint8Array(o.width*o.height*4),0==s[n-1].dispose?(t(u,i,r,k.img,o.width,o.height,-o.x,-o.y,0),f(p,i,r,k.img,o)):t(p,i,r,k.img,o.width,o.height,-o.x,-o.y,0)}function f(e,i,r,s,n){t(e,i,r,s,n.width,n.height,-n.x,-n.y,2)}function d(t,e,i,r,s,n,o){const h=[];let l,a=[0,1,2,3,4];-1!=n?a=[n]:(e*r>5e5||1==i)&&(a=[0]),o&&(l={level:0});const u=io;for(var c=0;c<a.length;c++){for(let n=0;n<e;n++)p(s,t,n,r,i,a[c]);h.push(u.deflate(s,l))}let f,d=1e9;for(c=0;c<h.length;c++)h[c].length<d&&(f=c,d=h[c].length);return h[f]}function p(t,e,r,s,n,o){const h=r*s;let l=h+r;if(t[l]=o,l++,0==o)if(s<500)for(var a=0;a<s;a++)t[l+a]=e[h+a];else t.set(new Uint8Array(e.buffer,h,s),l);else if(1==o){for(a=0;a<n;a++)t[l+a]=e[h+a];for(a=n;a<s;a++)t[l+a]=e[h+a]-e[h+a-n]+256&255}else if(0==r){for(a=0;a<n;a++)t[l+a]=e[h+a];if(2==o)for(a=n;a<s;a++)t[l+a]=e[h+a];if(3==o)for(a=n;a<s;a++)t[l+a]=e[h+a]-(e[h+a-n]>>1)+256&255;if(4==o)for(a=n;a<s;a++)t[l+a]=e[h+a]-i(e[h+a-n],0,0)+256&255}else{if(2==o)for(a=0;a<s;a++)t[l+a]=e[h+a]+256-e[h+a-s]&255;if(3==o){for(a=0;a<n;a++)t[l+a]=e[h+a]+256-(e[h+a-s]>>1)&255;for(a=n;a<s;a++)t[l+a]=e[h+a]+256-(e[h+a-s]+e[h+a-n]>>1)&255}if(4==o){for(a=0;a<n;a++)t[l+a]=e[h+a]+256-i(0,e[h+a-s],0)&255;for(a=n;a<s;a++)t[l+a]=e[h+a]+256-i(e[h+a-n],e[h+a-s],e[h+a-n-s])&255}}}function g(t,e){const i=new Uint8Array(t),r=i.slice(0),s=new Uint32Array(r.buffer),n=w(r,e),o=n[0],h=n[1],l=i.length,a=new Uint8Array(l>>2);let u;if(i.length<2e7)for(var c=0;c<l;c+=4)u=m(o,f=i[c]*(1/255),d=i[c+1]*(1/255),p=i[c+2]*(1/255),g=i[c+3]*(1/255)),a[c>>2]=u.ind,s[c>>2]=u.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),g=i[c+3]*(1/255);for(u=o;u.left;)u=v(u.est,f,d,p,g)<=0?u.left:u.right;a[c>>2]=u.ind,s[c>>2]=u.est.rgba}return{abuf:r.buffer,inds:a,plte:h}}function w(t,e,i){null==i&&(i=1e-4);const r=new Uint32Array(t.buffer),s={i0:0,i1:t.length,bst:null,est:null,tdst:0,left:null,right:null};s.bst=b(t,s.i0,s.i1),s.est=M(s.bst);const n=[s];for(;n.length<e;){let e=0,s=0;for(var o=0;o<n.length;o++)n[o].est.L>e&&(e=n[o].est.L,s=o);if(e<i)break;const h=n[s],l=y(t,r,h.i0,h.i1,h.est.e,h.est.eMq255);if(h.i0>=l||h.i1<=l){h.est.L=0;continue}const a={i0:h.i0,i1:l,bst:null,est:null,tdst:0,left:null,right:null};a.bst=b(t,a.i0,a.i1),a.est=M(a.bst);const u={i0:l,i1:h.i1,bst:null,est:null,tdst:0,left:null,right:null};for(u.bst={R:[],m:[],N:h.bst.N-a.bst.N},o=0;o<16;o++)u.bst.R[o]=h.bst.R[o]-a.bst.R[o];for(o=0;o<4;o++)u.bst.m[o]=h.bst.m[o]-a.bst.m[o];u.est=M(u.bst),h.left=a,h.right=u,n[s]=a,n.push(u)}for(n.sort(((t,e)=>e.bst.N-t.bst.N)),o=0;o<n.length;o++)n[o].ind=o;return[s,n]}function m(t,e,i,r,s){if(null==t.left)return t.tdst=function(t,e,i,r,s){const n=e-t[0],o=i-t[1],h=r-t[2],l=s-t[3];return n*n+o*o+h*h+l*l}(t.est.q,e,i,r,s),t;const n=v(t.est,e,i,r,s);let o=t.left,h=t.right;n>0&&(o=t.right,h=t.left);const l=m(o,e,i,r,s);if(l.tdst<=n*n)return l;const a=m(h,e,i,r,s);return a.tdst<l.tdst?a:l}function v(t,e,i,r,s){const{e:n}=t;return n[0]*e+n[1]*i+n[2]*r+n[3]*s-t.eMq}function y(t,e,i,r,s,n){for(r-=4;i<r;){for(;k(t,i,s)<=n;)i+=4;for(;k(t,r,s)>n;)r-=4;if(i>=r)break;const o=e[i>>2];e[i>>2]=e[r>>2],e[r>>2]=o,i+=4,r-=4}for(;k(t,i,s)>n;)i-=4;return i+4}function k(t,e,i){return t[e]*i[0]+t[e+1]*i[1]+t[e+2]*i[2]+t[e+3]*i[3]}function b(t,e,i){const r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],s=[0,0,0,0],n=i-e>>2;for(let n=e;n<i;n+=4){const e=t[n]*(1/255),i=t[n+1]*(1/255),o=t[n+2]*(1/255),h=t[n+3]*(1/255);s[0]+=e,s[1]+=i,s[2]+=o,s[3]+=h,r[0]+=e*e,r[1]+=e*i,r[2]+=e*o,r[3]+=e*h,r[5]+=i*i,r[6]+=i*o,r[7]+=i*h,r[10]+=o*o,r[11]+=o*h,r[15]+=h*h}return r[4]=r[1],r[8]=r[2],r[9]=r[6],r[12]=r[3],r[13]=r[7],r[14]=r[11],{R:r,m:s,N:n}}function M(t){const{R:e}=t,{m:i}=t,{N:r}=t,s=i[0],n=i[1],o=i[2],h=i[3],l=0==r?0:1/r,a=[e[0]-s*s*l,e[1]-s*n*l,e[2]-s*o*l,e[3]-s*h*l,e[4]-n*s*l,e[5]-n*n*l,e[6]-n*o*l,e[7]-n*h*l,e[8]-o*s*l,e[9]-o*n*l,e[10]-o*o*l,e[11]-o*h*l,e[12]-h*s*l,e[13]-h*n*l,e[14]-h*o*l,e[15]-h*h*l],u=a,c=x;let f=[Math.random(),Math.random(),Math.random(),Math.random()],d=0,p=0;if(0!=r)for(let t=0;t<16&&(f=c.multVec(u,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 g=[s*l,n*l,o*l,h*l];return{Cov:a,q:g,e:f,L:d,eMq255:c.dot(c.sml(255,g),f),eMq:c.dot(f,g),rgba:(Math.round(255*g[3])<<24|Math.round(255*g[2])<<16|Math.round(255*g[1])<<8|Math.round(255*g[0]))>>>0}}var x={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]]};ro.encode=function(t,e,i,r,s,n,o){null==r&&(r=0),null==o&&(o=!1);const h=u(t,e,i,r,[!1,!1,!1,0,o,!1]);return a(h,-1),l(h,e,i,s,n)},ro.encodeLL=function(t,e,i,r,s,n,o,h){const u={ctype:0+(1==r?0:2)+(0==s?0:4),depth:n,frames:[]},c=(r+s)*n,f=c*e;for(let r=0;r<t.length;r++)u.frames.push({rect:{x:0,y:0,width:e,height:i},img:new Uint8Array(t[r]),blend:0,dispose:1,bpp:Math.ceil(c/8),bpl:Math.ceil(f/8)});return a(u,0,!0),l(u,e,i,o,h)},ro.encode.compress=u,ro.encode.dither=h,ro.quantize=g,ro.quantize.getKDtree=w,ro.quantize.getNearest=m}();const so={toArrayBuffer(t,e){const i=t.width,r=t.height,s=i<<2,n=t.getContext("2d").getImageData(0,0,i,r),o=new Uint32Array(n.data.buffer),h=(32*i+31)/32<<2,l=h*r,a=122+l,u=new ArrayBuffer(a),c=new DataView(u),f=1<<20;let d,p,g,w,m=f,v=0,y=0,k=0;function b(t){c.setUint16(y,t,!0),y+=2}function M(t){c.setUint32(y,t,!0),y+=4}function x(t){y+=t}b(19778),M(a),x(4),M(122),M(108),M(i),M(-r>>>0),b(1),b(32),M(3),M(l),M(2835),M(2835),x(8),M(16711680),M(65280),M(255),M(4278190080),M(1466527264),function t(){for(;v<r&&m>0;){for(w=122+v*h,d=0;d<s;)m--,p=o[k++],g=p>>>24,c.setUint32(w+d,p<<8|g),d+=4;v++}k<o.length?(m=f,setTimeout(t,so._dly)):e(u)}()},toBlob(t,e){this.toArrayBuffer(t,(t=>{e(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var no={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},oo={[no.CHROME]:16384,[no.FIREFOX]:11180,[no.DESKTOP_SAFARI]:16384,[no.IE]:8192,[no.IOS]:4096,[no.ETC]:8192};const ho="undefined"!=typeof window,lo="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,ao=ho&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),uo=(ho||lo)&&(ao&&ao.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),co=(ho||lo)&&(ao&&ao.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function fo(t,e,i=Date.now()){return new Promise((r=>{const s=t.split(","),n=s[0].match(/:(.*?);/)[1],o=globalThis.atob(s[1]);let h=o.length;const l=new Uint8Array(h);for(;h--;)l[h]=o.charCodeAt(h);const a=new Blob([l],{type:n});a.name=e,a.lastModified=i,r(a)}))}function po(t){return new Promise(((e,i)=>{const r=new co;r.onload=()=>e(r.result),r.onerror=t=>i(t),r.readAsDataURL(t)}))}function go(t){return new Promise(((e,i)=>{const r=new Image;r.onload=()=>e(r),r.onerror=t=>i(t),r.src=t}))}function wo(){if(void 0!==wo.cachedResult)return wo.cachedResult;let t=no.ETC;const{userAgent:e}=navigator;return/Chrom(e|ium)/i.test(e)?t=no.CHROME:/iP(ad|od|hone)/i.test(e)&&/WebKit/i.test(e)?t=no.IOS:/Safari/i.test(e)?t=no.DESKTOP_SAFARI:/Firefox/i.test(e)?t=no.FIREFOX:(/MSIE/i.test(e)||1==!!document.documentMode)&&(t=no.IE),wo.cachedResult=t}function mo(t,e){const i=wo(),r=oo[i];let s=t,n=e,o=s*n;const h=s>n?n/s:s/n;for(;o>r*r;){const t=(r+s)/2,e=(r+n)/2;t<e?(n=e,s=e*h):(n=t*h,s=t),o=s*n}return{width:s,height:n}}function vo(t,e){let i,r;try{if(i=new OffscreenCanvas(t,e),r=i.getContext("2d"),null===r)throw new Error("getContext of OffscreenCanvas returns null")}catch(t){i=document.createElement("canvas"),r=i.getContext("2d")}return i.width=t,i.height=e,[i,r]}function yo(t,e){const{width:i,height:r}=mo(t.width,t.height),[s,n]=vo(i,r);return e&&/jpe?g/.test(e)&&(n.fillStyle="white",n.fillRect(0,0,s.width,s.height)),n.drawImage(t,0,0,s.width,s.height),s}function ko(){return void 0!==ko.cachedResult||(ko.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),ko.cachedResult}function bo(t,e={}){return new Promise((function(i,r){let s,n;var o=function(){try{return n=yo(s,e.fileType||t.type),i([s,n])}catch(t){return r(t)}},h=function(){try{var e=function(t){try{throw t}catch(t){return r(t)}};try{let i;return po(t).then((function(t){try{return i=t,go(i).then((function(t){try{return s=t,function(){try{return o()}catch(t){return r(t)}}()}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){e(t)}}catch(t){return r(t)}};try{if(ko()||[no.DESKTOP_SAFARI,no.MOBILE_SAFARI].includes(wo()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return s=t,o()}catch(t){return h()}}),h)}catch(t){h()}}))}function Mo(t,e,i,r,s=1){return new Promise((function(n,o){let h;if("image/png"===e){let a,u,c;return a=t.getContext("2d"),({data:u}=a.getImageData(0,0,t.width,t.height)),c=ro.encode([u.buffer],t.width,t.height,4096*s),h=new Blob([c],{type:e}),h.name=i,h.lastModified=r,l.call(this)}{if("image/bmp"===e)return new Promise((e=>so.toBlob(t,e))).then(function(t){try{return h=t,h.name=i,h.lastModified=r,f.call(this)}catch(t){return o(t)}}.bind(this),o);{if("function"==typeof OffscreenCanvas&&t instanceof OffscreenCanvas)return t.convertToBlob({type:e,quality:s}).then(function(t){try{return h=t,h.name=i,h.lastModified=r,d.call(this)}catch(t){return o(t)}}.bind(this),o);{let p;return p=t.toDataURL(e,s),fo(p,i,r).then(function(t){try{return h=t,d.call(this)}catch(t){return o(t)}}.bind(this),o)}function d(){return f.call(this)}}function f(){return l.call(this)}}function l(){return n(h)}}))}function xo(t){t.width=0,t.height=0}function Co(){return new Promise((function(t,e){let i,r,s,n;return void 0!==Co.cachedResult?t(Co.cachedResult):fo("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return i=o,bo(i).then((function(o){try{return r=o[1],Mo(r,i.type,i.name,i.lastModified).then((function(i){try{return s=i,xo(r),bo(s).then((function(i){try{return n=i[0],t(Co.cachedResult=1===n.width&&2===n.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 Ao(t){return new Promise(((e,i)=>{const r=new co;r.onload=t=>{const i=new DataView(t.target.result);if(65496!=i.getUint16(0,!1))return e(-2);const r=i.byteLength;let s=2;for(;s<r;){if(i.getUint16(s+2,!1)<=8)return e(-1);const t=i.getUint16(s,!1);if(s+=2,65505==t){if(1165519206!=i.getUint32(s+=2,!1))return e(-1);const t=18761==i.getUint16(s+=6,!1);s+=i.getUint32(s+4,t);const r=i.getUint16(s,t);s+=2;for(let n=0;n<r;n++)if(274==i.getUint16(s+12*n,t))return e(i.getUint16(s+12*n+8,t))}else{if(65280&~t)break;s+=i.getUint16(s,!1)}}return e(-1)},r.onerror=t=>i(t),r.readAsArrayBuffer(t)}))}function So(t,e){const{width:i}=t,{height:r}=t,{maxWidthOrHeight:s}=e;let n,o=t;return isFinite(s)&&(i>s||r>s)&&([o,n]=vo(i,r),i>r?(o.width=s,o.height=r/i*s):(o.width=i/r*s,o.height=s),n.drawImage(t,0,0,o.width,o.height),xo(t)),o}function Bo(t,e){const{width:i}=t,{height:r}=t,[s,n]=vo(i,r);switch(e>4&&e<9?(s.width=r,s.height=i):(s.width=i,s.height=r),e){case 2:n.transform(-1,0,0,1,i,0);break;case 3:n.transform(-1,0,0,-1,i,r);break;case 4:n.transform(1,0,0,-1,0,r);break;case 5:n.transform(0,1,1,0,0,0);break;case 6:n.transform(0,1,-1,0,r,0);break;case 7:n.transform(0,-1,-1,0,r,i);break;case 8:n.transform(0,-1,1,0,0,i)}return n.drawImage(t,0,0,i,r),xo(t),s}function To(t,e,i=0){return new Promise((function(r,s){let n,o,h,l,a,u,c,f,d,p,g,w,m,v,y,k,b,M,x,C;function A(t=5){if(e.signal&&e.signal.aborted)throw e.signal.reason;n+=t,e.onProgress(Math.min(n,100))}function S(t){if(e.signal&&e.signal.aborted)throw e.signal.reason;n=Math.min(Math.max(t,n),100),e.onProgress(n)}return n=i,o=e.maxIteration||10,h=1024*e.maxSizeMB*1024,A(),bo(t,e).then(function(i){try{return[,l]=i,A(),a=So(l,e),A(),new Promise((function(i,r){var s;if(!(s=e.exifOrientation))return Ao(t).then(function(t){try{return s=t,n.call(this)}catch(t){return r(t)}}.bind(this),r);function n(){return i(s)}return n.call(this)})).then(function(i){try{return u=i,A(),Co().then(function(i){try{return c=i?a:Bo(a,u),A(),f=e.initialQuality||1,d=e.fileType||t.type,Mo(c,d,t.name,t.lastModified,f).then(function(i){try{{if(p=i,A(),g=p.size>h,w=p.size>t.size,!g&&!w)return S(100),r(p);var n;function u(){if(o--&&(y>h||y>m)){let e,i;return e=C?.95*x.width:x.width,i=C?.95*x.height:x.height,[b,M]=vo(e,i),M.drawImage(x,0,0,e,i),f*="image/png"===d?.85:.95,Mo(b,d,t.name,t.lastModified,f).then((function(t){try{return k=t,xo(x),x=b,y=k.size,S(Math.min(99,Math.floor((v-y)/(v-h)*100))),u}catch(t){return s(t)}}),s)}return[1]}return m=t.size,v=p.size,y=v,x=c,C=!e.alwaysKeepResolution&&g,(n=function(t){for(;t;){if(t.then)return void t.then(n,s);try{if(t.pop){if(t.length)return t.pop()?B.call(this):t;t=u}else t=t.call(this)}catch(t){return s(t)}}}.bind(this))(u);function B(){return xo(x),xo(b),xo(a),xo(c),xo(l),S(100),r(k)}}}catch(T){return s(T)}}.bind(this),s)}catch(t){return s(t)}}.bind(this),s)}catch(t){return s(t)}}.bind(this),s)}catch(t){return s(t)}}.bind(this),s)}))}let Oo;function Eo(t,e){return new Promise(((i,r)=>{Oo||(Oo=function(){const t=[];return t.push("\nlet scriptImported = false\nself.addEventListener('message', async (e) => {\n const { file, id, imageCompressionLibUrl, options } = e.data\n options.onProgress = (progress) => self.postMessage({ progress, id })\n try {\n if (!scriptImported) {\n // console.log('[worker] importScripts', imageCompressionLibUrl)\n self.importScripts(imageCompressionLibUrl)\n scriptImported = true\n }\n // console.log('[worker] self', self)\n const compressedFile = await imageCompression(file, options)\n self.postMessage({ file: compressedFile, id })\n } catch (e) {\n // console.error('[worker] error', e)\n self.postMessage({ error: e.message + '\\n' + e.stack, id })\n }\n})\n"),URL.createObjectURL(new Blob(t))}());const s=new Worker(Oo);s.addEventListener("message",(function(t){if(e.signal&&e.signal.aborted)s.terminate();else if(void 0===t.data.progress){if(t.data.error)return r(new Error(t.data.error)),void s.terminate();i(t.data.file),s.terminate()}else e.onProgress(t.data.progress)})),s.addEventListener("error",r),e.signal&&e.signal.addEventListener("abort",(()=>{r(e.signal.reason),s.terminate()})),s.postMessage({file:t,imageCompressionLibUrl:e.libURL,options:{...e,onProgress:void 0,signal:void 0}})}))}function Io(t,e){return new Promise((function(i,r){let s,n,o,h,l,a;if(s={...e},o=0,({onProgress:h}=s),s.maxSizeMB=s.maxSizeMB||Number.POSITIVE_INFINITY,l="boolean"!=typeof s.useWebWorker||s.useWebWorker,delete s.useWebWorker,s.onProgress=t=>{o=t,"function"==typeof h&&h(o)},!(t instanceof Blob||t instanceof uo))return r(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(t.type))return r(new Error("The file given is not an image"));if(a="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!l||"function"!=typeof Worker||a)return To(t,s).then(function(t){try{return n=t,f.call(this)}catch(t){return r(t)}}.bind(this),r);var u=function(){try{return f.call(this)}catch(t){return r(t)}}.bind(this),c=function(){try{return To(t,s).then((function(t){try{return n=t,u()}catch(t){return r(t)}}),r)}catch(t){return r(t)}};try{return s.libURL=s.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",Eo(t,s).then((function(t){try{return n=t,u()}catch(t){return c()}}),c)}catch(t){c()}function f(){try{n.name=t.name,n.lastModified=t.lastModified}catch(t){}try{s.preserveExif&&"image/jpeg"===t.type&&(!s.fileType||s.fileType&&s.fileType===t.type)&&(n=Gn(t,n))}catch(t){}return i(n)}}))}Io.getDataUrlFromFile=po,Io.getFilefromDataUrl=fo,Io.loadImage=go,Io.drawImageInCanvas=yo,Io.drawFileInCanvas=bo,Io.canvasToFile=Mo,Io.getExifOrientation=Ao,Io.handleMaxWidthOrHeight=So,Io.followExifOrientation=Bo,Io.cleanupCanvasMemory=xo,Io.isAutoOrientationInBrowser=Co,Io.approximateBelowMaximumCanvasSizeOfBrowser=mo,Io.copyExifWithoutOrientation=Gn,Io.getBrowserName=wo,Io.version="2.0.2";class Do extends Vn{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]?Io(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=Ln.create(this._core),{scaledWidth:i,scaledHeight:r}=e.calculateScaledDimensions(t);return e.src=t.src,e.width=i,e.height=r,e.zIndex=this._core.store.currentZIndex,e.centerInViewport(),this.addImageToStore(e),e}addImageToStore(t){this._core.addObject(t),this._core.store.setState("activeTool",i.getTool("selection")),this._core.selectObjects([t]),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])}handleCancel(){this._core.store.setState("activeTool",i.getTool("selection"))}}class Po extends Vn{fontFamily="Arial";fontSize=16;fontColor=An[0];opacity=1;palette=[...An];constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){const e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),r=this._core.findObjectById(e?.id),s=this._core.store.activeText;if(null===s&&r instanceof Pn)return void r.edit(t);if(null!==s&&r instanceof Pn)return s.save(),void r.edit(t);if(null!==s&&r instanceof Pn==0)return this._core.resetActiveText(),void this._core.store.setState("activeTool",i.getTool("selection"));if(!1===Wn.isLeftClick(t))return;const n=t.clientX-this._core.store.offsetX,o=t.clientY-this._core.store.offsetY,h=this._core.store.state.scale,l=Pn.create(this._core,this.fontSize,this.fontFamily,this._core.store.state.lockDrawingScale?1:h);l.fontColor=this.fontColor,l.opacity=this.opacity,l.translateX=(n-this._core.store.state.translateX)/h,l.translateY=(o-this._core.store.state.translateY)/h,l.zIndex=this._core.store.currentZIndex,this._core.store.state.objects.insert(l),this._core.rerender(),l.edit(t)}if("touch"===t.pointerType||"pen"===t.pointerType){const e=Array.from(this._core.store.state.pointers.values()),r=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),s=this._core.findObjectById(r?.id),n=this._core.store.activeText;if(null===n&&s instanceof Pn)return void s.edit(t);if(null!==n&&s instanceof Pn)return n.save(),void s.edit(t);if(null!==n&&s instanceof Pn==0)return this._core.resetActiveText(),void this._core.store.setState("activeTool",i.getTool("selection"));if(e.length>1)return;const o=Math.round(e[0].clientX-this._core.store.offsetX),h=Math.round(e[0].clientY-this._core.store.offsetY),l=this._core.store.state.scale,a=Pn.create(this._core,this.fontSize,this.fontFamily,this._core.store.state.lockDrawingScale?1:l);a.fontColor=this.fontColor,a.opacity=this.opacity,a.translateX=(o-this._core.store.state.translateX)/l,a.translateY=(h-this._core.store.state.translateY)/l,a.zIndex=this._core.store.currentZIndex,this._core.store.state.objects.insert(a),this._core.rerender(),a.edit(t)}}handlePointerUp(t){const e=this._core.store.activeText;e&&e.isMounted&&!e.editor?.hasFocus()&&e.focus({x:t.clientX,y:t.clientY})}}class $o extends Vn{shapeType=Rn.Rectangle;fillColor={light:"transparent",dark:"transparent"};strokeColor=An[0];strokeWidth=4;opacity=1;fontFamily="Arial";fontSize=16;fontColor=An[0];palette=[...An];startX=0;startY=0;isDrawing=!1;currentShape=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){const e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),r=this._core.findObjectById(e?.id),s=this._core.store.activeShape;if(null===s&&r instanceof Yn)return void r.edit(t);if(null!==s&&r instanceof Yn)return s.save(),void r.edit(t);if(null!==s&&r instanceof Yn==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",i.getTool("selection"));if(!1===Wn.isLeftClick(t))return;this.startDrawing(t.clientX,t.clientY)}if("touch"===t.pointerType||"pen"===t.pointerType){const e=Array.from(this._core.store.state.pointers.values()),r=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),s=this._core.findObjectById(r?.id),n=this._core.store.activeShape;if(null===n&&s instanceof Yn)return void s.edit(t);if(null!==n&&s instanceof Yn)return n.save(),void s.edit(t);if(null!==n&&s instanceof Yn==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",i.getTool("selection"));if(e.length>1)return;const o=Math.round(e[0].clientX),h=Math.round(e[0].clientY);this.startDrawing(o,h)}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),this.isDrawing&&this.currentShape&&("mouse"===t.pointerType&&this.updateShapeSize(t.clientX,t.clientY),"touch"===t.pointerType||"pen"===t.pointerType)){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const e=Math.round(t[0].clientX),i=Math.round(t[0].clientY);this.updateShapeSize(e,i)}}}handlePointerUp(t){t.cancelable&&t.preventDefault(),this.isDrawing&&this.currentShape&&this.finishDrawing()}startDrawing(t,e){const i=this._core.store.state.scale,r=this._core.store.state.lockDrawingScale,s=r?i:1;this.startX=(t-this._core.store.offsetX)/s,this.startY=(e-this._core.store.offsetY)/s,this.isDrawing=!0,this.currentShape=Yn.create(this._core,{x:this.startX,y:this.startY,translateX:-this._core.store.state.translateX/s,translateY:-this._core.store.state.translateY/s,width:1,height:1,shapeType:this.shapeType,fillColor:this.fillColor,strokeColor:this.strokeColor,strokeWidth:this.strokeWidth,opacity:this.opacity,fontSize:this.fontSize,fontFamily:this.fontFamily,scale:r?1:i}),this._core.store.state.objects.insert(this.currentShape),this._core.store.state.objects?.setActiveDrawingObject(this.currentShape.id),this._core.rerender()}updateShapeSize(t,e){if(!this.currentShape)return;const i=this._core.store.state.lockDrawingScale?this._core.store.state.scale:1,r=(t-this._core.store.offsetX)/i,s=(e-this._core.store.offsetY)/i,n=Math.min(this.startX,r),o=Math.min(this.startY,s),h=Math.abs(r-this.startX),l=Math.abs(s-this.startY);this.currentShape.x=n,this.currentShape.y=o,this.currentShape.width=Math.max(1,h),this.currentShape.height=Math.max(1,l),this.currentShape.translateX=-this._core.store.state.translateX/i,this.currentShape.translateY=-this._core.store.state.translateY/i,this.currentShape.updateDimensions(),this._core.store.state.objects.update(this.currentShape)}finishDrawing(){if(this.currentShape){if(this.currentShape.width<10&&this.currentShape.height<10){const t=this.currentShape.id;this._core.store.state.objects.remove((e=>e.id===t))}else this.currentShape.zIndex=this._core.store.currentZIndex,this._core.store.state.objects.update(this.currentShape),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([this.currentShape]),this._core.selectObjects([this.currentShape]),this._core.store.setState("activeTool",i.getTool("selection"));this.isDrawing=!1,this._core.store.state.objects?.setActiveDrawingObject(null),this.currentShape=null,this._core.rerender()}}}class Ro{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)}}Ro.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>',"arrow-up-from-dot":'<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-from-dot-icon lucide-arrow-up-from-dot"><path d="m5 9 7-7 7 7"/><path d="M12 16V2"/><circle cx="12" cy="21" r="1"/></svg>',"arrow-down-from-dot":'<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-from-dot-icon lucide-arrow-down-from-dot" transform="rotate(180)"><path d="m5 9 7-7 7 7"/><path d="M12 16V2"/><circle cx="12" cy="21" r="1"/></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>',"chevron-left":'<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-chevron-left-icon lucide-chevron-left"><path d="m15 18-6-6 6-6"/></svg>',"chevron-right":'<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-chevron-right-icon lucide-chevron-right"><path d="m9 18 6-6-6-6"/></svg>',"chevrons-left":'<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-chevrons-left-icon lucide-chevrons-left"><path d="m11 17-5-5 5-5"/><path d="m18 17-5-5 5-5"/></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>',upload:'<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-upload-icon lucide-upload"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" x2="12" y1="3" y2="15"/></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>',settings:'<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-settings-icon lucide-settings"><path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"/><circle cx="12" cy="12" r="3"/></svg>',share:'<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-share2-icon lucide-share-2"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.59" x2="15.42" y1="13.51" y2="17.49"/><line x1="15.41" x2="8.59" y1="6.51" y2="10.49"/></svg>',palette:'<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-palette-icon lucide-palette"><path d="M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z"/><circle cx="13.5" cy="6.5" r=".5" fill="currentColor"/><circle cx="17.5" cy="10.5" r=".5" fill="currentColor"/><circle cx="6.5" cy="12.5" r=".5" fill="currentColor"/><circle cx="8.5" cy="7.5" r=".5" fill="currentColor"/></svg>',command:'<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-command-icon lucide-command"><path d="M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3"/></svg>',info:'<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-info-icon lucide-info"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>',ordering:'<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-bring-to-front-icon lucide-bring-to-front"><rect x="8" y="8" width="8" height="8" rx="2"/><path d="M4 10a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2"/><path d="M14 20a2 2 0 0 0 2 2h4a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2"/></svg>',"layout-template":'<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-layout-template-icon lucide-layout-template"><rect width="18" height="7" x="3" y="3" rx="1"/><rect width="9" height="7" x="3" y="14" rx="1"/><rect width="5" height="7" x="16" y="14" rx="1"/></svg>',align:'<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="21" x2="3" y1="10" y2="10"/><line x1="21" x2="3" y1="6" y2="6"/><line x1="21" x2="3" y1="14" y2="14"/><line x1="21" x2="3" y1="18" y2="18"/></svg>',"align-start-horizontal":'<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-align-start-horizontal-icon lucide-align-start-horizontal"><rect width="6" height="16" x="4" y="6" rx="2"/><rect width="6" height="9" x="14" y="6" rx="2"/><path d="M22 2H2"/></svg>',"align-center-horizontal":'<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-align-center-horizontal-icon lucide-align-center-horizontal"><path d="M2 12h20"/><path d="M10 16v4a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-4"/><path d="M10 8V4a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v4"/><path d="M20 16v1a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2v-1"/><path d="M14 8V7c0-1.1.9-2 2-2h2a2 2 0 0 1 2 2v1"/></svg>',"align-end-horizontal":'<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-align-end-horizontal-icon lucide-align-end-horizontal"><rect width="6" height="16" x="4" y="2" rx="2"/><rect width="6" height="9" x="14" y="9" rx="2"/><path d="M22 22H2"/></svg>',"align-start-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-align-start-vertical-icon lucide-align-start-vertical"><rect width="9" height="6" x="6" y="14" rx="2"/><rect width="16" height="6" x="6" y="4" rx="2"/><path d="M2 2v20"/></svg>',"align-center-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-align-center-vertical-icon lucide-align-center-vertical"><path d="M12 2v20"/><path d="M8 10H4a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h4"/><path d="M16 10h4a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2h-4"/><path d="M8 20H7a2 2 0 0 1-2-2v-2c0-1.1.9-2 2-2h1"/><path d="M16 14h1a2 2 0 0 1 2 2v2a2 2 0 0 1-2 2h-1"/></svg>',"align-end-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-align-end-vertical-icon lucide-align-end-vertical"><rect width="16" height="6" x="2" y="4" rx="2"/><rect width="9" height="6" x="9" y="14" rx="2"/><path d="M22 22V2"/></svg>',viewport:'<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-maximize-icon lucide-maximize"><path d="M8 3H5a2 2 0 0 0-2 2v3"/><path d="M21 8V5a2 2 0 0 0-2-2h-3"/><path d="M3 16v3a2 2 0 0 0 2 2h3"/><path d="M16 21h3a2 2 0 0 0 2-2v-3"/></svg>',"log-out":'<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-log-out-icon lucide-log-out"><path d="m16 17 5-5-5-5"/><path d="M21 12H9"/><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/></svg>',"users-round":'<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-users-round-icon lucide-users-round"><path d="M18 21a8 8 0 0 0-16 0"/><circle cx="10" cy="8" r="5"/><path d="M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3"/></svg>',google:'<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" xmlns:xlink="http://www.w3.org/1999/xlink" style="display: block;"><path fill="#EA4335" d="M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z"></path><path fill="#4285F4" d="M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z"></path><path fill="#FBBC05" d="M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z"></path><path fill="#34A853" d="M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z"></path><path fill="none" d="M0 0h48v48H0z"></path></svg>',braces:'<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-braces-icon lucide-braces"><path d="M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1"/><path d="M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1"/></svg>'});class jo{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=Ro.get(e);if(!i)return console.warn(`Icon "${e}" not found in registry.`),"auto";const r=t.size||24,s=t.rotation||0,n=t.color||"black",o=t.hotspot||("default"===t.iconName?{x:4,y:4}:{x:r/2,y:r/2});let h=i.replace(/width="\d+"/,`width="${r}"`).replace(/height="\d+"/,`height="${r}"`).replace(/currentColor/g,n);const l=r/2;return`url('data:image/svg+xml;charset=utf-8,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${r}" viewBox="0 0 ${r} ${r}">\n <g transform="rotate(${s} ${l} ${l})">\n ${h}\n </g>\n </svg>\n `.replace(/\s+/g," ").trim()).replace(/'/g,"%27").replace(/"/g,"%22")}') ${o.x} ${o.y}, auto`}}class Fo{_core;constructor(t){this._core=t}}class No extends Fo{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(Wn.isLeftClick(t)){const e=this._core.store.selectionGroup,i=t.shiftKey||t.ctrlKey;if(!e?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||i)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||"pen"===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,r=t.shiftKey||t.ctrlKey;if(!i?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||r)this.trackedPointerId=null;else{const i=Math.round(e[0].clientX-this._core.store.offsetX),r=Math.round(e[0].clientY-this._core.store.offsetY);this.dragStartX=i,this.dragStartY=r,this.startX=i,this.startY=r,this.initialDragX=i,this.initialDragY=r,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,r=t.clientY-this._core.store.offsetY;this.endX=i,this.endY=r;const s=Math.abs(i-this.startX),n=Math.abs(r-this.startY),o=5;(this.hasMoved||s>o||n>o)&&(this.checkAndDisconnectAnchors(i,r),e.move(i,r,this.dragStartX,this.dragStartY),this.dragStartX=i,this.dragStartY=r,this.hasMoved=!0)}}if("touch"===t.pointerType||"pen"===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),r=Math.round(t[0].clientY-this._core.store.offsetY);this._core.store.state.isDragging=!0,this.endX=i,this.endY=r;const s=Math.abs(i-this.startX),n=Math.abs(r-this.startY),o=5;(this.hasMoved||s>o||n>o)&&(globalThis.clearTimeout?.(this._core.store.state.longTouchTimeout),this.checkAndDisconnectAnchors(i,r),e.move(i,r,this.dragStartX,this.dragStartY),this.dragStartX=i,this.dragStartY=r,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&&"pen"!==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,r=e-this.initialDragY;if(Math.sqrt(i*i+r*r)<30)return;const s=this._core.store.selectionGroup;if(!s)return;const n=s.objects;if(n.every((t=>t instanceof _n)))for(const t of n)if(!this.disconnectedLineIds.has(t.id)&&t instanceof _n){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 Uo;!function(t){t.TopLeft="top-left",t.TopRight="top-right",t.BottomLeft="bottom-left",t.BottomRight="bottom-right"}(Uo||(Uo={}));class zo extends Fo{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&&Wn.isLeftClick(t)){const e=this._core.store.selectionGroup;if(e&&this._core.store.state.isResizeHandleSelected){e.beginTransform();const i=t.clientX-this._core.store.offsetX,r=t.clientY-this._core.store.offsetY;this._core.store.state.isResizing=!0,this.initialMouseX=i,this.initialMouseY=r,this.initialSize.width=e.width,this.initialSize.height=e.height,this.initialSize.x=e.translateX,this.initialSize.y=e.translateY}}if("touch"===t.pointerType||"pen"===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){t.beginTransform();const i=Math.round(e.clientX-this._core.store.offsetX),r=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isResizing=!0,this.initialMouseX=i,this.initialMouseY=r,this.initialSize.width=t.width,this.initialSize.height=t.height,this.initialSize.x=t.translateX,this.initialSize.y=t.translateY,globalThis.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,r=t.clientY-this._core.store.offsetY-this.initialMouseY,s=Math.abs(i),n=Math.abs(r),o=5;if((s>o||n>o)&&(this.hasResized=!0),!this.hasResized)return;const h=e.rotation,l=Math.sin(h),a=Math.cos(h),u=e.scale||1,c=this._core.store.state.scale,f=(i*a+r*l)/c,d=(-i*l+r*a)/c,p=this.initialSize.x+this.initialSize.width/u/2+i/c/2,g=this.initialSize.y+this.initialSize.height/u/2+r/c/2;switch(this._core.store.state.resizeHandleType){case Uo.TopLeft:this.newSize.width=this.initialSize.width-f*u,this.newSize.height=this.initialSize.height-d*u;break;case Uo.TopRight:this.newSize.width=this.initialSize.width+f*u,this.newSize.height=this.initialSize.height-d*u;break;case Uo.BottomLeft:this.newSize.width=this.initialSize.width-f*u,this.newSize.height=this.initialSize.height+d*u;break;case Uo.BottomRight:this.newSize.width=this.initialSize.width+f*u,this.newSize.height=this.initialSize.height+d*u}t.shiftKey&&this.constrainToAspectRatio(),this.newSize.x=p-this.newSize.width/u/2,this.newSize.y=g-this.newSize.height/u/2,e.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}if("touch"===t.pointerType||"pen"===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),r=Math.round(t.clientY-this._core.store.offsetY),s=i-this.initialMouseX,n=r-this.initialMouseY,o=Math.abs(s),h=Math.abs(n),l=5;if((o>l||h>l)&&(globalThis.clearTimeout?.(this._core.store.state.longTouchTimeout),this.hasResized=!0),!this.hasResized)return;const a=e.rotation,u=Math.sin(a),c=Math.cos(a),f=e.scale||1,d=this._core.store.state.scale,p=(s*c+n*u)/d,g=(-s*u+n*c)/d,w=this.initialSize.x+this.initialSize.width/f/2+s/d/2,m=this.initialSize.y+this.initialSize.height/f/2+n/d/2;switch(this._core.store.state.resizeHandleType){case Uo.TopLeft:this.newSize.width=this.initialSize.width-p*f,this.newSize.height=this.initialSize.height-g*f;break;case Uo.TopRight:this.newSize.width=this.initialSize.width+p*f,this.newSize.height=this.initialSize.height-g*f;break;case Uo.BottomLeft:this.newSize.width=this.initialSize.width-p*f,this.newSize.height=this.initialSize.height+g*f;break;case Uo.BottomRight:this.newSize.width=this.initialSize.width+p*f,this.newSize.height=this.initialSize.height+g*f}this.newSize.x=w-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)}}}constrainToAspectRatio(){const t=this.initialSize.width,e=this.initialSize.height;if(0===t||0===e)return;const i=t/e,r=this.newSize.height/e;Math.abs(this.newSize.width/t-1)>Math.abs(r-1)?this.newSize.height=this.newSize.width/i:this.newSize.width=this.newSize.height*i}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&&"pen"!==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(),globalThis.clearTimeout?.(this._core.store.state.longTouchTimeout))}}class Lo extends Fo{initialRotation=0;rotation=0;initialSelectionGroupRotation=0;constructor(t){super(t)}reset(){this.initialRotation=0,this.rotation=0}handlePointerDown(t){if("mouse"===t.pointerType&&Wn.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,r=t.clientY-this._core.store.offsetY;this._core.store.state.isRotating=!0;const s=e.scale||1,n=e.translateX+e.width/2/s,o=e.translateY+e.height/2/s,h=(i-this._core.store.state.translateX)/this._core.store.state.scale,l=(r-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=e.rotation,this.initialRotation=Math.atan2(o-l,n-h)-e.rotation}}if("touch"===t.pointerType||"pen"===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),r=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isRotating=!0;const s=t.scale||1,n=t.translateX+t.width/2/s,o=t.translateY+t.height/2/s,h=(i-this._core.store.state.translateX)/this._core.store.state.scale,l=(r-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=t.rotation,this.initialRotation=Math.atan2(o-l,n-h)-t.rotation,globalThis.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,r=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=r-this.initialRotation,e.rotate(this.rotation)}}if("touch"===t.pointerType||"pen"===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),r=Math.round(t.clientY-this._core.store.offsetY),s=e.scale||1,n=Math.atan2(e.translateY+e.height/2/s-(r-this._core.store.state.translateY)/this._core.store.state.scale,e.translateX+e.width/2/s-(i-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=n-this.initialRotation,e.rotate(this.rotation),globalThis.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&&"pen"!==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(),globalThis.clearTimeout?.(this._core.store.state.longTouchTimeout))}}class _o extends n{__class__="KritzelSelectionBox";static create(t){const e=new _o;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.scale=t.store.state.scale,e.zIndex=99999,e.backgroundColor={light:"rgba(0, 122, 255, 0.2)",dark:"rgba(0, 122, 255, 0.2)"},e.borderColor={light:"rgba(0, 122, 255, 0.5)",dark:"rgba(0, 122, 255, 0.5)"},e.borderWidth=2,e.height=0,e.width=0,e}}class Ho extends Fo{startX;startY;touchStartX=0;touchStartY=0;touchStartTimeout=null;_previouslySelectedObjects=new Set;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){if(this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected)return;const e=t.shiftKey||t.ctrlKey;"mouse"===t.pointerType&&(!Wn.isLeftClick(t)||this._core.store.selectionGroup&&!e||this.startMouseSelection(t,e)),"touch"!==t.pointerType&&"pen"!==t.pointerType||(this.touchStartTimeout=setTimeout((()=>{1!==this._core.store.state.pointers.size||this._core.store.state.isScaling||this._core.store.selectionGroup&&!e||(this.startTouchSelection(t,e),this.updateTouchSelection())}),80))}handlePointerMove(t){if("mouse"===t.pointerType&&this._core.store.state.isSelecting&&this.updateMouseSelection(t),"touch"===t.pointerType||"pen"===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),r=Math.abs(e-this.touchStartX),s=Math.abs(i-this.touchStartY),n=5;(r>n||s>n)&&this._core.store.state.isSelecting&&(this.updateTouchSelection(),clearTimeout(this._core.store.state.longTouchTimeout))}}handlePointerUp(t){if("mouse"===t.pointerType&&Wn.isLeftClick(t)){const e=this._core.store.state.hasObjectsChanged,i=this._core.store.selectionGroup,r=t.shiftKey||t.ctrlKey;if(1!==i?.objects.length||!1!==e||r||i.objects[0].edit(t),this._core.store.state.hasObjectsChanged=!1,this._core.store.state.isSelecting){if(this.isSelectionClick&&this.handleSelectionClick(t),this.isSelectionDrag){const e=t.shiftKey||t.ctrlKey;this.updateMouseSelection(t),this.addSelectedObjectsToSelectionGroup(e),this.removeSelectionBox()}this._core.engine.emitObjectsChange()}}if("touch"===t.pointerType||"pen"===t.pointerType){clearTimeout(this.touchStartTimeout);const e=this._core.store.state.hasObjectsChanged,i=this._core.store.selectionGroup,r=t.shiftKey||t.ctrlKey;if(1!==i?.objects.length||!1!==e||r||i.objects[0].edit(t),this._core.store.state.hasObjectsChanged=!1,this._core.store.state.isSelecting){if(this.isSelectionClick&&this.handleSelectionClick(t),this.isSelectionDrag){const e=t.shiftKey||t.ctrlKey;this.updateTouchSelection(),this.addSelectedObjectsToSelectionGroup(e),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 _o)),this._core.store.setSelectionBox(null),this._core.store.state.objects.clearLocalSelectionBox()}startMouseSelection(t,e=!1){let i,r;i=t.clientX-this._core.store.offsetX,r=t.clientY-this._core.store.offsetY;const s=_o.create(this._core);this.startX=(i-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(r-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 _o||!e&&t instanceof Qn&&(null==t.userId||t.userId===this._core.user?.id))),this._core.store.setSelectionBox(null),e||this._core.store.setSelectionGroup(null),this._core.store.state.objects.insert(s),this._core.store.setSelectionBox(s)}startTouchSelection(t,e=!1){const i=Array.from(this._core.store.state.pointers.values())[0];if(!i)return;let r,s;r=Math.round(i.clientX-this._core.store.offsetX),s=Math.round(i.clientY-this._core.store.offsetY),this.touchStartX=r,this.touchStartY=s;const n=_o.create(this._core);this.startX=(r-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(s-this._core.store.state.translateY)/this._core.store.state.scale,n.translateX=this.startX,n.translateY=this.startY,this._core.store.state.isSelecting=!0,this._core.store.state.objects.remove((t=>t instanceof _o||!e&&t instanceof Qn&&(null==t.userId||t.userId===this._core.user?.id))),this._core.store.setSelectionBox(null),e||this._core.store.setSelectionGroup(null),this._core.store.state.objects.insert(n),this._core.store.setSelectionBox(n)}updateMouseSelection(t){let e,i;e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;const r=this._core.store.selectionBox;if(r){const t=(e-this._core.store.state.translateX)/r.scale,s=(i-this._core.store.state.translateY)/r.scale,n=Math.abs(t-this.startX)*r.scale,o=Math.abs(s-this.startY)*r.scale;r.width=n,r.height=o,r.translateX=Math.min(t,this.startX),r.translateY=Math.min(s,this.startY),this._core.store.state.objects.setLocalSelectionBox({x:r.translateX,y:r.translateY,width:n/r.scale,height:o/r.scale}),n>0||o>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 r=this._core.store.selectionBox;if(r){const t=(e-this._core.store.state.translateX)/r.scale,s=(i-this._core.store.state.translateY)/r.scale,n=Math.abs(t-this.startX)*r.scale,o=Math.abs(s-this.startY)*r.scale;r.width=n,r.height=o,r.translateX=Math.min(t,this.startX),r.translateY=Math.min(s,this.startY),this._core.store.state.objects.setLocalSelectionBox({x:r.translateX,y:r.translateY,width:n/r.scale,height:o/r.scale}),n>0||o>0?this.updateSelectedObjects():this.clearSelectionPreview()}}updateSelectedObjects(){const t=this._core.store.selectionBox;if(!t)return;const e=t.rotatedPolygon,i=[e.topLeft.x,e.topRight.x,e.bottomRight.x,e.bottomLeft.x],r=[e.topLeft.y,e.topRight.y,e.bottomRight.y,e.bottomLeft.y],s=Math.min(...i),n=Math.max(...i),o=Math.min(...r),h=Math.max(...r),l=this._core.store.state.objects.query({x:s,y:o,z:t.scale,width:n-s,height:h-o}),a=new Set;for(const t of l){if(t instanceof _o||t instanceof Qn)continue;const i=t.hitTestPolygon(e);t.isSelected=i,i&&a.add(t)}for(const t of this._previouslySelectedObjects)a.has(t)||(t.isSelected=!1);this._previouslySelectedObjects=a}handleSelectionClick(t){const e=this.getTopmostHitObject(t),i=t.shiftKey||t.ctrlKey;this.clearSelectionPreview(),this.addObjectToSelectionGroup(e,i),this.removeSelectionBox()}getTopmostHitObject(t){const e=this._core.store.state.pointerX,i=this._core.store.state.pointerY,r=this._core.getObjectsFromPointerEvent(t,".object");for(const t of r)if(!(t instanceof _o||t instanceof Qn)&&t.hitTest(e,i))return t;return null}clearSelectionPreview(){for(const t of this._previouslySelectedObjects)t.isSelected=!1;this._previouslySelectedObjects.clear()}addObjectToSelectionGroup(t,e=!1){if(!t)return;const i=Xn.findParentGroup(this._core,t.id)||t;i.isSelected=!1;const r=this._core.store.selectionGroup;if(e&&r)r.addOrRemove(i),0===r.objects.length?this._core.removeSelectionGroup():this._core.rerender();else{const t=Qn.create(this._core);t.addOrRemove(i),t.isSelected=!0,this._core.addSelectionGroup(t),this._core.rerender()}}addSelectedObjectsToSelectionGroup(t=!1){const e=this._core.store.selectedObjects;if(0===e.length)return;const i=this._core.store.state.objects.filter((t=>"KritzelGroup"===t.__class__)),r=new Map;for(const t of i)for(const e of t.childIds)r.set(e,t);const s=new Map;for(const t of e){const e=r.get(t.id)||t;s.set(e.id,e),t.isSelected=!1}const n=Array.from(s.values()),o=this._core.store.selectionGroup;if(t&&o)o.addObjects(n),this._core.rerender();else{const t=Qn.create(this._core);t.objectIds=Array.from(s.keys()),1===t.length&&(t.rotation=t.objects[0].rotation),t.captureUnchangedSnapshots(),t.refreshObjectDimensions(),t.isSelected=!0,this._core.addSelectionGroup(t),this._core.rerender()}}}class Xo extends Fo{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 Yo extends Fo{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&&Wn.isLeftClick(t)&&this.startHandleDrag(t),("touch"===t.pointerType||"pen"===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,r=t.clientY-this._core.store.offsetY;this._core.store.state.isLineHandleDragging=!0,this.initialMouseX=i,this.initialMouseY=r,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 s=this._core.store.state.lineHandleType;"start"!==s&&"end"!==s||this._core.anchorManager.removeAnchor(e.id,s),globalThis.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,r=t.clientY-this._core.store.offsetY,s=i-this.initialMouseX,n=r-this.initialMouseY;if((Math.abs(s)>3||Math.abs(n)>3)&&(this.hasMoved=!0),!this.hasMoved)return;const o=this._core.store.state.scale,h=e.scale||1,l=e.rotation,a=s/o,u=n/o,c=Math.cos(-l),f=Math.sin(-l),d=(a*c-u*f)*h,p=(a*f+u*c)*h,g=this._core.store.state.lineHandleType;if("start"===g){const t=(i-this._core.store.state.translateX)/o,s=(r-this._core.store.state.translateY)/o,n=e.endAnchor?.objectId,h=this._core.anchorManager.findSnapTarget(t,s,e.id,n);if(this.currentSnapTarget=h,h){const t=this.worldToLineLocal(e,h.centerX,h.centerY);this.updateLineEndpoint(e,t.x,t.y,this.initialEndX,this.initialEndY);const i=this.lineLocalToWorld(e,this.initialEndX,this.initialEndY),r=this._core.store.allNonSelectionObjects.find((t=>t.id===h.objectId));let s,n,o,l;if(r){const t=this._core.anchorManager.computeAnchorClipInfo(e,"start",r);t&&(s=t.worldX,n=t.worldY,o=t.t)}void 0!==e.controlX&&void 0!==e.controlY&&(l=this.lineLocalToWorld(e,e.controlX,e.controlY)),this._core.anchorManager.setSnapCandidate({objectId:h.objectId,endpoint:"start",centerX:h.centerX,centerY:h.centerY,lineEndpointX:i.x,lineEndpointY:i.y,controlX:l?.x,controlY:l?.y,t:o,edgeX:s,edgeY:n,lineStroke:Dn.resolveThemeColor(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"===g){const t=(i-this._core.store.state.translateX)/o,s=(r-this._core.store.state.translateY)/o,n=e.startAnchor?.objectId,h=this._core.anchorManager.findSnapTarget(t,s,e.id,n);if(this.currentSnapTarget=h,h){const t=this.worldToLineLocal(e,h.centerX,h.centerY);this.updateLineEndpoint(e,this.initialStartX,this.initialStartY,t.x,t.y);const i=this.lineLocalToWorld(e,this.initialStartX,this.initialStartY),r=this._core.store.allNonSelectionObjects.find((t=>t.id===h.objectId));let s,n,o,l;if(r){const t=this._core.anchorManager.computeAnchorClipInfo(e,"end",r);t&&(s=t.worldX,n=t.worldY,o=t.t)}void 0!==e.controlX&&void 0!==e.controlY&&(l=this.lineLocalToWorld(e,e.controlX,e.controlY)),this._core.anchorManager.setSnapCandidate({objectId:h.objectId,endpoint:"end",centerX:h.centerX,centerY:h.centerY,lineEndpointX:i.x,lineEndpointY:i.y,controlX:l?.x,controlY:l?.y,t:o,edgeX:s,edgeY:n,lineStroke:Dn.resolveThemeColor(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"===g){const t=(this.initialControlX??(this.initialStartX+this.initialEndX)/2)+2*d,i=(this.initialControlY??(this.initialStartY+this.initialEndY)/2)+2*p,r=e.startX,s=e.startY,n=e.endX,o=e.endY,h=n-r,l=o-s,a=h*h+l*l;let u,c,f=-1;0!==a&&(f=((t-r)*h+(i-s)*l)/a),f<0?(u=r,c=s):f>1?(u=n,c=o):(u=r+f*h,c=s+f*l);const g=t-u,w=i-c;Math.sqrt(g*g+w*w)<15?e.updateControlPoint(void 0,void 0):e.updateControlPoint(t,i)}this._core.rerender()}worldToLineLocal(t,e,i){const r=(e-t.translateX)*t.scale,s=(i-t.translateY)*t.scale,n=t.totalWidth/2,o=t.totalHeight/2,h=Math.cos(-t.rotation),l=Math.sin(-t.rotation);return{x:(r-n)*h-(s-o)*l+n+t.x,y:(r-n)*l+(s-o)*h+o+t.y}}lineLocalToWorld(t,e,i){const r=e-t.x,s=i-t.y,n=t.totalWidth/2,o=t.totalHeight/2,h=Math.cos(t.rotation),l=Math.sin(t.rotation);return{x:((r-n)*h-(s-o)*l+n)/t.scale+t.translateX,y:((r-n)*l+(s-o)*h+o)/t.scale+t.translateY}}updateLineEndpoint(t,e,i,r,s){const{minX:n,minY:o,maxX:h,maxY:l}=_n.calculateBoundingBox(e,i,r,s,t.controlX,t.controlY,t.strokeWidth),a=h-n,u=l-o,{minX:c,minY:f,maxX:d,maxY:p}=_n.calculateBoundingBox(this.initialStartX,this.initialStartY,this.initialEndX,this.initialEndY,this.initialControlX,this.initialControlY,t.strokeWidth),g=d-c,w=p-f,m=n-c+(a-g)/2,v=o-f+(u-w)/2,y=t.rotation,k=Math.cos(y),b=Math.sin(y),M=1/t.scale,x=this.initialTranslateX+M*(g-a)/2+M*(m*k-v*b),C=this.initialTranslateY+M*(w-u)/2+M*(m*b+v*k);t.startX=e,t.startY=i,t.endX=r,t.endY=s,t.x=n,t.y=o,t.width=a,t.height=u,t.translateX=x,t.translateY=C,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 _n?e:null}}class Wo extends Vn{selectionHandler;moveHandler;hoverHandler;resizeHandler;rotationHandler;lineHandleHandler;palette=[...An];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)Hn.isInstanceOf(i,"KritzelGroup")?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 An[0];for(const e of t){if(e instanceof zn)return e.fill;if(e instanceof _n)return e.stroke;if(e instanceof Pn)return e.fontColor;if(e instanceof Yn)return e.strokeColor}return An[0]}set color(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof zn&&this._core.updateObject(e,{fill:t}),e instanceof _n&&this._core.updateObject(e,{stroke:t}),e instanceof Pn&&this._core.updateObject(e,{fontColor:t}),e instanceof Yn&&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 zn)return e.strokeWidth;if(e instanceof _n)return e.strokeWidth;if(e instanceof Pn)return e.fontSize;if(e instanceof Yn)return e.strokeWidth}return 1}set size(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof zn&&this._core.updateObject(e,{strokeWidth:t}),e instanceof _n&&this._core.updateObject(e,{strokeWidth:t}),e instanceof Pn&&this._core.updateObject(e,{fontSize:t}),e instanceof Yn&&this._core.updateObject(e,{strokeWidth:t})})),this._core.rerender(),this.refreshSelectionGroupDimensions()}get fillColor(){const t=this.flattenObjects(this.getSelectedObjects());for(const e of t)if(e instanceof Yn)return e.fillColor;return{light:"transparent",dark:"transparent"}}set fillColor(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{if(e instanceof Yn){const i=Dn.determineTextColor(t);this._core.updateObject(e,{fillColor:t,fontColor:i}),("string"==typeof t?"transparent"===t:"transparent"===t.light&&"transparent"===t.dark)||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 Pn)return e.fontFamily;if(e instanceof Yn)return e.fontFamily}return"Arial"}set fontFamily(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Pn&&this._core.updateObject(e,{fontFamily:t}),e instanceof Yn&&this._core.updateObject(e,{fontFamily:t})})),this._core.rerender(),this.refreshSelectionGroupDimensions()}get arrows(){const t=this.flattenObjects(this.getSelectedObjects());for(const e of t)if(e instanceof _n)return e.arrows;return{start:{enabled:!1},end:{enabled:!1}}}set arrows(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof _n&&this._core.updateObject(e,{arrows:t})})),this._core.rerender(),this.refreshSelectionGroupDimensions()}getToolConfig(){if(!this.hasSelection())return null;const t=this.flattenObjects(this.getSelectedObjects()),e=[],i=t.some((t=>t instanceof Yn)),r=t.some((t=>t instanceof Pn)),s=t.some((t=>t instanceof _n)),n=t.some((t=>t instanceof Ln)),o=t.some((t=>t instanceof zn||t instanceof _n||t instanceof Yn));return!n||i||r||s||o?(r&&!o?(e.push({type:"font-size",propertyName:"size"}),e.push({type:"font-family",propertyName:"fontFamily"})):o&&!r?e.push({type:"stroke-size",propertyName:"size"}):(o&&e.push({type:"stroke-size",propertyName:"size"}),r&&e.push({type:"font-family",propertyName:"fontFamily"})),s&&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}):{type:"selection",colorProperty:"color",sizeProperty:"size",opacityProperty:"opacity",paletteSource:"none",controls:[]}}refreshSelectionGroupDimensions(){const t=this._core.store.selectionGroup;t&&requestAnimationFrame((()=>{requestAnimationFrame((()=>{t.refreshObjectDimensions(),this._core.rerender()}))}))}constructor(t){super(t),this.selectionHandler=new Ho(this._core),this.moveHandler=new No(this._core),this.hoverHandler=new Xo(this._core),this.resizeHandler=new zo(this._core),this.rotationHandler=new Lo(this._core),this.lineHandleHandler=new Yo(this._core)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){if(Wn.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||t.shiftKey||t.ctrlKey||(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||"pen"===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,r=e&&i&&e.id!==i.id,s=t.shiftKey||t.ctrlKey;!i&&e&&(this._core.store.state.skipContextMenu=!0),null!==e&&!r||!i||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||s||(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||"pen"===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||"pen"===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:r,y:s}=this._core.getCanvasPoint(t);if(!i.hitTest(r,s))return null;if(i instanceof Qn)return i;{const t=Qn.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]}}class Vo{type="local";provider;isConnected=!1;constructor(e,i,r){this.provider=new t(r?.name||e,i)}async connect(){if(!this.isConnected)return new Promise((t=>{this.provider.on("synced",(()=>{this.isConnected=!0,t()}))}))}disconnect(){this.isConnected=!1}async reconnect(){return this.disconnect(),this.connect()}destroy(){this.provider&&this.provider.destroy(),this.isConnected=!1}}const Jo=Math.floor,Qo=127,Ko=Number.MAX_SAFE_INTEGER,qo="undefined"!=typeof TextEncoder?new TextEncoder:null,Go=qo?t=>qo.encode(t):t=>{const e=unescape(encodeURIComponent(t)),i=e.length,r=new Uint8Array(i);for(let t=0;t<i;t++)r[t]=e.codePointAt(t);return r};let Zo="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Zo&&1===Zo.decode(new Uint8Array).length&&(Zo=null);const th=(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},eh=(t,e)=>{for(;e>Qo;)th(t,128|Qo&e),e=Jo(e/128);th(t,Qo&e)},ih=new Uint8Array(3e4),rh=ih.length/3,sh=qo&&qo.encodeInto?(t,e)=>{if(e.length<rh){const i=qo.encodeInto(e,ih).written||0;eh(t,i);for(let e=0;e<i;e++)th(t,ih[e])}else nh(t,Go(e))}:(t,e)=>{const i=unescape(encodeURIComponent(e)),r=i.length;eh(t,r);for(let e=0;e<r;e++)th(t,i.codePointAt(e))},nh=(t,e)=>{eh(t,e.byteLength),((t,e)=>{const i=t.cbuf.length,r=t.cpos,s=((t,e)=>t<e?t:e)(i-r,e.length),n=e.length-s;t.cbuf.set(e.subarray(0,s),r),t.cpos+=s,n>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(((t,e)=>t>e?t:e)(2*i,n)),t.cbuf.set(e.subarray(s)),t.cpos=n)})(t,e)},oh=t=>new Error(t),hh=oh("Unexpected end of array"),lh=oh("Integer out of Range"),ah=t=>t.arr[t.pos++],uh=t=>{let e=0,i=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(e+=(r&Qo)*i,i*=128,r<128)return e;if(e>Ko)throw lh}throw hh},ch=Zo?t=>Zo.decode((t=>((t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,i})(t,uh(t)))(t)):t=>{let e=uh(t);if(0===e)return"";{let i=String.fromCodePoint(ah(t));if(--e<100)for(;e--;)i+=String.fromCodePoint(ah(t));else for(;e>0;){const r=e<1e4?e:1e4,s=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,i+=String.fromCodePoint.apply(null,s),e-=r}return decodeURIComponent(escape(i))}};var fh;!function(t){t[t.Token=0]="Token",t[t.PermissionDenied=1]="PermissionDenied",t[t.Authenticated=2]="Authenticated"}(fh||(fh={}));const dh=t=>Array.from(t.entries()).map((([t,e])=>({clientId:t,...e})));var ph;async function gh(t){return new Promise((e=>setTimeout(e,t)))}function wh(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),r=Math.floor(i);i=Math.floor(Math.random()*(r-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"}(ph||(ph={}));const mh=Math.floor,vh=128,yh=127,kh=Number.MAX_SAFE_INTEGER,bh=()=>new Set,Mh=Array.from,xh="undefined"!=typeof TextEncoder?new TextEncoder:null,Ch=xh?t=>xh.encode(t):t=>{const e=unescape(encodeURIComponent(t)),i=e.length,r=new Uint8Array(i);for(let t=0;t<i;t++)r[t]=e.codePointAt(t);return r};let Ah="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Ah&&1===Ah.decode(new Uint8Array).length&&(Ah=null);class Sh{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Bh=()=>new Sh,Th=t=>{let e=t.cpos;for(let i=0;i<t.bufs.length;i++)e+=t.bufs[i].length;return e},Oh=t=>{const e=new Uint8Array(Th(t));let i=0;for(let r=0;r<t.bufs.length;r++){const s=t.bufs[r];e.set(s,i),i+=s.length}return e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),i),e},Eh=(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},Ih=(t,e)=>{for(;e>yh;)Eh(t,vh|yh&e),e=mh(e/128);Eh(t,yh&e)},Dh=new Uint8Array(3e4),Ph=Dh.length/3,$h=xh&&xh.encodeInto?(t,e)=>{if(e.length<Ph){const i=xh.encodeInto(e,Dh).written||0;Ih(t,i);for(let e=0;e<i;e++)Eh(t,Dh[e])}else Rh(t,Ch(e))}:(t,e)=>{const i=unescape(encodeURIComponent(e)),r=i.length;Ih(t,r);for(let e=0;e<r;e++)Eh(t,i.codePointAt(e))},Rh=(t,e)=>{Ih(t,e.byteLength),((t,e)=>{const i=t.cbuf.length,r=t.cpos,s=((t,e)=>t<e?t:e)(i-r,e.length),n=e.length-s;t.cbuf.set(e.subarray(0,s),r),t.cpos+=s,n>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(((t,e)=>t>e?t:e)(2*i,n)),t.cbuf.set(e.subarray(s)),t.cpos=n)})(t,e)},jh=t=>new Error(t),Fh=jh("Unexpected end of array"),Nh=jh("Integer out of Range");class Uh{constructor(t){this.arr=t,this.pos=0}}const zh=t=>new Uh(t),Lh=t=>((t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,i})(t,Hh(t)),_h=t=>t.arr[t.pos++],Hh=t=>{let e=0,i=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(e+=(r&yh)*i,i*=128,r<vh)return e;if(e>kh)throw Nh}throw Fh},Xh=Ah?t=>Ah.decode(Lh(t)):t=>{let e=Hh(t);if(0===e)return"";{let i=String.fromCodePoint(_h(t));if(--e<100)for(;e--;)i+=String.fromCodePoint(_h(t));else for(;e>0;){const r=e<1e4?e:1e4,s=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,i+=String.fromCodePoint.apply(null,s),e-=r}return decodeURIComponent(escape(i))}},Yh=Date.now,Wh=()=>new Map;class Vh{constructor(){this._observers=Wh()}on(t,e){((t,e,i)=>{let r=t.get(e);return void 0===r&&t.set(e,r=i()),r})(this._observers,t,bh).add(e)}once(t,e){const i=(...r)=>{this.off(t,i),e(...r)};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 Mh((this._observers.get(t)||Wh()).values()).forEach((t=>t(...e)))}destroy(){this._observers=Wh()}}const Jh=Object.keys,Qh=t=>Jh(t).length,Kh=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),qh=(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)||!qh(t.get(i),e.get(i)))return!1;break;case Object:if(Qh(t)!==Qh(e))return!1;for(const i in t)if(!Kh(t,i)||!qh(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(!qh(t[i],e[i]))return!1;break;default:return!1}return!0};class Gh extends Vh{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const t=Yh();null!==this.getLocalState()&&15e3<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const e=[];this.meta.forEach(((i,r)=>{r!==this.clientID&&3e4<=t-i.lastUpdated&&this.states.has(r)&&e.push(r)})),e.length>0&&Zh(this,e,"timeout")}),mh(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),r=void 0===i?0:i.clock+1,s=this.states.get(e);null===t?this.states.delete(e):this.states.set(e,t),this.meta.set(e,{clock:r,lastUpdated:Yh()});const n=[],o=[],h=[],l=[];null===t?l.push(e):null==s?null!=t&&n.push(e):(o.push(e),qh(s,t)||h.push(e)),(n.length>0||h.length>0||l.length>0)&&this.emit("change",[{added:n,updated:h,removed:l},"local"]),this.emit("update",[{added:n,updated:o,removed:l},"local"])}setLocalStateField(t,e){const i=this.getLocalState();null!==i&&this.setLocalState({...i,[t]:e})}getStates(){return this.states}}const Zh=(t,e,i)=>{const r=[];for(let i=0;i<e.length;i++){const s=e[i];if(t.states.has(s)){if(t.states.delete(s),s===t.clientID){const e=t.meta.get(s);t.meta.set(s,{clock:e.clock+1,lastUpdated:Yh()})}r.push(s)}}r.length>0&&(t.emit("change",[{added:[],updated:[],removed:r},i]),t.emit("update",[{added:[],updated:[],removed:r},i]))},tl=(t,e,i=t.states)=>{const r=e.length,s=Bh();Ih(s,r);for(let n=0;n<r;n++){const r=e[n],o=i.get(r)||null,h=t.meta.get(r).clock;Ih(s,r),Ih(s,h),$h(s,JSON.stringify(o))}return Oh(s)};class el{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 il{constructor(t){this.data=t,this.encoder=Bh(),this.decoder=zh(new Uint8Array(this.data))}peekVarString(){return(t=>{const e=t.pos,i=Xh(t);return t.pos=e,i})(this.decoder)}readVarUint(){return Hh(this.decoder)}readVarString(){return Xh(this.decoder)}readVarUint8Array(){return Lh(this.decoder)}writeVarUint(t){return Ih(this.encoder,t)}writeVarString(t){return $h(this.encoder,t)}writeVarUint8Array(t){return Rh(this.encoder,t)}length(){return Th(this.encoder)}}var rl,sl;!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"}(rl||(rl={})),function(t){t.Connecting="connecting",t.Connected="connected",t.Disconnected="disconnected"}(sl||(sl={}));class nl{constructor(){this.encoder=Bh()}get(t){return t.encoder}toUint8Array(){return Oh(this.encoder)}}class ol extends nl{constructor(){super(...arguments),this.type=rl.CLOSE,this.description="Ask the server to close the connection"}get(t){return $h(this.encoder,t.documentName),Ih(this.encoder,this.type),this.encoder}}class hl extends el{constructor(t){super(),this.messageQueue=[],this.configuration={url:"",autoConnect:!0,preserveTrailingSlash:!1,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=sl.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=sl.Connected,this.emit("status",{status:sl.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=t}attach(t){this.configuration.providerMap.set(t.configuration.name,t),this.status===sl.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===sl.Connected&&t.onOpen(this.receivedOnOpenPayload)}detach(t){this.configuration.providerMap.has(t.configuration.name)&&(t.send(ol,{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===sl.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 r={attemptNum:0,attemptsRemaining:i.maxAttempts?i.maxAttempts:-1,aborted:!1,abort(){r.aborted=!0}},s=i.calculateDelay||wh,n=i.calculateDelay?i.calculateDelay(r,i):i.initialDelay;if(n&&await gh(n),r.attemptNum<1&&i.initialJitter){const t=s(r,i);t&&await gh(t)}return async function e(){if(i.beforeAttempt&&i.beforeAttempt(r,i),r.aborted){const t=new Error("Attempt aborted");throw t.code="ATTEMPT_ABORTED",t}const n=async t=>{if(i.handleError&&await i.handleError(t,r,i),r.aborted||0===r.attemptsRemaining)throw t;r.attemptNum++;const n=s(r,i);return n&&await gh(n),e()};return r.attemptsRemaining>0&&r.attemptsRemaining--,i.timeout?new Promise(((e,s)=>{const o=setTimeout((()=>{if(i.handleTimeout)try{e(i.handleTimeout(r,i))}catch(t){s(t)}else{const t=new Error(`Retry timeout (attemptNum: ${r.attemptNum}, timeout: ${i.timeout})`);t.code="ATTEMPT_TIMEOUT",s(t)}}),i.timeout);t(r,i).then((t=>{clearTimeout(o),e(t)})).catch((t=>{clearTimeout(o),n(t).then(e).catch(s)}))})):t(r,i).catch(n)}()}(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 r=this.webSocketHandlers[t.identifier];Object.keys(r).forEach((e=>{t.addEventListener(e,r[e])}))}cleanupWebSocket(){if(!this.webSocket)return;const{identifier:t}=this.webSocket,e=this.webSocketHandlers[t];Object.keys(e).forEach((i=>{var r;null===(r=this.webSocket)||void 0===r||r.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=sl.Connecting,this.emit("status",{status:sl.Connecting}),this.connectionAttempt={resolve:t,reject:e}}))}onMessage(t){var e;this.resolveConnectionAttempt(),this.lastMessageReceived=Yh();const i=new il(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=sl.Connected,this.emit("status",{status:sl.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===sl.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=Yh()-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(){if(this.configuration.preserveTrailingSlash)return this.configuration.url;let t=this.configuration.url;for(;"/"===t[t.length-1];)t=t.slice(0,t.length-1);return t}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)===ph.Open?this.webSocket.send(t):this.messageQueue.push(t)}onClose({event:t}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=sl.Disconnected,this.emit("status",{status:sl.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 ll=(t,i,r)=>{try{e.applyUpdate(i,Lh(t),r)}catch(t){console.error("Caught error while handling a Yjs update",t)}},al=ll;class ul{constructor(t){this.message=t}apply(t,e){const{message:i}=this,r=i.readVarUint(),s=i.length();switch(r){case rl.Sync:this.applySyncMessage(t,e);break;case rl.Awareness:this.applyAwarenessMessage(t);break;case rl.Auth:this.applyAuthMessage(t);break;case rl.QueryAwareness:this.applyQueryAwarenessMessage(t);break;case rl.Stateless:t.receiveStateless(Xh(i.decoder));break;case rl.SyncStatus:this.applySyncStatusMessage(t,1===(t=>{let e=t.arr[t.pos++],i=63&e,r=64;const s=(64&e)>0?-1:1;if(!(e&vh))return s*i;const n=t.arr.length;for(;t.pos<n;){if(e=t.arr[t.pos++],i+=(e&yh)*r,r*=128,e<vh)return s*i;if(i>kh)throw Nh}throw Fh})(i.decoder));break;case rl.CLOSE:const s={code:1e3,reason:Xh(i.decoder),target:t.configuration.websocketProvider.webSocket,type:"close"};t.onClose(),t.configuration.onClose({event:s}),t.forwardClose({event:s});break;default:throw new Error(`Can’t apply message of unknown type: ${r}`)}i.length()>s+1&&t.send(nl,{encoder:i.encoder})}applySyncMessage(t,i){const{message:r}=this;r.writeVarUint(rl.Sync);const s=((t,i,r,s)=>{const n=Hh(t);switch(n){case 0:((t,i,r)=>{((t,i,r)=>{Ih(t,1),Rh(t,e.encodeStateAsUpdate(i,r))})(i,r,Lh(t))})(t,i,r);break;case 1:ll(t,r,s);break;case 2:al(t,r,s);break;default:throw new Error("Unknown message type")}return n})(r.decoder,r.encoder,t.document,t);i&&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 r=zh(e),s=Yh(),n=[],o=[],h=[],l=[],a=Hh(r);for(let e=0;e<a;e++){const e=Hh(r);let i=Hh(r);const a=JSON.parse(Xh(r)),u=t.meta.get(e),c=t.states.get(e),f=void 0===u?0:u.clock;(f<i||f===i&&null===a&&t.states.has(e))&&(null===a?e===t.clientID&&null!=t.getLocalState()?i++:t.states.delete(e):t.states.set(e,a),t.meta.set(e,{clock:i,lastUpdated:s}),void 0===u&&null!==a?n.push(e):void 0!==u&&null===a?l.push(e):null!==a&&(qh(a,c)||h.push(e),o.push(e)))}(n.length>0||h.length>0||l.length>0)&&t.emit("change",[{added:n,updated:h,removed:l},i]),(n.length>0||o.length>0||l.length>0)&&t.emit("update",[{added:n,updated:o,removed:l},i])})(t.awareness,e.readVarUint8Array(),t)}applyAuthMessage(t){const{message:e}=this;((t,e,i,r)=>{switch(uh(t)){case fh.Token:e();break;case fh.PermissionDenied:i(ch(t));break;case fh.Authenticated:r(ch(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(rl.Awareness),e.writeVarUint8Array(tl(t.awareness,Array.from(t.awareness.getStates().keys())))}}class cl{constructor(t,e={}){this.message=new t,this.encoder=this.message.get(e)}create(){return Oh(this.encoder)}send(t){null==t||t.send(this.create())}}class fl extends nl{constructor(){super(...arguments),this.type=rl.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 $h(this.encoder,t.documentName),Ih(this.encoder,this.type),i=t.token,eh(e=this.encoder,fh.Token),sh(e,i),this.encoder}}class dl extends nl{constructor(){super(...arguments),this.type=rl.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 $h(this.encoder,t.documentName),Ih(this.encoder,this.type),e=void 0===t.states?tl(t.awareness,t.clients):tl(t.awareness,t.clients,t.states),Rh(this.encoder,e),this.encoder}}class pl extends nl{constructor(){super(...arguments),this.type=rl.Stateless,this.description="A stateless message"}get(t){var e;return $h(this.encoder,t.documentName),Ih(this.encoder,this.type),$h(this.encoder,null!==(e=t.payload)&&void 0!==e?e:""),this.encoder}}class gl extends nl{constructor(){super(...arguments),this.type=rl.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 $h(this.encoder,t.documentName),Ih(this.encoder,this.type),((t,i)=>{Ih(t,0);const r=e.encodeStateVector(i);Rh(t,r)})(this.encoder,t.document),this.encoder}}class wl extends nl{constructor(){super(...arguments),this.type=rl.Sync,this.description="A document update"}get(t){var e,i;return $h(this.encoder,t.documentName),Ih(this.encoder,this.type),i=t.update,Ih(e=this.encoder,2),Rh(e,i),this.encoder}}class ml extends Error{constructor(){super(...arguments),this.code=1001}}class vl extends el{constructor(t){var i,r,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 e.Doc,this.configuration.awareness=void 0!==t.awareness?t.awareness:new Gh(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===(i=this.awareness)||void 0===i||i.on("update",(()=>{this.emit("awarenessUpdate",{states:dh(this.awareness.getStates())})})),null===(r=this.awareness)||void 0===r||r.on("change",(()=>{this.emit("awarenessChange",{states:dh(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={}){t.websocketProvider||(this.manageSocket=!0,this.configuration.websocketProvider=new hl(t)),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(gl,{document:this.document,documentName:this.configuration.name})}pageHide(){this.awareness&&Zh(this.awareness,[this.document.clientID],"page hide")}registerEventListeners(){"undefined"!=typeof window&&"addEventListener"in window&&window.addEventListener("pagehide",this.boundPageHide)}sendStateless(t){this.send(pl,{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(fl,{token:null!=t?t:"",documentName:this.configuration.name})}documentUpdateHandler(t,e){e!==this&&(this.incrementUnsyncedChanges(),this.send(wl,{update:t,documentName:this.configuration.name}))}awarenessUpdateHandler({added:t,updated:e,removed:i},r){const s=t.concat(e).concat(i);this.send(dl,{awareness:this.awareness,clients:s,documentName:this.configuration.name})}get synced(){return this.isSynced}set synced(t){this.isSynced!==t&&(this.isSynced=t,t&&this.emit("synced",{state:t}))}receiveStateless(t){this.emit("stateless",{payload:t})}async connect(){if(this.manageSocket)return this.configuration.websocketProvider.connect();console.warn("HocuspocusProvider::connect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.")}disconnect(){if(this.manageSocket)return this.configuration.websocketProvider.disconnect();console.warn("HocuspocusProvider::disconnect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.")}async onOpen(t){this.isAuthenticated=!1,this.emit("open",{event:t}),await this.sendToken(),this.startSync()}async getToken(){return"function"==typeof this.configuration.token?await this.configuration.token():this.configuration.token}startSync(){this.resetUnsyncedChanges(),this.send(gl,{document:this.document,documentName:this.configuration.name}),this.awareness&&null!==this.awareness.getLocalState()&&this.send(dl,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.configuration.name})}send(t,e){if(!this._isAttached)return;const i=new cl(t,e);this.emit("outgoingMessage",{message:i.message}),i.send(this.configuration.websocketProvider)}onMessage(t){const e=new il(t.data),i=e.readVarString();e.writeVarString(i),this.emit("message",{event:t,message:new il(t.data)}),new ul(e).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&Zh(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&&(Zh(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 ml(`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)}}const yl="1.2.0";class kl{__class__="KritzelWorkspace";id;name;createdAt;updatedAt;viewport;isPublic;_core;constructor(t,e,i={centerWorldX:0,centerWorldY:0,scale:1}){this.id=t,this.name=e,this.createdAt=new Date,this.updatedAt=new Date,this.viewport=i,this.isPublic=!1}static create(t,e){const i=new kl(e.id,e.name,e.viewport);return i._core=t,i}addObject(t){this._core.engine.addObject(t)}serialize(t){const e={__class__:this.__class__,version:yl,id:this.id,name:this.name,createdAt:this.createdAt.toISOString(),updatedAt:this.updatedAt.toISOString(),viewport:this.viewport,isPublic:this.isPublic};return t?.includeObjects&&this._core&&(e.objects=this._core.store.allNonSelectionObjects.map((t=>t.serialize()))),e}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}deserialize(t){return Object.assign(this,t),this.createdAt=new Date(t.createdAt),this.updatedAt=new Date(t.updatedAt),this}}class bl{_core;_anchorIndex=new Map;constructor(t){this._core=t}setAnchor(t,e,i){const r=this.getLineById(t);if(!r)return;if("start"===e&&r.endAnchor?.objectId===i)return;if("end"===e&&r.startAnchor?.objectId===i)return;this.removeAnchor(t,e);const s={objectId:i};"start"===e?r.startAnchor=s:r.endAnchor=s,this.addToIndex(i,t,e),this.snapEndpointToObject(r,e,i),this._core.store.state.objects.update(r)}removeAnchor(t,e){const i=this.getLineById(t);if(!i)return;const r="start"===e?i.startAnchor:i.endAnchor;r&&(this.removeFromIndex(r.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 r=this.getObjectById(i);if(!r)return;const s=this.worldToLineLocal(t,r.centerX,r.centerY);t.updateEndpoint(e,s.x,s.y)}worldToLineLocal(t,e,i){const r=e-t.centerX,s=i-t.centerY,n=Math.cos(-t.rotation),o=Math.sin(-t.rotation);return{x:(r*n-s*o+t.totalWidth/2/t.scale)*t.scale+t.x,y:(r*o+s*n+t.totalHeight/2/t.scale)*t.scale+t.y}}findSnapTarget(t,e,i,r){let n=null,o=-1/0;const h=this._core.store.allNonSelectionObjects;for(const l of h){if(l.id===i)continue;if(r&&l.id===r)continue;if(!this.isAnchorable(l))continue;const h=l.rotatedPolygon;s.isPointInPolygon({x:t,y:e},[h.topLeft,h.topRight,h.bottomRight,h.bottomLeft])&&l.zIndex>o&&(o=l.zIndex,n={objectId:l.id,centerX:l.centerX,centerY:l.centerY})}return n}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(!Hn.isInstanceOf(e,"KritzelLine"))return null;const i=e,r=this.computeAnchorVisualization(i,"start"),s=this.computeAnchorVisualization(i,"end"),n=this.isFiniteAnchorVisualization(r)?r:null,o=this.isFiniteAnchorVisualization(s)?s:null;if(!n&&!o)return null;const h=this.getSafeScale(this._core.store.state.scale),l=this.getSafeScale(i.scale),a=i.strokeWidth/l,u=""+2/h,c=Math.max(2*a,4/h),f=`${c} ${c}`,d=8/h;return this.areFiniteNumbers(a,c,d)?{lineStrokeWidth:a,indicatorStrokeWidth:u,dashArray:f,indicatorRadius:d,startAnchorViz:n,endAnchorViz:o}:null}getSnapIndicatorRenderData(){const t=this.getSnapCandidate();if(!t)return null;if(!this.areFiniteNumbers(t.centerX,t.centerY,t.lineEndpointX,t.lineEndpointY))return null;const e=this.getSafeScale(this._core.store.state.scale),i=8/e,r=""+2/e,s=this.areFiniteNumbers(t.lineStrokeWidth)&&t.lineStrokeWidth>0?t.lineStrokeWidth:4/e,n=`${s}`,o=Math.max(2*s,4/e),h=`${o} ${o}`,l=t.lineStroke||"#000000";let a,u=this.areFiniteNumbers(t.edgeX)?t.edgeX:void 0,c=this.areFiniteNumbers(t.edgeY)?t.edgeY:void 0,f=u,d=c;const p=this.areFiniteNumbers(t.arrowOffset)&&t.arrowOffset>0?t.arrowOffset:void 0;if(void 0!==p&&void 0!==u&&void 0!==c){const e=t.lineEndpointX-u,i=t.lineEndpointY-c,r=Math.sqrt(e*e+i*i);r>p&&(f=u+e/r*p,d=c+i/r*p);const s=u-t.lineEndpointX,n=c-t.lineEndpointY,o=Math.sqrt(s*s+n*n);if(o>0){const t=s/o,e=n/o,i=-e,r=u,h=c,l=r-t*p,f=h-e*p,d=l+i*p/2,g=f+t*p/2,w=l-i*p/2,m=f-t*p/2;this.areFiniteNumbers(r,h,d,g,w,m)&&(a=`${r},${h} ${d},${g} ${w},${m}`)}}if(!this.areFiniteNumbers(i,s,o))return null;const g=(()=>{if(void 0!==t.controlX&&void 0!==t.controlY&&void 0!==t.t&&this.areFiniteNumbers(t.controlX,t.controlY,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);if(!this.areFiniteNumbers(i.start.x,i.start.y,i.control.x,i.control.y,i.end.x,i.end.y))return;return`M ${i.start.x} ${i.start.y} Q ${i.control.x} ${i.control.y} ${i.end.x} ${i.end.y}`}})();return{indicatorRadius:i,indicatorStrokeWidth:r,lineStrokeWidth:n,dashArray:h,lineStroke:l,centerX:t.centerX,centerY:t.centerY,lineEndpointX:t.lineEndpointX,lineEndpointY:t.lineEndpointY,edgeX:u,edgeY:c,arrowOffset:p,arrowStyle:t.arrowStyle,arrowFill:t.arrowFill,solidLineEndX:f,solidLineEndY:d,arrowPoints:a,snapLinePath:g}}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 _n&&(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 r=this._anchorIndex.get(t);for(const t of r)if(t.lineId===e&&t.endpoint===i)return;r.add({lineId:e,endpoint:i})}removeFromIndex(t,e,i){const r=this._anchorIndex.get(t);if(r){for(const t of r)if(t.lineId===e&&t.endpoint===i){r.delete(t);break}0===r.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 _n?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 r=this.computeAnchorClipInfo(t,e,i);if(!r)return null;const s=i.centerX,n=i.centerY;if(!this.areFiniteNumbers(r.worldX,r.worldY,s,n))return null;const o=this.buildAnchorPath(t,e,r,i)??void 0;return o&&!this.isFinitePathData(o)?null:{edgeX:r.worldX,edgeY:r.worldY,centerX:s,centerY:n,pathD:o}}computeClippedLinePath(t,e=!1){const i=this.getSnapCandidate(),r=this._core.store.selectionGroup,s=i&&r&&1===r.objects.length&&r.objects[0].id===t.id;if(!t.startAnchor&&!t.endAnchor&&!s)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 n=t.startAnchor?this.findAnchorTarget(t,"start"):null,o=t.endAnchor?this.findAnchorTarget(t,"end"):null;let h=n?this.computeAnchorClipInfo(t,"start",n):null,l=o?this.computeAnchorClipInfo(t,"end",o):null;if(s&&void 0!==i.edgeX&&void 0!==i.edgeY){const e=this.lineWorldToLocal(t,i.edgeX,i.edgeY),r={worldX:i.edgeX,worldY:i.edgeY,localX:e.x,localY:e.y,t:i.t};"start"===i.endpoint?h=r:l=r}const a=e?t.x:0,u=e?t.y:0;if(void 0!==t.controlX&&void 0!==t.controlY){let e=h?.t??0,i=l?.t??1;if(h&&t.hasStartArrow){const i=t.getArrowSize("start"),r=this.evaluateDerivativeSpeedAtT(t,e);r>0&&(e+=i/r)}if(l&&t.hasEndArrow){const e=t.getArrowSize("end"),r=this.evaluateDerivativeSpeedAtT(t,i);r>0&&(i-=e/r)}if(e<0&&(e=0),i>1&&(i=1),i<=e){const t=(e+i)/2;e=t,i=t}const r=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},e,i);return`M ${r.start.x-a} ${r.start.y-u} Q ${r.control.x-a} ${r.control.y-u} ${r.end.x-a} ${r.end.y-u}`}let c=h?.localX??t.startX,f=h?.localY??t.startY,d=l?.localX??t.endX,p=l?.localY??t.endY;if(h&&t.hasStartArrow){const e=t.getArrowSize("start"),i=d-c,r=p-f,s=Math.sqrt(i*i+r*r);s>e&&(c+=i/s*e,f+=r/s*e)}if(l&&t.hasEndArrow){const e=t.getArrowSize("end"),i=c-d,r=f-p,s=Math.sqrt(i*i+r*r);s>e&&(d+=i/s*e,p+=r/s*e)}return`M ${c-a} ${f-u} L ${d-a} ${p-u}`}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,i){const r="start"===e?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY),n=this.getPathClipPoint(i,r);if(n){const i=this.lineWorldToLocal(t,n.x,n.y),r=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),s=Math.sqrt(Math.pow(i.x-t.startX,2)+Math.pow(i.y-t.startY,2));return{localX:i.x,localY:i.y,worldX:n.x,worldY:n.y,t:r>0?s/r:"start"===e?0:1}}const o=this.getClipPolygonForObject(i);let h;if(h=o?s.getLinePointsArrayIntersection(r,{x:i.centerX,y:i.centerY},o):s.getLinePolygonIntersection(r,{x:i.centerX,y:i.centerY},i.rotatedPolygon),!h)return null;const l=this.lineWorldToLocal(t,h.x,h.y),a=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),u=Math.sqrt(Math.pow(l.x-t.startX,2)+Math.pow(l.y-t.startY,2));return{localX:l.x,localY:l.y,worldX:h.x,worldY:h.y,t:a>0?u/a:"start"===e?0:1}}computeCurvedClipInfo(t,e,i){if(Hn.isInstanceOf(i,"KritzelPath"))return this.findCurveExitPointForPath(t,e,i);const r=this.getClipPolygonForObject(i),n=r??this.getPolygonPoints(i.rotatedPolygon),o=this.findCurveExitPoint(t,e,n);if(o)return o;const h="start"===e?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY);let l;if(l=r?s.getLinePointsArrayIntersection(h,{x:i.centerX,y:i.centerY},r):s.getLinePolygonIntersection(h,{x:i.centerX,y:i.centerY},i.rotatedPolygon),!l)return null;const a=this.lineWorldToLocal(t,l.x,l.y),u=this.approximateParameterForWorldPoint(t,l);return{localX:a.x,localY:a.y,worldX:l.x,worldY:l.y,t:u}}findCurveExitPoint(t,e,i){const r="start"===e?0:1,n=this.evaluateLineAtT(t,r);let o=s.isPointInPolygon({x:n.worldX,y:n.worldY},i),h=r;for(let r=1;r<=64;r++){const n="start"===e?r/64:1-r/64,l=this.evaluateLineAtT(t,n),a=s.isPointInPolygon({x:l.worldX,y:l.worldY},i);if(o&&!a){const e=this.refineCurveExitParameter(t,i,h,n),r=this.evaluateLineAtT(t,e);return{localX:r.localX,localY:r.localY,worldX:r.worldX,worldY:r.worldY,t:e}}o=a,h=n}return null}findCurveExitPointForPath(t,e,i){const r="start"===e?0:1,s=i.strokeWidth/i.scale/2,n=this.getPathAdjustedPoints(i);if(n.length<1)return null;const o=this.evaluateLineAtT(t,r);let h=this.isPointInPathStroke(o.worldX,o.worldY,n,s),l=r;for(let i=1;i<=64;i++){const r="start"===e?i/64:1-i/64,o=this.evaluateLineAtT(t,r),a=this.isPointInPathStroke(o.worldX,o.worldY,n,s);if(h&&!a){const e=this.refineCurveExitParameterForPath(t,n,s,l,r),i=this.evaluateLineAtT(t,e);return{localX:i.localX,localY:i.localY,worldX:i.worldX,worldY:i.worldY,t:e}}h=a,l=r}return null}refineCurveExitParameterForPath(t,e,i,r,s){let n=r,o=s;for(let r=0;r<8;r++){const r=(n+o)/2,s=this.evaluateLineAtT(t,r);this.isPointInPathStroke(s.worldX,s.worldY,e,i)?n=r:o=r}return(n+o)/2}getPathAdjustedPoints(t){return this.computePathAdjustedPoints(t)}computePathAdjustedPoints(t){if(!t.points?.length)return[];const e=t.rotation,i=Math.cos(e),r=Math.sin(e),s=t.points.map((t=>t[0])),n=t.points.map((t=>t[1])),o={x:(Math.min(...s)+Math.max(...s))/2,y:(Math.min(...n)+Math.max(...n))/2},{x:h,y:l}=o;return t.points.map((([t,e])=>{const s=t-h,n=e-l;return[h+s*i-n*r,l+s*r+n*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,r){if(1===i.length){const s=i[0],n=t-s[0],o=e-s[1];return Math.sqrt(n*n+o*o)<=r}for(let s=0;s<i.length-1;s++){const n=i[s],o=i[s+1];if(this.pointToSegmentDistance(t,e,n[0],n[1],o[0],o[1])<=r)return!0}return!1}pointToSegmentDistance(t,e,i,r,s,n){const o=s-i,h=n-r,l=o*o+h*h;if(0===l)return Math.sqrt((t-i)*(t-i)+(e-r)*(e-r));let a=((t-i)*o+(e-r)*h)/l;a=Math.max(0,Math.min(1,a));const u=i+a*o,c=r+a*h;return Math.sqrt((t-u)*(t-u)+(e-c)*(e-c))}refineCurveExitParameter(t,e,i,r){let n=i,o=r;for(let i=0;i<8;i++){const i=(n+o)/2,r=this.evaluateLineAtT(t,i);s.isPointInPolygon({x:r.worldX,y:r.worldY},e)?n=i:o=i}return(n+o)/2}approximateParameterForWorldPoint(t,e){let i=0,r=1/0;for(let s=0;s<=80;s++){const n=s/80,o=this.evaluateLineAtT(t,n),h=Math.hypot(o.worldX-e.x,o.worldY-e.y);h<r&&(r=h,i=n)}return i}evaluateLineAtT(t,e){const i=Math.max(0,Math.min(1,e));let r,s;if(void 0!==t.controlX&&void 0!==t.controlY){const e=1-i;r=e*e*t.startX+2*e*i*t.controlX+i*i*t.endX,s=e*e*t.startY+2*e*i*t.controlY+i*i*t.endY}else r=t.startX+(t.endX-t.startX)*i,s=t.startY+(t.endY-t.startY)*i;const n=this.lineLocalToWorld(t,r,s);return{t:i,localX:r,localY:s,worldX:n.x,worldY:n.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,r=t.controlY,s=2*(1-i)*(e-t.startX)+2*i*(t.endX-e),n=2*(1-i)*(r-t.startY)+2*i*(t.endY-r);return Math.sqrt(s*s+n*n)}{const e=t.endX-t.startX,i=t.endY-t.startY;return Math.sqrt(e*e+i*i)}}extractQuadraticSegment(t,e,i,r,s){let n=Math.max(0,Math.min(1,r)),o=Math.max(0,Math.min(1,s));if(o<n){const t=n;n=o,o=t}let h={start:t,control:e,end:i};if(n>0){h=this.splitQuadraticSegment(h,n).right;const t=1-n;o=t>0?(o-n)/t:1}return o<1&&(h=this.splitQuadraticSegment(h,o).left),h}splitQuadraticSegment(t,e){const i=Math.max(0,Math.min(1,e)),r=t.start,s=t.control,n=t.end,o=this.lerpPoint(r,s,i),h=this.lerpPoint(s,n,i),l=this.lerpPoint(o,h,i);return{left:{start:r,control:o,end:l},right:{start:l,control:h,end:n}}}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,r){if(void 0===t.controlX||void 0===t.controlY||void 0===i.t)return`M ${i.worldX} ${i.worldY} L ${r.centerX} ${r.centerY}`;const s="start"===e?0:i.t,n="start"===e?i.t:1;if(n<=s)return`M ${i.worldX} ${i.worldY} L ${r.centerX} ${r.centerY}`;const o=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},s,n);return this.buildWorldQuadraticPath(t,o,"start"===e)}buildWorldQuadraticPath(t,e,i=!1){const r=i?e.end:e.start,s=i?e.start:e.end,n=e.control,o=this.lineLocalToWorld(t,r.x,r.y),h=this.lineLocalToWorld(t,n.x,n.y),l=this.lineLocalToWorld(t,s.x,s.y);return`M ${o.x} ${o.y} Q ${h.x} ${h.y} ${l.x} ${l.y}`}getPolygonPoints(t){return[t.topLeft,t.topRight,t.bottomRight,t.bottomLeft]}getClipPolygonForObject(t){return Hn.isInstanceOf(t,"KritzelShape")?t.getClipPolygon():null}getPathClipPoint(t,e){return Hn.isInstanceOf(t,"KritzelPath")?t.getClipPoint(e):null}lineLocalToWorld(t,e,i){const r=e-t.x,s=i-t.y,n=t.totalWidth/2,o=t.totalHeight/2,h=Math.cos(t.rotation),l=Math.sin(t.rotation),a=(r-n)*h-(s-o)*l+n,u=(r-n)*l+(s-o)*h+o,c=this.getSafeScale(t.scale);return{x:a/c+t.translateX,y:u/c+t.translateY}}lineWorldToLocal(t,e,i){const r=this.getSafeScale(t.scale),s=(e-t.translateX)*r,n=(i-t.translateY)*r,o=t.totalWidth/2,h=t.totalHeight/2,l=Math.cos(-t.rotation),a=Math.sin(-t.rotation);return{x:(s-o)*l-(n-h)*a+o+t.x,y:(s-o)*a+(n-h)*l+h+t.y}}getSafeScale(t){return Number.isFinite(t)&&Math.abs(t)>1e-6?t:1}areFiniteNumbers(...t){return t.every((t=>void 0!==t&&Number.isFinite(t)))}isFiniteAnchorVisualization(t){return!(!t||!this.areFiniteNumbers(t.edgeX,t.edgeY,t.centerX,t.centerY)||t.pathD&&!this.isFinitePathData(t.pathD))}isFinitePathData(t){return!t.includes("Infinity")&&!t.includes("NaN")}isAnchorable(t){return!(t instanceof _o||t instanceof Qn)&&!(t instanceof _n)&&t.isVisible}}const Ml={type:"pen",color:An[0],size:16,palettes:{pen:[...An]}},xl={color:An[0],size:8,fontFamily:"Arial",palette:[...An]},Cl={color:An[0],size:4,palette:[...An],arrows:{end:{enabled:!0,style:"triangle"}}};var Al;!function(t){t.StartHorizontal="start-horizontal",t.CenterHorizontal="center-horizontal",t.EndHorizontal="end-horizontal",t.StartVertical="start-vertical",t.CenterVertical="center-vertical",t.EndVertical="end-vertical"}(Al||(Al={}));const Sl=2,Bl=2;function Tl(t,e,i,r,s,n){const o=n?.quiet??!0,h=e.get("schemaVersion")??0;if(h>=s)return{migrated:!1,fromVersion:h,toVersion:h};const l=r.filter((t=>t.fromVersion>=h&&t.toVersion<=s)).sort(((t,e)=>t.fromVersion-e.fromVersion));return o||console.log(`[Kritzel] Running ${l.length} migration(s) from v${h} to v${s}`),t.transact((()=>{for(const e of l)o||console.log(`[Kritzel] Migrating v${e.fromVersion} → v${e.toVersion}`),e.migrate(t,i);e.set("schemaVersion",s)}),"migration"),o||console.log(`[Kritzel] Migrations complete. Schema now at v${s}`),{migrated:!0,fromVersion:h,toVersion:s}}const Ol=[{fromVersion:1,toVersion:2,migrate(t,e){const i=e.workspaces;i&&i.forEach(((t,e)=>{const r=t?.viewport;if(!r)return;if("centerWorldX"in r)return;const s=r.scale??1,n=r.translateX??0,o=r.translateY??0,h={...t,viewport:{centerWorldX:-n/s||0,centerWorldY:-o/s||0,scale:s}};i.set(e,h)}))}}],El=[{fromVersion:1,toVersion:2,migrate(t,e){}}];export{Ol as A,o as B,Sl as C,Ml as D,jn as E,An as F,Qn as G,vl as H,Vo as I,_o as J,Pn as K,Ro as L,h as M,Fo as N,i as O,n as P,r as Q,Hn as R,Rn as S,Wn as T,Vn as U,yl as W,hl as a,zn as b,Ln as c,_n as d,Xn as e,Yn as f,Jn as g,Kn as h,qn as i,Do as j,Po as k,$o as l,jo as m,Wo as n,kl as o,bl as p,In as q,xl as r,Cl as s,Sn as t,Bn as u,Al as v,Bl as w,Tl as x,El as y,Dn as z}
|