kritzel-stencil 0.2.5 → 0.2.7
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.cjs.js +1 -1
- package/dist/cjs/kritzel-active-users_42.cjs.entry.js +53 -6
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stencil.cjs.js +1 -1
- package/dist/cjs/{workspace.migrations-m5BeAY7R.js → workspace.migrations-CmrjHSeI.js} +35 -0
- package/dist/collection/classes/tools/brush-tool.class.js +35 -0
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +5 -1
- package/dist/collection/components/shared/kritzel-dialog/kritzel-dialog.js +58 -3
- package/dist/collection/constants/version.js +1 -1
- package/dist/components/index.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-dialog.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-login-dialog.js +1 -1
- package/dist/components/kritzel-settings.js +1 -1
- package/dist/components/kritzel-share-dialog.js +1 -1
- package/dist/components/kritzel-tool-config.js +1 -1
- package/dist/components/{p-R60vdaIY.js → p-B1V6yEGY.js} +1 -1
- package/dist/components/{p-BDOSy6zd.js → p-BuSOJ7Xd.js} +1 -1
- package/dist/components/{p-BeOG6L2d.js → p-CQ9mhm-K.js} +1 -1
- package/dist/components/{p-BmYsz1bP.js → p-DBIK7z89.js} +1 -1
- package/dist/components/{p-eez_2Ccc.js → p-DEHYU_Jk.js} +2 -2
- package/dist/components/p-DPxSr1wV.js +1 -0
- package/dist/components/{p-ZpItdhxS.js → p-Dpr_JQam.js} +1 -1
- package/dist/components/{p-KAwmnjZJ.js → p-Dqt5KPSA.js} +1 -1
- package/dist/components/{p-DwZAEb-2.js → p-DuR1ZNrl.js} +1 -1
- package/dist/components/{p-BcWZP5At.js → p-fgTIoj8J.js} +1 -1
- package/dist/components/{p-DYHF_MSN.js → p-nW05C2cx.js} +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/kritzel-active-users_42.entry.js +53 -6
- package/dist/esm/loader.js +1 -1
- package/dist/esm/stencil.js +1 -1
- package/dist/esm/{workspace.migrations-BcQJ1TH8.js → workspace.migrations-C39ztzVG.js} +35 -0
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/{p-BcQJ1TH8.js → p-C39ztzVG.js} +1 -1
- package/dist/stencil/p-bd48bf3d.entry.js +9 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/types/classes/tools/brush-tool.class.d.ts +19 -0
- package/dist/types/components/shared/kritzel-dialog/kritzel-dialog.d.ts +8 -0
- package/dist/types/constants/version.d.ts +1 -1
- package/package.json +1 -1
- package/dist/components/p-0F9_lw6l.js +0 -1
- package/dist/stencil/p-ed67061b.entry.js +0 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
import{IndexeddbPersistence as t}from"y-indexeddb";import*as e from"yjs";class i{static registry={};static registerTool(t,e,i){const s=new e(i);return s.name=t,this.registry[t]=s,s}static getTool(t){return this.registry[t]||(console.warn(`Unknown tool: ${t}`),null)}static getToolByIndex(t){return Object.values(this.registry)[t]??null}}class s{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 r{static doPolygonsIntersect(t,e){const i=[t.bottomLeft,t.bottomRight,t.topRight,t.topLeft],s=[e.bottomLeft,e.bottomRight,e.topRight,e.topLeft];for(const t of i)if(this.isPointInPolygon(t,s))return!0;for(const t of s)if(this.isPointInPolygon(t,i))return!0;for(let t=0;t<i.length;t++){const e=i[t],r=i[(t+1)%i.length];for(let t=0;t<s.length;t++)if(this.intersectLines(e,r,s[t],s[(t+1)%s.length]))return!0}return!1}static isPointInPolygon(t,e){let i=!1;for(let s=0,r=e.length-1;s<e.length;r=s++){const n=e[s].x,o=e[s].y,h=e[r].y;o>t.y!=h>t.y&&t.x<(e[r].x-n)*(t.y-o)/(h-o)+n&&(i=!i)}return i}static intersectLines(t,e,i,s){const r=(e.x-t.x)*(s.y-i.y)-(e.y-t.y)*(s.x-i.x);if(0===r)return!1;const n=((i.x-t.x)*(s.y-i.y)-(i.y-t.y)*(s.x-i.x))/r,o=-((t.x-i.x)*(e.y-t.y)-(t.y-i.y)*(e.x-t.x))/r;return n>=0&&n<=1&&o>=0&&o<=1}static getLineIntersectionPoint(t,e,i,s){const r=(e.x-t.x)*(s.y-i.y)-(e.y-t.y)*(s.x-i.x);if(0===r)return null;const n=((i.x-t.x)*(s.y-i.y)-(i.y-t.y)*(s.x-i.x))/r,o=-((t.x-i.x)*(e.y-t.y)-(t.y-i.y)*(e.x-t.x))/r;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 s=[i.topLeft,i.topRight,i.bottomRight,i.bottomLeft];let r=null,n=1/0;for(let i=0;i<s.length;i++){const o=this.getLineIntersectionPoint(t,e,s[i],s[(i+1)%s.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,r=o)}}return r}static getEllipsePolygonApproximation(t,e,i,s,r=32,n=0){const o=[],h=Math.cos(n),l=Math.sin(n);for(let n=0;n<r;n++){const a=2*Math.PI*n/r,u=i*Math.cos(a),c=s*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 s=null,r=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<r&&(r=e,s=o)}}return s}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],s=Math.min(...e),r=Math.max(...e),n=Math.min(...i),o=Math.max(...i);return{x:s,y:n,z:this.scale,width:r-s,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,s=Math.cos(i),r=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:s*(i-t)-r*(n-e)+t,y:r*(i-t)+s*(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 s.generateUUID()}isInViewport(){const t=this._core.store.state.scale;if(this.boundingBox.width*t*(this.boundingBox.height*t)<.5)return!1;const e=-this._core.store.state.translateX/this._core.store.state.scale,i=-this._core.store.state.translateY/this._core.store.state.scale;return this.rotatedBoundingBox.x<e+this._core.store.state.viewportWidth/this._core.store.state.scale&&this.rotatedBoundingBox.x+this.rotatedBoundingBox.width>e&&this.rotatedBoundingBox.y<i+this._core.store.state.viewportHeight/this._core.store.state.scale&&this.rotatedBoundingBox.y+this.rotatedBoundingBox.height>i}centerInViewport(){const{viewportWidth:t,viewportHeight:e,translateX:i,translateY:s,scale:r}=this._core.store.state,{x:n,y:o,width:h,height:l}=this.rotatedBoundingBox;this.updatePosition(this.translateX+((t/2-i)/r-(n+h/2)),this.translateY+((e/2-s)/r-(o+l/2)))}update(){this._core.store.objects.update(this)}move(t,e,i,s){const r=(e-s)/this._core.store.state.scale;this.translateX+=(t-i)/this._core.store.state.scale,this.translateY+=r,this._core.store.objects.update(this)}resize(t,e,i,s){i<=1||s<=1||(this.width=i,this.height=s,this.translateX=t,this.translateY=e,this._core.store.objects.update(this),this._core.anchorManager.updateAnchorsForObject(this.id))}rotate(t){this.rotation=t,this._core.store.objects.update(this)}clone(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.id,t}copy(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.generateId(),t.isMounted=!1,t}serialize(){const{_core:t,_elementRef:e,element:i,totalWidth:s,totalHeight:r,...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}adoptTransientStateFrom(t){}isClass(t){return this.__class__===t}edit(t){}onAfterUpdate(t){}hitTest(t,e){return!0}hitTestPolygon(t){return r.doPolygonsIntersect(this.rotatedPolygon,t)}updatePosition(t,e){this.translateX=t,this.translateY=e,this._core.store.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"),e&&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"),i=e?.replace(/\s*interactive-widget=resizes-content\s*[,;]?/g,"");void 0!==i&&(i=i.replace(/,(\s*,)+/g,",").replace(/^,/,"").replace(/,$/,"").trim(),t.setAttribute("content",i))}}static onKeyboardVisibleChanged(t){if("visualViewport"in window){const e=.75,i=i=>{const s=i.target,r=o.isMobile(),n=s.height*s.scale/window.screen.height<e;t(r&&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 s=0;;s++){if(s==t.childCount||s==e.childCount)return t.childCount==e.childCount?null:i;let r=t.child(s),n=e.child(s);if(r!=n){if(!r.sameMarkup(n))return i;if(r.isText&&r.text!=n.text){for(let t=0;r.text[t]==n.text[t];t++)i++;return i}if(r.content.size||n.content.size){let t=a(r.content,n.content,i+1);if(null!=t)return t}i+=r.nodeSize}else i+=r.nodeSize}}function u(t,e,i,s){for(let r=t.childCount,n=e.childCount;;){if(0==r||0==n)return r==n?null:{a:i,b:s};let o=t.child(--r),h=e.child(--n),l=o.nodeSize;if(o!=h){if(!o.sameMarkup(h))return{a:i,b:s};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--,s--;return{a:i,b:s}}if(o.content.size||h.content.size){let t=u(o.content,h.content,i-1,s-1);if(t)return t}i-=l,s-=l}else i-=l,s-=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 s=i&&i!=t?this.remove(i):this,r=s.find(t),n=s.content.slice();return-1==r?n.push(i||t,e):(n[r+1]=e,i&&(n[r]=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 s=this.remove(e),r=s.content.slice(),n=s.find(t);return r.splice(-1==n?r.length:n,0,e,i),new l(r)},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,s=0,r){for(let n=0,o=0;o<e;n++){let h=this.content[n],l=o+h.nodeSize;if(l>t&&!1!==i(h,s+o,r||null,n)&&h.content.size){let r=o+1;h.nodesBetween(Math.max(0,t-r),Math.min(h.content.size,e-r),i,s+r)}o=l}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,e,i,s){let r="",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?s?"function"==typeof s?s(o):s:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&l||o.isTextblock)&&i&&(n?n=!1:r+=i),r+=l}),0),r}append(t){if(!t.size)return this;if(!this.size)return t;let e=this.lastChild,i=t.firstChild,s=this.content.slice(),r=0;for(e.isText&&e.sameMarkup(i)&&(s[s.length-1]=e.withText(e.text+i.text),r=1);r<t.content.length;r++)s.push(t.content[r]);return new c(s,this.size+t.size)}cut(t,e=this.size){if(0==t&&e==this.size)return this;let i=[],s=0;if(e>t)for(let r=0,n=0;n<e;r++){let o=this.content[r],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),s+=o.nodeSize),n=h}return new c(i,s)}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 s=this.content.slice(),r=this.size+e.nodeSize-i.nodeSize;return s[t]=e,new c(s,r)}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 s=this.content[e];t(s,i,e),i+=s.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 s=i+this.child(e).nodeSize;if(s>=t)return s==t?d(e+1,s):d(e,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map((t=>t.toJSON())):null}static fromJSON(t,e){if(!e)return 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 s=0;s<t.length;s++){let r=t[s];i+=r.nodeSize,s&&r.isText&&t[s-1].sameMarkup(r)?(e||(e=t.slice(0,s)),e[e.length-1]=r.withText(e[e.length-1].text+r.text)):e&&e.push(r)}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 s=0;s<t.length;s++){let r=t[s];if(this.eq(r))return t;if(this.type.excludes(r.type))e||(e=t.slice(0,s));else{if(r.type.excludes(this.type))return t;!i&&r.type.rank>this.type.rank&&(e||(e=t.slice(0,s)),e.push(this),i=!0),e&&e.push(r)}}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 s=i.create(e.attrs);return i.checkAttrs(s.attrs),s}static sameSet(t,e){if(t==e)return!0;if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].eq(e[i]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&0==t.length)return 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,s=e.openEnd||0;if("number"!=typeof i||"number"!=typeof s)throw new RangeError("Invalid input for Slice.fromJSON");return new m(c.fromJSON(t,e.content),i,s)}static maxOpen(t,e=!0){let i=0,s=0;for(let s=t.firstChild;s&&!s.isLeaf&&(e||!s.type.spec.isolating);s=s.firstChild)i++;for(let i=t.lastChild;i&&!i.isLeaf&&(e||!i.type.spec.isolating);i=i.lastChild)s++;return new m(t,i,s)}}function v(t,e,i){let{index:s,offset:r}=t.findIndex(e),n=t.maybeChild(s),{index:o,offset:h}=t.findIndex(i);if(r==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(s!=o)throw new RangeError("Removing non-flat range");return t.replaceChild(s,n.copy(v(n.content,e-r-1,i-r-1)))}function y(t,e,i,s){let{index:r,offset:n}=t.findIndex(e),o=t.maybeChild(r);if(n==e||o.isText)return s&&!s.canReplace(r,r,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(r,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,s){let r=t.index(s),n=t.node(s);if(r==e.index(s)&&s<t.depth-i.openStart){let o=b(t,e,i,s+1);return n.copy(n.content.replaceChild(r,o))}if(i.content.size){if(i.openStart||i.openEnd||t.depth!=s||e.depth!=s){let{start:r,end:o}=function(t,e){let i=e.depth-t.openStart,s=e.node(i).copy(t.content);for(let t=i-1;t>=0;t--)s=e.node(t).copy(c.from(s));return{start:s.resolveNoCache(t.openStart+i),end:s.resolveNoCache(s.content.size-t.openEnd-i)}}(i,t);return S(n,B(t,r,o,e,s))}{let s=t.parent,r=s.content;return S(s,r.cut(0,t.parentOffset).append(i.content).append(r.cut(e.parentOffset)))}}return S(n,T(t,e,s))}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 s=t.node(i);return M(s,e.node(i)),s}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,s){let r=(e||t).node(i),n=0,o=e?e.index(i):r.childCount;t&&(n=t.index(i),t.depth>i?n++:t.textOffset&&(C(t.nodeAfter,s),n++));for(let t=n;t<o;t++)C(r.child(t),s);e&&e.depth==i&&e.textOffset&&C(e.nodeBefore,s)}function S(t,e){return t.type.checkContent(e),t.copy(e)}function B(t,e,i,s,r){let n=t.depth>r&&x(t,e,r+1),o=s.depth>r&&x(i,s,r+1),h=[];return A(null,t,r,h),n&&o&&e.index(r)==i.index(r)?(M(n,o),C(S(n,B(t,e,i,s,r+1)),h)):(n&&C(S(n,T(t,e,r+1)),h),A(e,i,r,h),o&&C(S(o,T(i,s,r+1)),h)),A(s,null,r,h),new c(h)}function T(t,e,i){let s=[];return A(null,t,i,s),t.depth>i&&C(S(x(t,e,i+1),T(t,e,i+1)),s),A(e,null,i,s),new c(s)}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],s=t.child(e);return i?t.child(e).cut(i):s}get nodeBefore(){let t=this.index(this.depth),e=this.pos-this.path[this.path.length-1];return e?this.parent.child(t).cut(0,e):0==t?null:this.parent.child(t-1)}posAtIndex(t,e){e=this.resolveDepth(e);let i=this.path[3*e],s=0==e?0:this.path[3*e-1]+1;for(let e=0;e<t;e++)s+=i.child(e).nodeSize;return s}marks(){let t=this.parent,e=this.index();if(0==t.content.size)return g.none;if(this.textOffset)return t.child(e).marks;let i=t.maybeChild(e-1),s=t.maybeChild(e);if(!i){let t=i;i=s,s=t}let r=i.marks;for(var n=0;n<r.length;n++)!1!==r[n].type.spec.inclusive||s&&r[n].isInSet(s.marks)||(r=r[n--].removeFromSet(r));return r}marksAcross(t){let e=this.parent.maybeChild(this.index());if(!e||!e.isInline)return null;let i=e.marks,s=t.parent.maybeChild(t.index());for(var r=0;r<i.length;r++)!1!==i[r].type.spec.inclusive||s&&i[r].isInSet(s.marks)||(i=i[r--].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=[],s=0,r=e;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(r),o=r-n;if(i.push(e,t,s+n),!o)break;if(e=e.child(t),e.isText)break;r=o-1,s+=n+1}return new O(e,i,r)}static resolveCached(t,e){let i=$.get(t);if(i)for(let t=0;t<i.elts.length;t++){let s=i.elts[t];if(s.pos==e)return s}else $.set(t,i=new E);let s=i.elts[i.i]=O.resolve(t,e);return i.i=(i.i+1)%I,s}}class E{constructor(){this.elts=[],this.i=0}}const I=12,$=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 D=Object.create(null);class R{constructor(t,e,i,s=g.none){this.type=t,this.attrs=e,this.marks=s,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,s=0){this.content.nodesBetween(t,e,i,s,this)}descendants(t){this.nodesBetween(0,this.content.size,t)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(t,e,i,s){return this.content.textBetween(t,e,i,s)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(t){return this==t||this.sameMarkup(t)&&this.content.eq(t.content)}sameMarkup(t){return this.hasMarkup(t.type,t.attrs,t.marks)}hasMarkup(t,e,i){return this.type==t&&p(this.attrs,e||t.defaultAttrs||D)&&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 s=this.resolve(t),r=this.resolve(e),n=i?0:s.sharedDepth(e),o=s.start(n),h=s.node(n).content.cut(s.pos-o,r.pos-o);return new m(h,s.depth-n,r.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:s}=e.content.findIndex(t);if(e=e.maybeChild(i),!e)return null;if(s==t||e.isText)return e;t-=s+1}}childAfter(t){let{index:e,offset:i}=this.content.findIndex(t);return{node:this.content.maybeChild(e),index:e,offset:i}}childBefore(t){if(0==t)return{node:null,index:0,offset:0};let{index:e,offset:i}=this.content.findIndex(t);if(i<t)return{node:this.content.child(e),index:e,offset:i};let s=this.content.child(e-1);return{node:s,index:e-1,offset:i-s.nodeSize}}resolve(t){return O.resolveCached(this,t)}resolveNoCache(t){return O.resolve(this,t)}rangeHasMark(t,e,i){let s=!1;return e>t&&this.nodesBetween(t,e,(t=>(i.isInSet(t.marks)&&(s=!0),!s))),s}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let t=this.type.name;return this.content.size&&(t+="("+this.content.toStringInner()+")"),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,s=0,r=i.childCount){let n=this.contentMatchAt(t).matchFragment(i,s,r),o=n&&n.matchFragment(this.content,e);if(!o||!o.validEnd)return!1;for(let t=s;t<r;t++)if(!this.type.allowsMarks(i.child(t).marks))return!1;return!0}canReplaceWith(t,e,i,s){if(s&&!this.type.allowsMarks(s))return!1;let r=this.contentMatchAt(t).matchType(i),n=r&&r.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 s=c.fromJSON(t,e.content),r=t.nodeType(e.type).create(e.attrs,s,i);return r.type.checkAttrs(r.attrs),r}}R.prototype.text=void 0;class j extends R{constructor(t,e,i,s){if(super(t,e,null,s),!i)throw new RangeError("Empty text nodes are not allowed");this.text=i}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):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 U{constructor(t){this.validEnd=t,this.next=[],this.wrapCache=[]}static parse(t,e){let i=new N(t,e);if(null==i.next)return U.empty;let s=z(i);i.next&&i.err("Unexpected trailing text");let r=function(t){let e=Object.create(null);return function i(s){let r=[];s.forEach((e=>{t[e].forEach((({term:e,to:i})=>{if(!e)return;let s;for(let t=0;t<r.length;t++)r[t][0]==e&&(s=r[t][1]);W(t,i).forEach((t=>{s||r.push([e,s=[]]),-1==s.indexOf(t)&&s.push(t)}))}))}));let n=e[s.join(",")]=new U(s.indexOf(t.length-1)>-1);for(let t=0;t<r.length;t++){let s=r[t][1].sort(Y);n.next.push({type:r[t][0],next:e[s.join(",")]||i(s)})}return n}(W(t,0))}(function(t){let e=[[]];return r(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 s(n,o),r(t(e.expr,o),o),[s(o)]}if("plus"==e.type){let o=i();return r(t(e.expr,n),o),r(t(e.expr,o),o),[s(o)]}if("opt"==e.type)return[s(n)].concat(t(e.expr,n));if("range"==e.type){let o=n;for(let s=0;s<e.min;s++){let s=i();r(t(e.expr,o),s),o=s}if(-1==e.max)r(t(e.expr,o),o);else for(let n=e.min;n<e.max;n++){let n=i();s(o,n),r(t(e.expr,o),n),o=n}return[s(o)]}if("name"==e.type)return[s(n,void 0,e.value)];throw new Error("Unknown expr type")}for(let s=0;;s++){let o=t(e.exprs[s],n);if(s==e.exprs.length-1)return o;r(o,n=i())}}(t,0),i()),e;function i(){return e.push([])-1}function s(t,i,s){let r={term:s,to:i};return e[t].push(r),r}function r(t,e){t.forEach((t=>t.to=e))}}(s));return function(t,e){for(let i=0,s=[t];i<s.length;i++){let t=s[i],r=!t.validEnd,n=[];for(let e=0;e<t.next.length;e++){let{type:i,next:o}=t.next[e];n.push(i.name),!r||i.isText||i.hasRequiredAttrs()||(r=!1),-1==s.indexOf(o)&&s.push(o)}r&&e.err("Only non-generatable nodes ("+n.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(r,i),r}matchType(t){for(let e=0;e<this.next.length;e++)if(this.next[e].type==t)return this.next[e].next;return null}matchFragment(t,e=0,i=t.childCount){let s=this;for(let r=e;s&&r<i;r++)s=s.matchType(t.child(r).type);return s}get inlineContent(){return 0!=this.next.length&&this.next[0].type.isInline}get defaultType(){for(let t=0;t<this.next.length;t++){let{type:e}=this.next[t];if(!e.isText&&!e.hasRequiredAttrs())return e}return null}compatible(t){for(let e=0;e<this.next.length;e++)for(let i=0;i<t.next.length;i++)if(this.next[e].type==t.next[i].type)return!0;return!1}fillBefore(t,e=!1,i=0){let s=[this];return function r(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==s.indexOf(i)){s.push(i);let t=r(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 s=i.shift(),r=s.match;if(r.matchType(t)){let t=[];for(let e=s;e.type;e=e.via)t.push(e.type);return t.reverse()}for(let t=0;t<r.next.length;t++){let{type:n,next:o}=r.next[t];n.isLeaf||n.hasRequiredAttrs()||n.name in e||s.type&&!o.validEnd||(i.push({match:n.contentMatch,type:n,via:s}),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 s=0;s<i.next.length;s++)-1==t.indexOf(i.next[s].next)&&e(i.next[s].next)}(this),t.map(((e,i)=>{let s=i+(e.validEnd?"*":" ")+" ";for(let i=0;i<e.next.length;i++)s+=(i?", ":"")+e.next[i].type.name+"->"+t.indexOf(e.next[i].next);return s})).join("\n")}}U.empty=new U(!0);class N{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(_(t))}while(t.eat("|"));return 1==e.length?e[0]:{type:"choice",exprs:e}}function _(t){let e=[];do{e.push(L(t))}while(t.next&&")"!=t.next&&"|"!=t.next);return 1==e.length?e[0]:{type:"seq",exprs:e}}function L(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,s=i[e];if(s)return[s];let r=[];for(let t in i){let s=i[t];s.isInGroup(e)&&r.push(s)}return 0==r.length&&t.err("No node type or group '"+e+"' found"),r}(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),s=i;return t.eat(",")&&(s="}"!=t.next?H(t):-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:i,max:s,expr:e}}function Y(t,e){return e-t}function W(t,e){let i=[];return function e(s){let r=t[s];if(1==r.length&&!r[0].term)return e(r[0].to);i.push(s);for(let t=0;t<r.length;t++){let{term:s,to:n}=r[t];s||-1!=i.indexOf(n)||e(n)}}(e),i.sort(Y)}function V(t){let e=Object.create(null);for(let i in t){let s=t[i];if(!s.hasDefault)return null;e[i]=s.default}return e}function K(t,e){let i=Object.create(null);for(let s in t){let r=e&&e[s];if(void 0===r){let e=t[s];if(!e.hasDefault)throw new RangeError("No value supplied for attribute "+s);r=e.default}i[s]=r}return i}function J(t,e,i){for(let s in e)if(!(s in t))throw new RangeError(`Unsupported attribute ${s} for ${i} of type ${s}`);for(let i in t){let s=t[i];s.validate&&s.validate(e[i])}}function Q(t,e){let i=Object.create(null);if(e)for(let s in e)i[s]=new G(t,s,e[s]);return i}let q=class t{constructor(t,e,i){this.name=t,this.schema=e,this.spec=i,this.markSet=null,this.groups=i.group?i.group.split(" "):[],this.attrs=Q(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==U.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:K(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 s=this.contentMatch.matchFragment(e),r=s&&s.fillBefore(c.empty,!0);return r?new R(this,t,e.append(r),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){J(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 s=Object.create(null);e.forEach(((e,r)=>s[e]=new t(e,i,r)));let r=i.spec.topNode||"doc";if(!s[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!s.text)throw new RangeError("Every schema needs a 'text' type");for(let t in s.text.attrs)throw new RangeError("The text node type should not have attributes");return s}};class 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 s=i.split("|");return i=>{let r=null===i?"null":typeof i;if(s.indexOf(r)<0)throw new RangeError(`Expected value of type ${s} for attribute ${e} on type ${t}, got ${r}`)}}(t,e,i.validate):i.validate}get isRequired(){return!this.hasDefault}}class Z{constructor(t,e,i,s){this.name=t,this.rank=e,this.schema=i,this.spec=s,this.attrs=Q(t,s.attrs),this.excluded=null;let r=V(this.attrs);this.instance=r?new g(this,r):null}create(t=null){return!t&&this.instance?this.instance:new g(this,K(this.attrs,t))}static compile(t,e){let i=Object.create(null),s=0;return t.forEach(((t,r)=>i[t]=new Z(t,s++,e,r))),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){J(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],s=e.spec.content||"",r=e.spec.marks;if(e.contentMatch=i[s]||(i[s]=U.parse(s,this.nodes)),e.inlineContent=e.contentMatch.inlineContent,e.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!e.isInline||!e.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=e}e.markSet="_"==r?null:r?et(this,r.split(" ")):""!=r&&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,s){if("string"==typeof t)t=this.nodeType(t);else{if(!(t instanceof q))throw new RangeError("Invalid node type: "+t);if(t.schema!=this)throw new RangeError("Node type from different schema used ("+t.name+")")}return t.createChecked(e,i,s)}text(t,e){let i=this.nodes.text;return new 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 s=0;s<e.length;s++){let r=e[s],n=t.marks[r],o=n;if(n)i.push(n);else for(let e in t.marks){let s=t.marks[e];("_"==r||s.spec.group&&s.spec.group.split(" ").indexOf(r)>-1)&&i.push(o=s)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[s]+"'")}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 s=i?this.tags.indexOf(i)+1:0;s<this.tags.length;s++){let i=this.tags[s];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,s){for(let r=s?this.styles.indexOf(s)+1:0;r<this.styles.length;r++){let s=this.styles[r],n=s.style;if(!(0!=n.indexOf(t)||s.context&&!i.matchesContext(s.context)||n.length>t.length&&(61!=n.charCodeAt(t.length)||n.slice(t.length+1)!=e))){if(s.getAttrs){let t=s.getAttrs(e);if(!1===t)continue;s.attrs=t||void 0}return s}}}static schemaRules(t){let e=[];function i(t){let i=null==t.priority?50:t.priority,s=0;for(;s<e.length;s++){let t=e[s];if((null==t.priority?50:t.priority)<i)break}e.splice(s,0,t)}for(let e in t.marks){let s=t.marks[e].spec.parseDOM;s&&s.forEach((t=>{i(t=ut(t)),t.mark||t.ignore||t.clearMark||(t.mark=e)}))}for(let e in t.nodes){let s=t.nodes[e].spec.parseDOM;s&&s.forEach((t=>{i(t=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 st={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},rt={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,s,r,n){this.type=t,this.attrs=e,this.marks=i,this.solid=s,this.options=n,this.content=[],this.activeMarks=g.none,this.match=r||(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&&!st.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 s,r=e.topNode,n=ot(null,e.preserveWhitespace,0)|(i?4:0);s=r?new ht(r.type,r.attrs,g.none,!0,e.topMatch||r.type.contentMatch,n):new ht(i?null:t.schema.topNodeType,null,g.none,!0,null,n),this.nodes=[s],this.find=e.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t,e){3==t.nodeType?this.addTextNode(t,e):1==t.nodeType&&this.addElement(t,e)}addTextNode(t,e){let i=t.nodeValue,s=this.top,r=2&s.options?"full":this.localPreserveWS||(1&s.options)>0,{schema:n}=this.parser;if("full"===r||s.inlineContext(t)||/[^ \t\r\n\u000c]/.test(i)){if(r)if("full"===r)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=s.content[s.content.length-1],r=t.previousSibling;(!e||r&&"BR"==r.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 s=this.localPreserveWS,r=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:rt.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,s=this.needsBlock;if(st.hasOwnProperty(o))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),i=!0,r.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(r),this.needsBlock=s}else{let i=this.readStyles(t,e);i&&this.addElementByRule(t,h,i,!1===h.consuming?n:void 0)}this.localPreserveWS=s}leafFallback(t,e){"BR"==t.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode("\n"),e)}ignoreFallback(t,e){"BR"!=t.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),e,!0)}readStyles(t,e){let i=t.style;if(i&&i.length)for(let t=0;t<this.parser.matchedStyles.length;t++){let s=this.parser.matchedStyles[t],r=i.getPropertyValue(s);if(r)for(let t;;){let i=this.parser.matchStyle(s,r,this,t);if(!i)break;if(i.ignore)return null;if(e=i.clearMark?e.filter((t=>!i.clearMark(t))):e.concat(this.parser.schema.marks[i.mark].create(i.attrs)),!1!==i.consuming)break;t=i}}return e}addElementByRule(t,e,i,s){let r,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&&(r=!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(s)this.addElement(t,i,s);else if(e.getContent)this.findInside(t),e.getContent(t,this.parser.schema).forEach((t=>this.insertNode(t,i,!1)));else{let s=t;"string"==typeof e.contentElement?s=t.querySelector(e.contentElement):"function"==typeof e.contentElement?s=e.contentElement(t):e.contentElement&&(s=e.contentElement),this.findAround(t,s,!0),this.addAll(s,i),this.findAround(t,s,!1)}r&&this.sync(o)&&this.open--}addAll(t,e,i,s){let r=i||0;for(let n=i?t.childNodes[i]:t.firstChild,o=null==s?null:t.childNodes[s];n!=o;n=n.nextSibling,++r)this.findAtPoint(t,r),this.addDOM(n,e);this.findAtPoint(t,r)}findPlace(t,e,i){let s,r;for(let e=this.open,n=0;e>=0;e--){let o=this.nodes[e],h=o.findWrapping(t);if(h&&(!s||s.length>h.length+n)&&(s=h,r=o,!h.length))break;if(o.solid){if(i)break;n+=2}}if(!s)return null;this.sync(r);for(let t=0;t<s.length;t++)e=this.enterInner(s[t],null,e,!1);return e}insertNode(t,e,i){if(t.isInline&&this.needsBlock&&!this.top.type){let t=this.textblockFromContext();t&&(e=this.enterInner(t,null,e))}let s=this.findPlace(t,e,i);if(s){this.closeExtra();let e=this.top;e.match&&(e.match=e.match.matchType(t.type));let i=g.none;for(let r of s.concat(t.marks))(e.type?e.type.allowsMarkType(r.type):ct(r.type,t.type))&&(i=r.addToSet(i));return e.content.push(t.mark(i)),!0}return!1}enter(t,e,i,s){let r=this.findPlace(t.create(e),i,!1);return r&&(r=this.enterInner(t,e,i,!0,s)),r}enterInner(t,e,i,s=!1,r){this.closeExtra();let n=this.top;n.match=n.match&&n.match.matchType(t);let o=ot(t,r,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,s,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 s=0;s<this.find.length;s++)null==this.find[s].pos&&1==t.nodeType&&t.contains(this.find[s].node)&&e.compareDocumentPosition(this.find[s].node)&(i?2:4)&&(this.find[s].pos=this.currentPos)}findInText(t){if(this.find)for(let e=0;e<this.find.length;e++)this.find[e].node==t&&(this.find[e].pos=this.currentPos-(t.nodeValue.length-this.find[e].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let e=t.split("/"),i=this.options.context,s=!(this.isOpen||i&&i.parent.type!=this.nodes[0].type),r=(s?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>=r;o--)if(n(t-1,o))return!0;return!1}{let t=o>0||0==o&&s?this.nodes[o].type:i&&o>=r?i.node(o-r).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 s in i){let r=i[s];if(!r.allowsMarkType(t))continue;let n=[],o=t=>{n.push(t);for(let i=0;i<t.edgeCount;i++){let{type:s,next:r}=t.edge(i);if(s==e)return!0;if(n.indexOf(r)<0&&o(r))return!0}};if(o(r.contentMatch))return!0}}class ft{constructor(t,e){this.nodes=t,this.marks=e}serializeFragment(t,e={},i){i||(i=pt(e).createDocumentFragment());let s=i,r=[];return t.forEach((t=>{if(r.length||t.marks.length){let i=0,n=0;for(;i<r.length&&n<t.marks.length;){let e=t.marks[n];if(this.marks[e.type.name]){if(!e.eq(r[i][0])||!1===e.type.spec.spanning)break;i++,n++}else n++}for(;i<r.length;)s=r.pop()[1];for(;n<t.marks.length;){let i=t.marks[n++],o=this.serializeMark(i,t.isInline,e);o&&(r.push([i,s]),s.appendChild(o.dom),s=o.contentDOM||o.dom)}}s.appendChild(this.serializeNodeInner(t,e))})),i}serializeNodeInner(t,e){let{dom:i,contentDOM:s}=wt(pt(e),this.nodes[t.type.name](t),null,t.attrs);if(s){if(t.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(t.content,e,s)}return i}serializeNode(t,e={}){let i=this.serializeNodeInner(t,e);for(let s=t.marks.length-1;s>=0;s--){let r=this.serializeMark(t.marks[s],t.isInline,e);r&&((r.contentDOM||r.dom).appendChild(i),i=r.dom)}return i}serializeMark(t,e,i={}){let s=this.marks[t.type.name];return s&&wt(pt(i),s(t,e),null,t.attrs)}static renderSpec(t,e,i=null,s){return wt(t,e,i,s)}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 s=t[i].spec.toDOM;s&&(e[i]=s)}return e}function pt(t){return t.document||window.document}const gt=new WeakMap;function wt(t,e,i,s){if("string"==typeof e)return{dom:t.createTextNode(e)};if(null!=e.nodeType)return{dom:e};if(e.dom&&null!=e.dom.nodeType)return e;let r,n=e[0];if("string"!=typeof n)throw new RangeError("Invalid array passed to renderSpec");if(s&&(r=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}(s))&&r.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 r=u;r<e.length;r++){let n=e[r];if(0===n){if(r<e.length-1||r>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}{let{dom:e,contentDOM:r}=wt(t,n,i,s);if(l.appendChild(e),r){if(o)throw new RangeError("Multiple content holes");o=r}}}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 s=0,r=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?s:0);if(h>t)break;let l=this.ranges[o+r],a=this.ranges[o+n],u=h+l;if(t<=u){let r=h+s+((l?t==h?-1:t==u?1:e:e)<0?0:a);if(i)return r;let n=t==h?2:t==u?1:4;return(e<0?t!=h:t!=u)&&(n|=8),new yt(r,n,t==(e<0?h:u)?null:o/3+(t-h)*mt)}s+=a-l}return i?t+s:new yt(t+s,0,null)}touches(t,e){let i=0,s=vt(e),r=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+r];if(t<=o+h&&e==3*s)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 s=0,r=0;s<this.ranges.length;s+=3){let n=this.ranges[s],o=n-(this.inverted?r:0),h=n+(this.inverted?0:r),l=this.ranges[s+e],a=this.ranges[s+i];t(o,o+l,h,h+a),r+=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,s=(t?t.length:0)){this.mirror=e,this.from=i,this.to=s,this._maps=t||[],this.ownData=!(t||e)}get maps(){return this._maps}slice(t=0,e=this.maps.length){return new 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 s=t.getMirror(e);this.appendMap(t._maps[e],null!=s&&s<e?i+s:void 0)}}getMirror(t){if(this.mirror)for(let e=0;e<this.mirror.length;e++)if(this.mirror[e]==t)return this.mirror[e+(e%2?-1:1)]}setMirror(t,e){this.mirror||(this.mirror=[]),this.mirror.push(t,e)}appendMappingInverted(t){for(let e=t.maps.length-1,i=this._maps.length+t._maps.length;e>=0;e--){let s=t.getMirror(e);this.appendMap(t._maps[e].invert(),null!=s&&s>e?i-s-1:void 0)}}invert(){let t=new 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 s=0;for(let i=this.from;i<this.to;i++){let r=this._maps[i].mapResult(t,e);if(null!=r.recover){let e=this.getMirror(i);if(null!=e&&e>i&&e<this.to){i=e,t=this._maps[e].recover(r.recover);continue}}s|=r.delInfo,t=r.pos}return i?t:new yt(t,s,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,s){try{return Ct.ok(t.replace(e,i,s))}catch(t){if(t instanceof w)return Ct.fail(t.message);throw t}}}function At(t,e,i){let s=[];for(let r=0;r<t.childCount;r++){let n=t.child(r);n.content.size&&(n=n.copy(At(n.content,e,n))),n.isInline&&(n=e(n,i,r)),s.push(n)}return c.fromArray(s)}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),s=i.node(i.sharedDepth(this.to)),r=new m(At(e.content,((t,e)=>t.isAtom&&e.type.allowsMarkType(this.mark.type)?t.mark(this.mark.addToSet(t.marks)):t),s),e.openStart,e.openEnd);return Ct.fromReplace(t,this.from,this.to,r)}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,s=!1){super(),this.from=t,this.to=e,this.slice=i,this.structure=s}apply(t){return this.structure&&$t(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.to,-1),i=this.from==this.to&&Et.MAP_BIAS<0?e:t.mapResult(this.from,1);return i.deletedAcross&&e.deletedAcross?null:new Et(i.pos,Math.max(i.pos,e.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)}}Et.MAP_BIAS=1,xt.jsonID("replace",Et);class It extends xt{constructor(t,e,i,s,r,n,o=!1){super(),this.from=t,this.to=e,this.gapFrom=i,this.gapTo=s,this.slice=r,this.insert=n,this.structure=o}apply(t){if(this.structure&&($t(t,this.from,this.gapFrom)||$t(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),s=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1),r=this.to==this.gapTo?i.pos:t.map(this.gapTo,1);return e.deletedAcross&&i.deletedAcross||s<e.pos||r>i.pos?null:new It(e.pos,i.pos,s,r,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 $t(t,e,i){let s=t.resolve(e),r=i-e,n=s.depth;for(;r>0&&n>0&&s.indexAfter(n)==s.node(n).childCount;)n--,r--;if(r>0){let t=s.node(n).maybeChild(s.indexAfter(n));for(;r>0;){if(!t||t.isLeaf)return!0;t=t.firstChild,r--}}return!1}function Pt(t,e,i,s=i.contentMatch,r=!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=s.matchType(l.type);if(u){s=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(r&&l.isText&&"pre"!=i.whitespace){let t,e,s=/\r?\n|\r/g;for(;t=s.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(!s.validEnd){let e=s.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 Dt(t,e,i){return(0==e||t.canReplace(e,t.childCount))&&(i==t.childCount||t.canReplace(0,i))}function Rt(t){let e=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let i=t.depth,s=0,r=0;;--i){let n=t.$from.node(i),o=t.$from.index(i)+s,h=t.$to.indexAfter(i)-r;if(i<t.depth&&n.canReplace(o,h,e))return i;if(0==i||n.type.spec.isolating||!Dt(n,o,h))break;o&&(s=1),h<n.childCount&&(r=1)}return null}function jt(t,e,i,s){e.forEach(((r,n)=>{if(r.isText){let o,h=/\r?\n|\r/g;for(;o=h.exec(r.text);){let r=t.mapping.slice(s).map(i+1+n+o.index);t.replaceWith(r,r+1,e.type.schema.linebreakReplacement.create())}}}))}function Ft(t,e,i,s){e.forEach(((r,n)=>{if(r.type==r.type.schema.linebreakReplacement){let r=t.mapping.slice(s).map(i+1+n);t.replaceWith(r,r+1,e.type.schema.text("\n"))}}))}function Ut(t,e,i=1,s){let r=t.resolve(e),n=r.depth-i,o=s&&s[s.length-1]||r.parent;if(n<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!o.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let t=r.depth-1,e=i-2;t>n;t--,e--){let i=r.node(t),n=r.index(t);if(i.type.spec.isolating)return!1;let o=i.content.cutByIndex(n,i.childCount),h=s&&s[e+1];h&&(o=o.replaceChild(0,h.type.create(h.attrs)));let l=s&&s[e]||i;if(!i.canReplace(n+1,i.childCount)||!l.type.validContent(o))return!1}let h=r.indexAfter(n),l=s&&s[0];return r.node(n).canReplaceWith(h,h,l?l.type:r.node(n+1).type)}function Nt(t,e){let i=t.resolve(e),s=i.index();return function(t,e){return!(!t||!e||t.isLeaf||!function(t,e){e.content.size||t.type.compatibleContent(e.type);let i=t.contentMatchAt(t.childCount),{linebreakReplacement:s}=t.type.schema;for(let r=0;r<e.childCount;r++){let n=e.child(r);if(i=i.matchType(n.type==s?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(s,s+1)}function zt(t,e,i=e,s=m.empty){if(e==i&&!s.size)return null;let r=t.resolve(e),n=t.resolve(i);return _t(r,n,s)?new Et(e,i,s):new Lt(r,n,s).fit()}function _t(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 Lt{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,s=this.close(t<0?this.$to:i.doc.resolve(t));if(!s)return null;let r=this.placed,n=i.depth,o=s.depth;for(;n&&o&&1==r.childCount;)r=r.firstChild.content,n--,o--;let h=new m(r,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,s.pos,h):null}findFittable(){let t=this.unplaced.openStart;for(let e=this.unplaced.content,i=0,s=this.unplaced.openEnd;i<t;i++){let r=e.firstChild;if(e.childCount>1&&(s=0),r.type.spec.isolating&&s<=i){t=i;break}e=r.content}for(let e=1;e<=2;e++)for(let i=1==e?t:this.unplaced.openStart;i>=0;i--){let t,s=null;i?(s=Yt(this.unplaced.content,i-1).firstChild,t=s.content):t=this.unplaced.content;let r=t.firstChild;for(let t=this.depth;t>=0;t--){let n,{type:o,match:h}=this.frontier[t],l=null;if(1==e&&(r?h.matchType(r.type)||(l=h.fillBefore(c.from(r),!1)):s&&o.compatibleContent(s.type)))return{sliceDepth:i,frontierDepth:t,parent:s,inject:l};if(2==e&&r&&(n=h.findWrapping(r.type)))return{sliceDepth:i,frontierDepth:t,parent:s,wrap:n};if(s&&h.matchType(s.type))break}}}openMore(){let{content:t,openStart:e,openEnd:i}=this.unplaced,s=Yt(t,e);return!(!s.childCount||s.firstChild.isLeaf||(this.unplaced=new m(t,e+1,Math.max(i,s.size+e>=t.size-i?e+1:0)),0))}dropNode(){let{content:t,openStart:e,openEnd:i}=this.unplaced,s=Yt(t,e);if(s.childCount<=1&&e>0){let r=t.size-e<=e+s.size;this.unplaced=new m(Ht(t,e-1,1),e-1,r?e-1:i)}else this.unplaced=new m(Ht(t,e,1),e,i)}placeNodes({sliceDepth:t,frontierDepth:e,parent:i,inject:s,wrap:r}){for(;this.depth>e;)this.closeFrontierNode();if(r)for(let t=0;t<r.length;t++)this.openFrontierNode(r[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(s){for(let t=0;t<s.childCount;t++)a.push(s.child(t));u=u.matchFragment(s)}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,s=this.$to.after(i);for(;i>1&&s==this.$to.end(--i);)++s;return s}findCloseLevel(t){t:for(let e=Math.min(this.depth,t.depth);e>=0;e--){let{match:i,type:s}=this.frontier[e],r=e<t.depth&&t.end(e+1)==t.pos+(t.depth-(e+1)),n=Vt(t,e,s,i,r);if(n){for(let i=e-1;i>=0;i--){let{match:e,type:s}=this.frontier[i],r=Vt(t,i,s,e,!0);if(!r||r.childCount)continue t}return{depth:e,fit:n,move:r?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),s=e.type.contentMatch.fillBefore(e.content,!0,t.index(i));this.openFrontierNode(e.type,e.attrs,s)}return t}openFrontierNode(t,e=null,i){let s=this.frontier[this.depth];s.match=s.match.matchType(t),this.placed=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 s=t.content;return e>1&&(s=s.replaceChild(0,Wt(s.firstChild,e-1,1==s.childCount?i-1:0))),e>0&&(s=t.type.contentMatch.fillBefore(s).append(s),i<=0&&(s=s.append(t.type.contentMatch.matchFragment(s).fillBefore(c.empty,!0)))),t.copy(s)}function Vt(t,e,i,s,r){let n=t.node(e),o=r?t.indexAfter(e):t.index(e);if(o==n.childCount&&!i.compatibleContent(n.type))return null;let h=s.fillBefore(n.content,!0,o);return h&&!function(t,e,i){for(let s=i;s<e.childCount;s++)if(!t.allowsMarks(e.child(s).marks))return!0;return!1}(i,n.content,o)?h:null}function Kt(t,e,i,s,r){if(e<i){let r=t.firstChild;t=t.replaceChild(0,r.copy(Kt(r.content,e+1,i,s,r)))}if(e>s){let e=r.contentMatchAt(0),i=e.fillBefore(t).append(t);t=i.append(e.matchFragment(i).fillBefore(c.empty,!0))}return t}function Jt(t,e){let i=[];for(let s=Math.min(t.depth,e.depth);s>=0;s--){let r=t.start(s);if(r<t.pos-(t.depth-s)||e.end(s)>e.pos+(e.depth-s)||t.node(s).type.spec.isolating||e.node(s).type.spec.isolating)break;(r==e.start(s)||s==t.depth&&s==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&s&&e.start(s-1)==r-1)&&i.push(s)}return i}class Qt 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 s=e.type.create(i,null,e.marks);return Ct.fromReplace(t,this.pos,this.pos+1,new m(c.from(s),0,e.isLeaf?0:1))}getMap(){return kt.empty}invert(t){return new Qt(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 Qt(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 Qt(e.pos,e.attr,e.value)}}xt.jsonID("attr",Qt);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 s=this.mapping.maps[i];i&&(t=s.map(t,1),e=s.map(e,-1)),s.forEach(((i,s,r,n)=>{t=Math.min(t,r),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 s=zt(this.doc,t,e,i);return s&&this.step(s),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,s){if(!s.size)return t.deleteRange(e,i);let r=t.doc.resolve(e),n=t.doc.resolve(i);if(_t(r,n,s))return t.step(new Et(e,i,s));let o=Jt(r,n);0==o[o.length-1]&&o.pop();let h=-(r.depth+1);o.unshift(h);for(let t=r.depth,e=r.pos-1;t>0;t--,e--){let i=r.node(t).type.spec;if(i.defining||i.definingAsContext||i.isolating)break;o.indexOf(t)>-1?h=t:r.before(t)==e&&o.splice(1,0,-t)}let l=o.indexOf(h),a=[],u=s.openStart;for(let t=s.content,e=0;;e++){let i=t.firstChild;if(a.push(i),e==s.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(r.node(Math.abs(h)-1)))u=t;else if(i||!e.type.isTextblock)break}var c;for(let e=s.openStart;e>=0;e--){let h=(e+u+1)%(s.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=r.node(a-1),d=r.index(a-1);if(f.canReplaceWith(d,d,c.type,c.marks))return t.replace(r.before(a),u?n.after(a):i,new m(Kt(s.content,0,s.openStart,h),h,s.openEnd))}}let f=t.steps.length;for(let h=o.length-1;h>=0&&(t.replace(e,i,s),!(t.steps.length>f));h--){let t=o[h];t<0||(e=r.before(t),i=n.after(t))}}(this,t,e,i),this}replaceRangeWith(t,e,i){return function(t,e,i,s){if(!s.isInline&&e==i&&t.doc.resolve(e).parent.content.size){let r=function(t,e,i){let s=t.resolve(e);if(s.parent.canReplaceWith(s.index(),s.index(),i))return e;if(0==s.parentOffset)for(let t=s.depth-1;t>=0;t--){let e=s.index(t);if(s.node(t).canReplaceWith(e,e,i))return s.before(t+1);if(e>0)return null}if(s.parentOffset==s.parent.content.size)for(let t=s.depth-1;t>=0;t--){let e=s.indexAfter(t);if(s.node(t).canReplaceWith(e,e,i))return s.after(t+1);if(e<s.node(t).childCount)return null}return null}(t.doc,e,s.type);null!=r&&(e=i=r)}t.replaceRange(e,i,new m(c.from(s),0,0))}(this,t,e,i),this}deleteRange(t,e){return function(t,e,i){let s=t.doc.resolve(e),r=t.doc.resolve(i);if(s.parent.isTextblock&&r.parent.isTextblock&&s.start()!=r.start()&&0==s.parentOffset&&0==r.parentOffset){let n=s.sharedDepth(i),o=!1;for(let t=s.depth;t>n;t--)s.node(t).type.spec.isolating&&(o=!0);for(let t=r.depth;t>n;t--)r.node(t).type.spec.isolating&&(o=!0);if(!o){for(let t=s.depth;t>0&&e==s.start(t);t--)e=s.before(t);for(let t=r.depth;t>0&&i==r.start(t);t--)i=r.before(t);s=t.doc.resolve(e),r=t.doc.resolve(i)}}let n=Jt(s,r);for(let e=0;e<n.length;e++){let i=n[e],o=e==n.length-1;if(o&&0==i||s.node(i).type.contentMatch.validEnd)return t.delete(s.start(i),r.end(i));if(i>0&&(o||s.node(i-1).canReplace(s.index(i-1),r.indexAfter(i-1))))return t.delete(s.before(i),r.after(i))}for(let n=1;n<=s.depth&&n<=r.depth;n++)if(e-s.start(n)==s.depth-n&&i>s.end(n)&&r.end(n)-i!=r.depth-n&&s.start(n-1)==r.start(n-1)&&s.node(n-1).canReplace(s.index(n-1),r.index(n-1)))return t.delete(s.before(n),i);t.delete(e,i)}(this,t,e),this}lift(t,e){return function(t,e,i){let{$from:s,$to:r,depth:n}=e,o=s.before(n+1),h=r.after(n+1),l=o,a=h,u=c.empty,f=0;for(let t=n,e=!1;t>i;t--)e||s.index(t)>0?(e=!0,u=c.from(s.node(t).copy(u)),f++):l--;let d=c.empty,p=0;for(let t=n,e=!1;t>i;t--)e||r.after(t+1)<r.end(t)?(e=!0,d=c.from(r.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 s=null,{linebreakReplacement:r}=t.doc.type.schema,n=t.doc.resolve(e-i),o=n.node().type;if(r&&o.inlineContent){let t="pre"==o.whitespace,e=!!o.contentMatch.matchType(r);t&&!e?s=!1:!t&&e&&(s=!0)}let h=t.steps.length;if(!1===s){let s=t.doc.resolve(e+i);Ft(t,s.node(),s.before(),h)}o.inlineContent&&Pt(t,e+i-1,o,n.node().contentMatchAt(n.index()),null==s);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===s){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 s=c.empty;for(let t=i.length-1;t>=0;t--){if(s.size){let e=i[t].type.contentMatch.matchFragment(s);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}s=c.from(i[t].type.create(i[t].attrs,s))}let r=e.start,n=e.end;t.step(new It(r,n,r,n,new m(s,0,0),i.length,!0))}(this,t,e),this}setBlockType(t,e=t,i,s=null){return function(t,e,i,s,r){if(!s.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 r?r(e):r;if(e.isTextblock&&!e.hasMarkup(s,o)&&function(t,e,i){let s=t.resolve(e),r=s.index();return s.parent.canReplaceWith(r,r+1,i)}(t.doc,t.mapping.slice(n).map(i),s)){let r=null;if(s.schema.linebreakReplacement){let t="pre"==s.whitespace,e=!!s.contentMatch.matchType(s.schema.linebreakReplacement);t&&!e?r=!1:!t&&e&&(r=!0)}!1===r&&Ft(t,e,i,n),Pt(t,t.mapping.slice(n).map(i,1),s,void 0,null===r);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(s.create(o,null,e.marks)),0,0),1,!0)),!0===r&&jt(t,e,i,n),!1}}))}(this,t,e,i,s),this}setNodeMarkup(t,e,i=null,s){return function(t,e,i,s,r){let n=t.doc.nodeAt(e);if(!n)throw new RangeError("No node at given position");i||(i=n.type);let o=i.create(s,null,r||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,s),this}setNodeAttribute(t,e,i){return this.step(new Qt(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 s,r=i.marks,n=[];for(;s=e.isInSet(r);)n.push(new Ot(t,s)),r=s.removeFromSet(r);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,s){let r=t.doc.resolve(e),n=c.empty,o=c.empty;for(let t=r.depth,e=r.depth-i,h=i-1;t>e;t--,h--){n=c.from(r.node(t).copy(n));let e=s&&s[h];o=c.from(e?e.type.create(e.attrs,o):r.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,s){let r,n,o=[],h=[];t.doc.nodesBetween(e,i,((t,l,a)=>{if(!t.isInline)return;let u=t.marks;if(!s.isInSet(u)&&a.type.allowsMarkType(s.type)){let a=Math.max(l,e),c=Math.min(l+t.nodeSize,i),f=s.addToSet(u);for(let t=0;t<u.length;t++)u[t].isInSet(f)||(r&&r.to==a&&r.mark.eq(u[t])?r.to=c:o.push(r=new Bt(a,c,u[t])));n&&n.to==a?n.to=c:h.push(n=new St(a,c,s))}})),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,s){let r=[],n=0;t.doc.nodesBetween(e,i,((t,o)=>{if(!t.isInline)return;n++;let h=null;if(s instanceof Z){let e,i=t.marks;for(;e=s.isInSet(i);)(h||(h=[])).push(e),i=e.removeFromSet(i)}else s?s.isInSet(t.marks)&&(h=[s]):h=t.marks;if(h&&h.length){let s=Math.min(o+t.nodeSize,i);for(let t=0;t<h.length;t++){let i,l=h[t];for(let t=0;t<r.length;t++){let e=r[t];e.step==n-1&&l.eq(r[t].style)&&(i=e)}i?(i.to=s,i.step=n):r.push({style:l,from:Math.max(o,e),to:s,step:n})}}})),r.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,s=null;for(let t=0;t<e.openEnd;t++)s=i,i=i.lastChild;let r=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(r);t.replaceRange(a.map(h.pos),a.map(l.pos),o?m.empty:e),0==o&&fe(t,r,(i?i.isInline:s&&s.isTextblock)?-1:1)}}replaceWith(t,e){let i=t.steps.length,s=this.ranges;for(let r=0;r<s.length;r++){let{$from:n,$to:o}=s[r],h=t.mapping.slice(i),l=h.map(n.pos),a=h.map(o.pos);r?t.deleteRange(l,a):(t.replaceRangeWith(l,a,e),fe(t,i,e.isInline?-1:1))}}static findFrom(t,e,i=!1){let s=t.parent.inlineContent?new ne(t):ce(t.node(0),t.parent,t.pos,t.index(),e,i);if(s)return s;for(let s=t.depth-1;s>=0;s--){let r=e<0?ce(t.node(0),t.node(s),t.before(s+1),t.index(s),e,i):ce(t.node(0),t.node(s),t.after(s+1),t.index(s)+1,e,i);if(r)return r}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 se=!1;function re(t){se||t.parent.inlineContent||(se=!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){re(t),re(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 s=t.resolve(e.map(this.anchor));return new ne(s.parent.inlineContent?s: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 s=t.resolve(e);return new this(s,i==e?s:t.resolve(i))}static between(t,e,i){let s=t.pos-e.pos;if(i&&!s||(i=s>=0?1:-1),!e.parent.inlineContent){let t=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==s||(t=(ee.findFrom(t,-i,!0)||ee.findFrom(t,i,!0)).$anchor).pos<e.pos!=s<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:s}=e.mapResult(this.anchor),r=t.resolve(s);return i?ee.near(r):new he(r)}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,s,r,n=!1){if(e.inlineContent)return ne.create(t,i);for(let o=s-(r>0?0:1);r>0?o<e.childCount:o>=0;o+=r){let s=e.child(o);if(s.isAtom){if(!n&&he.isSelectable(s))return he.create(t,i-(r<0?s.nodeSize:0))}else{let e=ce(t,s,i+r,r<0?s.childCount:0,r,n);if(e)return e}i+=s.nodeSize*r}return null}function fe(t,e,i){let s=t.steps.length-1;if(s<e)return;let r,n=t.steps[s];(n instanceof Et||n instanceof It)&&(t.mapping.maps[s].forEach(((t,e,i,s)=>{null==r&&(r=s)})),t.setSelection(ee.near(t.doc.resolve(r),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 s=this.doc.type.schema;if(null==e)return t?this.replaceSelectionWith(s.text(t),!0):this.deleteSelection();{if(null==i&&(i=e),!t)return this.deleteRange(e,i);let r=this.storedMarks;if(!r){let t=this.doc.resolve(e);r=i==e?t.marks():t.marksAcross(this.doc.resolve(i))}return this.replaceRangeWith(e,i,s.text(t,r)),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,s)=>s.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),s=null;for(;;){let r=!1;for(let n=0;n<this.config.plugins.length;n++){let o=this.config.plugins[n];if(o.spec.appendTransaction){let h=s?s[n].n:0,l=s?s[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),!s){s=[];for(let t=0;t<this.config.plugins.length;t++)s.push(t<n?{state:i,n:e.length}:{state:this,n:0})}e.push(a),i=i.applyInner(a),r=!0}s&&(s[n]={state:i,n:e.length})}}if(!r)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 s=0;s<i.length;s++){let r=i[s];e[r.name]=r.apply(t,this[r.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 s=0;s<e.fields.length;s++)i[e.fields[s].name]=e.fields[s].init(t,i);return i}reconfigure(t){let e=new me(this.schema,t.plugins),i=e.fields,s=new ve(e);for(let e=0;e<i.length;e++){let r=i[e].name;s[r]=this.hasOwnProperty(r)?this[r]:i[e].init(t,s)}return s}toJSON(t){let e={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(e.storedMarks=this.storedMarks.map((t=>t.toJSON()))),t&&"object"==typeof t)for(let i in t){if("doc"==i||"selection"==i)throw new RangeError("The JSON fields `doc` and `selection` are reserved");let s=t[i],r=s.spec.state;r&&r.toJSON&&(e[i]=r.toJSON.call(s,this[s.key]))}return e}static fromJSON(t,e,i){if(!e)throw new RangeError("Invalid input for EditorState.fromJSON");if(!t.schema)throw new RangeError("Required config field 'schema' missing");let s=new me(t.schema,t.plugins),r=new ve(s);return s.fields.forEach((s=>{if("doc"==s.name)r.doc=R.fromJSON(t.schema,e.doc);else if("selection"==s.name)r.selection=ee.fromJSON(r.doc,e.selection);else if("storedMarks"==s.name)e.storedMarks&&(r.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==s.name&&h&&h.fromJSON&&Object.prototype.hasOwnProperty.call(e,n))return void(r[s.name]=h.fromJSON.call(o,t,e[n],r))}r[s.name]=s.init(t,r)}})),r}}function ye(t,e,i){for(let s in t){let r=t[s];r instanceof Function?r=r.bind(e):"handleDOMEvents"==s&&(r=ye(r,e,{})),i[s]=r}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 s=Ce||(Ce=document.createRange());return s.setEnd(t,null==i?t.nodeValue.length:i),s.setStart(t,e||0),s},Se=function(t,e,i,s){return i&&(Te(t,e,i,s,-1)||Te(t,e,i,s,1))},Be=/^(img|br|input|textarea|hr)$/i;function Te(t,e,i,s,r){for(var n;;){if(t==i&&e==s)return!0;if(e==(r<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)+(r<0?0:1),t=i}else{if(1!=t.nodeType)return!1;{let i=t.childNodes[e+(r<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+=r}else t=i,e=r<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 $e(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,De="undefined"!=typeof document?document:null,Re=Pe&&Pe.userAgent||"",je=/Edge\/(\d+)/.exec(Re),Fe=/MSIE \d/.exec(Re),Ue=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Re),Ne=!!(Fe||Ue||je),ze=Fe?document.documentMode:Ue?+Ue[1]:je?+je[1]:0,_e=!Ne&&/gecko\/(\d+)/i.test(Re),Le=!Ne&&/Chrome\/(\d+)/.exec(Re),He=!!Le,Xe=Le?+Le[1]:0,Ye=!Ne&&!!Pe&&/Apple Computer/.test(Pe.vendor),We=Ye&&(/Mobile\/\w+/.test(Re)||!!Pe&&Pe.maxTouchPoints>2),Ve=We||!!Pe&&/Mac/.test(Pe.platform),Ke=!!Pe&&/Win/.test(Pe.platform),Je=/Android \d/.test(Re),Qe=!!De&&"webkitFontSmoothing"in De.documentElement.style,qe=Qe?+(/\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 s=t.someProp("scrollThreshold")||0,r=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(s,"top")?a=-(h.top-e.top+Ze(r,"top")):e.bottom>h.bottom-Ze(s,"bottom")&&(a=e.bottom-e.top>h.bottom-h.top?e.top+Ze(r,"top")-h.top:e.bottom-h.bottom+Ze(r,"bottom")),e.left<h.left+Ze(s,"left")?l=-(h.left-e.left+Ze(r,"left")):e.right>h.right-Ze(s,"right")&&(l=e.right-h.right+Ze(r,"right")),l||a)if(i)n.defaultView.scrollBy(l,a);else{let i=t.scrollLeft,s=t.scrollTop;a&&(t.scrollTop+=a),l&&(t.scrollLeft+=l);let r=t.scrollLeft-i,n=t.scrollTop-s;e={left:e.left-r,top:e.top-n,right:e.right-r,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 s=t;s&&(e.push({dom:s,top:s.scrollTop,left:s.scrollLeft}),t!=i);s=xe(s));return e}function si(t,e){for(let i=0;i<t.length;i++){let{dom:s,top:r,left:n}=t[i];s.scrollTop!=r+e&&(s.scrollTop=r+e),s.scrollLeft!=n&&(s.scrollLeft=n)}}let ri=null;function ni(t,e){let i,s,r,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,s=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&&!r&&d.left<=e.left&&d.right>=e.left&&(r=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&&r&&(i=r,s=n,o=0),i&&3==i.nodeType?function(t,e){let i,s=t.nodeValue.length,r=document.createRange();for(let n=0;n<s;n++){r.setEnd(t,n+1),r.setStart(t,n);let s=ui(r,1);if(s.top!=s.bottom&&oi(e,s)){i={node:t,offset:n+(e.left>=(s.left+s.right)/2?1:0)};break}}return r.detach(),i||{node:t,offset:0}}(i,s):!i||o&&1==i.nodeType?{node:t,offset:h}:ni(i,s)}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 s=t.childNodes.length;if(s&&i.top<i.bottom)for(let r=Math.max(0,Math.min(s-1,Math.floor(s*(e.top-i.top)/(i.bottom-i.top))-2)),n=r;;){let i=t.childNodes[n];if(1==i.nodeType){let t=i.getClientRects();for(let s=0;s<t.length;s++){let r=t[s];if(oi(e,r))return hi(i,e,r)}}if((n=(n+1)%s)==r)break}return t}function li(t,e){let i,s=t.dom.ownerDocument,r=0,n=function(t,e,i){if(t.caretPositionFromPoint)try{let s=t.caretPositionFromPoint(e,i);if(s)return{node:s.offsetNode,offset:Math.min(Oe(s.offsetNode),s.offset)}}catch(t){}if(t.caretRangeFromPoint){let s=t.caretRangeFromPoint(e,i);if(s)return{node:s.startContainer,offset:Math.min(Oe(s.startContainer),s.startOffset)}}}(s,e.left,e.top);n&&({node:i,offset:r}=n);let o,h=(t.root.elementFromPoint?t.root:s).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(_e&&1==i.nodeType&&(r=Math.min(r,i.childNodes.length),r<i.childNodes.length)){let t,s=i.childNodes[r];"IMG"==s.nodeName&&(t=s.getBoundingClientRect()).right<=e.left&&t.bottom>e.top&&r++}let s;Qe&&r&&1==i.nodeType&&1==(s=i.childNodes[r-1]).nodeType&&"false"==s.contentEditable&&s.getBoundingClientRect().top>=e.top&&r--,i==t.dom&&r==i.childNodes.length-1&&1==i.lastChild.nodeType&&e.top>i.lastChild.getBoundingClientRect().bottom?o=t.state.doc.content.size:0!=r&&1==i.nodeType&&"BR"==i.childNodes[r-1].nodeName||(o=function(t,e,i,s){let r=-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>s.left||e.top>s.top?r=o.posBefore:(!n&&e.right<s.left||e.bottom<s.top)&&(r=o.posAfter),n=!0),!o.contentDOM&&r<0&&!o.node.isText))return(o.node.isBlock?s.top<(e.top+e.bottom)/2:s.left<(e.left+e.right)/2)?o.posBefore:o.posAfter;i=o.dom.parentNode}return r>-1?r:t.docView.posFromDOM(e,i,-1)}(t,i,r,e))}null==o&&(o=function(t,e,i){let{node:s,offset:r}=ni(e,i),n=-1;if(1==s.nodeType&&!s.firstChild){let t=s.getBoundingClientRect();n=t.left!=t.right&&i.left>(t.left+t.right)/2?1:-1}return t.docView.posFromDOM(s,r,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:s,offset:r,atom:n}=t.docView.domFromPos(e,i<0?-1:1),o=Qe||_e;if(3==s.nodeType){if(!o||!ci.test(s.nodeValue)&&(i<0?r:r!=s.nodeValue.length)){let t=r,e=r,n=i<0?1:-1;return i<0&&!r?(e++,n=-1):i>=0&&r==s.nodeValue.length?(t--,n=1):i<0?t--:e++,di(ui(Ae(s,t,e),n),n<0)}{let t=ui(Ae(s,r,r),i);if(_e&&r&&/\s/.test(s.nodeValue[r-1])&&r<s.nodeValue.length){let e=ui(Ae(s,r-1,r-1),-1);if(e.top==t.top){let i=ui(Ae(s,r,r+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&&r&&(i<0||r==Oe(s))){let t=s.childNodes[r-1];if(1==t.nodeType)return pi(t.getBoundingClientRect(),!1)}if(null==n&&r<Oe(s)){let t=s.childNodes[r];if(1==t.nodeType)return pi(t.getBoundingClientRect(),!0)}return pi(s.getBoundingClientRect(),i>=0)}if(null==n&&r&&(i<0||r==Oe(s))){let t=s.childNodes[r-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&&r<Oe(s)){let t=s.childNodes[r];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==s.nodeType?Ae(s):s,-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 s=t.state,r=t.root.activeElement;s!=e&&t.updateState(e),r!=t.dom&&t.focus();try{return i()}finally{s!=e&&t.updateState(s),r!=t.dom&&r&&r.focus()}}const wi=/[\u0590-\u08ac]/;let mi=null,vi=null,yi=!1;class ki{constructor(t,e,i,s){this.parent=t,this.children=e,this.dom=i,this.contentDOM=s,this.dirty=0,i.pmViewDesc=this}matchesWidget(t){return!1}matchesMark(t){return!1}matchesNode(t,e,i){return!1}matchesHack(t){return!1}parseRule(){return null}stopEvent(t){return!1}get size(){let t=0;for(let e=0;e<this.children.length;e++)t+=this.children[e].size;return t}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let t=0;t<this.children.length;t++)this.children[t].destroy()}posBeforeChild(t){for(let e=0,i=this.posAtStart;;e++){let s=this.children[e];if(s==t)return i;i+=s.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(t,e,i){if(this.contentDOM&&this.contentDOM.contains(1==t.nodeType?t:t.parentNode)){if(i<0){let i,s;if(t==this.contentDOM)i=t.childNodes[e-1];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.previousSibling}for(;i&&(!(s=i.pmViewDesc)||s.parent!=this);)i=i.previousSibling;return i?this.posBeforeChild(s)+s.size:this.posAtStart}{let i,s;if(t==this.contentDOM)i=t.childNodes[e];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.nextSibling}for(;i&&(!(s=i.pmViewDesc)||s.parent!=this);)i=i.nextSibling;return i?this.posBeforeChild(s):this.posAtEnd}}let s;if(t==this.dom&&this.contentDOM)s=e>Me(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))s=2&t.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==e)for(let e=t;;e=e.parentNode){if(e==this.dom){s=!1;break}if(e.previousSibling)break}if(null==s&&e==t.childNodes.length)for(let e=t;;e=e.parentNode){if(e==this.dom){s=!0;break}if(e.nextSibling)break}}return(null==s?i>0:s)?this.posAtEnd:this.posAtStart}nearestDesc(t,e=!1){for(let i=!0,s=t;s;s=s.parentNode){let r,n=this.getDesc(s);if(n&&(!e||n.node)){if(!i||!(r=n.nodeDOM)||(1==r.nodeType?r.contains(1==t.nodeType?t:t.parentNode):r==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 s=t;s;s=s.parentNode){let r=this.getDesc(s);if(r)return r.localPosFromDOM(t,e,i)}return-1}descAt(t){for(let e=0,i=0;e<this.children.length;e++){let s=this.children[e],r=i+s.size;if(i==t&&r!=i){for(;!s.border&&s.children.length;)for(let t=0;t<s.children.length;t++){let e=s.children[t];if(e.size){s=e;break}}return s}if(t<r)return s.descAt(t-i-s.border);i=r}}domFromPos(t,e){if(!this.contentDOM)return{node:this.dom,offset:0,atom:t+1};let i=0,s=0;for(let e=0;i<this.children.length;i++){let r=this.children[i],n=e+r.size;if(n>t||r instanceof Bi){s=t-e;break}e=n}if(s)return this.children[i].domFromPos(s-this.children[i].border,e);for(let t;i&&!(t=this.children[i-1]).size&&t instanceof bi&&t.side>=0;i--);if(e<=0){let t,s=!0;for(;t=i?this.children[i-1]:null,t&&t.dom.parentNode!=this.contentDOM;i--,s=!1);return t&&e&&s&&!t.border&&!t.domAtom?t.domFromPos(t.size,e):{node:this.contentDOM,offset:t?Me(t.dom)+1:0}}{let t,s=!0;for(;t=i<this.children.length?this.children[i]:null,t&&t.dom.parentNode!=this.contentDOM;i++,s=!1);return t&&s&&!t.border&&!t.domAtom?t.domFromPos(0,e):{node:this.contentDOM,offset:t?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 s=-1,r=-1;for(let n=i,o=0;;o++){let i=this.children[o],h=n+i.size;if(-1==s&&t<=h){let r=n+i.border;if(t>=r&&e<=h-i.border&&i.node&&i.contentDOM&&this.contentDOM.contains(i.contentDOM))return i.parseRange(t,e,r);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)){s=Me(i.dom)+1;break}t-=i.size}-1==s&&(s=0)}if(s>-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)){r=Me(i.dom);break}e+=i.size}-1==r&&(r=this.contentDOM.childNodes.length);break}n=h}return{node:this.contentDOM,from:t,to:e,fromOffset:s,toOffset:r}}emptyChildAt(t){if(this.border||!this.contentDOM||!this.children.length)return!1;let e=this.children[t<0?0:this.children.length-1];return 0==e.size||e.emptyChildAt(t)}domAfterPos(t){let{node:e,offset:i}=this.domFromPos(t,0);if(1!=e.nodeType||i==e.childNodes.length)throw new RangeError("No node after pos "+t);return e.childNodes[i]}setSelection(t,e,i,s=!1){let r=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(r>h&&n<a)return l.setSelection(t-h-l.border,e-h-l.border,i,s);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((_e||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(_e&&a.focusNode&&a.focusNode!=h.node&&1==a.focusNode.nodeType){let t=a.focusNode.childNodes[a.focusOffset];t&&"false"==t.contentEditable&&(s=!0)}if(!(s||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||!_e)){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,s=0;s<this.children.length;s++){let r=this.children[s],n=i+r.size;if(i==n?t<=n&&e>=i:t<n&&e>i){let s=i+r.border,o=n-r.border;if(t>=s&&e<=o)return this.dirty=t==i||e==n?2:1,void(t!=s||e!=o||!r.contentLost&&r.dom.parentNode==this.contentDOM?r.markDirty(t-s,e-s):r.dirty=3);r.dirty=r.dom!=r.contentDOM||r.dom.parentNode!=this.contentDOM||r.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,s){let r,n=e.type.toDOM;if("function"==typeof n&&(n=n(i,(()=>r?r.parent?r.parent.posBeforeChild(r):void 0:s))),!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,r=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,s){super(t,[],e,null),this.textDOM=i,this.text=s}get size(){return this.text.length}localPosFromDOM(t,e){return t!=this.textDOM?this.posAtStart+(e?this.size:0):this.posAtStart+e}domFromPos(t){return{node:this.textDOM,offset:t}}ignoreMutation(t){return"characterData"===t.type&&t.target.nodeValue==t.oldValue}}class xi extends ki{constructor(t,e,i,s,r){super(t,[],i,s),this.mark=e,this.spec=r}static create(t,e,i,s){let r=s.nodeViews[e.type.name],n=r&&r(e,s,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 s=xi.create(this.parent,this.mark,!0,i),r=this.children,n=this.size;e<n&&(r=zi(r,e,n,i)),t>0&&(r=zi(r,0,t,i));for(let t=0;t<r.length;t++)r[t].parent=s;return s.children=r,s}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,s,r,n,o,h,l){super(t,[],r,n),this.node=e,this.outerDeco=i,this.innerDeco=s,this.nodeDOM=o}static create(t,e,i,s,r,n){let o,h=r.nodeViews[e.type.name],l=h&&h(e,r,(()=>o?o.parent?o.parent.posBeforeChild(o):void 0:n),i,s),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,s,a,u||null,c,l,r,n+1):e.isText?new Si(t,e,i,s,a,c,r):new Ci(t,e,i,s,a,u||null,c,r,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,s=e,r=t.composing?this.localCompositionInfo(t,e):null,n=r&&r.pos>-1?r:null,o=r&&r.pos<0,h=new Ui(this,n&&n.node,t);!function(t,e,i,s){let r=e.locals(t),n=0;if(0==r.length){for(let i=0;i<t.childCount;i++){let o=t.child(i);s(o,r,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<r.length&&r[o].to==n;){let t=r[o++];t.widget&&(u?(c||(c=[u])).push(t):u=t)}if(u)if(c){c.sort(Ni);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<r.length&&r[o].from<=n&&r[o].to>n;)h.push(r[o++]);let p=n+f.nodeSize;if(f.isText){let t=p;o<r.length&&r[o].from<t&&(t=r[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<r.length&&r[o].to<p;)o++;s(f,f.isInline&&!f.isLeaf?h.filter((t=>!t.inline)):h.slice(),e.forChild(n,f),d),n=p}}(this.node,this.innerDeco,((e,r,n)=>{e.spec.marks?h.syncToMarks(e.spec.marks,i,t,r):e.type.side>=0&&!n&&h.syncToMarks(r==this.node.childCount?g.none:this.node.child(r).marks,i,t,r),h.placeWidget(e,t,s)}),((e,n,l,a)=>{let u;h.syncToMarks(e.marks,i,t,a),h.findNodeMatch(e,n,l,a)||o&&t.state.selection.from>s&&t.state.selection.to<s+e.nodeSize&&(u=h.findIndexWithChild(r.node))>-1&&h.updateNodeAt(e,n,l,u,t)||h.updateNextNode(e,n,l,t,a,s)||h.addNode(e,n,l,t,s),s+=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:s}=t.state.selection;if(!(t.state.selection instanceof ne)||i<e||s>e+this.node.content.size)return null;let r=t.input.compositionNode;if(!r||!this.dom.contains(r.parentNode))return null;if(this.node.inlineContent){let t=r.nodeValue,n=function(t,e,i,s){for(let r=0,n=0;r<t.childCount&&n<=s;){let o=t.child(r++),h=n;if(n+=o.nodeSize,!o.isText)continue;let l=o.text;for(;r<t.childCount;){let e=t.child(r++);if(n+=e.nodeSize,!e.isText)break;l+=e.text}if(n>=i){if(n>=s&&l.slice(s-e.length-h,s-h)==e)return s-e.length;let t=h<s?l.lastIndexOf(e,s-h-1):-1;if(t>=0&&t+e.length+h>=i)return h+t;if(i==s&&l.length>=s+e.length-h&&l.slice(s-h,s-h+e.length)==e)return s}}return-1}(this.node.content,t,i-e,s-e);return n<0?null:{node:r,pos:n,text:t}}return{node:r,pos:-1,text:""}}protectLocalComposition(t,{node:e,pos:i,text:s}){if(this.getDesc(e))return;let r=e;for(;r.parentNode!=this.contentDOM;r=r.parentNode){for(;r.previousSibling;)r.parentNode.removeChild(r.previousSibling);for(;r.nextSibling;)r.parentNode.removeChild(r.nextSibling);r.pmViewDesc&&(r.pmViewDesc=void 0)}let n=new Mi(this,r,e,s);t.input.compositionNodes.push(n),this.children=zi(this.children,i,i+s.length,t,n)}update(t,e,i,s){return!(3==this.dirty||!t.sameMarkup(this.node)||(this.updateInner(t,e,i,s),0))}updateInner(t,e,i,s){this.updateOuterDeco(e),this.node=t,this.innerDeco=i,this.contentDOM&&this.updateChildren(s,this.posAtStart),this.dirty=0}updateOuterDeco(t){if(ji(t,this.outerDeco))return;let e=1!=this.nodeDOM.nodeType,i=this.dom;this.dom=Pi(this.dom,this.nodeDOM,$i(this.outerDeco,this.node,e),$i(t,this.node,e)),this.dom!=i&&(i.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=t}selectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||(this.nodeDOM.draggable=!0))}deselectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Ai(t,e,i,s,r){Ri(s,e,t);let n=new Ci(void 0,t,e,i,s,s,s,r,0);return n.contentDOM&&n.updateChildren(r,0),n}class Si extends Ci{constructor(t,e,i,s,r,n,o){super(t,e,i,s,r,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,s){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!t.sameMarkup(this.node)||(this.updateOuterDeco(e),0==this.dirty&&t.text==this.node.text||t.text==this.nodeDOM.nodeValue||(this.nodeDOM.nodeValue=t.text,s.trackWrites==this.nodeDOM&&(s.trackWrites=null)),this.node=t,this.dirty=0,0))}inParent(){let t=this.parent.contentDOM;for(let e=this.nodeDOM;e;e=e.parentNode)if(e==t)return!0;return!1}domFromPos(t){return{node:this.nodeDOM,offset:t}}localPosFromDOM(t,e,i){return t==this.nodeDOM?this.posAtStart+Math.min(e,this.node.text.length):super.localPosFromDOM(t,e,i)}ignoreMutation(t){return"characterData"!=t.type&&"selection"!=t.type}slice(t,e,i){let s=this.node.cut(t,e),r=document.createTextNode(s.text);return new Si(this.parent,s,this.outerDeco,this.innerDeco,r,r,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,s,r,n,o,h,l,a){super(t,e,i,s,r,n,o,l,a),this.spec=h}update(t,e,i,s){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==t.type||this.spec.multiType)){let r=this.spec.update(t,e,i);return r&&this.updateInner(t,e,i,s),r}return!(!this.contentDOM&&!t.isLeaf)&&super.update(t,e,i,s)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(t,e,i,s){this.spec.setSelection?this.spec.setSelection(t,e,i.root):super.setSelection(t,e,i,s)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(t){return!!this.spec.stopEvent&&this.spec.stopEvent(t)}ignoreMutation(t){return this.spec.ignoreMutation?this.spec.ignoreMutation(t):super.ignoreMutation(t)}}function Oi(t,e,i){let s=t.firstChild,r=!1;for(let n=0;n<e.length;n++){let o=e[n],h=o.dom;if(h.parentNode==t){for(;h!=s;)s=Fi(s),r=!0;s=s.nextSibling}else r=!0,t.insertBefore(h,s);if(o instanceof xi){let e=s?s.previousSibling:t.lastChild;Oi(o.contentDOM,o.children,i),s=e?e.nextSibling:t.firstChild}}for(;s;)s=Fi(s),r=!0;r&&i.trackWrites==t&&(i.trackWrites=null)}const Ei=function(t){t&&(this.nodeName=t)};Ei.prototype=Object.create(null);const Ii=[new Ei];function $i(t,e,i){if(0==t.length)return Ii;let s=i?Ii[0]:new Ei,r=[s];for(let n=0;n<t.length;n++){let o=t[n].type.attrs;if(o){o.nodeName&&r.push(s=new Ei(o.nodeName));for(let t in o){let n=o[t];null!=n&&(i&&1==r.length&&r.push(s=new Ei(e.isInline?"span":"div")),"class"==t?s.class=(s.class?s.class+" ":"")+n:"style"==t?s.style=(s.style?s.style+";":"")+n:"nodeName"!=t&&(s[t]=n))}}}return r}function Pi(t,e,i,s){if(i==Ii&&s==Ii)return e;let r=e;for(let e=0;e<s.length;e++){let n=s[e],o=i[e];if(e){let e;o&&o.nodeName==n.nodeName&&r!=t&&(e=r.parentNode)&&e.nodeName.toLowerCase()==n.nodeName||(e=document.createElement(n.nodeName),e.pmIsDeco=!0,e.appendChild(r),o=Ii[0]),r=e}Di(r,o||Ii[0],n)}return r}function Di(t,e,i){for(let s in e)"class"==s||"style"==s||"nodeName"==s||s in i||t.removeAttribute(s);for(let s in i)"class"!=s&&"style"!=s&&"nodeName"!=s&&i[s]!=e[s]&&t.setAttribute(s,i[s]);if(e.class!=i.class){let s=e.class?e.class.split(" ").filter(Boolean):[],r=i.class?i.class.split(" ").filter(Boolean):[];for(let e=0;e<s.length;e++)-1==r.indexOf(s[e])&&t.classList.remove(s[e]);for(let e=0;e<r.length;e++)-1==s.indexOf(r[e])&&t.classList.add(r[e]);0==t.classList.length&&t.removeAttribute("class")}if(e.style!=i.style){if(e.style){let i,s=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;i=s.exec(e.style);)t.style.removeProperty(i[1])}i.style&&(t.style.cssText+=i.style)}}function Ri(t,e,i){return Pi(t,t,Ii,$i(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 Ui{constructor(t,e,i){this.lock=e,this.view=i,this.index=0,this.stack=[],this.changed=!1,this.top=t,this.preMatch=function(t,e){let i=e,s=i.children.length,r=t.childCount,n=new Map,o=[];t:for(;r>0;){let h;for(;;)if(s){let t=i.children[s-1];if(!(t instanceof xi)){h=t,s--;break}i=t,s=t.children.length}else{if(i==e)break t;s=i.parent.children.indexOf(i),i=i.parent}let l=h.node;if(l){if(l!=t.child(r-1))break;--r,n.set(h,r),o.push(h)}}return{index:r,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,s){let r=0,n=this.stack.length>>1,o=Math.min(n,t.length);for(;r<o&&(r==n-1?this.top:this.stack[r+1<<1]).matchesMark(t[r])&&!1!==t[r].type.spec.spanning;)r++;for(;r<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 r=-1,o=this.top.children.length;s<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)){r=e;break}}if(r>-1)r>this.index&&(this.changed=!0,this.destroyBetween(this.index,r)),this.top=this.top.children[this.index];else{let s=xi.create(this.top,t[n],e,i);this.top.children.splice(this.index,0,s),this.top=s,this.changed=!0}this.index=0,n++}}findNodeMatch(t,e,i,s){let r,n=-1;if(s>=this.preMatch.index&&(r=this.preMatch.matches[s-this.preMatch.index]).parent==this.top&&r.matchesNode(t,e,i))n=this.top.children.indexOf(r,this.index);else for(let s=this.index,r=Math.min(this.top.children.length,s+5);s<r;s++){let r=this.top.children[s];if(r.matchesNode(t,e,i)&&!this.preMatch.matched.has(r)){n=s;break}}return!(n<0||(this.destroyBetween(this.index,n),this.index++,0))}updateNodeAt(t,e,i,s,r){let n=this.top.children[s];return 3==n.dirty&&n.dom==n.contentDOM&&(n.dirty=2),!!n.update(t,e,i,r)&&(this.destroyBetween(this.index,s),this.index++,!0)}findIndexWithChild(t){for(;;){let e=t.parentNode;if(!e)return-1;if(e==this.top.contentDOM){let e=t.pmViewDesc;if(e)for(let t=this.index;t<this.top.children.length;t++)if(this.top.children[t]==e)return t;return-1}t=e}}updateNextNode(t,e,i,s,r,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!=r)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,s))return this.destroyBetween(this.index,o),h.dom!=u&&(this.changed=!0),this.index++,!0;if(!c&&(a=this.recreateWrapper(h,t,e,i,s,n)))return this.destroyBetween(this.index,o),this.top.children[this.index]=a,a.contentDOM&&(a.dirty=2,a.updateChildren(s,n+1),a.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(t,e,i,s,r,n){if(t.dirty||e.isAtom||!t.children.length||!t.node.content.eq(e.content)||!ji(i,t.outerDeco)||!s.eq(t.innerDeco))return null;let o=Ci.create(this.top,e,i,s,r,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,s,r){let n=Ci.create(this.top,t,e,i,s,r);n.contentDOM&&n.updateChildren(s,r+1),this.top.children.splice(this.index++,0,n),this.changed=!0}placeWidget(t,e,i){let s=this.index<this.top.children.length?this.top.children[this.index]:null;if(!s||!s.matchesWidget(t)||t!=s.widget&&s.widget.type.toDOM.parentNode){let s=new bi(this.top,t,e,i);this.top.children.splice(this.index++,0,s),this.changed=!0}else this.index++}addTextblockHacks(){let t=this.top.children[this.index-1],e=this.top;for(;t instanceof 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 s=new Bi(this.top,[],i,null);e!=this.top?e.children.push(s):e.children.splice(this.index++,0,s),this.changed=!0}}isLocked(t){return this.lock&&(t==this.lock||1==t.nodeType&&t.contains(this.lock.parentNode))}}function Ni(t,e){return t.type.side-e.type.side}function zi(t,e,i,s,r){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,s)),r&&(n.push(r),r=void 0),u>i&&n.push(l.slice(i-a,l.size,s)))}return n}function _i(t,e=null){let i=t.domSelectionRange(),s=t.state.doc;if(!i.focusNode)return null;let r=t.docView.nearestDesc(i.focusNode),n=r&&0==r.size,o=t.docView.posFromDOM(i.focusNode,i.focusOffset,1);if(o<0)return null;let h,l,a=s.resolve(o);if(Ie(i)){for(h=o;r&&!r.node;)r=r.parent;let t=r.node;if(r&&t.isAtom&&he.isSelectable(t)&&r.parent&&(!t.isInline||!function(t,e,i){for(let s=0==e,r=e==Oe(t);s||r;){if(t==i)return!0;let e=Me(t);if(!(t=t.parentNode))return!1;s=s&&0==e,r=r&&e==Oe(t)}}(i.focusNode,i.focusOffset,r.dom))){let t=r.posBefore;l=new he(o==t?a:s.resolve(t))}}else{if(i instanceof t.dom.ownerDocument.defaultView.Selection&&i.rangeCount>1){let e=o,r=o;for(let s=0;s<i.rangeCount;s++){let n=i.getRangeAt(s);e=Math.min(e,t.docView.posFromDOM(n.startContainer,n.startOffset,1)),r=Math.max(r,t.docView.posFromDOM(n.endContainer,n.endOffset,-1))}if(e<0)return null;[h,o]=r==t.state.selection.anchor?[r,e]:[e,r],a=s.resolve(o)}else h=t.docView.posFromDOM(i.anchorNode,i.anchorOffset,1);if(h<0)return null}let u=s.resolve(h);return l||(l=Qi(t,u,a,"pointer"==e||t.state.selection.head<a.pos&&!n?1:-1)),l}function Li(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(Ki(t,i),Li(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,s="IMG"==i.nodeName;s?e.collapse(i.parentNode,Me(i)+1):e.collapse(i,0),!s&&!t.state.selection.visible&&Ne&&ze<=11&&(i.disabled=!0,i.disabled=!1)}(t);else{let s,r,{anchor:n,head:o}=i;!Xi||i instanceof ne||(i.$from.parent.inlineContent||(s=Yi(t,i.from)),i.empty||i.$from.parent.inlineContent||(r=Yi(t,i.to))),t.docView.setSelection(n,o,t,e),Xi&&(s&&Vi(s),r&&Vi(r)),i.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(t){let e=t.dom.ownerDocument;e.removeEventListener("selectionchange",t.input.hideSelectionGuard);let i=t.domSelectionRange(),s=i.anchorNode,r=i.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{i.anchorNode==s&&i.anchorOffset==r||(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout((()=>{Li(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:s}=t.docView.domFromPos(e,0),r=s<i.childNodes.length?i.childNodes[s]:null,n=s?i.childNodes[s-1]:null;if(Ye&&r&&"false"==r.contentEditable)return Wi(r);if(!(r&&"false"!=r.contentEditable||n&&"false"!=n.contentEditable)){if(r)return Wi(r);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 Ki(t,e){if(e instanceof he){let i=t.docView.descAt(e.from);i!=t.lastSelectedViewDesc&&(Ji(t),i&&i.selectNode(),t.lastSelectedViewDesc=i)}else Ji(t)}function Ji(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Qi(t,e,i,s){return t.someProp("createSelectionBetween",(s=>s(t,e,i)))||ne.between(e,i,s)}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:s}=t.selection,r=e>0?i.max(s):i.min(s),n=r.parent.inlineContent?r.depth?t.doc.resolve(e>0?r.after():r.before()):null:r;return n&&ee.findFrom(n,e)}function ts(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function es(t,e,i){let s=t.state.selection;if(!(s instanceof ne)){if(s instanceof he&&s.node.isInline)return ts(t,new ne(e>0?s.$to:s.$from));{let i=Zi(t.state,e);return!!i&&ts(t,i)}}if(i.indexOf("s")>-1){let{$head:i}=s,r=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!r||r.isText||!r.isLeaf)return!1;let n=t.state.doc.resolve(i.pos+r.nodeSize*(e<0?-1:1));return ts(t,new ne(s.$anchor,n))}if(!s.empty)return!1;if(t.endOfTextblock(e>0?"forward":"backward")){let i=Zi(t.state,e);return!!(i&&i instanceof he)&&ts(t,i)}if(!(Ve&&i.indexOf("m")>-1)){let i,r=s.$head,n=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter;if(!n||n.isText)return!1;let o=e<0?r.pos-n.nodeSize:r.pos;return!!(n.isAtom||(i=t.docView.descAt(o))&&!i.contentDOM)&&(he.isSelectable(n)?ts(t,new he(e<0?t.state.doc.resolve(r.pos-n.nodeSize):r)):!!Qe&&ts(t,new ne(t.state.doc.resolve(e<0?o:o+n.nodeSize))))}}function is(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function ss(t,e){let i=t.pmViewDesc;return i&&0==i.size&&(e<0||t.nextSibling||"BR"!=t.nodeName)}function rs(t,e){return e<0?function(t){let e=t.domSelectionRange(),i=e.focusNode,s=e.focusOffset;if(!i)return;let r,n,o=!1;for(_e&&1==i.nodeType&&s<is(i)&&ss(i.childNodes[s],-1)&&(o=!0);;)if(s>0){if(1!=i.nodeType)break;{let t=i.childNodes[s-1];if(ss(t,-1))r=i,n=--s;else{if(3!=t.nodeType)break;i=t,s=i.nodeValue.length}}}else{if(ns(i))break;{let e=i.previousSibling;for(;e&&ss(e,-1);)r=i.parentNode,n=Me(e),e=e.previousSibling;if(e)i=e,s=is(i);else{if(i=i.parentNode,i==t.dom)break;s=0}}}o?hs(t,i,s):r&&hs(t,r,n)}(t):function(t){let e=t.domSelectionRange(),i=e.focusNode,s=e.focusOffset;if(!i)return;let r,n,o=is(i);for(;;)if(s<o){if(1!=i.nodeType)break;if(!ss(i.childNodes[s],1))break;r=i,n=++s}else{if(ns(i))break;{let e=i.nextSibling;for(;e&&ss(e,1);)r=e.parentNode,n=Me(e)+1,e=e.nextSibling;if(e)i=e,s=0,o=is(i);else{if(i=i.parentNode,i==t.dom)break;s=o=0}}}r&&hs(t,r,n)}(t)}function ns(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function hs(t,e,i){if(3!=e.nodeType){let t,s;(s=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=s,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 s=t.domSelection();if(!s)return;if(Ie(s)){let t=document.createRange();t.setEnd(e,i),t.setStart(e,i),s.removeAllRanges(),s.addRange(t)}else s.extend&&s.extend(e,i);t.domObserver.setCurSelection();let{state:r}=t;setTimeout((()=>{t.state==r&&Hi(t)}),50)}function ls(t,e){let i=t.state.doc.resolve(e);if(!He&&!Ke&&i.parent.inlineContent){let s=t.coordsAtPos(e);if(e>i.start()){let i=t.coordsAtPos(e-1),r=(i.top+i.bottom)/2;if(r>s.top&&r<s.bottom&&Math.abs(i.left-s.left)>1)return i.left<s.left?"ltr":"rtl"}if(e<i.end()){let i=t.coordsAtPos(e+1),r=(i.top+i.bottom)/2;if(r>s.top&&r<s.bottom&&Math.abs(i.left-s.left)>1)return i.left>s.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(t.dom).direction?"rtl":"ltr"}function as(t,e,i){let s=t.state.selection;if(s instanceof ne&&!s.empty||i.indexOf("s")>-1)return!1;if(Ve&&i.indexOf("m")>-1)return!1;let{$from:r,$to:n}=s;if(!r.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let i=Zi(t.state,e);if(i&&i instanceof he)return ts(t,i)}if(!r.parent.inlineContent){let i=e<0?r:n,o=s instanceof ae?ee.near(i,e):ee.findFrom(i,e);return!!o&&ts(t,o)}return!1}function us(t,e){if(!(t.state.selection instanceof ne))return!0;let{$head:i,$anchor:s,empty:r}=t.state.selection;if(!i.sameParent(s))return!0;if(!r)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 s=t.state.tr;return e<0?s.delete(i.pos-n.nodeSize,i.pos):s.delete(i.pos,i.pos+n.nodeSize),t.dispatch(s),!0}return!1}function cs(t,e,i){t.domObserver.stop(),e.contentEditable=i,t.domObserver.start()}function fs(t,e){t.someProp("transformCopied",(i=>{e=i(e,t)}));let i=[],{content:s,openStart:r,openEnd:n}=e;for(;r>1&&n>1&&1==s.childCount&&1==s.firstChild.childCount;){r--,n--;let t=s.firstChild;i.push(t.type.name,t.attrs!=t.type.defaultAttrs?t.attrs:null),s=t.content}let o=t.someProp("clipboardSerializer")||ft.fromSchema(t.state.schema),h=Ms(),l=h.createElement("div");l.appendChild(o.serializeFragment(s,{document:h}));let a,u=l.firstChild,c=0;for(;u&&1==u.nodeType&&(a=ks[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",`${r} ${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 ds(t,e,i,s,r){let n,o,h=r.parent.type.spec.code;if(!i&&!e)return null;let l=!!e&&(s||h||!i);if(l){if(t.someProp("transformPastedText",(i=>{e=i(e,h||s,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,r,s,t)));if(i)o=i;else{let i=r.marks(),{schema:s}=t.state,o=ft.fromSchema(s);n=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach((t=>{let e=n.appendChild(document.createElement("p"));t&&e.appendChild(o.serializeNode(s.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,s=Ms().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t);if((i=r&&ks[r[1].toLowerCase()])&&(t=i.map((t=>"<"+t+">")).join("")+t+i.map((t=>"</"+t+">")).reverse().join("")),s.innerHTML=function(t){let e=window.trustedTypes;return e?(xs||(xs=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),xs.createHTML(t)):t}(t),i)for(let t=0;t<i.length;t++)s=s.querySelector(i[t])||s;return s}(i),Qe&&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 s=e[i];1==s.childNodes.length&&" "==s.textContent&&s.parentNode&&s.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),s)}}(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:r,ruleFromNode:t=>"BR"!=t.nodeName||t.nextSibling||!t.parentNode||ps.test(t.parentNode.nodeName)?null:{ignore:!0}})}if(u)o=function(t,e){if(!t.size)return t;let i,s=t.content.firstChild.type.schema;try{i=JSON.parse(e)}catch(e){return t}let{content:r,openStart:n,openEnd:o}=t;for(let t=i.length-2;t>=0;t-=2){let e=s.nodes[i[t]];if(!e||e.hasRequiredAttrs())break;r=c.from(e.create(i[t+1],r)),n++,o++}return new m(r,n,o)}(ys(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 s,r=e.node(i).contentMatchAt(e.index(i)),n=[];if(t.forEach((t=>{if(!n)return;let e,i=r.findWrapping(t.type);if(!i)return n=null;if(e=n.length&&s.length&&ws(i,s,t,n[n.length-1],0))n[n.length-1]=e;else{n.length&&(n[n.length-1]=ms(n[n.length-1],s.length));let e=gs(t,i);n.push(e),r=r.matchType(e.type),s=i}})),n)return c.from(n)}return t}(o.content,r),!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=ys(o,t,e)}return t.someProp("transformPasted",(e=>{o=e(o,t,l)})),o}const ps=/^(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 gs(t,e,i=0){for(let s=e.length-1;s>=i;s--)t=e[s].create(null,c.from(t));return t}function ws(t,e,i,s,r){if(r<t.length&&r<e.length&&t[r]==e[r]){let n=ws(t,e,i,s.lastChild,r+1);if(n)return s.copy(s.content.replaceChild(s.childCount-1,n));if(s.contentMatchAt(s.childCount).matchType(r==t.length-1?i.type:t[r+1]))return s.copy(s.content.append(c.from(gs(i,t,r+1))))}}function ms(t,e){if(0==e)return t;let i=t.content.replaceChild(t.childCount-1,ms(t.lastChild,e-1)),s=t.contentMatchAt(t.childCount).fillBefore(c.empty,!0);return t.copy(i.append(s))}function vs(t,e,i,s,r,n){let o=e<0?t.firstChild:t.lastChild,h=o.content;return t.childCount>1&&(n=0),r<s-1&&(h=vs(h,e,i,s,r+1,n)),r>=i&&(h=e<0?o.contentMatchAt(0).fillBefore(h,n<=r).append(h):h.append(o.contentMatchAt(o.childCount).fillBefore(c.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,o.copy(h))}function ys(t,e,i){return e<t.openStart&&(t=new m(vs(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),i<t.openEnd&&(t=new m(vs(t.content,1,i,t.openEnd,0,0),t.openStart,i)),t}const ks={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 bs=null;function Ms(){return bs||(bs=document.implementation.createHTMLDocument("title"))}let xs=null;const Cs={},As={},Ss={touchstart:!0,touchmove:!0};class Bs{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 Ts(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function Os(t){t.someProp("handleDOMEvents",(e=>{for(let i in e)t.input.eventHandlers[i]||t.dom.addEventListener(i,t.input.eventHandlers[i]=e=>Es(t,e))}))}function Es(t,e){return t.someProp("handleDOMEvents",(i=>{let s=i[e.type];return!!s&&(s(t,e)||e.defaultPrevented)}))}function Is(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 $s(t){return{left:t.clientX,top:t.clientY}}function Ps(t,e,i,s,r){if(-1==s)return!1;let n=t.state.doc.resolve(s);for(let s=n.depth+1;s>0;s--)if(t.someProp(e,(e=>s>n.depth?e(t,i,n.nodeAfter,n.before(s),r,!0):e(t,i,n.node(s),n.before(s),r,!1))))return!0;return!1}function Ds(t,e){if(t.focused||t.focus(),t.state.selection.eq(e))return;let i=t.state.tr.setSelection(e);i.setMeta("pointer",!0),t.dispatch(i)}function Rs(t,e,i,s){return Ps(t,"handleDoubleClickOn",e,i,s)||t.someProp("handleDoubleClick",(i=>i(t,e,s)))}function js(t,e,i,s){return Ps(t,"handleTripleClickOn",e,i,s)||t.someProp("handleTripleClick",(i=>i(t,e,s)))||function(t,e,i){if(0!=i.button)return!1;let s=t.state.doc;if(-1==e)return!!s.inlineContent&&(Ds(t,ne.create(s,0,s.content.size)),!0);let r=s.resolve(e);for(let e=r.depth+1;e>0;e--){let i=e>r.depth?r.nodeAfter:r.node(e),n=r.before(e);if(i.inlineContent)Ds(t,ne.create(s,n+1,n+1+i.content.size));else{if(!he.isSelectable(i))continue;Ds(t,he.create(s,n))}return!0}}(t,i,s)}function Fs(t){return Xs(t)}As.keydown=(t,e)=>{let i=e;if(t.input.shiftKey=16==i.keyCode||i.shiftKey,!zs(t,i)&&(t.input.lastKeyCode=i.keyCode,t.input.lastKeyCodeTime=Date.now(),!Je||!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,s=function(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}(e);if(8==i||Ve&&72==i&&"c"==s)return us(t,-1)||rs(t,-1);if(46==i&&!e.shiftKey||Ve&&68==i&&"c"==s)return us(t,1)||rs(t,1);if(13==i||27==i)return!0;if(37==i||Ve&&66==i&&"c"==s){let e=37==i?"ltr"==ls(t,t.state.selection.from)?-1:1:-1;return es(t,e,s)||rs(t,e)}if(39==i||Ve&&70==i&&"c"==s){let e=39==i?"ltr"==ls(t,t.state.selection.from)?1:-1:1;return es(t,e,s)||rs(t,e)}return 38==i||Ve&&80==i&&"c"==s?as(t,-1,s)||rs(t,-1):40==i||Ve&&78==i&&"c"==s?function(t){if(!Ye||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(e&&1==e.nodeType&&0==i&&e.firstChild&&"false"==e.firstChild.contentEditable){let i=e.firstChild;cs(t,i,"true"),setTimeout((()=>cs(t,i,"false")),20)}return!1}(t)||as(t,1,s)||rs(t,1):s==(Ve?"m":"c")&&(66==i||73==i||89==i||90==i)}(t,i)?i.preventDefault():Ts(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,$e(13,"Enter")))),t.input.lastIOSEnter=0)}),200)}},As.keyup=(t,e)=>{16==e.keyCode&&(t.input.shiftKey=!1)},As.keypress=(t,e)=>{let i=e;if(zs(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 s=t.state.selection;if(!(s instanceof ne&&s.$from.sameParent(s.$to))){let e=String.fromCharCode(i.charCode),r=()=>t.state.tr.insertText(e).scrollIntoView();/[\r\n]/.test(e)||t.someProp("handleTextInput",(i=>i(t,s.$from.pos,s.$to.pos,e,r)))||t.dispatch(r()),i.preventDefault()}};const Us=Ve?"metaKey":"ctrlKey";Cs.mousedown=(t,e)=>{let i=e;t.input.shiftKey=i.shiftKey;let s=Fs(t),r=Date.now(),n="singleClick";r-t.input.lastClick.time<500&&function(t,e){let i=e.x-t.clientX,s=e.y-t.clientY;return i*i+s*s<100}(i,t.input.lastClick)&&!i[Us]&&t.input.lastClick.button==i.button&&("singleClick"==t.input.lastClick.type?n="doubleClick":"doubleClick"==t.input.lastClick.type&&(n="tripleClick")),t.input.lastClick={time:r,x:i.clientX,y:i.clientY,type:n,button:i.button};let o=t.posAtCoords($s(i));o&&("singleClick"==n?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new Ns(t,o,i,!!s)):("doubleClick"==n?Rs:js)(t,o.pos,o.inside,i)?i.preventDefault():Ts(t,"pointer"))};class Ns{constructor(t,e,i,s){let r,n;if(this.view=t,this.pos=e,this.event=i,this.flushed=s,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=t.state.doc,this.selectNode=!!i[Us],this.allowDefault=i.shiftKey,e.inside>-1)r=t.state.doc.nodeAt(e.inside),n=e.inside;else{let i=t.state.doc.resolve(e.pos);r=i.parent,n=i.depth?i.before():0}const o=s?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&&(r.type.spec.draggable&&!1!==r.type.spec.selectable||l instanceof he&&l.from<=n&&l.to>n)&&(this.mightDrag={node:r,pos:n,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!_e||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)),Ts(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($s(t))),this.updateAllowDefault(t),this.allowDefault||!e?Ts(this.view,"pointer"):function(t,e,i,s,r){return Ps(t,"handleClickOn",e,i,s)||t.someProp("handleClick",(i=>i(t,e,s)))||(r?function(t,e){if(-1==e)return!1;let i,s,r=t.state.selection;r instanceof he&&(i=r.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)){s=i&&r.$from.depth>0&&t>=r.$from.depth&&n.before(r.$from.depth+1)==r.$from.pos?n.before(r.$from.depth):n.before(t);break}}return null!=s&&(Ds(t,he.create(t.state.doc,s)),!0)}(t,i):function(t,e){if(-1==e)return!1;let i=t.state.doc.resolve(e),s=i.nodeAfter;return!!(s&&s.isAtom&&he.isSelectable(s))&&(Ds(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)?(Ds(this.view,ee.near(this.view.state.doc.resolve(e.pos))),t.preventDefault()):Ts(this.view,"pointer")}move(t){this.updateAllowDefault(t),Ts(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 zs(t,e){return!!t.composing||!!(Ye&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500)&&(t.input.compositionEndedAt=-2e8,!0)}Cs.touchstart=t=>{t.input.lastTouch=Date.now(),Fs(t),Ts(t,"pointer")},Cs.touchmove=t=>{t.input.lastTouch=Date.now(),Ts(t,"pointer")},Cs.contextmenu=t=>Fs(t);const _s=Je?5e3:-1;function Ls(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout((()=>Xs(t)),e))}function Hs(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 Xs(t,e=!1){if(!(Je&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Hs(t),e||t.docView&&t.docView.dirty){let i=_i(t),s=t.state.selection;return i&&!i.eq(s)?t.dispatch(t.state.tr.setSelection(i)):!t.markCursor&&!e||s.$from.node(s.$from.sharedDepth(s.to)).inlineContent?t.updateState(t.state):t.dispatch(t.state.tr.deleteSelection()),!0}return!1}}As.compositionstart=As.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,i=e.selection.$to;if(e.selection instanceof ne&&(e.storedMarks||!i.textOffset&&i.parentOffset&&i.nodeBefore.marks.some((t=>!1===t.type.spec.inclusive))||He&&Ke&&function(t){let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(!e||1!=e.nodeType||i>=e.childNodes.length)return!1;let s=e.childNodes[i];return 1==s.nodeType&&"false"==s.contentEditable}(t)))t.markCursor=t.state.storedMarks||i.marks(),Xs(t,!0),t.markCursor=null;else if(Xs(t,!e.selection.empty),_e&&e.selection.empty&&i.parentOffset&&!i.textOffset&&i.nodeBefore.marks.length){let e=t.domSelectionRange();for(let i=e.focusNode,s=e.focusOffset;i&&1==i.nodeType&&0!=s;){let e=s<0?i.lastChild:i.childNodes[s-1];if(!e)break;if(3==e.nodeType){let i=t.domSelection();i&&i.collapse(e,e.nodeValue.length);break}i=e,s=-1}}t.input.composing=!0}Ls(t,_s)},As.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.timeStamp,t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.badSafariComposition?t.domObserver.forceFlush():t.input.compositionPendingChanges&&Promise.resolve().then((()=>t.domObserver.flush())),t.input.compositionID++,Ls(t,20))};const Ys=Ne&&ze<15||We&&qe<604;function Ws(t,e,i,s,r){let n=ds(t,e,i,s,t.state.selection.$from);if(t.someProp("handlePaste",(e=>e(t,r,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,s):t.state.tr.replaceSelection(n);return t.dispatch(h.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Vs(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," "):""}Cs.copy=As.cut=(t,e)=>{let i=e,s=t.state.selection,r="cut"==i.type;if(s.empty)return;let n=Ys?null:i.clipboardData,o=s.content(),{dom:h,text:l}=fs(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 s=getSelection(),r=document.createRange();r.selectNodeContents(e),t.dom.blur(),s.removeAllRanges(),s.addRange(r),setTimeout((()=>{i.parentNode&&i.parentNode.removeChild(i),t.focus()}),50)}(t,h),r&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},As.paste=(t,e)=>{let i=e;if(t.composing&&!Je)return;let s=Ys?null:i.clipboardData,r=t.input.shiftKey&&45!=t.input.lastKeyCode;s&&Ws(t,Vs(s),s.getData("text/html"),r,i)?i.preventDefault():function(t,e){if(!t.dom.parentNode)return;let i=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,s=t.dom.parentNode.appendChild(document.createElement(i?"textarea":"div"));i||(s.contentEditable="true"),s.style.cssText="position: fixed; left: -10000px; top: 10px",s.focus();let r=t.input.shiftKey&&45!=t.input.lastKeyCode;setTimeout((()=>{t.focus(),s.parentNode&&s.parentNode.removeChild(s),i?Ws(t,s.value,null,r,e):Ws(t,s.textContent,s.innerHTML,r,e)}),50)}(t,i)};class Ks{constructor(t,e,i){this.slice=t,this.move=e,this.node=i}}const Js=Ve?"altKey":"ctrlKey";function Qs(t,e){let i;return t.someProp("dragCopies",(t=>{i=i||t(e)})),null!=i?!i:!e[Js]}Cs.dragstart=(t,e)=>{let i=e,s=t.input.mouseDown;if(s&&s.done(),!i.dataTransfer)return;let r,n=t.state.selection,o=n.empty?null:t.posAtCoords($s(i));if(o&&o.pos>=n.from&&o.pos<=(n instanceof he?n.to-1:n.to));else if(s&&s.mightDrag)r=he.create(t.state.doc,s.mightDrag.pos);else if(i.target&&1==i.target.nodeType){let e=t.docView.nearestDesc(i.target,!0);e&&e.node.type.spec.draggable&&e!=t.docView&&(r=he.create(t.state.doc,e.posBefore))}let h=(r||t.state.selection).content(),{dom:l,text:a,slice:u}=fs(t,h);(!i.dataTransfer.files.length||!He||Xe>120)&&i.dataTransfer.clearData(),i.dataTransfer.setData(Ys?"Text":"text/html",l.innerHTML),i.dataTransfer.effectAllowed="copyMove",Ys||i.dataTransfer.setData("text/plain",a),t.dragging=new Ks(u,Qs(t,i),r)},Cs.dragend=t=>{let e=t.dragging;window.setTimeout((()=>{t.dragging==e&&(t.dragging=null)}),50)},As.dragover=As.dragenter=(t,e)=>e.preventDefault(),As.drop=(t,e)=>{try{!function(t,e,i){if(!e.dataTransfer)return;let s=t.posAtCoords($s(e));if(!s)return;let r=t.state.doc.resolve(s.pos),n=i&&i.slice;n?t.someProp("transformPasted",(e=>{n=e(n,t,!1)})):n=ds(t,Vs(e.dataTransfer),Ys?null:e.dataTransfer.getData("text/html"),!1,r);let o=!(!i||!Qs(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 s=t.resolve(e);if(!i.content.size)return e;let r=i.content;for(let t=0;t<i.openStart;t++)r=r.firstChild.content;for(let t=1;t<=(0==i.openStart&&i.size?2:1);t++)for(let e=s.depth;e>=0;e--){let i=e==s.depth?0:s.pos<=(s.start(e+1)+s.end(e+1))/2?-1:1,n=s.index(e)+(i>0?1:0),o=s.node(e),h=!1;if(1==t)h=o.canReplace(n,n,r);else{let t=o.contentMatchAt(n).findWrapping(r.firstChild.type);h=t&&o.canReplaceWith(n,n,t[0])}if(h)return 0==i?s.pos:i<0?s.before(e+1):s.after(e+1)}return null}(t.state.doc,r.pos,n):r.pos;null==h&&(h=r.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,s,r)=>e=r)),l.setSelection(Qi(t,f,l.doc.resolve(e)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}(t,e,t.dragging)}finally{t.dragging=null}},Cs.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))},Cs.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)},Cs.beforeinput=(t,e)=>{if(He&&Je&&"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,$e(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())}),50)}};for(let t in As)Cs[t]=As[t];function qs(t,e){if(t==e)return!0;for(let i in t)if(t[i]!==e[i])return!1;for(let i in e)if(!(i in t))return!1;return!0}class Gs{constructor(t,e){this.toDOM=t,this.spec=e||sr,this.side=this.spec.side||0}map(t,e,i,s){let{pos:r,deleted:n}=t.mapResult(e.from+s,this.side<0?-1:1);return n?null:new er(r-i,r-i,this)}valid(){return!0}eq(t){return this==t||t instanceof Gs&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&qs(this.spec,t.spec))}destroy(t){this.spec.destroy&&this.spec.destroy(t)}}class Zs{constructor(t,e){this.attrs=t,this.spec=e||sr}map(t,e,i,s){let r=t.map(e.from+s,this.spec.inclusiveStart?-1:1)-i,n=t.map(e.to+s,this.spec.inclusiveEnd?1:-1)-i;return r>=n?null:new er(r,n,this)}valid(t,e){return e.from<e.to}eq(t){return this==t||t instanceof Zs&&qs(this.attrs,t.attrs)&&qs(this.spec,t.spec)}static is(t){return t.type instanceof Zs}destroy(){}}class tr{constructor(t,e){this.attrs=t,this.spec=e||sr}map(t,e,i,s){let r=t.mapResult(e.from+s,1);if(r.deleted)return null;let n=t.mapResult(e.to+s,-1);return n.deleted||n.pos<=r.pos?null:new er(r.pos-i,n.pos-i,this)}valid(t,e){let i,{index:s,offset:r}=t.content.findIndex(e.from);return r==e.from&&!(i=t.child(s)).isText&&r+i.nodeSize==e.to}eq(t){return this==t||t instanceof tr&&qs(this.attrs,t.attrs)&&qs(this.spec,t.spec)}destroy(){}}class er{constructor(t,e,i){this.from=t,this.to=e,this.type=i}copy(t,e){return new er(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 er(t,t,new Gs(e,i))}static inline(t,e,i,s){return new er(t,e,new Zs(i,s))}static node(t,e,i,s){return new er(t,e,new tr(i,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof Zs}get widget(){return this.type instanceof Gs}}const ir=[],sr={};class rr{constructor(t,e){this.local=t.length?t:ir,this.children=e.length?e:ir}static create(t,e){return e.length?ur(e,t,0,sr):nr}find(t,e,i){let s=[];return this.findInner(null==t?0:t,null==e?1e9:e,s,0,i),s}findInner(t,e,i,s,r){for(let n=0;n<this.local.length;n++){let o=this.local[n];o.from<=e&&o.to>=t&&(!r||r(o.spec))&&i.push(o.copy(o.from+s,o.to+s))}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,s+o,r)}}map(t,e,i){return this==nr||0==t.maps.length?this:this.mapInner(t,e,0,0,i||sr)}mapInner(t,e,i,s,r){let n;for(let o=0;o<this.local.length;o++){let h=this.local[o].map(t,i,s);h&&h.type.valid(e,h)?(n||(n=[])).push(h):r.onRemove&&r.onRemove(this.local[o].spec)}return this.children.length?function(t,e,i,s,r,n,o){let h=t.slice();for(let t=0,e=n;t<i.maps.length;t++){let s=0;i.maps[t].forEach(((t,i,r,n)=>{let o=n-r-(i-t);for(let r=0;r<h.length;r+=3){let n=h[r+1];if(n<0||t>n+e-s)continue;let l=h[r]+e-s;i>=l?h[r+1]=t<=l?-2:-1:t>=e&&o&&(h[r]+=o,h[r+1]+=o)}s+=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-r;if(u<0||u>=s.content.size){l=!0;continue}let c=i.map(t[e+1]+n,-1)-r,{index:f,offset:d}=s.content.findIndex(u),p=s.maybeChild(f);if(p&&d==u&&d+p.nodeSize==c){let s=h[e+2].mapInner(i,p,a+1,t[e]+n+1,o);s!=nr?(h[e]=u,h[e+1]=c,h[e+2]=s):(h[e+1]=-2,l=!0)}else l=!0}if(l){let l=function(t,e,i,s,r,n,o){function h(t,e){for(let n=0;n<t.local.length;n++){let h=t.local[n].map(s,r,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,r,n,o),a=ur(l,s,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 rr(e.sort(cr),h)}(this.children,n||[],t,e,i,s,r):n?new rr(n.sort(cr),ir):nr}add(t,e){return e.length?this==nr?rr.create(t,e):this.addInner(t,e,0):this}addInner(t,e,i){let s,r=0;t.forEach(((t,n)=>{let o,h=n+i;if(o=lr(e,t,h)){for(s||(s=this.children.slice());r<s.length&&s[r]<n;)r+=3;s[r]==n?s[r+2]=s[r+2].addInner(t,o,h+1):s.splice(r,0,n,n+t.nodeSize,ur(o,t,h+1,sr)),r+=3}}));let n=hr(r?ar(e):e,-i);for(let e=0;e<n.length;e++)n[e].type.valid(t,n[e])||n.splice(e--,1);return new rr(n.length?this.local.concat(n).sort(cr):this.local,s||this.children)}remove(t){return 0==t.length||this==nr?this:this.removeInner(t,0)}removeInner(t,e){let i=this.children,s=this.local;for(let s=0;s<i.length;s+=3){let r,n=i[s]+e,o=i[s+1]+e;for(let e,i=0;i<t.length;i++)(e=t[i])&&e.from>n&&e.to<o&&(t[i]=null,(r||(r=[])).push(e));if(!r)continue;i==this.children&&(i=this.children.slice());let h=i[s+2].removeInner(r,n+1);h!=nr?i[s+2]=h:(i.splice(s,3),s-=3)}if(s.length)for(let i,r=0;r<t.length;r++)if(i=t[r])for(let t=0;t<s.length;t++)s[t].eq(i,e)&&(s==this.local&&(s=this.local.slice()),s.splice(t--,1));return i==this.children&&s==this.local?this:s.length||i.length?new rr(s,i):nr}forChild(t,e){if(this==nr)return this;if(e.isLeaf)return rr.empty;let i,s;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){this.children[e]==t&&(i=this.children[e+2]);break}let r=t+1,n=r+e.content.size;for(let t=0;t<this.local.length;t++){let e=this.local[t];if(e.from<n&&e.to>r&&e.type instanceof Zs){let t=Math.max(r,e.from)-r,i=Math.min(n,e.to)-r;t<i&&(s||(s=[])).push(e.copy(t,i))}}if(s){let t=new rr(s.sort(cr),ir);return i?new or([t,i]):t}return i||nr}eq(t){if(this==t)return!0;if(!(t instanceof rr)||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 fr(this.localsInner(t))}localsInner(t){if(this==nr)return ir;if(t.inlineContent||!this.local.some(Zs.is))return this.local;let e=[];for(let t=0;t<this.local.length;t++)this.local[t].type instanceof Zs||e.push(this.local[t]);return e}forEachSet(t){t(this)}}rr.empty=new rr([],[]),rr.removeOverlap=fr;const nr=rr.empty;class or{constructor(t){this.members=t}map(t,e){const i=this.members.map((i=>i.map(t,e,sr)));return or.from(i)}forChild(t,e){if(e.isLeaf)return rr.empty;let i=[];for(let s=0;s<this.members.length;s++){let r=this.members[s].forChild(t,e);r!=nr&&(r instanceof or?i=i.concat(r.members):i.push(r))}return or.from(i)}eq(t){if(!(t instanceof or)||t.members.length!=this.members.length)return!1;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return!1;return!0}locals(t){let e,i=!0;for(let s=0;s<this.members.length;s++){let r=this.members[s].localsInner(t);if(r.length)if(e){i&&(e=e.slice(),i=!1);for(let t=0;t<r.length;t++)e.push(r[t])}else e=r}return e?fr(i?e:e.sort(cr)):ir}static from(t){switch(t.length){case 0:return nr;case 1:return t[0];default:return new or(t.every((t=>t instanceof rr))?t:t.reduce(((t,e)=>t.concat(e instanceof rr?e:e.members)),[]))}}forEachSet(t){for(let e=0;e<this.members.length;e++)this.members[e].forEachSet(t)}}function hr(t,e){if(!e||!t.length)return t;let i=[];for(let s=0;s<t.length;s++){let r=t[s];i.push(new er(r.from+e,r.to+e,r.type))}return i}function lr(t,e,i){if(e.isLeaf)return null;let s=i+e.nodeSize,r=null;for(let e,n=0;n<t.length;n++)(e=t[n])&&e.from>i&&e.to<s&&((r||(r=[])).push(e),t[n]=null);return r}function ar(t){let e=[];for(let i=0;i<t.length;i++)null!=t[i]&&e.push(t[i]);return e}function ur(t,e,i,s){let r=[],n=!1;e.forEach(((e,o)=>{let h=lr(t,e,o+i);if(h){n=!0;let t=ur(h,e,i+o+1,s);t!=nr&&r.push(o,o+e.nodeSize,t)}}));let o=hr(n?ar(t):t,-i).sort(cr);for(let t=0;t<o.length;t++)o[t].type.valid(e,o[t])||(s.onRemove&&s.onRemove(o[t].spec),o.splice(t--,1));return o.length||r.length?new rr(o,r):nr}function cr(t,e){return t.from-e.from||t.to-e.to}function fr(t){let e=t;for(let i=0;i<e.length-1;i++){let s=e[i];if(s.from!=s.to)for(let r=i+1;r<e.length;r++){let n=e[r];if(n.from!=s.from){n.from<s.to&&(e==t&&(e=t.slice()),e[i]=s.copy(s.from,n.from),dr(e,r,s.copy(n.from,s.to)));break}n.to!=s.to&&(e==t&&(e=t.slice()),e[r]=n.copy(n.from,s.to),dr(e,r+1,n.copy(s.to,n.to)))}}return e}function dr(t,e,i){for(;e<t.length&&cr(i,t[e])>0;)e++;t.splice(e,0,i)}function pr(t){let e=[];return t.someProp("decorations",(i=>{let s=i(t.state);s&&s!=nr&&e.push(s)})),t.cursorWrapper&&e.push(rr.create(t.state.doc,[t.cursorWrapper.deco])),or.from(e)}const gr={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},wr=Ne&&ze<=11;class mr{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 vr{constructor(t,e){this.view=t,this.handleDOMChange=e,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new mr,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]);Ne&&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()})),wr&&(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,gr)),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(Ne&&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 s=t.anchorNode;s;s=xe(s))if(i.has(s)){e=s;break}let s=e&&this.view.docView.nearestDesc(e);return s&&s.ignoreMutation({type:"selection",target:3==e.nodeType?e.parentNode:e})?(this.setCurSelection(),!0):void 0}pendingRecords(){if(this.observer)for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}flush(){let{view:t}=this;if(!t.docView||this.flushingSoon>-1)return;let e=this.pendingRecords();e.length&&(this.queue=[]);let i=t.domSelectionRange(),s=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(i)&&qi(t)&&!this.ignoreSelectionChange(i),r=-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&&(r=r<0?i.from:Math.min(i.from,r),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(_e&&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 s of e){let e=s.parentNode;!e||"LI"!=e.nodeName||i&&Mr(t,i)==e||s.remove()}}}}else for(let t of h)if("BR"==t.nodeName&&t.parentNode){let e=t.nextSibling;for(;e&&1==e.nodeType;){if("false"==e.contentEditable){t.parentNode.removeChild(t);break}e=e.firstChild}}let l=null;r<0&&s&&t.input.lastFocus>Date.now()-200&&Math.max(t.input.lastTouch,t.input.lastClick.time)<Date.now()-300&&Ie(i)&&(l=_i(t))&&l.eq(ee.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,Hi(t),this.currentSelection.set(i),t.scrollToSelection()):(r>-1||s)&&(r>-1&&(t.docView.markDirty(r,n),function(t){if(!yr.has(t)&&(yr.set(t,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace))){if(t.requiresGeckoHackNode=_e,kr)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."),kr=!0}}(t)),t.input.badSafariComposition&&(t.input.badSafariComposition=!1,function(t,e){var i;let{focusNode:s,focusOffset:r}=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),s==n&&t.domSelection().collapse(n,r)}else n.parentNode.removeChild(n)}}(t,h)),this.handleDOMChange(r,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 s=t.addedNodes[i];e.push(s),3==s.nodeType&&(this.lastChangedTextNode=s)}if(i.contentDOM&&i.contentDOM!=i.dom&&!i.contentDOM.contains(t.target))return{from:i.posBefore,to:i.posAfter};let s=t.previousSibling,r=t.nextSibling;if(Ne&&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)&&(s=i),(!n||Array.prototype.indexOf.call(t.addedNodes,n)<0)&&(r=n)}let n=s&&s.parentNode==t.target?Me(s)+1:0,o=i.localPosFromDOM(t.target,n,-1),h=r&&r.parentNode==t.target?Me(r):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 yr=new WeakMap,kr=!1;function br(t,e){let i=e.startContainer,s=e.startOffset,r=e.endContainer,n=e.endOffset,o=t.domAtPos(t.state.selection.anchor);return Se(o.node,o.offset,r,n)&&([i,s,r,n]=[r,n,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:n}}function Mr(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 xr(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 Cr=/^(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 Ar(t,e,i){return Math.max(i.anchor,i.head)>e.content.size?null:Qi(t,e.resolve(i.anchor),e.resolve(i.head))}function Sr(t,e,i){let s=t.depth,r=e?t.end():t.pos;for(;s>0&&(e||t.indexAfter(s)==t.node(s).childCount);)s--,r++,e=!1;if(i){let e=t.node(s).maybeChild(t.indexAfter(s));for(;e&&!e.isLeaf;)e=e.firstChild,r++}return r}function Br(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 Tr{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 Bs,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=e,this.state=e.state,this.directPlugins=e.plugins||[],this.directPlugins.forEach(Pr),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=Ir(this),Er(this),this.nodeViews=$r(this),this.docView=Ai(this.state.doc,Or(this),pr(this),this.dom,this),this.domObserver=new vr(this,((t,e,i,s)=>function(t,e,i,s,r){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=_i(t,e);if(i&&!t.state.selection.eq(i)){if(He&&Je&&13===t.input.lastKeyCode&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",(e=>e(t,$e(13,"Enter")))))return;let s=t.state.tr.setSelection(i);"pointer"==e?s.setMeta("pointer",!0):"key"==e&&s.scrollIntoView(),n&&s.setMeta("composition",n),t.dispatch(s)}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 s,{node:r,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)&&(s=[{node:u,offset:a.anchorOffset}],Ie(a)||s.push({node:a.focusNode,offset:a.focusOffset})),He&&8===t.input.lastKeyCode)for(let t=o;t>n;t--){let e=r.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(r,{topNode:d.parent,topMatch:d.parent.contentMatchAt(d.index()),topOpen:!0,from:n,to:o,preserveWhitespace:"pre"!=d.parent.type.whitespace||"full",findPositions:s,ruleFromNode:xr,context:d});if(s&&null!=s[0].pos){let t=s[0].pos,e=s[1]&&s[1].pos;null==e&&(e=t),p={anchor:t+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,s,r){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"==r&&(s-=o+Math.max(0,n-Math.min(o,h))-n),o<n&&t.size<e.size){let t=s<=n&&s>=o?n-s:0;n-=t,n&&n<e.size&&Br(e.textBetween(n-1,n+1))&&(n+=t?1:-1),h=n+(h-o),o=n}else if(h<n){let e=s<=n&&s>=h?n-s:0;n-=e,n&&n<t.size&&Br(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||Je)&&r.some((t=>1==t.nodeType&&!Cr.test(t.nodeName)))&&(!g||g.endA>=g.endB)&&t.someProp("handleKeyDown",(e=>e(t,$e(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(!g){if(!(s&&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=Ar(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)),Ne&&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||r.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,$e(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(t.state.selection.anchor>g.start&&function(t,e,i,s,r){if(i-e<=r.pos-s.pos||Sr(s,!0,!1)<r.pos)return!1;let n=t.resolve(e);if(!s.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(Sr(n,!0,!0));return!(!o.parent.isTextblock||o.pos>i||Sr(o,!0,!1)<i)&&s.parent.content.cut(s.parentOffset).eq(o.parent.content)}(d,g.start,g.endA,w,m)&&t.someProp("handleKeyDown",(e=>e(t,$e(8,"Backspace")))))return void(Je&&He&&t.domObserver.suppressSelectionUpdates());He&&g.endB==g.start&&(t.input.lastChromeDelete=Date.now()),Je&&!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,$e(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=Ar(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)||Ne&&e.empty&&e.head==b)&&i.setSelection(e)}return n&&i.setMeta("composition",n),i.scrollIntoView()};if(y)if(w.pos==m.pos){Ne&&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,s,r,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)s=h[0],i="add",r=t=>t.mark(s.addToSet(t.marks));else{if(0!=h.length||1!=l.length)return null;s=l[0],i="remove",r=t=>t.mark(s.removeFromSet(t.marks))}let a=[];for(let t=0;t<e.childCount;t++)a.push(r(e.child(t)));if(c.from(a).eq(t))return{mark:s,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",(s=>s(t,b,M,e,i)))||t.dispatch(i())}else t.dispatch(x());else t.dispatch(x())}(this,t,e,i,s))),this.domObserver.start(),function(t){for(let e in Cs){let i=Cs[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=e=>{!Is(t,e)||Es(t,e)||!t.editable&&e.type in As||i(t,e)},Ss[e]?{passive:!0}:void 0)}Ye&&t.dom.addEventListener("input",(()=>null)),Os(t)}(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let t=this._props;this._props={};for(let e in t)this._props[e]=t[e];this._props.state=this.state}return this._props}update(t){t.handleDOMEvents!=this._props.handleDOMEvents&&Os(this);let e=this._props;this._props=t,t.plugins&&(t.plugins.forEach(Pr),this.directPlugins=t.plugins),this.updateStateInner(t.state,e)}setProps(t){let e={};for(let t in this._props)e[t]=this._props[t];e.state=this.state;for(let i in t)e[i]=t[i];this.update(e)}updateState(t){this.updateStateInner(t,this._props)}updateStateInner(t,e){var i;let s=this.state,r=!1,n=!1;t.storedMarks&&this.composing&&(Hs(this),n=!0),this.state=t;let o=s.plugins!=t.plugins||this._props.plugins!=e.plugins;if(o||this._props.plugins!=e.plugins||this._props.nodeViews!=e.nodeViews){let t=$r(this);(function(t,e){let i=0,s=0;for(let s in t){if(t[s]!=e[s])return!0;i++}for(let t in e)s++;return i!=s})(t,this.nodeViews)&&(this.nodeViews=t,r=!0)}(o||e.handleDOMEvents!=this._props.handleDOMEvents)&&Os(this),this.editable=Ir(this),Er(this);let h=pr(this),l=Or(this),a=s.plugins==t.plugins||s.doc.eq(t.doc)?t.scrollToSelection>s.scrollToSelection?"to selection":"preserve":"reset",u=r||!this.docView.matchesNode(t.doc,l,h);!u&&t.selection.eq(s.selection)||(n=!0);let c="preserve"==a&&n&&null==this.dom.style.overflowAnchor&&function(t){let e,i,s=t.dom.getBoundingClientRect(),r=Math.max(0,s.top);for(let n=(s.left+s.right)/2,o=r+1;o<Math.min(innerHeight,s.bottom);o+=5){let s=t.root.elementFromPoint(n,o);if(!s||s==t.dom||!t.dom.contains(s))continue;let h=s.getBoundingClientRect();if(h.top>=r-20){e=s,i=h.top;break}}return{refDOM:e,refTop:i,stack:ii(t.dom)}}(this);if(n){this.domObserver.stop();let e=u&&(Ne||He)&&!this.composing&&!s.selection.empty&&!t.selection.empty&&function(t,e){let i=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(i)!=e.$anchor.start(i)}(s.selection,t.selection);if(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),s=function(t,e){for(;;){if(3==t.nodeType&&e<t.nodeValue.length)return t;if(1==t.nodeType&&e<t.childNodes.length){if("false"==t.contentEditable)return null;t=t.childNodes[e],e=0}else{if(!t.parentNode||Ee(t))return null;e=Me(t)+1,t=t.parentNode}}}(e.focusNode,e.focusOffset);if(i&&s&&i!=s){let e=s.pmViewDesc,r=t.domObserver.lastChangedTextNode;if(i==r||s==r)return r;if(!e||!e.isText(s.nodeValue))return s;if(t.input.compositionNode==s){let t=i.pmViewDesc;if(t&&t.isText(i.nodeValue))return s}}return i||s}(this)),!r&&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):(Ki(this,t.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),(null===(i=this.dragging)||void 0===i?void 0:i.node)&&!s.doc.eq(t.doc)&&this.updateDraggedNode(this.dragging,s),"reset"==a?this.dom.scrollTop=0:"to selection"==a?this.scrollToSelection():c&&function({refDOM:t,refTop:e,stack:i}){let s=t?t.getBoundingClientRect().top:0;si(i,0==s?0:s-e)}(c)}scrollToSelection(){let t=this.domSelectionRange().focusNode;if(t&&this.dom.contains(1==t.nodeType?t:t.parentNode))if(this.someProp("handleScrollToSelection",(t=>t(this))));else if(this.state.selection instanceof 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,s=-1;if(i.from<this.state.doc.content.size&&this.state.doc.nodeAt(i.from)==i.node)s=i.from;else{let t=i.from+(this.state.doc.content.size-e.doc.content.size);(t>0&&t<this.state.doc.content.size&&this.state.doc.nodeAt(t))==i.node&&(s=t)}this.dragging=new Ks(t.slice,t.move,s<0?void 0:he.create(this.state.doc,s))}someProp(t,e){let i,s=this._props&&this._props[t];if(null!=s&&(i=e?e(s):s))return i;for(let s=0;s<this.directPlugins.length;s++){let r=this.directPlugins[s].props[t];if(null!=r&&(i=e?e(r):r))return i}let r=this.state.plugins;if(r)for(let s=0;s<r.length;s++){let n=r[s].props[t];if(null!=n&&(i=e?e(n):n))return i}}hasFocus(){if(Ne){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(ri)return t.focus(ri);let e=ii(t);t.focus(null==ri?{get preventScroll(){return ri={preventScroll:!0},!0}}:void 0),ri||(ri=!1,si(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 s=this.docView.posFromDOM(t,e,i);if(null==s)throw new RangeError("DOM position not inside the editor");return s}endOfTextblock(t,e){return function(t,e,i){return mi==e&&vi==i?yi:(mi=e,vi=i,yi="up"==i||"down"==i?function(t,e,i){let s=e.selection,r="up"==i?s.$from:s.$to;return gi(t,e,(()=>{let{node:e}=t.docView.domFromPos(r.pos,"up"==i?-1:1);for(;;){let i=t.docView.nearestDesc(e,!0);if(!i)break;if(i.node.isBlock){e=i.contentDOM||i.dom;break}e=i.dom.parentNode}let s=fi(t,r.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 r=e[t];if(r.bottom>r.top+1&&("up"==i?s.top-r.top>2*(r.bottom-s.top):r.bottom-s.bottom>2*(s.bottom-r.top)))return!1}}return!0}))}(t,e,i):function(t,e,i){let{$head:s}=e.selection;if(!s.parent.isTextblock)return!1;let r=s.parentOffset,n=!r,o=r==s.parent.content.size,h=t.domSelection();return h?wi.test(s.parent.textContent)&&h.modify?gi(t,e,(()=>{let{focusNode:e,focusOffset:r,anchorNode:n,anchorOffset:o}=t.domSelectionRange(),l=h.caretBidiLevel;h.modify("move",i,"character");let a=s.depth?t.docView.domAfterPos(s.before()):t.dom,{focusNode:u,focusOffset:c}=t.domSelectionRange(),f=u&&!a.contains(1==u.nodeType?u:u.parentNode)||e==u&&r==c;try{h.collapse(n,o),e&&(e!=n||r!=o)&&h.extend&&h.extend(e,r)}catch(t){}return null!=l&&(h.caretBidiLevel=l),f})):"left"==i||"backward"==i?n:o:s.pos==s.start()||s.pos==s.end()}(t,e,i))}(this,e||this.state,t)}pasteHTML(t,e){return Ws(this,"",t,!1,e||new ClipboardEvent("paste"))}pasteText(t,e){return Ws(this,t,null,!0,e||new ClipboardEvent("paste"))}serializeForClipboard(t){return fs(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,[],pr(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){Es(t,e)||!Cs[e.type]||!t.editable&&e.type in As||Cs[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 br(t,i)}let i;function s(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",s,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",s,!0),i?br(t,i):null}(this,t)||t:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function Or(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"),[er.node(0,t.state.doc.content.size,e)]}function Er(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:er.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Ir(t){return!t.someProp("editable",(e=>!1===e(t.state)))}function $r(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 Pr(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")}Tr.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};const Dr=["p",0],Rr=["blockquote",0],jr=["hr"],Fr=["pre",["code",0]],Ur=["br"],Nr=["em",0],zr=["strong",0],_r=["code",0],Lr=new tt({nodes:{doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:()=>Dr},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:()=>Rr},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>jr},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:()=>Fr},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs:t=>({src:t.getAttribute("src"),title:t.getAttribute("title"),alt:t.getAttribute("alt")})}],toDOM(t){let{src:e,alt:i,title:s}=t.attrs;return["img",{src:e,alt:i,title:s}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM:()=>Ur}},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:()=>Nr},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:()=>zr},code:{code:!0,parseDOM:[{tag:"code"}],toDOM:()=>_r}}}),Hr=["ol",0],Xr=["ul",0],Yr=["li",0],Wr={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?Hr:["ol",{start:t.attrs.order},0]},Vr={parseDOM:[{tag:"ul"}],toDOM:()=>Xr},Kr={parseDOM:[{tag:"li"}],toDOM:()=>Yr,defining:!0};function Jr(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 Qr(t,e,i){return t.append({ordered_list:Jr(Wr,{content:"list_item+",group:i}),bullet_list:Jr(Vr,{content:"list_item+",group:i}),list_item:Jr(Kr,{content:e})})}for(var qr={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:"'"},Gr={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Zr="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++)qr[48+en]=qr[96+en]=String(en);for(en=1;en<=24;en++)qr[en+111]="F"+en;for(en=65;en<=90;en++)qr[en]=String.fromCharCode(en+32),Gr[en]=String.fromCharCode(en);for(var sn in qr)Gr.hasOwnProperty(sn)||(Gr[sn]=qr[sn]);const rn="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,s,r,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))r=!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))s=!0;else{if(!/^mod$/i.test(o))throw new Error("Unrecognized modifier name: "+o);rn?r=!0:i=!0}}return e&&(o="Alt-"+o),i&&(o="Ctrl-"+o),r&&(o="Meta-"+o),s&&(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 s,r=function(t){var e=!(Zr&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||tn&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?Gr:qr)[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(r,i)];if(n&&n(t.state,t.dispatch,t))return!0;if(1==r.length&&" "!=r){if(i.shiftKey){let s=e[hn(r,i,!1)];if(s&&s(t.state,t.dispatch,t))return!0}if((i.altKey||i.metaKey||i.ctrlKey)&&!(nn&&i.ctrlKey&&i.altKey)&&(s=qr[i.keyCode])&&s!=r){let r=e[hn(s,i)];if(r&&r(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 s=t;s;s="start"==e?s.firstChild:s.lastChild){if(s.isTextblock)return!0;if(i&&1!=s.childCount)return!1}return!1}function 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,s){let r,n,o=e.nodeBefore,h=e.nodeAfter,l=o.type.spec.isolating||h.type.spec.isolating;if(!l&&function(t,e,i){let s=e.nodeBefore,r=e.nodeAfter,n=e.index();return!(!(s&&r&&s.type.compatibleContent(r.type))||(!s.content.size&&e.parent.canReplace(n-1,n)?(i&&i(t.tr.delete(e.pos-s.nodeSize,e.pos).scrollIntoView()),0):!e.parent.canReplace(n,n+1)||!r.isTextblock&&!Nt(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&&(r=(n=o.contentMatchAt(o.childCount)).findWrapping(h.type))&&n.matchType(r[0]||h.type).validEnd){if(i){let s=e.pos+h.nodeSize,n=c.empty;for(let t=r.length-1;t>=0;t--)n=c.from(r[t].create(null,n));n=c.from(o.copy(n));let l=t.tr.step(new It(e.pos-1,s,e.pos,s,new m(n,1,0),r.length,!0)),a=l.doc.resolve(s+2*r.length);a.nodeAfter&&a.nodeAfter.type==o.type&&Nt(l.doc,a.pos)&&l.join(a.pos),i(l.scrollIntoView())}return!0}let u=h.type.spec.isolating||s>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 s=o,r=[];for(;r.push(s),!s.isTextblock;)s=s.lastChild;let n=h,l=1;for(;!n.isTextblock;n=n.firstChild)l++;if(s.canReplace(s.childCount,s.childCount,n.content)){if(i){let s=c.empty;for(let t=r.length-1;t>=0;t--)s=c.from(r[t].copy(s));i(t.tr.step(new It(e.pos-r.length,e.pos+h.nodeSize,e.pos+l,e.pos+h.nodeSize-l,new m(s,r.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function wn(t){return function(e,i){let s=e.selection,r=t<0?s.$from:s.$to,n=r.depth;for(;r.node(n).isInline;){if(!n)return!1;n--}return!!r.node(n).isTextblock&&(i&&i(e.tr.setSelection(ne.create(e.doc,t<0?r.start(n):r.end(n)))),!0)}}const mn=wn(-1),vn=wn(1);function yn(...t){return function(e,i,s){for(let r=0;r<t.length;r++)if(t[r](e,i,s))return!0;return!1}}let kn=yn(un,((t,e,i)=>{let s=function(t,e){let{$cursor:i}=t.selection;return!i||(e?!e.endOfTextblock("backward",t):i.parentOffset>0)?null:i}(t,i);if(!s)return!1;let r=fn(s);if(!r){let i=s.blockRange(),r=i&&Rt(i);return null!=r&&(e&&e(t.tr.lift(i,r).scrollIntoView()),!0)}let n=r.nodeBefore;if(gn(t,r,e,-1))return!0;if(0==s.parent.content.size&&(cn(n,"end")||he.isSelectable(n)))for(let i=s.depth;;i--){let o=zt(t.doc,s.before(i),s.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(r.pos,-1)),-1):he.create(i.doc,r.pos-n.nodeSize)),e(i.scrollIntoView())}return!0}if(1==i||s.node(i-1).childCount>1)break}return!(!n.isAtom||r.depth!=s.depth-1||(e&&e(t.tr.delete(r.pos-n.nodeSize,r.pos).scrollIntoView()),0))}),((t,e,i)=>{let{$head:s,empty:r}=t.selection,n=s;if(!r)return!1;if(s.parent.isTextblock){if(i?!i.endOfTextblock("backward",t):s.parentOffset>0)return!1;n=fn(s)}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 s=function(t,e){let{$cursor:i}=t.selection;return!i||(e?!e.endOfTextblock("forward",t):i.parentOffset<i.parent.content.size)?null:i}(t,i);if(!s)return!1;let r=dn(s);if(!r)return!1;let n=r.nodeAfter;if(gn(t,r,e,1))return!0;if(0==s.parent.content.size&&(cn(n,"start")||he.isSelectable(n))){let i=zt(t.doc,s.before(),s.after(),m.empty);if(i&&i.slice.size<i.to-i.from){if(e){let s=t.tr.step(i);s.setSelection(cn(n,"start")?ee.findFrom(s.doc.resolve(s.mapping.map(r.pos)),1):he.create(s.doc,s.mapping.map(r.pos))),e(s.scrollIntoView())}return!0}}return!(!n.isAtom||r.depth!=s.depth-1||(e&&e(t.tr.delete(r.pos,r.pos+n.nodeSize).scrollIntoView()),0))}),((t,e,i)=>{let{$head:s,empty:r}=t.selection,n=s;if(!r)return!1;if(s.parent.isTextblock){if(i?!i.endOfTextblock("forward",t):s.parentOffset<s.parent.content.size)return!1;n=dn(s)}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:s}=t.selection;return!(!i.parent.type.spec.code||!i.sameParent(s)||(e&&e(t.tr.insertText("\n").scrollIntoView()),0))}),((t,e)=>{let i=t.selection,{$from:s,$to:r}=i;if(i instanceof ae||s.parent.inlineContent||r.parent.inlineContent)return!1;let n=pn(r.parent.contentMatchAt(r.indexAfter()));if(!n||!n.isTextblock)return!1;if(e){let i=(!s.parentOffset&&r.index()<r.parent.childCount?s:r).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 s=i.before();if(Ut(t.doc,s))return e&&e(t.tr.split(s).scrollIntoView()),!0}let s=i.blockRange(),r=s&&Rt(s);return null!=r&&(e&&e(t.tr.lift(s,r).scrollIntoView()),!0)}),((t,e)=>{let{$from:i}=t.selection;if(t.selection instanceof he&&t.selection.node.isBlock)return!(!i.parentOffset||!Ut(t.doc,i.pos)||(e&&e(t.tr.split(i.pos).scrollIntoView()),0));if(!i.depth)return!1;let s,r,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),r=pn(i.node(t-1).contentMatchAt(i.indexAfter(t-1))),n.unshift(o&&r?{type:r}:null),s=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=Ut(l.doc,a,n.length,n);if(u||(n[0]=r?{type:r}:null,u=Ut(l.doc,a,n.length,n)),!u)return!1;if(l.split(a,n.length,n),!o&&h&&i.node(s).type!=r){let t=l.mapping.map(i.before(s)),e=l.doc.resolve(t);r&&i.node(s-1).canReplaceWith(e.index(),e.index()+1,r)&&l.setNodeMarkup(l.mapping.map(i.before(s)),r)}return e&&e(l.scrollIntoView()),!0})),"Mod-Enter":(t,e)=>{let{$head:i,$anchor:s}=t.selection;if(!i.parent.type.spec.code||!i.sameParent(s))return!1;let r=i.node(-1),n=i.indexAfter(-1),o=pn(r.contentMatchAt(n));if(!o||!r.canReplaceWith(n,n,o))return!1;if(e){let s=i.after(),r=t.tr.replaceWith(s,s,o.createAndFill());r.setSelection(ee.near(r.doc.resolve(s),1)),e(r.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",loadingOverlayBackground:"rgba(255, 255, 255, 0.85)",loadingOverlayColor:"#333333",loadingOverlaySpinnerActiveColor:"#333333",loadingOverlaySpinnerColor:"#cccccc"},snap:{indicatorFill:"rgba(59, 130, 246, 0.3)",indicatorStroke:"#007bff",lineStroke:"rgba(0, 0, 0, 0.2)"},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",loadingOverlayBackground:"rgba(26, 26, 26, 0.85)",loadingOverlayColor:"#e0e0e0",loadingOverlaySpinnerActiveColor:"#e0e0e0",loadingOverlaySpinnerColor:"#555555"},snap:{indicatorFill:"rgba(10, 132, 255, 0.35)",indicatorStroke:"#0A84FF",lineStroke:"rgba(255, 255, 255, 0.35)"},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,s=(t,e,r=!1)=>{for(const[n,o]of Object.entries(t)){if(r&&"name"===n)continue;const t=`${e}-${Tn.camelToKebab(n)}`;"object"==typeof o&&null!==o?s(o,t):"string"==typeof o&&i.set(t,o)}};return s(t,e,!0),i}static applyVariablesToElement(t,e){for(const[i,s]of e)t.style.setProperty(i,s)}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 $n{static resolveThemeColor(t,e){return t?function(t,e){return t[e]}(t,e??In.getStoredTheme()):""}static applyOpacity(t,e,i){const s="string"==typeof t?t:this.resolveThemeColor(t,i);if(!s||e>=1)return s;const r=s.startsWith("#")?s.slice(1):s;let n,o,h;if(3===r.length)n=parseInt(r[0]+r[0],16),o=parseInt(r[1]+r[1],16),h=parseInt(r[2]+r[2],16);else{if(6!==r.length)return s;n=parseInt(r.substring(0,2),16),o=parseInt(r.substring(2,4),16),h=parseInt(r.substring(4,6),16)}return isNaN(n)||isNaN(o)||isNaN(h)?s:`rgba(${n}, ${o}, ${h}, ${e})`}static getContrastColor(t){const e=t.startsWith("#")?t.slice(1):t;let i,s,r;if(3===e.length)i=parseInt(e[0]+e[0],16),s=parseInt(e[1]+e[1],16),r=parseInt(e[2]+e[2],16);else{if(6!==e.length)return"#000000";i=parseInt(e.substring(0,2),16),s=parseInt(e.substring(2,4),16),r=parseInt(e.substring(4,6),16)}return isNaN(i)||isNaN(s)||isNaN(r)||.299*i+.587*s+.114*r>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:Qr(Lr.spec.nodes,"paragraph block*","block"),marks:Lr.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,s){const r=new Pn;r._core=t,r.id=r.generateId(),r.workspaceId=t.store.state.activeWorkspace.id,r.userId=t.user?.id,r.fontSize=e||8,r.fontFamily=i||"Arial",r.translateX=0,r.translateY=0;const n=t.store.state.scale,o=n<0?n:1;return r.width=r.initialWidth/o,r.height=1.2*r.fontSize/o,r.backgroundColor={light:"transparent",dark:"transparent"},r.initialWidth=r.width,r.initialHeight=r.height,r.scaleFactor=1,r.scale=s??n,r.zIndex=t.store.currentZIndex,r}mount(t){null!==t&&!1!==this.isInViewport()&&(t.style.fontFamily=this.fontFamily,t.style.fontSize=`${this.fontSize}pt`,t.style.color=$n.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 Tr(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.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const e=this.editor.state.schema.nodeFromJSON(t),i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",!0),this.editor.dispatch(i)}}adjustSizeOnInput(){const t=this.elementRef;if(t&&this.isMounted&&t.scrollWidth>0){const e=this.totalWidth,i=this.totalHeight,s=t.scrollHeight;if(this.width=t.scrollWidth*this.scaleFactor,this.height=s*this.scaleFactor,0!==this.rotation){const t=(this.totalWidth-e)/2/this.scale,s=(this.totalHeight-i)/2/this.scale;if(0!==t||0!==s){const e=Math.cos(this.rotation),i=Math.sin(this.rotation),r=i*t+e*s;this.translateX+=e*t-i*s-t,this.translateY+=r-s}}}}resize(t,e,i,s){if(i<=1||s<=1)return;const r=this.width/this.scaleFactor,n=this.height/this.scaleFactor;this.scaleFactor=Math.min(i/r,s/n),this.width=r*this.scaleFactor,this.height=n*this.scaleFactor,this.translateX=t,this.translateY=e,this._core.store.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(),t?.clientX&&t?.clientY&&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.objects.consolidateTemporaryItems(),this._core.store.objects.update(this),this._core.engine.emitObjectsChange()}handleEscape(){if(!this.editor||!this.isEditing)return;const{state:t}=this.editor;if(!t.selection.empty)return this.editor.dispatch(t.tr.setSelection(ne.create(t.doc,t.selection.head))),void this.editor.focus();this._core.resetActiveText(),this._core.clearSelection(),this._core.store.setState("activeTool",i.getTool("selection"))}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:s,totalWidth:r,totalHeight:n,editor:o,uneditedObject:h,...l}=this,a=structuredClone(l);return s&&"object"==typeof s&&"nodeType"in s&&1===s.nodeType&&(a.element=s.cloneNode(!0)),a}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}}var Dn,Rn={},jn=(Dn||(Dn=1,function(t){Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const{PI:e}=Math,i=e+1e-4,s=[1,1];function r(t,e,i,s=t=>t){return t*s(.5-e*(.5-i))}const{min:n}=Math;function o(t,e,i){let s=n(1,e/i);return n(1,t+(n(1,1-s)-t)*(.275*s))}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],s=t[1]-e[1];return i*i+s*s}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 s=Math.sin(i),r=Math.cos(i),n=t[0]-e[0],o=t[1]-e[1];return[n*r-o*s+e[0],n*s+o*r+e[1]]}function b(t,e,i,s){let r=Math.sin(s),n=Math.cos(s),o=e[0]-i[0],h=e[1]-i[1],l=o*r+h*n;return t[0]=o*n-h*r+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,s){let r=i[1]-e[1];return t[0]=e[0]+(i[0]-e[0])*s,t[1]=e[1]+r*s,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 s=C(t,v(d(a(t,h(t,[1,1])))),-e),r=[],n=1/13;for(let e=n;e<=1;e+=n)r.push(k(s,t,2*i*e));return r}function O(t,e,s){let r=[],n=1/s;for(let s=n;s<=1;s+=n)r.push(k(e,t,i*s));return r}function E(t,e,i){let s=a(e,i),r=c(s,.5),n=c(s,.51);return[a(t,r),a(t,n),h(t,n),h(t,r)]}function I(t,e,s,r){let n=[],o=C(t,e,s),h=1/r;for(let e=h;e<1;e+=h)n.push(k(o,t,3*i*e));return n}function $(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 D(t,e={}){let{size:s=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:D=t=>t*(2-t)}=y,{cap:R=!0,easing:j=t=>--t*t*t+1}=k;if(0===t.length||s<=0)return[];let F,U=t[t.length-1].runningLength,N=P(y.taper,s,U),z=P(k.taper,s,U),_=(s*n)**2,L=[],H=[],X=function(t,e,i){return t.slice(0,10).reduce(((t,s)=>{let r=s.pressure;return e&&(r=o(t,s.distance,i)),(t+r)/2}),t[0].pressure)}(t,w,s),Y=r(s,c,t[t.length-1].pressure,v),W=t[0].vector,V=t[0].point,K=V,J=V,Q=K,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&&U-M<3)continue;c?(w&&(n=o(X,k,s)),Y=r(s,c,n,v)):Y=s/2,void 0===F&&(F=Y);let T=M<N?D(M/N):1,O=U-M<z?j((U-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),$=null!==I&&I<0;if(g(y,W)<0&&!q||$){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),J=[S[0],S[1]],L.push(J),l(B,d,A),b(B,B,d,i*-t),Q=[B[0],B[1]],H.push(Q);V=J,K=Q,$&&(q=!0)}else q=!1,C?(p(A,y),f(A,A,Y),L.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),J=[S[0],S[1]],(e<=1||m(V,J)>_)&&(L.push(J),V=J),l(B,d,A),Q=[B[0],B[1]],(e<=1||m(K,Q)>_)&&(H.push(Q),K=Q),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(!N&&!z||M)return T(G,F||Y)}else{N||z&&1===t.length||(C?tt.push(...O(G,H[0],13)):tt.push(...E(G,L[0],H[0])));let e=d(function(t){return[-t[0],-t[1]]}(t[t.length-1].vector));z||N&&1===t.length?et.push(Z):R?et.push(...I(Z,e,Y,29)):et.push(...$(Z,e,Y))}return L.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:r=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],s),...l[0].slice(2)]]);let a=[{point:[l[0][0],l[0][1]],pressure:j(l[0][2])?l[0][2]:.25,vector:[...s],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<r)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 U(t,e={}){return D(F(t,e),e)}t.default=U,t.getStroke=U,t.getStrokeOutlinePoints=D,t.getStrokePoints=F}(Rn)),Rn);class Fn{static average(t,e){return(t+e)/2}}class Un 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 Un;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,s){if(i<=1||s<=1)return;const r=i/this.width,n=s/this.height;if(this.width=i,this.height=s,1===this.points.length){const t=this.points[0],e=Math.max(0,i-this.strokeWidth)/r,o=Math.max(0,s-this.strokeWidth)/n;this.points.push([t[0]+e,t[1]+o])}this.points=this.points.map((([t,e])=>[t*r,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.objects.update(this)}rotate(t){this.rotation=t,this._adjustedPoints=null,this._core.store.objects.update(this)}move(t,e,i,s){const r=(e-s)/this._core.store.state.scale;this.translateX+=(t-i)/this._core.store.state.scale,this.translateY+=r,this._adjustedPoints=null,this._core.store.objects.update(this)}hitTest(t,e){const i=this.strokeWidth/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),1===this._adjustedPoints.length){const s=this._adjustedPoints[0];return this.pointToLineSegmentDistance(t,e,s[0],s[1],s[0],s[1])<=i}for(let s=0;s<this._adjustedPoints.length-1;s++){const r=this._adjustedPoints[s],n=this._adjustedPoints[s+1];if(this.pointToLineSegmentDistance(t,e,r[0],r[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(r.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]},s={x:this._adjustedPoints[t+1][0],y:this._adjustedPoints[t+1][1]};for(let t=0;t<i.length;t++)if(r.intersectLines(e,s,i[t],i[(t+1)%i.length]))return!0}for(let t=0;t<this._adjustedPoints.length-1;t++){const s=this._adjustedPoints[t],r=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,s[0],s[1],r[0],r[1]),l=this.pointToLineSegmentDistance(o.x,o.y,s[0],s[1],r[0],r[1]),a=this.pointToLineSegmentDistance(s[0],s[1],n.x,n.y,o.x,o.y),u=this.pointToLineSegmentDistance(r[0],r[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.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),s=this.points.map((t=>t[0])),r=this.points.map((t=>t[1])),n={x:(Math.min(...s)+Math.max(...s))/2,y:(Math.min(...r)+Math.max(...r))/2},{x:o,y:h}=n;return this.points.map((([t,s])=>{const r=t-o,n=s-h;return[o+r*e-n*i,h+r*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,s,r,n){const o=r-i,h=n-s,l=o*o+h*h;let a,u,c=-1;0!==l&&(c=((t-i)*o+(e-s)*h)/l),c<0?(a=i,u=s):c>1?(a=r,u=n):(a=i+c*o,u=s+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))),s=Math.max(...t.map((t=>t[0]+this.strokeWidth/2))),r=Math.max(...t.map((t=>t[1]+this.strokeWidth/2)));this.width=s-e+this.lineSlack,this.height=r-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,s=Math.max(...this.points.map((t=>t[1])))+this.strokeWidth/2;this.width=i-t+this.lineSlack,this.height=s-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 jn.getStroke(t,{size:e,thinning:.5,smoothing:.5,streamline:.5,easing:t=>t,simulatePressure:!0,last:!0,start:{cap:!0,taper:0,easing:t=>t},end:{cap:!0,taper:0,easing:t=>t}})}getSvgPathFromStroke(t,e=!0){const i=t.length;if(i<4)return"";let s=t[0],r=t[1];const n=t[2];let o=`M${s[0].toFixed(2)},${s[1].toFixed(2)} Q${r[0].toFixed(2)},${r[1].toFixed(2)} ${Fn.average(r[0],n[0]).toFixed(2)},${Fn.average(r[1],n[1]).toFixed(2)} T`;for(let e=2,n=i-1;e<n;e++)s=t[e],r=t[e+1],o+=`${Fn.average(s[0],r[0]).toFixed(2)},${Fn.average(s[1],r[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,s=this.strokeWidth/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),this._adjustedPoints.length<1)return null;let r=!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],s=this.pointToLineSegmentDistance(h,l,e[0],e[1],i[0],i[1]);s<a&&(a=s)}const u=a<=s;if(r&&u){let r=(n-1)/32,h=o;for(let n=0;n<8;n++){const n=(r+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],s=this.pointToLineSegmentDistance(o,l,e[0],e[1],i[0],i[1]);s<a&&(a=s)}a<=s?h=n:r=n}const l=(r+h)/2;return{x:t.x+(e-t.x)*l,y:t.y+(i-t.y)*l}}r=!u}return null}}const Nn="blobs",zn="metadata";class _n{type="local";name="IndexedDBAssetProvider";_dbName;_quiet;_db=null;_urlCache=new Map;_knownIds=new Set;constructor(t){this._dbName=t?.dbName??"kritzel-assets",this._quiet=t?.quiet??!1}static with(t){return{create:()=>new _n(t)}}async init(){this._db||(this._db=await this.openDatabase(),await this.loadKnownIds(),this._quiet||console.info(`IndexedDBAssetProvider initialized: ${this._dbName}`))}destroy(){for(const t of this._urlCache.values())try{URL.revokeObjectURL(t)}catch{}this._urlCache.clear(),this._knownIds.clear(),this._db&&(this._db.close(),this._db=null),this._quiet||console.info(`IndexedDBAssetProvider destroyed: ${this._dbName}`)}canResolve(t){return this._knownIds.has(t)}async put(t,e){const i=await this.ensureDb(),s=e.id??this.generateUuid(),r={id:s,kind:e.kind??"file",mimeType:e.mimeType,size:t.size,createdAt:Date.now(),width:e.width,height:e.height,durationMs:e.durationMs,originalFilename:e.originalFilename};return await new Promise(((e,n)=>{const o=i.transaction([Nn,zn],"readwrite");o.oncomplete=()=>e(),o.onerror=()=>n(o.error),o.onabort=()=>n(o.error),o.objectStore(Nn).put(t,s),o.objectStore(zn).put(r,s)})),this._knownIds.add(s),r}async resolve(t){const e=this._urlCache.get(t);if(e)return e;const i=await this.fetch(t),s=URL.createObjectURL(i);return this._urlCache.set(t,s),s}async fetch(t){const e=await this.ensureDb(),i=await new Promise(((i,s)=>{const r=e.transaction(Nn,"readonly").objectStore(Nn).get(t);r.onsuccess=()=>i(r.result),r.onerror=()=>s(r.error)}));if(!i)throw new Error(`[IndexedDBAssetProvider] Asset ${t} not found`);return this._knownIds.add(t),i}async delete(t){const e=await this.ensureDb();await new Promise(((i,s)=>{const r=e.transaction([Nn,zn],"readwrite");r.oncomplete=()=>i(),r.onerror=()=>s(r.error),r.objectStore(Nn).delete(t),r.objectStore(zn).delete(t)}));const i=this._urlCache.get(t);if(i){try{URL.revokeObjectURL(i)}catch{}this._urlCache.delete(t)}this._knownIds.delete(t)}async getMetadata(t){const e=await this.ensureDb();return new Promise(((i,s)=>{const r=e.transaction(zn,"readonly").objectStore(zn).get(t);r.onsuccess=()=>i(r.result),r.onerror=()=>s(r.error)}))}async listAssetsWithPendingRemotes(){const t=await this.ensureDb();return new Promise(((e,i)=>{const s=t.transaction(zn,"readonly").objectStore(zn).getAll();s.onsuccess=()=>{e((s.result??[]).filter((t=>Array.isArray(t.pendingRemotes)&&t.pendingRemotes.length>0)))},s.onerror=()=>i(s.error)}))}async setPendingRemotes(t,e){const i=await this.ensureDb();await new Promise(((s,r)=>{const n=i.transaction(zn,"readwrite");n.oncomplete=()=>s(),n.onerror=()=>r(n.error);const o=n.objectStore(zn),h=o.get(t);h.onsuccess=()=>{const i=h.result;if(!i)return;const s={...i};e.length>0?s.pendingRemotes=e:delete s.pendingRemotes,o.put(s,t)}}))}async ensureDb(){return this._db||await this.init(),this._db}openDatabase(){return new Promise(((t,e)=>{const i=indexedDB.open(this._dbName,1);i.onupgradeneeded=()=>{const t=i.result;t.objectStoreNames.contains(Nn)||t.createObjectStore(Nn),t.objectStoreNames.contains(zn)||t.createObjectStore(zn)},i.onsuccess=()=>t(i.result),i.onerror=()=>e(i.error)}))}async loadKnownIds(){const t=this._db;t&&await new Promise(((e,i)=>{const s=t.transaction(zn,"readonly").objectStore(zn).getAllKeys();s.onsuccess=()=>{for(const t of s.result)"string"==typeof t&&this._knownIds.add(t);e()},s.onerror=()=>i(s.error)}))}generateUuid(){if("undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID)return crypto.randomUUID();const t=crypto.getRandomValues(new Uint8Array(16));t[6]=15&t[6]|64,t[8]=63&t[8]|128;const e=Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}}class Ln extends Error{assetId;constructor(t,e){super(e??`[KritzelAssetResolver] Asset ${t} not found in any configured provider.`),this.name="AssetNotFoundError",this.assetId=t}}class Hn{_providers=[];_local=null;_remoteProviders=[];_initialized=!1;_readyPromise=null;_resolveReady=null;_rejectReady=null;_pending=new Map;_flushTimer=null;_destroyed=!1;_quiet=!1;_resolvePromises=new Map;get hasRemoteProvider(){return this._remoteProviders.length>0}get localProvider(){return this._local}async init(t){if(this._initialized)return;this.getReadyPromise(),this._quiet=t?.quiet??!1;const e=this.instantiateProviders(t?.providers??[]);e.some((t=>"local"===t.type))||e.unshift(new _n),e.sort(((t,e)=>"local"===t.type&&"local"!==e.type?-1:"local"!==t.type&&"local"===e.type?1:0)),this._providers=e,this._local=e.find((t=>"local"===t.type&&"IndexedDBAssetProvider"===t.name))??null,this._remoteProviders=e.filter((t=>"remote"===t.type)),this._local&&await this._local.init();for(const t of this._remoteProviders)try{await t.init()}catch(e){console.warn(`[KritzelAssetResolver] Remote provider "${t.name}" failed to initialize. Assets will be served from the local provider until the remote becomes available.`,e)}await this.recoverPendingUploads(),this._initialized=!0,this._resolveReady&&(this._resolveReady(),this._resolveReady=null,this._rejectReady=null),this._quiet||this.logProviderConfiguration(),this._pending.size>0&&this.scheduleFlush(0)}destroy(){this._quiet||console.info("Asset resolver destroyed"),this._destroyed=!0,this._flushTimer&&(clearTimeout(this._flushTimer),this._flushTimer=null);for(const t of this._providers)try{t.destroy()}catch{}this._providers=[],this._local=null,this._remoteProviders=[],this._pending.clear(),this._resolvePromises.clear(),this._initialized=!1,this._rejectReady&&this._rejectReady(new Error("[KritzelAssetResolver] Destroyed before initialization completed.")),this._readyPromise=null,this._resolveReady=null,this._rejectReady=null}async put(t,e){await this.ensureReady();const i=e.id??this.generateUuid(),s={...e,id:i};let r=null;if(this._local&&(r=await this._local.put(t,s)),this._remoteProviders.length>0){const t=this._remoteProviders.map((t=>t.name));this._local&&await this._local.setPendingRemotes(i,t);for(const e of t)this._pending.set(this.pendingKey(i,e),{id:i,providerName:e,attempts:0,nextAttemptAt:Date.now()})}if(!r){if(0===this._remoteProviders.length)throw new Error("[KritzelAssetResolver] No providers configured to store asset.");r=await this._remoteProviders[0].put(t,s)}return this.scheduleFlush(0),r}async resolve(t){await this.ensureReady();const e=this._resolvePromises.get(t);if(e)return e;const i=(async()=>{if(this._local&&this._local.canResolve(t))return this._local.resolve(t);let e,i=0;for(const s of this._providers)if(s!==this._local){i++;try{const e=await s.fetch(t);if(this._local){try{await this._local.put(e,{id:t,mimeType:e.type||"application/octet-stream",kind:"file"})}catch{}return this._local.resolve(t)}return URL.createObjectURL(e)}catch(t){e=t}}if(0===i)throw new Ln(t);throw new Error(`[KritzelAssetResolver] Failed to resolve asset ${t}: ${String(e)}`)})();this._resolvePromises.set(t,i);try{return await i}finally{this._resolvePromises.delete(t)}}async fetchBlob(t){let e;await this.ensureReady();let i=!1,s=!1,r=0;const n=this._local?[this._local,...this._providers.filter((t=>t!==this._local))]:this._providers;for(const o of n){o===this._local?i=!0:r++;try{return await o.fetch(t)}catch(t){o===this._local&&(s=!0),e=t}}if(0===r&&(!i||s))throw new Ln(t);throw new Error(`[KritzelAssetResolver] Failed to fetch blob for ${t}: ${String(e)}`)}async putDataUrl(t,e){const i=await this.dataUrlToBlob(t);return this.put(i,{...e,mimeType:e.mimeType??i.type??"application/octet-stream"})}logProviderConfiguration(){const t=[`Asset resolver initialized with ${this._providers.length} provider(s):`];for(const e of this._providers)t.push(` - ${e.name} [${e===this._local?"local (primary write target)":e.type}]`);this._local&&t.push(`Write strategy: local-first (${this._local.name} → immediate, remote → background queue)`),this._remoteProviders.length>0&&t.push(`Remote replication: ${this._remoteProviders.map((t=>t.name)).join(", ")}`),this._pending.size>0&&t.push(`Pending uploads recovered: ${this._pending.size}`),console.info(t.join("\n"))}instantiateProviders(t){return t.map((t=>"function"==typeof t?new t:t.create()))}pendingKey(t,e){return`${t}::${e}`}async recoverPendingUploads(){if(!this._local||0===this._remoteProviders.length)return;const t=await this._local.listAssetsWithPendingRemotes(),e=new Set(this._remoteProviders.map((t=>t.name))),i=Date.now();let s=0;for(const r of t){const t=(r.pendingRemotes??[]).filter((t=>e.has(t)));if(0!==t.length)for(const e of t)this._pending.set(this.pendingKey(r.id,e),{id:r.id,providerName:e,attempts:0,nextAttemptAt:i}),s++;else await this._local.setPendingRemotes(r.id,[])}!this._quiet&&s>0&&console.info(`Asset resolver: recovered ${s} pending upload(s)`)}scheduleFlush(t){this._destroyed||(this._flushTimer&&clearTimeout(this._flushTimer),this._flushTimer=setTimeout((()=>{this._flushTimer=null,this.flushQueue()}),Math.max(0,t)))}async flushQueue(){if(this._destroyed)return;if(!this._local)return;const t=Date.now();let e=Number.POSITIVE_INFINITY;for(const[i,s]of Array.from(this._pending.entries())){if(s.nextAttemptAt>t){e=Math.min(e,s.nextAttemptAt-t);continue}const r=this._remoteProviders.find((t=>t.name===s.providerName));if(!r){this._pending.delete(i);continue}let n,o;try{[n,o]=await Promise.all([this._local.fetch(s.id),this._local.getMetadata(s.id)])}catch{this._pending.delete(i);continue}try{await r.put(n,{id:s.id,mimeType:o?.mimeType??n.type??"application/octet-stream",kind:o?.kind,width:o?.width,height:o?.height,durationMs:o?.durationMs,originalFilename:o?.originalFilename}),this._pending.delete(i),await this.clearPendingRemote(s.id,s.providerName),this._quiet||console.info(`Asset resolver: uploaded ${s.id} to ${r.name}`)}catch(t){s.attempts+=1;const i=Math.min(3e5,2e3*Math.pow(2,s.attempts-1));s.nextAttemptAt=Date.now()+i,e=Math.min(e,i),console.warn(`[KritzelAssetResolver] Upload to ${r.name} failed for ${s.id} (attempt ${s.attempts}). Retrying in ${Math.round(i/1e3)}s.`,t)}}this._pending.size>0&&Number.isFinite(e)&&this.scheduleFlush(e)}async clearPendingRemote(t,e){if(!this._local)return;const i=await this._local.getMetadata(t);if(!i)return;const s=(i.pendingRemotes??[]).filter((t=>t!==e));await this._local.setPendingRemotes(t,s)}ensureReady(){return this._initialized?Promise.resolve():this._destroyed?Promise.reject(new Error("[KritzelAssetResolver] Resolver was destroyed.")):this.getReadyPromise()}getReadyPromise(){return this._readyPromise||(this._readyPromise=new Promise(((t,e)=>{this._resolveReady=t,this._rejectReady=e}))),this._readyPromise}generateUuid(){if("undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID)return crypto.randomUUID();const t=crypto.getRandomValues(new Uint8Array(16));t[6]=15&t[6]|64,t[8]=63&t[8]|128;const e=Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}async dataUrlToBlob(t){return(await fetch(t)).blob()}}class Xn extends n{__class__="KritzelImage";assetId="";mimeType="";src="";maxWidth=300;maxHeight=300;maxCompressionSize=1200;isDebugInfoVisible=!0;resolvedSrc;loadState="idle";maxLoadAttempts=3;loadAttempts=0;maxTransientRetryDurationMs=3e4;transientRetryStartedAt=null;constructor(t){super(),this.assetId=t?.assetId||"",this.mimeType=t?.mimeType||"",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,this.maxLoadAttempts=t?.maxLoadAttempts??3}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.x=0,e.y=0,e.translateX=0,e.translateY=0,e.scale=e._core.store.state.scale,e.zIndex=t.store.currentZIndex,e}resize(t,e,i,s){if(i<=1||s<=1)return;const r=s/this.height;this.width=this.width*r,this.height=this.height*r,this.translateX=t,this.translateY=e,this._core.store.objects.update(this)}serialize(){const t=super.serialize();return delete t.resolvedSrc,delete t.loadState,delete t.loadAttempts,delete t.transientRetryStartedAt,t}adoptTransientStateFrom(t){t instanceof Xn&&t.assetId===this.assetId&&(this.resolvedSrc=t.resolvedSrc,this.loadState=t.loadState,this.loadAttempts=t.loadAttempts,this.transientRetryStartedAt=t.transientRetryStartedAt)}ensureResolved(){if("loading"===this.loadState||"ready"===this.loadState)return;if("error"===this.loadState)return;if(!this.assetId)return;if(!this._core?.assetResolver)return;if(this.loadAttempts>=this.maxLoadAttempts)return void(this.loadState="error");this.loadState="loading";const t=this.loadAttempts;this._core.assetResolver.resolve(this.assetId).then((t=>{this.resolvedSrc=t,this.loadState="ready",this.transientRetryStartedAt=null,this._core?.rerender()})).catch((e=>{if(e instanceof Ln){this.loadAttempts+=1,this.transientRetryStartedAt=null;const t=this.loadAttempts>=this.maxLoadAttempts;return console.warn(`[KritzelImage] Asset ${this.assetId} not found (attempt ${this.loadAttempts}/${this.maxLoadAttempts}):`,e),t?(this.loadState="error",void this._core?.rerender()):void this.scheduleRetry(this.loadAttempts)}const i=Date.now();null===this.transientRetryStartedAt&&(this.transientRetryStartedAt=i);const s=i-this.transientRetryStartedAt,r=s>=this.maxTransientRetryDurationMs;if(console.warn(`[KritzelImage] Transient resolve failure for asset ${this.assetId} (elapsed ${Math.round(s/1e3)}s/${Math.round(this.maxTransientRetryDurationMs/1e3)}s):`,e),r)return this.loadState="error",void this._core?.rerender();this.scheduleRetry(t+1)}))}scheduleRetry(t){this.loadState="idle";const e=Math.min(2e3,250*Math.pow(2,Math.max(0,t-1)));setTimeout((()=>{"idle"===this.loadState&&this.ensureResolved()}),e)}migrateLegacyDataUrlIfNeeded(){if(this.assetId)return;if(!this.src||!this.src.startsWith("data:"))return;if(!this._core?.assetResolver)return;const t=this.src;this.resolvedSrc=t,this.loadState="ready",this._core.assetResolver.putDataUrl(t,{kind:"image"}).then((t=>{this.assetId=t.id,this.mimeType=t.mimeType,this.src="",this._core?.store.objects?.update(this)})).catch((t=>{console.warn("[KritzelImage] Failed to migrate legacy data URL to asset storage:",t)}))}ensureLoaded(){this.assetId&&!this.resolvedSrc?this.ensureResolved():!this.assetId&&this.src?.startsWith("data:")&&this.migrateLegacyDataUrlIfNeeded()}mount(t){super.mount(t),this.ensureLoaded()}static fromUrl(t,e){return new Promise(((i,s)=>{const r=new Image;r.onload=()=>{const s=new Xn({...e,src:t}),{scaledWidth:n,scaledHeight:o}=s.calculateScaledDimensions(r);s.width=n,s.height=o,i(s)},r.onerror=t=>s(t),r.src=t}))}calculateScaledDimensions(t){let e=t.width,i=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const s=Math.min(this.maxWidth/t.width,this.maxHeight/t.height);e=t.width*s,i=t.height*s}return{scaledWidth:e,scaledHeight:i}}}class Yn 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 Yn;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,s){if(i<=1||s<=1)return;const r=i/this.width,n=s/this.height;this.startX=this.startX*r,this.startY=this.startY*n,this.endX=this.endX*r,this.endY=this.endY*n,void 0!==this.controlX&&void 0!==this.controlY&&(this.controlX=this.controlX*r,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.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.objects.update(this)}move(t,e,i,s){const r=(e-s)/this._core.store.state.scale;this.translateX+=(t-i)/this._core.store.state.scale,this.translateY+=r,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.objects.update(this)}hitTest(t,e){const i=Math.max(this.strokeWidth,20)/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),void 0!==this.controlX&&void 0!==this.controlY){const s=this.getClipInfo();return this.pointToBezierDistance(t,e,s.start?.t??0,s.end?.t??1)<=i}const s=this.getClipInfo(),r=s.start?[s.start.x,s.start.y]:this._adjustedPoints[0],n=s.end?[s.end.x,s.end.y]:this._adjustedPoints[1];return this.pointToLineSegmentDistance(t,e,r[0],r[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(),s=[{x:t.bottomLeft.x,y:t.bottomLeft.y},{x:t.bottomRight.x,y:t.bottomRight.y},{x:t.topRight.x,y:t.topRight.y},{x:t.topLeft.x,y:t.topLeft.y}],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(r.isPointInPolygon({x:t,y:e},s))return!0;for(const t of s)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(r.isPointInPolygon({x:f,y:d},s))return!0;for(let t=0;t<s.length;t++){const i=s[t],r=s[(t+1)%s.length];if(this.pointToLineSegmentDistance(f,d,i.x,i.y,r.x,r.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<s.length;t++){const i=s[t],n=s[(t+1)%s.length];if(r.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.objects.update(this)}updateEndpoint(t,e,i){"start"===t?(this.startX=e,this.startY=i):(this.endX=e,this.endY=i);const s=this.width,r=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-s)/2,p=(f-r)/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.objects.update(this)}updateControlPoint(t,e){this.controlX=t,this.controlY=e;const i=this.width,s=this.height,{minX:r,minY:n,maxX:o,maxY:h}=this.calculateBoundingBox(),l=r-this.x,a=n-this.y,u=o-r,c=h-n,f=(u-i)/2,d=(c-s)/2;this.x=r,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.objects.update(this)}computeAdjustedPoints(){const t=[[this.startX,this.startY],[this.endX,this.endY]],e=this.rotation,i=Math.cos(e),s=Math.sin(e),r=t.map((t=>t[0])),n=t.map((t=>t[1])),o={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...n)+Math.max(...n))/2},{x:h,y:l}=o;return t.map((([t,e])=>{const r=t-h,n=e-l;return[h+r*i-n*s,l+r*s+n*i]})).map((([t,e])=>[(t-this.x)/this.scale+this.translateX,(e-this.y)/this.scale+this.translateY]))}pointToLineSegmentDistance(t,e,i,s,r,n){const o=r-i,h=n-s,l=o*o+h*h;let a,u,c=-1;0!==l&&(c=((t-i)*o+(e-s)*h)/l),c<0?(a=i,u=s):c>1?(a=r,u=n):(a=i+c*o,u=s+c*h);const f=t-a,d=e-u;return Math.sqrt(f*f+d*d)}pointToBezierDistance(t,e,i=0,s=1){null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const r=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*(s-i),u=1-a,c=t-(u*u*r[0]+2*u*a*o[0]+a*a*n[0]),f=e-(u*u*r[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),s=[this.startX,this.endX],r=[this.startY,this.endY],n={x:(Math.min(...s)+Math.max(...s))/2,y:(Math.min(...r)+Math.max(...r))/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:s,maxY:r}=Yn.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=s-this.x+t,l=r-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,s,r,n,o){let h=Math.min(t,i),l=Math.min(e,s),a=Math.max(t,i),u=Math.max(e,s);if(void 0!==r&&void 0!==n){const o=t-2*r+i;if(0!==o){const e=(t-r)/o;if(e>0&&e<1){const s=(1-e)*(1-e)*t+2*(1-e)*e*r+e*e*i;h=Math.min(h,s),a=Math.max(a,s)}}const c=e-2*n+s;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*s;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 Yn.calculateBoundingBox(this.startX,this.startY,this.endX,this.endY,this.controlX,this.controlY,this.strokeWidth)}updateDimensions(){const{minX:t,minY:e,maxX:i,maxY:s}=this.calculateBoundingBox();this.width=i-t,this.height=s-e,this.x=t,this.y=e,this.translateX=(this.x+this.translateX)/this.scale,this.translateY=(this.y+this.translateY)/this.scale}get startMarkerId(){return`arrow-start-${this.id}`}get endMarkerId(){return`arrow-end-${this.id}`}getArrowSize(t){const e="start"===t?this.arrows?.start:this.arrows?.end;return e?.size??3*this.strokeWidth}getArrowFill(t){const e="start"===t?this.arrows?.start:this.arrows?.end;return $n.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 Wn{static isInstanceOf(t,e){return!!t&&t.__class__===e}}class Vn 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.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 Vn;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=Vn.create(t);return e.forEach((t=>{i.childIds.push(t.id)})),i.refreshBoundingBox(),i.captureChildSnapshots(),i}static findParentGroup(t,e){const i=t.store.objects.filter((t=>"KritzelGroup"===t.__class__));for(const t of i)if(t.childIds.includes(e))return t;return null}static collectDescendantIds(t,e=new Set){for(const i of t.children)e.add(i.id),i instanceof Vn&&Vn.collectDescendantIds(i,e);return e}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(){for(const t of this.children)t instanceof Vn&&t.finalize();this.refreshBoundingBox(),this.captureChildSnapshots()}centerInViewport(){const{viewportWidth:t,viewportHeight:e,translateX:i,translateY:s,scale:r}=this._core.store.state,{x:n,y:o,width:h,height:l}=this.rotatedBoundingBox,a=(t/2-i)/r-(n+h/2),u=(e/2-s)/r-(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 s=1/0,r=-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<s&&(s=h),h>r&&(r=h),l<n&&(n=l),l>o&&(o=l)}))}));const h=o-n;this.width=(r-s-this.padding)*this.scale,this.height=(h-this.padding)*this.scale;const l=(s+r)/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,s){const r=(t-i)/this._core.store.state.scale,n=(e-s)/this._core.store.state.scale;this.translateX+=r,this.translateY+=n,this._core.store.objects.transaction((()=>{this._core.store.objects.update(this),this.children.forEach((r=>{r.move(t,e,i,s),this._core.anchorManager.updateAnchorsForObject(r.id)}))})),this.unchangedChildSnapshots.forEach((t=>{t.translateX+=r,t.translateY+=n}))}resize(t,e,i,s){const r=this.snapshotTotalWidth>0?this.snapshotTotalWidth-2*this.padding:this.width,n=this.snapshotTotalHeight>0?this.snapshotTotalHeight-2*this.padding:this.height,o=this.snapshotScale||this.scale||1,h=0!==r?i/r:1,l=0!==n?s/n:1,a=this.snapshotTranslateX+(this.snapshotTotalWidth||this.width+2*this.padding)/2/o,u=this.snapshotTranslateY+(this.snapshotTotalHeight||this.height+2*this.padding)/2/o,c=t+(i+2*this.padding)/2/this.scale,f=e+(s+2*this.padding)/2/this.scale,d=this.rotation,p=Math.cos(-d),g=Math.sin(-d),w=Math.cos(d),m=Math.sin(d);this._core.store.objects.transaction((()=>{this.children.forEach((t=>{const e=this.unchangedChildSnapshots.get(t.id),i=e?e.width:t.width,s=e?e.height:t.height,r=(e?e.scale:t.scale)||1,n=(e?e.translateX:t.translateX)+(e?e.totalWidth:t.totalWidth)/2/r-a,o=(e?e.translateY:t.translateY)+(e?e.totalHeight:t.totalHeight)/2/r-u,v=(n*p-o*g)*h,y=(n*g+o*p)*l,k=c+(v*w-y*m),b=f+(v*m+y*w),M=(e?e.rotation:t.rotation)-d,x=Math.cos(M),C=Math.sin(M),A=i*Math.sqrt(Math.pow(h*x,2)+Math.pow(l*C,2)),S=s*Math.sqrt(Math.pow(h*C,2)+Math.pow(l*x,2));t.resize(k-(A+2*t.padding)/2/t.scale,b-(S+2*t.padding)/2/t.scale,A,S),this._core.anchorManager.updateAnchorsForObject(t.id)})),this.refreshBoundingBox(),this._core.store.state.isResizing||this.captureChildSnapshots(),this._core.store.objects.update(this)}))}rotate(t){this.rotation=t;const e=this.translateX+this.totalWidth/2/this.scale,i=this.translateY+this.totalHeight/2/this.scale,s=t-this.snapshotRotation,r=Math.cos(s),n=Math.sin(s);this._core.store.objects.transaction((()=>{this._core.store.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+r*a;o.translateX=e+(r*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+s)}))}))}getOffsetXToCenterFromSnapshot(t){return t.translateX+t.totalWidth/t.scale/2-(this.snapshotTranslateX+this.snapshotTotalWidth/(this.snapshotScale||this.scale||1)/2)}getOffsetYToCenterFromSnapshot(t){return t.translateY+t.totalHeight/t.scale/2-(this.snapshotTranslateY+this.snapshotTotalHeight/(this.snapshotScale||this.scale||1)/2)}hitTest(t,e){return this.children.some((i=>i.hitTest(t,e)))}hitTestPolygon(t){return this.children.some((e=>e.hitTestPolygon(t)))}copy(){const t=Vn.create(this._core),e=[];return this.children.sort(((t,e)=>t.zIndex-e.zIndex)).forEach((i=>{const s=i.copy();e.push(s),t.childIds.push(s.id)})),t._pendingChildren=e,t.rotation=this.rotation,t.translateX=this.translateX,t.translateY=this.translateY,t.width=this.width,t.height=this.height,t}serialize(){const{_core:t,_elementRef:e,element:i,totalWidth:s,totalHeight:r,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.objects.update(this)}updateWorkspaceId(t){this.workspaceId=t,this.children.forEach((e=>{e.workspaceId=t,Wn.isInstanceOf(e,"KritzelGroup")&&e.updateWorkspaceId(t)}))}}var Kn,Jn;!function(t){t.Rectangle="rectangle",t.Ellipse="ellipse",t.Triangle="triangle"}(Kn||(Kn={}));class Qn extends n{__class__="KritzelShape";shapeType=Kn.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:Qr(Lr.spec.nodes,"paragraph block*","block"),marks:Lr.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??Kn.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??$n.determineTextColor(this.fillColor),this.scale=t.scale??1,this.scaleFactor=t.scaleX??1)}static create(t,e){const i=new Qn;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??Kn.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??$n.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=$n.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 Tr(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.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const e=this.editor.state.schema.nodeFromJSON(t),i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",!0),this.editor.dispatch(i)}}resize(t,e,i,s){i<=1||s<=1||(this.width=i,this.height=s,this.translateX=t,this.translateY=e,this._core.store.objects.update(this))}focus(t){if(!this.editor)return;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(),t?.clientX&&t?.clientY&&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.objects.consolidateTemporaryItems(),this._core.store.objects.update(this),this._core.engine.emitObjectsChange()}handleEscape(){if(!this.editor||!this.isEditing)return;const{state:t}=this.editor;if(!t.selection.empty)return this.editor.dispatch(t.tr.setSelection(ne.create(t.doc,t.selection.head))),void this.editor.focus();this._core.resetActiveShape(),this._core.clearSelection(),this._core.store.setState("activeTool",i.getTool("selection"))}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:s,totalWidth:r,totalHeight:n,editor:o,uneditedObject:h,...l}=this,a=structuredClone(l);return s&&"object"==typeof s&&"nodeType"in s&&1===s.nodeType&&(a.element=s.cloneNode(!0)),a}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}onAfterUpdate(t){t.includes("fillColor")?(this.fontColor=$n.determineTextColor(this.fillColor),this.editor?.dom?.parentElement&&(this.editor.dom.parentElement.style.color=$n.resolveThemeColor(this.fontColor))):t.includes("fontColor")&&this.editor?.dom?.parentElement&&(this.editor.dom.parentElement.style.color=$n.resolveThemeColor(this.fontColor))}getClipPolygon(){const t=this.totalWidth/this.scale,e=this.totalHeight/this.scale,i=this.translateX+t/2,s=this.translateY+e/2,n=this.strokeWidth/this.scale/2;switch(this.shapeType){case Kn.Ellipse:return r.getEllipsePolygonApproximation(i,s,t/2+n,e/2+n,32,this.rotation);case Kn.Triangle:const o=(t,e)=>{const r=t-i,o=e-s,h=Math.sqrt(r*r+o*o);if(0===h)return{x:t,y:e};const l=(h+n)/h;return{x:i+r*l,y:s+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),r=r=>{const n=r.x-i,o=r.y-s;return{x:i+n*t-o*e,y:s+n*e+o*t}};return[r(c),r(f),r(d)]}return[c,f,d];default:return null}}getSvgPath(){const t=this.width,e=this.height;switch(this.shapeType){case Kn.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 Kn.Ellipse:const i=this.x+t/2,s=this.y+e/2,r=t/2,n=e/2;return`M ${i-r} ${s} A ${r} ${n} 0 1 0 ${i+r} ${s} A ${r} ${n} 0 1 0 ${i-r} ${s}`;case Kn.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 qn{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 s=t.clientX,r=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-s)>10||Math.abs(t.clientY-r)>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 Gn{__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 Zn extends Gn{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&&qn.isLeftClick(t)){this._core.store.state.isDrawing=!0;const e=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,s=i?e:1,r=Un.create(this._core,{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:i?1:e,fill:this.color,strokeWidth:this.size,opacity:this.opacity});r.isCompleted=!1,this._currentPathId=r.id,this._core.store.objects.insert(r),this._core.store.objects?.setActiveDrawingObject(r.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,s=i?e:1,r=Math.round((t[0].clientX-this._core.store.offsetX)/s),n=Math.round((t[0].clientY-this._core.store.offsetY)/s);this._core.store.state.isDrawing=!0;const o=Un.create(this._core,{points:[[r,n]],translateX:-this._core.store.state.translateX/s,translateY:-this._core.store.state.translateY/s,scale:i?1:e,fill:this.color,strokeWidth:this.size,opacity:this.opacity});o.isCompleted=!1,this._currentPathId=o.id,this._core.store.objects.insert(o),this._core.store.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.objects.findById(this._currentPathId);if(e){const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1,n=Un.create(this._core,{points:[...e.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:s?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.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.objects.findById(this._currentPathId);if(e){const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1,n=Math.round((t[0].clientX-this._core.store.offsetX)/r),o=Math.round((t[0].clientY-this._core.store.offsetY)/r),h=Un.create(this._core,{points:[...e.points,[n,o]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:s?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.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.objects.findById(this._currentPathId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])),this._core.store.objects?.setActiveDrawingObject(null),this._currentPathId=null,this._core.store.objects?.stopUndoCapturing()}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.objects.findById(this._currentPathId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])),this._core.store.objects?.setActiveDrawingObject(null),this._currentPathId=null,this._core.store.objects?.stopUndoCapturing()}}}class to extends n{__class__="KritzelSelectionGroup";_objectIds=[];_cachedObjects=null;_cachedObjectIdsHash="";unchangedObjectSnapshots=new Map;snapshotRotation=0;snapshotWidth=0;snapshotHeight=0;snapshotTranslateX=0;snapshotTranslateY=0;clientId;minX=0;maxX=0;minY=0;maxY=0;handleColor;handleStrokeColor;handleSize=6;_lastChildPersistTime=0;static CHILD_PERSIST_THROTTLE_MS=100;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.objects.filter((t=>e.has(t.id))),s=new Map(i.map((t=>[t.id,t])));return this._cachedObjects=this._objectIds.map((t=>s.get(t))).filter((t=>void 0!==t)),this._cachedObjectIdsHash=t,this._cachedObjects}get length(){return this.objectIds.length}static create(t){const e=new to;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.clientId=t.store.objects?.localClientId??void 0,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)Wn.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 s of i)s.updatePosition(t+(s.translateX-this.translateX),e+(s.translateY-this.translateY));this.unchangedObjectSnapshots.forEach((i=>{const s=i.translateY-this.translateY;i.translateX=t+(i.translateX-this.translateX),i.translateY=e+s})),this.translateX=t,this.translateY=e,this._core.store.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:s,totalHeight:r,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.objects.update(this)}move(t,e,i,s){const r=(t-i)/this._core.store.state.scale,n=(e-s)/this._core.store.state.scale;this.translateX+=r,this.translateY+=n;const o=Date.now();o-this._lastChildPersistTime>=to.CHILD_PERSIST_THROTTLE_MS?(this._core.store.objects.transaction((()=>{this._core.store.objects.update(this);const r=this.objects;for(const n of r)n.move(t,e,i,s),this._core.anchorManager.updateAnchorsForObject(n.id)})),this._lastChildPersistTime=o):(this._core.store.objects.update(this),this._core.store.objects.withLocalUpdatesOnly((()=>{const r=this.objects;for(const n of r)n.move(t,e,i,s),this._core.anchorManager.updateAnchorsForObject(n.id)}))),this.unchangedObjectSnapshots.forEach((t=>{t.translateX+=r,t.translateY+=n}))}persistChildren(){this._core.store.objects.transaction((()=>{const t=this.objects;for(const e of t)this._core.store.objects.update(e)}))}resize(t,e,i,s){const r=i/this.snapshotWidth,n=s/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+(s+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.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,s=e.translateY+e.totalHeight/2/e.scale-h,g=(i*c-s*f)*r,w=(i*f+s*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(r*k,2)+Math.pow(n*b,2)),x=Math.sqrt(Math.pow(r*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.objects.update(this)}))}rotate(t){this.rotation=t;const e=this.translateX+this.totalWidth/2/this.scale,i=this.translateY+this.totalHeight/2/this.scale,s=t-this.snapshotRotation,r=Math.cos(s),n=Math.sin(s),o=this.objects;this._core.store.objects.transaction((()=>{this._core.store.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+r*u;l.translateX=e+(r*a-n*u)-l.totalWidth/2/l.scale,l.translateY=i+c-l.totalHeight/2/l.scale,l.rotate(1===h?t:o.rotation+s)}}))}copy(){const t=to.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),s=Math.sin(-t);let r=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*s,l=t.x*s+t.y*e;i<r&&(r=i),i>n&&(n=i),l<o&&(o=l),l>h&&(h=l)}))}));const l=h-o;this.width=(n-r-this.padding)*this.scale,this.height=(l-this.padding)*this.scale;const a=(r+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.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 s=this.rotatedPolygon;if(r.isPointInPolygon({x:t,y:e},[s.topLeft,s.topRight,s.bottomRight,s.bottomLeft]))return!0;for(const s of i)if(s.hitTest(t,e))return!0;return!1}}class eo extends Gn{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&&qn.isLeftClick(t)){this._core.store.state.isDrawing=!0;const e=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,s=i?e:1,r=(t.clientX-this._core.store.offsetX)/s,n=(t.clientY-this._core.store.offsetY)/s;this._startX=r,this._startY=n;const o=Yn.create(this._core,{startX:r,startY:n,endX:r,endY:n,translateX:-this._core.store.state.translateX/s,translateY:-this._core.store.state.translateY/s,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.objects.insert(o),this._core.store.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,s=i?e:1,r=Math.round((t[0].clientX-this._core.store.offsetX)/s),n=Math.round((t[0].clientY-this._core.store.offsetY)/s);this._core.store.state.isDrawing=!0,this._startX=r,this._startY=n;const o=Yn.create(this._core,{startX:r,startY:n,endX:r,endY:n,translateX:-this._core.store.state.translateX/s,translateY:-this._core.store.state.translateY/s,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.objects.insert(o),this._core.store.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.objects.findById(this._currentLineId);if(e){const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1,n=Yn.create(this._core,{startX:this._startX,startY:this._startY,endX:(t.clientX-this._core.store.offsetX)/r,endY:(t.clientY-this._core.store.offsetY)/r,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:s?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.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.objects.findById(this._currentLineId);if(e){const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1,n=Math.round((t[0].clientX-this._core.store.offsetX)/r),o=Math.round((t[0].clientY-this._core.store.offsetY)/r),h=Yn.create(this._core,{startX:this._startX,startY:this._startY,endX:n,endY:o,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:s?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.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.objects.findById(this._currentLineId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t]),this.selectLineAndSwitchTool(t)),this._core.store.objects?.setActiveDrawingObject(null),this._currentLineId=null,this._core.store.objects?.stopUndoCapturing()}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.objects.findById(this._currentLineId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t]),this.selectLineAndSwitchTool(t)),this._core.store.objects?.setActiveDrawingObject(null),this._currentLineId=null,this._core.store.objects?.stopUndoCapturing()}}selectLineAndSwitchTool(t){const e=to.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 io extends Gn{touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&qn.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,s=this._core.store.state.pointerY;e.forEach((t=>{t.markedForRemoval=t.hitTest(i,s)})),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 s=this._core.store.state.pointerX,r=this._core.store.state.pointerY;i.forEach((t=>{t.markedForRemoval=t.hitTest(s,r)})),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.length>0&&(this._core.store.objects.stopUndoCapturing(),this._core.store.objects.transaction((()=>{t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)}))})),this._core.rerender()),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange(),t.length>0&&(this._core.engine.emitObjectsRemoved(t),this._core.store.objects.stopUndoCapturing())}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.length>0&&(this._core.store.objects.stopUndoCapturing(),this._core.store.objects.transaction((()=>{t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)}))})),this._core.rerender()),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange(),t.length>0&&(this._core.engine.emitObjectsRemoved(t),this._core.store.objects.stopUndoCapturing())}}}function so(t,e){return new Promise((function(i,s){let r;return ro(t).then((function(t){try{return r=t,i(new Blob([e.slice(0,2),r,e.slice(2)],{type:"image/jpeg"}))}catch(t){return s(t)}}),s)}))}const ro=t=>new Promise(((e,i)=>{const s=new FileReader;s.addEventListener("load",(({target:{result:t}})=>{const s=new DataView(t);let r=0;if(65496!==s.getUint16(r))return i("not a valid JPEG");for(r+=2;;){const n=s.getUint16(r);if(65498===n)break;const o=s.getUint16(r+2);if(65505===n&&1165519206===s.getUint32(r+4)){const n=r+10;let h;switch(s.getUint16(n)){case 18761:h=!0;break;case 19789:h=!1;break;default:return i("TIFF header contains invalid endian")}if(42!==s.getUint16(n+2,h))return i("TIFF header contains invalid version");const l=s.getUint32(n+4,h),a=n+l+2+12*s.getUint16(n+l,h);for(let t=n+l+2;t<a;t+=12)if(274==s.getUint16(t,h)){if(3!==s.getUint16(t+2,h))return i("Orientation data type is invalid");if(1!==s.getUint32(t+4,h))return i("Orientation data count is invalid");s.setUint16(t+8,1,h);break}return e(t.slice(r,r+2+o))}r+=2+o}return e(new Blob)})),s.readAsArrayBuffer(t)}));var no={},oo={get exports(){return no},set exports(t){no=t}};!function(){var t,e,i={};oo.exports=i,i.parse=function(t,e){for(var s=i.bin.readUshort,r=i.bin.readUint,n=0,o={},h=new Uint8Array(t),l=h.length-4;101010256!=r(h,l);)l--;n=l,n+=4;var a=s(h,n+=4);s(h,n+=2);var u=r(h,n+=2),c=r(h,n+=4);n+=4,n=c;for(var f=0;f<a;f++){r(h,n),n+=4,n+=4,n+=4,r(h,n+=4),u=r(h,n+=4);var d=r(h,n+=4),p=s(h,n+=4),g=s(h,n+2),w=s(h,n+4);n+=6;var m=r(h,n+=8);n+=4,n+=p+g+w,i._readLocal(h,m,o,u,d,e)}return o},i._readLocal=function(t,e,s,r,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)s[f]={size:n,csize:r};else{var d=new Uint8Array(t.buffer,e);if(0==a)s[f]=new Uint8Array(d.buffer.slice(e,e+r));else{if(8!=a)throw"unknown compression method: "+a;var p=new Uint8Array(n);i.inflateRaw(d,p),s[f]=p}}},i.inflateRaw=function(t,e){return i.F.inflate(t,e)},i.inflate=function(t,e){return i.inflateRaw(new Uint8Array(t.buffer,t.byteOffset+2,t.length-6),e)},i.deflate=function(t,e){null==e&&(e={level:6});var s=0,r=new Uint8Array(50+Math.floor(1.1*t.length));r[s]=120,r[s+1]=156,s=i.F.deflateRaw(t,r,s+=2,e.level);var n=i.adler(t,0,t.length);return r[s+0]=n>>>24&255,r[s+1]=n>>>16&255,r[s+2]=n>>>8&255,r[s+3]=n>>>0&255,new Uint8Array(r.buffer,0,s+4)},i.deflateRaw=function(t,e){null==e&&(e={level:6});var s=new Uint8Array(50+Math.floor(1.1*t.length)),r=i.F.deflateRaw(t,s,r,e.level);return new Uint8Array(s.buffer,0,r)},i.encode=function(t,e){null==e&&(e=!1);var s=0,r=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)s+=o[h].file.length+30+46+2*i.bin.sizeUTF8(h);s+=22;var c=new Uint8Array(s),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 r(c,f,101010256),f+=4,n(c,f+=4,g),n(c,f+=2,g),r(c,f+=2,m),r(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,s,r,n,o){var h=i.bin.writeUint,l=i.bin.writeUshort,a=r.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,r.cpr?8:0),h(t,e+=2,0),h(t,e+=4,r.crc),h(t,e+=4,a.length),h(t,e+=4,r.usize),l(t,e+=4,i.bin.sizeUTF8(s)),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,s),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,s=0;s<8;s++)1&i?i=3988292384^i>>>1:i>>>=1;t[e]=i}return t}(),update:function(t,e,s,r){for(var n=0;n<r;n++)t=i.crc.table[255&(t^e[s+n])]^t>>>8;return t},crc:function(t,e,s){return 4294967295^i.crc.update(4294967295,t,e,s)}},i.adler=function(t,e,i){for(var s=1,r=0,n=e,o=e+i;n<o;){for(var h=Math.min(n+5552,o);n<h;)r+=s+=t[n++];s%=65521,r%=65521}return r<<16|s},i.bin={readUshort:function(t,e){return t[e]|t[e+1]<<8},writeUshort:function(t,e,i){t[e]=255&i,t[e+1]=i>>8&255},readUint:function(t,e){return 16777216*t[e+3]+(t[e+2]<<16|t[e+1]<<8|t[e])},writeUint:function(t,e,i){t[e]=255&i,t[e+1]=i>>8&255,t[e+2]=i>>16&255,t[e+3]=i>>24&255},readASCII:function(t,e,i){for(var s="",r=0;r<i;r++)s+=String.fromCharCode(t[e+r]);return s},writeASCII:function(t,e,i){for(var s=0;s<i.length;s++)t[e+s]=i.charCodeAt(s)},pad:function(t){return t.length<2?"0"+t:t},readUTF8:function(t,e,s){for(var r,n="",o=0;o<s;o++)n+="%"+i.bin.pad(t[e+o].toString(16));try{r=decodeURIComponent(n)}catch(r){return i.bin.readASCII(t,e,s)}return r},writeUTF8:function(t,e,i){for(var s=i.length,r=0,n=0;n<s;n++){var o=i.charCodeAt(n);if(4294967168&o)if(4294965248&o)if(4294901760&o){if(4292870144&o)throw"e";t[e+r]=240|o>>18,t[e+r+1]=128|o>>12&63,t[e+r+2]=128|o>>6&63,t[e+r+3]=128|63&o,r+=4}else t[e+r]=224|o>>12,t[e+r+1]=128|o>>6&63,t[e+r+2]=128|63&o,r+=3;else t[e+r]=192|o>>6,t[e+r+1]=128|63&o,r+=2;else t[e+r]=o,r++}return r},sizeUTF8:function(t){for(var e=t.length,i=0,s=0;s<e;s++){var r=t.charCodeAt(s);if(4294967168&r)if(4294965248&r)if(4294901760&r){if(4292870144&r)throw"e";i+=4}else i+=3;else i+=2;else i++}return i}},i.F={},i.F.deflateRaw=function(t,e,s,r){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]][r],o=i.F.U,h=i.F._goodIndex,l=i.F._putsE,a=0,u=s<<3,c=0,f=t.length;if(0==r){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,s,r,n,o){var h=32767&e,l=s[h],a=h-l+32768&32767;if(l==h||r!=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-s[w]+32768&32767;m>p&&(p=m,l=w)}}}a+=(h=l)-(l=s[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 s=e,r=Math.min(t.length,e+258);for(e+=3;e<r&&t[e]==t[e-i];)e++;return e-s},i.F._hash=function(t,e){return(t[e]<<8|t[e+1])+(t[e+2]<<4)&65535},i.saved=0,i.F._writeBlock=function(t,e,s,r,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=r+i.F.contSize(y.fltree,y.lhst)+i.F.contSize(y.fdtree,y.dhst),C=r+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<s;I+=2){for(var $=e[I],P=$>>>23,D=E+(8388607&$);E<D;)a=i.F._writeLit(n[E++],B,l,a);if(0!=P){var R=e[I+1],j=R>>16,F=R>>8&255,U=255&R;b(l,a=i.F._writeLit(257+F,B,l,a),P-y.of0[F]),k(l,a=i.F._writeLit(U,T,l,a+=y.exb[F]),j-y.df0[U]),a+=y.dxb[U],E+=P}}a=i.F._writeLit(256,B,l,a)}return a},i.F._copyExact=function(t,e,i,s,r){var n=r>>>3;return s[n]=i,s[n+1]=i>>>8,s[n+2]=255-s[n],s[n+3]=255-s[n+1],n+=4,s.set(new Uint8Array(t.buffer,e,i),n),r+(i+4<<3)},i.F.getTrees=function(){for(var t=i.F.U,e=i.F._hufTree(t.lhst,t.ltree,15),s=i.F._hufTree(t.dhst,t.dtree,15),r=[],n=i.F._lenCodes(t.ltree,r),o=[],h=i.F._lenCodes(t.dtree,o),l=0;l<r.length;l+=2)t.ihst[r[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,s,a,n,h,u,r,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,s=0;s<e.length;s++)i+=e[s]*t[1+(s<<1)];return i},i.F._codeTiny=function(t,e,s,r){for(var n=0;n<t.length;n+=2){var o=t[n],h=t[n+1];r=i.F._writeLit(o,e,s,r);var l=16==o?2:17==o?3:7;o>15&&(i.F._putsE(s,r,h,l),r+=l)}return r},i.F._lenCodes=function(t,e){for(var i=t.length;2!=i&&0==t[i-1];)i-=2;for(var s=0;s<i;s+=2){var r=t[s+1],n=s+3<i?t[s+3]:-1,o=s+5<i?t[s+5]:-1,h=0==s?-1:t[s-1];if(0==r&&n==r&&o==r){for(var l=s+5;l+2<i&&t[l+2]==r;)l+=2;(a=Math.min(l+1-s>>>1,138))<11?e.push(17,a-3):e.push(18,a-11),s+=2*a-2}else if(r==h&&n==r&&o==r){for(l=s+5;l+2<i&&t[l+2]==r;)l+=2;var a=Math.min(l+1-s>>>1,6);e.push(16,a-3),s+=2*a-2}else e.push(r,0)}return i>>>1},i.F._hufTree=function(t,e,s){var r=[],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]&&r.push({lit:h,f:t[h]});var l=r.length,a=r.slice(0);if(0==l)return 0;if(1==l){var u=r[0].lit;return a=0==u?1:0,e[1+(u<<1)]=1,e[1+(a<<1)]=1,1}r.sort((function(t,e){return t.f-e.f}));var c=r[0],f=r[1],d=0,p=1,g=2;for(r[0]={lit:-1,f:c.f+f.f,l:c,r:f,d:0};p!=l-1;)c=d!=p&&(g==l||r[d].f<r[g].f)?r[d++]:r[g++],f=d!=p&&(g==l||r[d].f<r[g].f)?r[d++]:r[g++],r[p++]={lit:-1,f:c.f+f.f,l:c,r:f};var w=i.F.setDepth(r[p-1],0);for(w>s&&(i.F.restrictDepth(a,s,w),w=s),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 s=0,r=1<<i-e,n=0;for(t.sort((function(t,e){return e.d==t.d?t.f-e.f:e.d-t.d})),s=0;s<t.length&&t[s].d>e;s++){var o=t[s].d;t[s].d=e,n+=r-(1<<i-o)}for(n>>>=i-e;n>0;)(o=t[s].d)<e?(t[s].d++,n-=1<<e-o-1):s++;for(;s>=0;s--)t[s].d==e&&n<0&&(t[s].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,s,r){return i.F._putsF(s,r,e[t<<1]),r+e[1+(t<<1)]},i.F.inflate=function(t,e){var s=Uint8Array;if(3==t[0]&&0==t[1])return e||new s(0);var r=i.F,n=r._bitsF,o=r._bitsE,h=r._decodeTiny,l=r.makeCodes,a=r.codes2map,u=r._get17,c=r.U,f=null==e;f&&(e=new s(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=r._copyOut(c.ttree,0,m,c.ltree);k=(1<<B)-1;var T=r._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 $=c.ldef[E-257];I=M+($>>>3)+o(t,x,7&$),x+=7&$}var P=p[u(t,x)&b],D=c.ddef[P>>>4],R=(D>>>4)+n(t,x+=15&P,15&D);for(x+=15&D,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 s(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 s=new Uint8Array(Math.max(i<<1,e));return s.set(t,0),s},i.F._decodeTiny=function(t,e,s,r,n,o){for(var h=i.F._bitsE,l=i.F._get17,a=0;a<s;){var u=t[l(r,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(r,n,2),n+=2,f=o[a-1]):17==c?(d=3+h(r,n,3),n+=3):18==c&&(d=11+h(r,n,7),n+=7);for(var p=a+d;a<p;)o[a]=f,a++}}return n},i.F._copyOut=function(t,e,i,s){for(var r=0,n=0,o=s.length>>>1;n<i;){var h=t[n+e];s[n<<1]=0,s[1+(n<<1)]=h,h>r&&(r=h),n++}for(;n<o;)s[n<<1]=0,s[1+(n<<1)]=0,n++;return r},i.F.makeCodes=function(t,e){for(var s,r,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(s=0,a[0]=0,r=1;r<=e;r++)c[r]=s=s+a[r-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,s){for(var r=t.length,n=i.F.U.rev15,o=0;o<r;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;)s[n[u]>>>15-e]=l,u++},i.F.revCodes=function(t,e){for(var s=i.F.U.rev15,r=15-e,n=0;n<t.length;n+=2)t[n]=s[t[n]<<e-t[n+1]]>>>r},i.F._putsE=function(t,e,i){var s=e>>>3;t[s]|=i<<=7&e,t[s+1]|=i>>>8},i.F._putsF=function(t,e,i){var s=e>>>3;t[s]|=i<<=7&e,t[s+1]|=i>>>8,t[s+2]|=i>>>16},i.F._bitsE=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<i)-1},i.F._bitsF=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<i)-1},i.F._get17=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},i.F._get25=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},i.F.U=(t=Uint16Array,e=Uint32Array,{next_code:new t(16),bl_count:new t(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],ldef:new t(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],ddef:new e(32),flmap:new t(512),fltree:[],fdmap:new t(32),fdtree:[],lmap:new t(32768),ltree:[],ttree:[],dmap:new t(32768),dtree:[],imap:new t(512),itree:[],rev15:new t(32768),lhst:new e(286),dhst:new e(30),ihst:new e(19),lits:new e(15e3),strt:new t(65536),prev:new t(32768)}),function(){for(var t=i.F.U,e=0;e<32768;e++){var s=e;s=(4278255360&(s=(4042322160&(s=(3435973836&(s=(2863311530&s)>>>1|(1431655765&s)<<1))>>>2|(858993459&s)<<2))>>>4|(252645135&s)<<4))>>>8|(16711935&s)<<8,t.rev15[e]=(s>>>16|s<<16)>>>17}function r(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];r(t.fltree,144,8),r(t.fltree,112,9),r(t.fltree,24,7),r(t.fltree,8,8),i.F.makeCodes(t.fltree,9),i.F.codes2map(t.fltree,9,t.flmap),i.F.revCodes(t.fltree,9),r(t.fdtree,32,5),i.F.makeCodes(t.fdtree,5),i.F.codes2map(t.fdtree,5,t.fdmap),i.F.revCodes(t.fdtree,5),r(t.itree,19,0),r(t.ltree,286,0),r(t.dtree,30,0),r(t.ttree,320,0)}()}();var ho=function(t,e){return e.forEach((function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach((function(i){if("default"!==i&&!(i in t)){var s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return e[i]}})}}))})),Object.freeze(t)}({__proto__:null,default:no},[no]);const lo=function(){var t={nextZero(t,e){for(;0!=t[e];)e++;return e},readUshort:(t,e)=>t[e]<<8|t[e+1],writeUshort(t,e,i){t[e]=i>>8&255,t[e+1]=255&i},readUint:(t,e)=>16777216*t[e]+(t[e+1]<<16|t[e+2]<<8|t[e+3]),writeUint(t,e,i){t[e]=i>>24&255,t[e+1]=i>>16&255,t[e+2]=i>>8&255,t[e+3]=255&i},readASCII(t,e,i){let s="";for(let r=0;r<i;r++)s+=String.fromCharCode(t[e+r]);return s},writeASCII(t,e,i){for(let s=0;s<i.length;s++)t[e+s]=i.charCodeAt(s)},readBytes(t,e,i){const s=[];for(let r=0;r<i;r++)s.push(t[e+r]);return s},pad:t=>t.length<2?`0${t}`:t,readUTF8(e,i,s){let r,n="";for(let r=0;r<s;r++)n+=`%${t.pad(e[i+r].toString(16))}`;try{r=decodeURIComponent(n)}catch(r){return t.readASCII(e,i,s)}return r}};function e(e,i,s,r){const o=i*s,h=n(r),l=Math.ceil(i*h/8),a=new Uint8Array(4*o),u=new Uint32Array(a.buffer),{ctype:c}=r,{depth:f}=r,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=r.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],s=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]==s&&(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)==s&&(a[m+3]=0)}}else if(3==c){const t=r.tabs.PLTE,n=r.tabs.tRNS,h=n?n.length:0;if(1==f)for(var v=0;v<s;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<s;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<s;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=r.tabs.tRNS?r.tabs.tRNS:-1,v=0;v<s;v++){const t=v*l,s=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[s+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[s+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[s+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[s+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[s+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?r(e,u):s(e,u),0==t.interlace?e=o(e,t,0,i,h):1==t.interlace&&(e=function(t,e){const i=e.width,s=e.height,r=n(e),h=r>>3,l=Math.ceil(i*r/8),a=new Uint8Array(s*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<s;)k+=n,y++;let b=f[g];for(;b<i;)b+=m,v++;const M=Math.ceil(v*r/8);o(t,e,u,v,y);let x=0,C=c[g];for(;C<s;){let e=f[g],s=u+x*M<<3;for(;e<i;){var w;if(1==r&&(w=(w=t[s>>3])>>7-(7&s)&1,a[C*l+(e>>3)]|=w<<7-(7&e)),2==r&&(w=(w=t[s>>3])>>6-(7&s)&3,a[C*l+(e>>2)]|=w<<6-((3&e)<<1)),4==r&&(w=(w=t[s>>3])>>4-(7&s)&15,a[C*l+(e>>1)]|=w<<4-((1&e)<<2)),r>=8){const i=C*l+e*h;for(let e=0;e<h;e++)a[i+e]=t[(s>>3)+e]}s+=r,e+=m}x++,C+=n}v*y!=0&&(u+=y*(1+M)),g+=1}return a}(e,t)),e}function s(t,e){return r(new Uint8Array(t.buffer,2,t.length-6),e)}var r=function(){const t={H:{}};return t.H.N=function(e,i){const s=Uint8Array;let r,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 s(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 s(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&&(r=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),r=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 s=g.V(M.v,l,a,M.D);f=(1<<s)-1,y(M.C,i),k(M.C,i,r),y(M.D,s),k(M.D,s,n)}for(;;){const t=r[b(e,p)&c];p+=15&t;const s=t>>>4;if(s>>>8==0)i[d++]=s;else{if(256==s)break;{let t=d+s-254;if(s>264){const i=M.q[s-257];t=d+(i>>>3)+m(e,p,7&i),p+=7&i}const r=n[b(e,p)&f];p+=15&r;const o=M.c[r>>>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 r=4+(p>>>3),n=e[r-4]|e[r-3]<<8;x&&(i=t.H.W(i,d+n)),i.set(new s(e.buffer,e.byteOffset+r,n),d),p=r+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 s=new Uint8Array(i<<1);return s.set(t,0),s},t.H.R=function(e,i,s,r,n,o){const h=t.H.e,l=t.H.Z;let a=0;for(;a<s;){const t=e[l(r,n)&i];n+=15&t;const s=t>>>4;if(s<=15)o[a]=s,a++;else{let t=0,e=0;16==s?(e=3+h(r,n,2),n+=2,t=o[a-1]):17==s?(e=3+h(r,n,3),n+=3):18==s&&(e=11+h(r,n,7),n+=7);const i=a+e;for(;a<i;)o[a]=t,a++}}return n},t.H.V=function(t,e,i,s){let r=0,n=0;const o=s.length>>>1;for(;n<i;){const i=t[n+e];s[n<<1]=0,s[1+(n<<1)]=i,i>r&&(r=i),n++}for(;n<o;)s[n<<1]=0,s[1+(n<<1)]=0,n++;return r},t.H.n=function(e,i){const s=t.H.m,r=e.length;let n,o,h,l;const a=s.j;for(var u=0;u<=i;u++)a[u]=0;for(u=1;u<r;u+=2)a[e[u]]++;const c=s.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<r;h+=2)l=e[h+1],0!=l&&(e[h]=c[l],c[l]++)},t.H.A=function(e,i,s){const r=e.length,n=t.H.m.r;for(let t=0;t<r;t+=2)if(0!=e[t+1]){const r=e[t+1],o=t>>1<<4|r,h=i-r;let l=e[t]<<h;const a=l+(1<<h);for(;l!=a;)s[n[l]>>>15-i]=o,l++}},t.H.l=function(e,i){const s=t.H.m.r,r=15-i;for(let t=0;t<e.length;t+=2)e[t]=s[e[t]<<i-e[t+1]]>>>r},t.H.M=function(t,e,i){const s=e>>>3;t[s]|=i<<=7&e,t[s+1]|=i>>>8},t.H.I=function(t,e,i){const s=e>>>3;t[s]|=i<<=7&e,t[s+1]|=i>>>8,t[s+2]|=i>>>16},t.H.e=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<i)-1},t.H.b=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<i)-1},t.H.Z=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},t.H.i=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},t.H.m=function(){const t=Uint16Array,e=Uint32Array;return{K:new t(16),j:new t(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new t(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new e(32),J:new t(512),_:[],h:new t(32),$:[],w:new t(32768),C:[],v:[],d:new t(32768),D:[],u:new t(512),Q:[],r:new t(32768),s:new e(286),Y:new e(30),a:new e(19),t:new e(15e3),k:new t(65536),g:new t(32768)}}(),function(){const e=t.H.m;for(var i=0;i<32768;i++){let t=i;t=(2863311530&t)>>>1|(1431655765&t)<<1,t=(3435973836&t)>>>2|(858993459&t)<<2,t=(4042322160&t)>>>4|(252645135&t)<<4,t=(4278255360&t)>>>8|(16711935&t)<<8,e.r[i]=(t>>>16|t<<16)>>>17}function s(t,e,i){for(;0!=e--;)t.push(0,i)}for(i=0;i<32;i++)e.q[i]=e.S[i]<<3|e.T[i],e.c[i]=e.p[i]<<4|e.z[i];s(e._,144,8),s(e._,112,9),s(e._,24,7),s(e._,8,8),t.H.n(e._,9),t.H.A(e._,9,e.J),t.H.l(e._,9),s(e.$,32,5),t.H.n(e.$,5),t.H.A(e.$,5,e.h),t.H.l(e.$,5),s(e.Q,19,0),s(e.C,286,0),s(e.D,30,0),s(e.v,320,0)}(),t.H.N}();function n(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function o(t,e,i,s,r){let o=n(e);const l=Math.ceil(s*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<r;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 s=t+e-i,r=s-t,n=s-e,o=s-i;return r*r<=n*n&&r*r<=o*o?t:n*n<=o*o?e:i}function l(e,i,s){s.width=t.readUint(e,i),s.height=t.readUint(e,i+=4),s.depth=e[i+=4],i++,s.ctype=e[i],i++,s.compress=e[i],i++,s.filter=e[i],i++,s.interlace=e[i],i++}function a(t,e,i,s,r,n,o,h,l){const a=Math.min(e,r),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)*r+o+n<<2):(c=(-h+i)*e-o+n<<2,f=i*r+n<<2),0==l)s[f]=t[c],s[f+1]=t[c+1],s[f+2]=t[c+2],s[f+3]=t[c+3];else if(1==l){var d=t[c+3]*(1/255),p=t[c]*d,g=t[c+1]*d,w=t[c+2]*d,m=s[f+3]*(1/255),v=s[f]*m,y=s[f+1]*m,k=s[f+2]*m;const e=1-d,i=d+m*e,r=0==i?0:1/i;s[f+3]=255*i,s[f+0]=(p+v*e)*r,s[f+1]=(g+y*e)*r,s[f+2]=(w+k*e)*r}else if(2==l)p=t[c],g=t[c+1],w=t[c+2],v=s[f],y=s[f+1],k=s[f+2],(d=t[c+3])==(m=s[f+3])&&p==v&&g==y&&w==k?(s[f]=0,s[f+1]=0,s[f+2]=0,s[f+3]=0):(s[f]=p,s[f+1]=g,s[f+2]=w,s[f+3]=d);else if(3==l){if(p=t[c],g=t[c+1],w=t[c+2],v=s[f],y=s[f+1],k=s[f+2],(d=t[c+3])==(m=s[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=s(i)}catch(t){l=r(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 s={rect:t,delay:Math.round(1e3*e),dispose:n[o+24],blend:n[o+25]};c.frames.push(s)}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=s(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=s(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,s=t.height;if(null==t.tabs.acTL)return[e(t.data,i,s,t).buffer];const r=[];null==t.frames[0].data&&(t.frames[0].data=t.data);const n=i*s*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,s,d,p,0):1==f.blend&&a(m,g,w,o,i,s,d,p,1),r.push(o.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)a(h,g,w,o,i,s,d,p,0);else if(2==f.dispose)for(u=0;u<n;u++)o[u]=l[u]}return r},_paeth:h,_copyTile:a,_bin:t}}();!function(){const{_copyTile:t}=lo,{_bin:e}=lo,i=lo._paeth;var s={table:function(){const t=new Uint32Array(256);for(let e=0;e<256;e++){let i=e;for(let t=0;t<8;t++)1&i?i=3988292384^i>>>1:i>>>=1;t[e]=i}return t}(),update(t,e,i,r){for(let n=0;n<r;n++)t=s.table[255&(t^e[i+n])]^t>>>8;return t},crc:(t,e,i)=>4294967295^s.update(4294967295,t,e,i)};function r(t,e,i,s){e[i]+=t[0]*s>>4,e[i+1]+=t[1]*s>>4,e[i+2]+=t[2]*s>>4,e[i+3]+=t[3]*s>>4}function n(t){return Math.max(0,Math.min(255,t))}function o(t,e){const i=t[0]-e[0],s=t[1]-e[1],r=t[2]-e[2],n=t[3]-e[3];return i*i+s*s+r*r+n*n}function h(t,e,i,s,h,l,a){null==a&&(a=1);const u=s.length,c=[];for(var f=0;f<u;f++){const t=s[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&&r(x,m,f+4,7),h!=i-1&&(0!=k&&r(x,m,f+4*e-4,3),r(x,m,f+4*e,5),k!=e-1&&r(x,m,f+4*e+4,1))),l[f>>2]=d,w[f>>2]=s[d]}}function l(t,i,r,n,o){null==o&&(o={});const{crc:h}=s,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,r),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],s=i>>>8&255,r=i>>>16&255;y[c+e+0]=255&i,y[c+e+1]=s,y[c+e+2]=r}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 s=0;s<t.frames.length;s++){const r=t.frames[s],n=r.rect.height,o=new Uint8Array(n*r.bpl+n);r.cimg=d(r.img,n,r.bpp,r.bpl,o,e,i)}}function u(e,i,s,r,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,s,r,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=s,y=r?1:0;if(0!=l){const k=o||r||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 r=new Uint32Array(e[l-1-t]);let o=i,h=s,a=-1,c=-1;for(let t=0;t<s;t++)for(let e=0;e<i;e++)d[p=t*i+e]!=r[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,s,a,m,v,-g,-w,0),y=t(c,i,s,a,m,v,-g,-w,3)?1:0,1==y?f(c,i,s,a,{x:g,y:w,width:m,height:v}):t(c,i,s,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(r)for(l=0;l<h.length;l++){if(1==(g=h[l]).blend)continue;const t=g.rect,r=h[l-1].rect,o=Math.min(t.x,r.x),a=Math.min(t.y,r.y),u={x:o,y:a,width:Math.max(t.x+t.width,r.x+r.width)-o,height:Math.max(t.y+t.height,r.y+r.height)-a};h[l-1].dispose=1,l-1!=0&&c(e,i,s,h,l-1,u,n),c(e,i,s,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,s,o,l,a),C={},A=[],S=[];if(0!=r){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 s=new Uint8Array(e);let r=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),s[r+t]=i,s[r+t+1]=n,s[r+t+2]=o,s[r+t+3]=h}r+=n}return s.buffer}(t),i=g(e,r);for(b=0;b<i.plte.length;b++)A.push(i.plte[b].est.rgba);let s=0;for(b=0;b<x.length;b++){const t=(T=x[b]).img.length;var B=new Uint8Array(i.inds.buffer,s>>2,t>>2);S.push(B);const e=new Uint8Array(i.abuf,s,t);p&&h(T.img,T.rect.width,T.rect.height,A,e,B),T.img.set(e),s+=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),s=4;if(E<=256&&0==d){i=Math.ceil(m*O/8);var I=new Uint8Array(i*t);const r=S[y];for(let e=0;e<t;e++){b=e*i;const t=e*O;if(8==m)for(var $=0;$<O;$++)I[b+$]=r[t+$];else if(4==m)for($=0;$<O;$++)I[b+($>>1)]|=r[t+$]<<4-4*(1&$);else if(2==m)for($=0;$<O;$++)I[b+($>>2)]|=r[t+$]<<6-2*(3&$);else if(1==m)for($=0;$<O;$++)I[b+($>>3)]|=r[t+$]<<7-1*(7&$)}e=I,w=3,s=1}else if(0==M&&1==x.length){I=new Uint8Array(O*t*3);const r=O*t;for(b=0;b<r;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,s=3,i=3*O}T.img=e,T.bpl=i,T.bpp=s}return{ctype:w,depth:m,plte:A,frames:x}}function c(e,i,s,r,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=s,v=-1,y=-1;for(let t=0;t<o.height;t++)for(let e=0;e<o.width;e++){const s=o.x+e,h=o.y+t,l=h*i+s,a=g[l];0==a||0==r[n-1].dispose&&c[l]==a&&(null==d||0!=d[4*l+3])||(s<w&&(w=s),s>v&&(v=s),h<m&&(m=h),h>y&&(y=h))}-1==v&&(w=m=v=y=0),h&&(!(1&~w)&&w--,!(1&~m)&&m--);const k=r[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==r[n-1].dispose?(t(u,i,s,k.img,o.width,o.height,-o.x,-o.y,0),f(p,i,s,k.img,o)):t(p,i,s,k.img,o.width,o.height,-o.x,-o.y,0)}function f(e,i,s,r,n){t(e,i,s,r,n.width,n.height,-n.x,-n.y,2)}function d(t,e,i,s,r,n,o){const h=[];let l,a=[0,1,2,3,4];-1!=n?a=[n]:(e*s>5e5||1==i)&&(a=[0]),o&&(l={level:0});const u=ho;for(var c=0;c<a.length;c++){for(let n=0;n<e;n++)p(r,t,n,s,i,a[c]);h.push(u.deflate(r,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,s,r,n,o){const h=s*r;let l=h+s;if(t[l]=o,l++,0==o)if(r<500)for(var a=0;a<r;a++)t[l+a]=e[h+a];else t.set(new Uint8Array(e.buffer,h,r),l);else if(1==o){for(a=0;a<n;a++)t[l+a]=e[h+a];for(a=n;a<r;a++)t[l+a]=e[h+a]-e[h+a-n]+256&255}else if(0==s){for(a=0;a<n;a++)t[l+a]=e[h+a];if(2==o)for(a=n;a<r;a++)t[l+a]=e[h+a];if(3==o)for(a=n;a<r;a++)t[l+a]=e[h+a]-(e[h+a-n]>>1)+256&255;if(4==o)for(a=n;a<r;a++)t[l+a]=e[h+a]-i(e[h+a-n],0,0)+256&255}else{if(2==o)for(a=0;a<r;a++)t[l+a]=e[h+a]+256-e[h+a-r]&255;if(3==o){for(a=0;a<n;a++)t[l+a]=e[h+a]+256-(e[h+a-r]>>1)&255;for(a=n;a<r;a++)t[l+a]=e[h+a]+256-(e[h+a-r]+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-r],0)&255;for(a=n;a<r;a++)t[l+a]=e[h+a]+256-i(e[h+a-n],e[h+a-r],e[h+a-n-r])&255}}}function g(t,e){const i=new Uint8Array(t),s=i.slice(0),r=new Uint32Array(s.buffer),n=w(s,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,r[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,r[c>>2]=u.est.rgba}return{abuf:s.buffer,inds:a,plte:h}}function w(t,e,i){null==i&&(i=1e-4);const s=new Uint32Array(t.buffer),r={i0:0,i1:t.length,bst:null,est:null,tdst:0,left:null,right:null};r.bst=b(t,r.i0,r.i1),r.est=M(r.bst);const n=[r];for(;n.length<e;){let e=0,r=0;for(var o=0;o<n.length;o++)n[o].est.L>e&&(e=n[o].est.L,r=o);if(e<i)break;const h=n[r],l=y(t,s,h.i0,h.i1,h.est.e,h.est.eMq255);if(h.i0>=l||h.i1<=l){h.est.L=0;continue}const a={i0:h.i0,i1:l,bst:null,est:null,tdst:0,left:null,right:null};a.bst=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[r]=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[r,n]}function m(t,e,i,s,r){if(null==t.left)return t.tdst=function(t,e,i,s,r){const n=e-t[0],o=i-t[1],h=s-t[2],l=r-t[3];return n*n+o*o+h*h+l*l}(t.est.q,e,i,s,r),t;const n=v(t.est,e,i,s,r);let o=t.left,h=t.right;n>0&&(o=t.right,h=t.left);const l=m(o,e,i,s,r);if(l.tdst<=n*n)return l;const a=m(h,e,i,s,r);return a.tdst<l.tdst?a:l}function v(t,e,i,s,r){const{e:n}=t;return n[0]*e+n[1]*i+n[2]*s+n[3]*r-t.eMq}function y(t,e,i,s,r,n){for(s-=4;i<s;){for(;k(t,i,r)<=n;)i+=4;for(;k(t,s,r)>n;)s-=4;if(i>=s)break;const o=e[i>>2];e[i>>2]=e[s>>2],e[s>>2]=o,i+=4,s-=4}for(;k(t,i,r)>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 s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=[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);r[0]+=e,r[1]+=i,r[2]+=o,r[3]+=h,s[0]+=e*e,s[1]+=e*i,s[2]+=e*o,s[3]+=e*h,s[5]+=i*i,s[6]+=i*o,s[7]+=i*h,s[10]+=o*o,s[11]+=o*h,s[15]+=h*h}return s[4]=s[1],s[8]=s[2],s[9]=s[6],s[12]=s[3],s[13]=s[7],s[14]=s[11],{R:s,m:r,N:n}}function M(t){const{R:e}=t,{m:i}=t,{N:s}=t,r=i[0],n=i[1],o=i[2],h=i[3],l=0==s?0:1/s,a=[e[0]-r*r*l,e[1]-r*n*l,e[2]-r*o*l,e[3]-r*h*l,e[4]-n*r*l,e[5]-n*n*l,e[6]-n*o*l,e[7]-n*h*l,e[8]-o*r*l,e[9]-o*n*l,e[10]-o*o*l,e[11]-o*h*l,e[12]-h*r*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!=s)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=[r*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]]};lo.encode=function(t,e,i,s,r,n,o){null==s&&(s=0),null==o&&(o=!1);const h=u(t,e,i,s,[!1,!1,!1,0,o,!1]);return a(h,-1),l(h,e,i,r,n)},lo.encodeLL=function(t,e,i,s,r,n,o,h){const u={ctype:0+(1==s?0:2)+(0==r?0:4),depth:n,frames:[]},c=(s+r)*n,f=c*e;for(let s=0;s<t.length;s++)u.frames.push({rect:{x:0,y:0,width:e,height:i},img:new Uint8Array(t[s]),blend:0,dispose:1,bpp:Math.ceil(c/8),bpl:Math.ceil(f/8)});return a(u,0,!0),l(u,e,i,o,h)},lo.encode.compress=u,lo.encode.dither=h,lo.quantize=g,lo.quantize.getKDtree=w,lo.quantize.getNearest=m}();const ao={toArrayBuffer(t,e){const i=t.width,s=t.height,r=i<<2,n=t.getContext("2d").getImageData(0,0,i,s),o=new Uint32Array(n.data.buffer),h=(32*i+31)/32<<2,l=h*s,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(-s>>>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<s&&m>0;){for(w=122+v*h,d=0;d<r;)m--,p=o[k++],g=p>>>24,c.setUint32(w+d,p<<8|g),d+=4;v++}k<o.length?(m=f,setTimeout(t,ao._dly)):e(u)}()},toBlob(t,e){this.toArrayBuffer(t,(t=>{e(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var uo={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},co={[uo.CHROME]:16384,[uo.FIREFOX]:11180,[uo.DESKTOP_SAFARI]:16384,[uo.IE]:8192,[uo.IOS]:4096,[uo.ETC]:8192};const fo="undefined"!=typeof window,po="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,go=fo&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),wo=(fo||po)&&(go&&go.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),mo=(fo||po)&&(go&&go.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function vo(t,e,i=Date.now()){return new Promise((s=>{const r=t.split(","),n=r[0].match(/:(.*?);/)[1],o=globalThis.atob(r[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,s(a)}))}function yo(t){return new Promise(((e,i)=>{const s=new mo;s.onload=()=>e(s.result),s.onerror=t=>i(t),s.readAsDataURL(t)}))}function ko(t){return new Promise(((e,i)=>{const s=new Image;s.onload=()=>e(s),s.onerror=t=>i(t),s.src=t}))}function bo(){if(void 0!==bo.cachedResult)return bo.cachedResult;let t=uo.ETC;const{userAgent:e}=navigator;return/Chrom(e|ium)/i.test(e)?t=uo.CHROME:/iP(ad|od|hone)/i.test(e)&&/WebKit/i.test(e)?t=uo.IOS:/Safari/i.test(e)?t=uo.DESKTOP_SAFARI:/Firefox/i.test(e)?t=uo.FIREFOX:(/MSIE/i.test(e)||1==!!document.documentMode)&&(t=uo.IE),bo.cachedResult=t}function Mo(t,e){const i=bo(),s=co[i];let r=t,n=e,o=r*n;const h=r>n?n/r:r/n;for(;o>s*s;){const t=(s+r)/2,e=(s+n)/2;t<e?(n=e,r=e*h):(n=t*h,r=t),o=r*n}return{width:r,height:n}}function xo(t,e){let i,s;try{if(i=new OffscreenCanvas(t,e),s=i.getContext("2d"),null===s)throw new Error("getContext of OffscreenCanvas returns null")}catch(t){i=document.createElement("canvas"),s=i.getContext("2d")}return i.width=t,i.height=e,[i,s]}function Co(t,e){const{width:i,height:s}=Mo(t.width,t.height),[r,n]=xo(i,s);return e&&/jpe?g/.test(e)&&(n.fillStyle="white",n.fillRect(0,0,r.width,r.height)),n.drawImage(t,0,0,r.width,r.height),r}function Ao(){return void 0!==Ao.cachedResult||(Ao.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),Ao.cachedResult}function So(t,e={}){return new Promise((function(i,s){let r,n;var o=function(){try{return n=Co(r,e.fileType||t.type),i([r,n])}catch(t){return s(t)}},h=function(){try{var e=function(t){try{throw t}catch(t){return s(t)}};try{let i;return yo(t).then((function(t){try{return i=t,ko(i).then((function(t){try{return r=t,function(){try{return o()}catch(t){return s(t)}}()}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){e(t)}}catch(t){return s(t)}};try{if(Ao()||[uo.DESKTOP_SAFARI,uo.MOBILE_SAFARI].includes(bo()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return r=t,o()}catch(t){return h()}}),h)}catch(t){h()}}))}function Bo(t,e,i,s,r=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=lo.encode([u.buffer],t.width,t.height,4096*r),h=new Blob([c],{type:e}),h.name=i,h.lastModified=s,l.call(this)}{if("image/bmp"===e)return new Promise((e=>ao.toBlob(t,e))).then(function(t){try{return h=t,h.name=i,h.lastModified=s,f.call(this)}catch(t){return o(t)}}.bind(this),o);{if("function"==typeof OffscreenCanvas&&t instanceof OffscreenCanvas)return t.convertToBlob({type:e,quality:r}).then(function(t){try{return h=t,h.name=i,h.lastModified=s,d.call(this)}catch(t){return o(t)}}.bind(this),o);{let p;return p=t.toDataURL(e,r),vo(p,i,s).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 To(t){t.width=0,t.height=0}function Oo(){return new Promise((function(t,e){let i,s,r,n;return void 0!==Oo.cachedResult?t(Oo.cachedResult):vo("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return i=o,So(i).then((function(o){try{return s=o[1],Bo(s,i.type,i.name,i.lastModified).then((function(i){try{return r=i,To(s),So(r).then((function(i){try{return n=i[0],t(Oo.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 Eo(t){return new Promise(((e,i)=>{const s=new mo;s.onload=t=>{const i=new DataView(t.target.result);if(65496!=i.getUint16(0,!1))return e(-2);const s=i.byteLength;let r=2;for(;r<s;){if(i.getUint16(r+2,!1)<=8)return e(-1);const t=i.getUint16(r,!1);if(r+=2,65505==t){if(1165519206!=i.getUint32(r+=2,!1))return e(-1);const t=18761==i.getUint16(r+=6,!1);r+=i.getUint32(r+4,t);const s=i.getUint16(r,t);r+=2;for(let n=0;n<s;n++)if(274==i.getUint16(r+12*n,t))return e(i.getUint16(r+12*n+8,t))}else{if(65280&~t)break;r+=i.getUint16(r,!1)}}return e(-1)},s.onerror=t=>i(t),s.readAsArrayBuffer(t)}))}function Io(t,e){const{width:i}=t,{height:s}=t,{maxWidthOrHeight:r}=e;let n,o=t;return isFinite(r)&&(i>r||s>r)&&([o,n]=xo(i,s),i>s?(o.width=r,o.height=s/i*r):(o.width=i/s*r,o.height=r),n.drawImage(t,0,0,o.width,o.height),To(t)),o}function $o(t,e){const{width:i}=t,{height:s}=t,[r,n]=xo(i,s);switch(e>4&&e<9?(r.width=s,r.height=i):(r.width=i,r.height=s),e){case 2:n.transform(-1,0,0,1,i,0);break;case 3:n.transform(-1,0,0,-1,i,s);break;case 4:n.transform(1,0,0,-1,0,s);break;case 5:n.transform(0,1,1,0,0,0);break;case 6:n.transform(0,1,-1,0,s,0);break;case 7:n.transform(0,-1,-1,0,s,i);break;case 8:n.transform(0,-1,1,0,0,i)}return n.drawImage(t,0,0,i,s),To(t),r}function Po(t,e,i=0){return new Promise((function(s,r){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(),So(t,e).then(function(i){try{return[,l]=i,A(),a=Io(l,e),A(),new Promise((function(i,s){var r;if(!(r=e.exifOrientation))return Eo(t).then(function(t){try{return r=t,n.call(this)}catch(t){return s(t)}}.bind(this),s);function n(){return i(r)}return n.call(this)})).then(function(i){try{return u=i,A(),Oo().then(function(i){try{return c=i?a:$o(a,u),A(),f=e.initialQuality||1,d=e.fileType||t.type,Bo(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),s(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]=xo(e,i),M.drawImage(x,0,0,e,i),f*="image/png"===d?.85:.95,Bo(b,d,t.name,t.lastModified,f).then((function(t){try{return k=t,To(x),x=b,y=k.size,S(Math.min(99,Math.floor((v-y)/(v-h)*100))),u}catch(t){return r(t)}}),r)}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,r);try{if(t.pop){if(t.length)return t.pop()?B.call(this):t;t=u}else t=t.call(this)}catch(t){return r(t)}}}.bind(this))(u);function B(){return To(x),To(b),To(a),To(c),To(l),S(100),s(k)}}}catch(T){return r(T)}}.bind(this),r)}catch(t){return r(t)}}.bind(this),r)}catch(t){return r(t)}}.bind(this),r)}catch(t){return r(t)}}.bind(this),r)}))}let Do;function Ro(t,e){return new Promise(((i,s)=>{Do||(Do=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 r=new Worker(Do);r.addEventListener("message",(function(t){if(e.signal&&e.signal.aborted)r.terminate();else if(void 0===t.data.progress){if(t.data.error)return s(new Error(t.data.error)),void r.terminate();i(t.data.file),r.terminate()}else e.onProgress(t.data.progress)})),r.addEventListener("error",s),e.signal&&e.signal.addEventListener("abort",(()=>{s(e.signal.reason),r.terminate()})),r.postMessage({file:t,imageCompressionLibUrl:e.libURL,options:{...e,onProgress:void 0,signal:void 0}})}))}function jo(t,e){return new Promise((function(i,s){let r,n,o,h,l,a;if(r={...e},o=0,({onProgress:h}=r),r.maxSizeMB=r.maxSizeMB||Number.POSITIVE_INFINITY,l="boolean"!=typeof r.useWebWorker||r.useWebWorker,delete r.useWebWorker,r.onProgress=t=>{o=t,"function"==typeof h&&h(o)},!(t instanceof Blob||t instanceof wo))return s(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(t.type))return s(new Error("The file given is not an image"));if(a="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!l||"function"!=typeof Worker||a)return Po(t,r).then(function(t){try{return n=t,f.call(this)}catch(t){return s(t)}}.bind(this),s);var u=function(){try{return f.call(this)}catch(t){return s(t)}}.bind(this),c=function(){try{return Po(t,r).then((function(t){try{return n=t,u()}catch(t){return s(t)}}),s)}catch(t){return s(t)}};try{return r.libURL=r.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",Ro(t,r).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{r.preserveExif&&"image/jpeg"===t.type&&(!r.fileType||r.fileType&&r.fileType===t.type)&&(n=so(t,n))}catch(t){}return i(n)}}))}jo.getDataUrlFromFile=yo,jo.getFilefromDataUrl=vo,jo.loadImage=ko,jo.drawImageInCanvas=Co,jo.drawFileInCanvas=So,jo.canvasToFile=Bo,jo.getExifOrientation=Eo,jo.handleMaxWidthOrHeight=Io,jo.followExifOrientation=$o,jo.cleanupCanvasMemory=To,jo.isAutoOrientationInBrowser=Oo,jo.approximateBelowMaximumCanvasSizeOfBrowser=Mo,jo.copyExifWithoutOrientation=so,jo.getBrowserName=bo,jo.version="2.0.2";class Fo extends Gn{fileInput=null;maxCompressionSize=1200;multiImportOffset=20;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.multiple=!0,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,i=e.files?Array.from(e.files):[];if(0===i.length)return console.info("File selection cancelled by user."),this.handleCancel(),void(e&&(e.value=""));const s=i.map((t=>jo(t,{maxWidthOrHeight:this.maxCompressionSize}).then((t=>this.prepareImage(t)))));Promise.allSettled(s).then((t=>{const e=[];for(const i of t)"fulfilled"===i.status?e.push(i.value):console.error("Error during image compression or processing:",i.reason);0!==e.length?this.addImagesToStore(e):this.handleCancel()})),e&&(e.value="")}async prepareImage(t){let e=null;try{const i=t.type||"image/png";e=URL.createObjectURL(t);const s=await this.measureImage(e),r=await this._core.assetResolver.put(t,{mimeType:i,kind:"image",width:s.naturalWidth,height:s.naturalHeight}),n=Xn.create(this._core);n.assetId=r.id,n.mimeType=r.mimeType;const{scaledWidth:o,scaledHeight:h}=n.calculateScaledDimensions({width:s.naturalWidth,height:s.naturalHeight});return n.width=o,n.height=h,n.resolvedSrc=await this._core.assetResolver.resolve(r.id),n.loadState="ready",n}finally{if(e)try{URL.revokeObjectURL(e)}catch{}}}measureImage(t){return new Promise(((e,i)=>{const s=new Image;s.onload=()=>e({naturalWidth:s.naturalWidth,naturalHeight:s.naturalHeight}),s.onerror=t=>i(t),s.src=t}))}addImagesToStore(t){const e=this._core.store.currentZIndex;t.forEach(((t,i)=>{if(t.zIndex=e+i,t.centerInViewport(),i>0){const e=i*this.multiImportOffset;t.updatePosition(t.translateX+e,t.translateY+e)}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 Uo extends Gn{_fontFamily="Arial";_fontSize=16;_fontColor=An[0];_opacity=1;get fontFamily(){return this._fontFamily}set fontFamily(t){this._fontFamily=t,this.applyToActiveText({fontFamily:t})}get fontSize(){return this._fontSize}set fontSize(t){this._fontSize=t,this.applyToActiveText({fontSize:t})}get fontColor(){return this._fontColor}set fontColor(t){this._fontColor=t,this.applyToActiveText({fontColor:t})}get opacity(){return this._opacity}set opacity(t){this._opacity=t,this.applyToActiveText({opacity:t})}palette=[...An];constructor(t){super(t)}applyToActiveText(t){const e=this._core?.store?.activeText;e&&(this._core.updateObject(e,t),this._core.rerender())}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){const e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),s=e?.id?this._core.findObjectById(e.id):null,r=this._core.store.activeText;if(null===r&&s instanceof Pn)return void s.edit(t);if(null!==r&&s instanceof Pn)return r.save(),void s.edit(t);if(null!==r&&s instanceof Pn==0)return this._core.resetActiveText(),void this._core.store.setState("activeTool",i.getTool("selection"));if(!1===qn.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.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()),s=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),r=s?.id?this._core.findObjectById(s.id):null,n=this._core.store.activeText;if(null===n&&r instanceof Pn)return void r.edit(t);if(null!==n&&r instanceof Pn)return n.save(),void r.edit(t);if(null!==n&&r 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.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 No extends Gn{shapeType=Kn.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"))),s=this._core.findObjectById(e?.id),r=this._core.store.activeShape;if(null===r&&s instanceof Qn)return void s.edit(t);if(null!==r&&s instanceof Qn)return r.save(),void s.edit(t);if(null!==r&&s instanceof Qn==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",i.getTool("selection"));if(!1===qn.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()),s=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),r=this._core.findObjectById(s?.id),n=this._core.store.activeShape;if(null===n&&r instanceof Qn)return void r.edit(t);if(null!==n&&r instanceof Qn)return n.save(),void r.edit(t);if(null!==n&&r instanceof Qn==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,s=this._core.store.state.lockDrawingScale,r=s?i:1;this.startX=(t-this._core.store.offsetX)/r,this.startY=(e-this._core.store.offsetY)/r,this.isDrawing=!0,this.currentShape=Qn.create(this._core,{x:this.startX,y:this.startY,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,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:s?1:i}),this._core.store.objects.insert(this.currentShape),this._core.store.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,s=(t-this._core.store.offsetX)/i,r=(e-this._core.store.offsetY)/i,n=Math.min(this.startX,s),o=Math.min(this.startY,r),h=Math.abs(s-this.startX),l=Math.abs(r-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.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.objects.remove((e=>e.id===t))}else this.currentShape.zIndex=this._core.store.currentZIndex,this._core.store.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.objects?.setActiveDrawingObject(null),this.currentShape=null,this._core.store.objects?.stopUndoCapturing(),this._core.rerender()}}}class zo{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)}}zo.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>',"image-off":'<svg xmlns="http://www.w3.org/2000/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-image-off-icon lucide-image-off"><line x1="2" x2="22" y1="2" y2="22"/><path d="M10.41 10.41a2 2 0 1 1-2.83-2.83"/><line x1="13.5" x2="6" y1="13.5" y2="21"/><line x1="18" x2="21" y1="12" y2="15"/><path d="M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59"/><path d="M21 15V5a2 2 0 0 0-2-2H9"/></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 _o{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=zo.get(e);if(!i)return console.warn(`Icon "${e}" not found in registry.`),"auto";const s=t.size||24,r=t.rotation||0,n=t.color||"black",o=t.hotspot||("default"===t.iconName?{x:4,y:4}:{x:s/2,y:s/2});let h=i.replace(/width="\d+"/,`width="${s}"`).replace(/height="\d+"/,`height="${s}"`).replace(/currentColor/g,n);const l=s/2;return`url('data:image/svg+xml;charset=utf-8,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${s}" viewBox="0 0 ${s} ${s}">\n <g transform="rotate(${r} ${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 Lo{_core;constructor(t){this._core=t}}class Ho extends Lo{dragStartX=0;dragStartY=0;startX=0;startY=0;endX=0;endY=0;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(qn.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,s=t.shiftKey||t.ctrlKey;if(!i?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||s)this.trackedPointerId=null;else{const i=Math.round(e[0].clientX-this._core.store.offsetX),s=Math.round(e[0].clientY-this._core.store.offsetY);this.dragStartX=i,this.dragStartY=s,this.startX=i,this.startY=s,this.initialDragX=i,this.initialDragY=s,this.disconnectedLineIds.clear(),this.trackedPointerId=t.pointerId}}}}handlePointerMove(t){if(null!==this.trackedPointerId&&this.trackedPointerId===t.pointerId){if("mouse"===t.pointerType){const e=this._core.store.selectionGroup;if(this._core.store.state.isDragging&&e){const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this.endX=i,this.endY=s;const r=Math.abs(i-this.startX),n=Math.abs(s-this.startY),o=5;(this.hasMoved||r>o||n>o)&&(this.checkAndDisconnectAnchors(i,s),e.move(i,s,this.dragStartX,this.dragStartY),this.dragStartX=i,this.dragStartY=s,this.hasMoved=!0)}}if("touch"===t.pointerType||"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),s=Math.round(t[0].clientY-this._core.store.offsetY);this._core.store.state.isDragging=!0,this.endX=i,this.endY=s;const r=Math.abs(i-this.startX),n=Math.abs(s-this.startY),o=5;if(this.hasMoved||r>o||n>o){const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t),this.checkAndDisconnectAnchors(i,s),e.move(i,s,this.dragStartX,this.dragStartY),this.dragStartX=i,this.dragStartY=s,this.hasMoved=!0}}}}}handlePointerUp(t){null!==this.trackedPointerId&&this.trackedPointerId===t.pointerId&&("mouse"===t.pointerType&&this._core.store.state.isDragging&&(this._core.store.state.isDragging=!1,this.hasMoved&&(this._core.store.selectionGroup.persistChildren(),this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0,this._core.store.objects.stopUndoCapturing())),"touch"!==t.pointerType&&"pen"!==t.pointerType||this._core.store.state.isDragging&&(this._core.store.state.isDragging=!1,this.hasMoved&&(this._core.store.selectionGroup.persistChildren(),this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0,this._core.store.objects.stopUndoCapturing())),this.reset())}checkAndDisconnectAnchors(t,e){const i=t-this.initialDragX,s=e-this.initialDragY;if(Math.sqrt(i*i+s*s)<30)return;const r=this._core.store.selectionGroup;if(!r)return;const n=r.objects;if(n.every((t=>t instanceof Yn)))for(const t of n)if(!this.disconnectedLineIds.has(t.id)&&t instanceof Yn){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.objects.update(e))}}}var Xo;!function(t){t.TopLeft="top-left",t.TopRight="top-right",t.BottomLeft="bottom-left",t.BottomRight="bottom-right"}(Xo||(Xo={}));class Yo extends Lo{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&&qn.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,s=t.clientY-this._core.store.offsetY;this._core.store.state.isResizing=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialSize.width=e.width,this.initialSize.height=e.height,this.initialSize.x=e.translateX,this.initialSize.y=e.translateY}}if("touch"===t.pointerType||"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),s=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isResizing=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialSize.width=t.width,this.initialSize.height=t.height,this.initialSize.x=t.translateX,this.initialSize.y=t.translateY;const r=this._core.store.state.longTouchTimeout;r&&globalThis.clearTimeout?.(r)}}}}handlePointerMove(t){if("mouse"===t.pointerType){const e=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&e){const i=t.clientX-this._core.store.offsetX-this.initialMouseX,s=t.clientY-this._core.store.offsetY-this.initialMouseY,r=Math.abs(i),n=Math.abs(s),o=5;if((r>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+s*l)/c,d=(-i*l+s*a)/c,p=this.initialSize.x+this.initialSize.width/u/2+i/c/2,g=this.initialSize.y+this.initialSize.height/u/2+s/c/2;switch(this._core.store.state.resizeHandleType){case Xo.TopLeft:this.newSize.width=this.initialSize.width-f*u,this.newSize.height=this.initialSize.height-d*u;break;case Xo.TopRight:this.newSize.width=this.initialSize.width+f*u,this.newSize.height=this.initialSize.height-d*u;break;case Xo.BottomLeft:this.newSize.width=this.initialSize.width-f*u,this.newSize.height=this.initialSize.height+d*u;break;case Xo.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),s=Math.round(t.clientY-this._core.store.offsetY),r=i-this.initialMouseX,n=s-this.initialMouseY,o=Math.abs(r),h=Math.abs(n),l=5;if(o>l||h>l){const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t),this.hasResized=!0}if(!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=(r*c+n*u)/d,g=(-r*u+n*c)/d,w=this.initialSize.x+this.initialSize.width/f/2+r/d/2,m=this.initialSize.y+this.initialSize.height/f/2+n/d/2;switch(this._core.store.state.resizeHandleType){case Xo.TopLeft:this.newSize.width=this.initialSize.width-p*f,this.newSize.height=this.initialSize.height-g*f;break;case Xo.TopRight:this.newSize.width=this.initialSize.width+p*f,this.newSize.height=this.initialSize.height-g*f;break;case Xo.BottomLeft:this.newSize.width=this.initialSize.width-p*f,this.newSize.height=this.initialSize.height+g*f;break;case Xo.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,s=this.newSize.height/e;Math.abs(this.newSize.width/t-1)>Math.abs(s-1)?this.newSize.height=this.newSize.width/i:this.newSize.width=this.newSize.height*i}handlePointerUp(t){if("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._core.store.objects.stopUndoCapturing()),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._core.store.objects.stopUndoCapturing()),this.reset();const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t)}}}class Wo extends Lo{initialRotation=0;rotation=0;initialSelectionGroupRotation=0;constructor(t){super(t)}reset(){this.initialRotation=0,this.rotation=0}handlePointerDown(t){if("mouse"===t.pointerType&&qn.isLeftClick(t)){const e=this._core.store.selectionGroup;if(e&&this._core.store.state.isRotationHandleSelected){e.beginTransform();const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isRotating=!0;const r=e.scale||1,n=e.translateX+e.width/2/r,o=e.translateY+e.height/2/r,h=(i-this._core.store.state.translateX)/this._core.store.state.scale,l=(s-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=e.rotation,this.initialRotation=Math.atan2(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),s=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isRotating=!0;const r=t.scale||1,n=t.translateX+t.width/2/r,o=t.translateY+t.height/2/r,h=(i-this._core.store.state.translateX)/this._core.store.state.scale,l=(s-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=t.rotation,this.initialRotation=Math.atan2(o-l,n-h)-t.rotation;const a=this._core.store.state.longTouchTimeout;a&&globalThis.clearTimeout?.(a)}}}}handlePointerMove(t){if("mouse"===t.pointerType){const e=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&e){const i=e.scale||1,s=Math.atan2(e.translateY+e.height/2/i-(t.clientY-this._core.store.offsetY-this._core.store.state.translateY)/this._core.store.state.scale,e.translateX+e.width/2/i-(t.clientX-this._core.store.offsetX-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=s-this.initialRotation,e.rotate(this.rotation)}}if("touch"===t.pointerType||"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),s=Math.round(t.clientY-this._core.store.offsetY),r=e.scale||1,n=Math.atan2(e.translateY+e.height/2/r-(s-this._core.store.state.translateY)/this._core.store.state.scale,e.translateX+e.width/2/r-(i-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=n-this.initialRotation,e.rotate(this.rotation);const o=this._core.store.state.longTouchTimeout;o&&globalThis.clearTimeout?.(o)}}}handlePointerUp(t){if("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._core.store.objects.stopUndoCapturing(),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._core.store.objects.stopUndoCapturing(),this.reset();const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t)}}}class Vo extends n{__class__="KritzelSelectionBox";static create(t){const e=new Vo;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 Ko extends Lo{startX=0;startY=0;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&&(!qn.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),s=Math.abs(e-this.touchStartX),r=Math.abs(i-this.touchStartY),n=5;if((s>n||r>n)&&this._core.store.state.isSelecting){this.updateTouchSelection();const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t)}}}handlePointerUp(t){if("mouse"===t.pointerType&&qn.isLeftClick(t)){const e=this._core.store.state.hasObjectsChanged,i=this._core.store.selectionGroup,s=t.shiftKey||t.ctrlKey;if(1!==i?.objects.length||!1!==e||s||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,s=t.shiftKey||t.ctrlKey;if(1!==i?.objects.length||!1!==e||s||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.objects.remove((t=>t instanceof Vo)),this._core.store.setSelectionBox(null),this._core.store.objects.clearLocalSelectionBox()}startMouseSelection(t,e=!1){let i,s;i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;const r=Vo.create(this._core);this.startX=(i-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(s-this._core.store.state.translateY)/this._core.store.state.scale,r.translateX=this.startX,r.translateY=this.startY,this._core.store.state.isSelecting=!0,this._core.store.objects.remove((t=>t instanceof Vo||!e&&t instanceof to&&(null==t.userId||t.userId===this._core.user?.id))),this._core.store.setSelectionBox(null),e||this._core.store.setSelectionGroup(null),this._core.store.objects.insert(r),this._core.store.setSelectionBox(r)}startTouchSelection(t,e=!1){const i=Array.from(this._core.store.state.pointers.values())[0];if(!i)return;let s,r;s=Math.round(i.clientX-this._core.store.offsetX),r=Math.round(i.clientY-this._core.store.offsetY),this.touchStartX=s,this.touchStartY=r;const n=Vo.create(this._core);this.startX=(s-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(r-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.objects.remove((t=>t instanceof Vo||!e&&t instanceof to&&(null==t.userId||t.userId===this._core.user?.id))),this._core.store.setSelectionBox(null),e||this._core.store.setSelectionGroup(null),this._core.store.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 s=this._core.store.selectionBox;if(s){const t=(e-this._core.store.state.translateX)/s.scale,r=(i-this._core.store.state.translateY)/s.scale,n=Math.abs(t-this.startX)*s.scale,o=Math.abs(r-this.startY)*s.scale;s.width=n,s.height=o,s.translateX=Math.min(t,this.startX),s.translateY=Math.min(r,this.startY),this._core.store.objects.setLocalSelectionBox({x:s.translateX,y:s.translateY,width:n/s.scale,height:o/s.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 s=this._core.store.selectionBox;if(s){const t=(e-this._core.store.state.translateX)/s.scale,r=(i-this._core.store.state.translateY)/s.scale,n=Math.abs(t-this.startX)*s.scale,o=Math.abs(r-this.startY)*s.scale;s.width=n,s.height=o,s.translateX=Math.min(t,this.startX),s.translateY=Math.min(r,this.startY),this._core.store.objects.setLocalSelectionBox({x:s.translateX,y:s.translateY,width:n/s.scale,height:o/s.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],s=[e.topLeft.y,e.topRight.y,e.bottomRight.y,e.bottomLeft.y],r=Math.min(...i),n=Math.max(...i),o=Math.min(...s),h=Math.max(...s),l=this._core.store.objects.query({x:r,y:o,z:t.scale,width:n-r,height:h-o}),a=new Set;for(const t of l){if(t instanceof Vo||t instanceof to)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(),e&&this.addObjectToSelectionGroup(e,i),this.removeSelectionBox()}getTopmostHitObject(t){const e=this._core.store.state.pointerX,i=this._core.store.state.pointerY,s=this._core.getObjectsFromPointerEvent(t,".object");for(const t of s)if(!(t instanceof Vo||t instanceof to)&&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=Vn.findParentGroup(this._core,t.id)||t;i.isSelected=!1;const s=this._core.store.selectionGroup;if(e&&s)s.addOrRemove(i),this.removeDescendantsOfSelectedGroups(s),0===s.objects.length?this._core.removeSelectionGroup():this._core.rerender();else{const t=to.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.objects.filter((t=>"KritzelGroup"===t.__class__)),s=new Map;for(const t of i)for(const e of t.childIds)s.set(e,t);const r=new Map;for(const t of e){const e=s.get(t.id)||t;r.set(e.id,e),t.isSelected=!1}const n=Array.from(r.values()),o=this.filterDescendantsOfSelectedGroups(n),h=this._core.store.selectionGroup;if(t&&h)h.addObjects(o),this.removeDescendantsOfSelectedGroups(h),this._core.rerender();else{const t=to.create(this._core);t.objectIds=o.map((t=>t.id)),1===t.length&&(t.rotation=t.objects[0].rotation),t.captureUnchangedSnapshots(),t.refreshObjectDimensions(),t.isSelected=!0,this._core.addSelectionGroup(t),this._core.rerender()}}filterDescendantsOfSelectedGroups(t){const e=new Set;for(const i of t)i instanceof Vn&&Vn.collectDescendantIds(i,e);return 0===e.size?t:t.filter((t=>!e.has(t.id)))}removeDescendantsOfSelectedGroups(t){const e=this.filterDescendantsOfSelectedGroups(t.objects);e.length!==t.objects.length&&(t.objectIds=e.map((t=>t.id)))}}class Jo extends Lo{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 Qo extends Lo{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&&qn.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,s=t.clientY-this._core.store.offsetY;this._core.store.state.isLineHandleDragging=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialStartX=e.startX,this.initialStartY=e.startY,this.initialEndX=e.endX,this.initialEndY=e.endY,this.initialControlX=e.controlX,this.initialControlY=e.controlY,this.initialTranslateX=e.translateX,this.initialTranslateY=e.translateY;const r=this._core.store.state.lineHandleType;"start"!==r&&"end"!==r||this._core.anchorManager.removeAnchor(e.id,r);const n=this._core.store.state.longTouchTimeout;n&&globalThis.clearTimeout?.(n)}handlePointerMove(t){const e=this.getSelectedLine();if(!e||!this._core.store.state.isLineHandleDragging)return;const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY,r=i-this.initialMouseX,n=s-this.initialMouseY;if((Math.abs(r)>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=r/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,r=(s-this._core.store.state.translateY)/o,n=e.endAnchor?.objectId,h=this._core.anchorManager.findSnapTarget(t,r,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),s=this._core.store.allNonSelectionObjects.find((t=>t.id===h.objectId));let r,n,o,l;if(s){const t=this._core.anchorManager.computeAnchorClipInfo(e,"start",s);t&&(r=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:r,edgeY:n,lineStroke:$n.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,r=(s-this._core.store.state.translateY)/o,n=e.startAnchor?.objectId,h=this._core.anchorManager.findSnapTarget(t,r,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),s=this._core.store.allNonSelectionObjects.find((t=>t.id===h.objectId));let r,n,o,l;if(s){const t=this._core.anchorManager.computeAnchorClipInfo(e,"end",s);t&&(r=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:r,edgeY:n,lineStroke:$n.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,s=e.startX,r=e.startY,n=e.endX,o=e.endY,h=n-s,l=o-r,a=h*h+l*l;let u,c,f=-1;0!==a&&(f=((t-s)*h+(i-r)*l)/a),f<0?(u=s,c=r):f>1?(u=n,c=o):(u=s+f*h,c=r+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 s=(e-t.translateX)*t.scale,r=(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:(s-n)*h-(r-o)*l+n+t.x,y:(s-n)*l+(r-o)*h+o+t.y}}lineLocalToWorld(t,e,i){const s=e-t.x,r=i-t.y,n=t.totalWidth/2,o=t.totalHeight/2,h=Math.cos(t.rotation),l=Math.sin(t.rotation);return{x:((s-n)*h-(r-o)*l+n)/t.scale+t.translateX,y:((s-n)*l+(r-o)*h+o)/t.scale+t.translateY}}updateLineEndpoint(t,e,i,s,r){const{minX:n,minY:o,maxX:h,maxY:l}=Yn.calculateBoundingBox(e,i,s,r,t.controlX,t.controlY,t.strokeWidth),a=h-n,u=l-o,{minX:c,minY:f,maxX:d,maxY:p}=Yn.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=s,t.endY=r,t.x=n,t.y=o,t.width=a,t.height=u,t.translateX=x,t.translateY=C,t._adjustedPoints=null,this._core.store.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.objects.stopUndoCapturing()}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 Yn?e:null}}class qo extends Gn{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)Wn.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 Un)return e.fill;if(e instanceof Yn)return e.stroke;if(e instanceof Pn)return e.fontColor;if(e instanceof Qn)return e.strokeColor}return An[0]}set color(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Un&&this._core.updateObject(e,{fill:t}),e instanceof Yn&&this._core.updateObject(e,{stroke:t}),e instanceof Pn&&this._core.updateObject(e,{fontColor:t}),e instanceof Qn&&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 Un)return e.strokeWidth;if(e instanceof Yn)return e.strokeWidth;if(e instanceof Pn)return e.fontSize;if(e instanceof Qn)return e.strokeWidth}return 1}set size(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Un&&this._core.updateObject(e,{strokeWidth:t}),e instanceof Yn&&this._core.updateObject(e,{strokeWidth:t}),e instanceof Pn&&this._core.updateObject(e,{fontSize:t}),e instanceof Qn&&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 Qn)return e.fillColor;return{light:"transparent",dark:"transparent"}}set fillColor(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{if(e instanceof Qn){const i=$n.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 Qn)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 Qn&&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 Yn)return e.arrows??{start:{enabled:!1},end:{enabled:!1}};return{start:{enabled:!1},end:{enabled:!1}}}set arrows(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Yn&&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 Qn)),s=t.some((t=>t instanceof Pn)),r=t.some((t=>t instanceof Yn)),n=t.some((t=>t instanceof Xn)),o=t.some((t=>t instanceof Un||t instanceof Yn||t instanceof Qn));return!n||i||s||r||o?(s&&!o?(e.push({type:"font-size",propertyName:"size"}),e.push({type:"font-family",propertyName:"fontFamily"})):o&&!s?e.push({type:"stroke-size",propertyName:"size"}):(o&&e.push({type:"stroke-size",propertyName:"size"}),s&&e.push({type:"font-family",propertyName:"fontFamily"})),r&&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 Ko(this._core),this.moveHandler=new Ho(this._core),this.hoverHandler=new Jo(this._core),this.resizeHandler=new Yo(this._core),this.rotationHandler=new Wo(this._core),this.lineHandleHandler=new Qo(this._core)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){if(qn.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,s=e&&i&&e.id!==i.id,r=t.shiftKey||t.ctrlKey;!i&&e&&(this._core.store.state.skipContextMenu=!0),null!==e&&!s||!i||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||r||(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=e?.id?this._core.findObjectById(e.id):null;if(!i)return null;const{x:s,y:r}=this._core.getCanvasPoint(t);if(!i.hitTest(s,r))return null;if(i instanceof to)return i;{const t=to.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 Go{type="local";provider;isConnected=!1;constructor(e,i,s){this.provider=new t(s?.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 Zo=Math.floor,th=127,eh=Number.MAX_SAFE_INTEGER,ih="undefined"!=typeof TextEncoder?new TextEncoder:null,sh=ih?t=>ih.encode(t):t=>{const e=unescape(encodeURIComponent(t)),i=e.length,s=new Uint8Array(i);for(let t=0;t<i;t++)s[t]=e.codePointAt(t);return s};let rh="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});rh&&1===rh.decode(new Uint8Array).length&&(rh=null);const nh=(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},oh=(t,e)=>{for(;e>th;)nh(t,128|th&e),e=Zo(e/128);nh(t,th&e)},hh=new Uint8Array(3e4),lh=hh.length/3,ah=ih&&ih.encodeInto?(t,e)=>{if(e.length<lh){const i=ih.encodeInto(e,hh).written||0;oh(t,i);for(let e=0;e<i;e++)nh(t,hh[e])}else uh(t,sh(e))}:(t,e)=>{const i=unescape(encodeURIComponent(e)),s=i.length;oh(t,s);for(let e=0;e<s;e++)nh(t,i.codePointAt(e))},uh=(t,e)=>{oh(t,e.byteLength),((t,e)=>{const i=t.cbuf.length,s=t.cpos,r=((t,e)=>t<e?t:e)(i-s,e.length),n=e.length-r;t.cbuf.set(e.subarray(0,r),s),t.cpos+=r,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(r)),t.cpos=n)})(t,e)},ch=t=>new Error(t),fh=ch("Unexpected end of array"),dh=ch("Integer out of Range"),ph=t=>t.arr[t.pos++],gh=t=>{let e=0,i=1;const s=t.arr.length;for(;t.pos<s;){const s=t.arr[t.pos++];if(e+=(s&th)*i,i*=128,s<128)return e;if(e>eh)throw dh}throw fh},wh=rh?t=>rh.decode((t=>((t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,i})(t,gh(t)))(t)):t=>{let e=gh(t);if(0===e)return"";{let i=String.fromCodePoint(ph(t));if(--e<100)for(;e--;)i+=String.fromCodePoint(ph(t));else for(;e>0;){const s=e<1e4?e:1e4,r=t.arr.subarray(t.pos,t.pos+s);t.pos+=s,i+=String.fromCodePoint.apply(null,r),e-=s}return decodeURIComponent(escape(i))}};var mh;!function(t){t[t.Token=0]="Token",t[t.PermissionDenied=1]="PermissionDenied",t[t.Authenticated=2]="Authenticated"}(mh||(mh={}));const vh=t=>Array.from(t.entries()).map((([t,e])=>({clientId:t,...e})));var yh;async function kh(t){return new Promise((e=>setTimeout(e,t)))}function bh(t,e){let i=e.delay;if(0===i)return 0;if(e.factor&&(i*=Math.pow(e.factor,t.attemptNum-1),0!==e.maxDelay&&(i=Math.min(i,e.maxDelay))),e.jitter){const t=Math.ceil(e.minDelay),s=Math.floor(i);i=Math.floor(Math.random()*(s-t+1))+t}return Math.round(i)}!function(t){t[t.Connecting=0]="Connecting",t[t.Open=1]="Open",t[t.Closing=2]="Closing",t[t.Closed=3]="Closed"}(yh||(yh={}));const Mh=Math.floor,xh=128,Ch=127,Ah=Number.MAX_SAFE_INTEGER,Sh=()=>new Set,Bh=Array.from,Th="undefined"!=typeof TextEncoder?new TextEncoder:null,Oh=Th?t=>Th.encode(t):t=>{const e=unescape(encodeURIComponent(t)),i=e.length,s=new Uint8Array(i);for(let t=0;t<i;t++)s[t]=e.codePointAt(t);return s};let Eh="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Eh&&1===Eh.decode(new Uint8Array).length&&(Eh=null);class Ih{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const $h=()=>new Ih,Ph=t=>{let e=t.cpos;for(let i=0;i<t.bufs.length;i++)e+=t.bufs[i].length;return e},Dh=t=>{const e=new Uint8Array(Ph(t));let i=0;for(let s=0;s<t.bufs.length;s++){const r=t.bufs[s];e.set(r,i),i+=r.length}return e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),i),e},Rh=(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},jh=(t,e)=>{for(;e>Ch;)Rh(t,xh|Ch&e),e=Mh(e/128);Rh(t,Ch&e)},Fh=new Uint8Array(3e4),Uh=Fh.length/3,Nh=Th&&Th.encodeInto?(t,e)=>{if(e.length<Uh){const i=Th.encodeInto(e,Fh).written||0;jh(t,i);for(let e=0;e<i;e++)Rh(t,Fh[e])}else zh(t,Oh(e))}:(t,e)=>{const i=unescape(encodeURIComponent(e)),s=i.length;jh(t,s);for(let e=0;e<s;e++)Rh(t,i.codePointAt(e))},zh=(t,e)=>{jh(t,e.byteLength),((t,e)=>{const i=t.cbuf.length,s=t.cpos,r=((t,e)=>t<e?t:e)(i-s,e.length),n=e.length-r;t.cbuf.set(e.subarray(0,r),s),t.cpos+=r,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(r)),t.cpos=n)})(t,e)},_h=t=>new Error(t),Lh=_h("Unexpected end of array"),Hh=_h("Integer out of Range");class Xh{constructor(t){this.arr=t,this.pos=0}}const Yh=t=>new Xh(t),Wh=t=>((t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,i})(t,Kh(t)),Vh=t=>t.arr[t.pos++],Kh=t=>{let e=0,i=1;const s=t.arr.length;for(;t.pos<s;){const s=t.arr[t.pos++];if(e+=(s&Ch)*i,i*=128,s<xh)return e;if(e>Ah)throw Hh}throw Lh},Jh=Eh?t=>Eh.decode(Wh(t)):t=>{let e=Kh(t);if(0===e)return"";{let i=String.fromCodePoint(Vh(t));if(--e<100)for(;e--;)i+=String.fromCodePoint(Vh(t));else for(;e>0;){const s=e<1e4?e:1e4,r=t.arr.subarray(t.pos,t.pos+s);t.pos+=s,i+=String.fromCodePoint.apply(null,r),e-=s}return decodeURIComponent(escape(i))}},Qh=Date.now,qh=()=>new Map;class Gh{constructor(){this._observers=qh()}on(t,e){((t,e,i)=>{let s=t.get(e);return void 0===s&&t.set(e,s=i()),s})(this._observers,t,Sh).add(e)}once(t,e){const i=(...s)=>{this.off(t,i),e(...s)};this.on(t,i)}off(t,e){const i=this._observers.get(t);void 0!==i&&(i.delete(e),0===i.size&&this._observers.delete(t))}emit(t,e){return Bh((this._observers.get(t)||qh()).values()).forEach((t=>t(...e)))}destroy(){this._observers=qh()}}const Zh=Object.keys,tl=t=>Zh(t).length,el=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),il=(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)||!il(t.get(i),e.get(i)))return!1;break;case Object:if(tl(t)!==tl(e))return!1;for(const i in t)if(!el(t,i)||!il(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(!il(t[i],e[i]))return!1;break;default:return!1}return!0};class sl extends Gh{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const t=Qh();null!==this.getLocalState()&&15e3<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const e=[];this.meta.forEach(((i,s)=>{s!==this.clientID&&3e4<=t-i.lastUpdated&&this.states.has(s)&&e.push(s)})),e.length>0&&rl(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),s=void 0===i?0:i.clock+1,r=this.states.get(e);null===t?this.states.delete(e):this.states.set(e,t),this.meta.set(e,{clock:s,lastUpdated:Qh()});const n=[],o=[],h=[],l=[];null===t?l.push(e):null==r?null!=t&&n.push(e):(o.push(e),il(r,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 rl=(t,e,i)=>{const s=[];for(let i=0;i<e.length;i++){const r=e[i];if(t.states.has(r)){if(t.states.delete(r),r===t.clientID){const e=t.meta.get(r);t.meta.set(r,{clock:e.clock+1,lastUpdated:Qh()})}s.push(r)}}s.length>0&&(t.emit("change",[{added:[],updated:[],removed:s},i]),t.emit("update",[{added:[],updated:[],removed:s},i]))},nl=(t,e,i=t.states)=>{const s=e.length,r=$h();jh(r,s);for(let n=0;n<s;n++){const s=e[n],o=i.get(s)||null,h=t.meta.get(s).clock;jh(r,s),jh(r,h),Nh(r,JSON.stringify(o))}return Dh(r)};class ol{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 hl{constructor(t){this.data=t,this.encoder=$h(),this.decoder=Yh(new Uint8Array(this.data))}peekVarString(){return(t=>{const e=t.pos,i=Jh(t);return t.pos=e,i})(this.decoder)}readVarUint(){return Kh(this.decoder)}readVarString(){return Jh(this.decoder)}readVarUint8Array(){return Wh(this.decoder)}writeVarUint(t){return jh(this.encoder,t)}writeVarString(t){return Nh(this.encoder,t)}writeVarUint8Array(t){return zh(this.encoder,t)}length(){return Ph(this.encoder)}}var ll,al;!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"}(ll||(ll={})),function(t){t.Connecting="connecting",t.Connected="connected",t.Disconnected="disconnected"}(al||(al={}));class ul{constructor(){this.encoder=$h()}get(t){return t.encoder}toUint8Array(){return Dh(this.encoder)}}class cl extends ul{constructor(){super(...arguments),this.type=ll.CLOSE,this.description="Ask the server to close the connection"}get(t){return Nh(this.encoder,t.documentName),jh(this.encoder,this.type),this.encoder}}class fl extends ol{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=al.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=al.Connected,this.emit("status",{status:al.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=t}attach(t){this.configuration.providerMap.set(t.configuration.name,t),this.status===al.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===al.Connected&&t.onOpen(this.receivedOnOpenPayload)}detach(t){this.configuration.providerMap.has(t.configuration.name)&&(t.send(cl,{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===al.Connected)return;this.cancelWebsocketRetry&&(this.cancelWebsocketRetry(),this.cancelWebsocketRetry=void 0),this.receivedOnOpenPayload=void 0,this.shouldConnect=!0;const{retryPromise:t,cancelFunc:e}=(()=>{let t=!1;const e=async function(t,e){const i=function(t){return t||(t={}),{delay:void 0===t.delay?200:t.delay,initialDelay:void 0===t.initialDelay?0:t.initialDelay,minDelay:void 0===t.minDelay?0:t.minDelay,maxDelay:void 0===t.maxDelay?0:t.maxDelay,factor:void 0===t.factor?0:t.factor,maxAttempts:void 0===t.maxAttempts?3:t.maxAttempts,timeout:void 0===t.timeout?0:t.timeout,jitter:!0===t.jitter,initialJitter:!0===t.initialJitter,handleError:void 0===t.handleError?null:t.handleError,handleTimeout:void 0===t.handleTimeout?null:t.handleTimeout,beforeAttempt:void 0===t.beforeAttempt?null:t.beforeAttempt,calculateDelay:void 0===t.calculateDelay?null:t.calculateDelay}}(e);for(const t of["delay","initialDelay","minDelay","maxDelay","maxAttempts","timeout"]){const e=i[t];if(!Number.isInteger(e)||e<0)throw new Error(`Value for ${t} must be an integer greater than or equal to 0`)}if(i.factor.constructor!==Number||i.factor<0)throw new Error("Value for factor must be a number greater than or equal to 0");if(i.delay<i.minDelay)throw new Error(`delay cannot be less than minDelay (delay: ${i.delay}, minDelay: ${i.minDelay}`);const s={attemptNum:0,attemptsRemaining:i.maxAttempts?i.maxAttempts:-1,aborted:!1,abort(){s.aborted=!0}},r=i.calculateDelay||bh,n=i.calculateDelay?i.calculateDelay(s,i):i.initialDelay;if(n&&await kh(n),s.attemptNum<1&&i.initialJitter){const t=r(s,i);t&&await kh(t)}return async function e(){if(i.beforeAttempt&&i.beforeAttempt(s,i),s.aborted){const t=new Error("Attempt aborted");throw t.code="ATTEMPT_ABORTED",t}const n=async t=>{if(i.handleError&&await i.handleError(t,s,i),s.aborted||0===s.attemptsRemaining)throw t;s.attemptNum++;const n=r(s,i);return n&&await kh(n),e()};return s.attemptsRemaining>0&&s.attemptsRemaining--,i.timeout?new Promise(((e,r)=>{const o=setTimeout((()=>{if(i.handleTimeout)try{e(i.handleTimeout(s,i))}catch(t){r(t)}else{const t=new Error(`Retry timeout (attemptNum: ${s.attemptNum}, timeout: ${i.timeout})`);t.code="ATTEMPT_TIMEOUT",r(t)}}),i.timeout);t(s,i).then((t=>{clearTimeout(o),e(t)})).catch((t=>{clearTimeout(o),n(t).then(e).catch(r)}))})):t(s,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 s=this.webSocketHandlers[t.identifier];Object.keys(s).forEach((e=>{t.addEventListener(e,s[e])}))}cleanupWebSocket(){if(!this.webSocket)return;const{identifier:t}=this.webSocket,e=this.webSocketHandlers[t];Object.keys(e).forEach((i=>{var s;null===(s=this.webSocket)||void 0===s||s.removeEventListener(i,e[i]),delete this.webSocketHandlers[t]})),this.webSocket.close(),this.webSocket=null}createWebSocketConnection(){return new Promise(((t,e)=>{this.webSocket&&(this.messageQueue=[],this.cleanupWebSocket()),this.lastMessageReceived=0,this.identifier+=1;const i=new this.configuration.WebSocketPolyfill(this.url);i.binaryType="arraybuffer",i.identifier=this.identifier,this.attachWebSocketListeners(i,e),this.webSocket=i,this.status=al.Connecting,this.emit("status",{status:al.Connecting}),this.connectionAttempt={resolve:t,reject:e}}))}onMessage(t){var e;this.resolveConnectionAttempt(),this.lastMessageReceived=Qh();const i=new hl(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=al.Connected,this.emit("status",{status:al.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===al.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=Qh()-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)===yh.Open?this.webSocket.send(t):this.messageQueue.push(t)}onClose({event:t}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=al.Disconnected,this.emit("status",{status:al.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 dl=(t,i,s)=>{try{e.applyUpdate(i,Wh(t),s)}catch(t){console.error("Caught error while handling a Yjs update",t)}},pl=dl;class gl{constructor(t){this.message=t}apply(t,e){const{message:i}=this,s=i.readVarUint(),r=i.length();switch(s){case ll.Sync:this.applySyncMessage(t,e);break;case ll.Awareness:this.applyAwarenessMessage(t);break;case ll.Auth:this.applyAuthMessage(t);break;case ll.QueryAwareness:this.applyQueryAwarenessMessage(t);break;case ll.Stateless:t.receiveStateless(Jh(i.decoder));break;case ll.SyncStatus:this.applySyncStatusMessage(t,1===(t=>{let e=t.arr[t.pos++],i=63&e,s=64;const r=(64&e)>0?-1:1;if(!(e&xh))return r*i;const n=t.arr.length;for(;t.pos<n;){if(e=t.arr[t.pos++],i+=(e&Ch)*s,s*=128,e<xh)return r*i;if(i>Ah)throw Hh}throw Lh})(i.decoder));break;case ll.CLOSE:const r={code:1e3,reason:Jh(i.decoder),target:t.configuration.websocketProvider.webSocket,type:"close"};t.onClose(),t.configuration.onClose({event:r}),t.forwardClose({event:r});break;default:throw new Error(`Can’t apply message of unknown type: ${s}`)}i.length()>r+1&&t.send(ul,{encoder:i.encoder})}applySyncMessage(t,i){const{message:s}=this;s.writeVarUint(ll.Sync);const r=((t,i,s,r)=>{const n=Kh(t);switch(n){case 0:((t,i,s)=>{((t,i,s)=>{jh(t,1),zh(t,e.encodeStateAsUpdate(i,s))})(i,s,Wh(t))})(t,i,s);break;case 1:dl(t,s,r);break;case 2:pl(t,s,r);break;default:throw new Error("Unknown message type")}return n})(s.decoder,s.encoder,t.document,t);i&&1===r&&(t.synced=!0)}applySyncStatusMessage(t,e){e&&t.decrementUnsyncedChanges()}applyAwarenessMessage(t){if(!t.awareness)return;const{message:e}=this;((t,e,i)=>{const s=Yh(e),r=Qh(),n=[],o=[],h=[],l=[],a=Kh(s);for(let e=0;e<a;e++){const e=Kh(s);let i=Kh(s);const a=JSON.parse(Jh(s)),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:r}),void 0===u&&null!==a?n.push(e):void 0!==u&&null===a?l.push(e):null!==a&&(il(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,s)=>{switch(gh(t)){case mh.Token:e();break;case mh.PermissionDenied:i(wh(t));break;case mh.Authenticated:s(wh(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(ll.Awareness),e.writeVarUint8Array(nl(t.awareness,Array.from(t.awareness.getStates().keys())))}}class wl{constructor(t,e={}){this.message=new t,this.encoder=this.message.get(e)}create(){return Dh(this.encoder)}send(t){null==t||t.send(this.create())}}class ml extends ul{constructor(){super(...arguments),this.type=ll.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 Nh(this.encoder,t.documentName),jh(this.encoder,this.type),i=t.token,oh(e=this.encoder,mh.Token),ah(e,i),this.encoder}}class vl extends ul{constructor(){super(...arguments),this.type=ll.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 Nh(this.encoder,t.documentName),jh(this.encoder,this.type),e=void 0===t.states?nl(t.awareness,t.clients):nl(t.awareness,t.clients,t.states),zh(this.encoder,e),this.encoder}}class yl extends ul{constructor(){super(...arguments),this.type=ll.Stateless,this.description="A stateless message"}get(t){var e;return Nh(this.encoder,t.documentName),jh(this.encoder,this.type),Nh(this.encoder,null!==(e=t.payload)&&void 0!==e?e:""),this.encoder}}class kl extends ul{constructor(){super(...arguments),this.type=ll.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 Nh(this.encoder,t.documentName),jh(this.encoder,this.type),((t,i)=>{jh(t,0);const s=e.encodeStateVector(i);zh(t,s)})(this.encoder,t.document),this.encoder}}class bl extends ul{constructor(){super(...arguments),this.type=ll.Sync,this.description="A document update"}get(t){var e,i;return Nh(this.encoder,t.documentName),jh(this.encoder,this.type),i=t.update,jh(e=this.encoder,2),zh(e,i),this.encoder}}class Ml extends Error{constructor(){super(...arguments),this.code=1001}}class xl extends ol{constructor(t){var i,s,r;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 sl(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:vh(this.awareness.getStates())})})),null===(s=this.awareness)||void 0===s||s.on("change",(()=>{this.emit("awarenessChange",{states:vh(this.awareness.getStates())})})),this.document.on("update",this.boundDocumentUpdateHandler),null===(r=this.awareness)||void 0===r||r.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 fl(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(kl,{document:this.document,documentName:this.configuration.name})}pageHide(){this.awareness&&rl(this.awareness,[this.document.clientID],"page hide")}registerEventListeners(){"undefined"!=typeof window&&"addEventListener"in window&&window.addEventListener("pagehide",this.boundPageHide)}sendStateless(t){this.send(yl,{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(ml,{token:null!=t?t:"",documentName:this.configuration.name})}documentUpdateHandler(t,e){e!==this&&(this.incrementUnsyncedChanges(),this.send(bl,{update:t,documentName:this.configuration.name}))}awarenessUpdateHandler({added:t,updated:e,removed:i},s){const r=t.concat(e).concat(i);this.send(vl,{awareness:this.awareness,clients:r,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(kl,{document:this.document,documentName:this.configuration.name}),this.awareness&&null!==this.awareness.getLocalState()&&this.send(vl,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.configuration.name})}send(t,e){if(!this._isAttached)return;const i=new wl(t,e);this.emit("outgoingMessage",{message:i.message}),i.send(this.configuration.websocketProvider)}onMessage(t){const e=new hl(t.data),i=e.readVarString();e.writeVarString(i),this.emit("message",{event:t,message:new hl(t.data)}),new gl(e).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&rl(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&&(rl(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 Cl="1.2.0";class Al{__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 Al(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:Cl,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 Sl{_core;_anchorIndex=new Map;constructor(t){this._core=t}setAnchor(t,e,i){const s=this.getLineById(t);if(!s)return;if("start"===e&&s.endAnchor?.objectId===i)return;if("end"===e&&s.startAnchor?.objectId===i)return;this.removeAnchor(t,e);const r={objectId:i};"start"===e?s.startAnchor=r:s.endAnchor=r,this.addToIndex(i,t,e),this.snapEndpointToObject(s,e,i),this._core.store.objects.update(s)}removeAnchor(t,e){const i=this.getLineById(t);if(!i)return;const s="start"===e?i.startAnchor:i.endAnchor;s&&(this.removeFromIndex(s.objectId,t,e),"start"===e?i.startAnchor=void 0:i.endAnchor=void 0)}getAnchor(t,e){const i=this.getLineById(t);return i?("start"===e?i.startAnchor:i.endAnchor)??null:null}getLinesAnchoredTo(t){const e=this._anchorIndex.get(t);return e?Array.from(e):[]}updateAnchorsForObject(t){const e=this.getLinesAnchoredTo(t);if(0!==e.length&&this.getObjectById(t))for(const i of e){const e=this.getLineById(i.lineId);e&&this.snapEndpointToObject(e,i.endpoint,t)}}snapEndpointToObject(t,e,i){const s=this.getObjectById(i);if(!s)return;const r=this.worldToLineLocal(t,s.centerX,s.centerY);t.updateEndpoint(e,r.x,r.y)}worldToLineLocal(t,e,i){const s=e-t.centerX,r=i-t.centerY,n=Math.cos(-t.rotation),o=Math.sin(-t.rotation);return{x:(s*n-r*o+t.totalWidth/2/t.scale)*t.scale+t.x,y:(s*o+r*n+t.totalHeight/2/t.scale)*t.scale+t.y}}findSnapTarget(t,e,i,s){let n=null,o=-1/0;const h=this._core.store.allNonSelectionObjects;for(const l of h){if(l.id===i)continue;if(s&&l.id===s)continue;if(!this.isAnchorable(l))continue;const h=l.rotatedPolygon;r.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(!Wn.isInstanceOf(e,"KritzelLine"))return null;const i=e,s=this.computeAnchorVisualization(i,"start"),r=this.computeAnchorVisualization(i,"end"),n=this.isFiniteAnchorVisualization(s)?s:null,o=this.isFiniteAnchorVisualization(r)?r: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,s=""+2/e,r=this.areFiniteNumbers(t.lineStrokeWidth)&&t.lineStrokeWidth>0?t.lineStrokeWidth:4/e,n=`${r}`,o=Math.max(2*r,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,s=Math.sqrt(e*e+i*i);s>p&&(f=u+e/s*p,d=c+i/s*p);const r=u-t.lineEndpointX,n=c-t.lineEndpointY,o=Math.sqrt(r*r+n*n);if(o>0){const t=r/o,e=n/o,i=-e,s=u,h=c,l=s-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(s,h,d,g,w,m)&&(a=`${s},${h} ${d},${g} ${w},${m}`)}}if(!this.areFiniteNumbers(i,r,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:s,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.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 Yn&&(e.startAnchor&&this.addToIndex(e.startAnchor.objectId,e.id,"start"),e.endAnchor&&this.addToIndex(e.endAnchor.objectId,e.id,"end"))}addToIndex(t,e,i){this._anchorIndex.has(t)||this._anchorIndex.set(t,new Set);const s=this._anchorIndex.get(t);for(const t of s)if(t.lineId===e&&t.endpoint===i)return;s.add({lineId:e,endpoint:i})}removeFromIndex(t,e,i){const s=this._anchorIndex.get(t);if(s){for(const t of s)if(t.lineId===e&&t.endpoint===i){s.delete(t);break}0===s.size&&this._anchorIndex.delete(t)}}getLineById(t){const e=this._core.store.objects.filter((e=>e.id===t));if(0===e.length)return null;const i=e[0];return i instanceof Yn?i:null}getObjectById(t){const e=this._core.store.objects.filter((e=>e.id===t));return e.length>0?e[0]:null}findAnchorTarget(t,e){const i="start"===e?t.startAnchor:t.endAnchor;return i?this._core.store.allNonSelectionObjects.find((t=>t.id===i.objectId))??null:null}computeAnchorVisualization(t,e){if(!("start"===e?t.startAnchor:t.endAnchor))return null;const i=this.findAnchorTarget(t,e);if(!i)return null;const s=this.computeAnchorClipInfo(t,e,i);if(!s)return null;const r=i.centerX,n=i.centerY;if(!this.areFiniteNumbers(s.worldX,s.worldY,r,n))return null;const o=this.buildAnchorPath(t,e,s,i)??void 0;return o&&!this.isFinitePathData(o)?null:{edgeX:s.worldX,edgeY:s.worldY,centerX:r,centerY:n,pathD:o}}computeClippedLinePath(t,e=!1){const i=this.getSnapCandidate(),s=this._core.store.selectionGroup,r=i&&s&&1===s.objects.length&&s.objects[0].id===t.id;if(!t.startAnchor&&!t.endAnchor&&!r)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(r&&void 0!==i.edgeX&&void 0!==i.edgeY){const e=this.lineWorldToLocal(t,i.edgeX,i.edgeY),s={worldX:i.edgeX,worldY:i.edgeY,localX:e.x,localY:e.y,t:i.t};"start"===i.endpoint?h=s:l=s}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"),s=this.evaluateDerivativeSpeedAtT(t,e);s>0&&(e+=i/s)}if(l&&t.hasEndArrow){const e=t.getArrowSize("end"),s=this.evaluateDerivativeSpeedAtT(t,i);s>0&&(i-=e/s)}if(e<0&&(e=0),i>1&&(i=1),i<=e){const t=(e+i)/2;e=t,i=t}const s=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},e,i);return`M ${s.start.x-a} ${s.start.y-u} Q ${s.control.x-a} ${s.control.y-u} ${s.end.x-a} ${s.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,s=p-f,r=Math.sqrt(i*i+s*s);r>e&&(c+=i/r*e,f+=s/r*e)}if(l&&t.hasEndArrow){const e=t.getArrowSize("end"),i=c-d,s=f-p,r=Math.sqrt(i*i+s*s);r>e&&(d+=i/r*e,p+=s/r*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 s="start"===e?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY),n=this.getPathClipPoint(i,s);if(n){const i=this.lineWorldToLocal(t,n.x,n.y),s=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),r=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:s>0?r/s:"start"===e?0:1}}const o=this.getClipPolygonForObject(i);let h;if(h=o?r.getLinePointsArrayIntersection(s,{x:i.centerX,y:i.centerY},o):r.getLinePolygonIntersection(s,{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(Wn.isInstanceOf(i,"KritzelPath"))return this.findCurveExitPointForPath(t,e,i);const s=this.getClipPolygonForObject(i),n=s??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=s?r.getLinePointsArrayIntersection(h,{x:i.centerX,y:i.centerY},s):r.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 s="start"===e?0:1,n=this.evaluateLineAtT(t,s);let o=r.isPointInPolygon({x:n.worldX,y:n.worldY},i),h=s;for(let s=1;s<=64;s++){const n="start"===e?s/64:1-s/64,l=this.evaluateLineAtT(t,n),a=r.isPointInPolygon({x:l.worldX,y:l.worldY},i);if(o&&!a){const e=this.refineCurveExitParameter(t,i,h,n),s=this.evaluateLineAtT(t,e);return{localX:s.localX,localY:s.localY,worldX:s.worldX,worldY:s.worldY,t:e}}o=a,h=n}return null}findCurveExitPointForPath(t,e,i){const s="start"===e?0:1,r=i.strokeWidth/i.scale/2,n=this.getPathAdjustedPoints(i);if(n.length<1)return null;const o=this.evaluateLineAtT(t,s);let h=this.isPointInPathStroke(o.worldX,o.worldY,n,r),l=s;for(let i=1;i<=64;i++){const s="start"===e?i/64:1-i/64,o=this.evaluateLineAtT(t,s),a=this.isPointInPathStroke(o.worldX,o.worldY,n,r);if(h&&!a){const e=this.refineCurveExitParameterForPath(t,n,r,l,s),i=this.evaluateLineAtT(t,e);return{localX:i.localX,localY:i.localY,worldX:i.worldX,worldY:i.worldY,t:e}}h=a,l=s}return null}refineCurveExitParameterForPath(t,e,i,s,r){let n=s,o=r;for(let s=0;s<8;s++){const s=(n+o)/2,r=this.evaluateLineAtT(t,s);this.isPointInPathStroke(r.worldX,r.worldY,e,i)?n=s:o=s}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),s=Math.sin(e),r=t.points.map((t=>t[0])),n=t.points.map((t=>t[1])),o={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...n)+Math.max(...n))/2},{x:h,y:l}=o;return t.points.map((([t,e])=>{const r=t-h,n=e-l;return[h+r*i-n*s,l+r*s+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,s){if(1===i.length){const r=i[0],n=t-r[0],o=e-r[1];return Math.sqrt(n*n+o*o)<=s}for(let r=0;r<i.length-1;r++){const n=i[r],o=i[r+1];if(this.pointToSegmentDistance(t,e,n[0],n[1],o[0],o[1])<=s)return!0}return!1}pointToSegmentDistance(t,e,i,s,r,n){const o=r-i,h=n-s,l=o*o+h*h;if(0===l)return Math.sqrt((t-i)*(t-i)+(e-s)*(e-s));let a=((t-i)*o+(e-s)*h)/l;a=Math.max(0,Math.min(1,a));const u=i+a*o,c=s+a*h;return Math.sqrt((t-u)*(t-u)+(e-c)*(e-c))}refineCurveExitParameter(t,e,i,s){let n=i,o=s;for(let i=0;i<8;i++){const i=(n+o)/2,s=this.evaluateLineAtT(t,i);r.isPointInPolygon({x:s.worldX,y:s.worldY},e)?n=i:o=i}return(n+o)/2}approximateParameterForWorldPoint(t,e){let i=0,s=1/0;for(let r=0;r<=80;r++){const n=r/80,o=this.evaluateLineAtT(t,n),h=Math.hypot(o.worldX-e.x,o.worldY-e.y);h<s&&(s=h,i=n)}return i}evaluateLineAtT(t,e){const i=Math.max(0,Math.min(1,e));let s,r;if(void 0!==t.controlX&&void 0!==t.controlY){const e=1-i;s=e*e*t.startX+2*e*i*t.controlX+i*i*t.endX,r=e*e*t.startY+2*e*i*t.controlY+i*i*t.endY}else s=t.startX+(t.endX-t.startX)*i,r=t.startY+(t.endY-t.startY)*i;const n=this.lineLocalToWorld(t,s,r);return{t:i,localX:s,localY:r,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,s=t.controlY,r=2*(1-i)*(e-t.startX)+2*i*(t.endX-e),n=2*(1-i)*(s-t.startY)+2*i*(t.endY-s);return Math.sqrt(r*r+n*n)}{const e=t.endX-t.startX,i=t.endY-t.startY;return Math.sqrt(e*e+i*i)}}extractQuadraticSegment(t,e,i,s,r){let n=Math.max(0,Math.min(1,s)),o=Math.max(0,Math.min(1,r));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)),s=t.start,r=t.control,n=t.end,o=this.lerpPoint(s,r,i),h=this.lerpPoint(r,n,i),l=this.lerpPoint(o,h,i);return{left:{start:s,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,s){if(void 0===t.controlX||void 0===t.controlY||void 0===i.t)return`M ${i.worldX} ${i.worldY} L ${s.centerX} ${s.centerY}`;const r="start"===e?0:i.t,n="start"===e?i.t:1;if(n<=r)return`M ${i.worldX} ${i.worldY} L ${s.centerX} ${s.centerY}`;const o=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},r,n);return this.buildWorldQuadraticPath(t,o,"start"===e)}buildWorldQuadraticPath(t,e,i=!1){const s=i?e.end:e.start,r=i?e.start:e.end,n=e.control,o=this.lineLocalToWorld(t,s.x,s.y),h=this.lineLocalToWorld(t,n.x,n.y),l=this.lineLocalToWorld(t,r.x,r.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 Wn.isInstanceOf(t,"KritzelShape")?t.getClipPolygon():null}getPathClipPoint(t,e){return Wn.isInstanceOf(t,"KritzelPath")?t.getClipPoint(e):null}lineLocalToWorld(t,e,i){const s=e-t.x,r=i-t.y,n=t.totalWidth/2,o=t.totalHeight/2,h=Math.cos(t.rotation),l=Math.sin(t.rotation),a=(s-n)*h-(r-o)*l+n,u=(s-n)*l+(r-o)*h+o,c=this.getSafeScale(t.scale);return{x:a/c+t.translateX,y:u/c+t.translateY}}lineWorldToLocal(t,e,i){const s=this.getSafeScale(t.scale),r=(e-t.translateX)*s,n=(i-t.translateY)*s,o=t.totalWidth/2,h=t.totalHeight/2,l=Math.cos(-t.rotation),a=Math.sin(-t.rotation);return{x:(r-o)*l-(n-h)*a+o+t.x,y:(r-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 Vo||t instanceof to)&&!(t instanceof Yn)&&t.isVisible}}const Bl={type:"pen",color:An[0],size:16,palettes:{pen:[...An]}},Tl={color:An[0],size:8,fontFamily:"Arial",palette:[...An]},Ol={color:An[0],size:4,palette:[...An],arrows:{end:{enabled:!0,style:"triangle"}}},El={providers:[_n]};var Il;!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"}(Il||(Il={}));const $l=2,Pl=2;function Dl(t,e,i,s,r,n){const o=n?.quiet??!0,h=e.get("schemaVersion")??0;if(h>=r)return{migrated:!1,fromVersion:h,toVersion:h};const l=s.filter((t=>t.fromVersion>=h&&t.toVersion<=r)).sort(((t,e)=>t.fromVersion-e.fromVersion));return o||console.log(`[Kritzel] Running ${l.length} migration(s) from v${h} to v${r}`),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",r)}),"migration"),o||console.log(`[Kritzel] Migrations complete. Schema now at v${r}`),{migrated:!0,fromVersion:h,toVersion:r}}const Rl=[{fromVersion:1,toVersion:2,migrate(t,e){const i=e.workspaces;i&&i.forEach(((t,e)=>{const s=t?.viewport;if(!s)return;if("centerWorldX"in s)return;const r=s.scale??1,n=s.translateX??0,o=s.translateY??0,h={...t,viewport:{centerWorldX:-n/r||0,centerWorldY:-o/r||0,scale:r}};i.set(e,h)}))}}],jl=[{fromVersion:1,toVersion:2,migrate(t,e){}}];export{Ln as A,Dl as B,$l as C,Bl as D,Rl as E,jl as F,$n as G,xl as H,Go as I,o as J,Pn as K,Jn as L,An as M,to as N,Vo as O,zo as P,h as Q,Lo as R,Kn as S,i as T,n as U,s as V,Cl as W,Wn as X,qn as Y,Gn as Z,fl as a,Un as b,Xn as c,Yn as d,Vn as e,Qn as f,Zn as g,eo as h,io as i,Fo as j,Uo as k,No as l,_o as m,qo as n,Hn as o,_n as p,Al as q,Sl as r,In as s,Tl as t,Ol as u,El as v,Sn as w,Bn as x,Il as y,Pl as z}
|
|
1
|
+
import{IndexeddbPersistence as t}from"y-indexeddb";import*as e from"yjs";class i{static registry={};static registerTool(t,e,i){const s=new e(i);return s.name=t,this.registry[t]=s,s}static getTool(t){return this.registry[t]||(console.warn(`Unknown tool: ${t}`),null)}static getToolByIndex(t){return Object.values(this.registry)[t]??null}}class s{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 r{static doPolygonsIntersect(t,e){const i=[t.bottomLeft,t.bottomRight,t.topRight,t.topLeft],s=[e.bottomLeft,e.bottomRight,e.topRight,e.topLeft];for(const t of i)if(this.isPointInPolygon(t,s))return!0;for(const t of s)if(this.isPointInPolygon(t,i))return!0;for(let t=0;t<i.length;t++){const e=i[t],r=i[(t+1)%i.length];for(let t=0;t<s.length;t++)if(this.intersectLines(e,r,s[t],s[(t+1)%s.length]))return!0}return!1}static isPointInPolygon(t,e){let i=!1;for(let s=0,r=e.length-1;s<e.length;r=s++){const n=e[s].x,o=e[s].y,h=e[r].y;o>t.y!=h>t.y&&t.x<(e[r].x-n)*(t.y-o)/(h-o)+n&&(i=!i)}return i}static intersectLines(t,e,i,s){const r=(e.x-t.x)*(s.y-i.y)-(e.y-t.y)*(s.x-i.x);if(0===r)return!1;const n=((i.x-t.x)*(s.y-i.y)-(i.y-t.y)*(s.x-i.x))/r,o=-((t.x-i.x)*(e.y-t.y)-(t.y-i.y)*(e.x-t.x))/r;return n>=0&&n<=1&&o>=0&&o<=1}static getLineIntersectionPoint(t,e,i,s){const r=(e.x-t.x)*(s.y-i.y)-(e.y-t.y)*(s.x-i.x);if(0===r)return null;const n=((i.x-t.x)*(s.y-i.y)-(i.y-t.y)*(s.x-i.x))/r,o=-((t.x-i.x)*(e.y-t.y)-(t.y-i.y)*(e.x-t.x))/r;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 s=[i.topLeft,i.topRight,i.bottomRight,i.bottomLeft];let r=null,n=1/0;for(let i=0;i<s.length;i++){const o=this.getLineIntersectionPoint(t,e,s[i],s[(i+1)%s.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,r=o)}}return r}static getEllipsePolygonApproximation(t,e,i,s,r=32,n=0){const o=[],h=Math.cos(n),l=Math.sin(n);for(let n=0;n<r;n++){const a=2*Math.PI*n/r,u=i*Math.cos(a),c=s*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 s=null,r=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<r&&(r=e,s=o)}}return s}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],s=Math.min(...e),r=Math.max(...e),n=Math.min(...i),o=Math.max(...i);return{x:s,y:n,z:this.scale,width:r-s,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,s=Math.cos(i),r=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:s*(i-t)-r*(n-e)+t,y:r*(i-t)+s*(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 s.generateUUID()}isInViewport(){const t=this._core.store.state.scale;if(this.boundingBox.width*t*(this.boundingBox.height*t)<.5)return!1;const e=-this._core.store.state.translateX/this._core.store.state.scale,i=-this._core.store.state.translateY/this._core.store.state.scale;return this.rotatedBoundingBox.x<e+this._core.store.state.viewportWidth/this._core.store.state.scale&&this.rotatedBoundingBox.x+this.rotatedBoundingBox.width>e&&this.rotatedBoundingBox.y<i+this._core.store.state.viewportHeight/this._core.store.state.scale&&this.rotatedBoundingBox.y+this.rotatedBoundingBox.height>i}centerInViewport(){const{viewportWidth:t,viewportHeight:e,translateX:i,translateY:s,scale:r}=this._core.store.state,{x:n,y:o,width:h,height:l}=this.rotatedBoundingBox;this.updatePosition(this.translateX+((t/2-i)/r-(n+h/2)),this.translateY+((e/2-s)/r-(o+l/2)))}update(){this._core.store.objects.update(this)}move(t,e,i,s){const r=(e-s)/this._core.store.state.scale;this.translateX+=(t-i)/this._core.store.state.scale,this.translateY+=r,this._core.store.objects.update(this)}resize(t,e,i,s){i<=1||s<=1||(this.width=i,this.height=s,this.translateX=t,this.translateY=e,this._core.store.objects.update(this),this._core.anchorManager.updateAnchorsForObject(this.id))}rotate(t){this.rotation=t,this._core.store.objects.update(this)}clone(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.id,t}copy(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.generateId(),t.isMounted=!1,t}serialize(){const{_core:t,_elementRef:e,element:i,totalWidth:s,totalHeight:r,...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}adoptTransientStateFrom(t){}isClass(t){return this.__class__===t}edit(t){}onAfterUpdate(t){}hitTest(t,e){return!0}hitTestPolygon(t){return r.doPolygonsIntersect(this.rotatedPolygon,t)}updatePosition(t,e){this.translateX=t,this.translateY=e,this._core.store.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"),e&&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"),i=e?.replace(/\s*interactive-widget=resizes-content\s*[,;]?/g,"");void 0!==i&&(i=i.replace(/,(\s*,)+/g,",").replace(/^,/,"").replace(/,$/,"").trim(),t.setAttribute("content",i))}}static onKeyboardVisibleChanged(t){if("visualViewport"in window){const e=.75,i=i=>{const s=i.target,r=o.isMobile(),n=s.height*s.scale/window.screen.height<e;t(r&&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 s=0;;s++){if(s==t.childCount||s==e.childCount)return t.childCount==e.childCount?null:i;let r=t.child(s),n=e.child(s);if(r!=n){if(!r.sameMarkup(n))return i;if(r.isText&&r.text!=n.text){for(let t=0;r.text[t]==n.text[t];t++)i++;return i}if(r.content.size||n.content.size){let t=a(r.content,n.content,i+1);if(null!=t)return t}i+=r.nodeSize}else i+=r.nodeSize}}function u(t,e,i,s){for(let r=t.childCount,n=e.childCount;;){if(0==r||0==n)return r==n?null:{a:i,b:s};let o=t.child(--r),h=e.child(--n),l=o.nodeSize;if(o!=h){if(!o.sameMarkup(h))return{a:i,b:s};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--,s--;return{a:i,b:s}}if(o.content.size||h.content.size){let t=u(o.content,h.content,i-1,s-1);if(t)return t}i-=l,s-=l}else i-=l,s-=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 s=i&&i!=t?this.remove(i):this,r=s.find(t),n=s.content.slice();return-1==r?n.push(i||t,e):(n[r+1]=e,i&&(n[r]=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 s=this.remove(e),r=s.content.slice(),n=s.find(t);return r.splice(-1==n?r.length:n,0,e,i),new l(r)},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,s=0,r){for(let n=0,o=0;o<e;n++){let h=this.content[n],l=o+h.nodeSize;if(l>t&&!1!==i(h,s+o,r||null,n)&&h.content.size){let r=o+1;h.nodesBetween(Math.max(0,t-r),Math.min(h.content.size,e-r),i,s+r)}o=l}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,e,i,s){let r="",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?s?"function"==typeof s?s(o):s:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&l||o.isTextblock)&&i&&(n?n=!1:r+=i),r+=l}),0),r}append(t){if(!t.size)return this;if(!this.size)return t;let e=this.lastChild,i=t.firstChild,s=this.content.slice(),r=0;for(e.isText&&e.sameMarkup(i)&&(s[s.length-1]=e.withText(e.text+i.text),r=1);r<t.content.length;r++)s.push(t.content[r]);return new c(s,this.size+t.size)}cut(t,e=this.size){if(0==t&&e==this.size)return this;let i=[],s=0;if(e>t)for(let r=0,n=0;n<e;r++){let o=this.content[r],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),s+=o.nodeSize),n=h}return new c(i,s)}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 s=this.content.slice(),r=this.size+e.nodeSize-i.nodeSize;return s[t]=e,new c(s,r)}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 s=this.content[e];t(s,i,e),i+=s.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 s=i+this.child(e).nodeSize;if(s>=t)return s==t?d(e+1,s):d(e,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map((t=>t.toJSON())):null}static fromJSON(t,e){if(!e)return 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 s=0;s<t.length;s++){let r=t[s];i+=r.nodeSize,s&&r.isText&&t[s-1].sameMarkup(r)?(e||(e=t.slice(0,s)),e[e.length-1]=r.withText(e[e.length-1].text+r.text)):e&&e.push(r)}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 s=0;s<t.length;s++){let r=t[s];if(this.eq(r))return t;if(this.type.excludes(r.type))e||(e=t.slice(0,s));else{if(r.type.excludes(this.type))return t;!i&&r.type.rank>this.type.rank&&(e||(e=t.slice(0,s)),e.push(this),i=!0),e&&e.push(r)}}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 s=i.create(e.attrs);return i.checkAttrs(s.attrs),s}static sameSet(t,e){if(t==e)return!0;if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].eq(e[i]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&0==t.length)return 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,s=e.openEnd||0;if("number"!=typeof i||"number"!=typeof s)throw new RangeError("Invalid input for Slice.fromJSON");return new m(c.fromJSON(t,e.content),i,s)}static maxOpen(t,e=!0){let i=0,s=0;for(let s=t.firstChild;s&&!s.isLeaf&&(e||!s.type.spec.isolating);s=s.firstChild)i++;for(let i=t.lastChild;i&&!i.isLeaf&&(e||!i.type.spec.isolating);i=i.lastChild)s++;return new m(t,i,s)}}function v(t,e,i){let{index:s,offset:r}=t.findIndex(e),n=t.maybeChild(s),{index:o,offset:h}=t.findIndex(i);if(r==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(s!=o)throw new RangeError("Removing non-flat range");return t.replaceChild(s,n.copy(v(n.content,e-r-1,i-r-1)))}function y(t,e,i,s){let{index:r,offset:n}=t.findIndex(e),o=t.maybeChild(r);if(n==e||o.isText)return s&&!s.canReplace(r,r,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(r,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,s){let r=t.index(s),n=t.node(s);if(r==e.index(s)&&s<t.depth-i.openStart){let o=b(t,e,i,s+1);return n.copy(n.content.replaceChild(r,o))}if(i.content.size){if(i.openStart||i.openEnd||t.depth!=s||e.depth!=s){let{start:r,end:o}=function(t,e){let i=e.depth-t.openStart,s=e.node(i).copy(t.content);for(let t=i-1;t>=0;t--)s=e.node(t).copy(c.from(s));return{start:s.resolveNoCache(t.openStart+i),end:s.resolveNoCache(s.content.size-t.openEnd-i)}}(i,t);return S(n,B(t,r,o,e,s))}{let s=t.parent,r=s.content;return S(s,r.cut(0,t.parentOffset).append(i.content).append(r.cut(e.parentOffset)))}}return S(n,T(t,e,s))}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 s=t.node(i);return M(s,e.node(i)),s}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,s){let r=(e||t).node(i),n=0,o=e?e.index(i):r.childCount;t&&(n=t.index(i),t.depth>i?n++:t.textOffset&&(C(t.nodeAfter,s),n++));for(let t=n;t<o;t++)C(r.child(t),s);e&&e.depth==i&&e.textOffset&&C(e.nodeBefore,s)}function S(t,e){return t.type.checkContent(e),t.copy(e)}function B(t,e,i,s,r){let n=t.depth>r&&x(t,e,r+1),o=s.depth>r&&x(i,s,r+1),h=[];return A(null,t,r,h),n&&o&&e.index(r)==i.index(r)?(M(n,o),C(S(n,B(t,e,i,s,r+1)),h)):(n&&C(S(n,T(t,e,r+1)),h),A(e,i,r,h),o&&C(S(o,T(i,s,r+1)),h)),A(s,null,r,h),new c(h)}function T(t,e,i){let s=[];return A(null,t,i,s),t.depth>i&&C(S(x(t,e,i+1),T(t,e,i+1)),s),A(e,null,i,s),new c(s)}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],s=t.child(e);return i?t.child(e).cut(i):s}get nodeBefore(){let t=this.index(this.depth),e=this.pos-this.path[this.path.length-1];return e?this.parent.child(t).cut(0,e):0==t?null:this.parent.child(t-1)}posAtIndex(t,e){e=this.resolveDepth(e);let i=this.path[3*e],s=0==e?0:this.path[3*e-1]+1;for(let e=0;e<t;e++)s+=i.child(e).nodeSize;return s}marks(){let t=this.parent,e=this.index();if(0==t.content.size)return g.none;if(this.textOffset)return t.child(e).marks;let i=t.maybeChild(e-1),s=t.maybeChild(e);if(!i){let t=i;i=s,s=t}let r=i.marks;for(var n=0;n<r.length;n++)!1!==r[n].type.spec.inclusive||s&&r[n].isInSet(s.marks)||(r=r[n--].removeFromSet(r));return r}marksAcross(t){let e=this.parent.maybeChild(this.index());if(!e||!e.isInline)return null;let i=e.marks,s=t.parent.maybeChild(t.index());for(var r=0;r<i.length;r++)!1!==i[r].type.spec.inclusive||s&&i[r].isInSet(s.marks)||(i=i[r--].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=[],s=0,r=e;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(r),o=r-n;if(i.push(e,t,s+n),!o)break;if(e=e.child(t),e.isText)break;r=o-1,s+=n+1}return new O(e,i,r)}static resolveCached(t,e){let i=$.get(t);if(i)for(let t=0;t<i.elts.length;t++){let s=i.elts[t];if(s.pos==e)return s}else $.set(t,i=new E);let s=i.elts[i.i]=O.resolve(t,e);return i.i=(i.i+1)%I,s}}class E{constructor(){this.elts=[],this.i=0}}const I=12,$=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 D=Object.create(null);class R{constructor(t,e,i,s=g.none){this.type=t,this.attrs=e,this.marks=s,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,s=0){this.content.nodesBetween(t,e,i,s,this)}descendants(t){this.nodesBetween(0,this.content.size,t)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(t,e,i,s){return this.content.textBetween(t,e,i,s)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(t){return this==t||this.sameMarkup(t)&&this.content.eq(t.content)}sameMarkup(t){return this.hasMarkup(t.type,t.attrs,t.marks)}hasMarkup(t,e,i){return this.type==t&&p(this.attrs,e||t.defaultAttrs||D)&&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 s=this.resolve(t),r=this.resolve(e),n=i?0:s.sharedDepth(e),o=s.start(n),h=s.node(n).content.cut(s.pos-o,r.pos-o);return new m(h,s.depth-n,r.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:s}=e.content.findIndex(t);if(e=e.maybeChild(i),!e)return null;if(s==t||e.isText)return e;t-=s+1}}childAfter(t){let{index:e,offset:i}=this.content.findIndex(t);return{node:this.content.maybeChild(e),index:e,offset:i}}childBefore(t){if(0==t)return{node:null,index:0,offset:0};let{index:e,offset:i}=this.content.findIndex(t);if(i<t)return{node:this.content.child(e),index:e,offset:i};let s=this.content.child(e-1);return{node:s,index:e-1,offset:i-s.nodeSize}}resolve(t){return O.resolveCached(this,t)}resolveNoCache(t){return O.resolve(this,t)}rangeHasMark(t,e,i){let s=!1;return e>t&&this.nodesBetween(t,e,(t=>(i.isInSet(t.marks)&&(s=!0),!s))),s}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let t=this.type.name;return this.content.size&&(t+="("+this.content.toStringInner()+")"),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,s=0,r=i.childCount){let n=this.contentMatchAt(t).matchFragment(i,s,r),o=n&&n.matchFragment(this.content,e);if(!o||!o.validEnd)return!1;for(let t=s;t<r;t++)if(!this.type.allowsMarks(i.child(t).marks))return!1;return!0}canReplaceWith(t,e,i,s){if(s&&!this.type.allowsMarks(s))return!1;let r=this.contentMatchAt(t).matchType(i),n=r&&r.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 s=c.fromJSON(t,e.content),r=t.nodeType(e.type).create(e.attrs,s,i);return r.type.checkAttrs(r.attrs),r}}R.prototype.text=void 0;class j extends R{constructor(t,e,i,s){if(super(t,e,null,s),!i)throw new RangeError("Empty text nodes are not allowed");this.text=i}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):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 s=z(i);i.next&&i.err("Unexpected trailing text");let r=function(t){let e=Object.create(null);return function i(s){let r=[];s.forEach((e=>{t[e].forEach((({term:e,to:i})=>{if(!e)return;let s;for(let t=0;t<r.length;t++)r[t][0]==e&&(s=r[t][1]);W(t,i).forEach((t=>{s||r.push([e,s=[]]),-1==s.indexOf(t)&&s.push(t)}))}))}));let n=e[s.join(",")]=new N(s.indexOf(t.length-1)>-1);for(let t=0;t<r.length;t++){let s=r[t][1].sort(Y);n.next.push({type:r[t][0],next:e[s.join(",")]||i(s)})}return n}(W(t,0))}(function(t){let e=[[]];return r(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 s(n,o),r(t(e.expr,o),o),[s(o)]}if("plus"==e.type){let o=i();return r(t(e.expr,n),o),r(t(e.expr,o),o),[s(o)]}if("opt"==e.type)return[s(n)].concat(t(e.expr,n));if("range"==e.type){let o=n;for(let s=0;s<e.min;s++){let s=i();r(t(e.expr,o),s),o=s}if(-1==e.max)r(t(e.expr,o),o);else for(let n=e.min;n<e.max;n++){let n=i();s(o,n),r(t(e.expr,o),n),o=n}return[s(o)]}if("name"==e.type)return[s(n,void 0,e.value)];throw new Error("Unknown expr type")}for(let s=0;;s++){let o=t(e.exprs[s],n);if(s==e.exprs.length-1)return o;r(o,n=i())}}(t,0),i()),e;function i(){return e.push([])-1}function s(t,i,s){let r={term:s,to:i};return e[t].push(r),r}function r(t,e){t.forEach((t=>t.to=e))}}(s));return function(t,e){for(let i=0,s=[t];i<s.length;i++){let t=s[i],r=!t.validEnd,n=[];for(let e=0;e<t.next.length;e++){let{type:i,next:o}=t.next[e];n.push(i.name),!r||i.isText||i.hasRequiredAttrs()||(r=!1),-1==s.indexOf(o)&&s.push(o)}r&&e.err("Only non-generatable nodes ("+n.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(r,i),r}matchType(t){for(let e=0;e<this.next.length;e++)if(this.next[e].type==t)return this.next[e].next;return null}matchFragment(t,e=0,i=t.childCount){let s=this;for(let r=e;s&&r<i;r++)s=s.matchType(t.child(r).type);return s}get inlineContent(){return 0!=this.next.length&&this.next[0].type.isInline}get defaultType(){for(let t=0;t<this.next.length;t++){let{type:e}=this.next[t];if(!e.isText&&!e.hasRequiredAttrs())return e}return null}compatible(t){for(let e=0;e<this.next.length;e++)for(let i=0;i<t.next.length;i++)if(this.next[e].type==t.next[i].type)return!0;return!1}fillBefore(t,e=!1,i=0){let s=[this];return function r(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==s.indexOf(i)){s.push(i);let t=r(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 s=i.shift(),r=s.match;if(r.matchType(t)){let t=[];for(let e=s;e.type;e=e.via)t.push(e.type);return t.reverse()}for(let t=0;t<r.next.length;t++){let{type:n,next:o}=r.next[t];n.isLeaf||n.hasRequiredAttrs()||n.name in e||s.type&&!o.validEnd||(i.push({match:n.contentMatch,type:n,via:s}),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 s=0;s<i.next.length;s++)-1==t.indexOf(i.next[s].next)&&e(i.next[s].next)}(this),t.map(((e,i)=>{let s=i+(e.validEnd?"*":" ")+" ";for(let i=0;i<e.next.length;i++)s+=(i?", ":"")+e.next[i].type.name+"->"+t.indexOf(e.next[i].next);return s})).join("\n")}}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(_(t))}while(t.eat("|"));return 1==e.length?e[0]:{type:"choice",exprs:e}}function _(t){let e=[];do{e.push(L(t))}while(t.next&&")"!=t.next&&"|"!=t.next);return 1==e.length?e[0]:{type:"seq",exprs:e}}function L(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,s=i[e];if(s)return[s];let r=[];for(let t in i){let s=i[t];s.isInGroup(e)&&r.push(s)}return 0==r.length&&t.err("No node type or group '"+e+"' found"),r}(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),s=i;return t.eat(",")&&(s="}"!=t.next?H(t):-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:i,max:s,expr:e}}function Y(t,e){return e-t}function W(t,e){let i=[];return function e(s){let r=t[s];if(1==r.length&&!r[0].term)return e(r[0].to);i.push(s);for(let t=0;t<r.length;t++){let{term:s,to:n}=r[t];s||-1!=i.indexOf(n)||e(n)}}(e),i.sort(Y)}function V(t){let e=Object.create(null);for(let i in t){let s=t[i];if(!s.hasDefault)return null;e[i]=s.default}return e}function K(t,e){let i=Object.create(null);for(let s in t){let r=e&&e[s];if(void 0===r){let e=t[s];if(!e.hasDefault)throw new RangeError("No value supplied for attribute "+s);r=e.default}i[s]=r}return i}function J(t,e,i){for(let s in e)if(!(s in t))throw new RangeError(`Unsupported attribute ${s} for ${i} of type ${s}`);for(let i in t){let s=t[i];s.validate&&s.validate(e[i])}}function Q(t,e){let i=Object.create(null);if(e)for(let s in e)i[s]=new G(t,s,e[s]);return i}let q=class t{constructor(t,e,i){this.name=t,this.schema=e,this.spec=i,this.markSet=null,this.groups=i.group?i.group.split(" "):[],this.attrs=Q(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:K(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 s=this.contentMatch.matchFragment(e),r=s&&s.fillBefore(c.empty,!0);return r?new R(this,t,e.append(r),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){J(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 s=Object.create(null);e.forEach(((e,r)=>s[e]=new t(e,i,r)));let r=i.spec.topNode||"doc";if(!s[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!s.text)throw new RangeError("Every schema needs a 'text' type");for(let t in s.text.attrs)throw new RangeError("The text node type should not have attributes");return s}};class 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 s=i.split("|");return i=>{let r=null===i?"null":typeof i;if(s.indexOf(r)<0)throw new RangeError(`Expected value of type ${s} for attribute ${e} on type ${t}, got ${r}`)}}(t,e,i.validate):i.validate}get isRequired(){return!this.hasDefault}}class Z{constructor(t,e,i,s){this.name=t,this.rank=e,this.schema=i,this.spec=s,this.attrs=Q(t,s.attrs),this.excluded=null;let r=V(this.attrs);this.instance=r?new g(this,r):null}create(t=null){return!t&&this.instance?this.instance:new g(this,K(this.attrs,t))}static compile(t,e){let i=Object.create(null),s=0;return t.forEach(((t,r)=>i[t]=new Z(t,s++,e,r))),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){J(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],s=e.spec.content||"",r=e.spec.marks;if(e.contentMatch=i[s]||(i[s]=N.parse(s,this.nodes)),e.inlineContent=e.contentMatch.inlineContent,e.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!e.isInline||!e.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=e}e.markSet="_"==r?null:r?et(this,r.split(" ")):""!=r&&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,s){if("string"==typeof t)t=this.nodeType(t);else{if(!(t instanceof q))throw new RangeError("Invalid node type: "+t);if(t.schema!=this)throw new RangeError("Node type from different schema used ("+t.name+")")}return t.createChecked(e,i,s)}text(t,e){let i=this.nodes.text;return new 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 s=0;s<e.length;s++){let r=e[s],n=t.marks[r],o=n;if(n)i.push(n);else for(let e in t.marks){let s=t.marks[e];("_"==r||s.spec.group&&s.spec.group.split(" ").indexOf(r)>-1)&&i.push(o=s)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[s]+"'")}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 s=i?this.tags.indexOf(i)+1:0;s<this.tags.length;s++){let i=this.tags[s];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,s){for(let r=s?this.styles.indexOf(s)+1:0;r<this.styles.length;r++){let s=this.styles[r],n=s.style;if(!(0!=n.indexOf(t)||s.context&&!i.matchesContext(s.context)||n.length>t.length&&(61!=n.charCodeAt(t.length)||n.slice(t.length+1)!=e))){if(s.getAttrs){let t=s.getAttrs(e);if(!1===t)continue;s.attrs=t||void 0}return s}}}static schemaRules(t){let e=[];function i(t){let i=null==t.priority?50:t.priority,s=0;for(;s<e.length;s++){let t=e[s];if((null==t.priority?50:t.priority)<i)break}e.splice(s,0,t)}for(let e in t.marks){let s=t.marks[e].spec.parseDOM;s&&s.forEach((t=>{i(t=ut(t)),t.mark||t.ignore||t.clearMark||(t.mark=e)}))}for(let e in t.nodes){let s=t.nodes[e].spec.parseDOM;s&&s.forEach((t=>{i(t=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 st={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},rt={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,s,r,n){this.type=t,this.attrs=e,this.marks=i,this.solid=s,this.options=n,this.content=[],this.activeMarks=g.none,this.match=r||(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&&!st.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 s,r=e.topNode,n=ot(null,e.preserveWhitespace,0)|(i?4:0);s=r?new ht(r.type,r.attrs,g.none,!0,e.topMatch||r.type.contentMatch,n):new ht(i?null:t.schema.topNodeType,null,g.none,!0,null,n),this.nodes=[s],this.find=e.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t,e){3==t.nodeType?this.addTextNode(t,e):1==t.nodeType&&this.addElement(t,e)}addTextNode(t,e){let i=t.nodeValue,s=this.top,r=2&s.options?"full":this.localPreserveWS||(1&s.options)>0,{schema:n}=this.parser;if("full"===r||s.inlineContext(t)||/[^ \t\r\n\u000c]/.test(i)){if(r)if("full"===r)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=s.content[s.content.length-1],r=t.previousSibling;(!e||r&&"BR"==r.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 s=this.localPreserveWS,r=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:rt.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,s=this.needsBlock;if(st.hasOwnProperty(o))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),i=!0,r.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(r),this.needsBlock=s}else{let i=this.readStyles(t,e);i&&this.addElementByRule(t,h,i,!1===h.consuming?n:void 0)}this.localPreserveWS=s}leafFallback(t,e){"BR"==t.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode("\n"),e)}ignoreFallback(t,e){"BR"!=t.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),e,!0)}readStyles(t,e){let i=t.style;if(i&&i.length)for(let t=0;t<this.parser.matchedStyles.length;t++){let s=this.parser.matchedStyles[t],r=i.getPropertyValue(s);if(r)for(let t;;){let i=this.parser.matchStyle(s,r,this,t);if(!i)break;if(i.ignore)return null;if(e=i.clearMark?e.filter((t=>!i.clearMark(t))):e.concat(this.parser.schema.marks[i.mark].create(i.attrs)),!1!==i.consuming)break;t=i}}return e}addElementByRule(t,e,i,s){let r,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&&(r=!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(s)this.addElement(t,i,s);else if(e.getContent)this.findInside(t),e.getContent(t,this.parser.schema).forEach((t=>this.insertNode(t,i,!1)));else{let s=t;"string"==typeof e.contentElement?s=t.querySelector(e.contentElement):"function"==typeof e.contentElement?s=e.contentElement(t):e.contentElement&&(s=e.contentElement),this.findAround(t,s,!0),this.addAll(s,i),this.findAround(t,s,!1)}r&&this.sync(o)&&this.open--}addAll(t,e,i,s){let r=i||0;for(let n=i?t.childNodes[i]:t.firstChild,o=null==s?null:t.childNodes[s];n!=o;n=n.nextSibling,++r)this.findAtPoint(t,r),this.addDOM(n,e);this.findAtPoint(t,r)}findPlace(t,e,i){let s,r;for(let e=this.open,n=0;e>=0;e--){let o=this.nodes[e],h=o.findWrapping(t);if(h&&(!s||s.length>h.length+n)&&(s=h,r=o,!h.length))break;if(o.solid){if(i)break;n+=2}}if(!s)return null;this.sync(r);for(let t=0;t<s.length;t++)e=this.enterInner(s[t],null,e,!1);return e}insertNode(t,e,i){if(t.isInline&&this.needsBlock&&!this.top.type){let t=this.textblockFromContext();t&&(e=this.enterInner(t,null,e))}let s=this.findPlace(t,e,i);if(s){this.closeExtra();let e=this.top;e.match&&(e.match=e.match.matchType(t.type));let i=g.none;for(let r of s.concat(t.marks))(e.type?e.type.allowsMarkType(r.type):ct(r.type,t.type))&&(i=r.addToSet(i));return e.content.push(t.mark(i)),!0}return!1}enter(t,e,i,s){let r=this.findPlace(t.create(e),i,!1);return r&&(r=this.enterInner(t,e,i,!0,s)),r}enterInner(t,e,i,s=!1,r){this.closeExtra();let n=this.top;n.match=n.match&&n.match.matchType(t);let o=ot(t,r,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,s,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 s=0;s<this.find.length;s++)null==this.find[s].pos&&1==t.nodeType&&t.contains(this.find[s].node)&&e.compareDocumentPosition(this.find[s].node)&(i?2:4)&&(this.find[s].pos=this.currentPos)}findInText(t){if(this.find)for(let e=0;e<this.find.length;e++)this.find[e].node==t&&(this.find[e].pos=this.currentPos-(t.nodeValue.length-this.find[e].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let e=t.split("/"),i=this.options.context,s=!(this.isOpen||i&&i.parent.type!=this.nodes[0].type),r=(s?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>=r;o--)if(n(t-1,o))return!0;return!1}{let t=o>0||0==o&&s?this.nodes[o].type:i&&o>=r?i.node(o-r).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 s in i){let r=i[s];if(!r.allowsMarkType(t))continue;let n=[],o=t=>{n.push(t);for(let i=0;i<t.edgeCount;i++){let{type:s,next:r}=t.edge(i);if(s==e)return!0;if(n.indexOf(r)<0&&o(r))return!0}};if(o(r.contentMatch))return!0}}class ft{constructor(t,e){this.nodes=t,this.marks=e}serializeFragment(t,e={},i){i||(i=pt(e).createDocumentFragment());let s=i,r=[];return t.forEach((t=>{if(r.length||t.marks.length){let i=0,n=0;for(;i<r.length&&n<t.marks.length;){let e=t.marks[n];if(this.marks[e.type.name]){if(!e.eq(r[i][0])||!1===e.type.spec.spanning)break;i++,n++}else n++}for(;i<r.length;)s=r.pop()[1];for(;n<t.marks.length;){let i=t.marks[n++],o=this.serializeMark(i,t.isInline,e);o&&(r.push([i,s]),s.appendChild(o.dom),s=o.contentDOM||o.dom)}}s.appendChild(this.serializeNodeInner(t,e))})),i}serializeNodeInner(t,e){let{dom:i,contentDOM:s}=wt(pt(e),this.nodes[t.type.name](t),null,t.attrs);if(s){if(t.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(t.content,e,s)}return i}serializeNode(t,e={}){let i=this.serializeNodeInner(t,e);for(let s=t.marks.length-1;s>=0;s--){let r=this.serializeMark(t.marks[s],t.isInline,e);r&&((r.contentDOM||r.dom).appendChild(i),i=r.dom)}return i}serializeMark(t,e,i={}){let s=this.marks[t.type.name];return s&&wt(pt(i),s(t,e),null,t.attrs)}static renderSpec(t,e,i=null,s){return wt(t,e,i,s)}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 s=t[i].spec.toDOM;s&&(e[i]=s)}return e}function pt(t){return t.document||window.document}const gt=new WeakMap;function wt(t,e,i,s){if("string"==typeof e)return{dom:t.createTextNode(e)};if(null!=e.nodeType)return{dom:e};if(e.dom&&null!=e.dom.nodeType)return e;let r,n=e[0];if("string"!=typeof n)throw new RangeError("Invalid array passed to renderSpec");if(s&&(r=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}(s))&&r.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 r=u;r<e.length;r++){let n=e[r];if(0===n){if(r<e.length-1||r>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}{let{dom:e,contentDOM:r}=wt(t,n,i,s);if(l.appendChild(e),r){if(o)throw new RangeError("Multiple content holes");o=r}}}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 s=0,r=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?s:0);if(h>t)break;let l=this.ranges[o+r],a=this.ranges[o+n],u=h+l;if(t<=u){let r=h+s+((l?t==h?-1:t==u?1:e:e)<0?0:a);if(i)return r;let n=t==h?2:t==u?1:4;return(e<0?t!=h:t!=u)&&(n|=8),new yt(r,n,t==(e<0?h:u)?null:o/3+(t-h)*mt)}s+=a-l}return i?t+s:new yt(t+s,0,null)}touches(t,e){let i=0,s=vt(e),r=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+r];if(t<=o+h&&e==3*s)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 s=0,r=0;s<this.ranges.length;s+=3){let n=this.ranges[s],o=n-(this.inverted?r:0),h=n+(this.inverted?0:r),l=this.ranges[s+e],a=this.ranges[s+i];t(o,o+l,h,h+a),r+=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,s=(t?t.length:0)){this.mirror=e,this.from=i,this.to=s,this._maps=t||[],this.ownData=!(t||e)}get maps(){return this._maps}slice(t=0,e=this.maps.length){return new 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 s=t.getMirror(e);this.appendMap(t._maps[e],null!=s&&s<e?i+s:void 0)}}getMirror(t){if(this.mirror)for(let e=0;e<this.mirror.length;e++)if(this.mirror[e]==t)return this.mirror[e+(e%2?-1:1)]}setMirror(t,e){this.mirror||(this.mirror=[]),this.mirror.push(t,e)}appendMappingInverted(t){for(let e=t.maps.length-1,i=this._maps.length+t._maps.length;e>=0;e--){let s=t.getMirror(e);this.appendMap(t._maps[e].invert(),null!=s&&s>e?i-s-1:void 0)}}invert(){let t=new 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 s=0;for(let i=this.from;i<this.to;i++){let r=this._maps[i].mapResult(t,e);if(null!=r.recover){let e=this.getMirror(i);if(null!=e&&e>i&&e<this.to){i=e,t=this._maps[e].recover(r.recover);continue}}s|=r.delInfo,t=r.pos}return i?t:new yt(t,s,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,s){try{return Ct.ok(t.replace(e,i,s))}catch(t){if(t instanceof w)return Ct.fail(t.message);throw t}}}function At(t,e,i){let s=[];for(let r=0;r<t.childCount;r++){let n=t.child(r);n.content.size&&(n=n.copy(At(n.content,e,n))),n.isInline&&(n=e(n,i,r)),s.push(n)}return c.fromArray(s)}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),s=i.node(i.sharedDepth(this.to)),r=new m(At(e.content,((t,e)=>t.isAtom&&e.type.allowsMarkType(this.mark.type)?t.mark(this.mark.addToSet(t.marks)):t),s),e.openStart,e.openEnd);return Ct.fromReplace(t,this.from,this.to,r)}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,s=!1){super(),this.from=t,this.to=e,this.slice=i,this.structure=s}apply(t){return this.structure&&$t(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.to,-1),i=this.from==this.to&&Et.MAP_BIAS<0?e:t.mapResult(this.from,1);return i.deletedAcross&&e.deletedAcross?null:new Et(i.pos,Math.max(i.pos,e.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)}}Et.MAP_BIAS=1,xt.jsonID("replace",Et);class It extends xt{constructor(t,e,i,s,r,n,o=!1){super(),this.from=t,this.to=e,this.gapFrom=i,this.gapTo=s,this.slice=r,this.insert=n,this.structure=o}apply(t){if(this.structure&&($t(t,this.from,this.gapFrom)||$t(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),s=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1),r=this.to==this.gapTo?i.pos:t.map(this.gapTo,1);return e.deletedAcross&&i.deletedAcross||s<e.pos||r>i.pos?null:new It(e.pos,i.pos,s,r,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 $t(t,e,i){let s=t.resolve(e),r=i-e,n=s.depth;for(;r>0&&n>0&&s.indexAfter(n)==s.node(n).childCount;)n--,r--;if(r>0){let t=s.node(n).maybeChild(s.indexAfter(n));for(;r>0;){if(!t||t.isLeaf)return!0;t=t.firstChild,r--}}return!1}function Pt(t,e,i,s=i.contentMatch,r=!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=s.matchType(l.type);if(u){s=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(r&&l.isText&&"pre"!=i.whitespace){let t,e,s=/\r?\n|\r/g;for(;t=s.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(!s.validEnd){let e=s.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 Dt(t,e,i){return(0==e||t.canReplace(e,t.childCount))&&(i==t.childCount||t.canReplace(0,i))}function Rt(t){let e=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let i=t.depth,s=0,r=0;;--i){let n=t.$from.node(i),o=t.$from.index(i)+s,h=t.$to.indexAfter(i)-r;if(i<t.depth&&n.canReplace(o,h,e))return i;if(0==i||n.type.spec.isolating||!Dt(n,o,h))break;o&&(s=1),h<n.childCount&&(r=1)}return null}function jt(t,e,i,s){e.forEach(((r,n)=>{if(r.isText){let o,h=/\r?\n|\r/g;for(;o=h.exec(r.text);){let r=t.mapping.slice(s).map(i+1+n+o.index);t.replaceWith(r,r+1,e.type.schema.linebreakReplacement.create())}}}))}function Ft(t,e,i,s){e.forEach(((r,n)=>{if(r.type==r.type.schema.linebreakReplacement){let r=t.mapping.slice(s).map(i+1+n);t.replaceWith(r,r+1,e.type.schema.text("\n"))}}))}function Nt(t,e,i=1,s){let r=t.resolve(e),n=r.depth-i,o=s&&s[s.length-1]||r.parent;if(n<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!o.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let t=r.depth-1,e=i-2;t>n;t--,e--){let i=r.node(t),n=r.index(t);if(i.type.spec.isolating)return!1;let o=i.content.cutByIndex(n,i.childCount),h=s&&s[e+1];h&&(o=o.replaceChild(0,h.type.create(h.attrs)));let l=s&&s[e]||i;if(!i.canReplace(n+1,i.childCount)||!l.type.validContent(o))return!1}let h=r.indexAfter(n),l=s&&s[0];return r.node(n).canReplaceWith(h,h,l?l.type:r.node(n+1).type)}function Ut(t,e){let i=t.resolve(e),s=i.index();return function(t,e){return!(!t||!e||t.isLeaf||!function(t,e){e.content.size||t.type.compatibleContent(e.type);let i=t.contentMatchAt(t.childCount),{linebreakReplacement:s}=t.type.schema;for(let r=0;r<e.childCount;r++){let n=e.child(r);if(i=i.matchType(n.type==s?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(s,s+1)}function zt(t,e,i=e,s=m.empty){if(e==i&&!s.size)return null;let r=t.resolve(e),n=t.resolve(i);return _t(r,n,s)?new Et(e,i,s):new Lt(r,n,s).fit()}function _t(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 Lt{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,s=this.close(t<0?this.$to:i.doc.resolve(t));if(!s)return null;let r=this.placed,n=i.depth,o=s.depth;for(;n&&o&&1==r.childCount;)r=r.firstChild.content,n--,o--;let h=new m(r,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,s.pos,h):null}findFittable(){let t=this.unplaced.openStart;for(let e=this.unplaced.content,i=0,s=this.unplaced.openEnd;i<t;i++){let r=e.firstChild;if(e.childCount>1&&(s=0),r.type.spec.isolating&&s<=i){t=i;break}e=r.content}for(let e=1;e<=2;e++)for(let i=1==e?t:this.unplaced.openStart;i>=0;i--){let t,s=null;i?(s=Yt(this.unplaced.content,i-1).firstChild,t=s.content):t=this.unplaced.content;let r=t.firstChild;for(let t=this.depth;t>=0;t--){let n,{type:o,match:h}=this.frontier[t],l=null;if(1==e&&(r?h.matchType(r.type)||(l=h.fillBefore(c.from(r),!1)):s&&o.compatibleContent(s.type)))return{sliceDepth:i,frontierDepth:t,parent:s,inject:l};if(2==e&&r&&(n=h.findWrapping(r.type)))return{sliceDepth:i,frontierDepth:t,parent:s,wrap:n};if(s&&h.matchType(s.type))break}}}openMore(){let{content:t,openStart:e,openEnd:i}=this.unplaced,s=Yt(t,e);return!(!s.childCount||s.firstChild.isLeaf||(this.unplaced=new m(t,e+1,Math.max(i,s.size+e>=t.size-i?e+1:0)),0))}dropNode(){let{content:t,openStart:e,openEnd:i}=this.unplaced,s=Yt(t,e);if(s.childCount<=1&&e>0){let r=t.size-e<=e+s.size;this.unplaced=new m(Ht(t,e-1,1),e-1,r?e-1:i)}else this.unplaced=new m(Ht(t,e,1),e,i)}placeNodes({sliceDepth:t,frontierDepth:e,parent:i,inject:s,wrap:r}){for(;this.depth>e;)this.closeFrontierNode();if(r)for(let t=0;t<r.length;t++)this.openFrontierNode(r[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(s){for(let t=0;t<s.childCount;t++)a.push(s.child(t));u=u.matchFragment(s)}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,s=this.$to.after(i);for(;i>1&&s==this.$to.end(--i);)++s;return s}findCloseLevel(t){t:for(let e=Math.min(this.depth,t.depth);e>=0;e--){let{match:i,type:s}=this.frontier[e],r=e<t.depth&&t.end(e+1)==t.pos+(t.depth-(e+1)),n=Vt(t,e,s,i,r);if(n){for(let i=e-1;i>=0;i--){let{match:e,type:s}=this.frontier[i],r=Vt(t,i,s,e,!0);if(!r||r.childCount)continue t}return{depth:e,fit:n,move:r?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),s=e.type.contentMatch.fillBefore(e.content,!0,t.index(i));this.openFrontierNode(e.type,e.attrs,s)}return t}openFrontierNode(t,e=null,i){let s=this.frontier[this.depth];s.match=s.match.matchType(t),this.placed=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 s=t.content;return e>1&&(s=s.replaceChild(0,Wt(s.firstChild,e-1,1==s.childCount?i-1:0))),e>0&&(s=t.type.contentMatch.fillBefore(s).append(s),i<=0&&(s=s.append(t.type.contentMatch.matchFragment(s).fillBefore(c.empty,!0)))),t.copy(s)}function Vt(t,e,i,s,r){let n=t.node(e),o=r?t.indexAfter(e):t.index(e);if(o==n.childCount&&!i.compatibleContent(n.type))return null;let h=s.fillBefore(n.content,!0,o);return h&&!function(t,e,i){for(let s=i;s<e.childCount;s++)if(!t.allowsMarks(e.child(s).marks))return!0;return!1}(i,n.content,o)?h:null}function Kt(t,e,i,s,r){if(e<i){let r=t.firstChild;t=t.replaceChild(0,r.copy(Kt(r.content,e+1,i,s,r)))}if(e>s){let e=r.contentMatchAt(0),i=e.fillBefore(t).append(t);t=i.append(e.matchFragment(i).fillBefore(c.empty,!0))}return t}function Jt(t,e){let i=[];for(let s=Math.min(t.depth,e.depth);s>=0;s--){let r=t.start(s);if(r<t.pos-(t.depth-s)||e.end(s)>e.pos+(e.depth-s)||t.node(s).type.spec.isolating||e.node(s).type.spec.isolating)break;(r==e.start(s)||s==t.depth&&s==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&s&&e.start(s-1)==r-1)&&i.push(s)}return i}class Qt 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 s=e.type.create(i,null,e.marks);return Ct.fromReplace(t,this.pos,this.pos+1,new m(c.from(s),0,e.isLeaf?0:1))}getMap(){return kt.empty}invert(t){return new Qt(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 Qt(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 Qt(e.pos,e.attr,e.value)}}xt.jsonID("attr",Qt);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 s=this.mapping.maps[i];i&&(t=s.map(t,1),e=s.map(e,-1)),s.forEach(((i,s,r,n)=>{t=Math.min(t,r),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 s=zt(this.doc,t,e,i);return s&&this.step(s),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,s){if(!s.size)return t.deleteRange(e,i);let r=t.doc.resolve(e),n=t.doc.resolve(i);if(_t(r,n,s))return t.step(new Et(e,i,s));let o=Jt(r,n);0==o[o.length-1]&&o.pop();let h=-(r.depth+1);o.unshift(h);for(let t=r.depth,e=r.pos-1;t>0;t--,e--){let i=r.node(t).type.spec;if(i.defining||i.definingAsContext||i.isolating)break;o.indexOf(t)>-1?h=t:r.before(t)==e&&o.splice(1,0,-t)}let l=o.indexOf(h),a=[],u=s.openStart;for(let t=s.content,e=0;;e++){let i=t.firstChild;if(a.push(i),e==s.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(r.node(Math.abs(h)-1)))u=t;else if(i||!e.type.isTextblock)break}var c;for(let e=s.openStart;e>=0;e--){let h=(e+u+1)%(s.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=r.node(a-1),d=r.index(a-1);if(f.canReplaceWith(d,d,c.type,c.marks))return t.replace(r.before(a),u?n.after(a):i,new m(Kt(s.content,0,s.openStart,h),h,s.openEnd))}}let f=t.steps.length;for(let h=o.length-1;h>=0&&(t.replace(e,i,s),!(t.steps.length>f));h--){let t=o[h];t<0||(e=r.before(t),i=n.after(t))}}(this,t,e,i),this}replaceRangeWith(t,e,i){return function(t,e,i,s){if(!s.isInline&&e==i&&t.doc.resolve(e).parent.content.size){let r=function(t,e,i){let s=t.resolve(e);if(s.parent.canReplaceWith(s.index(),s.index(),i))return e;if(0==s.parentOffset)for(let t=s.depth-1;t>=0;t--){let e=s.index(t);if(s.node(t).canReplaceWith(e,e,i))return s.before(t+1);if(e>0)return null}if(s.parentOffset==s.parent.content.size)for(let t=s.depth-1;t>=0;t--){let e=s.indexAfter(t);if(s.node(t).canReplaceWith(e,e,i))return s.after(t+1);if(e<s.node(t).childCount)return null}return null}(t.doc,e,s.type);null!=r&&(e=i=r)}t.replaceRange(e,i,new m(c.from(s),0,0))}(this,t,e,i),this}deleteRange(t,e){return function(t,e,i){let s=t.doc.resolve(e),r=t.doc.resolve(i);if(s.parent.isTextblock&&r.parent.isTextblock&&s.start()!=r.start()&&0==s.parentOffset&&0==r.parentOffset){let n=s.sharedDepth(i),o=!1;for(let t=s.depth;t>n;t--)s.node(t).type.spec.isolating&&(o=!0);for(let t=r.depth;t>n;t--)r.node(t).type.spec.isolating&&(o=!0);if(!o){for(let t=s.depth;t>0&&e==s.start(t);t--)e=s.before(t);for(let t=r.depth;t>0&&i==r.start(t);t--)i=r.before(t);s=t.doc.resolve(e),r=t.doc.resolve(i)}}let n=Jt(s,r);for(let e=0;e<n.length;e++){let i=n[e],o=e==n.length-1;if(o&&0==i||s.node(i).type.contentMatch.validEnd)return t.delete(s.start(i),r.end(i));if(i>0&&(o||s.node(i-1).canReplace(s.index(i-1),r.indexAfter(i-1))))return t.delete(s.before(i),r.after(i))}for(let n=1;n<=s.depth&&n<=r.depth;n++)if(e-s.start(n)==s.depth-n&&i>s.end(n)&&r.end(n)-i!=r.depth-n&&s.start(n-1)==r.start(n-1)&&s.node(n-1).canReplace(s.index(n-1),r.index(n-1)))return t.delete(s.before(n),i);t.delete(e,i)}(this,t,e),this}lift(t,e){return function(t,e,i){let{$from:s,$to:r,depth:n}=e,o=s.before(n+1),h=r.after(n+1),l=o,a=h,u=c.empty,f=0;for(let t=n,e=!1;t>i;t--)e||s.index(t)>0?(e=!0,u=c.from(s.node(t).copy(u)),f++):l--;let d=c.empty,p=0;for(let t=n,e=!1;t>i;t--)e||r.after(t+1)<r.end(t)?(e=!0,d=c.from(r.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 s=null,{linebreakReplacement:r}=t.doc.type.schema,n=t.doc.resolve(e-i),o=n.node().type;if(r&&o.inlineContent){let t="pre"==o.whitespace,e=!!o.contentMatch.matchType(r);t&&!e?s=!1:!t&&e&&(s=!0)}let h=t.steps.length;if(!1===s){let s=t.doc.resolve(e+i);Ft(t,s.node(),s.before(),h)}o.inlineContent&&Pt(t,e+i-1,o,n.node().contentMatchAt(n.index()),null==s);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===s){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 s=c.empty;for(let t=i.length-1;t>=0;t--){if(s.size){let e=i[t].type.contentMatch.matchFragment(s);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}s=c.from(i[t].type.create(i[t].attrs,s))}let r=e.start,n=e.end;t.step(new It(r,n,r,n,new m(s,0,0),i.length,!0))}(this,t,e),this}setBlockType(t,e=t,i,s=null){return function(t,e,i,s,r){if(!s.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 r?r(e):r;if(e.isTextblock&&!e.hasMarkup(s,o)&&function(t,e,i){let s=t.resolve(e),r=s.index();return s.parent.canReplaceWith(r,r+1,i)}(t.doc,t.mapping.slice(n).map(i),s)){let r=null;if(s.schema.linebreakReplacement){let t="pre"==s.whitespace,e=!!s.contentMatch.matchType(s.schema.linebreakReplacement);t&&!e?r=!1:!t&&e&&(r=!0)}!1===r&&Ft(t,e,i,n),Pt(t,t.mapping.slice(n).map(i,1),s,void 0,null===r);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(s.create(o,null,e.marks)),0,0),1,!0)),!0===r&&jt(t,e,i,n),!1}}))}(this,t,e,i,s),this}setNodeMarkup(t,e,i=null,s){return function(t,e,i,s,r){let n=t.doc.nodeAt(e);if(!n)throw new RangeError("No node at given position");i||(i=n.type);let o=i.create(s,null,r||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,s),this}setNodeAttribute(t,e,i){return this.step(new Qt(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 s,r=i.marks,n=[];for(;s=e.isInSet(r);)n.push(new Ot(t,s)),r=s.removeFromSet(r);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,s){let r=t.doc.resolve(e),n=c.empty,o=c.empty;for(let t=r.depth,e=r.depth-i,h=i-1;t>e;t--,h--){n=c.from(r.node(t).copy(n));let e=s&&s[h];o=c.from(e?e.type.create(e.attrs,o):r.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,s){let r,n,o=[],h=[];t.doc.nodesBetween(e,i,((t,l,a)=>{if(!t.isInline)return;let u=t.marks;if(!s.isInSet(u)&&a.type.allowsMarkType(s.type)){let a=Math.max(l,e),c=Math.min(l+t.nodeSize,i),f=s.addToSet(u);for(let t=0;t<u.length;t++)u[t].isInSet(f)||(r&&r.to==a&&r.mark.eq(u[t])?r.to=c:o.push(r=new Bt(a,c,u[t])));n&&n.to==a?n.to=c:h.push(n=new St(a,c,s))}})),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,s){let r=[],n=0;t.doc.nodesBetween(e,i,((t,o)=>{if(!t.isInline)return;n++;let h=null;if(s instanceof Z){let e,i=t.marks;for(;e=s.isInSet(i);)(h||(h=[])).push(e),i=e.removeFromSet(i)}else s?s.isInSet(t.marks)&&(h=[s]):h=t.marks;if(h&&h.length){let s=Math.min(o+t.nodeSize,i);for(let t=0;t<h.length;t++){let i,l=h[t];for(let t=0;t<r.length;t++){let e=r[t];e.step==n-1&&l.eq(r[t].style)&&(i=e)}i?(i.to=s,i.step=n):r.push({style:l,from:Math.max(o,e),to:s,step:n})}}})),r.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,s=null;for(let t=0;t<e.openEnd;t++)s=i,i=i.lastChild;let r=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(r);t.replaceRange(a.map(h.pos),a.map(l.pos),o?m.empty:e),0==o&&fe(t,r,(i?i.isInline:s&&s.isTextblock)?-1:1)}}replaceWith(t,e){let i=t.steps.length,s=this.ranges;for(let r=0;r<s.length;r++){let{$from:n,$to:o}=s[r],h=t.mapping.slice(i),l=h.map(n.pos),a=h.map(o.pos);r?t.deleteRange(l,a):(t.replaceRangeWith(l,a,e),fe(t,i,e.isInline?-1:1))}}static findFrom(t,e,i=!1){let s=t.parent.inlineContent?new ne(t):ce(t.node(0),t.parent,t.pos,t.index(),e,i);if(s)return s;for(let s=t.depth-1;s>=0;s--){let r=e<0?ce(t.node(0),t.node(s),t.before(s+1),t.index(s),e,i):ce(t.node(0),t.node(s),t.after(s+1),t.index(s)+1,e,i);if(r)return r}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 se=!1;function re(t){se||t.parent.inlineContent||(se=!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){re(t),re(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 s=t.resolve(e.map(this.anchor));return new ne(s.parent.inlineContent?s: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 s=t.resolve(e);return new this(s,i==e?s:t.resolve(i))}static between(t,e,i){let s=t.pos-e.pos;if(i&&!s||(i=s>=0?1:-1),!e.parent.inlineContent){let t=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==s||(t=(ee.findFrom(t,-i,!0)||ee.findFrom(t,i,!0)).$anchor).pos<e.pos!=s<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:s}=e.mapResult(this.anchor),r=t.resolve(s);return i?ee.near(r):new he(r)}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,s,r,n=!1){if(e.inlineContent)return ne.create(t,i);for(let o=s-(r>0?0:1);r>0?o<e.childCount:o>=0;o+=r){let s=e.child(o);if(s.isAtom){if(!n&&he.isSelectable(s))return he.create(t,i-(r<0?s.nodeSize:0))}else{let e=ce(t,s,i+r,r<0?s.childCount:0,r,n);if(e)return e}i+=s.nodeSize*r}return null}function fe(t,e,i){let s=t.steps.length-1;if(s<e)return;let r,n=t.steps[s];(n instanceof Et||n instanceof It)&&(t.mapping.maps[s].forEach(((t,e,i,s)=>{null==r&&(r=s)})),t.setSelection(ee.near(t.doc.resolve(r),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 s=this.doc.type.schema;if(null==e)return t?this.replaceSelectionWith(s.text(t),!0):this.deleteSelection();{if(null==i&&(i=e),!t)return this.deleteRange(e,i);let r=this.storedMarks;if(!r){let t=this.doc.resolve(e);r=i==e?t.marks():t.marksAcross(this.doc.resolve(i))}return this.replaceRangeWith(e,i,s.text(t,r)),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,s)=>s.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),s=null;for(;;){let r=!1;for(let n=0;n<this.config.plugins.length;n++){let o=this.config.plugins[n];if(o.spec.appendTransaction){let h=s?s[n].n:0,l=s?s[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),!s){s=[];for(let t=0;t<this.config.plugins.length;t++)s.push(t<n?{state:i,n:e.length}:{state:this,n:0})}e.push(a),i=i.applyInner(a),r=!0}s&&(s[n]={state:i,n:e.length})}}if(!r)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 s=0;s<i.length;s++){let r=i[s];e[r.name]=r.apply(t,this[r.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 s=0;s<e.fields.length;s++)i[e.fields[s].name]=e.fields[s].init(t,i);return i}reconfigure(t){let e=new me(this.schema,t.plugins),i=e.fields,s=new ve(e);for(let e=0;e<i.length;e++){let r=i[e].name;s[r]=this.hasOwnProperty(r)?this[r]:i[e].init(t,s)}return s}toJSON(t){let e={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(e.storedMarks=this.storedMarks.map((t=>t.toJSON()))),t&&"object"==typeof t)for(let i in t){if("doc"==i||"selection"==i)throw new RangeError("The JSON fields `doc` and `selection` are reserved");let s=t[i],r=s.spec.state;r&&r.toJSON&&(e[i]=r.toJSON.call(s,this[s.key]))}return e}static fromJSON(t,e,i){if(!e)throw new RangeError("Invalid input for EditorState.fromJSON");if(!t.schema)throw new RangeError("Required config field 'schema' missing");let s=new me(t.schema,t.plugins),r=new ve(s);return s.fields.forEach((s=>{if("doc"==s.name)r.doc=R.fromJSON(t.schema,e.doc);else if("selection"==s.name)r.selection=ee.fromJSON(r.doc,e.selection);else if("storedMarks"==s.name)e.storedMarks&&(r.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==s.name&&h&&h.fromJSON&&Object.prototype.hasOwnProperty.call(e,n))return void(r[s.name]=h.fromJSON.call(o,t,e[n],r))}r[s.name]=s.init(t,r)}})),r}}function ye(t,e,i){for(let s in t){let r=t[s];r instanceof Function?r=r.bind(e):"handleDOMEvents"==s&&(r=ye(r,e,{})),i[s]=r}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 s=Ce||(Ce=document.createRange());return s.setEnd(t,null==i?t.nodeValue.length:i),s.setStart(t,e||0),s},Se=function(t,e,i,s){return i&&(Te(t,e,i,s,-1)||Te(t,e,i,s,1))},Be=/^(img|br|input|textarea|hr)$/i;function Te(t,e,i,s,r){for(var n;;){if(t==i&&e==s)return!0;if(e==(r<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)+(r<0?0:1),t=i}else{if(1!=t.nodeType)return!1;{let i=t.childNodes[e+(r<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+=r}else t=i,e=r<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 $e(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,De="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,_e=!Ue&&/gecko\/(\d+)/i.test(Re),Le=!Ue&&/Chrome\/(\d+)/.exec(Re),He=!!Le,Xe=Le?+Le[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),Ke=!!Pe&&/Win/.test(Pe.platform),Je=/Android \d/.test(Re),Qe=!!De&&"webkitFontSmoothing"in De.documentElement.style,qe=Qe?+(/\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 s=t.someProp("scrollThreshold")||0,r=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(s,"top")?a=-(h.top-e.top+Ze(r,"top")):e.bottom>h.bottom-Ze(s,"bottom")&&(a=e.bottom-e.top>h.bottom-h.top?e.top+Ze(r,"top")-h.top:e.bottom-h.bottom+Ze(r,"bottom")),e.left<h.left+Ze(s,"left")?l=-(h.left-e.left+Ze(r,"left")):e.right>h.right-Ze(s,"right")&&(l=e.right-h.right+Ze(r,"right")),l||a)if(i)n.defaultView.scrollBy(l,a);else{let i=t.scrollLeft,s=t.scrollTop;a&&(t.scrollTop+=a),l&&(t.scrollLeft+=l);let r=t.scrollLeft-i,n=t.scrollTop-s;e={left:e.left-r,top:e.top-n,right:e.right-r,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 s=t;s&&(e.push({dom:s,top:s.scrollTop,left:s.scrollLeft}),t!=i);s=xe(s));return e}function si(t,e){for(let i=0;i<t.length;i++){let{dom:s,top:r,left:n}=t[i];s.scrollTop!=r+e&&(s.scrollTop=r+e),s.scrollLeft!=n&&(s.scrollLeft=n)}}let ri=null;function ni(t,e){let i,s,r,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,s=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&&!r&&d.left<=e.left&&d.right>=e.left&&(r=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&&r&&(i=r,s=n,o=0),i&&3==i.nodeType?function(t,e){let i,s=t.nodeValue.length,r=document.createRange();for(let n=0;n<s;n++){r.setEnd(t,n+1),r.setStart(t,n);let s=ui(r,1);if(s.top!=s.bottom&&oi(e,s)){i={node:t,offset:n+(e.left>=(s.left+s.right)/2?1:0)};break}}return r.detach(),i||{node:t,offset:0}}(i,s):!i||o&&1==i.nodeType?{node:t,offset:h}:ni(i,s)}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 s=t.childNodes.length;if(s&&i.top<i.bottom)for(let r=Math.max(0,Math.min(s-1,Math.floor(s*(e.top-i.top)/(i.bottom-i.top))-2)),n=r;;){let i=t.childNodes[n];if(1==i.nodeType){let t=i.getClientRects();for(let s=0;s<t.length;s++){let r=t[s];if(oi(e,r))return hi(i,e,r)}}if((n=(n+1)%s)==r)break}return t}function li(t,e){let i,s=t.dom.ownerDocument,r=0,n=function(t,e,i){if(t.caretPositionFromPoint)try{let s=t.caretPositionFromPoint(e,i);if(s)return{node:s.offsetNode,offset:Math.min(Oe(s.offsetNode),s.offset)}}catch(t){}if(t.caretRangeFromPoint){let s=t.caretRangeFromPoint(e,i);if(s)return{node:s.startContainer,offset:Math.min(Oe(s.startContainer),s.startOffset)}}}(s,e.left,e.top);n&&({node:i,offset:r}=n);let o,h=(t.root.elementFromPoint?t.root:s).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(_e&&1==i.nodeType&&(r=Math.min(r,i.childNodes.length),r<i.childNodes.length)){let t,s=i.childNodes[r];"IMG"==s.nodeName&&(t=s.getBoundingClientRect()).right<=e.left&&t.bottom>e.top&&r++}let s;Qe&&r&&1==i.nodeType&&1==(s=i.childNodes[r-1]).nodeType&&"false"==s.contentEditable&&s.getBoundingClientRect().top>=e.top&&r--,i==t.dom&&r==i.childNodes.length-1&&1==i.lastChild.nodeType&&e.top>i.lastChild.getBoundingClientRect().bottom?o=t.state.doc.content.size:0!=r&&1==i.nodeType&&"BR"==i.childNodes[r-1].nodeName||(o=function(t,e,i,s){let r=-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>s.left||e.top>s.top?r=o.posBefore:(!n&&e.right<s.left||e.bottom<s.top)&&(r=o.posAfter),n=!0),!o.contentDOM&&r<0&&!o.node.isText))return(o.node.isBlock?s.top<(e.top+e.bottom)/2:s.left<(e.left+e.right)/2)?o.posBefore:o.posAfter;i=o.dom.parentNode}return r>-1?r:t.docView.posFromDOM(e,i,-1)}(t,i,r,e))}null==o&&(o=function(t,e,i){let{node:s,offset:r}=ni(e,i),n=-1;if(1==s.nodeType&&!s.firstChild){let t=s.getBoundingClientRect();n=t.left!=t.right&&i.left>(t.left+t.right)/2?1:-1}return t.docView.posFromDOM(s,r,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:s,offset:r,atom:n}=t.docView.domFromPos(e,i<0?-1:1),o=Qe||_e;if(3==s.nodeType){if(!o||!ci.test(s.nodeValue)&&(i<0?r:r!=s.nodeValue.length)){let t=r,e=r,n=i<0?1:-1;return i<0&&!r?(e++,n=-1):i>=0&&r==s.nodeValue.length?(t--,n=1):i<0?t--:e++,di(ui(Ae(s,t,e),n),n<0)}{let t=ui(Ae(s,r,r),i);if(_e&&r&&/\s/.test(s.nodeValue[r-1])&&r<s.nodeValue.length){let e=ui(Ae(s,r-1,r-1),-1);if(e.top==t.top){let i=ui(Ae(s,r,r+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&&r&&(i<0||r==Oe(s))){let t=s.childNodes[r-1];if(1==t.nodeType)return pi(t.getBoundingClientRect(),!1)}if(null==n&&r<Oe(s)){let t=s.childNodes[r];if(1==t.nodeType)return pi(t.getBoundingClientRect(),!0)}return pi(s.getBoundingClientRect(),i>=0)}if(null==n&&r&&(i<0||r==Oe(s))){let t=s.childNodes[r-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&&r<Oe(s)){let t=s.childNodes[r];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==s.nodeType?Ae(s):s,-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 s=t.state,r=t.root.activeElement;s!=e&&t.updateState(e),r!=t.dom&&t.focus();try{return i()}finally{s!=e&&t.updateState(s),r!=t.dom&&r&&r.focus()}}const wi=/[\u0590-\u08ac]/;let mi=null,vi=null,yi=!1;class ki{constructor(t,e,i,s){this.parent=t,this.children=e,this.dom=i,this.contentDOM=s,this.dirty=0,i.pmViewDesc=this}matchesWidget(t){return!1}matchesMark(t){return!1}matchesNode(t,e,i){return!1}matchesHack(t){return!1}parseRule(){return null}stopEvent(t){return!1}get size(){let t=0;for(let e=0;e<this.children.length;e++)t+=this.children[e].size;return t}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let t=0;t<this.children.length;t++)this.children[t].destroy()}posBeforeChild(t){for(let e=0,i=this.posAtStart;;e++){let s=this.children[e];if(s==t)return i;i+=s.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(t,e,i){if(this.contentDOM&&this.contentDOM.contains(1==t.nodeType?t:t.parentNode)){if(i<0){let i,s;if(t==this.contentDOM)i=t.childNodes[e-1];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.previousSibling}for(;i&&(!(s=i.pmViewDesc)||s.parent!=this);)i=i.previousSibling;return i?this.posBeforeChild(s)+s.size:this.posAtStart}{let i,s;if(t==this.contentDOM)i=t.childNodes[e];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.nextSibling}for(;i&&(!(s=i.pmViewDesc)||s.parent!=this);)i=i.nextSibling;return i?this.posBeforeChild(s):this.posAtEnd}}let s;if(t==this.dom&&this.contentDOM)s=e>Me(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))s=2&t.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==e)for(let e=t;;e=e.parentNode){if(e==this.dom){s=!1;break}if(e.previousSibling)break}if(null==s&&e==t.childNodes.length)for(let e=t;;e=e.parentNode){if(e==this.dom){s=!0;break}if(e.nextSibling)break}}return(null==s?i>0:s)?this.posAtEnd:this.posAtStart}nearestDesc(t,e=!1){for(let i=!0,s=t;s;s=s.parentNode){let r,n=this.getDesc(s);if(n&&(!e||n.node)){if(!i||!(r=n.nodeDOM)||(1==r.nodeType?r.contains(1==t.nodeType?t:t.parentNode):r==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 s=t;s;s=s.parentNode){let r=this.getDesc(s);if(r)return r.localPosFromDOM(t,e,i)}return-1}descAt(t){for(let e=0,i=0;e<this.children.length;e++){let s=this.children[e],r=i+s.size;if(i==t&&r!=i){for(;!s.border&&s.children.length;)for(let t=0;t<s.children.length;t++){let e=s.children[t];if(e.size){s=e;break}}return s}if(t<r)return s.descAt(t-i-s.border);i=r}}domFromPos(t,e){if(!this.contentDOM)return{node:this.dom,offset:0,atom:t+1};let i=0,s=0;for(let e=0;i<this.children.length;i++){let r=this.children[i],n=e+r.size;if(n>t||r instanceof Bi){s=t-e;break}e=n}if(s)return this.children[i].domFromPos(s-this.children[i].border,e);for(let t;i&&!(t=this.children[i-1]).size&&t instanceof bi&&t.side>=0;i--);if(e<=0){let t,s=!0;for(;t=i?this.children[i-1]:null,t&&t.dom.parentNode!=this.contentDOM;i--,s=!1);return t&&e&&s&&!t.border&&!t.domAtom?t.domFromPos(t.size,e):{node:this.contentDOM,offset:t?Me(t.dom)+1:0}}{let t,s=!0;for(;t=i<this.children.length?this.children[i]:null,t&&t.dom.parentNode!=this.contentDOM;i++,s=!1);return t&&s&&!t.border&&!t.domAtom?t.domFromPos(0,e):{node:this.contentDOM,offset:t?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 s=-1,r=-1;for(let n=i,o=0;;o++){let i=this.children[o],h=n+i.size;if(-1==s&&t<=h){let r=n+i.border;if(t>=r&&e<=h-i.border&&i.node&&i.contentDOM&&this.contentDOM.contains(i.contentDOM))return i.parseRange(t,e,r);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)){s=Me(i.dom)+1;break}t-=i.size}-1==s&&(s=0)}if(s>-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)){r=Me(i.dom);break}e+=i.size}-1==r&&(r=this.contentDOM.childNodes.length);break}n=h}return{node:this.contentDOM,from:t,to:e,fromOffset:s,toOffset:r}}emptyChildAt(t){if(this.border||!this.contentDOM||!this.children.length)return!1;let e=this.children[t<0?0:this.children.length-1];return 0==e.size||e.emptyChildAt(t)}domAfterPos(t){let{node:e,offset:i}=this.domFromPos(t,0);if(1!=e.nodeType||i==e.childNodes.length)throw new RangeError("No node after pos "+t);return e.childNodes[i]}setSelection(t,e,i,s=!1){let r=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(r>h&&n<a)return l.setSelection(t-h-l.border,e-h-l.border,i,s);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((_e||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(_e&&a.focusNode&&a.focusNode!=h.node&&1==a.focusNode.nodeType){let t=a.focusNode.childNodes[a.focusOffset];t&&"false"==t.contentEditable&&(s=!0)}if(!(s||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||!_e)){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,s=0;s<this.children.length;s++){let r=this.children[s],n=i+r.size;if(i==n?t<=n&&e>=i:t<n&&e>i){let s=i+r.border,o=n-r.border;if(t>=s&&e<=o)return this.dirty=t==i||e==n?2:1,void(t!=s||e!=o||!r.contentLost&&r.dom.parentNode==this.contentDOM?r.markDirty(t-s,e-s):r.dirty=3);r.dirty=r.dom!=r.contentDOM||r.dom.parentNode!=this.contentDOM||r.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,s){let r,n=e.type.toDOM;if("function"==typeof n&&(n=n(i,(()=>r?r.parent?r.parent.posBeforeChild(r):void 0:s))),!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,r=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,s){super(t,[],e,null),this.textDOM=i,this.text=s}get size(){return this.text.length}localPosFromDOM(t,e){return t!=this.textDOM?this.posAtStart+(e?this.size:0):this.posAtStart+e}domFromPos(t){return{node:this.textDOM,offset:t}}ignoreMutation(t){return"characterData"===t.type&&t.target.nodeValue==t.oldValue}}class xi extends ki{constructor(t,e,i,s,r){super(t,[],i,s),this.mark=e,this.spec=r}static create(t,e,i,s){let r=s.nodeViews[e.type.name],n=r&&r(e,s,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 s=xi.create(this.parent,this.mark,!0,i),r=this.children,n=this.size;e<n&&(r=zi(r,e,n,i)),t>0&&(r=zi(r,0,t,i));for(let t=0;t<r.length;t++)r[t].parent=s;return s.children=r,s}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,s,r,n,o,h,l){super(t,[],r,n),this.node=e,this.outerDeco=i,this.innerDeco=s,this.nodeDOM=o}static create(t,e,i,s,r,n){let o,h=r.nodeViews[e.type.name],l=h&&h(e,r,(()=>o?o.parent?o.parent.posBeforeChild(o):void 0:n),i,s),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,s,a,u||null,c,l,r,n+1):e.isText?new Si(t,e,i,s,a,c,r):new Ci(t,e,i,s,a,u||null,c,r,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,s=e,r=t.composing?this.localCompositionInfo(t,e):null,n=r&&r.pos>-1?r:null,o=r&&r.pos<0,h=new Ni(this,n&&n.node,t);!function(t,e,i,s){let r=e.locals(t),n=0;if(0==r.length){for(let i=0;i<t.childCount;i++){let o=t.child(i);s(o,r,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<r.length&&r[o].to==n;){let t=r[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<r.length&&r[o].from<=n&&r[o].to>n;)h.push(r[o++]);let p=n+f.nodeSize;if(f.isText){let t=p;o<r.length&&r[o].from<t&&(t=r[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<r.length&&r[o].to<p;)o++;s(f,f.isInline&&!f.isLeaf?h.filter((t=>!t.inline)):h.slice(),e.forChild(n,f),d),n=p}}(this.node,this.innerDeco,((e,r,n)=>{e.spec.marks?h.syncToMarks(e.spec.marks,i,t,r):e.type.side>=0&&!n&&h.syncToMarks(r==this.node.childCount?g.none:this.node.child(r).marks,i,t,r),h.placeWidget(e,t,s)}),((e,n,l,a)=>{let u;h.syncToMarks(e.marks,i,t,a),h.findNodeMatch(e,n,l,a)||o&&t.state.selection.from>s&&t.state.selection.to<s+e.nodeSize&&(u=h.findIndexWithChild(r.node))>-1&&h.updateNodeAt(e,n,l,u,t)||h.updateNextNode(e,n,l,t,a,s)||h.addNode(e,n,l,t,s),s+=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:s}=t.state.selection;if(!(t.state.selection instanceof ne)||i<e||s>e+this.node.content.size)return null;let r=t.input.compositionNode;if(!r||!this.dom.contains(r.parentNode))return null;if(this.node.inlineContent){let t=r.nodeValue,n=function(t,e,i,s){for(let r=0,n=0;r<t.childCount&&n<=s;){let o=t.child(r++),h=n;if(n+=o.nodeSize,!o.isText)continue;let l=o.text;for(;r<t.childCount;){let e=t.child(r++);if(n+=e.nodeSize,!e.isText)break;l+=e.text}if(n>=i){if(n>=s&&l.slice(s-e.length-h,s-h)==e)return s-e.length;let t=h<s?l.lastIndexOf(e,s-h-1):-1;if(t>=0&&t+e.length+h>=i)return h+t;if(i==s&&l.length>=s+e.length-h&&l.slice(s-h,s-h+e.length)==e)return s}}return-1}(this.node.content,t,i-e,s-e);return n<0?null:{node:r,pos:n,text:t}}return{node:r,pos:-1,text:""}}protectLocalComposition(t,{node:e,pos:i,text:s}){if(this.getDesc(e))return;let r=e;for(;r.parentNode!=this.contentDOM;r=r.parentNode){for(;r.previousSibling;)r.parentNode.removeChild(r.previousSibling);for(;r.nextSibling;)r.parentNode.removeChild(r.nextSibling);r.pmViewDesc&&(r.pmViewDesc=void 0)}let n=new Mi(this,r,e,s);t.input.compositionNodes.push(n),this.children=zi(this.children,i,i+s.length,t,n)}update(t,e,i,s){return!(3==this.dirty||!t.sameMarkup(this.node)||(this.updateInner(t,e,i,s),0))}updateInner(t,e,i,s){this.updateOuterDeco(e),this.node=t,this.innerDeco=i,this.contentDOM&&this.updateChildren(s,this.posAtStart),this.dirty=0}updateOuterDeco(t){if(ji(t,this.outerDeco))return;let e=1!=this.nodeDOM.nodeType,i=this.dom;this.dom=Pi(this.dom,this.nodeDOM,$i(this.outerDeco,this.node,e),$i(t,this.node,e)),this.dom!=i&&(i.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=t}selectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||(this.nodeDOM.draggable=!0))}deselectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Ai(t,e,i,s,r){Ri(s,e,t);let n=new Ci(void 0,t,e,i,s,s,s,r,0);return n.contentDOM&&n.updateChildren(r,0),n}class Si extends Ci{constructor(t,e,i,s,r,n,o){super(t,e,i,s,r,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,s){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!t.sameMarkup(this.node)||(this.updateOuterDeco(e),0==this.dirty&&t.text==this.node.text||t.text==this.nodeDOM.nodeValue||(this.nodeDOM.nodeValue=t.text,s.trackWrites==this.nodeDOM&&(s.trackWrites=null)),this.node=t,this.dirty=0,0))}inParent(){let t=this.parent.contentDOM;for(let e=this.nodeDOM;e;e=e.parentNode)if(e==t)return!0;return!1}domFromPos(t){return{node:this.nodeDOM,offset:t}}localPosFromDOM(t,e,i){return t==this.nodeDOM?this.posAtStart+Math.min(e,this.node.text.length):super.localPosFromDOM(t,e,i)}ignoreMutation(t){return"characterData"!=t.type&&"selection"!=t.type}slice(t,e,i){let s=this.node.cut(t,e),r=document.createTextNode(s.text);return new Si(this.parent,s,this.outerDeco,this.innerDeco,r,r,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,s,r,n,o,h,l,a){super(t,e,i,s,r,n,o,l,a),this.spec=h}update(t,e,i,s){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==t.type||this.spec.multiType)){let r=this.spec.update(t,e,i);return r&&this.updateInner(t,e,i,s),r}return!(!this.contentDOM&&!t.isLeaf)&&super.update(t,e,i,s)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(t,e,i,s){this.spec.setSelection?this.spec.setSelection(t,e,i.root):super.setSelection(t,e,i,s)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(t){return!!this.spec.stopEvent&&this.spec.stopEvent(t)}ignoreMutation(t){return this.spec.ignoreMutation?this.spec.ignoreMutation(t):super.ignoreMutation(t)}}function Oi(t,e,i){let s=t.firstChild,r=!1;for(let n=0;n<e.length;n++){let o=e[n],h=o.dom;if(h.parentNode==t){for(;h!=s;)s=Fi(s),r=!0;s=s.nextSibling}else r=!0,t.insertBefore(h,s);if(o instanceof xi){let e=s?s.previousSibling:t.lastChild;Oi(o.contentDOM,o.children,i),s=e?e.nextSibling:t.firstChild}}for(;s;)s=Fi(s),r=!0;r&&i.trackWrites==t&&(i.trackWrites=null)}const Ei=function(t){t&&(this.nodeName=t)};Ei.prototype=Object.create(null);const Ii=[new Ei];function $i(t,e,i){if(0==t.length)return Ii;let s=i?Ii[0]:new Ei,r=[s];for(let n=0;n<t.length;n++){let o=t[n].type.attrs;if(o){o.nodeName&&r.push(s=new Ei(o.nodeName));for(let t in o){let n=o[t];null!=n&&(i&&1==r.length&&r.push(s=new Ei(e.isInline?"span":"div")),"class"==t?s.class=(s.class?s.class+" ":"")+n:"style"==t?s.style=(s.style?s.style+";":"")+n:"nodeName"!=t&&(s[t]=n))}}}return r}function Pi(t,e,i,s){if(i==Ii&&s==Ii)return e;let r=e;for(let e=0;e<s.length;e++){let n=s[e],o=i[e];if(e){let e;o&&o.nodeName==n.nodeName&&r!=t&&(e=r.parentNode)&&e.nodeName.toLowerCase()==n.nodeName||(e=document.createElement(n.nodeName),e.pmIsDeco=!0,e.appendChild(r),o=Ii[0]),r=e}Di(r,o||Ii[0],n)}return r}function Di(t,e,i){for(let s in e)"class"==s||"style"==s||"nodeName"==s||s in i||t.removeAttribute(s);for(let s in i)"class"!=s&&"style"!=s&&"nodeName"!=s&&i[s]!=e[s]&&t.setAttribute(s,i[s]);if(e.class!=i.class){let s=e.class?e.class.split(" ").filter(Boolean):[],r=i.class?i.class.split(" ").filter(Boolean):[];for(let e=0;e<s.length;e++)-1==r.indexOf(s[e])&&t.classList.remove(s[e]);for(let e=0;e<r.length;e++)-1==s.indexOf(r[e])&&t.classList.add(r[e]);0==t.classList.length&&t.removeAttribute("class")}if(e.style!=i.style){if(e.style){let i,s=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;i=s.exec(e.style);)t.style.removeProperty(i[1])}i.style&&(t.style.cssText+=i.style)}}function Ri(t,e,i){return Pi(t,t,Ii,$i(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,s=i.children.length,r=t.childCount,n=new Map,o=[];t:for(;r>0;){let h;for(;;)if(s){let t=i.children[s-1];if(!(t instanceof xi)){h=t,s--;break}i=t,s=t.children.length}else{if(i==e)break t;s=i.parent.children.indexOf(i),i=i.parent}let l=h.node;if(l){if(l!=t.child(r-1))break;--r,n.set(h,r),o.push(h)}}return{index:r,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,s){let r=0,n=this.stack.length>>1,o=Math.min(n,t.length);for(;r<o&&(r==n-1?this.top:this.stack[r+1<<1]).matchesMark(t[r])&&!1!==t[r].type.spec.spanning;)r++;for(;r<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 r=-1,o=this.top.children.length;s<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)){r=e;break}}if(r>-1)r>this.index&&(this.changed=!0,this.destroyBetween(this.index,r)),this.top=this.top.children[this.index];else{let s=xi.create(this.top,t[n],e,i);this.top.children.splice(this.index,0,s),this.top=s,this.changed=!0}this.index=0,n++}}findNodeMatch(t,e,i,s){let r,n=-1;if(s>=this.preMatch.index&&(r=this.preMatch.matches[s-this.preMatch.index]).parent==this.top&&r.matchesNode(t,e,i))n=this.top.children.indexOf(r,this.index);else for(let s=this.index,r=Math.min(this.top.children.length,s+5);s<r;s++){let r=this.top.children[s];if(r.matchesNode(t,e,i)&&!this.preMatch.matched.has(r)){n=s;break}}return!(n<0||(this.destroyBetween(this.index,n),this.index++,0))}updateNodeAt(t,e,i,s,r){let n=this.top.children[s];return 3==n.dirty&&n.dom==n.contentDOM&&(n.dirty=2),!!n.update(t,e,i,r)&&(this.destroyBetween(this.index,s),this.index++,!0)}findIndexWithChild(t){for(;;){let e=t.parentNode;if(!e)return-1;if(e==this.top.contentDOM){let e=t.pmViewDesc;if(e)for(let t=this.index;t<this.top.children.length;t++)if(this.top.children[t]==e)return t;return-1}t=e}}updateNextNode(t,e,i,s,r,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!=r)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,s))return this.destroyBetween(this.index,o),h.dom!=u&&(this.changed=!0),this.index++,!0;if(!c&&(a=this.recreateWrapper(h,t,e,i,s,n)))return this.destroyBetween(this.index,o),this.top.children[this.index]=a,a.contentDOM&&(a.dirty=2,a.updateChildren(s,n+1),a.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(t,e,i,s,r,n){if(t.dirty||e.isAtom||!t.children.length||!t.node.content.eq(e.content)||!ji(i,t.outerDeco)||!s.eq(t.innerDeco))return null;let o=Ci.create(this.top,e,i,s,r,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,s,r){let n=Ci.create(this.top,t,e,i,s,r);n.contentDOM&&n.updateChildren(s,r+1),this.top.children.splice(this.index++,0,n),this.changed=!0}placeWidget(t,e,i){let s=this.index<this.top.children.length?this.top.children[this.index]:null;if(!s||!s.matchesWidget(t)||t!=s.widget&&s.widget.type.toDOM.parentNode){let s=new bi(this.top,t,e,i);this.top.children.splice(this.index++,0,s),this.changed=!0}else this.index++}addTextblockHacks(){let t=this.top.children[this.index-1],e=this.top;for(;t instanceof 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 s=new Bi(this.top,[],i,null);e!=this.top?e.children.push(s):e.children.splice(this.index++,0,s),this.changed=!0}}isLocked(t){return this.lock&&(t==this.lock||1==t.nodeType&&t.contains(this.lock.parentNode))}}function Ui(t,e){return t.type.side-e.type.side}function zi(t,e,i,s,r){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,s)),r&&(n.push(r),r=void 0),u>i&&n.push(l.slice(i-a,l.size,s)))}return n}function _i(t,e=null){let i=t.domSelectionRange(),s=t.state.doc;if(!i.focusNode)return null;let r=t.docView.nearestDesc(i.focusNode),n=r&&0==r.size,o=t.docView.posFromDOM(i.focusNode,i.focusOffset,1);if(o<0)return null;let h,l,a=s.resolve(o);if(Ie(i)){for(h=o;r&&!r.node;)r=r.parent;let t=r.node;if(r&&t.isAtom&&he.isSelectable(t)&&r.parent&&(!t.isInline||!function(t,e,i){for(let s=0==e,r=e==Oe(t);s||r;){if(t==i)return!0;let e=Me(t);if(!(t=t.parentNode))return!1;s=s&&0==e,r=r&&e==Oe(t)}}(i.focusNode,i.focusOffset,r.dom))){let t=r.posBefore;l=new he(o==t?a:s.resolve(t))}}else{if(i instanceof t.dom.ownerDocument.defaultView.Selection&&i.rangeCount>1){let e=o,r=o;for(let s=0;s<i.rangeCount;s++){let n=i.getRangeAt(s);e=Math.min(e,t.docView.posFromDOM(n.startContainer,n.startOffset,1)),r=Math.max(r,t.docView.posFromDOM(n.endContainer,n.endOffset,-1))}if(e<0)return null;[h,o]=r==t.state.selection.anchor?[r,e]:[e,r],a=s.resolve(o)}else h=t.docView.posFromDOM(i.anchorNode,i.anchorOffset,1);if(h<0)return null}let u=s.resolve(h);return l||(l=Qi(t,u,a,"pointer"==e||t.state.selection.head<a.pos&&!n?1:-1)),l}function Li(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(Ki(t,i),Li(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,s="IMG"==i.nodeName;s?e.collapse(i.parentNode,Me(i)+1):e.collapse(i,0),!s&&!t.state.selection.visible&&Ue&&ze<=11&&(i.disabled=!0,i.disabled=!1)}(t);else{let s,r,{anchor:n,head:o}=i;!Xi||i instanceof ne||(i.$from.parent.inlineContent||(s=Yi(t,i.from)),i.empty||i.$from.parent.inlineContent||(r=Yi(t,i.to))),t.docView.setSelection(n,o,t,e),Xi&&(s&&Vi(s),r&&Vi(r)),i.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(t){let e=t.dom.ownerDocument;e.removeEventListener("selectionchange",t.input.hideSelectionGuard);let i=t.domSelectionRange(),s=i.anchorNode,r=i.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{i.anchorNode==s&&i.anchorOffset==r||(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout((()=>{Li(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:s}=t.docView.domFromPos(e,0),r=s<i.childNodes.length?i.childNodes[s]:null,n=s?i.childNodes[s-1]:null;if(Ye&&r&&"false"==r.contentEditable)return Wi(r);if(!(r&&"false"!=r.contentEditable||n&&"false"!=n.contentEditable)){if(r)return Wi(r);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 Ki(t,e){if(e instanceof he){let i=t.docView.descAt(e.from);i!=t.lastSelectedViewDesc&&(Ji(t),i&&i.selectNode(),t.lastSelectedViewDesc=i)}else Ji(t)}function Ji(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Qi(t,e,i,s){return t.someProp("createSelectionBetween",(s=>s(t,e,i)))||ne.between(e,i,s)}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:s}=t.selection,r=e>0?i.max(s):i.min(s),n=r.parent.inlineContent?r.depth?t.doc.resolve(e>0?r.after():r.before()):null:r;return n&&ee.findFrom(n,e)}function ts(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function es(t,e,i){let s=t.state.selection;if(!(s instanceof ne)){if(s instanceof he&&s.node.isInline)return ts(t,new ne(e>0?s.$to:s.$from));{let i=Zi(t.state,e);return!!i&&ts(t,i)}}if(i.indexOf("s")>-1){let{$head:i}=s,r=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!r||r.isText||!r.isLeaf)return!1;let n=t.state.doc.resolve(i.pos+r.nodeSize*(e<0?-1:1));return ts(t,new ne(s.$anchor,n))}if(!s.empty)return!1;if(t.endOfTextblock(e>0?"forward":"backward")){let i=Zi(t.state,e);return!!(i&&i instanceof he)&&ts(t,i)}if(!(Ve&&i.indexOf("m")>-1)){let i,r=s.$head,n=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter;if(!n||n.isText)return!1;let o=e<0?r.pos-n.nodeSize:r.pos;return!!(n.isAtom||(i=t.docView.descAt(o))&&!i.contentDOM)&&(he.isSelectable(n)?ts(t,new he(e<0?t.state.doc.resolve(r.pos-n.nodeSize):r)):!!Qe&&ts(t,new ne(t.state.doc.resolve(e<0?o:o+n.nodeSize))))}}function is(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function ss(t,e){let i=t.pmViewDesc;return i&&0==i.size&&(e<0||t.nextSibling||"BR"!=t.nodeName)}function rs(t,e){return e<0?function(t){let e=t.domSelectionRange(),i=e.focusNode,s=e.focusOffset;if(!i)return;let r,n,o=!1;for(_e&&1==i.nodeType&&s<is(i)&&ss(i.childNodes[s],-1)&&(o=!0);;)if(s>0){if(1!=i.nodeType)break;{let t=i.childNodes[s-1];if(ss(t,-1))r=i,n=--s;else{if(3!=t.nodeType)break;i=t,s=i.nodeValue.length}}}else{if(ns(i))break;{let e=i.previousSibling;for(;e&&ss(e,-1);)r=i.parentNode,n=Me(e),e=e.previousSibling;if(e)i=e,s=is(i);else{if(i=i.parentNode,i==t.dom)break;s=0}}}o?hs(t,i,s):r&&hs(t,r,n)}(t):function(t){let e=t.domSelectionRange(),i=e.focusNode,s=e.focusOffset;if(!i)return;let r,n,o=is(i);for(;;)if(s<o){if(1!=i.nodeType)break;if(!ss(i.childNodes[s],1))break;r=i,n=++s}else{if(ns(i))break;{let e=i.nextSibling;for(;e&&ss(e,1);)r=e.parentNode,n=Me(e)+1,e=e.nextSibling;if(e)i=e,s=0,o=is(i);else{if(i=i.parentNode,i==t.dom)break;s=o=0}}}r&&hs(t,r,n)}(t)}function ns(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function hs(t,e,i){if(3!=e.nodeType){let t,s;(s=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=s,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 s=t.domSelection();if(!s)return;if(Ie(s)){let t=document.createRange();t.setEnd(e,i),t.setStart(e,i),s.removeAllRanges(),s.addRange(t)}else s.extend&&s.extend(e,i);t.domObserver.setCurSelection();let{state:r}=t;setTimeout((()=>{t.state==r&&Hi(t)}),50)}function ls(t,e){let i=t.state.doc.resolve(e);if(!He&&!Ke&&i.parent.inlineContent){let s=t.coordsAtPos(e);if(e>i.start()){let i=t.coordsAtPos(e-1),r=(i.top+i.bottom)/2;if(r>s.top&&r<s.bottom&&Math.abs(i.left-s.left)>1)return i.left<s.left?"ltr":"rtl"}if(e<i.end()){let i=t.coordsAtPos(e+1),r=(i.top+i.bottom)/2;if(r>s.top&&r<s.bottom&&Math.abs(i.left-s.left)>1)return i.left>s.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(t.dom).direction?"rtl":"ltr"}function as(t,e,i){let s=t.state.selection;if(s instanceof ne&&!s.empty||i.indexOf("s")>-1)return!1;if(Ve&&i.indexOf("m")>-1)return!1;let{$from:r,$to:n}=s;if(!r.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let i=Zi(t.state,e);if(i&&i instanceof he)return ts(t,i)}if(!r.parent.inlineContent){let i=e<0?r:n,o=s instanceof ae?ee.near(i,e):ee.findFrom(i,e);return!!o&&ts(t,o)}return!1}function us(t,e){if(!(t.state.selection instanceof ne))return!0;let{$head:i,$anchor:s,empty:r}=t.state.selection;if(!i.sameParent(s))return!0;if(!r)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 s=t.state.tr;return e<0?s.delete(i.pos-n.nodeSize,i.pos):s.delete(i.pos,i.pos+n.nodeSize),t.dispatch(s),!0}return!1}function cs(t,e,i){t.domObserver.stop(),e.contentEditable=i,t.domObserver.start()}function fs(t,e){t.someProp("transformCopied",(i=>{e=i(e,t)}));let i=[],{content:s,openStart:r,openEnd:n}=e;for(;r>1&&n>1&&1==s.childCount&&1==s.firstChild.childCount;){r--,n--;let t=s.firstChild;i.push(t.type.name,t.attrs!=t.type.defaultAttrs?t.attrs:null),s=t.content}let o=t.someProp("clipboardSerializer")||ft.fromSchema(t.state.schema),h=Ms(),l=h.createElement("div");l.appendChild(o.serializeFragment(s,{document:h}));let a,u=l.firstChild,c=0;for(;u&&1==u.nodeType&&(a=ks[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",`${r} ${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 ds(t,e,i,s,r){let n,o,h=r.parent.type.spec.code;if(!i&&!e)return null;let l=!!e&&(s||h||!i);if(l){if(t.someProp("transformPastedText",(i=>{e=i(e,h||s,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,r,s,t)));if(i)o=i;else{let i=r.marks(),{schema:s}=t.state,o=ft.fromSchema(s);n=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach((t=>{let e=n.appendChild(document.createElement("p"));t&&e.appendChild(o.serializeNode(s.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,s=Ms().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t);if((i=r&&ks[r[1].toLowerCase()])&&(t=i.map((t=>"<"+t+">")).join("")+t+i.map((t=>"</"+t+">")).reverse().join("")),s.innerHTML=function(t){let e=window.trustedTypes;return e?(xs||(xs=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),xs.createHTML(t)):t}(t),i)for(let t=0;t<i.length;t++)s=s.querySelector(i[t])||s;return s}(i),Qe&&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 s=e[i];1==s.childNodes.length&&" "==s.textContent&&s.parentNode&&s.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),s)}}(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:r,ruleFromNode:t=>"BR"!=t.nodeName||t.nextSibling||!t.parentNode||ps.test(t.parentNode.nodeName)?null:{ignore:!0}})}if(u)o=function(t,e){if(!t.size)return t;let i,s=t.content.firstChild.type.schema;try{i=JSON.parse(e)}catch(e){return t}let{content:r,openStart:n,openEnd:o}=t;for(let t=i.length-2;t>=0;t-=2){let e=s.nodes[i[t]];if(!e||e.hasRequiredAttrs())break;r=c.from(e.create(i[t+1],r)),n++,o++}return new m(r,n,o)}(ys(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 s,r=e.node(i).contentMatchAt(e.index(i)),n=[];if(t.forEach((t=>{if(!n)return;let e,i=r.findWrapping(t.type);if(!i)return n=null;if(e=n.length&&s.length&&ws(i,s,t,n[n.length-1],0))n[n.length-1]=e;else{n.length&&(n[n.length-1]=ms(n[n.length-1],s.length));let e=gs(t,i);n.push(e),r=r.matchType(e.type),s=i}})),n)return c.from(n)}return t}(o.content,r),!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=ys(o,t,e)}return t.someProp("transformPasted",(e=>{o=e(o,t,l)})),o}const ps=/^(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 gs(t,e,i=0){for(let s=e.length-1;s>=i;s--)t=e[s].create(null,c.from(t));return t}function ws(t,e,i,s,r){if(r<t.length&&r<e.length&&t[r]==e[r]){let n=ws(t,e,i,s.lastChild,r+1);if(n)return s.copy(s.content.replaceChild(s.childCount-1,n));if(s.contentMatchAt(s.childCount).matchType(r==t.length-1?i.type:t[r+1]))return s.copy(s.content.append(c.from(gs(i,t,r+1))))}}function ms(t,e){if(0==e)return t;let i=t.content.replaceChild(t.childCount-1,ms(t.lastChild,e-1)),s=t.contentMatchAt(t.childCount).fillBefore(c.empty,!0);return t.copy(i.append(s))}function vs(t,e,i,s,r,n){let o=e<0?t.firstChild:t.lastChild,h=o.content;return t.childCount>1&&(n=0),r<s-1&&(h=vs(h,e,i,s,r+1,n)),r>=i&&(h=e<0?o.contentMatchAt(0).fillBefore(h,n<=r).append(h):h.append(o.contentMatchAt(o.childCount).fillBefore(c.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,o.copy(h))}function ys(t,e,i){return e<t.openStart&&(t=new m(vs(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),i<t.openEnd&&(t=new m(vs(t.content,1,i,t.openEnd,0,0),t.openStart,i)),t}const ks={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 bs=null;function Ms(){return bs||(bs=document.implementation.createHTMLDocument("title"))}let xs=null;const Cs={},As={},Ss={touchstart:!0,touchmove:!0};class Bs{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 Ts(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function Os(t){t.someProp("handleDOMEvents",(e=>{for(let i in e)t.input.eventHandlers[i]||t.dom.addEventListener(i,t.input.eventHandlers[i]=e=>Es(t,e))}))}function Es(t,e){return t.someProp("handleDOMEvents",(i=>{let s=i[e.type];return!!s&&(s(t,e)||e.defaultPrevented)}))}function Is(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 $s(t){return{left:t.clientX,top:t.clientY}}function Ps(t,e,i,s,r){if(-1==s)return!1;let n=t.state.doc.resolve(s);for(let s=n.depth+1;s>0;s--)if(t.someProp(e,(e=>s>n.depth?e(t,i,n.nodeAfter,n.before(s),r,!0):e(t,i,n.node(s),n.before(s),r,!1))))return!0;return!1}function Ds(t,e){if(t.focused||t.focus(),t.state.selection.eq(e))return;let i=t.state.tr.setSelection(e);i.setMeta("pointer",!0),t.dispatch(i)}function Rs(t,e,i,s){return Ps(t,"handleDoubleClickOn",e,i,s)||t.someProp("handleDoubleClick",(i=>i(t,e,s)))}function js(t,e,i,s){return Ps(t,"handleTripleClickOn",e,i,s)||t.someProp("handleTripleClick",(i=>i(t,e,s)))||function(t,e,i){if(0!=i.button)return!1;let s=t.state.doc;if(-1==e)return!!s.inlineContent&&(Ds(t,ne.create(s,0,s.content.size)),!0);let r=s.resolve(e);for(let e=r.depth+1;e>0;e--){let i=e>r.depth?r.nodeAfter:r.node(e),n=r.before(e);if(i.inlineContent)Ds(t,ne.create(s,n+1,n+1+i.content.size));else{if(!he.isSelectable(i))continue;Ds(t,he.create(s,n))}return!0}}(t,i,s)}function Fs(t){return Xs(t)}As.keydown=(t,e)=>{let i=e;if(t.input.shiftKey=16==i.keyCode||i.shiftKey,!zs(t,i)&&(t.input.lastKeyCode=i.keyCode,t.input.lastKeyCodeTime=Date.now(),!Je||!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,s=function(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}(e);if(8==i||Ve&&72==i&&"c"==s)return us(t,-1)||rs(t,-1);if(46==i&&!e.shiftKey||Ve&&68==i&&"c"==s)return us(t,1)||rs(t,1);if(13==i||27==i)return!0;if(37==i||Ve&&66==i&&"c"==s){let e=37==i?"ltr"==ls(t,t.state.selection.from)?-1:1:-1;return es(t,e,s)||rs(t,e)}if(39==i||Ve&&70==i&&"c"==s){let e=39==i?"ltr"==ls(t,t.state.selection.from)?1:-1:1;return es(t,e,s)||rs(t,e)}return 38==i||Ve&&80==i&&"c"==s?as(t,-1,s)||rs(t,-1):40==i||Ve&&78==i&&"c"==s?function(t){if(!Ye||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(e&&1==e.nodeType&&0==i&&e.firstChild&&"false"==e.firstChild.contentEditable){let i=e.firstChild;cs(t,i,"true"),setTimeout((()=>cs(t,i,"false")),20)}return!1}(t)||as(t,1,s)||rs(t,1):s==(Ve?"m":"c")&&(66==i||73==i||89==i||90==i)}(t,i)?i.preventDefault():Ts(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,$e(13,"Enter")))),t.input.lastIOSEnter=0)}),200)}},As.keyup=(t,e)=>{16==e.keyCode&&(t.input.shiftKey=!1)},As.keypress=(t,e)=>{let i=e;if(zs(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 s=t.state.selection;if(!(s instanceof ne&&s.$from.sameParent(s.$to))){let e=String.fromCharCode(i.charCode),r=()=>t.state.tr.insertText(e).scrollIntoView();/[\r\n]/.test(e)||t.someProp("handleTextInput",(i=>i(t,s.$from.pos,s.$to.pos,e,r)))||t.dispatch(r()),i.preventDefault()}};const Ns=Ve?"metaKey":"ctrlKey";Cs.mousedown=(t,e)=>{let i=e;t.input.shiftKey=i.shiftKey;let s=Fs(t),r=Date.now(),n="singleClick";r-t.input.lastClick.time<500&&function(t,e){let i=e.x-t.clientX,s=e.y-t.clientY;return i*i+s*s<100}(i,t.input.lastClick)&&!i[Ns]&&t.input.lastClick.button==i.button&&("singleClick"==t.input.lastClick.type?n="doubleClick":"doubleClick"==t.input.lastClick.type&&(n="tripleClick")),t.input.lastClick={time:r,x:i.clientX,y:i.clientY,type:n,button:i.button};let o=t.posAtCoords($s(i));o&&("singleClick"==n?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new Us(t,o,i,!!s)):("doubleClick"==n?Rs:js)(t,o.pos,o.inside,i)?i.preventDefault():Ts(t,"pointer"))};class Us{constructor(t,e,i,s){let r,n;if(this.view=t,this.pos=e,this.event=i,this.flushed=s,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=t.state.doc,this.selectNode=!!i[Ns],this.allowDefault=i.shiftKey,e.inside>-1)r=t.state.doc.nodeAt(e.inside),n=e.inside;else{let i=t.state.doc.resolve(e.pos);r=i.parent,n=i.depth?i.before():0}const o=s?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&&(r.type.spec.draggable&&!1!==r.type.spec.selectable||l instanceof he&&l.from<=n&&l.to>n)&&(this.mightDrag={node:r,pos:n,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!_e||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)),Ts(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($s(t))),this.updateAllowDefault(t),this.allowDefault||!e?Ts(this.view,"pointer"):function(t,e,i,s,r){return Ps(t,"handleClickOn",e,i,s)||t.someProp("handleClick",(i=>i(t,e,s)))||(r?function(t,e){if(-1==e)return!1;let i,s,r=t.state.selection;r instanceof he&&(i=r.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)){s=i&&r.$from.depth>0&&t>=r.$from.depth&&n.before(r.$from.depth+1)==r.$from.pos?n.before(r.$from.depth):n.before(t);break}}return null!=s&&(Ds(t,he.create(t.state.doc,s)),!0)}(t,i):function(t,e){if(-1==e)return!1;let i=t.state.doc.resolve(e),s=i.nodeAfter;return!!(s&&s.isAtom&&he.isSelectable(s))&&(Ds(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)?(Ds(this.view,ee.near(this.view.state.doc.resolve(e.pos))),t.preventDefault()):Ts(this.view,"pointer")}move(t){this.updateAllowDefault(t),Ts(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 zs(t,e){return!!t.composing||!!(Ye&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500)&&(t.input.compositionEndedAt=-2e8,!0)}Cs.touchstart=t=>{t.input.lastTouch=Date.now(),Fs(t),Ts(t,"pointer")},Cs.touchmove=t=>{t.input.lastTouch=Date.now(),Ts(t,"pointer")},Cs.contextmenu=t=>Fs(t);const _s=Je?5e3:-1;function Ls(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout((()=>Xs(t)),e))}function Hs(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 Xs(t,e=!1){if(!(Je&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Hs(t),e||t.docView&&t.docView.dirty){let i=_i(t),s=t.state.selection;return i&&!i.eq(s)?t.dispatch(t.state.tr.setSelection(i)):!t.markCursor&&!e||s.$from.node(s.$from.sharedDepth(s.to)).inlineContent?t.updateState(t.state):t.dispatch(t.state.tr.deleteSelection()),!0}return!1}}As.compositionstart=As.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,i=e.selection.$to;if(e.selection instanceof ne&&(e.storedMarks||!i.textOffset&&i.parentOffset&&i.nodeBefore.marks.some((t=>!1===t.type.spec.inclusive))||He&&Ke&&function(t){let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(!e||1!=e.nodeType||i>=e.childNodes.length)return!1;let s=e.childNodes[i];return 1==s.nodeType&&"false"==s.contentEditable}(t)))t.markCursor=t.state.storedMarks||i.marks(),Xs(t,!0),t.markCursor=null;else if(Xs(t,!e.selection.empty),_e&&e.selection.empty&&i.parentOffset&&!i.textOffset&&i.nodeBefore.marks.length){let e=t.domSelectionRange();for(let i=e.focusNode,s=e.focusOffset;i&&1==i.nodeType&&0!=s;){let e=s<0?i.lastChild:i.childNodes[s-1];if(!e)break;if(3==e.nodeType){let i=t.domSelection();i&&i.collapse(e,e.nodeValue.length);break}i=e,s=-1}}t.input.composing=!0}Ls(t,_s)},As.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.timeStamp,t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.badSafariComposition?t.domObserver.forceFlush():t.input.compositionPendingChanges&&Promise.resolve().then((()=>t.domObserver.flush())),t.input.compositionID++,Ls(t,20))};const Ys=Ue&&ze<15||We&&qe<604;function Ws(t,e,i,s,r){let n=ds(t,e,i,s,t.state.selection.$from);if(t.someProp("handlePaste",(e=>e(t,r,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,s):t.state.tr.replaceSelection(n);return t.dispatch(h.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Vs(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," "):""}Cs.copy=As.cut=(t,e)=>{let i=e,s=t.state.selection,r="cut"==i.type;if(s.empty)return;let n=Ys?null:i.clipboardData,o=s.content(),{dom:h,text:l}=fs(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 s=getSelection(),r=document.createRange();r.selectNodeContents(e),t.dom.blur(),s.removeAllRanges(),s.addRange(r),setTimeout((()=>{i.parentNode&&i.parentNode.removeChild(i),t.focus()}),50)}(t,h),r&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},As.paste=(t,e)=>{let i=e;if(t.composing&&!Je)return;let s=Ys?null:i.clipboardData,r=t.input.shiftKey&&45!=t.input.lastKeyCode;s&&Ws(t,Vs(s),s.getData("text/html"),r,i)?i.preventDefault():function(t,e){if(!t.dom.parentNode)return;let i=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,s=t.dom.parentNode.appendChild(document.createElement(i?"textarea":"div"));i||(s.contentEditable="true"),s.style.cssText="position: fixed; left: -10000px; top: 10px",s.focus();let r=t.input.shiftKey&&45!=t.input.lastKeyCode;setTimeout((()=>{t.focus(),s.parentNode&&s.parentNode.removeChild(s),i?Ws(t,s.value,null,r,e):Ws(t,s.textContent,s.innerHTML,r,e)}),50)}(t,i)};class Ks{constructor(t,e,i){this.slice=t,this.move=e,this.node=i}}const Js=Ve?"altKey":"ctrlKey";function Qs(t,e){let i;return t.someProp("dragCopies",(t=>{i=i||t(e)})),null!=i?!i:!e[Js]}Cs.dragstart=(t,e)=>{let i=e,s=t.input.mouseDown;if(s&&s.done(),!i.dataTransfer)return;let r,n=t.state.selection,o=n.empty?null:t.posAtCoords($s(i));if(o&&o.pos>=n.from&&o.pos<=(n instanceof he?n.to-1:n.to));else if(s&&s.mightDrag)r=he.create(t.state.doc,s.mightDrag.pos);else if(i.target&&1==i.target.nodeType){let e=t.docView.nearestDesc(i.target,!0);e&&e.node.type.spec.draggable&&e!=t.docView&&(r=he.create(t.state.doc,e.posBefore))}let h=(r||t.state.selection).content(),{dom:l,text:a,slice:u}=fs(t,h);(!i.dataTransfer.files.length||!He||Xe>120)&&i.dataTransfer.clearData(),i.dataTransfer.setData(Ys?"Text":"text/html",l.innerHTML),i.dataTransfer.effectAllowed="copyMove",Ys||i.dataTransfer.setData("text/plain",a),t.dragging=new Ks(u,Qs(t,i),r)},Cs.dragend=t=>{let e=t.dragging;window.setTimeout((()=>{t.dragging==e&&(t.dragging=null)}),50)},As.dragover=As.dragenter=(t,e)=>e.preventDefault(),As.drop=(t,e)=>{try{!function(t,e,i){if(!e.dataTransfer)return;let s=t.posAtCoords($s(e));if(!s)return;let r=t.state.doc.resolve(s.pos),n=i&&i.slice;n?t.someProp("transformPasted",(e=>{n=e(n,t,!1)})):n=ds(t,Vs(e.dataTransfer),Ys?null:e.dataTransfer.getData("text/html"),!1,r);let o=!(!i||!Qs(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 s=t.resolve(e);if(!i.content.size)return e;let r=i.content;for(let t=0;t<i.openStart;t++)r=r.firstChild.content;for(let t=1;t<=(0==i.openStart&&i.size?2:1);t++)for(let e=s.depth;e>=0;e--){let i=e==s.depth?0:s.pos<=(s.start(e+1)+s.end(e+1))/2?-1:1,n=s.index(e)+(i>0?1:0),o=s.node(e),h=!1;if(1==t)h=o.canReplace(n,n,r);else{let t=o.contentMatchAt(n).findWrapping(r.firstChild.type);h=t&&o.canReplaceWith(n,n,t[0])}if(h)return 0==i?s.pos:i<0?s.before(e+1):s.after(e+1)}return null}(t.state.doc,r.pos,n):r.pos;null==h&&(h=r.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,s,r)=>e=r)),l.setSelection(Qi(t,f,l.doc.resolve(e)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}(t,e,t.dragging)}finally{t.dragging=null}},Cs.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))},Cs.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)},Cs.beforeinput=(t,e)=>{if(He&&Je&&"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,$e(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())}),50)}};for(let t in As)Cs[t]=As[t];function qs(t,e){if(t==e)return!0;for(let i in t)if(t[i]!==e[i])return!1;for(let i in e)if(!(i in t))return!1;return!0}class Gs{constructor(t,e){this.toDOM=t,this.spec=e||sr,this.side=this.spec.side||0}map(t,e,i,s){let{pos:r,deleted:n}=t.mapResult(e.from+s,this.side<0?-1:1);return n?null:new er(r-i,r-i,this)}valid(){return!0}eq(t){return this==t||t instanceof Gs&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&qs(this.spec,t.spec))}destroy(t){this.spec.destroy&&this.spec.destroy(t)}}class Zs{constructor(t,e){this.attrs=t,this.spec=e||sr}map(t,e,i,s){let r=t.map(e.from+s,this.spec.inclusiveStart?-1:1)-i,n=t.map(e.to+s,this.spec.inclusiveEnd?1:-1)-i;return r>=n?null:new er(r,n,this)}valid(t,e){return e.from<e.to}eq(t){return this==t||t instanceof Zs&&qs(this.attrs,t.attrs)&&qs(this.spec,t.spec)}static is(t){return t.type instanceof Zs}destroy(){}}class tr{constructor(t,e){this.attrs=t,this.spec=e||sr}map(t,e,i,s){let r=t.mapResult(e.from+s,1);if(r.deleted)return null;let n=t.mapResult(e.to+s,-1);return n.deleted||n.pos<=r.pos?null:new er(r.pos-i,n.pos-i,this)}valid(t,e){let i,{index:s,offset:r}=t.content.findIndex(e.from);return r==e.from&&!(i=t.child(s)).isText&&r+i.nodeSize==e.to}eq(t){return this==t||t instanceof tr&&qs(this.attrs,t.attrs)&&qs(this.spec,t.spec)}destroy(){}}class er{constructor(t,e,i){this.from=t,this.to=e,this.type=i}copy(t,e){return new er(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 er(t,t,new Gs(e,i))}static inline(t,e,i,s){return new er(t,e,new Zs(i,s))}static node(t,e,i,s){return new er(t,e,new tr(i,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof Zs}get widget(){return this.type instanceof Gs}}const ir=[],sr={};class rr{constructor(t,e){this.local=t.length?t:ir,this.children=e.length?e:ir}static create(t,e){return e.length?ur(e,t,0,sr):nr}find(t,e,i){let s=[];return this.findInner(null==t?0:t,null==e?1e9:e,s,0,i),s}findInner(t,e,i,s,r){for(let n=0;n<this.local.length;n++){let o=this.local[n];o.from<=e&&o.to>=t&&(!r||r(o.spec))&&i.push(o.copy(o.from+s,o.to+s))}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,s+o,r)}}map(t,e,i){return this==nr||0==t.maps.length?this:this.mapInner(t,e,0,0,i||sr)}mapInner(t,e,i,s,r){let n;for(let o=0;o<this.local.length;o++){let h=this.local[o].map(t,i,s);h&&h.type.valid(e,h)?(n||(n=[])).push(h):r.onRemove&&r.onRemove(this.local[o].spec)}return this.children.length?function(t,e,i,s,r,n,o){let h=t.slice();for(let t=0,e=n;t<i.maps.length;t++){let s=0;i.maps[t].forEach(((t,i,r,n)=>{let o=n-r-(i-t);for(let r=0;r<h.length;r+=3){let n=h[r+1];if(n<0||t>n+e-s)continue;let l=h[r]+e-s;i>=l?h[r+1]=t<=l?-2:-1:t>=e&&o&&(h[r]+=o,h[r+1]+=o)}s+=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-r;if(u<0||u>=s.content.size){l=!0;continue}let c=i.map(t[e+1]+n,-1)-r,{index:f,offset:d}=s.content.findIndex(u),p=s.maybeChild(f);if(p&&d==u&&d+p.nodeSize==c){let s=h[e+2].mapInner(i,p,a+1,t[e]+n+1,o);s!=nr?(h[e]=u,h[e+1]=c,h[e+2]=s):(h[e+1]=-2,l=!0)}else l=!0}if(l){let l=function(t,e,i,s,r,n,o){function h(t,e){for(let n=0;n<t.local.length;n++){let h=t.local[n].map(s,r,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,r,n,o),a=ur(l,s,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 rr(e.sort(cr),h)}(this.children,n||[],t,e,i,s,r):n?new rr(n.sort(cr),ir):nr}add(t,e){return e.length?this==nr?rr.create(t,e):this.addInner(t,e,0):this}addInner(t,e,i){let s,r=0;t.forEach(((t,n)=>{let o,h=n+i;if(o=lr(e,t,h)){for(s||(s=this.children.slice());r<s.length&&s[r]<n;)r+=3;s[r]==n?s[r+2]=s[r+2].addInner(t,o,h+1):s.splice(r,0,n,n+t.nodeSize,ur(o,t,h+1,sr)),r+=3}}));let n=hr(r?ar(e):e,-i);for(let e=0;e<n.length;e++)n[e].type.valid(t,n[e])||n.splice(e--,1);return new rr(n.length?this.local.concat(n).sort(cr):this.local,s||this.children)}remove(t){return 0==t.length||this==nr?this:this.removeInner(t,0)}removeInner(t,e){let i=this.children,s=this.local;for(let s=0;s<i.length;s+=3){let r,n=i[s]+e,o=i[s+1]+e;for(let e,i=0;i<t.length;i++)(e=t[i])&&e.from>n&&e.to<o&&(t[i]=null,(r||(r=[])).push(e));if(!r)continue;i==this.children&&(i=this.children.slice());let h=i[s+2].removeInner(r,n+1);h!=nr?i[s+2]=h:(i.splice(s,3),s-=3)}if(s.length)for(let i,r=0;r<t.length;r++)if(i=t[r])for(let t=0;t<s.length;t++)s[t].eq(i,e)&&(s==this.local&&(s=this.local.slice()),s.splice(t--,1));return i==this.children&&s==this.local?this:s.length||i.length?new rr(s,i):nr}forChild(t,e){if(this==nr)return this;if(e.isLeaf)return rr.empty;let i,s;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){this.children[e]==t&&(i=this.children[e+2]);break}let r=t+1,n=r+e.content.size;for(let t=0;t<this.local.length;t++){let e=this.local[t];if(e.from<n&&e.to>r&&e.type instanceof Zs){let t=Math.max(r,e.from)-r,i=Math.min(n,e.to)-r;t<i&&(s||(s=[])).push(e.copy(t,i))}}if(s){let t=new rr(s.sort(cr),ir);return i?new or([t,i]):t}return i||nr}eq(t){if(this==t)return!0;if(!(t instanceof rr)||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 fr(this.localsInner(t))}localsInner(t){if(this==nr)return ir;if(t.inlineContent||!this.local.some(Zs.is))return this.local;let e=[];for(let t=0;t<this.local.length;t++)this.local[t].type instanceof Zs||e.push(this.local[t]);return e}forEachSet(t){t(this)}}rr.empty=new rr([],[]),rr.removeOverlap=fr;const nr=rr.empty;class or{constructor(t){this.members=t}map(t,e){const i=this.members.map((i=>i.map(t,e,sr)));return or.from(i)}forChild(t,e){if(e.isLeaf)return rr.empty;let i=[];for(let s=0;s<this.members.length;s++){let r=this.members[s].forChild(t,e);r!=nr&&(r instanceof or?i=i.concat(r.members):i.push(r))}return or.from(i)}eq(t){if(!(t instanceof or)||t.members.length!=this.members.length)return!1;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return!1;return!0}locals(t){let e,i=!0;for(let s=0;s<this.members.length;s++){let r=this.members[s].localsInner(t);if(r.length)if(e){i&&(e=e.slice(),i=!1);for(let t=0;t<r.length;t++)e.push(r[t])}else e=r}return e?fr(i?e:e.sort(cr)):ir}static from(t){switch(t.length){case 0:return nr;case 1:return t[0];default:return new or(t.every((t=>t instanceof rr))?t:t.reduce(((t,e)=>t.concat(e instanceof rr?e:e.members)),[]))}}forEachSet(t){for(let e=0;e<this.members.length;e++)this.members[e].forEachSet(t)}}function hr(t,e){if(!e||!t.length)return t;let i=[];for(let s=0;s<t.length;s++){let r=t[s];i.push(new er(r.from+e,r.to+e,r.type))}return i}function lr(t,e,i){if(e.isLeaf)return null;let s=i+e.nodeSize,r=null;for(let e,n=0;n<t.length;n++)(e=t[n])&&e.from>i&&e.to<s&&((r||(r=[])).push(e),t[n]=null);return r}function ar(t){let e=[];for(let i=0;i<t.length;i++)null!=t[i]&&e.push(t[i]);return e}function ur(t,e,i,s){let r=[],n=!1;e.forEach(((e,o)=>{let h=lr(t,e,o+i);if(h){n=!0;let t=ur(h,e,i+o+1,s);t!=nr&&r.push(o,o+e.nodeSize,t)}}));let o=hr(n?ar(t):t,-i).sort(cr);for(let t=0;t<o.length;t++)o[t].type.valid(e,o[t])||(s.onRemove&&s.onRemove(o[t].spec),o.splice(t--,1));return o.length||r.length?new rr(o,r):nr}function cr(t,e){return t.from-e.from||t.to-e.to}function fr(t){let e=t;for(let i=0;i<e.length-1;i++){let s=e[i];if(s.from!=s.to)for(let r=i+1;r<e.length;r++){let n=e[r];if(n.from!=s.from){n.from<s.to&&(e==t&&(e=t.slice()),e[i]=s.copy(s.from,n.from),dr(e,r,s.copy(n.from,s.to)));break}n.to!=s.to&&(e==t&&(e=t.slice()),e[r]=n.copy(n.from,s.to),dr(e,r+1,n.copy(s.to,n.to)))}}return e}function dr(t,e,i){for(;e<t.length&&cr(i,t[e])>0;)e++;t.splice(e,0,i)}function pr(t){let e=[];return t.someProp("decorations",(i=>{let s=i(t.state);s&&s!=nr&&e.push(s)})),t.cursorWrapper&&e.push(rr.create(t.state.doc,[t.cursorWrapper.deco])),or.from(e)}const gr={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},wr=Ue&&ze<=11;class mr{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 vr{constructor(t,e){this.view=t,this.handleDOMChange=e,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new mr,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()})),wr&&(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,gr)),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 s=t.anchorNode;s;s=xe(s))if(i.has(s)){e=s;break}let s=e&&this.view.docView.nearestDesc(e);return s&&s.ignoreMutation({type:"selection",target:3==e.nodeType?e.parentNode:e})?(this.setCurSelection(),!0):void 0}pendingRecords(){if(this.observer)for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}flush(){let{view:t}=this;if(!t.docView||this.flushingSoon>-1)return;let e=this.pendingRecords();e.length&&(this.queue=[]);let i=t.domSelectionRange(),s=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(i)&&qi(t)&&!this.ignoreSelectionChange(i),r=-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&&(r=r<0?i.from:Math.min(i.from,r),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(_e&&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 s of e){let e=s.parentNode;!e||"LI"!=e.nodeName||i&&Mr(t,i)==e||s.remove()}}}}else for(let t of h)if("BR"==t.nodeName&&t.parentNode){let e=t.nextSibling;for(;e&&1==e.nodeType;){if("false"==e.contentEditable){t.parentNode.removeChild(t);break}e=e.firstChild}}let l=null;r<0&&s&&t.input.lastFocus>Date.now()-200&&Math.max(t.input.lastTouch,t.input.lastClick.time)<Date.now()-300&&Ie(i)&&(l=_i(t))&&l.eq(ee.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,Hi(t),this.currentSelection.set(i),t.scrollToSelection()):(r>-1||s)&&(r>-1&&(t.docView.markDirty(r,n),function(t){if(!yr.has(t)&&(yr.set(t,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace))){if(t.requiresGeckoHackNode=_e,kr)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."),kr=!0}}(t)),t.input.badSafariComposition&&(t.input.badSafariComposition=!1,function(t,e){var i;let{focusNode:s,focusOffset:r}=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),s==n&&t.domSelection().collapse(n,r)}else n.parentNode.removeChild(n)}}(t,h)),this.handleDOMChange(r,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 s=t.addedNodes[i];e.push(s),3==s.nodeType&&(this.lastChangedTextNode=s)}if(i.contentDOM&&i.contentDOM!=i.dom&&!i.contentDOM.contains(t.target))return{from:i.posBefore,to:i.posAfter};let s=t.previousSibling,r=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)&&(s=i),(!n||Array.prototype.indexOf.call(t.addedNodes,n)<0)&&(r=n)}let n=s&&s.parentNode==t.target?Me(s)+1:0,o=i.localPosFromDOM(t.target,n,-1),h=r&&r.parentNode==t.target?Me(r):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 yr=new WeakMap,kr=!1;function br(t,e){let i=e.startContainer,s=e.startOffset,r=e.endContainer,n=e.endOffset,o=t.domAtPos(t.state.selection.anchor);return Se(o.node,o.offset,r,n)&&([i,s,r,n]=[r,n,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:n}}function Mr(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 xr(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 Cr=/^(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 Ar(t,e,i){return Math.max(i.anchor,i.head)>e.content.size?null:Qi(t,e.resolve(i.anchor),e.resolve(i.head))}function Sr(t,e,i){let s=t.depth,r=e?t.end():t.pos;for(;s>0&&(e||t.indexAfter(s)==t.node(s).childCount);)s--,r++,e=!1;if(i){let e=t.node(s).maybeChild(t.indexAfter(s));for(;e&&!e.isLeaf;)e=e.firstChild,r++}return r}function Br(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 Tr{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 Bs,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=e,this.state=e.state,this.directPlugins=e.plugins||[],this.directPlugins.forEach(Pr),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=Ir(this),Er(this),this.nodeViews=$r(this),this.docView=Ai(this.state.doc,Or(this),pr(this),this.dom,this),this.domObserver=new vr(this,((t,e,i,s)=>function(t,e,i,s,r){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=_i(t,e);if(i&&!t.state.selection.eq(i)){if(He&&Je&&13===t.input.lastKeyCode&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",(e=>e(t,$e(13,"Enter")))))return;let s=t.state.tr.setSelection(i);"pointer"==e?s.setMeta("pointer",!0):"key"==e&&s.scrollIntoView(),n&&s.setMeta("composition",n),t.dispatch(s)}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 s,{node:r,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)&&(s=[{node:u,offset:a.anchorOffset}],Ie(a)||s.push({node:a.focusNode,offset:a.focusOffset})),He&&8===t.input.lastKeyCode)for(let t=o;t>n;t--){let e=r.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(r,{topNode:d.parent,topMatch:d.parent.contentMatchAt(d.index()),topOpen:!0,from:n,to:o,preserveWhitespace:"pre"!=d.parent.type.whitespace||"full",findPositions:s,ruleFromNode:xr,context:d});if(s&&null!=s[0].pos){let t=s[0].pos,e=s[1]&&s[1].pos;null==e&&(e=t),p={anchor:t+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,s,r){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"==r&&(s-=o+Math.max(0,n-Math.min(o,h))-n),o<n&&t.size<e.size){let t=s<=n&&s>=o?n-s:0;n-=t,n&&n<e.size&&Br(e.textBetween(n-1,n+1))&&(n+=t?1:-1),h=n+(h-o),o=n}else if(h<n){let e=s<=n&&s>=h?n-s:0;n-=e,n&&n<t.size&&Br(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||Je)&&r.some((t=>1==t.nodeType&&!Cr.test(t.nodeName)))&&(!g||g.endA>=g.endB)&&t.someProp("handleKeyDown",(e=>e(t,$e(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(!g){if(!(s&&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=Ar(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||r.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,$e(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(t.state.selection.anchor>g.start&&function(t,e,i,s,r){if(i-e<=r.pos-s.pos||Sr(s,!0,!1)<r.pos)return!1;let n=t.resolve(e);if(!s.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(Sr(n,!0,!0));return!(!o.parent.isTextblock||o.pos>i||Sr(o,!0,!1)<i)&&s.parent.content.cut(s.parentOffset).eq(o.parent.content)}(d,g.start,g.endA,w,m)&&t.someProp("handleKeyDown",(e=>e(t,$e(8,"Backspace")))))return void(Je&&He&&t.domObserver.suppressSelectionUpdates());He&&g.endB==g.start&&(t.input.lastChromeDelete=Date.now()),Je&&!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,$e(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=Ar(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,s,r,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)s=h[0],i="add",r=t=>t.mark(s.addToSet(t.marks));else{if(0!=h.length||1!=l.length)return null;s=l[0],i="remove",r=t=>t.mark(s.removeFromSet(t.marks))}let a=[];for(let t=0;t<e.childCount;t++)a.push(r(e.child(t)));if(c.from(a).eq(t))return{mark:s,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",(s=>s(t,b,M,e,i)))||t.dispatch(i())}else t.dispatch(x());else t.dispatch(x())}(this,t,e,i,s))),this.domObserver.start(),function(t){for(let e in Cs){let i=Cs[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=e=>{!Is(t,e)||Es(t,e)||!t.editable&&e.type in As||i(t,e)},Ss[e]?{passive:!0}:void 0)}Ye&&t.dom.addEventListener("input",(()=>null)),Os(t)}(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let t=this._props;this._props={};for(let e in t)this._props[e]=t[e];this._props.state=this.state}return this._props}update(t){t.handleDOMEvents!=this._props.handleDOMEvents&&Os(this);let e=this._props;this._props=t,t.plugins&&(t.plugins.forEach(Pr),this.directPlugins=t.plugins),this.updateStateInner(t.state,e)}setProps(t){let e={};for(let t in this._props)e[t]=this._props[t];e.state=this.state;for(let i in t)e[i]=t[i];this.update(e)}updateState(t){this.updateStateInner(t,this._props)}updateStateInner(t,e){var i;let s=this.state,r=!1,n=!1;t.storedMarks&&this.composing&&(Hs(this),n=!0),this.state=t;let o=s.plugins!=t.plugins||this._props.plugins!=e.plugins;if(o||this._props.plugins!=e.plugins||this._props.nodeViews!=e.nodeViews){let t=$r(this);(function(t,e){let i=0,s=0;for(let s in t){if(t[s]!=e[s])return!0;i++}for(let t in e)s++;return i!=s})(t,this.nodeViews)&&(this.nodeViews=t,r=!0)}(o||e.handleDOMEvents!=this._props.handleDOMEvents)&&Os(this),this.editable=Ir(this),Er(this);let h=pr(this),l=Or(this),a=s.plugins==t.plugins||s.doc.eq(t.doc)?t.scrollToSelection>s.scrollToSelection?"to selection":"preserve":"reset",u=r||!this.docView.matchesNode(t.doc,l,h);!u&&t.selection.eq(s.selection)||(n=!0);let c="preserve"==a&&n&&null==this.dom.style.overflowAnchor&&function(t){let e,i,s=t.dom.getBoundingClientRect(),r=Math.max(0,s.top);for(let n=(s.left+s.right)/2,o=r+1;o<Math.min(innerHeight,s.bottom);o+=5){let s=t.root.elementFromPoint(n,o);if(!s||s==t.dom||!t.dom.contains(s))continue;let h=s.getBoundingClientRect();if(h.top>=r-20){e=s,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&&!s.selection.empty&&!t.selection.empty&&function(t,e){let i=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(i)!=e.$anchor.start(i)}(s.selection,t.selection);if(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),s=function(t,e){for(;;){if(3==t.nodeType&&e<t.nodeValue.length)return t;if(1==t.nodeType&&e<t.childNodes.length){if("false"==t.contentEditable)return null;t=t.childNodes[e],e=0}else{if(!t.parentNode||Ee(t))return null;e=Me(t)+1,t=t.parentNode}}}(e.focusNode,e.focusOffset);if(i&&s&&i!=s){let e=s.pmViewDesc,r=t.domObserver.lastChangedTextNode;if(i==r||s==r)return r;if(!e||!e.isText(s.nodeValue))return s;if(t.input.compositionNode==s){let t=i.pmViewDesc;if(t&&t.isText(i.nodeValue))return s}}return i||s}(this)),!r&&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):(Ki(this,t.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),(null===(i=this.dragging)||void 0===i?void 0:i.node)&&!s.doc.eq(t.doc)&&this.updateDraggedNode(this.dragging,s),"reset"==a?this.dom.scrollTop=0:"to selection"==a?this.scrollToSelection():c&&function({refDOM:t,refTop:e,stack:i}){let s=t?t.getBoundingClientRect().top:0;si(i,0==s?0:s-e)}(c)}scrollToSelection(){let t=this.domSelectionRange().focusNode;if(t&&this.dom.contains(1==t.nodeType?t:t.parentNode))if(this.someProp("handleScrollToSelection",(t=>t(this))));else if(this.state.selection instanceof 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,s=-1;if(i.from<this.state.doc.content.size&&this.state.doc.nodeAt(i.from)==i.node)s=i.from;else{let t=i.from+(this.state.doc.content.size-e.doc.content.size);(t>0&&t<this.state.doc.content.size&&this.state.doc.nodeAt(t))==i.node&&(s=t)}this.dragging=new Ks(t.slice,t.move,s<0?void 0:he.create(this.state.doc,s))}someProp(t,e){let i,s=this._props&&this._props[t];if(null!=s&&(i=e?e(s):s))return i;for(let s=0;s<this.directPlugins.length;s++){let r=this.directPlugins[s].props[t];if(null!=r&&(i=e?e(r):r))return i}let r=this.state.plugins;if(r)for(let s=0;s<r.length;s++){let n=r[s].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(ri)return t.focus(ri);let e=ii(t);t.focus(null==ri?{get preventScroll(){return ri={preventScroll:!0},!0}}:void 0),ri||(ri=!1,si(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 s=this.docView.posFromDOM(t,e,i);if(null==s)throw new RangeError("DOM position not inside the editor");return s}endOfTextblock(t,e){return function(t,e,i){return mi==e&&vi==i?yi:(mi=e,vi=i,yi="up"==i||"down"==i?function(t,e,i){let s=e.selection,r="up"==i?s.$from:s.$to;return gi(t,e,(()=>{let{node:e}=t.docView.domFromPos(r.pos,"up"==i?-1:1);for(;;){let i=t.docView.nearestDesc(e,!0);if(!i)break;if(i.node.isBlock){e=i.contentDOM||i.dom;break}e=i.dom.parentNode}let s=fi(t,r.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 r=e[t];if(r.bottom>r.top+1&&("up"==i?s.top-r.top>2*(r.bottom-s.top):r.bottom-s.bottom>2*(s.bottom-r.top)))return!1}}return!0}))}(t,e,i):function(t,e,i){let{$head:s}=e.selection;if(!s.parent.isTextblock)return!1;let r=s.parentOffset,n=!r,o=r==s.parent.content.size,h=t.domSelection();return h?wi.test(s.parent.textContent)&&h.modify?gi(t,e,(()=>{let{focusNode:e,focusOffset:r,anchorNode:n,anchorOffset:o}=t.domSelectionRange(),l=h.caretBidiLevel;h.modify("move",i,"character");let a=s.depth?t.docView.domAfterPos(s.before()):t.dom,{focusNode:u,focusOffset:c}=t.domSelectionRange(),f=u&&!a.contains(1==u.nodeType?u:u.parentNode)||e==u&&r==c;try{h.collapse(n,o),e&&(e!=n||r!=o)&&h.extend&&h.extend(e,r)}catch(t){}return null!=l&&(h.caretBidiLevel=l),f})):"left"==i||"backward"==i?n:o:s.pos==s.start()||s.pos==s.end()}(t,e,i))}(this,e||this.state,t)}pasteHTML(t,e){return Ws(this,"",t,!1,e||new ClipboardEvent("paste"))}pasteText(t,e){return Ws(this,t,null,!0,e||new ClipboardEvent("paste"))}serializeForClipboard(t){return fs(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,[],pr(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){Es(t,e)||!Cs[e.type]||!t.editable&&e.type in As||Cs[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 br(t,i)}let i;function s(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",s,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",s,!0),i?br(t,i):null}(this,t)||t:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function Or(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"),[er.node(0,t.state.doc.content.size,e)]}function Er(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:er.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Ir(t){return!t.someProp("editable",(e=>!1===e(t.state)))}function $r(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 Pr(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")}Tr.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};const Dr=["p",0],Rr=["blockquote",0],jr=["hr"],Fr=["pre",["code",0]],Nr=["br"],Ur=["em",0],zr=["strong",0],_r=["code",0],Lr=new tt({nodes:{doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:()=>Dr},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:()=>Rr},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>jr},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:()=>Fr},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs:t=>({src:t.getAttribute("src"),title:t.getAttribute("title"),alt:t.getAttribute("alt")})}],toDOM(t){let{src:e,alt:i,title:s}=t.attrs;return["img",{src:e,alt:i,title:s}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM:()=>Nr}},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:()=>Ur},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:()=>zr},code:{code:!0,parseDOM:[{tag:"code"}],toDOM:()=>_r}}}),Hr=["ol",0],Xr=["ul",0],Yr=["li",0],Wr={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?Hr:["ol",{start:t.attrs.order},0]},Vr={parseDOM:[{tag:"ul"}],toDOM:()=>Xr},Kr={parseDOM:[{tag:"li"}],toDOM:()=>Yr,defining:!0};function Jr(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 Qr(t,e,i){return t.append({ordered_list:Jr(Wr,{content:"list_item+",group:i}),bullet_list:Jr(Vr,{content:"list_item+",group:i}),list_item:Jr(Kr,{content:e})})}for(var qr={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:"'"},Gr={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Zr="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++)qr[48+en]=qr[96+en]=String(en);for(en=1;en<=24;en++)qr[en+111]="F"+en;for(en=65;en<=90;en++)qr[en]=String.fromCharCode(en+32),Gr[en]=String.fromCharCode(en);for(var sn in qr)Gr.hasOwnProperty(sn)||(Gr[sn]=qr[sn]);const rn="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,s,r,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))r=!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))s=!0;else{if(!/^mod$/i.test(o))throw new Error("Unrecognized modifier name: "+o);rn?r=!0:i=!0}}return e&&(o="Alt-"+o),i&&(o="Ctrl-"+o),r&&(o="Meta-"+o),s&&(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 s,r=function(t){var e=!(Zr&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||tn&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?Gr:qr)[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(r,i)];if(n&&n(t.state,t.dispatch,t))return!0;if(1==r.length&&" "!=r){if(i.shiftKey){let s=e[hn(r,i,!1)];if(s&&s(t.state,t.dispatch,t))return!0}if((i.altKey||i.metaKey||i.ctrlKey)&&!(nn&&i.ctrlKey&&i.altKey)&&(s=qr[i.keyCode])&&s!=r){let r=e[hn(s,i)];if(r&&r(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 s=t;s;s="start"==e?s.firstChild:s.lastChild){if(s.isTextblock)return!0;if(i&&1!=s.childCount)return!1}return!1}function 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,s){let r,n,o=e.nodeBefore,h=e.nodeAfter,l=o.type.spec.isolating||h.type.spec.isolating;if(!l&&function(t,e,i){let s=e.nodeBefore,r=e.nodeAfter,n=e.index();return!(!(s&&r&&s.type.compatibleContent(r.type))||(!s.content.size&&e.parent.canReplace(n-1,n)?(i&&i(t.tr.delete(e.pos-s.nodeSize,e.pos).scrollIntoView()),0):!e.parent.canReplace(n,n+1)||!r.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&&(r=(n=o.contentMatchAt(o.childCount)).findWrapping(h.type))&&n.matchType(r[0]||h.type).validEnd){if(i){let s=e.pos+h.nodeSize,n=c.empty;for(let t=r.length-1;t>=0;t--)n=c.from(r[t].create(null,n));n=c.from(o.copy(n));let l=t.tr.step(new It(e.pos-1,s,e.pos,s,new m(n,1,0),r.length,!0)),a=l.doc.resolve(s+2*r.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||s>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 s=o,r=[];for(;r.push(s),!s.isTextblock;)s=s.lastChild;let n=h,l=1;for(;!n.isTextblock;n=n.firstChild)l++;if(s.canReplace(s.childCount,s.childCount,n.content)){if(i){let s=c.empty;for(let t=r.length-1;t>=0;t--)s=c.from(r[t].copy(s));i(t.tr.step(new It(e.pos-r.length,e.pos+h.nodeSize,e.pos+l,e.pos+h.nodeSize-l,new m(s,r.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function wn(t){return function(e,i){let s=e.selection,r=t<0?s.$from:s.$to,n=r.depth;for(;r.node(n).isInline;){if(!n)return!1;n--}return!!r.node(n).isTextblock&&(i&&i(e.tr.setSelection(ne.create(e.doc,t<0?r.start(n):r.end(n)))),!0)}}const mn=wn(-1),vn=wn(1);function yn(...t){return function(e,i,s){for(let r=0;r<t.length;r++)if(t[r](e,i,s))return!0;return!1}}let kn=yn(un,((t,e,i)=>{let s=function(t,e){let{$cursor:i}=t.selection;return!i||(e?!e.endOfTextblock("backward",t):i.parentOffset>0)?null:i}(t,i);if(!s)return!1;let r=fn(s);if(!r){let i=s.blockRange(),r=i&&Rt(i);return null!=r&&(e&&e(t.tr.lift(i,r).scrollIntoView()),!0)}let n=r.nodeBefore;if(gn(t,r,e,-1))return!0;if(0==s.parent.content.size&&(cn(n,"end")||he.isSelectable(n)))for(let i=s.depth;;i--){let o=zt(t.doc,s.before(i),s.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(r.pos,-1)),-1):he.create(i.doc,r.pos-n.nodeSize)),e(i.scrollIntoView())}return!0}if(1==i||s.node(i-1).childCount>1)break}return!(!n.isAtom||r.depth!=s.depth-1||(e&&e(t.tr.delete(r.pos-n.nodeSize,r.pos).scrollIntoView()),0))}),((t,e,i)=>{let{$head:s,empty:r}=t.selection,n=s;if(!r)return!1;if(s.parent.isTextblock){if(i?!i.endOfTextblock("backward",t):s.parentOffset>0)return!1;n=fn(s)}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 s=function(t,e){let{$cursor:i}=t.selection;return!i||(e?!e.endOfTextblock("forward",t):i.parentOffset<i.parent.content.size)?null:i}(t,i);if(!s)return!1;let r=dn(s);if(!r)return!1;let n=r.nodeAfter;if(gn(t,r,e,1))return!0;if(0==s.parent.content.size&&(cn(n,"start")||he.isSelectable(n))){let i=zt(t.doc,s.before(),s.after(),m.empty);if(i&&i.slice.size<i.to-i.from){if(e){let s=t.tr.step(i);s.setSelection(cn(n,"start")?ee.findFrom(s.doc.resolve(s.mapping.map(r.pos)),1):he.create(s.doc,s.mapping.map(r.pos))),e(s.scrollIntoView())}return!0}}return!(!n.isAtom||r.depth!=s.depth-1||(e&&e(t.tr.delete(r.pos,r.pos+n.nodeSize).scrollIntoView()),0))}),((t,e,i)=>{let{$head:s,empty:r}=t.selection,n=s;if(!r)return!1;if(s.parent.isTextblock){if(i?!i.endOfTextblock("forward",t):s.parentOffset<s.parent.content.size)return!1;n=dn(s)}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:s}=t.selection;return!(!i.parent.type.spec.code||!i.sameParent(s)||(e&&e(t.tr.insertText("\n").scrollIntoView()),0))}),((t,e)=>{let i=t.selection,{$from:s,$to:r}=i;if(i instanceof ae||s.parent.inlineContent||r.parent.inlineContent)return!1;let n=pn(r.parent.contentMatchAt(r.indexAfter()));if(!n||!n.isTextblock)return!1;if(e){let i=(!s.parentOffset&&r.index()<r.parent.childCount?s:r).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 s=i.before();if(Nt(t.doc,s))return e&&e(t.tr.split(s).scrollIntoView()),!0}let s=i.blockRange(),r=s&&Rt(s);return null!=r&&(e&&e(t.tr.lift(s,r).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 s,r,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),r=pn(i.node(t-1).contentMatchAt(i.indexAfter(t-1))),n.unshift(o&&r?{type:r}:null),s=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]=r?{type:r}:null,u=Nt(l.doc,a,n.length,n)),!u)return!1;if(l.split(a,n.length,n),!o&&h&&i.node(s).type!=r){let t=l.mapping.map(i.before(s)),e=l.doc.resolve(t);r&&i.node(s-1).canReplaceWith(e.index(),e.index()+1,r)&&l.setNodeMarkup(l.mapping.map(i.before(s)),r)}return e&&e(l.scrollIntoView()),!0})),"Mod-Enter":(t,e)=>{let{$head:i,$anchor:s}=t.selection;if(!i.parent.type.spec.code||!i.sameParent(s))return!1;let r=i.node(-1),n=i.indexAfter(-1),o=pn(r.contentMatchAt(n));if(!o||!r.canReplaceWith(n,n,o))return!1;if(e){let s=i.after(),r=t.tr.replaceWith(s,s,o.createAndFill());r.setSelection(ee.near(r.doc.resolve(s),1)),e(r.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",loadingOverlayBackground:"rgba(255, 255, 255, 0.85)",loadingOverlayColor:"#333333",loadingOverlaySpinnerActiveColor:"#333333",loadingOverlaySpinnerColor:"#cccccc"},snap:{indicatorFill:"rgba(59, 130, 246, 0.3)",indicatorStroke:"#007bff",lineStroke:"rgba(0, 0, 0, 0.2)"},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",loadingOverlayBackground:"rgba(26, 26, 26, 0.85)",loadingOverlayColor:"#e0e0e0",loadingOverlaySpinnerActiveColor:"#e0e0e0",loadingOverlaySpinnerColor:"#555555"},snap:{indicatorFill:"rgba(10, 132, 255, 0.35)",indicatorStroke:"#0A84FF",lineStroke:"rgba(255, 255, 255, 0.35)"},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,s=(t,e,r=!1)=>{for(const[n,o]of Object.entries(t)){if(r&&"name"===n)continue;const t=`${e}-${Tn.camelToKebab(n)}`;"object"==typeof o&&null!==o?s(o,t):"string"==typeof o&&i.set(t,o)}};return s(t,e,!0),i}static applyVariablesToElement(t,e){for(const[i,s]of e)t.style.setProperty(i,s)}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 $n{static resolveThemeColor(t,e){return t?function(t,e){return t[e]}(t,e??In.getStoredTheme()):""}static applyOpacity(t,e,i){const s="string"==typeof t?t:this.resolveThemeColor(t,i);if(!s||e>=1)return s;const r=s.startsWith("#")?s.slice(1):s;let n,o,h;if(3===r.length)n=parseInt(r[0]+r[0],16),o=parseInt(r[1]+r[1],16),h=parseInt(r[2]+r[2],16);else{if(6!==r.length)return s;n=parseInt(r.substring(0,2),16),o=parseInt(r.substring(2,4),16),h=parseInt(r.substring(4,6),16)}return isNaN(n)||isNaN(o)||isNaN(h)?s:`rgba(${n}, ${o}, ${h}, ${e})`}static getContrastColor(t){const e=t.startsWith("#")?t.slice(1):t;let i,s,r;if(3===e.length)i=parseInt(e[0]+e[0],16),s=parseInt(e[1]+e[1],16),r=parseInt(e[2]+e[2],16);else{if(6!==e.length)return"#000000";i=parseInt(e.substring(0,2),16),s=parseInt(e.substring(2,4),16),r=parseInt(e.substring(4,6),16)}return isNaN(i)||isNaN(s)||isNaN(r)||.299*i+.587*s+.114*r>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:Qr(Lr.spec.nodes,"paragraph block*","block"),marks:Lr.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,s){const r=new Pn;r._core=t,r.id=r.generateId(),r.workspaceId=t.store.state.activeWorkspace.id,r.userId=t.user?.id,r.fontSize=e||8,r.fontFamily=i||"Arial",r.translateX=0,r.translateY=0;const n=t.store.state.scale,o=n<0?n:1;return r.width=r.initialWidth/o,r.height=1.2*r.fontSize/o,r.backgroundColor={light:"transparent",dark:"transparent"},r.initialWidth=r.width,r.initialHeight=r.height,r.scaleFactor=1,r.scale=s??n,r.zIndex=t.store.currentZIndex,r}mount(t){null!==t&&!1!==this.isInViewport()&&(t.style.fontFamily=this.fontFamily,t.style.fontSize=`${this.fontSize}pt`,t.style.color=$n.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 Tr(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.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const e=this.editor.state.schema.nodeFromJSON(t),i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",!0),this.editor.dispatch(i)}}adjustSizeOnInput(){const t=this.elementRef;if(t&&this.isMounted&&t.scrollWidth>0){const e=this.totalWidth,i=this.totalHeight,s=t.scrollHeight;if(this.width=t.scrollWidth*this.scaleFactor,this.height=s*this.scaleFactor,0!==this.rotation){const t=(this.totalWidth-e)/2/this.scale,s=(this.totalHeight-i)/2/this.scale;if(0!==t||0!==s){const e=Math.cos(this.rotation),i=Math.sin(this.rotation),r=i*t+e*s;this.translateX+=e*t-i*s-t,this.translateY+=r-s}}}}resize(t,e,i,s){if(i<=1||s<=1)return;const r=this.width/this.scaleFactor,n=this.height/this.scaleFactor;this.scaleFactor=Math.min(i/r,s/n),this.width=r*this.scaleFactor,this.height=n*this.scaleFactor,this.translateX=t,this.translateY=e,this._core.store.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(),t?.clientX&&t?.clientY&&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.objects.consolidateTemporaryItems(),this._core.store.objects.update(this),this._core.engine.emitObjectsChange()}handleEscape(){if(!this.editor||!this.isEditing)return;const{state:t}=this.editor;if(!t.selection.empty)return this.editor.dispatch(t.tr.setSelection(ne.create(t.doc,t.selection.head))),void this.editor.focus();this._core.resetActiveText(),this._core.clearSelection(),this._core.store.setState("activeTool",i.getTool("selection"))}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:s,totalWidth:r,totalHeight:n,editor:o,uneditedObject:h,...l}=this,a=structuredClone(l);return s&&"object"==typeof s&&"nodeType"in s&&1===s.nodeType&&(a.element=s.cloneNode(!0)),a}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}}var Dn,Rn={},jn=(Dn||(Dn=1,function(t){Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const{PI:e}=Math,i=e+1e-4,s=[1,1];function r(t,e,i,s=t=>t){return t*s(.5-e*(.5-i))}const{min:n}=Math;function o(t,e,i){let s=n(1,e/i);return n(1,t+(n(1,1-s)-t)*(.275*s))}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],s=t[1]-e[1];return i*i+s*s}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 s=Math.sin(i),r=Math.cos(i),n=t[0]-e[0],o=t[1]-e[1];return[n*r-o*s+e[0],n*s+o*r+e[1]]}function b(t,e,i,s){let r=Math.sin(s),n=Math.cos(s),o=e[0]-i[0],h=e[1]-i[1],l=o*r+h*n;return t[0]=o*n-h*r+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,s){let r=i[1]-e[1];return t[0]=e[0]+(i[0]-e[0])*s,t[1]=e[1]+r*s,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 s=C(t,v(d(a(t,h(t,[1,1])))),-e),r=[],n=1/13;for(let e=n;e<=1;e+=n)r.push(k(s,t,2*i*e));return r}function O(t,e,s){let r=[],n=1/s;for(let s=n;s<=1;s+=n)r.push(k(e,t,i*s));return r}function E(t,e,i){let s=a(e,i),r=c(s,.5),n=c(s,.51);return[a(t,r),a(t,n),h(t,n),h(t,r)]}function I(t,e,s,r){let n=[],o=C(t,e,s),h=1/r;for(let e=h;e<1;e+=h)n.push(k(o,t,3*i*e));return n}function $(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 D(t,e={}){let{size:s=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:D=t=>t*(2-t)}=y,{cap:R=!0,easing:j=t=>--t*t*t+1}=k;if(0===t.length||s<=0)return[];let F,N=t[t.length-1].runningLength,U=P(y.taper,s,N),z=P(k.taper,s,N),_=(s*n)**2,L=[],H=[],X=function(t,e,i){return t.slice(0,10).reduce(((t,s)=>{let r=s.pressure;return e&&(r=o(t,s.distance,i)),(t+r)/2}),t[0].pressure)}(t,w,s),Y=r(s,c,t[t.length-1].pressure,v),W=t[0].vector,V=t[0].point,K=V,J=V,Q=K,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,s)),Y=r(s,c,n,v)):Y=s/2,void 0===F&&(F=Y);let T=M<U?D(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),$=null!==I&&I<0;if(g(y,W)<0&&!q||$){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),J=[S[0],S[1]],L.push(J),l(B,d,A),b(B,B,d,i*-t),Q=[B[0],B[1]],H.push(Q);V=J,K=Q,$&&(q=!0)}else q=!1,C?(p(A,y),f(A,A,Y),L.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),J=[S[0],S[1]],(e<=1||m(V,J)>_)&&(L.push(J),V=J),l(B,d,A),Q=[B[0],B[1]],(e<=1||m(K,Q)>_)&&(H.push(Q),K=Q),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,L[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(...$(Z,e,Y))}return L.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:r=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],s),...l[0].slice(2)]]);let a=[{point:[l[0][0],l[0][1]],pressure:j(l[0][2])?l[0][2]:.25,vector:[...s],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<r)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 D(F(t,e),e)}t.default=N,t.getStroke=N,t.getStrokeOutlinePoints=D,t.getStrokePoints=F}(Rn)),Rn);class Fn{static average(t,e){return(t+e)/2}}class Nn 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 Nn;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,s){if(i<=1||s<=1)return;const r=i/this.width,n=s/this.height;if(this.width=i,this.height=s,1===this.points.length){const t=this.points[0],e=Math.max(0,i-this.strokeWidth)/r,o=Math.max(0,s-this.strokeWidth)/n;this.points.push([t[0]+e,t[1]+o])}this.points=this.points.map((([t,e])=>[t*r,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.objects.update(this)}rotate(t){this.rotation=t,this._adjustedPoints=null,this._core.store.objects.update(this)}move(t,e,i,s){const r=(e-s)/this._core.store.state.scale;this.translateX+=(t-i)/this._core.store.state.scale,this.translateY+=r,this._adjustedPoints=null,this._core.store.objects.update(this)}hitTest(t,e){const i=this.strokeWidth/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),1===this._adjustedPoints.length){const s=this._adjustedPoints[0];return this.pointToLineSegmentDistance(t,e,s[0],s[1],s[0],s[1])<=i}for(let s=0;s<this._adjustedPoints.length-1;s++){const r=this._adjustedPoints[s],n=this._adjustedPoints[s+1];if(this.pointToLineSegmentDistance(t,e,r[0],r[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(r.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]},s={x:this._adjustedPoints[t+1][0],y:this._adjustedPoints[t+1][1]};for(let t=0;t<i.length;t++)if(r.intersectLines(e,s,i[t],i[(t+1)%i.length]))return!0}for(let t=0;t<this._adjustedPoints.length-1;t++){const s=this._adjustedPoints[t],r=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,s[0],s[1],r[0],r[1]),l=this.pointToLineSegmentDistance(o.x,o.y,s[0],s[1],r[0],r[1]),a=this.pointToLineSegmentDistance(s[0],s[1],n.x,n.y,o.x,o.y),u=this.pointToLineSegmentDistance(r[0],r[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.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),s=this.points.map((t=>t[0])),r=this.points.map((t=>t[1])),n={x:(Math.min(...s)+Math.max(...s))/2,y:(Math.min(...r)+Math.max(...r))/2},{x:o,y:h}=n;return this.points.map((([t,s])=>{const r=t-o,n=s-h;return[o+r*e-n*i,h+r*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,s,r,n){const o=r-i,h=n-s,l=o*o+h*h;let a,u,c=-1;0!==l&&(c=((t-i)*o+(e-s)*h)/l),c<0?(a=i,u=s):c>1?(a=r,u=n):(a=i+c*o,u=s+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))),s=Math.max(...t.map((t=>t[0]+this.strokeWidth/2))),r=Math.max(...t.map((t=>t[1]+this.strokeWidth/2)));this.width=s-e+this.lineSlack,this.height=r-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,s=Math.max(...this.points.map((t=>t[1])))+this.strokeWidth/2;this.width=i-t+this.lineSlack,this.height=s-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 jn.getStroke(t,{size:e,thinning:.5,smoothing:.5,streamline:.5,easing:t=>t,simulatePressure:!0,last:!0,start:{cap:!0,taper:0,easing:t=>t},end:{cap:!0,taper:0,easing:t=>t}})}getSvgPathFromStroke(t,e=!0){const i=t.length;if(i<4)return"";let s=t[0],r=t[1];const n=t[2];let o=`M${s[0].toFixed(2)},${s[1].toFixed(2)} Q${r[0].toFixed(2)},${r[1].toFixed(2)} ${Fn.average(r[0],n[0]).toFixed(2)},${Fn.average(r[1],n[1]).toFixed(2)} T`;for(let e=2,n=i-1;e<n;e++)s=t[e],r=t[e+1],o+=`${Fn.average(s[0],r[0]).toFixed(2)},${Fn.average(s[1],r[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,s=this.strokeWidth/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),this._adjustedPoints.length<1)return null;let r=!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],s=this.pointToLineSegmentDistance(h,l,e[0],e[1],i[0],i[1]);s<a&&(a=s)}const u=a<=s;if(r&&u){let r=(n-1)/32,h=o;for(let n=0;n<8;n++){const n=(r+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],s=this.pointToLineSegmentDistance(o,l,e[0],e[1],i[0],i[1]);s<a&&(a=s)}a<=s?h=n:r=n}const l=(r+h)/2;return{x:t.x+(e-t.x)*l,y:t.y+(i-t.y)*l}}r=!u}return null}}const Un="blobs",zn="metadata";class _n{type="local";name="IndexedDBAssetProvider";_dbName;_quiet;_db=null;_urlCache=new Map;_knownIds=new Set;constructor(t){this._dbName=t?.dbName??"kritzel-assets",this._quiet=t?.quiet??!1}static with(t){return{create:()=>new _n(t)}}async init(){this._db||(this._db=await this.openDatabase(),await this.loadKnownIds(),this._quiet||console.info(`IndexedDBAssetProvider initialized: ${this._dbName}`))}destroy(){for(const t of this._urlCache.values())try{URL.revokeObjectURL(t)}catch{}this._urlCache.clear(),this._knownIds.clear(),this._db&&(this._db.close(),this._db=null),this._quiet||console.info(`IndexedDBAssetProvider destroyed: ${this._dbName}`)}canResolve(t){return this._knownIds.has(t)}async put(t,e){const i=await this.ensureDb(),s=e.id??this.generateUuid(),r={id:s,kind:e.kind??"file",mimeType:e.mimeType,size:t.size,createdAt:Date.now(),width:e.width,height:e.height,durationMs:e.durationMs,originalFilename:e.originalFilename};return await new Promise(((e,n)=>{const o=i.transaction([Un,zn],"readwrite");o.oncomplete=()=>e(),o.onerror=()=>n(o.error),o.onabort=()=>n(o.error),o.objectStore(Un).put(t,s),o.objectStore(zn).put(r,s)})),this._knownIds.add(s),r}async resolve(t){const e=this._urlCache.get(t);if(e)return e;const i=await this.fetch(t),s=URL.createObjectURL(i);return this._urlCache.set(t,s),s}async fetch(t){const e=await this.ensureDb(),i=await new Promise(((i,s)=>{const r=e.transaction(Un,"readonly").objectStore(Un).get(t);r.onsuccess=()=>i(r.result),r.onerror=()=>s(r.error)}));if(!i)throw new Error(`[IndexedDBAssetProvider] Asset ${t} not found`);return this._knownIds.add(t),i}async delete(t){const e=await this.ensureDb();await new Promise(((i,s)=>{const r=e.transaction([Un,zn],"readwrite");r.oncomplete=()=>i(),r.onerror=()=>s(r.error),r.objectStore(Un).delete(t),r.objectStore(zn).delete(t)}));const i=this._urlCache.get(t);if(i){try{URL.revokeObjectURL(i)}catch{}this._urlCache.delete(t)}this._knownIds.delete(t)}async getMetadata(t){const e=await this.ensureDb();return new Promise(((i,s)=>{const r=e.transaction(zn,"readonly").objectStore(zn).get(t);r.onsuccess=()=>i(r.result),r.onerror=()=>s(r.error)}))}async listAssetsWithPendingRemotes(){const t=await this.ensureDb();return new Promise(((e,i)=>{const s=t.transaction(zn,"readonly").objectStore(zn).getAll();s.onsuccess=()=>{e((s.result??[]).filter((t=>Array.isArray(t.pendingRemotes)&&t.pendingRemotes.length>0)))},s.onerror=()=>i(s.error)}))}async setPendingRemotes(t,e){const i=await this.ensureDb();await new Promise(((s,r)=>{const n=i.transaction(zn,"readwrite");n.oncomplete=()=>s(),n.onerror=()=>r(n.error);const o=n.objectStore(zn),h=o.get(t);h.onsuccess=()=>{const i=h.result;if(!i)return;const s={...i};e.length>0?s.pendingRemotes=e:delete s.pendingRemotes,o.put(s,t)}}))}async ensureDb(){return this._db||await this.init(),this._db}openDatabase(){return new Promise(((t,e)=>{const i=indexedDB.open(this._dbName,1);i.onupgradeneeded=()=>{const t=i.result;t.objectStoreNames.contains(Un)||t.createObjectStore(Un),t.objectStoreNames.contains(zn)||t.createObjectStore(zn)},i.onsuccess=()=>t(i.result),i.onerror=()=>e(i.error)}))}async loadKnownIds(){const t=this._db;t&&await new Promise(((e,i)=>{const s=t.transaction(zn,"readonly").objectStore(zn).getAllKeys();s.onsuccess=()=>{for(const t of s.result)"string"==typeof t&&this._knownIds.add(t);e()},s.onerror=()=>i(s.error)}))}generateUuid(){if("undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID)return crypto.randomUUID();const t=crypto.getRandomValues(new Uint8Array(16));t[6]=15&t[6]|64,t[8]=63&t[8]|128;const e=Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}}class Ln extends Error{assetId;constructor(t,e){super(e??`[KritzelAssetResolver] Asset ${t} not found in any configured provider.`),this.name="AssetNotFoundError",this.assetId=t}}class Hn{_providers=[];_local=null;_remoteProviders=[];_initialized=!1;_readyPromise=null;_resolveReady=null;_rejectReady=null;_pending=new Map;_flushTimer=null;_destroyed=!1;_quiet=!1;_resolvePromises=new Map;get hasRemoteProvider(){return this._remoteProviders.length>0}get localProvider(){return this._local}async init(t){if(this._initialized)return;this.getReadyPromise(),this._quiet=t?.quiet??!1;const e=this.instantiateProviders(t?.providers??[]);e.some((t=>"local"===t.type))||e.unshift(new _n),e.sort(((t,e)=>"local"===t.type&&"local"!==e.type?-1:"local"!==t.type&&"local"===e.type?1:0)),this._providers=e,this._local=e.find((t=>"local"===t.type&&"IndexedDBAssetProvider"===t.name))??null,this._remoteProviders=e.filter((t=>"remote"===t.type)),this._local&&await this._local.init();for(const t of this._remoteProviders)try{await t.init()}catch(e){console.warn(`[KritzelAssetResolver] Remote provider "${t.name}" failed to initialize. Assets will be served from the local provider until the remote becomes available.`,e)}await this.recoverPendingUploads(),this._initialized=!0,this._resolveReady&&(this._resolveReady(),this._resolveReady=null,this._rejectReady=null),this._quiet||this.logProviderConfiguration(),this._pending.size>0&&this.scheduleFlush(0)}destroy(){this._quiet||console.info("Asset resolver destroyed"),this._destroyed=!0,this._flushTimer&&(clearTimeout(this._flushTimer),this._flushTimer=null);for(const t of this._providers)try{t.destroy()}catch{}this._providers=[],this._local=null,this._remoteProviders=[],this._pending.clear(),this._resolvePromises.clear(),this._initialized=!1,this._rejectReady&&this._rejectReady(new Error("[KritzelAssetResolver] Destroyed before initialization completed.")),this._readyPromise=null,this._resolveReady=null,this._rejectReady=null}async put(t,e){await this.ensureReady();const i=e.id??this.generateUuid(),s={...e,id:i};let r=null;if(this._local&&(r=await this._local.put(t,s)),this._remoteProviders.length>0){const t=this._remoteProviders.map((t=>t.name));this._local&&await this._local.setPendingRemotes(i,t);for(const e of t)this._pending.set(this.pendingKey(i,e),{id:i,providerName:e,attempts:0,nextAttemptAt:Date.now()})}if(!r){if(0===this._remoteProviders.length)throw new Error("[KritzelAssetResolver] No providers configured to store asset.");r=await this._remoteProviders[0].put(t,s)}return this.scheduleFlush(0),r}async resolve(t){await this.ensureReady();const e=this._resolvePromises.get(t);if(e)return e;const i=(async()=>{if(this._local&&this._local.canResolve(t))return this._local.resolve(t);let e,i=0;for(const s of this._providers)if(s!==this._local){i++;try{const e=await s.fetch(t);if(this._local){try{await this._local.put(e,{id:t,mimeType:e.type||"application/octet-stream",kind:"file"})}catch{}return this._local.resolve(t)}return URL.createObjectURL(e)}catch(t){e=t}}if(0===i)throw new Ln(t);throw new Error(`[KritzelAssetResolver] Failed to resolve asset ${t}: ${String(e)}`)})();this._resolvePromises.set(t,i);try{return await i}finally{this._resolvePromises.delete(t)}}async fetchBlob(t){let e;await this.ensureReady();let i=!1,s=!1,r=0;const n=this._local?[this._local,...this._providers.filter((t=>t!==this._local))]:this._providers;for(const o of n){o===this._local?i=!0:r++;try{return await o.fetch(t)}catch(t){o===this._local&&(s=!0),e=t}}if(0===r&&(!i||s))throw new Ln(t);throw new Error(`[KritzelAssetResolver] Failed to fetch blob for ${t}: ${String(e)}`)}async putDataUrl(t,e){const i=await this.dataUrlToBlob(t);return this.put(i,{...e,mimeType:e.mimeType??i.type??"application/octet-stream"})}logProviderConfiguration(){const t=[`Asset resolver initialized with ${this._providers.length} provider(s):`];for(const e of this._providers)t.push(` - ${e.name} [${e===this._local?"local (primary write target)":e.type}]`);this._local&&t.push(`Write strategy: local-first (${this._local.name} → immediate, remote → background queue)`),this._remoteProviders.length>0&&t.push(`Remote replication: ${this._remoteProviders.map((t=>t.name)).join(", ")}`),this._pending.size>0&&t.push(`Pending uploads recovered: ${this._pending.size}`),console.info(t.join("\n"))}instantiateProviders(t){return t.map((t=>"function"==typeof t?new t:t.create()))}pendingKey(t,e){return`${t}::${e}`}async recoverPendingUploads(){if(!this._local||0===this._remoteProviders.length)return;const t=await this._local.listAssetsWithPendingRemotes(),e=new Set(this._remoteProviders.map((t=>t.name))),i=Date.now();let s=0;for(const r of t){const t=(r.pendingRemotes??[]).filter((t=>e.has(t)));if(0!==t.length)for(const e of t)this._pending.set(this.pendingKey(r.id,e),{id:r.id,providerName:e,attempts:0,nextAttemptAt:i}),s++;else await this._local.setPendingRemotes(r.id,[])}!this._quiet&&s>0&&console.info(`Asset resolver: recovered ${s} pending upload(s)`)}scheduleFlush(t){this._destroyed||(this._flushTimer&&clearTimeout(this._flushTimer),this._flushTimer=setTimeout((()=>{this._flushTimer=null,this.flushQueue()}),Math.max(0,t)))}async flushQueue(){if(this._destroyed)return;if(!this._local)return;const t=Date.now();let e=Number.POSITIVE_INFINITY;for(const[i,s]of Array.from(this._pending.entries())){if(s.nextAttemptAt>t){e=Math.min(e,s.nextAttemptAt-t);continue}const r=this._remoteProviders.find((t=>t.name===s.providerName));if(!r){this._pending.delete(i);continue}let n,o;try{[n,o]=await Promise.all([this._local.fetch(s.id),this._local.getMetadata(s.id)])}catch{this._pending.delete(i);continue}try{await r.put(n,{id:s.id,mimeType:o?.mimeType??n.type??"application/octet-stream",kind:o?.kind,width:o?.width,height:o?.height,durationMs:o?.durationMs,originalFilename:o?.originalFilename}),this._pending.delete(i),await this.clearPendingRemote(s.id,s.providerName),this._quiet||console.info(`Asset resolver: uploaded ${s.id} to ${r.name}`)}catch(t){s.attempts+=1;const i=Math.min(3e5,2e3*Math.pow(2,s.attempts-1));s.nextAttemptAt=Date.now()+i,e=Math.min(e,i),console.warn(`[KritzelAssetResolver] Upload to ${r.name} failed for ${s.id} (attempt ${s.attempts}). Retrying in ${Math.round(i/1e3)}s.`,t)}}this._pending.size>0&&Number.isFinite(e)&&this.scheduleFlush(e)}async clearPendingRemote(t,e){if(!this._local)return;const i=await this._local.getMetadata(t);if(!i)return;const s=(i.pendingRemotes??[]).filter((t=>t!==e));await this._local.setPendingRemotes(t,s)}ensureReady(){return this._initialized?Promise.resolve():this._destroyed?Promise.reject(new Error("[KritzelAssetResolver] Resolver was destroyed.")):this.getReadyPromise()}getReadyPromise(){return this._readyPromise||(this._readyPromise=new Promise(((t,e)=>{this._resolveReady=t,this._rejectReady=e}))),this._readyPromise}generateUuid(){if("undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID)return crypto.randomUUID();const t=crypto.getRandomValues(new Uint8Array(16));t[6]=15&t[6]|64,t[8]=63&t[8]|128;const e=Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}async dataUrlToBlob(t){return(await fetch(t)).blob()}}class Xn extends n{__class__="KritzelImage";assetId="";mimeType="";src="";maxWidth=300;maxHeight=300;maxCompressionSize=1200;isDebugInfoVisible=!0;resolvedSrc;loadState="idle";maxLoadAttempts=3;loadAttempts=0;maxTransientRetryDurationMs=3e4;transientRetryStartedAt=null;constructor(t){super(),this.assetId=t?.assetId||"",this.mimeType=t?.mimeType||"",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,this.maxLoadAttempts=t?.maxLoadAttempts??3}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.x=0,e.y=0,e.translateX=0,e.translateY=0,e.scale=e._core.store.state.scale,e.zIndex=t.store.currentZIndex,e}resize(t,e,i,s){if(i<=1||s<=1)return;const r=s/this.height;this.width=this.width*r,this.height=this.height*r,this.translateX=t,this.translateY=e,this._core.store.objects.update(this)}serialize(){const t=super.serialize();return delete t.resolvedSrc,delete t.loadState,delete t.loadAttempts,delete t.transientRetryStartedAt,t}adoptTransientStateFrom(t){t instanceof Xn&&t.assetId===this.assetId&&(this.resolvedSrc=t.resolvedSrc,this.loadState=t.loadState,this.loadAttempts=t.loadAttempts,this.transientRetryStartedAt=t.transientRetryStartedAt)}ensureResolved(){if("loading"===this.loadState||"ready"===this.loadState)return;if("error"===this.loadState)return;if(!this.assetId)return;if(!this._core?.assetResolver)return;if(this.loadAttempts>=this.maxLoadAttempts)return void(this.loadState="error");this.loadState="loading";const t=this.loadAttempts;this._core.assetResolver.resolve(this.assetId).then((t=>{this.resolvedSrc=t,this.loadState="ready",this.transientRetryStartedAt=null,this._core?.rerender()})).catch((e=>{if(e instanceof Ln){this.loadAttempts+=1,this.transientRetryStartedAt=null;const t=this.loadAttempts>=this.maxLoadAttempts;return console.warn(`[KritzelImage] Asset ${this.assetId} not found (attempt ${this.loadAttempts}/${this.maxLoadAttempts}):`,e),t?(this.loadState="error",void this._core?.rerender()):void this.scheduleRetry(this.loadAttempts)}const i=Date.now();null===this.transientRetryStartedAt&&(this.transientRetryStartedAt=i);const s=i-this.transientRetryStartedAt,r=s>=this.maxTransientRetryDurationMs;if(console.warn(`[KritzelImage] Transient resolve failure for asset ${this.assetId} (elapsed ${Math.round(s/1e3)}s/${Math.round(this.maxTransientRetryDurationMs/1e3)}s):`,e),r)return this.loadState="error",void this._core?.rerender();this.scheduleRetry(t+1)}))}scheduleRetry(t){this.loadState="idle";const e=Math.min(2e3,250*Math.pow(2,Math.max(0,t-1)));setTimeout((()=>{"idle"===this.loadState&&this.ensureResolved()}),e)}migrateLegacyDataUrlIfNeeded(){if(this.assetId)return;if(!this.src||!this.src.startsWith("data:"))return;if(!this._core?.assetResolver)return;const t=this.src;this.resolvedSrc=t,this.loadState="ready",this._core.assetResolver.putDataUrl(t,{kind:"image"}).then((t=>{this.assetId=t.id,this.mimeType=t.mimeType,this.src="",this._core?.store.objects?.update(this)})).catch((t=>{console.warn("[KritzelImage] Failed to migrate legacy data URL to asset storage:",t)}))}ensureLoaded(){this.assetId&&!this.resolvedSrc?this.ensureResolved():!this.assetId&&this.src?.startsWith("data:")&&this.migrateLegacyDataUrlIfNeeded()}mount(t){super.mount(t),this.ensureLoaded()}static fromUrl(t,e){return new Promise(((i,s)=>{const r=new Image;r.onload=()=>{const s=new Xn({...e,src:t}),{scaledWidth:n,scaledHeight:o}=s.calculateScaledDimensions(r);s.width=n,s.height=o,i(s)},r.onerror=t=>s(t),r.src=t}))}calculateScaledDimensions(t){let e=t.width,i=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const s=Math.min(this.maxWidth/t.width,this.maxHeight/t.height);e=t.width*s,i=t.height*s}return{scaledWidth:e,scaledHeight:i}}}class Yn 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 Yn;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,s){if(i<=1||s<=1)return;const r=i/this.width,n=s/this.height;this.startX=this.startX*r,this.startY=this.startY*n,this.endX=this.endX*r,this.endY=this.endY*n,void 0!==this.controlX&&void 0!==this.controlY&&(this.controlX=this.controlX*r,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.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.objects.update(this)}move(t,e,i,s){const r=(e-s)/this._core.store.state.scale;this.translateX+=(t-i)/this._core.store.state.scale,this.translateY+=r,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.objects.update(this)}hitTest(t,e){const i=Math.max(this.strokeWidth,20)/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),void 0!==this.controlX&&void 0!==this.controlY){const s=this.getClipInfo();return this.pointToBezierDistance(t,e,s.start?.t??0,s.end?.t??1)<=i}const s=this.getClipInfo(),r=s.start?[s.start.x,s.start.y]:this._adjustedPoints[0],n=s.end?[s.end.x,s.end.y]:this._adjustedPoints[1];return this.pointToLineSegmentDistance(t,e,r[0],r[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(),s=[{x:t.bottomLeft.x,y:t.bottomLeft.y},{x:t.bottomRight.x,y:t.bottomRight.y},{x:t.topRight.x,y:t.topRight.y},{x:t.topLeft.x,y:t.topLeft.y}],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(r.isPointInPolygon({x:t,y:e},s))return!0;for(const t of s)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(r.isPointInPolygon({x:f,y:d},s))return!0;for(let t=0;t<s.length;t++){const i=s[t],r=s[(t+1)%s.length];if(this.pointToLineSegmentDistance(f,d,i.x,i.y,r.x,r.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<s.length;t++){const i=s[t],n=s[(t+1)%s.length];if(r.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.objects.update(this)}updateEndpoint(t,e,i){"start"===t?(this.startX=e,this.startY=i):(this.endX=e,this.endY=i);const s=this.width,r=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-s)/2,p=(f-r)/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.objects.update(this)}updateControlPoint(t,e){this.controlX=t,this.controlY=e;const i=this.width,s=this.height,{minX:r,minY:n,maxX:o,maxY:h}=this.calculateBoundingBox(),l=r-this.x,a=n-this.y,u=o-r,c=h-n,f=(u-i)/2,d=(c-s)/2;this.x=r,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.objects.update(this)}computeAdjustedPoints(){const t=[[this.startX,this.startY],[this.endX,this.endY]],e=this.rotation,i=Math.cos(e),s=Math.sin(e),r=t.map((t=>t[0])),n=t.map((t=>t[1])),o={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...n)+Math.max(...n))/2},{x:h,y:l}=o;return t.map((([t,e])=>{const r=t-h,n=e-l;return[h+r*i-n*s,l+r*s+n*i]})).map((([t,e])=>[(t-this.x)/this.scale+this.translateX,(e-this.y)/this.scale+this.translateY]))}pointToLineSegmentDistance(t,e,i,s,r,n){const o=r-i,h=n-s,l=o*o+h*h;let a,u,c=-1;0!==l&&(c=((t-i)*o+(e-s)*h)/l),c<0?(a=i,u=s):c>1?(a=r,u=n):(a=i+c*o,u=s+c*h);const f=t-a,d=e-u;return Math.sqrt(f*f+d*d)}pointToBezierDistance(t,e,i=0,s=1){null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const r=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*(s-i),u=1-a,c=t-(u*u*r[0]+2*u*a*o[0]+a*a*n[0]),f=e-(u*u*r[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),s=[this.startX,this.endX],r=[this.startY,this.endY],n={x:(Math.min(...s)+Math.max(...s))/2,y:(Math.min(...r)+Math.max(...r))/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:s,maxY:r}=Yn.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=s-this.x+t,l=r-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,s,r,n,o){let h=Math.min(t,i),l=Math.min(e,s),a=Math.max(t,i),u=Math.max(e,s);if(void 0!==r&&void 0!==n){const o=t-2*r+i;if(0!==o){const e=(t-r)/o;if(e>0&&e<1){const s=(1-e)*(1-e)*t+2*(1-e)*e*r+e*e*i;h=Math.min(h,s),a=Math.max(a,s)}}const c=e-2*n+s;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*s;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 Yn.calculateBoundingBox(this.startX,this.startY,this.endX,this.endY,this.controlX,this.controlY,this.strokeWidth)}updateDimensions(){const{minX:t,minY:e,maxX:i,maxY:s}=this.calculateBoundingBox();this.width=i-t,this.height=s-e,this.x=t,this.y=e,this.translateX=(this.x+this.translateX)/this.scale,this.translateY=(this.y+this.translateY)/this.scale}get startMarkerId(){return`arrow-start-${this.id}`}get endMarkerId(){return`arrow-end-${this.id}`}getArrowSize(t){const e="start"===t?this.arrows?.start:this.arrows?.end;return e?.size??3*this.strokeWidth}getArrowFill(t){const e="start"===t?this.arrows?.start:this.arrows?.end;return $n.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 Wn{static isInstanceOf(t,e){return!!t&&t.__class__===e}}class Vn 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.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 Vn;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=Vn.create(t);return e.forEach((t=>{i.childIds.push(t.id)})),i.refreshBoundingBox(),i.captureChildSnapshots(),i}static findParentGroup(t,e){const i=t.store.objects.filter((t=>"KritzelGroup"===t.__class__));for(const t of i)if(t.childIds.includes(e))return t;return null}static collectDescendantIds(t,e=new Set){for(const i of t.children)e.add(i.id),i instanceof Vn&&Vn.collectDescendantIds(i,e);return e}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(){for(const t of this.children)t instanceof Vn&&t.finalize();this.refreshBoundingBox(),this.captureChildSnapshots()}centerInViewport(){const{viewportWidth:t,viewportHeight:e,translateX:i,translateY:s,scale:r}=this._core.store.state,{x:n,y:o,width:h,height:l}=this.rotatedBoundingBox,a=(t/2-i)/r-(n+h/2),u=(e/2-s)/r-(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 s=1/0,r=-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<s&&(s=h),h>r&&(r=h),l<n&&(n=l),l>o&&(o=l)}))}));const h=o-n;this.width=(r-s-this.padding)*this.scale,this.height=(h-this.padding)*this.scale;const l=(s+r)/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,s){const r=(t-i)/this._core.store.state.scale,n=(e-s)/this._core.store.state.scale;this.translateX+=r,this.translateY+=n,this._core.store.objects.transaction((()=>{this._core.store.objects.update(this),this.children.forEach((r=>{r.move(t,e,i,s),this._core.anchorManager.updateAnchorsForObject(r.id)}))})),this.unchangedChildSnapshots.forEach((t=>{t.translateX+=r,t.translateY+=n}))}resize(t,e,i,s){const r=this.snapshotTotalWidth>0?this.snapshotTotalWidth-2*this.padding:this.width,n=this.snapshotTotalHeight>0?this.snapshotTotalHeight-2*this.padding:this.height,o=this.snapshotScale||this.scale||1,h=0!==r?i/r:1,l=0!==n?s/n:1,a=this.snapshotTranslateX+(this.snapshotTotalWidth||this.width+2*this.padding)/2/o,u=this.snapshotTranslateY+(this.snapshotTotalHeight||this.height+2*this.padding)/2/o,c=t+(i+2*this.padding)/2/this.scale,f=e+(s+2*this.padding)/2/this.scale,d=this.rotation,p=Math.cos(-d),g=Math.sin(-d),w=Math.cos(d),m=Math.sin(d);this._core.store.objects.transaction((()=>{this.children.forEach((t=>{const e=this.unchangedChildSnapshots.get(t.id),i=e?e.width:t.width,s=e?e.height:t.height,r=(e?e.scale:t.scale)||1,n=(e?e.translateX:t.translateX)+(e?e.totalWidth:t.totalWidth)/2/r-a,o=(e?e.translateY:t.translateY)+(e?e.totalHeight:t.totalHeight)/2/r-u,v=(n*p-o*g)*h,y=(n*g+o*p)*l,k=c+(v*w-y*m),b=f+(v*m+y*w),M=(e?e.rotation:t.rotation)-d,x=Math.cos(M),C=Math.sin(M),A=i*Math.sqrt(Math.pow(h*x,2)+Math.pow(l*C,2)),S=s*Math.sqrt(Math.pow(h*C,2)+Math.pow(l*x,2));t.resize(k-(A+2*t.padding)/2/t.scale,b-(S+2*t.padding)/2/t.scale,A,S),this._core.anchorManager.updateAnchorsForObject(t.id)})),this.refreshBoundingBox(),this._core.store.state.isResizing||this.captureChildSnapshots(),this._core.store.objects.update(this)}))}rotate(t){this.rotation=t;const e=this.translateX+this.totalWidth/2/this.scale,i=this.translateY+this.totalHeight/2/this.scale,s=t-this.snapshotRotation,r=Math.cos(s),n=Math.sin(s);this._core.store.objects.transaction((()=>{this._core.store.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+r*a;o.translateX=e+(r*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+s)}))}))}getOffsetXToCenterFromSnapshot(t){return t.translateX+t.totalWidth/t.scale/2-(this.snapshotTranslateX+this.snapshotTotalWidth/(this.snapshotScale||this.scale||1)/2)}getOffsetYToCenterFromSnapshot(t){return t.translateY+t.totalHeight/t.scale/2-(this.snapshotTranslateY+this.snapshotTotalHeight/(this.snapshotScale||this.scale||1)/2)}hitTest(t,e){return this.children.some((i=>i.hitTest(t,e)))}hitTestPolygon(t){return this.children.some((e=>e.hitTestPolygon(t)))}copy(){const t=Vn.create(this._core),e=[];return this.children.sort(((t,e)=>t.zIndex-e.zIndex)).forEach((i=>{const s=i.copy();e.push(s),t.childIds.push(s.id)})),t._pendingChildren=e,t.rotation=this.rotation,t.translateX=this.translateX,t.translateY=this.translateY,t.width=this.width,t.height=this.height,t}serialize(){const{_core:t,_elementRef:e,element:i,totalWidth:s,totalHeight:r,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.objects.update(this)}updateWorkspaceId(t){this.workspaceId=t,this.children.forEach((e=>{e.workspaceId=t,Wn.isInstanceOf(e,"KritzelGroup")&&e.updateWorkspaceId(t)}))}}var Kn,Jn;!function(t){t.Rectangle="rectangle",t.Ellipse="ellipse",t.Triangle="triangle"}(Kn||(Kn={}));class Qn extends n{__class__="KritzelShape";shapeType=Kn.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:Qr(Lr.spec.nodes,"paragraph block*","block"),marks:Lr.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??Kn.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??$n.determineTextColor(this.fillColor),this.scale=t.scale??1,this.scaleFactor=t.scaleX??1)}static create(t,e){const i=new Qn;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??Kn.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??$n.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=$n.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 Tr(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.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const e=this.editor.state.schema.nodeFromJSON(t),i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",!0),this.editor.dispatch(i)}}resize(t,e,i,s){i<=1||s<=1||(this.width=i,this.height=s,this.translateX=t,this.translateY=e,this._core.store.objects.update(this))}focus(t){if(!this.editor)return;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(),t?.clientX&&t?.clientY&&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.objects.consolidateTemporaryItems(),this._core.store.objects.update(this),this._core.engine.emitObjectsChange()}handleEscape(){if(!this.editor||!this.isEditing)return;const{state:t}=this.editor;if(!t.selection.empty)return this.editor.dispatch(t.tr.setSelection(ne.create(t.doc,t.selection.head))),void this.editor.focus();this._core.resetActiveShape(),this._core.clearSelection(),this._core.store.setState("activeTool",i.getTool("selection"))}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:s,totalWidth:r,totalHeight:n,editor:o,uneditedObject:h,...l}=this,a=structuredClone(l);return s&&"object"==typeof s&&"nodeType"in s&&1===s.nodeType&&(a.element=s.cloneNode(!0)),a}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}onAfterUpdate(t){t.includes("fillColor")?(this.fontColor=$n.determineTextColor(this.fillColor),this.editor?.dom?.parentElement&&(this.editor.dom.parentElement.style.color=$n.resolveThemeColor(this.fontColor))):t.includes("fontColor")&&this.editor?.dom?.parentElement&&(this.editor.dom.parentElement.style.color=$n.resolveThemeColor(this.fontColor))}getClipPolygon(){const t=this.totalWidth/this.scale,e=this.totalHeight/this.scale,i=this.translateX+t/2,s=this.translateY+e/2,n=this.strokeWidth/this.scale/2;switch(this.shapeType){case Kn.Ellipse:return r.getEllipsePolygonApproximation(i,s,t/2+n,e/2+n,32,this.rotation);case Kn.Triangle:const o=(t,e)=>{const r=t-i,o=e-s,h=Math.sqrt(r*r+o*o);if(0===h)return{x:t,y:e};const l=(h+n)/h;return{x:i+r*l,y:s+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),r=r=>{const n=r.x-i,o=r.y-s;return{x:i+n*t-o*e,y:s+n*e+o*t}};return[r(c),r(f),r(d)]}return[c,f,d];default:return null}}getSvgPath(){const t=this.width,e=this.height;switch(this.shapeType){case Kn.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 Kn.Ellipse:const i=this.x+t/2,s=this.y+e/2,r=t/2,n=e/2;return`M ${i-r} ${s} A ${r} ${n} 0 1 0 ${i+r} ${s} A ${r} ${n} 0 1 0 ${i-r} ${s}`;case Kn.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 qn{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 s=t.clientX,r=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-s)>10||Math.abs(t.clientY-r)>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 Gn{__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 Zn extends Gn{color=An[0];size=6;opacity=1;palette=[...An];static MIN_POINT_DISTANCE_PX=5;_currentPathId=null;shouldAppendPoint(t,e,i,s){const r=t.points;if(!r||0===r.length)return!0;const n=r[r.length-1],o=e-n[0],h=i-n[1],l=Zn.MIN_POINT_DISTANCE_PX/s;return o*o+h*h>=l*l}constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&qn.isLeftClick(t)){this._core.store.state.isDrawing=!0;const e=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,s=i?e:1,r=Nn.create(this._core,{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:i?1:e,fill:this.color,strokeWidth:this.size,opacity:this.opacity});r.isCompleted=!1,this._currentPathId=r.id,this._core.store.objects.insert(r),this._core.store.objects?.setActiveDrawingObject(r.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,s=i?e:1,r=Math.round((t[0].clientX-this._core.store.offsetX)/s),n=Math.round((t[0].clientY-this._core.store.offsetY)/s);this._core.store.state.isDrawing=!0;const o=Nn.create(this._core,{points:[[r,n]],translateX:-this._core.store.state.translateX/s,translateY:-this._core.store.state.translateY/s,scale:i?1:e,fill:this.color,strokeWidth:this.size,opacity:this.opacity});o.isCompleted=!1,this._currentPathId=o.id,this._core.store.objects.insert(o),this._core.store.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.objects.findById(this._currentPathId);if(e){const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1,n=(t.clientX-this._core.store.offsetX)/r,o=(t.clientY-this._core.store.offsetY)/r;if(!this.shouldAppendPoint(e,n,o,r))return;const h=Nn.create(this._core,{points:[...e.points,[n,o]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:s?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.objects.update(h)}}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.objects.findById(this._currentPathId);if(e){const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1,n=Math.round((t[0].clientX-this._core.store.offsetX)/r),o=Math.round((t[0].clientY-this._core.store.offsetY)/r);if(!this.shouldAppendPoint(e,n,o,r))return;const h=Nn.create(this._core,{points:[...e.points,[n,o]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:s?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.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.objects.findById(this._currentPathId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])),this._core.store.objects?.setActiveDrawingObject(null),this._currentPathId=null,this._core.store.objects?.stopUndoCapturing()}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.objects.findById(this._currentPathId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t])),this._core.store.objects?.setActiveDrawingObject(null),this._currentPathId=null,this._core.store.objects?.stopUndoCapturing()}}}class to extends n{__class__="KritzelSelectionGroup";_objectIds=[];_cachedObjects=null;_cachedObjectIdsHash="";unchangedObjectSnapshots=new Map;snapshotRotation=0;snapshotWidth=0;snapshotHeight=0;snapshotTranslateX=0;snapshotTranslateY=0;clientId;minX=0;maxX=0;minY=0;maxY=0;handleColor;handleStrokeColor;handleSize=6;_lastChildPersistTime=0;static CHILD_PERSIST_THROTTLE_MS=100;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.objects.filter((t=>e.has(t.id))),s=new Map(i.map((t=>[t.id,t])));return this._cachedObjects=this._objectIds.map((t=>s.get(t))).filter((t=>void 0!==t)),this._cachedObjectIdsHash=t,this._cachedObjects}get length(){return this.objectIds.length}static create(t){const e=new to;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.userId=t.user?.id,e.clientId=t.store.objects?.localClientId??void 0,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)Wn.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 s of i)s.updatePosition(t+(s.translateX-this.translateX),e+(s.translateY-this.translateY));this.unchangedObjectSnapshots.forEach((i=>{const s=i.translateY-this.translateY;i.translateX=t+(i.translateX-this.translateX),i.translateY=e+s})),this.translateX=t,this.translateY=e,this._core.store.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:s,totalHeight:r,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.objects.update(this)}move(t,e,i,s){const r=(t-i)/this._core.store.state.scale,n=(e-s)/this._core.store.state.scale;this.translateX+=r,this.translateY+=n;const o=Date.now();o-this._lastChildPersistTime>=to.CHILD_PERSIST_THROTTLE_MS?(this._core.store.objects.transaction((()=>{this._core.store.objects.update(this);const r=this.objects;for(const n of r)n.move(t,e,i,s),this._core.anchorManager.updateAnchorsForObject(n.id)})),this._lastChildPersistTime=o):(this._core.store.objects.update(this),this._core.store.objects.withLocalUpdatesOnly((()=>{const r=this.objects;for(const n of r)n.move(t,e,i,s),this._core.anchorManager.updateAnchorsForObject(n.id)}))),this.unchangedObjectSnapshots.forEach((t=>{t.translateX+=r,t.translateY+=n}))}persistChildren(){this._core.store.objects.transaction((()=>{const t=this.objects;for(const e of t)this._core.store.objects.update(e)}))}resize(t,e,i,s){const r=i/this.snapshotWidth,n=s/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+(s+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.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,s=e.translateY+e.totalHeight/2/e.scale-h,g=(i*c-s*f)*r,w=(i*f+s*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(r*k,2)+Math.pow(n*b,2)),x=Math.sqrt(Math.pow(r*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.objects.update(this)}))}rotate(t){this.rotation=t;const e=this.translateX+this.totalWidth/2/this.scale,i=this.translateY+this.totalHeight/2/this.scale,s=t-this.snapshotRotation,r=Math.cos(s),n=Math.sin(s),o=this.objects;this._core.store.objects.transaction((()=>{this._core.store.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+r*u;l.translateX=e+(r*a-n*u)-l.totalWidth/2/l.scale,l.translateY=i+c-l.totalHeight/2/l.scale,l.rotate(1===h?t:o.rotation+s)}}))}copy(){const t=to.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),s=Math.sin(-t);let r=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*s,l=t.x*s+t.y*e;i<r&&(r=i),i>n&&(n=i),l<o&&(o=l),l>h&&(h=l)}))}));const l=h-o;this.width=(n-r-this.padding)*this.scale,this.height=(l-this.padding)*this.scale;const a=(r+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.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 s=this.rotatedPolygon;if(r.isPointInPolygon({x:t,y:e},[s.topLeft,s.topRight,s.bottomRight,s.bottomLeft]))return!0;for(const s of i)if(s.hitTest(t,e))return!0;return!1}}class eo extends Gn{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&&qn.isLeftClick(t)){this._core.store.state.isDrawing=!0;const e=this._core.store.state.scale,i=this._core.store.state.lockDrawingScale,s=i?e:1,r=(t.clientX-this._core.store.offsetX)/s,n=(t.clientY-this._core.store.offsetY)/s;this._startX=r,this._startY=n;const o=Yn.create(this._core,{startX:r,startY:n,endX:r,endY:n,translateX:-this._core.store.state.translateX/s,translateY:-this._core.store.state.translateY/s,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.objects.insert(o),this._core.store.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,s=i?e:1,r=Math.round((t[0].clientX-this._core.store.offsetX)/s),n=Math.round((t[0].clientY-this._core.store.offsetY)/s);this._core.store.state.isDrawing=!0,this._startX=r,this._startY=n;const o=Yn.create(this._core,{startX:r,startY:n,endX:r,endY:n,translateX:-this._core.store.state.translateX/s,translateY:-this._core.store.state.translateY/s,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.objects.insert(o),this._core.store.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.objects.findById(this._currentLineId);if(e){const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1,n=Yn.create(this._core,{startX:this._startX,startY:this._startY,endX:(t.clientX-this._core.store.offsetX)/r,endY:(t.clientY-this._core.store.offsetY)/r,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:s?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.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.objects.findById(this._currentLineId);if(e){const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1,n=Math.round((t[0].clientX-this._core.store.offsetX)/r),o=Math.round((t[0].clientY-this._core.store.offsetY)/r),h=Yn.create(this._core,{startX:this._startX,startY:this._startY,endX:n,endY:o,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:s?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.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.objects.findById(this._currentLineId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t]),this.selectLineAndSwitchTool(t)),this._core.store.objects?.setActiveDrawingObject(null),this._currentLineId=null,this._core.store.objects?.stopUndoCapturing()}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.objects.findById(this._currentLineId);t&&(t.isCompleted=!0,this._core.store.objects.update(t),this._core.engine.emitObjectsChange(),this._core.engine.emitObjectsAdded([t]),this.selectLineAndSwitchTool(t)),this._core.store.objects?.setActiveDrawingObject(null),this._currentLineId=null,this._core.store.objects?.stopUndoCapturing()}}selectLineAndSwitchTool(t){const e=to.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 io extends Gn{touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&qn.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,s=this._core.store.state.pointerY;e.forEach((t=>{t.markedForRemoval=t.hitTest(i,s)})),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 s=this._core.store.state.pointerX,r=this._core.store.state.pointerY;i.forEach((t=>{t.markedForRemoval=t.hitTest(s,r)})),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.length>0&&(this._core.store.objects.stopUndoCapturing(),this._core.store.objects.transaction((()=>{t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)}))})),this._core.rerender()),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange(),t.length>0&&(this._core.engine.emitObjectsRemoved(t),this._core.store.objects.stopUndoCapturing())}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.length>0&&(this._core.store.objects.stopUndoCapturing(),this._core.store.objects.transaction((()=>{t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)}))})),this._core.rerender()),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange(),t.length>0&&(this._core.engine.emitObjectsRemoved(t),this._core.store.objects.stopUndoCapturing())}}}function so(t,e){return new Promise((function(i,s){let r;return ro(t).then((function(t){try{return r=t,i(new Blob([e.slice(0,2),r,e.slice(2)],{type:"image/jpeg"}))}catch(t){return s(t)}}),s)}))}const ro=t=>new Promise(((e,i)=>{const s=new FileReader;s.addEventListener("load",(({target:{result:t}})=>{const s=new DataView(t);let r=0;if(65496!==s.getUint16(r))return i("not a valid JPEG");for(r+=2;;){const n=s.getUint16(r);if(65498===n)break;const o=s.getUint16(r+2);if(65505===n&&1165519206===s.getUint32(r+4)){const n=r+10;let h;switch(s.getUint16(n)){case 18761:h=!0;break;case 19789:h=!1;break;default:return i("TIFF header contains invalid endian")}if(42!==s.getUint16(n+2,h))return i("TIFF header contains invalid version");const l=s.getUint32(n+4,h),a=n+l+2+12*s.getUint16(n+l,h);for(let t=n+l+2;t<a;t+=12)if(274==s.getUint16(t,h)){if(3!==s.getUint16(t+2,h))return i("Orientation data type is invalid");if(1!==s.getUint32(t+4,h))return i("Orientation data count is invalid");s.setUint16(t+8,1,h);break}return e(t.slice(r,r+2+o))}r+=2+o}return e(new Blob)})),s.readAsArrayBuffer(t)}));var no={},oo={get exports(){return no},set exports(t){no=t}};!function(){var t,e,i={};oo.exports=i,i.parse=function(t,e){for(var s=i.bin.readUshort,r=i.bin.readUint,n=0,o={},h=new Uint8Array(t),l=h.length-4;101010256!=r(h,l);)l--;n=l,n+=4;var a=s(h,n+=4);s(h,n+=2);var u=r(h,n+=2),c=r(h,n+=4);n+=4,n=c;for(var f=0;f<a;f++){r(h,n),n+=4,n+=4,n+=4,r(h,n+=4),u=r(h,n+=4);var d=r(h,n+=4),p=s(h,n+=4),g=s(h,n+2),w=s(h,n+4);n+=6;var m=r(h,n+=8);n+=4,n+=p+g+w,i._readLocal(h,m,o,u,d,e)}return o},i._readLocal=function(t,e,s,r,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)s[f]={size:n,csize:r};else{var d=new Uint8Array(t.buffer,e);if(0==a)s[f]=new Uint8Array(d.buffer.slice(e,e+r));else{if(8!=a)throw"unknown compression method: "+a;var p=new Uint8Array(n);i.inflateRaw(d,p),s[f]=p}}},i.inflateRaw=function(t,e){return i.F.inflate(t,e)},i.inflate=function(t,e){return i.inflateRaw(new Uint8Array(t.buffer,t.byteOffset+2,t.length-6),e)},i.deflate=function(t,e){null==e&&(e={level:6});var s=0,r=new Uint8Array(50+Math.floor(1.1*t.length));r[s]=120,r[s+1]=156,s=i.F.deflateRaw(t,r,s+=2,e.level);var n=i.adler(t,0,t.length);return r[s+0]=n>>>24&255,r[s+1]=n>>>16&255,r[s+2]=n>>>8&255,r[s+3]=n>>>0&255,new Uint8Array(r.buffer,0,s+4)},i.deflateRaw=function(t,e){null==e&&(e={level:6});var s=new Uint8Array(50+Math.floor(1.1*t.length)),r=i.F.deflateRaw(t,s,r,e.level);return new Uint8Array(s.buffer,0,r)},i.encode=function(t,e){null==e&&(e=!1);var s=0,r=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)s+=o[h].file.length+30+46+2*i.bin.sizeUTF8(h);s+=22;var c=new Uint8Array(s),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 r(c,f,101010256),f+=4,n(c,f+=4,g),n(c,f+=2,g),r(c,f+=2,m),r(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,s,r,n,o){var h=i.bin.writeUint,l=i.bin.writeUshort,a=r.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,r.cpr?8:0),h(t,e+=2,0),h(t,e+=4,r.crc),h(t,e+=4,a.length),h(t,e+=4,r.usize),l(t,e+=4,i.bin.sizeUTF8(s)),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,s),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,s=0;s<8;s++)1&i?i=3988292384^i>>>1:i>>>=1;t[e]=i}return t}(),update:function(t,e,s,r){for(var n=0;n<r;n++)t=i.crc.table[255&(t^e[s+n])]^t>>>8;return t},crc:function(t,e,s){return 4294967295^i.crc.update(4294967295,t,e,s)}},i.adler=function(t,e,i){for(var s=1,r=0,n=e,o=e+i;n<o;){for(var h=Math.min(n+5552,o);n<h;)r+=s+=t[n++];s%=65521,r%=65521}return r<<16|s},i.bin={readUshort:function(t,e){return t[e]|t[e+1]<<8},writeUshort:function(t,e,i){t[e]=255&i,t[e+1]=i>>8&255},readUint:function(t,e){return 16777216*t[e+3]+(t[e+2]<<16|t[e+1]<<8|t[e])},writeUint:function(t,e,i){t[e]=255&i,t[e+1]=i>>8&255,t[e+2]=i>>16&255,t[e+3]=i>>24&255},readASCII:function(t,e,i){for(var s="",r=0;r<i;r++)s+=String.fromCharCode(t[e+r]);return s},writeASCII:function(t,e,i){for(var s=0;s<i.length;s++)t[e+s]=i.charCodeAt(s)},pad:function(t){return t.length<2?"0"+t:t},readUTF8:function(t,e,s){for(var r,n="",o=0;o<s;o++)n+="%"+i.bin.pad(t[e+o].toString(16));try{r=decodeURIComponent(n)}catch(r){return i.bin.readASCII(t,e,s)}return r},writeUTF8:function(t,e,i){for(var s=i.length,r=0,n=0;n<s;n++){var o=i.charCodeAt(n);if(4294967168&o)if(4294965248&o)if(4294901760&o){if(4292870144&o)throw"e";t[e+r]=240|o>>18,t[e+r+1]=128|o>>12&63,t[e+r+2]=128|o>>6&63,t[e+r+3]=128|63&o,r+=4}else t[e+r]=224|o>>12,t[e+r+1]=128|o>>6&63,t[e+r+2]=128|63&o,r+=3;else t[e+r]=192|o>>6,t[e+r+1]=128|63&o,r+=2;else t[e+r]=o,r++}return r},sizeUTF8:function(t){for(var e=t.length,i=0,s=0;s<e;s++){var r=t.charCodeAt(s);if(4294967168&r)if(4294965248&r)if(4294901760&r){if(4292870144&r)throw"e";i+=4}else i+=3;else i+=2;else i++}return i}},i.F={},i.F.deflateRaw=function(t,e,s,r){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]][r],o=i.F.U,h=i.F._goodIndex,l=i.F._putsE,a=0,u=s<<3,c=0,f=t.length;if(0==r){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,s,r,n,o){var h=32767&e,l=s[h],a=h-l+32768&32767;if(l==h||r!=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-s[w]+32768&32767;m>p&&(p=m,l=w)}}}a+=(h=l)-(l=s[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 s=e,r=Math.min(t.length,e+258);for(e+=3;e<r&&t[e]==t[e-i];)e++;return e-s},i.F._hash=function(t,e){return(t[e]<<8|t[e+1])+(t[e+2]<<4)&65535},i.saved=0,i.F._writeBlock=function(t,e,s,r,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=r+i.F.contSize(y.fltree,y.lhst)+i.F.contSize(y.fdtree,y.dhst),C=r+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<s;I+=2){for(var $=e[I],P=$>>>23,D=E+(8388607&$);E<D;)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,s,r){var n=r>>>3;return s[n]=i,s[n+1]=i>>>8,s[n+2]=255-s[n],s[n+3]=255-s[n+1],n+=4,s.set(new Uint8Array(t.buffer,e,i),n),r+(i+4<<3)},i.F.getTrees=function(){for(var t=i.F.U,e=i.F._hufTree(t.lhst,t.ltree,15),s=i.F._hufTree(t.dhst,t.dtree,15),r=[],n=i.F._lenCodes(t.ltree,r),o=[],h=i.F._lenCodes(t.dtree,o),l=0;l<r.length;l+=2)t.ihst[r[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,s,a,n,h,u,r,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,s=0;s<e.length;s++)i+=e[s]*t[1+(s<<1)];return i},i.F._codeTiny=function(t,e,s,r){for(var n=0;n<t.length;n+=2){var o=t[n],h=t[n+1];r=i.F._writeLit(o,e,s,r);var l=16==o?2:17==o?3:7;o>15&&(i.F._putsE(s,r,h,l),r+=l)}return r},i.F._lenCodes=function(t,e){for(var i=t.length;2!=i&&0==t[i-1];)i-=2;for(var s=0;s<i;s+=2){var r=t[s+1],n=s+3<i?t[s+3]:-1,o=s+5<i?t[s+5]:-1,h=0==s?-1:t[s-1];if(0==r&&n==r&&o==r){for(var l=s+5;l+2<i&&t[l+2]==r;)l+=2;(a=Math.min(l+1-s>>>1,138))<11?e.push(17,a-3):e.push(18,a-11),s+=2*a-2}else if(r==h&&n==r&&o==r){for(l=s+5;l+2<i&&t[l+2]==r;)l+=2;var a=Math.min(l+1-s>>>1,6);e.push(16,a-3),s+=2*a-2}else e.push(r,0)}return i>>>1},i.F._hufTree=function(t,e,s){var r=[],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]&&r.push({lit:h,f:t[h]});var l=r.length,a=r.slice(0);if(0==l)return 0;if(1==l){var u=r[0].lit;return a=0==u?1:0,e[1+(u<<1)]=1,e[1+(a<<1)]=1,1}r.sort((function(t,e){return t.f-e.f}));var c=r[0],f=r[1],d=0,p=1,g=2;for(r[0]={lit:-1,f:c.f+f.f,l:c,r:f,d:0};p!=l-1;)c=d!=p&&(g==l||r[d].f<r[g].f)?r[d++]:r[g++],f=d!=p&&(g==l||r[d].f<r[g].f)?r[d++]:r[g++],r[p++]={lit:-1,f:c.f+f.f,l:c,r:f};var w=i.F.setDepth(r[p-1],0);for(w>s&&(i.F.restrictDepth(a,s,w),w=s),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 s=0,r=1<<i-e,n=0;for(t.sort((function(t,e){return e.d==t.d?t.f-e.f:e.d-t.d})),s=0;s<t.length&&t[s].d>e;s++){var o=t[s].d;t[s].d=e,n+=r-(1<<i-o)}for(n>>>=i-e;n>0;)(o=t[s].d)<e?(t[s].d++,n-=1<<e-o-1):s++;for(;s>=0;s--)t[s].d==e&&n<0&&(t[s].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,s,r){return i.F._putsF(s,r,e[t<<1]),r+e[1+(t<<1)]},i.F.inflate=function(t,e){var s=Uint8Array;if(3==t[0]&&0==t[1])return e||new s(0);var r=i.F,n=r._bitsF,o=r._bitsE,h=r._decodeTiny,l=r.makeCodes,a=r.codes2map,u=r._get17,c=r.U,f=null==e;f&&(e=new s(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=r._copyOut(c.ttree,0,m,c.ltree);k=(1<<B)-1;var T=r._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 $=c.ldef[E-257];I=M+($>>>3)+o(t,x,7&$),x+=7&$}var P=p[u(t,x)&b],D=c.ddef[P>>>4],R=(D>>>4)+n(t,x+=15&P,15&D);for(x+=15&D,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 s(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 s=new Uint8Array(Math.max(i<<1,e));return s.set(t,0),s},i.F._decodeTiny=function(t,e,s,r,n,o){for(var h=i.F._bitsE,l=i.F._get17,a=0;a<s;){var u=t[l(r,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(r,n,2),n+=2,f=o[a-1]):17==c?(d=3+h(r,n,3),n+=3):18==c&&(d=11+h(r,n,7),n+=7);for(var p=a+d;a<p;)o[a]=f,a++}}return n},i.F._copyOut=function(t,e,i,s){for(var r=0,n=0,o=s.length>>>1;n<i;){var h=t[n+e];s[n<<1]=0,s[1+(n<<1)]=h,h>r&&(r=h),n++}for(;n<o;)s[n<<1]=0,s[1+(n<<1)]=0,n++;return r},i.F.makeCodes=function(t,e){for(var s,r,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(s=0,a[0]=0,r=1;r<=e;r++)c[r]=s=s+a[r-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,s){for(var r=t.length,n=i.F.U.rev15,o=0;o<r;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;)s[n[u]>>>15-e]=l,u++},i.F.revCodes=function(t,e){for(var s=i.F.U.rev15,r=15-e,n=0;n<t.length;n+=2)t[n]=s[t[n]<<e-t[n+1]]>>>r},i.F._putsE=function(t,e,i){var s=e>>>3;t[s]|=i<<=7&e,t[s+1]|=i>>>8},i.F._putsF=function(t,e,i){var s=e>>>3;t[s]|=i<<=7&e,t[s+1]|=i>>>8,t[s+2]|=i>>>16},i.F._bitsE=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<i)-1},i.F._bitsF=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<i)-1},i.F._get17=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},i.F._get25=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},i.F.U=(t=Uint16Array,e=Uint32Array,{next_code:new t(16),bl_count:new t(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],ldef:new t(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],ddef:new e(32),flmap:new t(512),fltree:[],fdmap:new t(32),fdtree:[],lmap:new t(32768),ltree:[],ttree:[],dmap:new t(32768),dtree:[],imap:new t(512),itree:[],rev15:new t(32768),lhst:new e(286),dhst:new e(30),ihst:new e(19),lits:new e(15e3),strt:new t(65536),prev:new t(32768)}),function(){for(var t=i.F.U,e=0;e<32768;e++){var s=e;s=(4278255360&(s=(4042322160&(s=(3435973836&(s=(2863311530&s)>>>1|(1431655765&s)<<1))>>>2|(858993459&s)<<2))>>>4|(252645135&s)<<4))>>>8|(16711935&s)<<8,t.rev15[e]=(s>>>16|s<<16)>>>17}function r(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];r(t.fltree,144,8),r(t.fltree,112,9),r(t.fltree,24,7),r(t.fltree,8,8),i.F.makeCodes(t.fltree,9),i.F.codes2map(t.fltree,9,t.flmap),i.F.revCodes(t.fltree,9),r(t.fdtree,32,5),i.F.makeCodes(t.fdtree,5),i.F.codes2map(t.fdtree,5,t.fdmap),i.F.revCodes(t.fdtree,5),r(t.itree,19,0),r(t.ltree,286,0),r(t.dtree,30,0),r(t.ttree,320,0)}()}();var ho=function(t,e){return e.forEach((function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach((function(i){if("default"!==i&&!(i in t)){var s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return e[i]}})}}))})),Object.freeze(t)}({__proto__:null,default:no},[no]);const lo=function(){var t={nextZero(t,e){for(;0!=t[e];)e++;return e},readUshort:(t,e)=>t[e]<<8|t[e+1],writeUshort(t,e,i){t[e]=i>>8&255,t[e+1]=255&i},readUint:(t,e)=>16777216*t[e]+(t[e+1]<<16|t[e+2]<<8|t[e+3]),writeUint(t,e,i){t[e]=i>>24&255,t[e+1]=i>>16&255,t[e+2]=i>>8&255,t[e+3]=255&i},readASCII(t,e,i){let s="";for(let r=0;r<i;r++)s+=String.fromCharCode(t[e+r]);return s},writeASCII(t,e,i){for(let s=0;s<i.length;s++)t[e+s]=i.charCodeAt(s)},readBytes(t,e,i){const s=[];for(let r=0;r<i;r++)s.push(t[e+r]);return s},pad:t=>t.length<2?`0${t}`:t,readUTF8(e,i,s){let r,n="";for(let r=0;r<s;r++)n+=`%${t.pad(e[i+r].toString(16))}`;try{r=decodeURIComponent(n)}catch(r){return t.readASCII(e,i,s)}return r}};function e(e,i,s,r){const o=i*s,h=n(r),l=Math.ceil(i*h/8),a=new Uint8Array(4*o),u=new Uint32Array(a.buffer),{ctype:c}=r,{depth:f}=r,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=r.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],s=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]==s&&(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)==s&&(a[m+3]=0)}}else if(3==c){const t=r.tabs.PLTE,n=r.tabs.tRNS,h=n?n.length:0;if(1==f)for(var v=0;v<s;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<s;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<s;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=r.tabs.tRNS?r.tabs.tRNS:-1,v=0;v<s;v++){const t=v*l,s=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[s+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[s+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[s+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[s+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[s+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?r(e,u):s(e,u),0==t.interlace?e=o(e,t,0,i,h):1==t.interlace&&(e=function(t,e){const i=e.width,s=e.height,r=n(e),h=r>>3,l=Math.ceil(i*r/8),a=new Uint8Array(s*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<s;)k+=n,y++;let b=f[g];for(;b<i;)b+=m,v++;const M=Math.ceil(v*r/8);o(t,e,u,v,y);let x=0,C=c[g];for(;C<s;){let e=f[g],s=u+x*M<<3;for(;e<i;){var w;if(1==r&&(w=(w=t[s>>3])>>7-(7&s)&1,a[C*l+(e>>3)]|=w<<7-(7&e)),2==r&&(w=(w=t[s>>3])>>6-(7&s)&3,a[C*l+(e>>2)]|=w<<6-((3&e)<<1)),4==r&&(w=(w=t[s>>3])>>4-(7&s)&15,a[C*l+(e>>1)]|=w<<4-((1&e)<<2)),r>=8){const i=C*l+e*h;for(let e=0;e<h;e++)a[i+e]=t[(s>>3)+e]}s+=r,e+=m}x++,C+=n}v*y!=0&&(u+=y*(1+M)),g+=1}return a}(e,t)),e}function s(t,e){return r(new Uint8Array(t.buffer,2,t.length-6),e)}var r=function(){const t={H:{}};return t.H.N=function(e,i){const s=Uint8Array;let r,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 s(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 s(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&&(r=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),r=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 s=g.V(M.v,l,a,M.D);f=(1<<s)-1,y(M.C,i),k(M.C,i,r),y(M.D,s),k(M.D,s,n)}for(;;){const t=r[b(e,p)&c];p+=15&t;const s=t>>>4;if(s>>>8==0)i[d++]=s;else{if(256==s)break;{let t=d+s-254;if(s>264){const i=M.q[s-257];t=d+(i>>>3)+m(e,p,7&i),p+=7&i}const r=n[b(e,p)&f];p+=15&r;const o=M.c[r>>>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 r=4+(p>>>3),n=e[r-4]|e[r-3]<<8;x&&(i=t.H.W(i,d+n)),i.set(new s(e.buffer,e.byteOffset+r,n),d),p=r+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 s=new Uint8Array(i<<1);return s.set(t,0),s},t.H.R=function(e,i,s,r,n,o){const h=t.H.e,l=t.H.Z;let a=0;for(;a<s;){const t=e[l(r,n)&i];n+=15&t;const s=t>>>4;if(s<=15)o[a]=s,a++;else{let t=0,e=0;16==s?(e=3+h(r,n,2),n+=2,t=o[a-1]):17==s?(e=3+h(r,n,3),n+=3):18==s&&(e=11+h(r,n,7),n+=7);const i=a+e;for(;a<i;)o[a]=t,a++}}return n},t.H.V=function(t,e,i,s){let r=0,n=0;const o=s.length>>>1;for(;n<i;){const i=t[n+e];s[n<<1]=0,s[1+(n<<1)]=i,i>r&&(r=i),n++}for(;n<o;)s[n<<1]=0,s[1+(n<<1)]=0,n++;return r},t.H.n=function(e,i){const s=t.H.m,r=e.length;let n,o,h,l;const a=s.j;for(var u=0;u<=i;u++)a[u]=0;for(u=1;u<r;u+=2)a[e[u]]++;const c=s.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<r;h+=2)l=e[h+1],0!=l&&(e[h]=c[l],c[l]++)},t.H.A=function(e,i,s){const r=e.length,n=t.H.m.r;for(let t=0;t<r;t+=2)if(0!=e[t+1]){const r=e[t+1],o=t>>1<<4|r,h=i-r;let l=e[t]<<h;const a=l+(1<<h);for(;l!=a;)s[n[l]>>>15-i]=o,l++}},t.H.l=function(e,i){const s=t.H.m.r,r=15-i;for(let t=0;t<e.length;t+=2)e[t]=s[e[t]<<i-e[t+1]]>>>r},t.H.M=function(t,e,i){const s=e>>>3;t[s]|=i<<=7&e,t[s+1]|=i>>>8},t.H.I=function(t,e,i){const s=e>>>3;t[s]|=i<<=7&e,t[s+1]|=i>>>8,t[s+2]|=i>>>16},t.H.e=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<i)-1},t.H.b=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<i)-1},t.H.Z=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},t.H.i=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},t.H.m=function(){const t=Uint16Array,e=Uint32Array;return{K:new t(16),j:new t(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new t(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new e(32),J:new t(512),_:[],h:new t(32),$:[],w:new t(32768),C:[],v:[],d:new t(32768),D:[],u:new t(512),Q:[],r:new t(32768),s:new e(286),Y:new e(30),a:new e(19),t:new e(15e3),k:new t(65536),g:new t(32768)}}(),function(){const e=t.H.m;for(var i=0;i<32768;i++){let t=i;t=(2863311530&t)>>>1|(1431655765&t)<<1,t=(3435973836&t)>>>2|(858993459&t)<<2,t=(4042322160&t)>>>4|(252645135&t)<<4,t=(4278255360&t)>>>8|(16711935&t)<<8,e.r[i]=(t>>>16|t<<16)>>>17}function s(t,e,i){for(;0!=e--;)t.push(0,i)}for(i=0;i<32;i++)e.q[i]=e.S[i]<<3|e.T[i],e.c[i]=e.p[i]<<4|e.z[i];s(e._,144,8),s(e._,112,9),s(e._,24,7),s(e._,8,8),t.H.n(e._,9),t.H.A(e._,9,e.J),t.H.l(e._,9),s(e.$,32,5),t.H.n(e.$,5),t.H.A(e.$,5,e.h),t.H.l(e.$,5),s(e.Q,19,0),s(e.C,286,0),s(e.D,30,0),s(e.v,320,0)}(),t.H.N}();function n(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function o(t,e,i,s,r){let o=n(e);const l=Math.ceil(s*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<r;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 s=t+e-i,r=s-t,n=s-e,o=s-i;return r*r<=n*n&&r*r<=o*o?t:n*n<=o*o?e:i}function l(e,i,s){s.width=t.readUint(e,i),s.height=t.readUint(e,i+=4),s.depth=e[i+=4],i++,s.ctype=e[i],i++,s.compress=e[i],i++,s.filter=e[i],i++,s.interlace=e[i],i++}function a(t,e,i,s,r,n,o,h,l){const a=Math.min(e,r),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)*r+o+n<<2):(c=(-h+i)*e-o+n<<2,f=i*r+n<<2),0==l)s[f]=t[c],s[f+1]=t[c+1],s[f+2]=t[c+2],s[f+3]=t[c+3];else if(1==l){var d=t[c+3]*(1/255),p=t[c]*d,g=t[c+1]*d,w=t[c+2]*d,m=s[f+3]*(1/255),v=s[f]*m,y=s[f+1]*m,k=s[f+2]*m;const e=1-d,i=d+m*e,r=0==i?0:1/i;s[f+3]=255*i,s[f+0]=(p+v*e)*r,s[f+1]=(g+y*e)*r,s[f+2]=(w+k*e)*r}else if(2==l)p=t[c],g=t[c+1],w=t[c+2],v=s[f],y=s[f+1],k=s[f+2],(d=t[c+3])==(m=s[f+3])&&p==v&&g==y&&w==k?(s[f]=0,s[f+1]=0,s[f+2]=0,s[f+3]=0):(s[f]=p,s[f+1]=g,s[f+2]=w,s[f+3]=d);else if(3==l){if(p=t[c],g=t[c+1],w=t[c+2],v=s[f],y=s[f+1],k=s[f+2],(d=t[c+3])==(m=s[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=s(i)}catch(t){l=r(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 s={rect:t,delay:Math.round(1e3*e),dispose:n[o+24],blend:n[o+25]};c.frames.push(s)}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=s(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=s(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,s=t.height;if(null==t.tabs.acTL)return[e(t.data,i,s,t).buffer];const r=[];null==t.frames[0].data&&(t.frames[0].data=t.data);const n=i*s*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,s,d,p,0):1==f.blend&&a(m,g,w,o,i,s,d,p,1),r.push(o.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)a(h,g,w,o,i,s,d,p,0);else if(2==f.dispose)for(u=0;u<n;u++)o[u]=l[u]}return r},_paeth:h,_copyTile:a,_bin:t}}();!function(){const{_copyTile:t}=lo,{_bin:e}=lo,i=lo._paeth;var s={table:function(){const t=new Uint32Array(256);for(let e=0;e<256;e++){let i=e;for(let t=0;t<8;t++)1&i?i=3988292384^i>>>1:i>>>=1;t[e]=i}return t}(),update(t,e,i,r){for(let n=0;n<r;n++)t=s.table[255&(t^e[i+n])]^t>>>8;return t},crc:(t,e,i)=>4294967295^s.update(4294967295,t,e,i)};function r(t,e,i,s){e[i]+=t[0]*s>>4,e[i+1]+=t[1]*s>>4,e[i+2]+=t[2]*s>>4,e[i+3]+=t[3]*s>>4}function n(t){return Math.max(0,Math.min(255,t))}function o(t,e){const i=t[0]-e[0],s=t[1]-e[1],r=t[2]-e[2],n=t[3]-e[3];return i*i+s*s+r*r+n*n}function h(t,e,i,s,h,l,a){null==a&&(a=1);const u=s.length,c=[];for(var f=0;f<u;f++){const t=s[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&&r(x,m,f+4,7),h!=i-1&&(0!=k&&r(x,m,f+4*e-4,3),r(x,m,f+4*e,5),k!=e-1&&r(x,m,f+4*e+4,1))),l[f>>2]=d,w[f>>2]=s[d]}}function l(t,i,r,n,o){null==o&&(o={});const{crc:h}=s,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,r),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],s=i>>>8&255,r=i>>>16&255;y[c+e+0]=255&i,y[c+e+1]=s,y[c+e+2]=r}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 s=0;s<t.frames.length;s++){const r=t.frames[s],n=r.rect.height,o=new Uint8Array(n*r.bpl+n);r.cimg=d(r.img,n,r.bpp,r.bpl,o,e,i)}}function u(e,i,s,r,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,s,r,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=s,y=r?1:0;if(0!=l){const k=o||r||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 r=new Uint32Array(e[l-1-t]);let o=i,h=s,a=-1,c=-1;for(let t=0;t<s;t++)for(let e=0;e<i;e++)d[p=t*i+e]!=r[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,s,a,m,v,-g,-w,0),y=t(c,i,s,a,m,v,-g,-w,3)?1:0,1==y?f(c,i,s,a,{x:g,y:w,width:m,height:v}):t(c,i,s,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(r)for(l=0;l<h.length;l++){if(1==(g=h[l]).blend)continue;const t=g.rect,r=h[l-1].rect,o=Math.min(t.x,r.x),a=Math.min(t.y,r.y),u={x:o,y:a,width:Math.max(t.x+t.width,r.x+r.width)-o,height:Math.max(t.y+t.height,r.y+r.height)-a};h[l-1].dispose=1,l-1!=0&&c(e,i,s,h,l-1,u,n),c(e,i,s,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,s,o,l,a),C={},A=[],S=[];if(0!=r){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 s=new Uint8Array(e);let r=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),s[r+t]=i,s[r+t+1]=n,s[r+t+2]=o,s[r+t+3]=h}r+=n}return s.buffer}(t),i=g(e,r);for(b=0;b<i.plte.length;b++)A.push(i.plte[b].est.rgba);let s=0;for(b=0;b<x.length;b++){const t=(T=x[b]).img.length;var B=new Uint8Array(i.inds.buffer,s>>2,t>>2);S.push(B);const e=new Uint8Array(i.abuf,s,t);p&&h(T.img,T.rect.width,T.rect.height,A,e,B),T.img.set(e),s+=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),s=4;if(E<=256&&0==d){i=Math.ceil(m*O/8);var I=new Uint8Array(i*t);const r=S[y];for(let e=0;e<t;e++){b=e*i;const t=e*O;if(8==m)for(var $=0;$<O;$++)I[b+$]=r[t+$];else if(4==m)for($=0;$<O;$++)I[b+($>>1)]|=r[t+$]<<4-4*(1&$);else if(2==m)for($=0;$<O;$++)I[b+($>>2)]|=r[t+$]<<6-2*(3&$);else if(1==m)for($=0;$<O;$++)I[b+($>>3)]|=r[t+$]<<7-1*(7&$)}e=I,w=3,s=1}else if(0==M&&1==x.length){I=new Uint8Array(O*t*3);const r=O*t;for(b=0;b<r;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,s=3,i=3*O}T.img=e,T.bpl=i,T.bpp=s}return{ctype:w,depth:m,plte:A,frames:x}}function c(e,i,s,r,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=s,v=-1,y=-1;for(let t=0;t<o.height;t++)for(let e=0;e<o.width;e++){const s=o.x+e,h=o.y+t,l=h*i+s,a=g[l];0==a||0==r[n-1].dispose&&c[l]==a&&(null==d||0!=d[4*l+3])||(s<w&&(w=s),s>v&&(v=s),h<m&&(m=h),h>y&&(y=h))}-1==v&&(w=m=v=y=0),h&&(!(1&~w)&&w--,!(1&~m)&&m--);const k=r[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==r[n-1].dispose?(t(u,i,s,k.img,o.width,o.height,-o.x,-o.y,0),f(p,i,s,k.img,o)):t(p,i,s,k.img,o.width,o.height,-o.x,-o.y,0)}function f(e,i,s,r,n){t(e,i,s,r,n.width,n.height,-n.x,-n.y,2)}function d(t,e,i,s,r,n,o){const h=[];let l,a=[0,1,2,3,4];-1!=n?a=[n]:(e*s>5e5||1==i)&&(a=[0]),o&&(l={level:0});const u=ho;for(var c=0;c<a.length;c++){for(let n=0;n<e;n++)p(r,t,n,s,i,a[c]);h.push(u.deflate(r,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,s,r,n,o){const h=s*r;let l=h+s;if(t[l]=o,l++,0==o)if(r<500)for(var a=0;a<r;a++)t[l+a]=e[h+a];else t.set(new Uint8Array(e.buffer,h,r),l);else if(1==o){for(a=0;a<n;a++)t[l+a]=e[h+a];for(a=n;a<r;a++)t[l+a]=e[h+a]-e[h+a-n]+256&255}else if(0==s){for(a=0;a<n;a++)t[l+a]=e[h+a];if(2==o)for(a=n;a<r;a++)t[l+a]=e[h+a];if(3==o)for(a=n;a<r;a++)t[l+a]=e[h+a]-(e[h+a-n]>>1)+256&255;if(4==o)for(a=n;a<r;a++)t[l+a]=e[h+a]-i(e[h+a-n],0,0)+256&255}else{if(2==o)for(a=0;a<r;a++)t[l+a]=e[h+a]+256-e[h+a-r]&255;if(3==o){for(a=0;a<n;a++)t[l+a]=e[h+a]+256-(e[h+a-r]>>1)&255;for(a=n;a<r;a++)t[l+a]=e[h+a]+256-(e[h+a-r]+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-r],0)&255;for(a=n;a<r;a++)t[l+a]=e[h+a]+256-i(e[h+a-n],e[h+a-r],e[h+a-n-r])&255}}}function g(t,e){const i=new Uint8Array(t),s=i.slice(0),r=new Uint32Array(s.buffer),n=w(s,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,r[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,r[c>>2]=u.est.rgba}return{abuf:s.buffer,inds:a,plte:h}}function w(t,e,i){null==i&&(i=1e-4);const s=new Uint32Array(t.buffer),r={i0:0,i1:t.length,bst:null,est:null,tdst:0,left:null,right:null};r.bst=b(t,r.i0,r.i1),r.est=M(r.bst);const n=[r];for(;n.length<e;){let e=0,r=0;for(var o=0;o<n.length;o++)n[o].est.L>e&&(e=n[o].est.L,r=o);if(e<i)break;const h=n[r],l=y(t,s,h.i0,h.i1,h.est.e,h.est.eMq255);if(h.i0>=l||h.i1<=l){h.est.L=0;continue}const a={i0:h.i0,i1:l,bst:null,est:null,tdst:0,left:null,right:null};a.bst=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[r]=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[r,n]}function m(t,e,i,s,r){if(null==t.left)return t.tdst=function(t,e,i,s,r){const n=e-t[0],o=i-t[1],h=s-t[2],l=r-t[3];return n*n+o*o+h*h+l*l}(t.est.q,e,i,s,r),t;const n=v(t.est,e,i,s,r);let o=t.left,h=t.right;n>0&&(o=t.right,h=t.left);const l=m(o,e,i,s,r);if(l.tdst<=n*n)return l;const a=m(h,e,i,s,r);return a.tdst<l.tdst?a:l}function v(t,e,i,s,r){const{e:n}=t;return n[0]*e+n[1]*i+n[2]*s+n[3]*r-t.eMq}function y(t,e,i,s,r,n){for(s-=4;i<s;){for(;k(t,i,r)<=n;)i+=4;for(;k(t,s,r)>n;)s-=4;if(i>=s)break;const o=e[i>>2];e[i>>2]=e[s>>2],e[s>>2]=o,i+=4,s-=4}for(;k(t,i,r)>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 s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=[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);r[0]+=e,r[1]+=i,r[2]+=o,r[3]+=h,s[0]+=e*e,s[1]+=e*i,s[2]+=e*o,s[3]+=e*h,s[5]+=i*i,s[6]+=i*o,s[7]+=i*h,s[10]+=o*o,s[11]+=o*h,s[15]+=h*h}return s[4]=s[1],s[8]=s[2],s[9]=s[6],s[12]=s[3],s[13]=s[7],s[14]=s[11],{R:s,m:r,N:n}}function M(t){const{R:e}=t,{m:i}=t,{N:s}=t,r=i[0],n=i[1],o=i[2],h=i[3],l=0==s?0:1/s,a=[e[0]-r*r*l,e[1]-r*n*l,e[2]-r*o*l,e[3]-r*h*l,e[4]-n*r*l,e[5]-n*n*l,e[6]-n*o*l,e[7]-n*h*l,e[8]-o*r*l,e[9]-o*n*l,e[10]-o*o*l,e[11]-o*h*l,e[12]-h*r*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!=s)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=[r*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]]};lo.encode=function(t,e,i,s,r,n,o){null==s&&(s=0),null==o&&(o=!1);const h=u(t,e,i,s,[!1,!1,!1,0,o,!1]);return a(h,-1),l(h,e,i,r,n)},lo.encodeLL=function(t,e,i,s,r,n,o,h){const u={ctype:0+(1==s?0:2)+(0==r?0:4),depth:n,frames:[]},c=(s+r)*n,f=c*e;for(let s=0;s<t.length;s++)u.frames.push({rect:{x:0,y:0,width:e,height:i},img:new Uint8Array(t[s]),blend:0,dispose:1,bpp:Math.ceil(c/8),bpl:Math.ceil(f/8)});return a(u,0,!0),l(u,e,i,o,h)},lo.encode.compress=u,lo.encode.dither=h,lo.quantize=g,lo.quantize.getKDtree=w,lo.quantize.getNearest=m}();const ao={toArrayBuffer(t,e){const i=t.width,s=t.height,r=i<<2,n=t.getContext("2d").getImageData(0,0,i,s),o=new Uint32Array(n.data.buffer),h=(32*i+31)/32<<2,l=h*s,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(-s>>>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<s&&m>0;){for(w=122+v*h,d=0;d<r;)m--,p=o[k++],g=p>>>24,c.setUint32(w+d,p<<8|g),d+=4;v++}k<o.length?(m=f,setTimeout(t,ao._dly)):e(u)}()},toBlob(t,e){this.toArrayBuffer(t,(t=>{e(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var uo={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},co={[uo.CHROME]:16384,[uo.FIREFOX]:11180,[uo.DESKTOP_SAFARI]:16384,[uo.IE]:8192,[uo.IOS]:4096,[uo.ETC]:8192};const fo="undefined"!=typeof window,po="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,go=fo&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),wo=(fo||po)&&(go&&go.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),mo=(fo||po)&&(go&&go.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function vo(t,e,i=Date.now()){return new Promise((s=>{const r=t.split(","),n=r[0].match(/:(.*?);/)[1],o=globalThis.atob(r[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,s(a)}))}function yo(t){return new Promise(((e,i)=>{const s=new mo;s.onload=()=>e(s.result),s.onerror=t=>i(t),s.readAsDataURL(t)}))}function ko(t){return new Promise(((e,i)=>{const s=new Image;s.onload=()=>e(s),s.onerror=t=>i(t),s.src=t}))}function bo(){if(void 0!==bo.cachedResult)return bo.cachedResult;let t=uo.ETC;const{userAgent:e}=navigator;return/Chrom(e|ium)/i.test(e)?t=uo.CHROME:/iP(ad|od|hone)/i.test(e)&&/WebKit/i.test(e)?t=uo.IOS:/Safari/i.test(e)?t=uo.DESKTOP_SAFARI:/Firefox/i.test(e)?t=uo.FIREFOX:(/MSIE/i.test(e)||1==!!document.documentMode)&&(t=uo.IE),bo.cachedResult=t}function Mo(t,e){const i=bo(),s=co[i];let r=t,n=e,o=r*n;const h=r>n?n/r:r/n;for(;o>s*s;){const t=(s+r)/2,e=(s+n)/2;t<e?(n=e,r=e*h):(n=t*h,r=t),o=r*n}return{width:r,height:n}}function xo(t,e){let i,s;try{if(i=new OffscreenCanvas(t,e),s=i.getContext("2d"),null===s)throw new Error("getContext of OffscreenCanvas returns null")}catch(t){i=document.createElement("canvas"),s=i.getContext("2d")}return i.width=t,i.height=e,[i,s]}function Co(t,e){const{width:i,height:s}=Mo(t.width,t.height),[r,n]=xo(i,s);return e&&/jpe?g/.test(e)&&(n.fillStyle="white",n.fillRect(0,0,r.width,r.height)),n.drawImage(t,0,0,r.width,r.height),r}function Ao(){return void 0!==Ao.cachedResult||(Ao.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),Ao.cachedResult}function So(t,e={}){return new Promise((function(i,s){let r,n;var o=function(){try{return n=Co(r,e.fileType||t.type),i([r,n])}catch(t){return s(t)}},h=function(){try{var e=function(t){try{throw t}catch(t){return s(t)}};try{let i;return yo(t).then((function(t){try{return i=t,ko(i).then((function(t){try{return r=t,function(){try{return o()}catch(t){return s(t)}}()}catch(t){return e(t)}}),e)}catch(t){return e(t)}}),e)}catch(t){e(t)}}catch(t){return s(t)}};try{if(Ao()||[uo.DESKTOP_SAFARI,uo.MOBILE_SAFARI].includes(bo()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return r=t,o()}catch(t){return h()}}),h)}catch(t){h()}}))}function Bo(t,e,i,s,r=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=lo.encode([u.buffer],t.width,t.height,4096*r),h=new Blob([c],{type:e}),h.name=i,h.lastModified=s,l.call(this)}{if("image/bmp"===e)return new Promise((e=>ao.toBlob(t,e))).then(function(t){try{return h=t,h.name=i,h.lastModified=s,f.call(this)}catch(t){return o(t)}}.bind(this),o);{if("function"==typeof OffscreenCanvas&&t instanceof OffscreenCanvas)return t.convertToBlob({type:e,quality:r}).then(function(t){try{return h=t,h.name=i,h.lastModified=s,d.call(this)}catch(t){return o(t)}}.bind(this),o);{let p;return p=t.toDataURL(e,r),vo(p,i,s).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 To(t){t.width=0,t.height=0}function Oo(){return new Promise((function(t,e){let i,s,r,n;return void 0!==Oo.cachedResult?t(Oo.cachedResult):vo("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return i=o,So(i).then((function(o){try{return s=o[1],Bo(s,i.type,i.name,i.lastModified).then((function(i){try{return r=i,To(s),So(r).then((function(i){try{return n=i[0],t(Oo.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 Eo(t){return new Promise(((e,i)=>{const s=new mo;s.onload=t=>{const i=new DataView(t.target.result);if(65496!=i.getUint16(0,!1))return e(-2);const s=i.byteLength;let r=2;for(;r<s;){if(i.getUint16(r+2,!1)<=8)return e(-1);const t=i.getUint16(r,!1);if(r+=2,65505==t){if(1165519206!=i.getUint32(r+=2,!1))return e(-1);const t=18761==i.getUint16(r+=6,!1);r+=i.getUint32(r+4,t);const s=i.getUint16(r,t);r+=2;for(let n=0;n<s;n++)if(274==i.getUint16(r+12*n,t))return e(i.getUint16(r+12*n+8,t))}else{if(65280&~t)break;r+=i.getUint16(r,!1)}}return e(-1)},s.onerror=t=>i(t),s.readAsArrayBuffer(t)}))}function Io(t,e){const{width:i}=t,{height:s}=t,{maxWidthOrHeight:r}=e;let n,o=t;return isFinite(r)&&(i>r||s>r)&&([o,n]=xo(i,s),i>s?(o.width=r,o.height=s/i*r):(o.width=i/s*r,o.height=r),n.drawImage(t,0,0,o.width,o.height),To(t)),o}function $o(t,e){const{width:i}=t,{height:s}=t,[r,n]=xo(i,s);switch(e>4&&e<9?(r.width=s,r.height=i):(r.width=i,r.height=s),e){case 2:n.transform(-1,0,0,1,i,0);break;case 3:n.transform(-1,0,0,-1,i,s);break;case 4:n.transform(1,0,0,-1,0,s);break;case 5:n.transform(0,1,1,0,0,0);break;case 6:n.transform(0,1,-1,0,s,0);break;case 7:n.transform(0,-1,-1,0,s,i);break;case 8:n.transform(0,-1,1,0,0,i)}return n.drawImage(t,0,0,i,s),To(t),r}function Po(t,e,i=0){return new Promise((function(s,r){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(),So(t,e).then(function(i){try{return[,l]=i,A(),a=Io(l,e),A(),new Promise((function(i,s){var r;if(!(r=e.exifOrientation))return Eo(t).then(function(t){try{return r=t,n.call(this)}catch(t){return s(t)}}.bind(this),s);function n(){return i(r)}return n.call(this)})).then(function(i){try{return u=i,A(),Oo().then(function(i){try{return c=i?a:$o(a,u),A(),f=e.initialQuality||1,d=e.fileType||t.type,Bo(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),s(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]=xo(e,i),M.drawImage(x,0,0,e,i),f*="image/png"===d?.85:.95,Bo(b,d,t.name,t.lastModified,f).then((function(t){try{return k=t,To(x),x=b,y=k.size,S(Math.min(99,Math.floor((v-y)/(v-h)*100))),u}catch(t){return r(t)}}),r)}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,r);try{if(t.pop){if(t.length)return t.pop()?B.call(this):t;t=u}else t=t.call(this)}catch(t){return r(t)}}}.bind(this))(u);function B(){return To(x),To(b),To(a),To(c),To(l),S(100),s(k)}}}catch(T){return r(T)}}.bind(this),r)}catch(t){return r(t)}}.bind(this),r)}catch(t){return r(t)}}.bind(this),r)}catch(t){return r(t)}}.bind(this),r)}))}let Do;function Ro(t,e){return new Promise(((i,s)=>{Do||(Do=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 r=new Worker(Do);r.addEventListener("message",(function(t){if(e.signal&&e.signal.aborted)r.terminate();else if(void 0===t.data.progress){if(t.data.error)return s(new Error(t.data.error)),void r.terminate();i(t.data.file),r.terminate()}else e.onProgress(t.data.progress)})),r.addEventListener("error",s),e.signal&&e.signal.addEventListener("abort",(()=>{s(e.signal.reason),r.terminate()})),r.postMessage({file:t,imageCompressionLibUrl:e.libURL,options:{...e,onProgress:void 0,signal:void 0}})}))}function jo(t,e){return new Promise((function(i,s){let r,n,o,h,l,a;if(r={...e},o=0,({onProgress:h}=r),r.maxSizeMB=r.maxSizeMB||Number.POSITIVE_INFINITY,l="boolean"!=typeof r.useWebWorker||r.useWebWorker,delete r.useWebWorker,r.onProgress=t=>{o=t,"function"==typeof h&&h(o)},!(t instanceof Blob||t instanceof wo))return s(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(t.type))return s(new Error("The file given is not an image"));if(a="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!l||"function"!=typeof Worker||a)return Po(t,r).then(function(t){try{return n=t,f.call(this)}catch(t){return s(t)}}.bind(this),s);var u=function(){try{return f.call(this)}catch(t){return s(t)}}.bind(this),c=function(){try{return Po(t,r).then((function(t){try{return n=t,u()}catch(t){return s(t)}}),s)}catch(t){return s(t)}};try{return r.libURL=r.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",Ro(t,r).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{r.preserveExif&&"image/jpeg"===t.type&&(!r.fileType||r.fileType&&r.fileType===t.type)&&(n=so(t,n))}catch(t){}return i(n)}}))}jo.getDataUrlFromFile=yo,jo.getFilefromDataUrl=vo,jo.loadImage=ko,jo.drawImageInCanvas=Co,jo.drawFileInCanvas=So,jo.canvasToFile=Bo,jo.getExifOrientation=Eo,jo.handleMaxWidthOrHeight=Io,jo.followExifOrientation=$o,jo.cleanupCanvasMemory=To,jo.isAutoOrientationInBrowser=Oo,jo.approximateBelowMaximumCanvasSizeOfBrowser=Mo,jo.copyExifWithoutOrientation=so,jo.getBrowserName=bo,jo.version="2.0.2";class Fo extends Gn{fileInput=null;maxCompressionSize=1200;multiImportOffset=20;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.multiple=!0,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,i=e.files?Array.from(e.files):[];if(0===i.length)return console.info("File selection cancelled by user."),this.handleCancel(),void(e&&(e.value=""));const s=i.map((t=>jo(t,{maxWidthOrHeight:this.maxCompressionSize}).then((t=>this.prepareImage(t)))));Promise.allSettled(s).then((t=>{const e=[];for(const i of t)"fulfilled"===i.status?e.push(i.value):console.error("Error during image compression or processing:",i.reason);0!==e.length?this.addImagesToStore(e):this.handleCancel()})),e&&(e.value="")}async prepareImage(t){let e=null;try{const i=t.type||"image/png";e=URL.createObjectURL(t);const s=await this.measureImage(e),r=await this._core.assetResolver.put(t,{mimeType:i,kind:"image",width:s.naturalWidth,height:s.naturalHeight}),n=Xn.create(this._core);n.assetId=r.id,n.mimeType=r.mimeType;const{scaledWidth:o,scaledHeight:h}=n.calculateScaledDimensions({width:s.naturalWidth,height:s.naturalHeight});return n.width=o,n.height=h,n.resolvedSrc=await this._core.assetResolver.resolve(r.id),n.loadState="ready",n}finally{if(e)try{URL.revokeObjectURL(e)}catch{}}}measureImage(t){return new Promise(((e,i)=>{const s=new Image;s.onload=()=>e({naturalWidth:s.naturalWidth,naturalHeight:s.naturalHeight}),s.onerror=t=>i(t),s.src=t}))}addImagesToStore(t){const e=this._core.store.currentZIndex;t.forEach(((t,i)=>{if(t.zIndex=e+i,t.centerInViewport(),i>0){const e=i*this.multiImportOffset;t.updatePosition(t.translateX+e,t.translateY+e)}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 No extends Gn{_fontFamily="Arial";_fontSize=16;_fontColor=An[0];_opacity=1;get fontFamily(){return this._fontFamily}set fontFamily(t){this._fontFamily=t,this.applyToActiveText({fontFamily:t})}get fontSize(){return this._fontSize}set fontSize(t){this._fontSize=t,this.applyToActiveText({fontSize:t})}get fontColor(){return this._fontColor}set fontColor(t){this._fontColor=t,this.applyToActiveText({fontColor:t})}get opacity(){return this._opacity}set opacity(t){this._opacity=t,this.applyToActiveText({opacity:t})}palette=[...An];constructor(t){super(t)}applyToActiveText(t){const e=this._core?.store?.activeText;e&&(this._core.updateObject(e,t),this._core.rerender())}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){const e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),s=e?.id?this._core.findObjectById(e.id):null,r=this._core.store.activeText;if(null===r&&s instanceof Pn)return void s.edit(t);if(null!==r&&s instanceof Pn)return r.save(),void s.edit(t);if(null!==r&&s instanceof Pn==0)return this._core.resetActiveText(),void this._core.store.setState("activeTool",i.getTool("selection"));if(!1===qn.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.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()),s=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),r=s?.id?this._core.findObjectById(s.id):null,n=this._core.store.activeText;if(null===n&&r instanceof Pn)return void r.edit(t);if(null!==n&&r instanceof Pn)return n.save(),void r.edit(t);if(null!==n&&r 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.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 Uo extends Gn{shapeType=Kn.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"))),s=this._core.findObjectById(e?.id),r=this._core.store.activeShape;if(null===r&&s instanceof Qn)return void s.edit(t);if(null!==r&&s instanceof Qn)return r.save(),void s.edit(t);if(null!==r&&s instanceof Qn==0)return this._core.resetActiveShape(),void this._core.store.setState("activeTool",i.getTool("selection"));if(!1===qn.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()),s=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),r=this._core.findObjectById(s?.id),n=this._core.store.activeShape;if(null===n&&r instanceof Qn)return void r.edit(t);if(null!==n&&r instanceof Qn)return n.save(),void r.edit(t);if(null!==n&&r instanceof Qn==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,s=this._core.store.state.lockDrawingScale,r=s?i:1;this.startX=(t-this._core.store.offsetX)/r,this.startY=(e-this._core.store.offsetY)/r,this.isDrawing=!0,this.currentShape=Qn.create(this._core,{x:this.startX,y:this.startY,translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,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:s?1:i}),this._core.store.objects.insert(this.currentShape),this._core.store.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,s=(t-this._core.store.offsetX)/i,r=(e-this._core.store.offsetY)/i,n=Math.min(this.startX,s),o=Math.min(this.startY,r),h=Math.abs(s-this.startX),l=Math.abs(r-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.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.objects.remove((e=>e.id===t))}else this.currentShape.zIndex=this._core.store.currentZIndex,this._core.store.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.objects?.setActiveDrawingObject(null),this.currentShape=null,this._core.store.objects?.stopUndoCapturing(),this._core.rerender()}}}class zo{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)}}zo.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>',"image-off":'<svg xmlns="http://www.w3.org/2000/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-image-off-icon lucide-image-off"><line x1="2" x2="22" y1="2" y2="22"/><path d="M10.41 10.41a2 2 0 1 1-2.83-2.83"/><line x1="13.5" x2="6" y1="13.5" y2="21"/><line x1="18" x2="21" y1="12" y2="15"/><path d="M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59"/><path d="M21 15V5a2 2 0 0 0-2-2H9"/></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 _o{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=zo.get(e);if(!i)return console.warn(`Icon "${e}" not found in registry.`),"auto";const s=t.size||24,r=t.rotation||0,n=t.color||"black",o=t.hotspot||("default"===t.iconName?{x:4,y:4}:{x:s/2,y:s/2});let h=i.replace(/width="\d+"/,`width="${s}"`).replace(/height="\d+"/,`height="${s}"`).replace(/currentColor/g,n);const l=s/2;return`url('data:image/svg+xml;charset=utf-8,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${s}" viewBox="0 0 ${s} ${s}">\n <g transform="rotate(${r} ${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 Lo{_core;constructor(t){this._core=t}}class Ho extends Lo{dragStartX=0;dragStartY=0;startX=0;startY=0;endX=0;endY=0;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(qn.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,s=t.shiftKey||t.ctrlKey;if(!i?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||s)this.trackedPointerId=null;else{const i=Math.round(e[0].clientX-this._core.store.offsetX),s=Math.round(e[0].clientY-this._core.store.offsetY);this.dragStartX=i,this.dragStartY=s,this.startX=i,this.startY=s,this.initialDragX=i,this.initialDragY=s,this.disconnectedLineIds.clear(),this.trackedPointerId=t.pointerId}}}}handlePointerMove(t){if(null!==this.trackedPointerId&&this.trackedPointerId===t.pointerId){if("mouse"===t.pointerType){const e=this._core.store.selectionGroup;if(this._core.store.state.isDragging&&e){const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this.endX=i,this.endY=s;const r=Math.abs(i-this.startX),n=Math.abs(s-this.startY),o=5;(this.hasMoved||r>o||n>o)&&(this.checkAndDisconnectAnchors(i,s),e.move(i,s,this.dragStartX,this.dragStartY),this.dragStartX=i,this.dragStartY=s,this.hasMoved=!0)}}if("touch"===t.pointerType||"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),s=Math.round(t[0].clientY-this._core.store.offsetY);this._core.store.state.isDragging=!0,this.endX=i,this.endY=s;const r=Math.abs(i-this.startX),n=Math.abs(s-this.startY),o=5;if(this.hasMoved||r>o||n>o){const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t),this.checkAndDisconnectAnchors(i,s),e.move(i,s,this.dragStartX,this.dragStartY),this.dragStartX=i,this.dragStartY=s,this.hasMoved=!0}}}}}handlePointerUp(t){null!==this.trackedPointerId&&this.trackedPointerId===t.pointerId&&("mouse"===t.pointerType&&this._core.store.state.isDragging&&(this._core.store.state.isDragging=!1,this.hasMoved&&(this._core.store.selectionGroup.persistChildren(),this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0,this._core.store.objects.stopUndoCapturing())),"touch"!==t.pointerType&&"pen"!==t.pointerType||this._core.store.state.isDragging&&(this._core.store.state.isDragging=!1,this.hasMoved&&(this._core.store.selectionGroup.persistChildren(),this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0,this._core.store.objects.stopUndoCapturing())),this.reset())}checkAndDisconnectAnchors(t,e){const i=t-this.initialDragX,s=e-this.initialDragY;if(Math.sqrt(i*i+s*s)<30)return;const r=this._core.store.selectionGroup;if(!r)return;const n=r.objects;if(n.every((t=>t instanceof Yn)))for(const t of n)if(!this.disconnectedLineIds.has(t.id)&&t instanceof Yn){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.objects.update(e))}}}var Xo;!function(t){t.TopLeft="top-left",t.TopRight="top-right",t.BottomLeft="bottom-left",t.BottomRight="bottom-right"}(Xo||(Xo={}));class Yo extends Lo{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&&qn.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,s=t.clientY-this._core.store.offsetY;this._core.store.state.isResizing=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialSize.width=e.width,this.initialSize.height=e.height,this.initialSize.x=e.translateX,this.initialSize.y=e.translateY}}if("touch"===t.pointerType||"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),s=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isResizing=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialSize.width=t.width,this.initialSize.height=t.height,this.initialSize.x=t.translateX,this.initialSize.y=t.translateY;const r=this._core.store.state.longTouchTimeout;r&&globalThis.clearTimeout?.(r)}}}}handlePointerMove(t){if("mouse"===t.pointerType){const e=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&e){const i=t.clientX-this._core.store.offsetX-this.initialMouseX,s=t.clientY-this._core.store.offsetY-this.initialMouseY,r=Math.abs(i),n=Math.abs(s),o=5;if((r>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+s*l)/c,d=(-i*l+s*a)/c,p=this.initialSize.x+this.initialSize.width/u/2+i/c/2,g=this.initialSize.y+this.initialSize.height/u/2+s/c/2;switch(this._core.store.state.resizeHandleType){case Xo.TopLeft:this.newSize.width=this.initialSize.width-f*u,this.newSize.height=this.initialSize.height-d*u;break;case Xo.TopRight:this.newSize.width=this.initialSize.width+f*u,this.newSize.height=this.initialSize.height-d*u;break;case Xo.BottomLeft:this.newSize.width=this.initialSize.width-f*u,this.newSize.height=this.initialSize.height+d*u;break;case Xo.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),s=Math.round(t.clientY-this._core.store.offsetY),r=i-this.initialMouseX,n=s-this.initialMouseY,o=Math.abs(r),h=Math.abs(n),l=5;if(o>l||h>l){const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t),this.hasResized=!0}if(!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=(r*c+n*u)/d,g=(-r*u+n*c)/d,w=this.initialSize.x+this.initialSize.width/f/2+r/d/2,m=this.initialSize.y+this.initialSize.height/f/2+n/d/2;switch(this._core.store.state.resizeHandleType){case Xo.TopLeft:this.newSize.width=this.initialSize.width-p*f,this.newSize.height=this.initialSize.height-g*f;break;case Xo.TopRight:this.newSize.width=this.initialSize.width+p*f,this.newSize.height=this.initialSize.height-g*f;break;case Xo.BottomLeft:this.newSize.width=this.initialSize.width-p*f,this.newSize.height=this.initialSize.height+g*f;break;case Xo.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,s=this.newSize.height/e;Math.abs(this.newSize.width/t-1)>Math.abs(s-1)?this.newSize.height=this.newSize.width/i:this.newSize.width=this.newSize.height*i}handlePointerUp(t){if("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._core.store.objects.stopUndoCapturing()),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._core.store.objects.stopUndoCapturing()),this.reset();const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t)}}}class Wo extends Lo{initialRotation=0;rotation=0;initialSelectionGroupRotation=0;constructor(t){super(t)}reset(){this.initialRotation=0,this.rotation=0}handlePointerDown(t){if("mouse"===t.pointerType&&qn.isLeftClick(t)){const e=this._core.store.selectionGroup;if(e&&this._core.store.state.isRotationHandleSelected){e.beginTransform();const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isRotating=!0;const r=e.scale||1,n=e.translateX+e.width/2/r,o=e.translateY+e.height/2/r,h=(i-this._core.store.state.translateX)/this._core.store.state.scale,l=(s-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=e.rotation,this.initialRotation=Math.atan2(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),s=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isRotating=!0;const r=t.scale||1,n=t.translateX+t.width/2/r,o=t.translateY+t.height/2/r,h=(i-this._core.store.state.translateX)/this._core.store.state.scale,l=(s-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=t.rotation,this.initialRotation=Math.atan2(o-l,n-h)-t.rotation;const a=this._core.store.state.longTouchTimeout;a&&globalThis.clearTimeout?.(a)}}}}handlePointerMove(t){if("mouse"===t.pointerType){const e=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&e){const i=e.scale||1,s=Math.atan2(e.translateY+e.height/2/i-(t.clientY-this._core.store.offsetY-this._core.store.state.translateY)/this._core.store.state.scale,e.translateX+e.width/2/i-(t.clientX-this._core.store.offsetX-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=s-this.initialRotation,e.rotate(this.rotation)}}if("touch"===t.pointerType||"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),s=Math.round(t.clientY-this._core.store.offsetY),r=e.scale||1,n=Math.atan2(e.translateY+e.height/2/r-(s-this._core.store.state.translateY)/this._core.store.state.scale,e.translateX+e.width/2/r-(i-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=n-this.initialRotation,e.rotate(this.rotation);const o=this._core.store.state.longTouchTimeout;o&&globalThis.clearTimeout?.(o)}}}handlePointerUp(t){if("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._core.store.objects.stopUndoCapturing(),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._core.store.objects.stopUndoCapturing(),this.reset();const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t)}}}class Vo extends n{__class__="KritzelSelectionBox";static create(t){const e=new Vo;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 Ko extends Lo{startX=0;startY=0;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&&(!qn.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),s=Math.abs(e-this.touchStartX),r=Math.abs(i-this.touchStartY),n=5;if((s>n||r>n)&&this._core.store.state.isSelecting){this.updateTouchSelection();const t=this._core.store.state.longTouchTimeout;t&&globalThis.clearTimeout?.(t)}}}handlePointerUp(t){if("mouse"===t.pointerType&&qn.isLeftClick(t)){const e=this._core.store.state.hasObjectsChanged,i=this._core.store.selectionGroup,s=t.shiftKey||t.ctrlKey;if(1!==i?.objects.length||!1!==e||s||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,s=t.shiftKey||t.ctrlKey;if(1!==i?.objects.length||!1!==e||s||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.objects.remove((t=>t instanceof Vo)),this._core.store.setSelectionBox(null),this._core.store.objects.clearLocalSelectionBox()}startMouseSelection(t,e=!1){let i,s;i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;const r=Vo.create(this._core);this.startX=(i-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(s-this._core.store.state.translateY)/this._core.store.state.scale,r.translateX=this.startX,r.translateY=this.startY,this._core.store.state.isSelecting=!0,this._core.store.objects.remove((t=>t instanceof Vo||!e&&t instanceof to&&(null==t.userId||t.userId===this._core.user?.id))),this._core.store.setSelectionBox(null),e||this._core.store.setSelectionGroup(null),this._core.store.objects.insert(r),this._core.store.setSelectionBox(r)}startTouchSelection(t,e=!1){const i=Array.from(this._core.store.state.pointers.values())[0];if(!i)return;let s,r;s=Math.round(i.clientX-this._core.store.offsetX),r=Math.round(i.clientY-this._core.store.offsetY),this.touchStartX=s,this.touchStartY=r;const n=Vo.create(this._core);this.startX=(s-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(r-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.objects.remove((t=>t instanceof Vo||!e&&t instanceof to&&(null==t.userId||t.userId===this._core.user?.id))),this._core.store.setSelectionBox(null),e||this._core.store.setSelectionGroup(null),this._core.store.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 s=this._core.store.selectionBox;if(s){const t=(e-this._core.store.state.translateX)/s.scale,r=(i-this._core.store.state.translateY)/s.scale,n=Math.abs(t-this.startX)*s.scale,o=Math.abs(r-this.startY)*s.scale;s.width=n,s.height=o,s.translateX=Math.min(t,this.startX),s.translateY=Math.min(r,this.startY),this._core.store.objects.setLocalSelectionBox({x:s.translateX,y:s.translateY,width:n/s.scale,height:o/s.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 s=this._core.store.selectionBox;if(s){const t=(e-this._core.store.state.translateX)/s.scale,r=(i-this._core.store.state.translateY)/s.scale,n=Math.abs(t-this.startX)*s.scale,o=Math.abs(r-this.startY)*s.scale;s.width=n,s.height=o,s.translateX=Math.min(t,this.startX),s.translateY=Math.min(r,this.startY),this._core.store.objects.setLocalSelectionBox({x:s.translateX,y:s.translateY,width:n/s.scale,height:o/s.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],s=[e.topLeft.y,e.topRight.y,e.bottomRight.y,e.bottomLeft.y],r=Math.min(...i),n=Math.max(...i),o=Math.min(...s),h=Math.max(...s),l=this._core.store.objects.query({x:r,y:o,z:t.scale,width:n-r,height:h-o}),a=new Set;for(const t of l){if(t instanceof Vo||t instanceof to)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(),e&&this.addObjectToSelectionGroup(e,i),this.removeSelectionBox()}getTopmostHitObject(t){const e=this._core.store.state.pointerX,i=this._core.store.state.pointerY,s=this._core.getObjectsFromPointerEvent(t,".object");for(const t of s)if(!(t instanceof Vo||t instanceof to)&&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=Vn.findParentGroup(this._core,t.id)||t;i.isSelected=!1;const s=this._core.store.selectionGroup;if(e&&s)s.addOrRemove(i),this.removeDescendantsOfSelectedGroups(s),0===s.objects.length?this._core.removeSelectionGroup():this._core.rerender();else{const t=to.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.objects.filter((t=>"KritzelGroup"===t.__class__)),s=new Map;for(const t of i)for(const e of t.childIds)s.set(e,t);const r=new Map;for(const t of e){const e=s.get(t.id)||t;r.set(e.id,e),t.isSelected=!1}const n=Array.from(r.values()),o=this.filterDescendantsOfSelectedGroups(n),h=this._core.store.selectionGroup;if(t&&h)h.addObjects(o),this.removeDescendantsOfSelectedGroups(h),this._core.rerender();else{const t=to.create(this._core);t.objectIds=o.map((t=>t.id)),1===t.length&&(t.rotation=t.objects[0].rotation),t.captureUnchangedSnapshots(),t.refreshObjectDimensions(),t.isSelected=!0,this._core.addSelectionGroup(t),this._core.rerender()}}filterDescendantsOfSelectedGroups(t){const e=new Set;for(const i of t)i instanceof Vn&&Vn.collectDescendantIds(i,e);return 0===e.size?t:t.filter((t=>!e.has(t.id)))}removeDescendantsOfSelectedGroups(t){const e=this.filterDescendantsOfSelectedGroups(t.objects);e.length!==t.objects.length&&(t.objectIds=e.map((t=>t.id)))}}class Jo extends Lo{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 Qo extends Lo{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&&qn.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,s=t.clientY-this._core.store.offsetY;this._core.store.state.isLineHandleDragging=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialStartX=e.startX,this.initialStartY=e.startY,this.initialEndX=e.endX,this.initialEndY=e.endY,this.initialControlX=e.controlX,this.initialControlY=e.controlY,this.initialTranslateX=e.translateX,this.initialTranslateY=e.translateY;const r=this._core.store.state.lineHandleType;"start"!==r&&"end"!==r||this._core.anchorManager.removeAnchor(e.id,r);const n=this._core.store.state.longTouchTimeout;n&&globalThis.clearTimeout?.(n)}handlePointerMove(t){const e=this.getSelectedLine();if(!e||!this._core.store.state.isLineHandleDragging)return;const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY,r=i-this.initialMouseX,n=s-this.initialMouseY;if((Math.abs(r)>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=r/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,r=(s-this._core.store.state.translateY)/o,n=e.endAnchor?.objectId,h=this._core.anchorManager.findSnapTarget(t,r,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),s=this._core.store.allNonSelectionObjects.find((t=>t.id===h.objectId));let r,n,o,l;if(s){const t=this._core.anchorManager.computeAnchorClipInfo(e,"start",s);t&&(r=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:r,edgeY:n,lineStroke:$n.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,r=(s-this._core.store.state.translateY)/o,n=e.startAnchor?.objectId,h=this._core.anchorManager.findSnapTarget(t,r,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),s=this._core.store.allNonSelectionObjects.find((t=>t.id===h.objectId));let r,n,o,l;if(s){const t=this._core.anchorManager.computeAnchorClipInfo(e,"end",s);t&&(r=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:r,edgeY:n,lineStroke:$n.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,s=e.startX,r=e.startY,n=e.endX,o=e.endY,h=n-s,l=o-r,a=h*h+l*l;let u,c,f=-1;0!==a&&(f=((t-s)*h+(i-r)*l)/a),f<0?(u=s,c=r):f>1?(u=n,c=o):(u=s+f*h,c=r+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 s=(e-t.translateX)*t.scale,r=(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:(s-n)*h-(r-o)*l+n+t.x,y:(s-n)*l+(r-o)*h+o+t.y}}lineLocalToWorld(t,e,i){const s=e-t.x,r=i-t.y,n=t.totalWidth/2,o=t.totalHeight/2,h=Math.cos(t.rotation),l=Math.sin(t.rotation);return{x:((s-n)*h-(r-o)*l+n)/t.scale+t.translateX,y:((s-n)*l+(r-o)*h+o)/t.scale+t.translateY}}updateLineEndpoint(t,e,i,s,r){const{minX:n,minY:o,maxX:h,maxY:l}=Yn.calculateBoundingBox(e,i,s,r,t.controlX,t.controlY,t.strokeWidth),a=h-n,u=l-o,{minX:c,minY:f,maxX:d,maxY:p}=Yn.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=s,t.endY=r,t.x=n,t.y=o,t.width=a,t.height=u,t.translateX=x,t.translateY=C,t._adjustedPoints=null,this._core.store.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.objects.stopUndoCapturing()}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 Yn?e:null}}class qo extends Gn{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)Wn.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 Nn)return e.fill;if(e instanceof Yn)return e.stroke;if(e instanceof Pn)return e.fontColor;if(e instanceof Qn)return e.strokeColor}return An[0]}set color(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Nn&&this._core.updateObject(e,{fill:t}),e instanceof Yn&&this._core.updateObject(e,{stroke:t}),e instanceof Pn&&this._core.updateObject(e,{fontColor:t}),e instanceof Qn&&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 Nn)return e.strokeWidth;if(e instanceof Yn)return e.strokeWidth;if(e instanceof Pn)return e.fontSize;if(e instanceof Qn)return e.strokeWidth}return 1}set size(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Nn&&this._core.updateObject(e,{strokeWidth:t}),e instanceof Yn&&this._core.updateObject(e,{strokeWidth:t}),e instanceof Pn&&this._core.updateObject(e,{fontSize:t}),e instanceof Qn&&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 Qn)return e.fillColor;return{light:"transparent",dark:"transparent"}}set fillColor(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{if(e instanceof Qn){const i=$n.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 Qn)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 Qn&&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 Yn)return e.arrows??{start:{enabled:!1},end:{enabled:!1}};return{start:{enabled:!1},end:{enabled:!1}}}set arrows(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Yn&&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 Qn)),s=t.some((t=>t instanceof Pn)),r=t.some((t=>t instanceof Yn)),n=t.some((t=>t instanceof Xn)),o=t.some((t=>t instanceof Nn||t instanceof Yn||t instanceof Qn));return!n||i||s||r||o?(s&&!o?(e.push({type:"font-size",propertyName:"size"}),e.push({type:"font-family",propertyName:"fontFamily"})):o&&!s?e.push({type:"stroke-size",propertyName:"size"}):(o&&e.push({type:"stroke-size",propertyName:"size"}),s&&e.push({type:"font-family",propertyName:"fontFamily"})),r&&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 Ko(this._core),this.moveHandler=new Ho(this._core),this.hoverHandler=new Jo(this._core),this.resizeHandler=new Yo(this._core),this.rotationHandler=new Wo(this._core),this.lineHandleHandler=new Qo(this._core)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){if(qn.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,s=e&&i&&e.id!==i.id,r=t.shiftKey||t.ctrlKey;!i&&e&&(this._core.store.state.skipContextMenu=!0),null!==e&&!s||!i||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||r||(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=e?.id?this._core.findObjectById(e.id):null;if(!i)return null;const{x:s,y:r}=this._core.getCanvasPoint(t);if(!i.hitTest(s,r))return null;if(i instanceof to)return i;{const t=to.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 Go{type="local";provider;isConnected=!1;constructor(e,i,s){this.provider=new t(s?.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 Zo=Math.floor,th=127,eh=Number.MAX_SAFE_INTEGER,ih="undefined"!=typeof TextEncoder?new TextEncoder:null,sh=ih?t=>ih.encode(t):t=>{const e=unescape(encodeURIComponent(t)),i=e.length,s=new Uint8Array(i);for(let t=0;t<i;t++)s[t]=e.codePointAt(t);return s};let rh="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});rh&&1===rh.decode(new Uint8Array).length&&(rh=null);const nh=(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},oh=(t,e)=>{for(;e>th;)nh(t,128|th&e),e=Zo(e/128);nh(t,th&e)},hh=new Uint8Array(3e4),lh=hh.length/3,ah=ih&&ih.encodeInto?(t,e)=>{if(e.length<lh){const i=ih.encodeInto(e,hh).written||0;oh(t,i);for(let e=0;e<i;e++)nh(t,hh[e])}else uh(t,sh(e))}:(t,e)=>{const i=unescape(encodeURIComponent(e)),s=i.length;oh(t,s);for(let e=0;e<s;e++)nh(t,i.codePointAt(e))},uh=(t,e)=>{oh(t,e.byteLength),((t,e)=>{const i=t.cbuf.length,s=t.cpos,r=((t,e)=>t<e?t:e)(i-s,e.length),n=e.length-r;t.cbuf.set(e.subarray(0,r),s),t.cpos+=r,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(r)),t.cpos=n)})(t,e)},ch=t=>new Error(t),fh=ch("Unexpected end of array"),dh=ch("Integer out of Range"),ph=t=>t.arr[t.pos++],gh=t=>{let e=0,i=1;const s=t.arr.length;for(;t.pos<s;){const s=t.arr[t.pos++];if(e+=(s&th)*i,i*=128,s<128)return e;if(e>eh)throw dh}throw fh},wh=rh?t=>rh.decode((t=>((t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,i})(t,gh(t)))(t)):t=>{let e=gh(t);if(0===e)return"";{let i=String.fromCodePoint(ph(t));if(--e<100)for(;e--;)i+=String.fromCodePoint(ph(t));else for(;e>0;){const s=e<1e4?e:1e4,r=t.arr.subarray(t.pos,t.pos+s);t.pos+=s,i+=String.fromCodePoint.apply(null,r),e-=s}return decodeURIComponent(escape(i))}};var mh;!function(t){t[t.Token=0]="Token",t[t.PermissionDenied=1]="PermissionDenied",t[t.Authenticated=2]="Authenticated"}(mh||(mh={}));const vh=t=>Array.from(t.entries()).map((([t,e])=>({clientId:t,...e})));var yh;async function kh(t){return new Promise((e=>setTimeout(e,t)))}function bh(t,e){let i=e.delay;if(0===i)return 0;if(e.factor&&(i*=Math.pow(e.factor,t.attemptNum-1),0!==e.maxDelay&&(i=Math.min(i,e.maxDelay))),e.jitter){const t=Math.ceil(e.minDelay),s=Math.floor(i);i=Math.floor(Math.random()*(s-t+1))+t}return Math.round(i)}!function(t){t[t.Connecting=0]="Connecting",t[t.Open=1]="Open",t[t.Closing=2]="Closing",t[t.Closed=3]="Closed"}(yh||(yh={}));const Mh=Math.floor,xh=128,Ch=127,Ah=Number.MAX_SAFE_INTEGER,Sh=()=>new Set,Bh=Array.from,Th="undefined"!=typeof TextEncoder?new TextEncoder:null,Oh=Th?t=>Th.encode(t):t=>{const e=unescape(encodeURIComponent(t)),i=e.length,s=new Uint8Array(i);for(let t=0;t<i;t++)s[t]=e.codePointAt(t);return s};let Eh="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Eh&&1===Eh.decode(new Uint8Array).length&&(Eh=null);class Ih{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const $h=()=>new Ih,Ph=t=>{let e=t.cpos;for(let i=0;i<t.bufs.length;i++)e+=t.bufs[i].length;return e},Dh=t=>{const e=new Uint8Array(Ph(t));let i=0;for(let s=0;s<t.bufs.length;s++){const r=t.bufs[s];e.set(r,i),i+=r.length}return e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),i),e},Rh=(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},jh=(t,e)=>{for(;e>Ch;)Rh(t,xh|Ch&e),e=Mh(e/128);Rh(t,Ch&e)},Fh=new Uint8Array(3e4),Nh=Fh.length/3,Uh=Th&&Th.encodeInto?(t,e)=>{if(e.length<Nh){const i=Th.encodeInto(e,Fh).written||0;jh(t,i);for(let e=0;e<i;e++)Rh(t,Fh[e])}else zh(t,Oh(e))}:(t,e)=>{const i=unescape(encodeURIComponent(e)),s=i.length;jh(t,s);for(let e=0;e<s;e++)Rh(t,i.codePointAt(e))},zh=(t,e)=>{jh(t,e.byteLength),((t,e)=>{const i=t.cbuf.length,s=t.cpos,r=((t,e)=>t<e?t:e)(i-s,e.length),n=e.length-r;t.cbuf.set(e.subarray(0,r),s),t.cpos+=r,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(r)),t.cpos=n)})(t,e)},_h=t=>new Error(t),Lh=_h("Unexpected end of array"),Hh=_h("Integer out of Range");class Xh{constructor(t){this.arr=t,this.pos=0}}const Yh=t=>new Xh(t),Wh=t=>((t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,i})(t,Kh(t)),Vh=t=>t.arr[t.pos++],Kh=t=>{let e=0,i=1;const s=t.arr.length;for(;t.pos<s;){const s=t.arr[t.pos++];if(e+=(s&Ch)*i,i*=128,s<xh)return e;if(e>Ah)throw Hh}throw Lh},Jh=Eh?t=>Eh.decode(Wh(t)):t=>{let e=Kh(t);if(0===e)return"";{let i=String.fromCodePoint(Vh(t));if(--e<100)for(;e--;)i+=String.fromCodePoint(Vh(t));else for(;e>0;){const s=e<1e4?e:1e4,r=t.arr.subarray(t.pos,t.pos+s);t.pos+=s,i+=String.fromCodePoint.apply(null,r),e-=s}return decodeURIComponent(escape(i))}},Qh=Date.now,qh=()=>new Map;class Gh{constructor(){this._observers=qh()}on(t,e){((t,e,i)=>{let s=t.get(e);return void 0===s&&t.set(e,s=i()),s})(this._observers,t,Sh).add(e)}once(t,e){const i=(...s)=>{this.off(t,i),e(...s)};this.on(t,i)}off(t,e){const i=this._observers.get(t);void 0!==i&&(i.delete(e),0===i.size&&this._observers.delete(t))}emit(t,e){return Bh((this._observers.get(t)||qh()).values()).forEach((t=>t(...e)))}destroy(){this._observers=qh()}}const Zh=Object.keys,tl=t=>Zh(t).length,el=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),il=(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)||!il(t.get(i),e.get(i)))return!1;break;case Object:if(tl(t)!==tl(e))return!1;for(const i in t)if(!el(t,i)||!il(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(!il(t[i],e[i]))return!1;break;default:return!1}return!0};class sl extends Gh{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const t=Qh();null!==this.getLocalState()&&15e3<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const e=[];this.meta.forEach(((i,s)=>{s!==this.clientID&&3e4<=t-i.lastUpdated&&this.states.has(s)&&e.push(s)})),e.length>0&&rl(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),s=void 0===i?0:i.clock+1,r=this.states.get(e);null===t?this.states.delete(e):this.states.set(e,t),this.meta.set(e,{clock:s,lastUpdated:Qh()});const n=[],o=[],h=[],l=[];null===t?l.push(e):null==r?null!=t&&n.push(e):(o.push(e),il(r,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 rl=(t,e,i)=>{const s=[];for(let i=0;i<e.length;i++){const r=e[i];if(t.states.has(r)){if(t.states.delete(r),r===t.clientID){const e=t.meta.get(r);t.meta.set(r,{clock:e.clock+1,lastUpdated:Qh()})}s.push(r)}}s.length>0&&(t.emit("change",[{added:[],updated:[],removed:s},i]),t.emit("update",[{added:[],updated:[],removed:s},i]))},nl=(t,e,i=t.states)=>{const s=e.length,r=$h();jh(r,s);for(let n=0;n<s;n++){const s=e[n],o=i.get(s)||null,h=t.meta.get(s).clock;jh(r,s),jh(r,h),Uh(r,JSON.stringify(o))}return Dh(r)};class ol{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 hl{constructor(t){this.data=t,this.encoder=$h(),this.decoder=Yh(new Uint8Array(this.data))}peekVarString(){return(t=>{const e=t.pos,i=Jh(t);return t.pos=e,i})(this.decoder)}readVarUint(){return Kh(this.decoder)}readVarString(){return Jh(this.decoder)}readVarUint8Array(){return Wh(this.decoder)}writeVarUint(t){return jh(this.encoder,t)}writeVarString(t){return Uh(this.encoder,t)}writeVarUint8Array(t){return zh(this.encoder,t)}length(){return Ph(this.encoder)}}var ll,al;!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"}(ll||(ll={})),function(t){t.Connecting="connecting",t.Connected="connected",t.Disconnected="disconnected"}(al||(al={}));class ul{constructor(){this.encoder=$h()}get(t){return t.encoder}toUint8Array(){return Dh(this.encoder)}}class cl extends ul{constructor(){super(...arguments),this.type=ll.CLOSE,this.description="Ask the server to close the connection"}get(t){return Uh(this.encoder,t.documentName),jh(this.encoder,this.type),this.encoder}}class fl extends ol{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=al.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=al.Connected,this.emit("status",{status:al.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=t}attach(t){this.configuration.providerMap.set(t.configuration.name,t),this.status===al.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===al.Connected&&t.onOpen(this.receivedOnOpenPayload)}detach(t){this.configuration.providerMap.has(t.configuration.name)&&(t.send(cl,{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===al.Connected)return;this.cancelWebsocketRetry&&(this.cancelWebsocketRetry(),this.cancelWebsocketRetry=void 0),this.receivedOnOpenPayload=void 0,this.shouldConnect=!0;const{retryPromise:t,cancelFunc:e}=(()=>{let t=!1;const e=async function(t,e){const i=function(t){return t||(t={}),{delay:void 0===t.delay?200:t.delay,initialDelay:void 0===t.initialDelay?0:t.initialDelay,minDelay:void 0===t.minDelay?0:t.minDelay,maxDelay:void 0===t.maxDelay?0:t.maxDelay,factor:void 0===t.factor?0:t.factor,maxAttempts:void 0===t.maxAttempts?3:t.maxAttempts,timeout:void 0===t.timeout?0:t.timeout,jitter:!0===t.jitter,initialJitter:!0===t.initialJitter,handleError:void 0===t.handleError?null:t.handleError,handleTimeout:void 0===t.handleTimeout?null:t.handleTimeout,beforeAttempt:void 0===t.beforeAttempt?null:t.beforeAttempt,calculateDelay:void 0===t.calculateDelay?null:t.calculateDelay}}(e);for(const t of["delay","initialDelay","minDelay","maxDelay","maxAttempts","timeout"]){const e=i[t];if(!Number.isInteger(e)||e<0)throw new Error(`Value for ${t} must be an integer greater than or equal to 0`)}if(i.factor.constructor!==Number||i.factor<0)throw new Error("Value for factor must be a number greater than or equal to 0");if(i.delay<i.minDelay)throw new Error(`delay cannot be less than minDelay (delay: ${i.delay}, minDelay: ${i.minDelay}`);const s={attemptNum:0,attemptsRemaining:i.maxAttempts?i.maxAttempts:-1,aborted:!1,abort(){s.aborted=!0}},r=i.calculateDelay||bh,n=i.calculateDelay?i.calculateDelay(s,i):i.initialDelay;if(n&&await kh(n),s.attemptNum<1&&i.initialJitter){const t=r(s,i);t&&await kh(t)}return async function e(){if(i.beforeAttempt&&i.beforeAttempt(s,i),s.aborted){const t=new Error("Attempt aborted");throw t.code="ATTEMPT_ABORTED",t}const n=async t=>{if(i.handleError&&await i.handleError(t,s,i),s.aborted||0===s.attemptsRemaining)throw t;s.attemptNum++;const n=r(s,i);return n&&await kh(n),e()};return s.attemptsRemaining>0&&s.attemptsRemaining--,i.timeout?new Promise(((e,r)=>{const o=setTimeout((()=>{if(i.handleTimeout)try{e(i.handleTimeout(s,i))}catch(t){r(t)}else{const t=new Error(`Retry timeout (attemptNum: ${s.attemptNum}, timeout: ${i.timeout})`);t.code="ATTEMPT_TIMEOUT",r(t)}}),i.timeout);t(s,i).then((t=>{clearTimeout(o),e(t)})).catch((t=>{clearTimeout(o),n(t).then(e).catch(r)}))})):t(s,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 s=this.webSocketHandlers[t.identifier];Object.keys(s).forEach((e=>{t.addEventListener(e,s[e])}))}cleanupWebSocket(){if(!this.webSocket)return;const{identifier:t}=this.webSocket,e=this.webSocketHandlers[t];Object.keys(e).forEach((i=>{var s;null===(s=this.webSocket)||void 0===s||s.removeEventListener(i,e[i]),delete this.webSocketHandlers[t]})),this.webSocket.close(),this.webSocket=null}createWebSocketConnection(){return new Promise(((t,e)=>{this.webSocket&&(this.messageQueue=[],this.cleanupWebSocket()),this.lastMessageReceived=0,this.identifier+=1;const i=new this.configuration.WebSocketPolyfill(this.url);i.binaryType="arraybuffer",i.identifier=this.identifier,this.attachWebSocketListeners(i,e),this.webSocket=i,this.status=al.Connecting,this.emit("status",{status:al.Connecting}),this.connectionAttempt={resolve:t,reject:e}}))}onMessage(t){var e;this.resolveConnectionAttempt(),this.lastMessageReceived=Qh();const i=new hl(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=al.Connected,this.emit("status",{status:al.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===al.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=Qh()-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)===yh.Open?this.webSocket.send(t):this.messageQueue.push(t)}onClose({event:t}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=al.Disconnected,this.emit("status",{status:al.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 dl=(t,i,s)=>{try{e.applyUpdate(i,Wh(t),s)}catch(t){console.error("Caught error while handling a Yjs update",t)}},pl=dl;class gl{constructor(t){this.message=t}apply(t,e){const{message:i}=this,s=i.readVarUint(),r=i.length();switch(s){case ll.Sync:this.applySyncMessage(t,e);break;case ll.Awareness:this.applyAwarenessMessage(t);break;case ll.Auth:this.applyAuthMessage(t);break;case ll.QueryAwareness:this.applyQueryAwarenessMessage(t);break;case ll.Stateless:t.receiveStateless(Jh(i.decoder));break;case ll.SyncStatus:this.applySyncStatusMessage(t,1===(t=>{let e=t.arr[t.pos++],i=63&e,s=64;const r=(64&e)>0?-1:1;if(!(e&xh))return r*i;const n=t.arr.length;for(;t.pos<n;){if(e=t.arr[t.pos++],i+=(e&Ch)*s,s*=128,e<xh)return r*i;if(i>Ah)throw Hh}throw Lh})(i.decoder));break;case ll.CLOSE:const r={code:1e3,reason:Jh(i.decoder),target:t.configuration.websocketProvider.webSocket,type:"close"};t.onClose(),t.configuration.onClose({event:r}),t.forwardClose({event:r});break;default:throw new Error(`Can’t apply message of unknown type: ${s}`)}i.length()>r+1&&t.send(ul,{encoder:i.encoder})}applySyncMessage(t,i){const{message:s}=this;s.writeVarUint(ll.Sync);const r=((t,i,s,r)=>{const n=Kh(t);switch(n){case 0:((t,i,s)=>{((t,i,s)=>{jh(t,1),zh(t,e.encodeStateAsUpdate(i,s))})(i,s,Wh(t))})(t,i,s);break;case 1:dl(t,s,r);break;case 2:pl(t,s,r);break;default:throw new Error("Unknown message type")}return n})(s.decoder,s.encoder,t.document,t);i&&1===r&&(t.synced=!0)}applySyncStatusMessage(t,e){e&&t.decrementUnsyncedChanges()}applyAwarenessMessage(t){if(!t.awareness)return;const{message:e}=this;((t,e,i)=>{const s=Yh(e),r=Qh(),n=[],o=[],h=[],l=[],a=Kh(s);for(let e=0;e<a;e++){const e=Kh(s);let i=Kh(s);const a=JSON.parse(Jh(s)),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:r}),void 0===u&&null!==a?n.push(e):void 0!==u&&null===a?l.push(e):null!==a&&(il(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,s)=>{switch(gh(t)){case mh.Token:e();break;case mh.PermissionDenied:i(wh(t));break;case mh.Authenticated:s(wh(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(ll.Awareness),e.writeVarUint8Array(nl(t.awareness,Array.from(t.awareness.getStates().keys())))}}class wl{constructor(t,e={}){this.message=new t,this.encoder=this.message.get(e)}create(){return Dh(this.encoder)}send(t){null==t||t.send(this.create())}}class ml extends ul{constructor(){super(...arguments),this.type=ll.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 Uh(this.encoder,t.documentName),jh(this.encoder,this.type),i=t.token,oh(e=this.encoder,mh.Token),ah(e,i),this.encoder}}class vl extends ul{constructor(){super(...arguments),this.type=ll.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 Uh(this.encoder,t.documentName),jh(this.encoder,this.type),e=void 0===t.states?nl(t.awareness,t.clients):nl(t.awareness,t.clients,t.states),zh(this.encoder,e),this.encoder}}class yl extends ul{constructor(){super(...arguments),this.type=ll.Stateless,this.description="A stateless message"}get(t){var e;return Uh(this.encoder,t.documentName),jh(this.encoder,this.type),Uh(this.encoder,null!==(e=t.payload)&&void 0!==e?e:""),this.encoder}}class kl extends ul{constructor(){super(...arguments),this.type=ll.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 Uh(this.encoder,t.documentName),jh(this.encoder,this.type),((t,i)=>{jh(t,0);const s=e.encodeStateVector(i);zh(t,s)})(this.encoder,t.document),this.encoder}}class bl extends ul{constructor(){super(...arguments),this.type=ll.Sync,this.description="A document update"}get(t){var e,i;return Uh(this.encoder,t.documentName),jh(this.encoder,this.type),i=t.update,jh(e=this.encoder,2),zh(e,i),this.encoder}}class Ml extends Error{constructor(){super(...arguments),this.code=1001}}class xl extends ol{constructor(t){var i,s,r;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 sl(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:vh(this.awareness.getStates())})})),null===(s=this.awareness)||void 0===s||s.on("change",(()=>{this.emit("awarenessChange",{states:vh(this.awareness.getStates())})})),this.document.on("update",this.boundDocumentUpdateHandler),null===(r=this.awareness)||void 0===r||r.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 fl(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(kl,{document:this.document,documentName:this.configuration.name})}pageHide(){this.awareness&&rl(this.awareness,[this.document.clientID],"page hide")}registerEventListeners(){"undefined"!=typeof window&&"addEventListener"in window&&window.addEventListener("pagehide",this.boundPageHide)}sendStateless(t){this.send(yl,{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(ml,{token:null!=t?t:"",documentName:this.configuration.name})}documentUpdateHandler(t,e){e!==this&&(this.incrementUnsyncedChanges(),this.send(bl,{update:t,documentName:this.configuration.name}))}awarenessUpdateHandler({added:t,updated:e,removed:i},s){const r=t.concat(e).concat(i);this.send(vl,{awareness:this.awareness,clients:r,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(kl,{document:this.document,documentName:this.configuration.name}),this.awareness&&null!==this.awareness.getLocalState()&&this.send(vl,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.configuration.name})}send(t,e){if(!this._isAttached)return;const i=new wl(t,e);this.emit("outgoingMessage",{message:i.message}),i.send(this.configuration.websocketProvider)}onMessage(t){const e=new hl(t.data),i=e.readVarString();e.writeVarString(i),this.emit("message",{event:t,message:new hl(t.data)}),new gl(e).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&rl(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&&(rl(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 Cl="1.2.0";class Al{__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 Al(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:Cl,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 Sl{_core;_anchorIndex=new Map;constructor(t){this._core=t}setAnchor(t,e,i){const s=this.getLineById(t);if(!s)return;if("start"===e&&s.endAnchor?.objectId===i)return;if("end"===e&&s.startAnchor?.objectId===i)return;this.removeAnchor(t,e);const r={objectId:i};"start"===e?s.startAnchor=r:s.endAnchor=r,this.addToIndex(i,t,e),this.snapEndpointToObject(s,e,i),this._core.store.objects.update(s)}removeAnchor(t,e){const i=this.getLineById(t);if(!i)return;const s="start"===e?i.startAnchor:i.endAnchor;s&&(this.removeFromIndex(s.objectId,t,e),"start"===e?i.startAnchor=void 0:i.endAnchor=void 0)}getAnchor(t,e){const i=this.getLineById(t);return i?("start"===e?i.startAnchor:i.endAnchor)??null:null}getLinesAnchoredTo(t){const e=this._anchorIndex.get(t);return e?Array.from(e):[]}updateAnchorsForObject(t){const e=this.getLinesAnchoredTo(t);if(0!==e.length&&this.getObjectById(t))for(const i of e){const e=this.getLineById(i.lineId);e&&this.snapEndpointToObject(e,i.endpoint,t)}}snapEndpointToObject(t,e,i){const s=this.getObjectById(i);if(!s)return;const r=this.worldToLineLocal(t,s.centerX,s.centerY);t.updateEndpoint(e,r.x,r.y)}worldToLineLocal(t,e,i){const s=e-t.centerX,r=i-t.centerY,n=Math.cos(-t.rotation),o=Math.sin(-t.rotation);return{x:(s*n-r*o+t.totalWidth/2/t.scale)*t.scale+t.x,y:(s*o+r*n+t.totalHeight/2/t.scale)*t.scale+t.y}}findSnapTarget(t,e,i,s){let n=null,o=-1/0;const h=this._core.store.allNonSelectionObjects;for(const l of h){if(l.id===i)continue;if(s&&l.id===s)continue;if(!this.isAnchorable(l))continue;const h=l.rotatedPolygon;r.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(!Wn.isInstanceOf(e,"KritzelLine"))return null;const i=e,s=this.computeAnchorVisualization(i,"start"),r=this.computeAnchorVisualization(i,"end"),n=this.isFiniteAnchorVisualization(s)?s:null,o=this.isFiniteAnchorVisualization(r)?r: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,s=""+2/e,r=this.areFiniteNumbers(t.lineStrokeWidth)&&t.lineStrokeWidth>0?t.lineStrokeWidth:4/e,n=`${r}`,o=Math.max(2*r,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,s=Math.sqrt(e*e+i*i);s>p&&(f=u+e/s*p,d=c+i/s*p);const r=u-t.lineEndpointX,n=c-t.lineEndpointY,o=Math.sqrt(r*r+n*n);if(o>0){const t=r/o,e=n/o,i=-e,s=u,h=c,l=s-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(s,h,d,g,w,m)&&(a=`${s},${h} ${d},${g} ${w},${m}`)}}if(!this.areFiniteNumbers(i,r,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:s,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.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 Yn&&(e.startAnchor&&this.addToIndex(e.startAnchor.objectId,e.id,"start"),e.endAnchor&&this.addToIndex(e.endAnchor.objectId,e.id,"end"))}addToIndex(t,e,i){this._anchorIndex.has(t)||this._anchorIndex.set(t,new Set);const s=this._anchorIndex.get(t);for(const t of s)if(t.lineId===e&&t.endpoint===i)return;s.add({lineId:e,endpoint:i})}removeFromIndex(t,e,i){const s=this._anchorIndex.get(t);if(s){for(const t of s)if(t.lineId===e&&t.endpoint===i){s.delete(t);break}0===s.size&&this._anchorIndex.delete(t)}}getLineById(t){const e=this._core.store.objects.filter((e=>e.id===t));if(0===e.length)return null;const i=e[0];return i instanceof Yn?i:null}getObjectById(t){const e=this._core.store.objects.filter((e=>e.id===t));return e.length>0?e[0]:null}findAnchorTarget(t,e){const i="start"===e?t.startAnchor:t.endAnchor;return i?this._core.store.allNonSelectionObjects.find((t=>t.id===i.objectId))??null:null}computeAnchorVisualization(t,e){if(!("start"===e?t.startAnchor:t.endAnchor))return null;const i=this.findAnchorTarget(t,e);if(!i)return null;const s=this.computeAnchorClipInfo(t,e,i);if(!s)return null;const r=i.centerX,n=i.centerY;if(!this.areFiniteNumbers(s.worldX,s.worldY,r,n))return null;const o=this.buildAnchorPath(t,e,s,i)??void 0;return o&&!this.isFinitePathData(o)?null:{edgeX:s.worldX,edgeY:s.worldY,centerX:r,centerY:n,pathD:o}}computeClippedLinePath(t,e=!1){const i=this.getSnapCandidate(),s=this._core.store.selectionGroup,r=i&&s&&1===s.objects.length&&s.objects[0].id===t.id;if(!t.startAnchor&&!t.endAnchor&&!r)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(r&&void 0!==i.edgeX&&void 0!==i.edgeY){const e=this.lineWorldToLocal(t,i.edgeX,i.edgeY),s={worldX:i.edgeX,worldY:i.edgeY,localX:e.x,localY:e.y,t:i.t};"start"===i.endpoint?h=s:l=s}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"),s=this.evaluateDerivativeSpeedAtT(t,e);s>0&&(e+=i/s)}if(l&&t.hasEndArrow){const e=t.getArrowSize("end"),s=this.evaluateDerivativeSpeedAtT(t,i);s>0&&(i-=e/s)}if(e<0&&(e=0),i>1&&(i=1),i<=e){const t=(e+i)/2;e=t,i=t}const s=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},e,i);return`M ${s.start.x-a} ${s.start.y-u} Q ${s.control.x-a} ${s.control.y-u} ${s.end.x-a} ${s.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,s=p-f,r=Math.sqrt(i*i+s*s);r>e&&(c+=i/r*e,f+=s/r*e)}if(l&&t.hasEndArrow){const e=t.getArrowSize("end"),i=c-d,s=f-p,r=Math.sqrt(i*i+s*s);r>e&&(d+=i/r*e,p+=s/r*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 s="start"===e?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY),n=this.getPathClipPoint(i,s);if(n){const i=this.lineWorldToLocal(t,n.x,n.y),s=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),r=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:s>0?r/s:"start"===e?0:1}}const o=this.getClipPolygonForObject(i);let h;if(h=o?r.getLinePointsArrayIntersection(s,{x:i.centerX,y:i.centerY},o):r.getLinePolygonIntersection(s,{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(Wn.isInstanceOf(i,"KritzelPath"))return this.findCurveExitPointForPath(t,e,i);const s=this.getClipPolygonForObject(i),n=s??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=s?r.getLinePointsArrayIntersection(h,{x:i.centerX,y:i.centerY},s):r.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 s="start"===e?0:1,n=this.evaluateLineAtT(t,s);let o=r.isPointInPolygon({x:n.worldX,y:n.worldY},i),h=s;for(let s=1;s<=64;s++){const n="start"===e?s/64:1-s/64,l=this.evaluateLineAtT(t,n),a=r.isPointInPolygon({x:l.worldX,y:l.worldY},i);if(o&&!a){const e=this.refineCurveExitParameter(t,i,h,n),s=this.evaluateLineAtT(t,e);return{localX:s.localX,localY:s.localY,worldX:s.worldX,worldY:s.worldY,t:e}}o=a,h=n}return null}findCurveExitPointForPath(t,e,i){const s="start"===e?0:1,r=i.strokeWidth/i.scale/2,n=this.getPathAdjustedPoints(i);if(n.length<1)return null;const o=this.evaluateLineAtT(t,s);let h=this.isPointInPathStroke(o.worldX,o.worldY,n,r),l=s;for(let i=1;i<=64;i++){const s="start"===e?i/64:1-i/64,o=this.evaluateLineAtT(t,s),a=this.isPointInPathStroke(o.worldX,o.worldY,n,r);if(h&&!a){const e=this.refineCurveExitParameterForPath(t,n,r,l,s),i=this.evaluateLineAtT(t,e);return{localX:i.localX,localY:i.localY,worldX:i.worldX,worldY:i.worldY,t:e}}h=a,l=s}return null}refineCurveExitParameterForPath(t,e,i,s,r){let n=s,o=r;for(let s=0;s<8;s++){const s=(n+o)/2,r=this.evaluateLineAtT(t,s);this.isPointInPathStroke(r.worldX,r.worldY,e,i)?n=s:o=s}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),s=Math.sin(e),r=t.points.map((t=>t[0])),n=t.points.map((t=>t[1])),o={x:(Math.min(...r)+Math.max(...r))/2,y:(Math.min(...n)+Math.max(...n))/2},{x:h,y:l}=o;return t.points.map((([t,e])=>{const r=t-h,n=e-l;return[h+r*i-n*s,l+r*s+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,s){if(1===i.length){const r=i[0],n=t-r[0],o=e-r[1];return Math.sqrt(n*n+o*o)<=s}for(let r=0;r<i.length-1;r++){const n=i[r],o=i[r+1];if(this.pointToSegmentDistance(t,e,n[0],n[1],o[0],o[1])<=s)return!0}return!1}pointToSegmentDistance(t,e,i,s,r,n){const o=r-i,h=n-s,l=o*o+h*h;if(0===l)return Math.sqrt((t-i)*(t-i)+(e-s)*(e-s));let a=((t-i)*o+(e-s)*h)/l;a=Math.max(0,Math.min(1,a));const u=i+a*o,c=s+a*h;return Math.sqrt((t-u)*(t-u)+(e-c)*(e-c))}refineCurveExitParameter(t,e,i,s){let n=i,o=s;for(let i=0;i<8;i++){const i=(n+o)/2,s=this.evaluateLineAtT(t,i);r.isPointInPolygon({x:s.worldX,y:s.worldY},e)?n=i:o=i}return(n+o)/2}approximateParameterForWorldPoint(t,e){let i=0,s=1/0;for(let r=0;r<=80;r++){const n=r/80,o=this.evaluateLineAtT(t,n),h=Math.hypot(o.worldX-e.x,o.worldY-e.y);h<s&&(s=h,i=n)}return i}evaluateLineAtT(t,e){const i=Math.max(0,Math.min(1,e));let s,r;if(void 0!==t.controlX&&void 0!==t.controlY){const e=1-i;s=e*e*t.startX+2*e*i*t.controlX+i*i*t.endX,r=e*e*t.startY+2*e*i*t.controlY+i*i*t.endY}else s=t.startX+(t.endX-t.startX)*i,r=t.startY+(t.endY-t.startY)*i;const n=this.lineLocalToWorld(t,s,r);return{t:i,localX:s,localY:r,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,s=t.controlY,r=2*(1-i)*(e-t.startX)+2*i*(t.endX-e),n=2*(1-i)*(s-t.startY)+2*i*(t.endY-s);return Math.sqrt(r*r+n*n)}{const e=t.endX-t.startX,i=t.endY-t.startY;return Math.sqrt(e*e+i*i)}}extractQuadraticSegment(t,e,i,s,r){let n=Math.max(0,Math.min(1,s)),o=Math.max(0,Math.min(1,r));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)),s=t.start,r=t.control,n=t.end,o=this.lerpPoint(s,r,i),h=this.lerpPoint(r,n,i),l=this.lerpPoint(o,h,i);return{left:{start:s,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,s){if(void 0===t.controlX||void 0===t.controlY||void 0===i.t)return`M ${i.worldX} ${i.worldY} L ${s.centerX} ${s.centerY}`;const r="start"===e?0:i.t,n="start"===e?i.t:1;if(n<=r)return`M ${i.worldX} ${i.worldY} L ${s.centerX} ${s.centerY}`;const o=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},r,n);return this.buildWorldQuadraticPath(t,o,"start"===e)}buildWorldQuadraticPath(t,e,i=!1){const s=i?e.end:e.start,r=i?e.start:e.end,n=e.control,o=this.lineLocalToWorld(t,s.x,s.y),h=this.lineLocalToWorld(t,n.x,n.y),l=this.lineLocalToWorld(t,r.x,r.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 Wn.isInstanceOf(t,"KritzelShape")?t.getClipPolygon():null}getPathClipPoint(t,e){return Wn.isInstanceOf(t,"KritzelPath")?t.getClipPoint(e):null}lineLocalToWorld(t,e,i){const s=e-t.x,r=i-t.y,n=t.totalWidth/2,o=t.totalHeight/2,h=Math.cos(t.rotation),l=Math.sin(t.rotation),a=(s-n)*h-(r-o)*l+n,u=(s-n)*l+(r-o)*h+o,c=this.getSafeScale(t.scale);return{x:a/c+t.translateX,y:u/c+t.translateY}}lineWorldToLocal(t,e,i){const s=this.getSafeScale(t.scale),r=(e-t.translateX)*s,n=(i-t.translateY)*s,o=t.totalWidth/2,h=t.totalHeight/2,l=Math.cos(-t.rotation),a=Math.sin(-t.rotation);return{x:(r-o)*l-(n-h)*a+o+t.x,y:(r-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 Vo||t instanceof to)&&!(t instanceof Yn)&&t.isVisible}}const Bl={type:"pen",color:An[0],size:16,palettes:{pen:[...An]}},Tl={color:An[0],size:8,fontFamily:"Arial",palette:[...An]},Ol={color:An[0],size:4,palette:[...An],arrows:{end:{enabled:!0,style:"triangle"}}},El={providers:[_n]};var Il;!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"}(Il||(Il={}));const $l=2,Pl=2;function Dl(t,e,i,s,r,n){const o=n?.quiet??!0,h=e.get("schemaVersion")??0;if(h>=r)return{migrated:!1,fromVersion:h,toVersion:h};const l=s.filter((t=>t.fromVersion>=h&&t.toVersion<=r)).sort(((t,e)=>t.fromVersion-e.fromVersion));return o||console.log(`[Kritzel] Running ${l.length} migration(s) from v${h} to v${r}`),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",r)}),"migration"),o||console.log(`[Kritzel] Migrations complete. Schema now at v${r}`),{migrated:!0,fromVersion:h,toVersion:r}}const Rl=[{fromVersion:1,toVersion:2,migrate(t,e){const i=e.workspaces;i&&i.forEach(((t,e)=>{const s=t?.viewport;if(!s)return;if("centerWorldX"in s)return;const r=s.scale??1,n=s.translateX??0,o=s.translateY??0,h={...t,viewport:{centerWorldX:-n/r||0,centerWorldY:-o/r||0,scale:r}};i.set(e,h)}))}}],jl=[{fromVersion:1,toVersion:2,migrate(t,e){}}];export{Ln as A,Dl as B,$l as C,Bl as D,Rl as E,jl as F,$n as G,xl as H,Go as I,o as J,Pn as K,Jn as L,An as M,to as N,Vo as O,zo as P,h as Q,Lo as R,Kn as S,i as T,n as U,s as V,Cl as W,Wn as X,qn as Y,Gn as Z,fl as a,Nn as b,Xn as c,Yn as d,Vn as e,Qn as f,Zn as g,eo as h,io as i,Fo as j,No as k,Uo as l,_o as m,qo as n,Hn as o,_n as p,Al as q,Sl as r,In as s,Tl as t,Ol as u,El as v,Sn as w,Bn as x,Il as y,Pl as z}
|