kritzel-stencil 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/cjs/{default-line-tool.config-Bva9deYM.js → default-line-tool.config-DSutud0N.js} +22 -6
  2. package/dist/cjs/index.cjs.js +1 -1
  3. package/dist/cjs/kritzel-back-to-content_32.cjs.entry.js +39 -49
  4. package/dist/collection/classes/objects/text.class.js +19 -3
  5. package/dist/collection/classes/tools/text-tool.class.js +3 -3
  6. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +20 -34
  7. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +17 -13
  8. package/dist/collection/constants/version.js +1 -1
  9. package/dist/components/index.js +1 -1
  10. package/dist/components/kritzel-controls.js +1 -1
  11. package/dist/components/kritzel-editor.js +1 -1
  12. package/dist/components/kritzel-engine.js +1 -1
  13. package/dist/components/kritzel-settings.js +1 -1
  14. package/dist/components/kritzel-tool-config.js +1 -1
  15. package/dist/components/p-B6WmB4Lk.js +1 -0
  16. package/dist/components/{p-CYX7RMRZ.js → p-BAVx6TLg.js} +1 -1
  17. package/dist/components/{p-Dmy0R-7y.js → p-BP6ggkYA.js} +1 -1
  18. package/dist/components/{p-BbHELXEC.js → p-CEHVU-Ri.js} +2 -2
  19. package/dist/components/{p-BsvZ2juR.js → p-DBUd8DTC.js} +1 -1
  20. package/dist/esm/{default-line-tool.config-DDIFE6oX.js → default-line-tool.config-_PqPRv7q.js} +22 -6
  21. package/dist/esm/index.js +2 -2
  22. package/dist/esm/kritzel-back-to-content_32.entry.js +39 -49
  23. package/dist/stencil/index.esm.js +1 -1
  24. package/dist/stencil/p-0472bdc3.entry.js +9 -0
  25. package/dist/stencil/p-_PqPRv7q.js +1 -0
  26. package/dist/stencil/stencil.esm.js +1 -1
  27. package/dist/types/components/ui/kritzel-controls/kritzel-controls.d.ts +1 -0
  28. package/dist/types/constants/version.d.ts +1 -1
  29. package/package.json +1 -1
  30. package/dist/components/p-DqtvAhfs.js +0 -1
  31. package/dist/stencil/p-3fc743ee.entry.js +0 -9
  32. package/dist/stencil/p-DDIFE6oX.js +0 -1
@@ -1 +0,0 @@
1
- class t{static registry={};static registerTool(t,e,i){const s=new e(i);return s.name=t,this.registry[t]=s,s}static getTool(t){return this.registry[t]||(console.warn(`Unknown tool: ${t}`),null)}}class e{static generateUUID(){return Math.random().toString(36).substr(2,9)}static isEmpty(t){return null==t||0===Object?.keys(t).length&&t?.constructor===Object}}class i{static doPolygonsIntersect(t,e){const i=[t.bottomLeft,t.bottomRight,t.topRight,t.topLeft],s=[e.bottomLeft,e.bottomRight,e.topRight,e.topLeft];for(const t of i)if(this.isPointInPolygon(t,s))return!0;for(const t of s)if(this.isPointInPolygon(t,i))return!0;for(let t=0;t<i.length;t++){const e=i[t],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 u=2*Math.PI*n/r,a=i*Math.cos(u),c=s*Math.sin(u);o.push({x:t+a*h-c*l,y:e+a*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 s{__class__="KritzelBaseObject";_core;_elementRef;id;workspaceId;x;y;translateX;translateY;height;width;backgroundColor;borderColor;borderWidth=0;opacity=1;padding=0;scale;resizing=!1;rotation=0;markedForRemoval=!1;zIndex=0;isVisible=!0;isSelected=!1;isHovered=!1;isMounted=!1;isEditable=!1;isInteractive=!1;isDebugInfoVisible=!1;get totalWidth(){return this.width+2*this.padding}get totalHeight(){return this.height+2*this.padding}set elementRef(t){this._elementRef=t}get elementRef(){return this._elementRef}get boundingBox(){return{x:this.translateX,y:this.translateY,z:this.scale,width:this.totalWidth/this.scale,height:this.totalHeight/this.scale}}get rotatedBoundingBox(){return{x:this.minXRotated,y:this.minYRotated,z:this.scale,width:this.maxXRotated-this.minXRotated,height:this.maxYRotated-this.minYRotated}}get rotatedPolygon(){const t=this.translateX+this.totalWidth/2/this.scale,e=this.translateY+this.totalHeight/2/this.scale,i=this.rotation,s=this.totalWidth/this.scale,r=this.totalHeight/this.scale,n={topLeft:{x:this.translateX,y:this.translateY},topRight:{x:this.translateX+s,y:this.translateY},bottomRight:{x:this.translateX+s,y:this.translateY+r},bottomLeft:{x:this.translateX,y:this.translateY+r}};return Object.keys(n).reduce(((s,r)=>{const o=n[r],h=Math.cos(i)*(o.x-t)-Math.sin(i)*(o.y-e)+t,l=Math.sin(i)*(o.x-t)+Math.cos(i)*(o.y-e)+e;return s[r]={x:h,y:l},s}),{})}get minXRotated(){return Math.min(this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x)}get minYRotated(){return Math.min(this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y)}get maxXRotated(){return Math.max(this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x)}get maxYRotated(){return Math.max(this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y)}get transformationMatrix(){const t=1/this.scale;return`matrix(${t}, 0, 0, ${t}, ${this.translateX}, ${this.translateY})`}get rotationDegrees(){return this.rotation*(180/Math.PI)}get centerX(){return this.translateX+this.totalWidth/2/this.scale}get centerY(){return this.translateY+this.totalHeight/2/this.scale}constructor(){this.id=this.generateId()}static create(t){const e=new s;return e._core=t,e.zIndex=t.store.currentZIndex,e.workspaceId=t.store.state.activeWorkspace.id,e}mount(t){this.isMounted||(this.elementRef=t,this.isMounted=!0)}generateId(){return e.generateUUID()}isInViewport(){const t=this._core.store.state.scale;if(this.boundingBox.width*t*(this.boundingBox.height*t)<.5)return!1;const e=-this._core.store.state.translateX/this._core.store.state.scale,i=-this._core.store.state.translateY/this._core.store.state.scale;return this.rotatedBoundingBox.x<e+this._core.store.state.viewportWidth/this._core.store.state.scale&&this.rotatedBoundingBox.x+this.rotatedBoundingBox.width>e&&this.rotatedBoundingBox.y<i+this._core.store.state.viewportHeight/this._core.store.state.scale&&this.rotatedBoundingBox.y+this.rotatedBoundingBox.height>i}centerInViewport(){const{viewportWidth:t,viewportHeight:e,translateX:i,translateY:s,scale: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.state.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.state.objects.update(this)}resize(t,e,i,s){i<=1||s<=1||(this.width=i,this.height=s,this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this),this._core.anchorManager.updateAnchorsForObject(this.id))}rotate(t){this.rotation=t,this._core.store.state.objects.update(this)}clone(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.id,t}copy(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.generateId(),t.isMounted=!1,t}serialize(){const{_core:t,_elementRef:e,element:i,totalWidth:s,totalHeight: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}isClass(t){return this.__class__===t}edit(t){}onAfterUpdate(t){}hitTest(t,e){return!0}hitTestPolygon(t){return i.doPolygonsIntersect(this.rotatedPolygon,t)}updatePosition(t,e){this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this)}}class r{static isTouchDevice(){return window.matchMedia("(any-pointer: coarse)").matches}static isAndroid(){return/android/i.test(navigator.userAgent)}static isIOS(){return/iPad|iPhone|iPod/.test(navigator.userAgent)}static detectOS(){return this.isIOS()?"iOS":this.isAndroid()?"Android":"Other"}static isFirefox(){return/firefox/i.test(navigator.userAgent)}}class n{static forceHideKeyboard(){document.activeElement instanceof HTMLElement&&document.activeElement.blur()}static enableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let e=t.getAttribute("content");e.includes("interactive-widget=resizes-content")||(e+=", interactive-widget=resizes-content"),t.setAttribute("content",e)}}static disableInteractiveWidget(){const t=document.querySelector('meta[name="viewport"][content*="interactive-widget=resizes-content"]');if(t){let e=t.getAttribute("content").replace(/\s*interactive-widget=resizes-content\s*[,;]?/g,"");e=e.replace(/,(\s*,)+/g,",").replace(/^,/,"").replace(/,$/,"").trim(),t.setAttribute("content",e)}}static isTextInputFocused(){const t=document.activeElement;return!!t&&(t instanceof HTMLInputElement?["text","password","email","number","search","tel","url"].includes(t.type):t instanceof HTMLTextAreaElement||!!(t instanceof HTMLElement&&t.isContentEditable))}static onKeyboardVisibleChanged(t){const e=r.detectOS();if("iOS"!==e&&"Android"!==e)return()=>{};if("virtualKeyboard"in navigator){const e=navigator.virtualKeyboard,i=()=>{t(e.boundingRect.height>0)};return e.addEventListener("geometrychange",i),()=>e.removeEventListener("geometrychange",i)}if("visualViewport"in window){const e=.75;let i=window.visualViewport.height;const s=()=>{const s=window.visualViewport.height*window.visualViewport.scale/i<e&&this.isTextInputFocused();t(s)},r=()=>{s()},n=()=>{this.isTextInputFocused()||(i=window.visualViewport.height),setTimeout(s,100)},o=()=>{setTimeout((()=>{this.isTextInputFocused()||(t(!1),setTimeout((()=>{i=window.visualViewport.height}),300))}),100)};return window.visualViewport.addEventListener("resize",r),document.addEventListener("focusin",n),document.addEventListener("focusout",o),()=>{window.visualViewport.removeEventListener("resize",r),document.removeEventListener("focusin",n),document.removeEventListener("focusout",o)}}return()=>{}}}function o(t){this.content=t}function h(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=h(r.content,n.content,i+1);if(null!=t)return t}i+=r.nodeSize}else i+=r.nodeSize}}function l(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),u=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=l(o.content,h.content,i-1,s-1);if(t)return t}i-=u,s-=u}else i-=u,s-=u}}o.prototype={constructor:o,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 o(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 o(i)},addToStart:function(t,e){return new o([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var i=this.remove(t).content.slice();return i.push(t,e),new o(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 o(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=o.from(t)).size?new o(t.content.concat(this.subtract(t).content)):this},append:function(t){return(t=o.from(t)).size?new o(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=o.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}},o.from=function(t){if(t instanceof o)return t;var e=[];if(t)for(var i in t)e.push(i,t[i]);return new o(e)};class u{constructor(t,e){if(this.content=t,this.size=e||0,null==e)for(let e=0;e<t.length;e++)this.size+=t[e].nodeSize}nodesBetween(t,e,i,s=0,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 u(s,this.size+t.size)}cut(t,e=this.size){if(0==t&&e==this.size)return this;let i=[],s=0;if(e>t)for(let 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 u(i,s)}cutByIndex(t,e){return t==e?u.empty:0==t&&e==this.content.length?this:new u(this.content.slice(t,e))}replaceChild(t,e){let i=this.content[t];if(i==e)return this;let s=this.content.slice(),r=this.size+e.nodeSize-i.nodeSize;return s[t]=e,new u(s,r)}addToStart(t){return new u([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new u(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let e=0;e<this.content.length;e++)if(!this.content[e].eq(t.content[e]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(t){let e=this.content[t];if(!e)throw new RangeError("Index "+t+" out of range for "+this);return e}maybeChild(t){return this.content[t]||null}forEach(t){for(let e=0,i=0;e<this.content.length;e++){let s=this.content[e];t(s,i,e),i+=s.nodeSize}}findDiffStart(t,e=0){return h(this,t,e)}findDiffEnd(t,e=this.size,i=t.size){return l(this,t,e,i)}findIndex(t){if(0==t)return c(0,t);if(t==this.size)return c(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let e=0,i=0;;e++){let s=i+this.child(e).nodeSize;if(s>=t)return s==t?c(e+1,s):c(e,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map((t=>t.toJSON())):null}static fromJSON(t,e){if(!e)return u.empty;if(!Array.isArray(e))throw new RangeError("Invalid input for Fragment.fromJSON");return new u(e.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return u.empty;let e,i=0;for(let s=0;s<t.length;s++){let 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 u(e||t,i)}static from(t){if(!t)return u.empty;if(t instanceof u)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new u([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}u.empty=new u([],0);const a={index:0,offset:0};function c(t,e){return a.index=t,a.offset=e,a}function f(t,e){if(t===e)return!0;if(!t||"object"!=typeof t||!e||"object"!=typeof e)return!1;let i=Array.isArray(t);if(Array.isArray(e)!=i)return!1;if(i){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!f(t[i],e[i]))return!1}else{for(let i in t)if(!(i in e)||!f(t[i],e[i]))return!1;for(let i in e)if(!(i in t))return!1}return!0}class d{constructor(t,e){this.type=t,this.attrs=e}addToSet(t){let e,i=!1;for(let s=0;s<t.length;s++){let 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&&f(this.attrs,t.attrs)}toJSON(){let t={type:this.type.name};for(let e in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Mark.fromJSON");let i=t.marks[e.type];if(!i)throw new RangeError(`There is no mark type ${e.type} in this schema`);let s=i.create(e.attrs);return i.checkAttrs(s.attrs),s}static sameSet(t,e){if(t==e)return!0;if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].eq(e[i]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&0==t.length)return d.none;if(t instanceof d)return[t];let e=t.slice();return e.sort(((t,e)=>t.type.rank-e.type.rank)),e}}d.none=[];class p extends Error{}class w{constructor(t,e,i){this.content=t,this.openStart=e,this.openEnd=i}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,e){let i=m(this.content,t+this.openStart,e);return i&&new w(i,this.openStart,this.openEnd)}removeBetween(t,e){return new w(g(this.content,t+this.openStart,e+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,e){if(!e)return w.empty;let i=e.openStart||0,s=e.openEnd||0;if("number"!=typeof i||"number"!=typeof s)throw new RangeError("Invalid input for Slice.fromJSON");return new w(u.fromJSON(t,e.content),i,s)}static maxOpen(t,e=!0){let i=0,s=0;for(let s=t.firstChild;s&&!s.isLeaf&&(e||!s.type.spec.isolating);s=s.firstChild)i++;for(let i=t.lastChild;i&&!i.isLeaf&&(e||!i.type.spec.isolating);i=i.lastChild)s++;return new w(t,i,s)}}function g(t,e,i){let{index:s,offset: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(g(n.content,e-r-1,i-r-1)))}function m(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=m(o.content,e-n-1,i,o);return h&&t.replaceChild(r,o.copy(h))}function v(t,e,i){if(i.openStart>t.depth)throw new p("Inserted content deeper than insertion position");if(t.depth-i.openStart!=e.depth-i.openEnd)throw new p("Inconsistent open depths");return y(t,e,i,0)}function y(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=y(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(u.from(s));return{start:s.resolveNoCache(t.openStart+i),end:s.resolveNoCache(s.content.size-t.openEnd-i)}}(i,t);return A(n,C(t,r,o,e,s))}{let s=t.parent,r=s.content;return A(s,r.cut(0,t.parentOffset).append(i.content).append(r.cut(e.parentOffset)))}}return A(n,S(t,e,s))}function b(t,e){if(!e.type.compatibleContent(t.type))throw new p("Cannot join "+e.type.name+" onto "+t.type.name)}function k(t,e,i){let s=t.node(i);return b(s,e.node(i)),s}function M(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 x(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&&(M(t.nodeAfter,s),n++));for(let t=n;t<o;t++)M(r.child(t),s);e&&e.depth==i&&e.textOffset&&M(e.nodeBefore,s)}function A(t,e){return t.type.checkContent(e),t.copy(e)}function C(t,e,i,s,r){let n=t.depth>r&&k(t,e,r+1),o=s.depth>r&&k(i,s,r+1),h=[];return x(null,t,r,h),n&&o&&e.index(r)==i.index(r)?(b(n,o),M(A(n,C(t,e,i,s,r+1)),h)):(n&&M(A(n,S(t,e,r+1)),h),x(e,i,r,h),o&&M(A(o,S(i,s,r+1)),h)),x(s,null,r,h),new u(h)}function S(t,e,i){let s=[];return x(null,t,i,s),t.depth>i&&M(A(k(t,e,i+1),S(t,e,i+1)),s),x(e,null,i,s),new u(s)}w.empty=new w(u.empty,0,0);class B{constructor(t,e,i){this.pos=t,this.path=e,this.parentOffset=i,this.depth=e.length/3-1}resolveDepth(t){return null==t?this.depth:t<0?this.depth+t:t}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(t){return this.path[3*this.resolveDepth(t)]}index(t){return this.path[3*this.resolveDepth(t)+1]}indexAfter(t){return t=this.resolveDepth(t),this.index(t)+(t!=this.depth||this.textOffset?1:0)}start(t){return 0==(t=this.resolveDepth(t))?0:this.path[3*t-1]+1}end(t){return t=this.resolveDepth(t),this.start(t)+this.node(t).content.size}before(t){if(!(t=this.resolveDepth(t)))throw new RangeError("There is no position before the top-level node");return t==this.depth+1?this.pos:this.path[3*t-1]}after(t){if(!(t=this.resolveDepth(t)))throw new RangeError("There is no position after the top-level node");return t==this.depth+1?this.pos:this.path[3*t-1]+this.path[3*t].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let t=this.parent,e=this.index(this.depth);if(e==t.childCount)return null;let i=this.pos-this.path[this.path.length-1],s=t.child(e);return i?t.child(e).cut(i):s}get nodeBefore(){let t=this.index(this.depth),e=this.pos-this.path[this.path.length-1];return e?this.parent.child(t).cut(0,e):0==t?null:this.parent.child(t-1)}posAtIndex(t,e){e=this.resolveDepth(e);let i=this.path[3*e],s=0==e?0:this.path[3*e-1]+1;for(let e=0;e<t;e++)s+=i.child(e).nodeSize;return s}marks(){let t=this.parent,e=this.index();if(0==t.content.size)return d.none;if(this.textOffset)return t.child(e).marks;let i=t.maybeChild(e-1),s=t.maybeChild(e);if(!i){let t=i;i=s,s=t}let 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 D(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 B(e,i,r)}static resolveCached(t,e){let i=E.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 E.set(t,i=new O);let s=i.elts[i.i]=B.resolve(t,e);return i.i=(i.i+1)%T,s}}class O{constructor(){this.elts=[],this.i=0}}const T=12,E=new WeakMap;class D{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 I=Object.create(null);class ${constructor(t,e,i,s=d.none){this.type=t,this.attrs=e,this.marks=s,this.content=i||u.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(t){return this.content.child(t)}maybeChild(t){return this.content.maybeChild(t)}forEach(t){this.content.forEach(t)}nodesBetween(t,e,i,s=0){this.content.nodesBetween(t,e,i,s,this)}descendants(t){this.nodesBetween(0,this.content.size,t)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(t,e,i,s){return this.content.textBetween(t,e,i,s)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(t){return this==t||this.sameMarkup(t)&&this.content.eq(t.content)}sameMarkup(t){return this.hasMarkup(t.type,t.attrs,t.marks)}hasMarkup(t,e,i){return this.type==t&&f(this.attrs,e||t.defaultAttrs||I)&&d.sameSet(this.marks,i||d.none)}copy(t=null){return t==this.content?this:new $(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new $(this.type,this.attrs,this.content,t)}cut(t,e=this.content.size){return 0==t&&e==this.content.size?this:this.copy(this.content.cut(t,e))}slice(t,e=this.content.size,i=!1){if(t==e)return w.empty;let s=this.resolve(t),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 w(h,s.depth-n,r.depth-n)}replace(t,e,i){return v(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 B.resolveCached(this,t)}resolveNoCache(t){return B.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()+")"),P(this.marks,t)}contentMatchAt(t){let e=this.type.contentMatch.matchFragment(this.content,0,t);if(!e)throw new Error("Called contentMatchAt on a node with invalid content");return e}canReplace(t,e,i=u.empty,s=0,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=d.none;for(let e=0;e<this.marks.length;e++){let i=this.marks[e];i.type.checkAttrs(i.attrs),t=i.addToSet(t)}if(!d.sameSet(t,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((t=>t.type.name))}`);this.content.forEach((t=>t.check()))}toJSON(){let t={type:this.type.name};for(let e in this.attrs){t.attrs=this.attrs;break}return this.content.size&&(t.content=this.content.toJSON()),this.marks.length&&(t.marks=this.marks.map((t=>t.toJSON()))),t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Node.fromJSON");let i;if(e.marks){if(!Array.isArray(e.marks))throw new RangeError("Invalid mark data for Node.fromJSON");i=e.marks.map(t.markFromJSON)}if("text"==e.type){if("string"!=typeof e.text)throw new RangeError("Invalid text node in JSON");return t.text(e.text,i)}let s=u.fromJSON(t,e.content),r=t.nodeType(e.type).create(e.attrs,s,i);return r.type.checkAttrs(r.attrs),r}}$.prototype.text=void 0;class R extends ${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):P(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 R(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new R(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 P(t,e){for(let i=t.length-1;i>=0;i--)e=t[i].type.name+"("+e+")";return e}class j{constructor(t){this.validEnd=t,this.next=[],this.wrapCache=[]}static parse(t,e){let i=new U(t,e);if(null==i.next)return j.empty;let s=N(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 j(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 u.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")}}j.empty=new j(!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 N(t){let e=[];do{e.push(F(t))}while(t.eat("|"));return 1==e.length?e[0]:{type:"choice",exprs:e}}function F(t){let e=[];do{e.push(_(t))}while(t.next&&")"!=t.next&&"|"!=t.next);return 1==e.length?e[0]:{type:"seq",exprs:e}}function _(t){let e=function(t){if(t.eat("(")){let e=N(t);return t.eat(")")||t.err("Missing closing paren"),e}if(!/\W/.test(t.next)){let e=function(t,e){let i=t.nodeTypes,s=i[e];if(s)return[s];let 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=z(t,e)}return e}function L(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function z(t,e){let i=L(t),s=i;return t.eat(",")&&(s="}"!=t.next?L(t):-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:i,max:s,expr:e}}function Y(t,e){return e-t}function W(t,e){let i=[];return function e(s){let 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 X(t){let e=Object.create(null);for(let i in t){let s=t[i];if(!s.hasDefault)return null;e[i]=s.default}return e}function H(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 V(t,e){let i=Object.create(null);if(e)for(let s in e)i[s]=new q(t,s,e[s]);return i}let Q=class t{constructor(t,e,i){this.name=t,this.schema=e,this.spec=i,this.markSet=null,this.groups=i.group?i.group.split(" "):[],this.attrs=V(t,i.attrs),this.defaultAttrs=X(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(i.inline||"text"==t),this.isText="text"==t}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==j.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(t){return this.groups.indexOf(t)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let t in this.attrs)if(this.attrs[t].isRequired)return!0;return!1}compatibleContent(t){return this==t||this.contentMatch.compatible(t.contentMatch)}computeAttrs(t){return!t&&this.defaultAttrs?this.defaultAttrs:H(this.attrs,t)}create(t=null,e,i){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new $(this,this.computeAttrs(t),u.from(e),d.setFrom(i))}createChecked(t=null,e,i){return e=u.from(e),this.checkContent(e),new $(this,this.computeAttrs(t),e,d.setFrom(i))}createAndFill(t=null,e,i){if(t=this.computeAttrs(t),(e=u.from(e)).size){let t=this.contentMatch.fillBefore(e);if(!t)return null;e=t.append(e)}let s=this.contentMatch.matchFragment(e),r=s&&s.fillBefore(u.empty,!0);return r?new $(this,t,e.append(r),d.setFrom(i)):null}validContent(t){let e=this.contentMatch.matchFragment(t);if(!e||!e.validEnd)return!1;for(let e=0;e<t.childCount;e++)if(!this.allowsMarks(t.child(e).marks))return!1;return!0}checkContent(t){if(!this.validContent(t))throw new RangeError(`Invalid content for node ${this.name}: ${t.toString().slice(0,50)}`)}checkAttrs(t){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:d.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 q{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 K{constructor(t,e,i,s){this.name=t,this.rank=e,this.schema=i,this.spec=s,this.attrs=V(t,s.attrs),this.excluded=null;let r=X(this.attrs);this.instance=r?new d(this,r):null}create(t=null){return!t&&this.instance?this.instance:new d(this,H(this.attrs,t))}static compile(t,e){let i=Object.create(null),s=0;return t.forEach(((t,r)=>i[t]=new K(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}}let G=class{constructor(t){this.linebreakReplacement=null,this.cached=Object.create(null);let e=this.spec={};for(let i in t)e[i]=t[i];e.nodes=o.from(t.nodes),e.marks=o.from(t.marks||{}),this.nodes=Q.compile(this.spec.nodes,this),this.marks=K.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]=j.parse(s,this.nodes)),e.inlineContent=e.contentMatch.inlineContent,e.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!e.isInline||!e.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=e}e.markSet="_"==r?null:r?Z(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?[]:Z(this,i.split(" "))}this.nodeFromJSON=t=>$.fromJSON(this,t),this.markFromJSON=t=>d.fromJSON(this,t),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(t,e=null,i,s){if("string"==typeof t)t=this.nodeType(t);else{if(!(t instanceof Q))throw new RangeError("Invalid node type: "+t);if(t.schema!=this)throw new RangeError("Node type from different schema used ("+t.name+")")}return t.createChecked(e,i,s)}text(t,e){let i=this.nodes.text;return new R(i,i.defaultAttrs,t,d.setFrom(e))}mark(t,e){return"string"==typeof t&&(t=this.marks[t]),t.create(e)}nodeType(t){let e=this.nodes[t];if(!e)throw new RangeError("Unknown node type: "+t);return e}};function Z(t,e){let i=[];for(let s=0;s<e.length;s++){let 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}let tt=class t{constructor(t,e){this.schema=t,this.rules=e,this.tags=[],this.styles=[];let i=this.matchedStyles=[];e.forEach((t=>{if(function(t){return null!=t.tag}(t))this.tags.push(t);else if(function(t){return null!=t.style}(t)){let e=/[^=]*/.exec(t.style)[0];i.indexOf(e)<0&&i.push(e),this.styles.push(t)}})),this.normalizeLists=!this.tags.some((e=>{if(!/^(ul|ol)\b/.test(e.tag)||!e.node)return!1;let i=t.nodes[e.node];return i.contentMatch.matchType(i)}))}parse(t,e={}){let i=new ot(this,e,!1);return i.addAll(t,d.none,e.from,e.to),i.finish()}parseSlice(t,e={}){let i=new ot(this,e,!0);return i.addAll(t,d.none,e.from,e.to),w.maxOpen(i.finish())}matchTag(t,e,i){for(let s=i?this.tags.indexOf(i)+1:0;s<this.tags.length;s++){let i=this.tags[s];if(ht(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=lt(t)),t.mark||t.ignore||t.clearMark||(t.mark=e)}))}for(let e in t.nodes){let s=t.nodes[e].spec.parseDOM;s&&s.forEach((t=>{i(t=lt(t)),t.node||t.ignore||t.mark||(t.node=e)}))}return e}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new t(e,t.schemaRules(e)))}};const et={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},it={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},st={ol:!0,ul:!0};function rt(t,e,i){return null!=e?(e?1:0)|("full"===e?2:0):t&&"pre"==t.whitespace?3:-5&i}class nt{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=d.none,this.match=r||(4&n?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let e=this.type.contentMatch.fillBefore(u.from(t));if(!e){let e,i=this.type.contentMatch;return(e=i.findWrapping(t.type))?(this.match=i,e):null}this.match=this.type.contentMatch.matchFragment(e)}return this.match.findWrapping(t.type)}finish(t){if(!(1&this.options)){let t,e=this.content[this.content.length-1];if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let i=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=i.withText(i.text.slice(0,i.text.length-t[0].length))}}let e=u.from(this.content);return!t&&this.match&&(e=e.append(this.match.fillBefore(u.empty,!0))),this.type?this.type.create(this.attrs,e,this.marks):e}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!et.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class ot{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=rt(null,e.preserveWhitespace,0)|(i?4:0);s=r?new nt(r.type,r.attrs,d.none,!0,e.topMatch||r.type.contentMatch,n):new nt(i?null:t.schema.topNodeType,null,d.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();st.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&&st.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:it.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(et.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=d.none;for(let r of s.concat(t.marks))(e.type?e.type.allowsMarkType(r.type):ut(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=rt(t,r,n.options);4&n.options&&0==n.content.length&&(o|=4);let h=d.none;return i=i.filter((e=>!(n.type?n.type.allowsMarkType(e.type):ut(e.type,t))||(h=e.addToSet(h),!1))),this.nodes.push(new nt(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 ht(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function lt(t){let e={};for(let i in t)e[i]=t[i];return e}function ut(t,e){let i=e.schema.nodes;for(let s in i){let 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 at{constructor(t,e){this.nodes=t,this.marks=e}serializeFragment(t,e={},i){i||(i=ft(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}=pt(ft(e),this.nodes[t.type.name](t),null,t.attrs);if(s){if(t.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(t.content,e,s)}return i}serializeNode(t,e={}){let i=this.serializeNodeInner(t,e);for(let s=t.marks.length-1;s>=0;s--){let 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&&pt(ft(i),s(t,e),null,t.attrs)}static renderSpec(t,e,i=null,s){return pt(t,e,i,s)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new at(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(t){let e=ct(t.nodes);return e.text||(e.text=t=>t.text),e}static marksFromSchema(t){return ct(t.marks)}}function ct(t){let e={};for(let i in t){let s=t[i].spec.toDOM;s&&(e[i]=s)}return e}function ft(t){return t.document||window.document}const dt=new WeakMap;function pt(t,e,i,s){if("string"==typeof e)return{dom:t.createTextNode(e)};if(null!=e.nodeType)return{dom:e};if(e.dom&&null!=e.dom.nodeType)return e;let r,n=e[0];if("string"!=typeof n)throw new RangeError("Invalid array passed to renderSpec");if(s&&(r=function(t){let e=dt.get(t);return void 0===e&&dt.set(t,e=function(t){let e=null;return function t(i){if(i&&"object"==typeof i)if(Array.isArray(i))if("string"==typeof i[0])e||(e=[]),e.push(i);else for(let e=0;e<i.length;e++)t(i[e]);else for(let e in i)t(i[e])}(t),e}(t)),e}(s))&&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),u=e[1],a=1;if(u&&"object"==typeof u&&null==u.nodeType&&!Array.isArray(u)){a=2;for(let t in u)if(null!=u[t]){let e=t.indexOf(" ");e>0?l.setAttributeNS(t.slice(0,e),t.slice(e+1),u[t]):"style"==t&&l.style?l.style.cssText=u[t]:l.setAttribute(t,u[t])}}for(let r=a;r<e.length;r++){let n=e[r];if(0===n){if(r<e.length-1||r>a)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}{let{dom:e,contentDOM:r}=pt(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 wt=Math.pow(2,16);function gt(t){return 65535&t}class mt{constructor(t,e,i){this.pos=t,this.delInfo=e,this.recover=i}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class vt{constructor(t,e=!1){if(this.ranges=t,this.inverted=e,!t.length&&vt.empty)return vt.empty}recover(t){let e=0,i=gt(t);if(!this.inverted)for(let t=0;t<i;t++)e+=this.ranges[3*t+2]-this.ranges[3*t+1];return this.ranges[3*i]+e+function(t){return(t-(65535&t))/wt}(t)}mapResult(t,e=1){return this._map(t,e,!1)}map(t,e=1){return this._map(t,e,!0)}_map(t,e,i){let s=0,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],u=this.ranges[o+n],a=h+l;if(t<=a){let r=h+s+((l?t==h?-1:t==a?1:e:e)<0?0:u);if(i)return r;let n=t==h?2:t==a?1:4;return(e<0?t!=h:t!=a)&&(n|=8),new mt(r,n,t==(e<0?h:a)?null:o/3+(t-h)*wt)}s+=u-l}return i?t+s:new mt(t+s,0,null)}touches(t,e){let i=0,s=gt(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],u=this.ranges[s+i];t(o,o+l,h,h+u),r+=u-l}}invert(){return new vt(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return 0==t?vt.empty:new vt(t<0?[0,-t,0]:[0,0,t])}}vt.empty=new vt([]);class yt{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 yt(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 yt;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 mt(t,s,null)}}const bt=Object.create(null);class kt{getMap(){return vt.empty}merge(t){return null}static fromJSON(t,e){if(!e||!e.stepType)throw new RangeError("Invalid input for Step.fromJSON");let i=bt[e.stepType];if(!i)throw new RangeError(`No step type ${e.stepType} defined`);return i.fromJSON(t,e)}static jsonID(t,e){if(t in bt)throw new RangeError("Duplicate use of step JSON ID "+t);return bt[t]=e,e.prototype.jsonID=t,e}}class Mt{constructor(t,e){this.doc=t,this.failed=e}static ok(t){return new Mt(t,null)}static fail(t){return new Mt(null,t)}static fromReplace(t,e,i,s){try{return Mt.ok(t.replace(e,i,s))}catch(t){if(t instanceof p)return Mt.fail(t.message);throw t}}}function xt(t,e,i){let s=[];for(let r=0;r<t.childCount;r++){let n=t.child(r);n.content.size&&(n=n.copy(xt(n.content,e,n))),n.isInline&&(n=e(n,i,r)),s.push(n)}return u.fromArray(s)}class At extends kt{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 w(xt(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 Mt.fromReplace(t,this.from,this.to,r)}invert(){return new Ct(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 At(e.pos,i.pos,this.mark)}merge(t){return t instanceof At&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new At(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 At(e.from,e.to,t.markFromJSON(e.mark))}}kt.jsonID("addMark",At);class Ct extends kt{constructor(t,e,i){super(),this.from=t,this.to=e,this.mark=i}apply(t){let e=t.slice(this.from,this.to),i=new w(xt(e.content,(t=>t.mark(this.mark.removeFromSet(t.marks))),t),e.openStart,e.openEnd);return Mt.fromReplace(t,this.from,this.to,i)}invert(){return new At(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 Ct(e.pos,i.pos,this.mark)}merge(t){return t instanceof Ct&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new Ct(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 Ct(e.from,e.to,t.markFromJSON(e.mark))}}kt.jsonID("removeMark",Ct);class St extends kt{constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return Mt.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.addToSet(e.marks));return Mt.fromReplace(t,this.pos,this.pos+1,new w(u.from(i),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);if(e){let t=this.mark.addToSet(e.marks);if(t.length==e.marks.length){for(let i=0;i<e.marks.length;i++)if(!e.marks[i].isInSet(t))return new St(this.pos,e.marks[i]);return new St(this.pos,this.mark)}}return new Bt(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new St(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 St(e.pos,t.markFromJSON(e.mark))}}kt.jsonID("addNodeMark",St);class Bt extends kt{constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return Mt.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.removeFromSet(e.marks));return Mt.fromReplace(t,this.pos,this.pos+1,new w(u.from(i),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);return e&&this.mark.isInSet(e.marks)?new St(this.pos,this.mark):this}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Bt(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 Bt(e.pos,t.markFromJSON(e.mark))}}kt.jsonID("removeNodeMark",Bt);class Ot extends kt{constructor(t,e,i,s=!1){super(),this.from=t,this.to=e,this.slice=i,this.structure=s}apply(t){return this.structure&&Et(t,this.from,this.to)?Mt.fail("Structure replace would overwrite content"):Mt.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new vt([this.from,this.to-this.from,this.slice.size])}invert(t){return new Ot(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);return e.deletedAcross&&i.deletedAcross?null:new Ot(e.pos,Math.max(e.pos,i.pos),this.slice,this.structure)}merge(t){if(!(t instanceof Ot)||t.structure||this.structure)return null;if(this.from+this.slice.size!=t.from||this.slice.openEnd||t.slice.openStart){if(t.to!=this.from||this.slice.openStart||t.slice.openEnd)return null;{let e=this.slice.size+t.slice.size==0?w.empty:new w(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new Ot(t.from,this.to,e,this.structure)}}{let e=this.slice.size+t.slice.size==0?w.empty:new w(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new Ot(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 Ot(e.from,e.to,w.fromJSON(t,e.slice),!!e.structure)}}kt.jsonID("replace",Ot);class Tt extends kt{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&&(Et(t,this.from,this.gapFrom)||Et(t,this.gapTo,this.to)))return Mt.fail("Structure gap-replace would overwrite content");let e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return Mt.fail("Gap is not a flat range");let i=this.slice.insertAt(this.insert,e.content);return i?Mt.fromReplace(t,this.from,this.to,i):Mt.fail("Content does not fit in gap")}getMap(){return new vt([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let e=this.gapTo-this.gapFrom;return new Tt(this.from,this.from+this.slice.size+e,this.from+this.insert,this.from+this.insert+e,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1),s=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1),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 Tt(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 Tt(e.from,e.to,e.gapFrom,e.gapTo,w.fromJSON(t,e.slice),e.insert,!!e.structure)}}function Et(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 Dt(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,c=s.matchType(l.type);if(c){s=c;for(let e=0;e<l.marks.length;e++)i.allowsMarkType(l.marks[e].type)||t.step(new Ct(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 w(u.from(i.schema.text(" ",i.allowedMarks(l.marks))),0,0)),o.push(new Ot(h+t.index,h+t.index+t[0].length,e))}}else o.push(new Ot(h,a,w.empty));h=a}if(!s.validEnd){let e=s.fillBefore(u.empty,!0);t.replace(h,h,new w(e,0,0))}for(let e=o.length-1;e>=0;e--)t.step(o[e])}function It(t,e,i){return(0==e||t.canReplace(e,t.childCount))&&(i==t.childCount||t.canReplace(0,i))}function $t(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||!It(n,o,h))break;o&&(s=1),h<n.childCount&&(r=1)}return null}function Rt(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 Pt(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 jt(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 Nt(t,e,i=e,s=w.empty){if(e==i&&!s.size)return null;let r=t.resolve(e),n=t.resolve(i);return Ft(r,n,s)?new Ot(e,i,s):new _t(r,n,s).fit()}function Ft(t,e,i){return!i.openStart&&!i.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),i.content)}kt.jsonID("replaceAround",Tt);class _t{constructor(t,e,i){this.$from=t,this.$to=e,this.unplaced=i,this.frontier=[],this.placed=u.empty;for(let e=0;e<=t.depth;e++){let i=t.node(e);this.frontier.push({type:i.type,match:i.contentMatchAt(t.indexAfter(e))})}for(let e=t.depth;e>0;e--)this.placed=u.from(t.node(e).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let t=this.findFittable();t?this.placeNodes(t):this.openMore()||this.dropNode()}let t=this.mustMoveInline(),e=this.placed.size-this.depth-this.$from.depth,i=this.$from,s=this.close(t<0?this.$to:i.doc.resolve(t));if(!s)return null;let r=this.placed,n=i.depth,o=s.depth;for(;n&&o&&1==r.childCount;)r=r.firstChild.content,n--,o--;let h=new w(r,n,o);return t>-1?new Tt(i.pos,t,this.$to.pos,this.$to.end(),h,e):h.size||i.pos!=this.$to.pos?new Ot(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(u.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 w(t,e+1,Math.max(i,s.size+e>=t.size-i?e+1:0)),0))}dropNode(){let{content:t,openStart:e,openEnd:i}=this.unplaced,s=Yt(t,e);if(s.childCount<=1&&e>0){let r=t.size-e<=e+s.size;this.unplaced=new w(Lt(t,e-1,1),e-1,r?e-1:i)}else this.unplaced=new w(Lt(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:c,type:f}=this.frontier[e];if(s){for(let t=0;t<s.childCount;t++)a.push(s.child(t));c=c.matchFragment(s)}let d=o.size+t-(n.content.size-n.openEnd);for(;l<o.childCount;){let t=o.child(l),e=c.matchType(t.type);if(!e)break;l++,(l>1||0==h||t.content.size)&&(c=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=zt(this.placed,e,u.from(a)),this.frontier[e].match=c,p&&d<0&&i&&i.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let t=0,e=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?w.empty:new w(Lt(n.content,t-1,1),t-1,d<0?n.openEnd:t-1):new w(Lt(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||!Xt(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:i}=this.$to,s=this.$to.after(i);for(;i>1&&s==this.$to.end(--i);)++s;return s}findCloseLevel(t){t:for(let e=Math.min(this.depth,t.depth);e>=0;e--){let{match:i,type:s}=this.frontier[e],r=e<t.depth&&t.end(e+1)==t.pos+(t.depth-(e+1)),n=Xt(t,e,s,i,r);if(n){for(let i=e-1;i>=0;i--){let{match:e,type:s}=this.frontier[i],r=Xt(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=zt(this.placed,e.depth,e.fit)),t=e.move;for(let i=e.depth+1;i<=t.depth;i++){let e=t.node(i),s=e.type.contentMatch.fillBefore(e.content,!0,t.index(i));this.openFrontierNode(e.type,e.attrs,s)}return t}openFrontierNode(t,e=null,i){let s=this.frontier[this.depth];s.match=s.match.matchType(t),this.placed=zt(this.placed,this.depth,u.from(t.create(e,i))),this.frontier.push({type:t,match:t.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(u.empty,!0);t.childCount&&(this.placed=zt(this.placed,this.frontier.length,t))}}function Lt(t,e,i){return 0==e?t.cutByIndex(i,t.childCount):t.replaceChild(0,t.firstChild.copy(Lt(t.firstChild.content,e-1,i)))}function zt(t,e,i){return 0==e?t.append(i):t.replaceChild(t.childCount-1,t.lastChild.copy(zt(t.lastChild.content,e-1,i)))}function Yt(t,e){for(let i=0;i<e;i++)t=t.firstChild.content;return t}function Wt(t,e,i){if(e<=0)return t;let s=t.content;return e>1&&(s=s.replaceChild(0,Wt(s.firstChild,e-1,1==s.childCount?i-1:0))),e>0&&(s=t.type.contentMatch.fillBefore(s).append(s),i<=0&&(s=s.append(t.type.contentMatch.matchFragment(s).fillBefore(u.empty,!0)))),t.copy(s)}function Xt(t,e,i,s,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 Ht(t,e,i,s,r){if(e<i){let r=t.firstChild;t=t.replaceChild(0,r.copy(Ht(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(u.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 Vt extends kt{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 Mt.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 Mt.fromReplace(t,this.pos,this.pos+1,new w(u.from(s),0,e.isLeaf?0:1))}getMap(){return vt.empty}invert(t){return new Vt(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Vt(e.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,e){if("number"!=typeof e.pos||"string"!=typeof e.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new Vt(e.pos,e.attr,e.value)}}kt.jsonID("attr",Vt);class Qt extends kt{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 Mt.ok(i)}getMap(){return vt.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)}}kt.jsonID("docAttr",Qt);let qt=class extends Error{};qt=function t(e){let i=Error.call(this,e);return i.__proto__=t.prototype,i},(qt.prototype=Object.create(Error.prototype)).constructor=qt,qt.prototype.name="TransformError";class Kt{constructor(t){this.doc=t,this.steps=[],this.docs=[],this.mapping=new yt}get before(){return this.docs.length?this.docs[0]:this.doc}step(t){let e=this.maybeStep(t);if(e.failed)throw new qt(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=w.empty){let s=Nt(this.doc,t,e,i);return s&&this.step(s),this}replaceWith(t,e,i){return this.replace(t,e,new w(u.from(i),0,0))}delete(t,e){return this.replace(t,e,w.empty)}insert(t,e){return this.replaceWith(t,t,e)}replaceRange(t,e,i){return function(t,e,i,s){if(!s.size)return t.deleteRange(e,i);let r=t.doc.resolve(e),n=t.doc.resolve(i);if(Ft(r,n,s))return t.step(new Ot(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),u=[],a=s.openStart;for(let t=s.content,e=0;;e++){let i=t.firstChild;if(u.push(i),e==s.openStart)break;t=i.content}for(let t=a-1;t>=0;t--){let e=u[t],i=(c=e.type).spec.defining||c.spec.definingForContent;if(i&&!e.sameMarkup(r.node(Math.abs(h)-1)))a=t;else if(i||!e.type.isTextblock)break}var c;for(let e=s.openStart;e>=0;e--){let h=(e+a+1)%(s.openStart+1),c=u[h];if(c)for(let e=0;e<o.length;e++){let u=o[(e+l)%o.length],a=!0;u<0&&(a=!1,u=-u);let f=r.node(u-1),d=r.index(u-1);if(f.canReplaceWith(d,d,c.type,c.marks))return t.replace(r.before(u),a?n.after(u):i,new w(Ht(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 w(u.from(s),0,0))}(this,t,e,i),this}deleteRange(t,e){return function(t,e,i){let s=t.doc.resolve(e),r=t.doc.resolve(i),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,c=u.empty,f=0;for(let t=n,e=!1;t>i;t--)e||s.index(t)>0?(e=!0,c=u.from(s.node(t).copy(c)),f++):l--;let d=u.empty,p=0;for(let t=n,e=!1;t>i;t--)e||r.after(t+1)<r.end(t)?(e=!0,d=u.from(r.node(t).copy(d)),p++):a++;t.step(new Tt(l,a,o,h,new w(c.append(d),f,p),c.size-f,!0))}(this,t,e),this}join(t,e=1){return function(t,e,i){let s=null,{linebreakReplacement: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);Pt(t,s.node(),s.before(),h)}o.inlineContent&&Dt(t,e+i-1,o,n.node().contentMatchAt(n.index()),null==s);let l=t.mapping.slice(h),u=l.map(e-i);if(t.step(new Ot(u,l.map(e+i,-1),w.empty,!0)),!0===s){let e=t.doc.resolve(u);Rt(t,e.node(),e.before(),t.steps.length)}}(this,t,e),this}wrap(t,e){return function(t,e,i){let s=u.empty;for(let t=i.length-1;t>=0;t--){if(s.size){let e=i[t].type.contentMatch.matchFragment(s);if(!e||!e.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}s=u.from(i[t].type.create(i[t].attrs,s))}let r=e.start,n=e.end;t.step(new Tt(r,n,r,n,new w(s,0,0),i.length,!0))}(this,t,e),this}setBlockType(t,e=t,i,s=null){return function(t,e,i,s,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&&Pt(t,e,i,n),Dt(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 Tt(l,a,l+1,a-1,new w(u.from(s.create(o,null,e.marks)),0,0),1,!0)),!0===r&&Rt(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 Tt(e,e+n.nodeSize,e+1,e+n.nodeSize-1,new w(u.from(o),0,0),1,!0))}(this,t,e,i,s),this}setNodeAttribute(t,e,i){return this.step(new Vt(t,e,i)),this}setDocAttribute(t,e){return this.step(new Qt(t,e)),this}addNodeMark(t,e){return this.step(new St(t,e)),this}removeNodeMark(t,e){let i=this.doc.nodeAt(t);if(!i)throw new RangeError("No node at position "+t);if(e instanceof d)e.isInSet(i.marks)&&this.step(new Bt(t,e));else{let s,r=i.marks,n=[];for(;s=e.isInSet(r);)n.push(new Bt(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=u.empty,o=u.empty;for(let t=r.depth,e=r.depth-i,h=i-1;t>e;t--,h--){n=u.from(r.node(t).copy(n));let e=s&&s[h];o=u.from(e?e.type.create(e.attrs,o):r.node(t).copy(o))}t.step(new Ot(e,e,new w(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,u)=>{if(!t.isInline)return;let a=t.marks;if(!s.isInSet(a)&&u.type.allowsMarkType(s.type)){let u=Math.max(l,e),c=Math.min(l+t.nodeSize,i),f=s.addToSet(a);for(let t=0;t<a.length;t++)a[t].isInSet(f)||(r&&r.to==u&&r.mark.eq(a[t])?r.to=c:o.push(r=new Ct(u,c,a[t])));n&&n.to==u?n.to=c:h.push(n=new At(u,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 K){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 Ct(e.from,e.to,e.style))))}(this,t,e,i),this}clearIncompatible(t,e,i){return Dt(this,t,e,i),this}}const Gt=Object.create(null);class Zt{constructor(t,e,i){this.$anchor=t,this.$head=e,this.ranges=i||[new te(t.min(e),t.max(e))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let t=this.ranges;for(let e=0;e<t.length;e++)if(t[e].$from.pos!=t[e].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,e=w.empty){let i=e.content.lastChild,s=null;for(let t=0;t<e.openEnd;t++)s=i,i=i.lastChild;let r=t.steps.length,n=this.ranges;for(let o=0;o<n.length;o++){let{$from:h,$to:l}=n[o],u=t.mapping.slice(r);t.replaceRange(u.map(h.pos),u.map(l.pos),o?w.empty:e),0==o&&ae(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),u=h.map(o.pos);r?t.deleteRange(l,u):(t.replaceRangeWith(l,u,e),ae(t,i,e.isInline?-1:1))}}static findFrom(t,e,i=!1){let s=t.parent.inlineContent?new se(t):ue(t.node(0),t.parent,t.pos,t.index(),e,i);if(s)return s;for(let s=t.depth-1;s>=0;s--){let r=e<0?ue(t.node(0),t.node(s),t.before(s+1),t.index(s),e,i):ue(t.node(0),t.node(s),t.after(s+1),t.index(s)+1,e,i);if(r)return r}return null}static near(t,e=1){return this.findFrom(t,e)||this.findFrom(t,-e)||new he(t.node(0))}static atStart(t){return ue(t,t,0,0,1)||new he(t)}static atEnd(t){return ue(t,t,t.content.size,t.childCount,-1)||new he(t)}static fromJSON(t,e){if(!e||!e.type)throw new RangeError("Invalid input for Selection.fromJSON");let i=Gt[e.type];if(!i)throw new RangeError(`No selection type ${e.type} defined`);return i.fromJSON(t,e)}static jsonID(t,e){if(t in Gt)throw new RangeError("Duplicate use of selection JSON ID "+t);return Gt[t]=e,e.prototype.jsonID=t,e}getBookmark(){return se.between(this.$anchor,this.$head).getBookmark()}}Zt.prototype.visible=!0;class te{constructor(t,e){this.$from=t,this.$to=e}}let ee=!1;function ie(t){ee||t.parent.inlineContent||(ee=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class se extends Zt{constructor(t,e=t){ie(t),ie(e),super(t,e)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,e){let i=t.resolve(e.map(this.head));if(!i.parent.inlineContent)return Zt.near(i);let s=t.resolve(e.map(this.anchor));return new se(s.parent.inlineContent?s:i,i)}replace(t,e=w.empty){if(super.replace(t,e),e==w.empty){let e=this.$from.marksAcross(this.$to);e&&t.ensureMarks(e)}}eq(t){return t instanceof se&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new re(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,e){if("number"!=typeof e.anchor||"number"!=typeof e.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new se(t.resolve(e.anchor),t.resolve(e.head))}static create(t,e,i=e){let s=t.resolve(e);return new this(s,i==e?s:t.resolve(i))}static between(t,e,i){let s=t.pos-e.pos;if(i&&!s||(i=s>=0?1:-1),!e.parent.inlineContent){let t=Zt.findFrom(e,i,!0)||Zt.findFrom(e,-i,!0);if(!t)return Zt.near(e,i);e=t.$head}return t.parent.inlineContent||(0==s||(t=(Zt.findFrom(t,-i,!0)||Zt.findFrom(t,i,!0)).$anchor).pos<e.pos!=s<0)&&(t=e),new se(t,e)}}Zt.jsonID("text",se);class re{constructor(t,e){this.anchor=t,this.head=e}map(t){return new re(t.map(this.anchor),t.map(this.head))}resolve(t){return se.between(t.resolve(this.anchor),t.resolve(this.head))}}class ne extends Zt{constructor(t){let e=t.nodeAfter,i=t.node(0).resolve(t.pos+e.nodeSize);super(t,i),this.node=e}map(t,e){let{deleted:i,pos:s}=e.mapResult(this.anchor),r=t.resolve(s);return i?Zt.near(r):new ne(r)}content(){return new w(u.from(this.node),0,0)}eq(t){return t instanceof ne&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new oe(this.anchor)}static fromJSON(t,e){if("number"!=typeof e.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new ne(t.resolve(e.anchor))}static create(t,e){return new ne(t.resolve(e))}static isSelectable(t){return!t.isText&&!1!==t.type.spec.selectable}}ne.prototype.visible=!1,Zt.jsonID("node",ne);class oe{constructor(t){this.anchor=t}map(t){let{deleted:e,pos:i}=t.mapResult(this.anchor);return e?new re(i,i):new oe(i)}resolve(t){let e=t.resolve(this.anchor),i=e.nodeAfter;return i&&ne.isSelectable(i)?new ne(e):Zt.near(e)}}class he extends Zt{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,e=w.empty){if(e==w.empty){t.delete(0,t.doc.content.size);let e=Zt.atStart(t.doc);e.eq(t.selection)||t.setSelection(e)}else super.replace(t,e)}toJSON(){return{type:"all"}}static fromJSON(t){return new he(t)}map(t){return new he(t)}eq(t){return t instanceof he}getBookmark(){return le}}Zt.jsonID("all",he);const le={map(){return this},resolve:t=>new he(t)};function ue(t,e,i,s,r,n=!1){if(e.inlineContent)return se.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&&ne.isSelectable(s))return ne.create(t,i-(r<0?s.nodeSize:0))}else{let e=ue(t,s,i+r,r<0?s.childCount:0,r,n);if(e)return e}i+=s.nodeSize*r}return null}function ae(t,e,i){let s=t.steps.length-1;if(s<e)return;let r,n=t.steps[s];(n instanceof Ot||n instanceof Tt)&&(t.mapping.maps[s].forEach(((t,e,i,s)=>{null==r&&(r=s)})),t.setSelection(Zt.near(t.doc.resolve(r),i)))}let ce=class extends Kt{constructor(t){super(t.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=t.selection,this.storedMarks=t.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(t){if(t.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=t,this.curSelectionFor=this.steps.length,this.updated=-3&this.updated|1,this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(t){return this.storedMarks=t,this.updated|=2,this}ensureMarks(t){return d.sameSet(this.storedMarks||this.selection.$from.marks(),t)||this.setStoredMarks(t),this}addStoredMark(t){return this.ensureMarks(t.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(t){return this.ensureMarks(t.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(2&this.updated)>0}addStep(t,e){super.addStep(t,e),this.updated=-3&this.updated,this.storedMarks=null}setTime(t){return this.time=t,this}replaceSelection(t){return this.selection.replace(this,t),this}replaceSelectionWith(t,e=!0){let i=this.selection;return e&&(t=t.mark(this.storedMarks||(i.empty?i.$from.marks():i.$from.marksAcross(i.$to)||d.none))),i.replaceWith(this,t),this}deleteSelection(){return this.selection.replace(this),this}insertText(t,e,i){let s=this.doc.type.schema;if(null==e)return t?this.replaceSelectionWith(s.text(t),!0):this.deleteSelection();{if(null==i&&(i=e),!t)return this.deleteRange(e,i);let 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(Zt.near(this.selection.$to)),this}}setMeta(t,e){return this.meta["string"==typeof t?t:t.key]=e,this}getMeta(t){return this.meta["string"==typeof t?t:t.key]}get isGeneric(){for(let t in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}};function fe(t,e){return e&&t?t.bind(e):t}class de{constructor(t,e,i){this.name=t,this.init=fe(e.init,i),this.apply=fe(e.apply,i)}}const pe=[new de("doc",{init:t=>t.doc||t.schema.topNodeType.createAndFill(),apply:t=>t.doc}),new de("selection",{init:(t,e)=>t.selection||Zt.atStart(e.doc),apply:t=>t.selection}),new de("storedMarks",{init:t=>t.storedMarks||null,apply:(t,e,i,s)=>s.selection.$cursor?t.storedMarks:null}),new de("scrollToSelection",{init:()=>0,apply:(t,e)=>t.scrolledIntoView?e+1:e})];class we{constructor(t,e){this.schema=t,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=pe.slice(),e&&e.forEach((t=>{if(this.pluginsByKey[t.key])throw new RangeError("Adding different instances of a keyed plugin ("+t.key+")");this.plugins.push(t),this.pluginsByKey[t.key]=t,t.spec.state&&this.fields.push(new de(t.key,t.spec.state,t))}))}}class ge{constructor(t){this.config=t}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(t){return this.applyTransaction(t).state}filterTransaction(t,e=-1){for(let i=0;i<this.config.plugins.length;i++)if(i!=e){let e=this.config.plugins[i];if(e.spec.filterTransaction&&!e.spec.filterTransaction.call(e,t,this))return!1}return!0}applyTransaction(t){if(!this.filterTransaction(t))return{state:this,transactions:[]};let e=[t],i=this.applyInner(t),s=null;for(;;){let 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,u=h<e.length&&o.spec.appendTransaction.call(o,h?e.slice(h):e,l,i);if(u&&i.filterTransaction(u,n)){if(u.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(u),i=i.applyInner(u),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 ge(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 ce(this)}static create(t){let e=new we(t.doc?t.doc.type.schema:t.schema,t.plugins),i=new ge(e);for(let s=0;s<e.fields.length;s++)i[e.fields[s].name]=e.fields[s].init(t,i);return i}reconfigure(t){let e=new we(this.schema,t.plugins),i=e.fields,s=new ge(e);for(let e=0;e<i.length;e++){let 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 we(t.schema,t.plugins),r=new ge(s);return s.fields.forEach((s=>{if("doc"==s.name)r.doc=$.fromJSON(t.schema,e.doc);else if("selection"==s.name)r.selection=Zt.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 me(t,e,i){for(let s in t){let r=t[s];r instanceof Function?r=r.bind(e):"handleDOMEvents"==s&&(r=me(r,e,{})),i[s]=r}return i}class ve{constructor(t){var e;this.spec=t,this.props={},t.props&&me(t.props,this,this.props),this.key=t.key?t.key.key:(e="plugin")in ye?e+"$"+ ++ye[e]:(ye[e]=0,e+"$")}getState(t){return t[this.key]}}const ye=Object.create(null),be=function(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e},ke=function(t){let e=t.assignedSlot||t.parentNode;return e&&11==e.nodeType?e.host:e};let Me=null;const xe=function(t,e,i){let s=Me||(Me=document.createRange());return s.setEnd(t,null==i?t.nodeValue.length:i),s.setStart(t,e||0),s},Ae=function(t,e,i,s){return i&&(Se(t,e,i,s,-1)||Se(t,e,i,s,1))},Ce=/^(img|br|input|textarea|hr)$/i;function Se(t,e,i,s,r){for(var n;;){if(t==i&&e==s)return!0;if(e==(r<0?0:Be(t))){let i=t.parentNode;if(!i||1!=i.nodeType||Oe(t)||Ce.test(t.nodeName)||"false"==t.contentEditable)return!1;e=be(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?Be(t):0}}}}function Be(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function Oe(t){let e;for(let i=t;i&&!(e=i.pmViewDesc);i=i.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const Te=function(t){return t.focusNode&&Ae(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function Ee(t,e){let i=document.createEvent("Event");return i.initEvent("keydown",!0,!0),i.keyCode=t,i.key=i.code=e,i}const De="undefined"!=typeof navigator?navigator:null,Ie="undefined"!=typeof document?document:null,$e=De&&De.userAgent||"",Re=/Edge\/(\d+)/.exec($e),Pe=/MSIE \d/.exec($e),je=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec($e),Ue=!!(Pe||je||Re),Ne=Pe?document.documentMode:je?+je[1]:Re?+Re[1]:0,Fe=!Ue&&/gecko\/(\d+)/i.test($e),_e=!Ue&&/Chrome\/(\d+)/.exec($e),Le=!!_e,ze=_e?+_e[1]:0,Ye=!Ue&&!!De&&/Apple Computer/.test(De.vendor),We=Ye&&(/Mobile\/\w+/.test($e)||!!De&&De.maxTouchPoints>2),Xe=We||!!De&&/Mac/.test(De.platform),He=!!De&&/Win/.test(De.platform),Je=/Android \d/.test($e),Ve=!!Ie&&"webkitFontSmoothing"in Ie.documentElement.style,Qe=Ve?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function qe(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 Ke(t,e){return"number"==typeof t?t:t[e]}function Ge(t){let e=t.getBoundingClientRect();return{left:e.left,right:e.left+t.clientWidth*(e.width/t.offsetWidth||1),top:e.top,bottom:e.top+t.clientHeight*(e.height/t.offsetHeight||1)}}function Ze(t,e,i){let s=t.someProp("scrollThreshold")||0,r=t.someProp("scrollMargin")||5,n=t.dom.ownerDocument;for(let o=i||t.dom;o;){if(1!=o.nodeType){o=ke(o);continue}let t=o,i=t==n.body,h=i?qe(n):Ge(t),l=0,u=0;if(e.top<h.top+Ke(s,"top")?u=-(h.top-e.top+Ke(r,"top")):e.bottom>h.bottom-Ke(s,"bottom")&&(u=e.bottom-e.top>h.bottom-h.top?e.top+Ke(r,"top")-h.top:e.bottom-h.bottom+Ke(r,"bottom")),e.left<h.left+Ke(s,"left")?l=-(h.left-e.left+Ke(r,"left")):e.right>h.right-Ke(s,"right")&&(l=e.right-h.right+Ke(r,"right")),l||u)if(i)n.defaultView.scrollBy(l,u);else{let i=t.scrollLeft,s=t.scrollTop;u&&(t.scrollTop+=u),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 a=i?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(a))break;o="absolute"==a?o.offsetParent:ke(o)}}function ti(t){let e=[],i=t.ownerDocument;for(let s=t;s&&(e.push({dom:s,top:s.scrollTop,left:s.scrollLeft}),t!=i);s=ke(s));return e}function ei(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 ii=null;function si(t,e){let i,s,r,n,o=2e8,h=0,l=e.top,u=e.top;for(let a=t.firstChild,c=0;a;a=a.nextSibling,c++){let t;if(1==a.nodeType)t=a.getClientRects();else{if(3!=a.nodeType)continue;t=xe(a).getClientRects()}for(let f=0;f<t.length;f++){let d=t[f];if(d.top<=l&&d.bottom>=u){l=Math.max(d.bottom,l),u=Math.min(d.top,u);let t=d.left>e.left?d.left-e.left:d.right<e.left?e.left-d.right:0;if(t<o){i=a,o=t,s=t&&3==i.nodeType?{left:d.right<e.left?d.right:d.left,top:e.top}:e,1==a.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=a,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=li(r,1);if(s.top!=s.bottom&&ri(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}:si(i,s)}function ri(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function ni(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(ri(e,r))return ni(i,e,r)}}if((n=(n+1)%s)==r)break}return t}function oi(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(Be(s.offsetNode),s.offset)}}catch(t){}if(t.caretRangeFromPoint){let s=t.caretRangeFromPoint(e,i);if(s)return{node:s.startContainer,offset:Math.min(Be(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(!ri(e,i))return null;if(h=ni(t.dom,e,i),!h)return null}if(Ye)for(let t=h;i&&t;t=ke(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(Fe&&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;Ve&&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}=si(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 hi(t){return t.top<t.bottom||t.left<t.right}function li(t,e){let i=t.getClientRects();if(i.length){let t=i[e<0?0:i.length-1];if(hi(t))return t}return Array.prototype.find.call(i,hi)||t.getBoundingClientRect()}const ui=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function ai(t,e,i){let{node:s,offset:r,atom:n}=t.docView.domFromPos(e,i<0?-1:1),o=Ve||Fe;if(3==s.nodeType){if(!o||!ui.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++,ci(li(xe(s,t,e),n),n<0)}{let t=li(xe(s,r,r),i);if(Fe&&r&&/\s/.test(s.nodeValue[r-1])&&r<s.nodeValue.length){let e=li(xe(s,r-1,r-1),-1);if(e.top==t.top){let i=li(xe(s,r,r+1),-1);if(i.top!=t.top)return ci(i,i.left<e.left)}}return t}}if(!t.state.doc.resolve(e-(n||0)).parent.inlineContent){if(null==n&&r&&(i<0||r==Be(s))){let t=s.childNodes[r-1];if(1==t.nodeType)return fi(t.getBoundingClientRect(),!1)}if(null==n&&r<Be(s)){let t=s.childNodes[r];if(1==t.nodeType)return fi(t.getBoundingClientRect(),!0)}return fi(s.getBoundingClientRect(),i>=0)}if(null==n&&r&&(i<0||r==Be(s))){let t=s.childNodes[r-1],e=3==t.nodeType?xe(t,Be(t)-(o?0:1)):1!=t.nodeType||"BR"==t.nodeName&&t.nextSibling?null:t;if(e)return ci(li(e,1),!1)}if(null==n&&r<Be(s)){let t=s.childNodes[r];for(;t.pmViewDesc&&t.pmViewDesc.ignoreForCoords;)t=t.nextSibling;let e=t?3==t.nodeType?xe(t,0,o?0:1):1==t.nodeType?t:null:null;if(e)return ci(li(e,-1),!0)}return ci(li(3==s.nodeType?xe(s):s,-i),i>=0)}function ci(t,e){if(0==t.width)return t;let i=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:i,right:i}}function fi(t,e){if(0==t.height)return t;let i=e?t.top:t.bottom;return{top:i,bottom:i,left:t.left,right:t.right}}function di(t,e,i){let s=t.state,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 pi=/[\u0590-\u08ac]/;let wi=null,gi=null,mi=!1;class vi{constructor(t,e,i,s){this.parent=t,this.children=e,this.dom=i,this.contentDOM=s,this.dirty=0,i.pmViewDesc=this}matchesWidget(t){return!1}matchesMark(t){return!1}matchesNode(t,e,i){return!1}matchesHack(t){return!1}parseRule(){return null}stopEvent(t){return!1}get size(){let t=0;for(let e=0;e<this.children.length;e++)t+=this.children[e].size;return t}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let t=0;t<this.children.length;t++)this.children[t].destroy()}posBeforeChild(t){for(let e=0,i=this.posAtStart;;e++){let s=this.children[e];if(s==t)return i;i+=s.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(t,e,i){if(this.contentDOM&&this.contentDOM.contains(1==t.nodeType?t:t.parentNode)){if(i<0){let i,s;if(t==this.contentDOM)i=t.childNodes[e-1];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.previousSibling}for(;i&&(!(s=i.pmViewDesc)||s.parent!=this);)i=i.previousSibling;return i?this.posBeforeChild(s)+s.size:this.posAtStart}{let i,s;if(t==this.contentDOM)i=t.childNodes[e];else{for(;t.parentNode!=this.contentDOM;)t=t.parentNode;i=t.nextSibling}for(;i&&(!(s=i.pmViewDesc)||s.parent!=this);)i=i.nextSibling;return i?this.posBeforeChild(s):this.posAtEnd}}let s;if(t==this.dom&&this.contentDOM)s=e>be(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))s=2&t.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==e)for(let e=t;;e=e.parentNode){if(e==this.dom){s=!1;break}if(e.previousSibling)break}if(null==s&&e==t.childNodes.length)for(let e=t;;e=e.parentNode){if(e==this.dom){s=!0;break}if(e.nextSibling)break}}return(null==s?i>0:s)?this.posAtEnd:this.posAtStart}nearestDesc(t,e=!1){for(let i=!0,s=t;s;s=s.parentNode){let 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 Ci){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 yi&&t.side>=0;i--);if(e<=0){let t,s=!0;for(;t=i?this.children[i-1]:null,t&&t.dom.parentNode!=this.contentDOM;i--,s=!1);return t&&e&&s&&!t.border&&!t.domAtom?t.domFromPos(t.size,e):{node:this.contentDOM,offset:t?be(t.dom)+1:0}}{let t,s=!0;for(;t=i<this.children.length?this.children[i]:null,t&&t.dom.parentNode!=this.contentDOM;i++,s=!1);return t&&s&&!t.border&&!t.domAtom?t.domFromPos(0,e):{node:this.contentDOM,offset:t?be(t.dom):this.contentDOM.childNodes.length}}}parseRange(t,e,i=0){if(0==this.children.length)return{node:this.contentDOM,from:t,to:e,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let s=-1,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=be(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=be(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],u=h+l.size;if(r>h&&n<u)return l.setSelection(t-h-l.border,e-h-l.border,i,s);h=u}let o=this.domFromPos(t,t?-1:1),h=e==t?o:this.domFromPos(e,e?-1:1),l=i.root.getSelection(),u=i.domSelectionRange(),a=!1;if((Fe||Ye)&&t==e){let{node:t,offset:e}=o;if(3==t.nodeType){if(a=!(!e||"\n"!=t.nodeValue[e-1]),a&&e==t.nodeValue.length)for(let e,i=t;i;i=i.parentNode){if(e=i.nextSibling){"BR"==e.nodeName&&(o=h={node:e.parentNode,offset:be(e)+1});break}let t=i.pmViewDesc;if(t&&t.node&&t.node.isBlock)break}}else{let i=t.childNodes[e-1];a=i&&("BR"==i.nodeName||"false"==i.contentEditable)}}if(Fe&&u.focusNode&&u.focusNode!=h.node&&1==u.focusNode.nodeType){let t=u.focusNode.childNodes[u.focusOffset];t&&"false"==t.contentEditable&&(s=!0)}if(!(s||a&&Ye)&&Ae(o.node,o.offset,u.anchorNode,u.anchorOffset)&&Ae(h.node,h.offset,u.focusNode,u.focusOffset))return;let c=!1;if((l.extend||t==e)&&(!a||!Fe)){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 yi extends vi{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 bi extends vi{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 ki extends vi{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=at.renderSpec(document,e.type.spec.toDOM(e,i),null,e.attrs)),new ki(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=ki.create(this.parent,this.mark,!0,i),r=this.children,n=this.size;e<n&&(r=Ni(r,e,n,i)),t>0&&(r=Ni(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 Mi extends vi{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),u=l&&l.dom,a=l&&l.contentDOM;if(e.isText)if(u){if(3!=u.nodeType)throw new RangeError("Text must be rendered as a DOM text node")}else u=document.createTextNode(e.text);else if(!u){let t=at.renderSpec(document,e.type.spec.toDOM(e),null,e.attrs);({dom:u,contentDOM:a}=t)}a||e.isText||"BR"==u.nodeName||(u.hasAttribute("contenteditable")||(u.contentEditable="false"),e.type.spec.draggable&&(u.draggable=!0));let c=u;return u=$i(u,i,e),l?o=new Si(t,e,i,s,u,a||null,c,l,r,n+1):e.isText?new Ai(t,e,i,s,u,c,r):new Mi(t,e,i,s,u,a||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=()=>u.empty)}else t.contentElement=this.contentDOM;else t.getContent=()=>this.node.content;return t}matchesNode(t,e,i){return 0==this.dirty&&t.eq(this.node)&&Ri(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 ji(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 u=0;;){let a,c,f,d;for(;o<r.length&&r[o].to==n;){let t=r[o++];t.widget&&(a?(c||(c=[a])).push(t):a=t)}if(a)if(c){c.sort(Ui);for(let t=0;t<c.length;t++)i(c[t],u,!!l)}else i(a,u,!!l);if(l)d=-1,f=l,l=null;else{if(!(u<t.childCount))break;d=u,f=t.child(u++)}for(let t=0;t<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?d.none:this.node.child(r).marks,i,t,r),h.placeWidget(e,t,s)}),((e,n,l,u)=>{let a;h.syncToMarks(e.marks,i,t,u),h.findNodeMatch(e,n,l,u)||o&&t.state.selection.from>s&&t.state.selection.to<s+e.nodeSize&&(a=h.findIndexWithChild(r.node))>-1&&h.updateNodeAt(e,n,l,a,t)||h.updateNextNode(e,n,l,t,u,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),Bi(this.contentDOM,this.children,t),We&&function(t){if("UL"==t.nodeName||"OL"==t.nodeName){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t),t.style.cssText=e}}(this.dom))}localCompositionInfo(t,e){let{from:i,to:s}=t.state.selection;if(!(t.state.selection instanceof se)||i<e||s>e+this.node.content.size)return null;let 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 bi(this,r,e,s);t.input.compositionNodes.push(n),this.children=Ni(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(Ri(t,this.outerDeco))return;let e=1!=this.nodeDOM.nodeType,i=this.dom;this.dom=Di(this.dom,this.nodeDOM,Ei(this.outerDeco,this.node,e),Ei(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 xi(t,e,i,s,r){$i(s,e,t);let n=new Mi(void 0,t,e,i,s,s,s,r,0);return n.contentDOM&&n.updateChildren(r,0),n}class Ai extends Mi{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 Ai(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 Ci extends vi{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 Si extends Mi{constructor(t,e,i,s,r,n,o,h,l,u){super(t,e,i,s,r,n,o,l,u),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 Bi(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=Pi(s),r=!0;s=s.nextSibling}else r=!0,t.insertBefore(h,s);if(o instanceof ki){let e=s?s.previousSibling:t.lastChild;Bi(o.contentDOM,o.children,i),s=e?e.nextSibling:t.firstChild}}for(;s;)s=Pi(s),r=!0;r&&i.trackWrites==t&&(i.trackWrites=null)}const Oi=function(t){t&&(this.nodeName=t)};Oi.prototype=Object.create(null);const Ti=[new Oi];function Ei(t,e,i){if(0==t.length)return Ti;let s=i?Ti[0]:new Oi,r=[s];for(let n=0;n<t.length;n++){let o=t[n].type.attrs;if(o){o.nodeName&&r.push(s=new Oi(o.nodeName));for(let t in o){let n=o[t];null!=n&&(i&&1==r.length&&r.push(s=new Oi(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 Di(t,e,i,s){if(i==Ti&&s==Ti)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=Ti[0]),r=e}Ii(r,o||Ti[0],n)}return r}function Ii(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 $i(t,e,i){return Di(t,t,Ti,Ei(e,i,1!=t.nodeType))}function Ri(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 Pi(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}class ji{constructor(t,e,i){this.lock=e,this.view=i,this.index=0,this.stack=[],this.changed=!1,this.top=t,this.preMatch=function(t,e){let i=e,s=i.children.length,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 ki)){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=ki.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 Mi){let l=this.preMatch.matched.get(h);if(null!=l&&l!=r)return!1;let u,a=h.dom,c=this.isLocked(a)&&!(t.isText&&h.node&&h.node.isText&&h.nodeDOM.nodeValue==t.text&&3!=h.dirty&&Ri(e,h.outerDeco));if(!c&&h.update(t,e,i,s))return this.destroyBetween(this.index,o),h.dom!=a&&(this.changed=!0),this.index++,!0;if(!c&&(u=this.recreateWrapper(h,t,e,i,s,n)))return this.destroyBetween(this.index,o),this.top.children[this.index]=u,u.contentDOM&&(u.dirty=2,u.updateChildren(s,n+1),u.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)||!Ri(i,t.outerDeco)||!s.eq(t.innerDeco))return null;let o=Mi.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=Mi.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 yi(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 ki;)e=t,t=e.children[e.children.length-1];(!t||!(t instanceof Ai)||/\n$/.test(t.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(t.node.text))&&((Ye||Le)&&t&&"false"==t.dom.contentEditable&&this.addHackNode("IMG",e),this.addHackNode("BR",this.top))}addHackNode(t,e){if(e==this.top&&this.index<e.children.length&&e.children[this.index].matchesHack(t))this.index++;else{let i=document.createElement(t);"IMG"==t&&(i.className="ProseMirror-separator",i.alt=""),"BR"==t&&(i.className="ProseMirror-trailingBreak");let s=new Ci(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 Ni(t,e,i,s,r){let n=[];for(let o=0,h=0;o<t.length;o++){let l=t[o],u=h,a=h+=l.size;u>=i||a<=e?n.push(l):(u<e&&n.push(l.slice(0,e-u,s)),r&&(n.push(r),r=void 0),a>i&&n.push(l.slice(i-u,l.size,s)))}return n}function Fi(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,u=s.resolve(o);if(Te(i)){for(h=o;r&&!r.node;)r=r.parent;let t=r.node;if(r&&t.isAtom&&ne.isSelectable(t)&&r.parent&&(!t.isInline||!function(t,e,i){for(let s=0==e,r=e==Be(t);s||r;){if(t==i)return!0;let e=be(t);if(!(t=t.parentNode))return!1;s=s&&0==e,r=r&&e==Be(t)}}(i.focusNode,i.focusOffset,r.dom))){let t=r.posBefore;l=new ne(o==t?u: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],u=s.resolve(o)}else h=t.docView.posFromDOM(i.anchorNode,i.anchorOffset,1);if(h<0)return null}let a=s.resolve(h);return l||(l=Vi(t,a,u,"pointer"==e||t.state.selection.head<u.pos&&!n?1:-1)),l}function _i(t){return t.editable?t.hasFocus():qi(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function Li(t,e=!1){let i=t.state.selection;if(Hi(t,i),_i(t)){if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&Le){let e=t.domSelectionRange(),i=t.domObserver.currentSelection;if(e.anchorNode&&i.anchorNode&&Ae(e.anchorNode,e.anchorOffset,i.anchorNode,i.anchorOffset))return t.input.mouseDown.delayedSelectionSync=!0,void t.domObserver.setCurSelection()}if(t.domObserver.disconnectSelection(),t.cursorWrapper)!function(t){let e=t.domSelection();if(!e)return;let i=t.cursorWrapper.dom,s="IMG"==i.nodeName;s?e.collapse(i.parentNode,be(i)+1):e.collapse(i,0),!s&&!t.state.selection.visible&&Ue&&Ne<=11&&(i.disabled=!0,i.disabled=!1)}(t);else{let s,r,{anchor:n,head:o}=i;!zi||i instanceof se||(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),zi&&(s&&Xi(s),r&&Xi(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((()=>{_i(t)&&!t.state.selection.visible||t.dom.classList.remove("ProseMirror-hideselection")}),20))})}(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}const zi=Ye||Le&&ze<63;function Yi(t,e){let{node:i,offset:s}=t.docView.domFromPos(e,0),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 Xi(t){t.contentEditable="false",t.wasDraggable&&(t.draggable=!0,t.wasDraggable=null)}function Hi(t,e){if(e instanceof ne){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 Vi(t,e,i,s){return t.someProp("createSelectionBetween",(s=>s(t,e,i)))||se.between(e,i,s)}function Qi(t){return!(t.editable&&!t.hasFocus())&&qi(t)}function qi(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 Ki(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&&Zt.findFrom(n,e)}function Gi(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function Zi(t,e,i){let s=t.state.selection;if(!(s instanceof se)){if(s instanceof ne&&s.node.isInline)return Gi(t,new se(e>0?s.$to:s.$from));{let i=Ki(t.state,e);return!!i&&Gi(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 Gi(t,new se(s.$anchor,n))}if(!s.empty)return!1;if(t.endOfTextblock(e>0?"forward":"backward")){let i=Ki(t.state,e);return!!(i&&i instanceof ne)&&Gi(t,i)}if(!(Xe&&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)&&(ne.isSelectable(n)?Gi(t,new ne(e<0?t.state.doc.resolve(r.pos-n.nodeSize):r)):!!Ve&&Gi(t,new se(t.state.doc.resolve(e<0?o:o+n.nodeSize))))}}function ts(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function es(t,e){let i=t.pmViewDesc;return i&&0==i.size&&(e<0||t.nextSibling||"BR"!=t.nodeName)}function is(t,e){return e<0?function(t){let e=t.domSelectionRange(),i=e.focusNode,s=e.focusOffset;if(!i)return;let r,n,o=!1;for(Fe&&1==i.nodeType&&s<ts(i)&&es(i.childNodes[s],-1)&&(o=!0);;)if(s>0){if(1!=i.nodeType)break;{let t=i.childNodes[s-1];if(es(t,-1))r=i,n=--s;else{if(3!=t.nodeType)break;i=t,s=i.nodeValue.length}}}else{if(ss(i))break;{let e=i.previousSibling;for(;e&&es(e,-1);)r=i.parentNode,n=be(e),e=e.previousSibling;if(e)i=e,s=ts(i);else{if(i=i.parentNode,i==t.dom)break;s=0}}}o?rs(t,i,s):r&&rs(t,r,n)}(t):function(t){let e=t.domSelectionRange(),i=e.focusNode,s=e.focusOffset;if(!i)return;let r,n,o=ts(i);for(;;)if(s<o){if(1!=i.nodeType)break;if(!es(i.childNodes[s],1))break;r=i,n=++s}else{if(ss(i))break;{let e=i.nextSibling;for(;e&&es(e,1);)r=e.parentNode,n=be(e)+1,e=e.nextSibling;if(e)i=e,s=0,o=ts(i);else{if(i=i.parentNode,i==t.dom)break;s=o=0}}}r&&rs(t,r,n)}(t)}function ss(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function rs(t,e,i){if(3!=e.nodeType){let t,s;(s=function(t,e){for(;t&&e==t.childNodes.length&&!Oe(t);)e=be(t)+1,t=t.parentNode;for(;t&&e<t.childNodes.length;){let i=t.childNodes[e];if(3==i.nodeType)return i;if(1==i.nodeType&&"false"==i.contentEditable)break;t=i,e=0}}(e,i))?(e=s,i=0):(t=function(t,e){for(;t&&!e&&!Oe(t);)e=be(t),t=t.parentNode;for(;t&&e;){let i=t.childNodes[e-1];if(3==i.nodeType)return i;if(1==i.nodeType&&"false"==i.contentEditable)break;e=(t=i).childNodes.length}}(e,i))&&(e=t,i=t.nodeValue.length)}let s=t.domSelection();if(!s)return;if(Te(s)){let t=document.createRange();t.setEnd(e,i),t.setStart(e,i),s.removeAllRanges(),s.addRange(t)}else s.extend&&s.extend(e,i);t.domObserver.setCurSelection();let{state:r}=t;setTimeout((()=>{t.state==r&&Li(t)}),50)}function ns(t,e){let i=t.state.doc.resolve(e);if(!Le&&!He&&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 hs(t,e,i){let s=t.state.selection;if(s instanceof se&&!s.empty||i.indexOf("s")>-1)return!1;if(Xe&&i.indexOf("m")>-1)return!1;let{$from:r,$to:n}=s;if(!r.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let i=Ki(t.state,e);if(i&&i instanceof ne)return Gi(t,i)}if(!r.parent.inlineContent){let i=e<0?r:n,o=s instanceof he?Zt.near(i,e):Zt.findFrom(i,e);return!!o&&Gi(t,o)}return!1}function ls(t,e){if(!(t.state.selection instanceof se))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 us(t,e,i){t.domObserver.stop(),e.contentEditable=i,t.domObserver.start()}function as(t,e){t.someProp("transformCopied",(i=>{e=i(e,t)}));let i=[],{content:s,openStart: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")||at.fromSchema(t.state.schema),h=bs(),l=h.createElement("div");l.appendChild(o.serializeFragment(s,{document:h}));let u,a=l.firstChild,c=0;for(;a&&1==a.nodeType&&(u=vs[a.nodeName.toLowerCase()]);){for(let t=u.length-1;t>=0;t--){let e=h.createElement(u[t]);for(;l.firstChild;)e.appendChild(l.firstChild);l.appendChild(e),c++}a=l.firstChild}a&&1==a.nodeType&&a.setAttribute("data-pm-slice",`${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 cs(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 w(u.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=at.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=bs().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t);if((i=r&&vs[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?(ks||(ks=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),ks.createHTML(t)):t}(t),i)for(let t=0;t<i.length;t++)s=s.querySelector(i[t])||s;return s}(i),Ve&&function(t){let e=t.querySelectorAll(Le?"span:not([class]):not([style])":"span.Apple-converted-space");for(let i=0;i<e.length;i++){let s=e[i];1==s.childNodes.length&&" "==s.textContent&&s.parentNode&&s.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),s)}}(n);let a=n&&n.querySelector("[data-pm-slice]"),c=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let t=+c[3];t>0;t--){let t=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")||tt.fromSchema(t.state.schema);o=e.parseSlice(n,{preserveWhitespace:!(!l&&!c),context:r,ruleFromNode:t=>"BR"!=t.nodeName||t.nextSibling||!t.parentNode||fs.test(t.parentNode.nodeName)?null:{ignore:!0}})}if(c)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=u.from(e.create(i[t+1],r)),n++,o++}return new w(r,n,o)}(ms(o,+c[1],+c[2]),c[4]);else if(o=w.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&&ps(i,s,t,n[n.length-1],0))n[n.length-1]=e;else{n.length&&(n[n.length-1]=ws(n[n.length-1],s.length));let e=ds(t,i);n.push(e),r=r.matchType(e.type),s=i}})),n)return u.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=ms(o,t,e)}return t.someProp("transformPasted",(e=>{o=e(o,t,l)})),o}const fs=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function ds(t,e,i=0){for(let s=e.length-1;s>=i;s--)t=e[s].create(null,u.from(t));return t}function ps(t,e,i,s,r){if(r<t.length&&r<e.length&&t[r]==e[r]){let n=ps(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(u.from(ds(i,t,r+1))))}}function ws(t,e){if(0==e)return t;let i=t.content.replaceChild(t.childCount-1,ws(t.lastChild,e-1)),s=t.contentMatchAt(t.childCount).fillBefore(u.empty,!0);return t.copy(i.append(s))}function gs(t,e,i,s,r,n){let o=e<0?t.firstChild:t.lastChild,h=o.content;return t.childCount>1&&(n=0),r<s-1&&(h=gs(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(u.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,o.copy(h))}function ms(t,e,i){return e<t.openStart&&(t=new w(gs(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),i<t.openEnd&&(t=new w(gs(t.content,1,i,t.openEnd,0,0),t.openStart,i)),t}const vs={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 ys=null;function bs(){return ys||(ys=document.implementation.createHTMLDocument("title"))}let ks=null;const Ms={},xs={},As={touchstart:!0,touchmove:!0};class Cs{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 Ss(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function Bs(t){t.someProp("handleDOMEvents",(e=>{for(let i in e)t.input.eventHandlers[i]||t.dom.addEventListener(i,t.input.eventHandlers[i]=e=>Os(t,e))}))}function Os(t,e){return t.someProp("handleDOMEvents",(i=>{let s=i[e.type];return!!s&&(s(t,e)||e.defaultPrevented)}))}function Ts(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i=e.target;i!=t.dom;i=i.parentNode)if(!i||11==i.nodeType||i.pmViewDesc&&i.pmViewDesc.stopEvent(e))return!1;return!0}function Es(t){return{left:t.clientX,top:t.clientY}}function Ds(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 Is(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 $s(t,e,i,s){return Ds(t,"handleDoubleClickOn",e,i,s)||t.someProp("handleDoubleClick",(i=>i(t,e,s)))}function Rs(t,e,i,s){return Ds(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&&(Is(t,se.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)Is(t,se.create(s,n+1,n+1+i.content.size));else{if(!ne.isSelectable(i))continue;Is(t,ne.create(s,n))}return!0}}(t,i,s)}function Ps(t){return zs(t)}xs.keydown=(t,e)=>{let i=e;if(t.input.shiftKey=16==i.keyCode||i.shiftKey,!Ns(t,i)&&(t.input.lastKeyCode=i.keyCode,t.input.lastKeyCodeTime=Date.now(),!Je||!Le||13!=i.keyCode))if(229!=i.keyCode&&t.domObserver.forceFlush(),!We||13!=i.keyCode||i.ctrlKey||i.altKey||i.metaKey)t.someProp("handleKeyDown",(e=>e(t,i)))||function(t,e){let i=e.keyCode,s=function(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}(e);if(8==i||Xe&&72==i&&"c"==s)return ls(t,-1)||is(t,-1);if(46==i&&!e.shiftKey||Xe&&68==i&&"c"==s)return ls(t,1)||is(t,1);if(13==i||27==i)return!0;if(37==i||Xe&&66==i&&"c"==s){let e=37==i?"ltr"==ns(t,t.state.selection.from)?-1:1:-1;return Zi(t,e,s)||is(t,e)}if(39==i||Xe&&70==i&&"c"==s){let e=39==i?"ltr"==ns(t,t.state.selection.from)?1:-1:1;return Zi(t,e,s)||is(t,e)}return 38==i||Xe&&80==i&&"c"==s?hs(t,-1,s)||is(t,-1):40==i||Xe&&78==i&&"c"==s?function(t){if(!Ye||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(e&&1==e.nodeType&&0==i&&e.firstChild&&"false"==e.firstChild.contentEditable){let i=e.firstChild;us(t,i,"true"),setTimeout((()=>us(t,i,"false")),20)}return!1}(t)||hs(t,1,s)||is(t,1):s==(Xe?"m":"c")&&(66==i||73==i||89==i||90==i)}(t,i)?i.preventDefault():Ss(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,Ee(13,"Enter")))),t.input.lastIOSEnter=0)}),200)}},xs.keyup=(t,e)=>{16==e.keyCode&&(t.input.shiftKey=!1)},xs.keypress=(t,e)=>{let i=e;if(Ns(t,i)||!i.charCode||i.ctrlKey&&!i.altKey||Xe&&i.metaKey)return;if(t.someProp("handleKeyPress",(e=>e(t,i))))return void i.preventDefault();let s=t.state.selection;if(!(s instanceof se&&s.$from.sameParent(s.$to))){let e=String.fromCharCode(i.charCode),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 js=Xe?"metaKey":"ctrlKey";Ms.mousedown=(t,e)=>{let i=e;t.input.shiftKey=i.shiftKey;let s=Ps(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[js]&&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(Es(i));o&&("singleClick"==n?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new Us(t,o,i,!!s)):("doubleClick"==n?$s:Rs)(t,o.pos,o.inside,i)?i.preventDefault():Ss(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[js],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 ne&&l.from<=n&&l.to>n)&&(this.mightDrag={node:r,pos:n,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!Fe||this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout((()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")}),20),this.view.domObserver.start()),t.root.addEventListener("mouseup",this.up=this.up.bind(this)),t.root.addEventListener("mousemove",this.move=this.move.bind(this)),Ss(t,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout((()=>Li(this.view))),this.view.input.mouseDown=null}up(t){if(this.done(),!this.view.dom.contains(t.target))return;let e=this.pos;this.view.state.doc!=this.startDoc&&(e=this.view.posAtCoords(Es(t))),this.updateAllowDefault(t),this.allowDefault||!e?Ss(this.view,"pointer"):function(t,e,i,s,r){return Ds(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 ne&&(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(ne.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&&(Is(t,ne.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&&ne.isSelectable(s))&&(Is(t,new ne(i)),!0)}(t,i))}(this.view,e.pos,e.inside,t,this.selectNode)?t.preventDefault():0==t.button&&(this.flushed||Ye&&this.mightDrag&&!this.mightDrag.node.isAtom||Le&&!this.view.state.selection.visible&&Math.min(Math.abs(e.pos-this.view.state.selection.from),Math.abs(e.pos-this.view.state.selection.to))<=2)?(Is(this.view,Zt.near(this.view.state.doc.resolve(e.pos))),t.preventDefault()):Ss(this.view,"pointer")}move(t){this.updateAllowDefault(t),Ss(this.view,"pointer"),0==t.buttons&&this.done()}updateAllowDefault(t){!this.allowDefault&&(Math.abs(this.event.x-t.clientX)>4||Math.abs(this.event.y-t.clientY)>4)&&(this.allowDefault=!0)}}function Ns(t,e){return!!t.composing||!!(Ye&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500)&&(t.input.compositionEndedAt=-2e8,!0)}Ms.touchstart=t=>{t.input.lastTouch=Date.now(),Ps(t),Ss(t,"pointer")},Ms.touchmove=t=>{t.input.lastTouch=Date.now(),Ss(t,"pointer")},Ms.contextmenu=t=>Ps(t);const Fs=Je?5e3:-1;function _s(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout((()=>zs(t)),e))}function Ls(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=function(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function zs(t,e=!1){if(!(Je&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Ls(t),e||t.docView&&t.docView.dirty){let i=Fi(t),s=t.state.selection;return i&&!i.eq(s)?t.dispatch(t.state.tr.setSelection(i)):!t.markCursor&&!e||s.$from.node(s.$from.sharedDepth(s.to)).inlineContent?t.updateState(t.state):t.dispatch(t.state.tr.deleteSelection()),!0}return!1}}xs.compositionstart=xs.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,i=e.selection.$to;if(e.selection instanceof se&&(e.storedMarks||!i.textOffset&&i.parentOffset&&i.nodeBefore.marks.some((t=>!1===t.type.spec.inclusive))||Le&&He&&function(t){let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(!e||1!=e.nodeType||i>=e.childNodes.length)return!1;let s=e.childNodes[i];return 1==s.nodeType&&"false"==s.contentEditable}(t)))t.markCursor=t.state.storedMarks||i.marks(),zs(t,!0),t.markCursor=null;else if(zs(t,!e.selection.empty),Fe&&e.selection.empty&&i.parentOffset&&!i.textOffset&&i.nodeBefore.marks.length){let e=t.domSelectionRange();for(let i=e.focusNode,s=e.focusOffset;i&&1==i.nodeType&&0!=s;){let e=s<0?i.lastChild:i.childNodes[s-1];if(!e)break;if(3==e.nodeType){let i=t.domSelection();i&&i.collapse(e,e.nodeValue.length);break}i=e,s=-1}}t.input.composing=!0}_s(t,Fs)},xs.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++,_s(t,20))};const Ys=Ue&&Ne<15||We&&Qe<604;function Ws(t,e,i,s,r){let n=cs(t,e,i,s,t.state.selection.$from);if(t.someProp("handlePaste",(e=>e(t,r,n||w.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 Xs(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let i=t.getData("text/uri-list");return i?i.replace(/\r?\n/g," "):""}Ms.copy=xs.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}=as(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"))},xs.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,Xs(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 Hs{constructor(t,e,i){this.slice=t,this.move=e,this.node=i}}const Js=Xe?"altKey":"ctrlKey";function Vs(t,e){let i=t.someProp("dragCopies",(t=>!t(e)));return null!=i?i:!e[Js]}Ms.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(Es(i));if(o&&o.pos>=n.from&&o.pos<=(n instanceof ne?n.to-1:n.to));else if(s&&s.mightDrag)r=ne.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=ne.create(t.state.doc,e.posBefore))}let h=(r||t.state.selection).content(),{dom:l,text:u,slice:a}=as(t,h);(!i.dataTransfer.files.length||!Le||ze>120)&&i.dataTransfer.clearData(),i.dataTransfer.setData(Ys?"Text":"text/html",l.innerHTML),i.dataTransfer.effectAllowed="copyMove",Ys||i.dataTransfer.setData("text/plain",u),t.dragging=new Hs(a,Vs(t,i),r)},Ms.dragend=t=>{let e=t.dragging;window.setTimeout((()=>{t.dragging==e&&(t.dragging=null)}),50)},xs.dragover=xs.dragenter=(t,e)=>e.preventDefault(),xs.drop=(t,e)=>{try{!function(t,e,i){if(!e.dataTransfer)return;let s=t.posAtCoords(Es(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=cs(t,Xs(e.dataTransfer),Ys?null:e.dataTransfer.getData("text/html"),!1,r);let o=!(!i||!Vs(t,e));if(t.someProp("handleDrop",(i=>i(t,e,n||w.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 u=l.mapping.map(h),a=0==n.openStart&&0==n.openEnd&&1==n.content.childCount,c=l.doc;if(a?l.replaceRangeWith(u,u,n.content.firstChild):l.replaceRange(u,u,n),l.doc.eq(c))return;let f=l.doc.resolve(u);if(a&&ne.isSelectable(n.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(n.content.firstChild))l.setSelection(new ne(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(Vi(t,f,l.doc.resolve(e)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}(t,e,t.dragging)}finally{t.dragging=null}},Ms.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout((()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&Li(t)}),20))},Ms.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)},Ms.beforeinput=(t,e)=>{if(Le&&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,Ee(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 xs)Ms[t]=xs[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 qs{constructor(t,e){this.toDOM=t,this.spec=e||er,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 Zs(r-i,r-i,this)}valid(){return!0}eq(t){return this==t||t instanceof qs&&(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 Ks{constructor(t,e){this.attrs=t,this.spec=e||er}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 Zs(r,n,this)}valid(t,e){return e.from<e.to}eq(t){return this==t||t instanceof Ks&&Qs(this.attrs,t.attrs)&&Qs(this.spec,t.spec)}static is(t){return t.type instanceof Ks}destroy(){}}class Gs{constructor(t,e){this.attrs=t,this.spec=e||er}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 Zs(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 Gs&&Qs(this.attrs,t.attrs)&&Qs(this.spec,t.spec)}destroy(){}}class Zs{constructor(t,e,i){this.from=t,this.to=e,this.type=i}copy(t,e){return new Zs(t,e,this.type)}eq(t,e=0){return this.type.eq(t.type)&&this.from+e==t.from&&this.to+e==t.to}map(t,e,i){return this.type.map(t,this,e,i)}static widget(t,e,i){return new Zs(t,t,new qs(e,i))}static inline(t,e,i,s){return new Zs(t,e,new Ks(i,s))}static node(t,e,i,s){return new Zs(t,e,new Gs(i,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof Ks}get widget(){return this.type instanceof qs}}const tr=[],er={};class ir{constructor(t,e){this.local=t.length?t:tr,this.children=e.length?e:tr}static create(t,e){return e.length?lr(e,t,0,er):sr}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==sr||0==t.maps.length?this:this.mapInner(t,e,0,0,i||er)}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 u=i.map(t[e]+n),a=u-r;if(a<0||a>=s.content.size){l=!0;continue}let c=i.map(t[e+1]+n,-1)-r,{index:f,offset:d}=s.content.findIndex(a),p=s.maybeChild(f);if(p&&d==a&&d+p.nodeSize==c){let s=h[e+2].mapInner(i,p,u+1,t[e]+n+1,o);s!=sr?(h[e]=a,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),u=lr(l,s,0,o);e=u.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<u.children.length;t+=3){let i=u.children[t];for(;e<h.length&&h[e]<i;)e+=3;h.splice(e,0,u.children[t],u.children[t+1],u.children[t+2])}}return new ir(e.sort(ur),h)}(this.children,n||[],t,e,i,s,r):n?new ir(n.sort(ur),tr):sr}add(t,e){return e.length?this==sr?ir.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=or(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,lr(o,t,h+1,er)),r+=3}}));let n=nr(r?hr(e):e,-i);for(let e=0;e<n.length;e++)n[e].type.valid(t,n[e])||n.splice(e--,1);return new ir(n.length?this.local.concat(n).sort(ur):this.local,s||this.children)}remove(t){return 0==t.length||this==sr?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!=sr?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 ir(s,i):sr}forChild(t,e){if(this==sr)return this;if(e.isLeaf)return ir.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 Ks){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 ir(s.sort(ur),tr);return i?new rr([t,i]):t}return i||sr}eq(t){if(this==t)return!0;if(!(t instanceof ir)||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 ar(this.localsInner(t))}localsInner(t){if(this==sr)return tr;if(t.inlineContent||!this.local.some(Ks.is))return this.local;let e=[];for(let t=0;t<this.local.length;t++)this.local[t].type instanceof Ks||e.push(this.local[t]);return e}forEachSet(t){t(this)}}ir.empty=new ir([],[]),ir.removeOverlap=ar;const sr=ir.empty;class rr{constructor(t){this.members=t}map(t,e){const i=this.members.map((i=>i.map(t,e,er)));return rr.from(i)}forChild(t,e){if(e.isLeaf)return ir.empty;let i=[];for(let s=0;s<this.members.length;s++){let r=this.members[s].forChild(t,e);r!=sr&&(r instanceof rr?i=i.concat(r.members):i.push(r))}return rr.from(i)}eq(t){if(!(t instanceof rr)||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?ar(i?e:e.sort(ur)):tr}static from(t){switch(t.length){case 0:return sr;case 1:return t[0];default:return new rr(t.every((t=>t instanceof ir))?t:t.reduce(((t,e)=>t.concat(e instanceof ir?e:e.members)),[]))}}forEachSet(t){for(let e=0;e<this.members.length;e++)this.members[e].forEachSet(t)}}function nr(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 Zs(r.from+e,r.to+e,r.type))}return i}function or(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 hr(t){let e=[];for(let i=0;i<t.length;i++)null!=t[i]&&e.push(t[i]);return e}function lr(t,e,i,s){let r=[],n=!1;e.forEach(((e,o)=>{let h=or(t,e,o+i);if(h){n=!0;let t=lr(h,e,i+o+1,s);t!=sr&&r.push(o,o+e.nodeSize,t)}}));let o=nr(n?hr(t):t,-i).sort(ur);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 ir(o,r):sr}function ur(t,e){return t.from-e.from||t.to-e.to}function ar(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),cr(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),cr(e,r+1,n.copy(s.to,n.to)))}}return e}function cr(t,e,i){for(;e<t.length&&ur(i,t[e])>0;)e++;t.splice(e,0,i)}function fr(t){let e=[];return t.someProp("decorations",(i=>{let s=i(t.state);s&&s!=sr&&e.push(s)})),t.cursorWrapper&&e.push(ir.create(t.state.doc,[t.cursorWrapper.deco])),rr.from(e)}const dr={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},pr=Ue&&Ne<=11;class wr{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 gr{constructor(t,e){this.view=t,this.handleDOMChange=e,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new wr,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&&Ne<=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()})),pr&&(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,dr)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let t=this.observer.takeRecords();if(t.length){for(let e=0;e<t.length;e++)this.queue.push(t[e]);window.setTimeout((()=>this.flush()),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout((()=>this.suppressingSelectionUpdates=!1),50)}onSelectionChange(){if(Qi(this.view)){if(this.suppressingSelectionUpdates)return Li(this.view);if(Ue&&Ne<=11&&!this.view.state.selection.empty){let t=this.view.domSelectionRange();if(t.focusNode&&Ae(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=ke(e))i.add(e);for(let s=t.anchorNode;s;s=ke(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(Fe&&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&&br(t,i)==e||s.remove()}}}else if((Le||Ye)&&h.some((t=>"BR"==t.nodeName))&&(8==t.input.lastKeyCode||46==t.input.lastKeyCode))for(let t of h)if("BR"==t.nodeName&&t.parentNode){let e=t.nextSibling;e&&1==e.nodeType&&"false"==e.contentEditable&&t.parentNode.removeChild(t)}let l=null;r<0&&s&&t.input.lastFocus>Date.now()-200&&Math.max(t.input.lastTouch,t.input.lastClick.time)<Date.now()-300&&Te(i)&&(l=Fi(t))&&l.eq(Zt.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,Li(t),this.currentSelection.set(i),t.scrollToSelection()):(r>-1||s)&&(r>-1&&(t.docView.markDirty(r,n),function(t){if(!mr.has(t)&&(mr.set(t,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace))){if(t.requiresGeckoHackNode=Fe,vr)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."),vr=!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)||Li(t),this.currentSelection.set(i))}registerMutation(t,e){if(e.indexOf(t.target)>-1)return null;let i=this.view.docView.nearestDesc(t.target);if("attributes"==t.type&&(i==this.view.docView||"contenteditable"==t.attributeName||"style"==t.attributeName&&!t.oldValue&&!t.target.getAttribute("style")))return null;if(!i||i.ignoreMutation(t))return null;if("childList"==t.type){for(let i=0;i<t.addedNodes.length;i++){let s=t.addedNodes[i];e.push(s),3==s.nodeType&&(this.lastChangedTextNode=s)}if(i.contentDOM&&i.contentDOM!=i.dom&&!i.contentDOM.contains(t.target))return{from:i.posBefore,to:i.posAfter};let s=t.previousSibling,r=t.nextSibling;if(Ue&&Ne<=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?be(s)+1:0,o=i.localPosFromDOM(t.target,n,-1),h=r&&r.parentNode==t.target?be(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 mr=new WeakMap,vr=!1;function yr(t,e){let i=e.startContainer,s=e.startOffset,r=e.endContainer,n=e.endOffset,o=t.domAtPos(t.state.selection.anchor);return Ae(o.node,o.offset,r,n)&&([i,s,r,n]=[r,n,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:n}}function br(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 kr(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 Mr=/^(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 xr(t,e,i){return Math.max(i.anchor,i.head)>e.content.size?null:Vi(t,e.resolve(i.anchor),e.resolve(i.head))}function Ar(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 Cr(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 Sr{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 Cs,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=e,this.state=e.state,this.directPlugins=e.plugins||[],this.directPlugins.forEach(Dr),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=Tr(this),Or(this),this.nodeViews=Er(this),this.docView=xi(this.state.doc,Br(this),fr(this),this.dom,this),this.domObserver=new gr(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=Fi(t,e);if(i&&!t.state.selection.eq(i)){if(Le&&Je&&13===t.input.lastKeyCode&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",(e=>e(t,Ee(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,c=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),u=t.domSelectionRange(),a=u.anchorNode;if(a&&t.dom.contains(1==a.nodeType?a:a.parentNode)&&(s=[{node:a,offset:u.anchorOffset}],Te(u)||s.push({node:u.focusNode,offset:u.focusOffset})),Le&&8===t.input.lastKeyCode)for(let t=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")||tt.fromSchema(t.state.schema),d=c.resolve(h),p=null,w=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:kr,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:w,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 w=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&&Cr(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&&Cr(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(w&&t.input.domChangeCount++,(We&&t.input.lastIOSEnter>Date.now()-225||Je)&&r.some((t=>1==t.nodeType&&!Mr.test(t.nodeName)))&&(!w||w.endA>=w.endB)&&t.someProp("handleKeyDown",(e=>e(t,Ee(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(!w){if(!(s&&c instanceof se&&!c.empty&&c.$head.sameParent(c.$anchor))||t.composing||f.sel&&f.sel.anchor!=f.sel.head){if(f.sel){let e=xr(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}w={start:c.from,endA:c.to,endB:c.to}}t.state.selection.from<t.state.selection.to&&w.start==w.endB&&t.state.selection instanceof se&&(w.start>t.state.selection.from&&w.start<=t.state.selection.from+2&&t.state.selection.from>=f.from?w.start=t.state.selection.from:w.endA<t.state.selection.to&&w.endA>=t.state.selection.to-2&&t.state.selection.to<=f.to&&(w.endB+=t.state.selection.to-w.endA,w.endA=t.state.selection.to)),Ue&&Ne<=11&&w.endB==w.start+1&&w.endA==w.start&&w.start>f.from&&"  "==f.doc.textBetween(w.start-f.from-1,w.start-f.from+1)&&(w.start--,w.endA--,w.endB--);let g=f.doc.resolveNoCache(w.start-f.from),m=f.doc.resolveNoCache(w.endB-f.from),v=d.resolve(w.start),y=g.sameParent(m)&&g.parent.inlineContent&&v.end()>=w.endA;if((We&&t.input.lastIOSEnter>Date.now()-225&&(!y||r.some((t=>"DIV"==t.nodeName||"P"==t.nodeName)))||!y&&g.pos<f.doc.content.size&&(!g.sameParent(m)||!g.parent.inlineContent)&&g.pos<m.pos&&!/\S/.test(f.doc.textBetween(g.pos,m.pos,"","")))&&t.someProp("handleKeyDown",(e=>e(t,Ee(13,"Enter")))))return void(t.input.lastIOSEnter=0);if(t.state.selection.anchor>w.start&&function(t,e,i,s,r){if(i-e<=r.pos-s.pos||Ar(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(Ar(n,!0,!0));return!(!o.parent.isTextblock||o.pos>i||Ar(o,!0,!1)<i)&&s.parent.content.cut(s.parentOffset).eq(o.parent.content)}(d,w.start,w.endA,g,m)&&t.someProp("handleKeyDown",(e=>e(t,Ee(8,"Backspace")))))return void(Je&&Le&&t.domObserver.suppressSelectionUpdates());Le&&w.endB==w.start&&(t.input.lastChromeDelete=Date.now()),Je&&!y&&g.start()!=m.start()&&0==m.parentOffset&&g.depth==m.depth&&f.sel&&f.sel.anchor==f.sel.head&&f.sel.head==w.endA&&(w.endB-=2,m=f.doc.resolveNoCache(w.endB-f.from),setTimeout((()=>{t.someProp("handleKeyDown",(function(e){return e(t,Ee(13,"Enter"))}))}),20));let b,k=w.start,M=w.endA,x=e=>{let i=e||t.state.tr.replace(k,M,f.doc.slice(w.start-f.from,w.endB-f.from));if(f.sel){let e=xr(t,i.doc,f.sel);e&&!(Le&&t.composing&&e.empty&&(w.start!=w.endB||t.input.lastChromeDelete<Date.now()-100)&&(e.head==k||e.head==i.mapping.map(M)-1)||Ue&&e.empty&&e.head==k)&&i.setSelection(e)}return n&&i.setMeta("composition",n),i.scrollIntoView()};if(y)if(g.pos==m.pos){Ue&&Ne<=11&&0==g.parentOffset&&(t.domObserver.suppressSelectionUpdates(),setTimeout((()=>Li(t)),20));let e=x(t.state.tr.delete(k,M)),i=d.resolve(w.start).marksAcross(d.resolve(w.endA));i&&e.ensureMarks(i),t.dispatch(e)}else if(w.endA==w.endB&&(b=function(t,e){let i,s,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(u.from(a).eq(t))return{mark:s,type:i}}(g.parent.content.cut(g.parentOffset,m.parentOffset),v.parent.content.cut(v.parentOffset,w.endA-v.start())))){let e=x(t.state.tr);"add"==b.type?e.addMark(k,M,b.mark):e.removeMark(k,M,b.mark),t.dispatch(e)}else if(g.parent.child(g.index()).isText&&g.index()==m.index()-(m.textOffset?0:1)){let e=g.parent.textBetween(g.parentOffset,m.parentOffset),i=()=>x(t.state.tr.insertText(e,k,M));t.someProp("handleTextInput",(s=>s(t,k,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 Ms){let i=Ms[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=e=>{!Ts(t,e)||Os(t,e)||!t.editable&&e.type in xs||i(t,e)},As[e]?{passive:!0}:void 0)}Ye&&t.dom.addEventListener("input",(()=>null)),Bs(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&&Bs(this);let e=this._props;this._props=t,t.plugins&&(t.plugins.forEach(Dr),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&&(Ls(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=Er(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)&&Bs(this),this.editable=Tr(this),Or(this);let h=fr(this),l=Br(this),u=s.plugins==t.plugins||s.doc.eq(t.doc)?t.scrollToSelection>s.scrollToSelection?"to selection":"preserve":"reset",a=r||!this.docView.matchesNode(t.doc,l,h);!a&&t.selection.eq(s.selection)||(n=!0);let c="preserve"==u&&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:ti(t.dom)}}(this);if(n){this.domObserver.stop();let e=a&&(Ue||Le)&&!this.composing&&!s.selection.empty&&!t.selection.empty&&function(t,e){let i=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(i)!=e.$anchor.start(i)}(s.selection,t.selection);if(a){let i=Le?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=function(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let i=function(t,e){for(;;){if(3==t.nodeType&&e)return t;if(1==t.nodeType&&e>0){if("false"==t.contentEditable)return null;e=Be(t=t.childNodes[e-1])}else{if(!t.parentNode||Oe(t))return null;e=be(t),t=t.parentNode}}}(e.focusNode,e.focusOffset),s=function(t,e){for(;;){if(3==t.nodeType&&e<t.nodeValue.length)return t;if(1==t.nodeType&&e<t.childNodes.length){if("false"==t.contentEditable)return null;t=t.childNodes[e],e=0}else{if(!t.parentNode||Oe(t))return null;e=be(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=xi(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 Ae(e.node,e.offset,i.anchorNode,i.anchorOffset)}(this))?Li(this,e):(Hi(this,t.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),(null===(i=this.dragging)||void 0===i?void 0:i.node)&&!s.doc.eq(t.doc)&&this.updateDraggedNode(this.dragging,s),"reset"==u?this.dom.scrollTop=0:"to selection"==u?this.scrollToSelection():c&&function({refDOM:t,refTop:e,stack:i}){let s=t?t.getBoundingClientRect().top:0;ei(i,0==s?0:s-e)}(c)}scrollToSelection(){let t=this.domSelectionRange().focusNode;if(t&&this.dom.contains(1==t.nodeType?t:t.parentNode))if(this.someProp("handleScrollToSelection",(t=>t(this))));else if(this.state.selection instanceof ne){let e=this.docView.domAfterPos(this.state.selection.from);1==e.nodeType&&Ze(this,e.getBoundingClientRect(),t)}else Ze(this,this.coordsAtPos(this.state.selection.head,1),t)}destroyPluginViews(){let t;for(;t=this.pluginViews.pop();)t.destroy&&t.destroy()}updatePluginViews(t){if(t&&t.plugins==this.state.plugins&&this.directPlugins==this.prevDirectPlugins)for(let e=0;e<this.pluginViews.length;e++){let i=this.pluginViews[e];i.update&&i.update(this,t)}else{this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let e=this.directPlugins[t];e.spec.view&&this.pluginViews.push(e.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let e=this.state.plugins[t];e.spec.view&&this.pluginViews.push(e.spec.view(this))}}}updateDraggedNode(t,e){let i=t.node,s=-1;if(this.state.doc.nodeAt(i.from)==i.node)s=i.from;else{let t=i.from+(this.state.doc.content.size-e.doc.content.size);(t>0&&this.state.doc.nodeAt(t))==i.node&&(s=t)}this.dragging=new Hs(t.slice,t.move,s<0?void 0:ne.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(ii)return t.focus(ii);let e=ti(t);t.focus(null==ii?{get preventScroll(){return ii={preventScroll:!0},!0}}:void 0),ii||(ii=!1,ei(e,0))}(this.dom),Li(this),this.domObserver.start()}get root(){let t=this._root;if(null==t)for(let t=this.dom.parentNode;t;t=t.parentNode)if(9==t.nodeType||11==t.nodeType&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t;return t||document}updateRoot(){this._root=null}posAtCoords(t){return oi(this,t)}coordsAtPos(t,e=1){return ai(this,t,e)}domAtPos(t,e=0){return this.docView.domFromPos(t,e)}nodeDOM(t){let e=this.docView.descAt(t);return e?e.nodeDOM:null}posAtDOM(t,e,i=-1){let s=this.docView.posFromDOM(t,e,i);if(null==s)throw new RangeError("DOM position not inside the editor");return s}endOfTextblock(t,e){return function(t,e,i){return wi==e&&gi==i?mi:(wi=e,gi=i,mi="up"==i||"down"==i?function(t,e,i){let s=e.selection,r="up"==i?s.$from:s.$to;return di(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=ai(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=xe(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?pi.test(s.parent.textContent)&&h.modify?di(t,e,(()=>{let{focusNode:e,focusOffset:r,anchorNode:n,anchorOffset:o}=t.domSelectionRange(),l=h.caretBidiLevel;h.modify("move",i,"character");let u=s.depth?t.docView.domAfterPos(s.before()):t.dom,{focusNode:a,focusOffset:c}=t.domSelectionRange(),f=a&&!u.contains(1==a.nodeType?a:a.parentNode)||e==a&&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 as(this,t)}destroy(){this.docView&&(function(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],fr(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Me=null)}get isDestroyed(){return null==this.docView}dispatchEvent(t){return function(t,e){Os(t,e)||!Ms[e.type]||!t.editable&&e.type in xs||Ms[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 yr(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?yr(t,i):null}(this,t)||t:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function Br(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",(i=>{if("function"==typeof i&&(i=i(t.state)),i)for(let t in i)"class"==t?e.class+=" "+i[t]:"style"==t?e.style=(e.style?e.style+";":"")+i[t]:e[t]||"contenteditable"==t||"nodeName"==t||(e[t]=String(i[t]))})),e.translate||(e.translate="no"),[Zs.node(0,t.state.doc.content.size,e)]}function Or(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:Zs.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Tr(t){return!t.someProp("editable",(e=>!1===e(t.state)))}function Er(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 Dr(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")}Sr.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};const Ir=["p",0],$r=["blockquote",0],Rr=["hr"],Pr=["pre",["code",0]],jr=["br"],Ur={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:()=>Ir},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:()=>$r},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>Rr},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:()=>Pr},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:()=>jr}},Nr=["em",0],Fr=["strong",0],_r=["code",0],Lr={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:()=>Fr},code:{code:!0,parseDOM:[{tag:"code"}],toDOM:()=>_r}},zr=new G({nodes:Ur,marks:Lr}),Yr=["ol",0],Wr=["ul",0],Xr=["li",0],Hr={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?Yr:["ol",{start:t.attrs.order},0]},Jr={parseDOM:[{tag:"ul"}],toDOM:()=>Wr},Vr={parseDOM:[{tag:"li"}],toDOM:()=>Xr,defining:!0};function Qr(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:Qr(Hr,{content:"list_item+",group:i}),bullet_list:Qr(Jr,{content:"list_item+",group:i}),list_item:Qr(Vr,{content:e})})}for(var Kr={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++)Kr[48+en]=Kr[96+en]=String(en);for(en=1;en<=24;en++)Kr[en+111]="F"+en;for(en=65;en<=90;en++)Kr[en]=String.fromCharCode(en+32),Gr[en]=String.fromCharCode(en);for(var sn in Kr)Gr.hasOwnProperty(sn)||(Gr[sn]=Kr[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 ve({props:{handleKeyDown:un(t)}})}function un(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:Kr)[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=Kr[i.keyCode])&&s!=r){let r=e[hn(s,i)];if(r&&r(t.state,t.dispatch,t))return!0}}return!1}}const an=(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 wn(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=u.empty;for(let t=r.length-1;t>=0;t--)n=u.from(r[t].create(null,n));n=u.from(o.copy(n));let l=t.tr.step(new Tt(e.pos-1,s,e.pos,s,new w(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 c=h.type.spec.isolating||s>0&&l?null:Zt.findFrom(e,1),f=c&&c.$from.blockRange(c.$to),d=f&&$t(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=u.empty;for(let t=r.length-1;t>=0;t--)s=u.from(r[t].copy(s));i(t.tr.step(new Tt(e.pos-r.length,e.pos+h.nodeSize,e.pos+l,e.pos+h.nodeSize-l,new w(s,r.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function gn(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(se.create(e.doc,t<0?r.start(n):r.end(n)))),!0)}}const mn=gn(-1),vn=gn(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 bn=yn(an,((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&&$t(i);return null!=r&&(e&&e(t.tr.lift(i,r).scrollIntoView()),!0)}let n=r.nodeBefore;if(wn(t,r,e,-1))return!0;if(0==s.parent.content.size&&(cn(n,"end")||ne.isSelectable(n)))for(let i=s.depth;;i--){let o=Nt(t.doc,s.before(i),s.after(i),w.empty);if(o&&o.slice.size<o.to-o.from){if(e){let i=t.tr.step(o);i.setSelection(cn(n,"end")?Zt.findFrom(i.doc.resolve(i.mapping.map(r.pos,-1)),-1):ne.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||!ne.isSelectable(o)||(e&&e(t.tr.setSelection(ne.create(t.doc,n.pos-o.nodeSize)).scrollIntoView()),0))})),kn=yn(an,((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(wn(t,r,e,1))return!0;if(0==s.parent.content.size&&(cn(n,"start")||ne.isSelectable(n))){let i=Nt(t.doc,s.before(),s.after(),w.empty);if(i&&i.slice.size<i.to-i.from){if(e){let s=t.tr.step(i);s.setSelection(cn(n,"start")?Zt.findFrom(s.doc.resolve(s.mapping.map(r.pos)),1):ne.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||!ne.isSelectable(o)||(e&&e(t.tr.setSelection(ne.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 he||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(se.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(jt(t.doc,s))return e&&e(t.tr.split(s).scrollIntoView()),!0}let s=i.blockRange(),r=s&&$t(s);return null!=r&&(e&&e(t.tr.lift(s,r).scrollIntoView()),!0)}),((t,e)=>{let{$from:i}=t.selection;if(t.selection instanceof ne&&t.selection.node.isBlock)return!(!i.parentOffset||!jt(t.doc,i.pos)||(e&&e(t.tr.split(i.pos).scrollIntoView()),0));if(!i.depth)return!1;let s,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 se||t.selection instanceof he)&&l.deleteSelection();let u=l.mapping.map(i.pos),a=jt(l.doc,u,n.length,n);if(a||(n[0]=r?{type:r}:null,a=jt(l.doc,u,n.length,n)),!a)return!1;if(l.split(u,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(Zt.near(r.doc.resolve(s),1)),e(r.scrollIntoView())}return!0},Backspace:bn,"Mod-Backspace":bn,"Shift-Backspace":bn,Delete:kn,"Mod-Delete":kn,"Mod-a":(t,e)=>(e&&e(t.tr.setSelection(new he(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 An=("undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"undefined"!=typeof os&&os.platform&&"darwin"==os.platform())?xn:Mn,Cn=[{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:"#007acc",focusRingColor:"rgba(0, 122, 255, 0.3)",hoverBackground:"hsl(0, 0%, 0%, 4.3%)",iconColor:"currentColor",scrollbarThumbColor:"#ebebeb",textPrimary:"#000000",textSecondary:"#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)",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"},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"},dropdown:{accentColor:"#007bff",hoverBackgroundColor:"#f0f0f0",selectedBackgroundColor:"#007bff1a",textColor:"#333333"},engine:{backgroundColor:"#ffffff"},fontSize:{hoverBackgroundColor:"#ebebeb",selectedBackgroundColor:"#ebebeb",textColor:"#333333"},lineEndings:{hoverBackgroundColor:"#ebebeb",labelColor:"#666666",optionBackground:"#ffffff",selectedBackgroundColor:"#ebebeb"},masterDetail:{backButtonColor:"#333333",backgroundColor:"#ffffff",detailBackgroundColor:"#ffffff",detailFocusOutline:"2px solid #007AFF",menuBackgroundColor:"#ffffff",menuBorderRight:"1px solid #ebebeb",menuItemActiveBackgroundColor:"hsl(0, 0%, 0%, 8.6%)",menuItemBackgroundColor:"transparent",menuItemChevronColor:"#aaaaaa",menuItemColor:"#333333",menuItemDisabledColor:"#aaaaaa",menuItemFocusOutline:"2px solid #007AFF",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 #ccc",itemInputSelectionColor:"rgba(255, 255, 255, 0.16)",itemInputSelectionTextColor:"#000000",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:{borderColor:"#ebebeb",focusBorderColor:"#007AFF",hoverBorderColor:"#ccc",inputBackground:"#ffffff",labelColor:"#666666",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"},shapeFill:{hoverBackgroundColor:"#ebebeb",optionBackground:"#ffffff",selectedBackgroundColor:"#ebebeb"},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:"#4da3ff",focusRingColor:"rgba(0, 122, 255, 0.4)",hoverBackground:"hsl(0, 0%, 100%, 8%)",iconColor:"currentColor",scrollbarThumbColor:"#555555",textPrimary:"#ffffff",textSecondary:"#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)",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"},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"},dropdown:{accentColor:"#0A84FF",hoverBackgroundColor:"#3a3a3a",selectedBackgroundColor:"rgba(10, 132, 255, 0.2)",textColor:"#e0e0e0"},engine:{backgroundColor:"#1a1a1a"},fontSize:{hoverBackgroundColor:"#3a3a3a",selectedBackgroundColor:"#3a3a3a",textColor:"#e0e0e0"},lineEndings:{hoverBackgroundColor:"#3a3a3a",labelColor:"#999999",optionBackground:"#2a2a2a",selectedBackgroundColor:"#3a3a3a"},masterDetail:{backButtonColor:"#e0e0e0",backgroundColor:"#2a2a2a",detailBackgroundColor:"#2a2a2a",detailFocusOutline:"2px solid #0A84FF",menuBackgroundColor:"#2a2a2a",menuBorderRight:"1px solid #3a3a3a",menuItemActiveBackgroundColor:"hsl(0, 0%, 100%, 12%)",menuItemBackgroundColor:"transparent",menuItemChevronColor:"#666666",menuItemColor:"#e0e0e0",menuItemDisabledColor:"#666666",menuItemFocusOutline:"2px solid #0A84FF",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 #4a4a4a",itemInputSelectionColor:"rgba(255, 255, 255, 0.2)",itemInputSelectionTextColor:"#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:"#3a3a3a",focusBorderColor:"#0A84FF",hoverBorderColor:"#4a4a4a",inputBackground:"#1a1a1a",labelColor:"#999999",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"},shapeFill:{hoverBackgroundColor:"#3a3a3a",optionBackground:"#2a2a2a",selectedBackgroundColor:"#3a3a3a"},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 On{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}-${On.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=On.flattenThemeToVariables(e);On.applyVariablesToElement(t,i)}}const Tn="kritzel-theme",En="light";class Dn{_core;_currentTheme=En;_targetElement=null;constructor(t){this._core=t,this._currentTheme=Dn.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}static getStoredTheme(){if("undefined"==typeof localStorage)return En;const t=localStorage.getItem(Tn);return"dark"===t||"light"===t?t:En}saveTheme(t){"undefined"!=typeof localStorage&&localStorage.setItem(Tn,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);On.applyThemeToElement(this._targetElement,e)}cleanup(){this._targetElement=null}}class In{static resolveThemeColor(t,e){return t?function(t,e){return t[e]}(t,e??Dn.getStoredTheme()):""}static applyOpacity(t,e,i){const s=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 $n extends s{__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 G({nodes:qr(zr.spec.nodes,"paragraph block*","block"),marks:zr.spec.marks});uneditedObject=null;rows=1;get isEmpty(){if(!this.editor)return!0;const t=this.editor.state.doc;return 0===t.content.size||0===t.textContent.trim().length}constructor(t){super(),t&&(this.translateX=t.translateX||0,this.translateY=t.translateY||0,this.fontSize=t.fontSize||8,this.fontFamily=t.fontFamily||"Arial",this.fontColor=t.fontColor||{light:"#000000",dark:"#ffffff"},this.width=this.initialWidth/(this._core.store.state.scale<0?this._core.store.state.scale:1),this.height=1.2*this.fontSize/(this._core.store.state.scale<0?this._core.store.state.scale:1),this.scale=t.scale||1,this.scaleFactor=t.scaleX??1)}static create(t,e,i,s){const r=new $n;return r._core=t,r.id=r.generateId(),r.workspaceId=t.store.state.activeWorkspace.id,r.fontSize=e,r.fontFamily=i,r.translateX=0,r.translateY=0,r.width=r.initialWidth/(r._core.store.state.scale<0?r._core.store.state.scale:1),r.height=1.2*r.fontSize/(r._core.store.state.scale<0?r._core.store.state.scale:1),r.backgroundColor={light:"transparent",dark:"transparent"},r.initialWidth=r.width,r.initialHeight=r.height,r.scaleFactor=1,r.scale=s??r._core.store.state.scale,r.zIndex=t.store.currentZIndex,r.editor=r.createEditor(),r}mount(t){null!==t&&!1!==this.isInViewport()&&(t.style.fontFamily=this.fontFamily,t.style.fontSize=`${this.fontSize}pt`,t.style.color=In.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 Sr(null,{state:ge.create({doc:t,plugins:[ln(An)]}),editable:()=>!1,dispatchTransaction:t=>{const e=this.editor.state.apply(t);this.editor.updateState(e),t.docChanged&&(this.content=e.doc.toJSON(),this.adjustSizeOnInput(),t.getMeta("fromRemote")||this._core.store.state.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const e=this.editor.state.schema.nodeFromJSON(t),i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",!0),this.editor.dispatch(i)}}adjustSizeOnInput(){const t=this.elementRef;if(t&&this.isMounted&&t.scrollWidth>0){const e=this.totalWidth,i=this.totalHeight,s=t.scrollHeight;if(this.width=t.scrollWidth*this.scaleFactor,this.height=s*this.scaleFactor,0!==this.rotation){const t=(this.totalWidth-e)/2/this.scale,s=(this.totalHeight-i)/2/this.scale;if(0!==t||0!==s){const e=Math.cos(this.rotation),i=Math.sin(this.rotation),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.state.objects.update(this)}focus(t){if(this.editor){const e=this.editor.state.doc;if(t.x&&t.y){const i=this.editor.posAtCoords({left:t.x,top:t.y});if(i)return this.editor.dispatch(this.editor.state.tr.setSelection(se.create(e,i.pos))),this.editor.focus(),void(r.isIOS()&&this.scrollIntoViewOnIOS())}const i=Math.max(1,e.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(se.create(e,i))),this.editor.focus(),r.isIOS()&&this.scrollIntoViewOnIOS()}}scrollIntoViewOnIOS(){setTimeout((()=>{this.editor&&this.editor.dom&&this.editor.dom.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"})}),300)}edit(e){n.disableInteractiveWidget(),this.uneditedObject=this.clone(),this._core.store.setState("activeTool",t.getTool("text")),this.editor.setProps({editable:()=>!0}),this.isEditing=!0,this._core.rerender(),this.adjustSizeOnInput(),this.focus({x:e?.clientX,y:e?.clientY}),n.enableInteractiveWidget()}save(){requestAnimationFrame((()=>this.adjustSizeOnInput())),this.content=this.editor.state.doc.toJSON(),this.editor.setProps({editable:()=>!1}),this.editor.dom.blur(),this.isEditing=!1,this._core.store.state.objects.consolidateTemporaryItems(),this._core.store.state.objects.update(this),this._core.engine.emitObjectsChange()}handlePointerDown(t){this.isEditing&&t.stopPropagation()}handlePointerMove(t){this.isEditing&&t.stopPropagation()}handlePointerUp(t){this.isEditing&&t.stopPropagation()}copy(){const t=super.copy();return t.editor=t.createEditor(),this.content&&t.setContent(this.content),t}serialize(){const{_core:t,_elementRef:e,_schema:i,element:s,totalWidth:r,totalHeight:n,editor:o,uneditedObject:h,...l}=this,u=structuredClone(l);return s&&"object"==typeof s&&"nodeType"in s&&1===s.nodeType&&(u.element=s.cloneNode(!0)),u}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}}var Rn,Pn,jn={},Un=(Rn||(Rn=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 u(t,e){return[t[0]-e[0],t[1]-e[1]]}function a(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 w(t,e){return t[0]*e[0]+t[1]*e[1]}function g(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 b(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 k(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(u(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 A(t,e,i){return h(t,c(e,i))}const C=[0,0],S=[0,0],B=[0,0];function O(t,e){let s=A(t,v(d(u(t,h(t,[1,1])))),-e),r=[],n=1/13;for(let e=n;e<=1;e+=n)r.push(b(s,t,2*i*e));return r}function T(t,e,s){let r=[],n=1/s;for(let s=n;s<=1;s+=n)r.push(b(e,t,i*s));return r}function E(t,e,i){let s=u(e,i),r=c(s,.5),n=c(s,.51);return[u(t,r),u(t,n),h(t,n),h(t,r)]}function D(t,e,s,r){let n=[],o=A(t,e,s),h=1/r;for(let e=h;e<1;e+=h)n.push(b(o,t,3*i*e));return n}function I(t,e,i){return[h(t,c(e,i)),h(t,c(e,.99*i)),u(t,c(e,.99*i)),u(t,c(e,i))]}function $(t,e,i){return!1===t||void 0===t?0:!0===t?Math.max(e,i):t}function R(t,e={}){let{size:s=16,smoothing:n=.5,thinning:c=.5,simulatePressure:g=!0,easing:v=t=>t,start:y={},end:b={},last:M=!1}=e,{cap:A=!0,easing:R=t=>t*(2-t)}=y,{cap:P=!0,easing:j=t=>--t*t*t+1}=b;if(0===t.length||s<=0)return[];let U,N=t[t.length-1].runningLength,F=$(y.taper,s,N),_=$(b.taper,s,N),L=(s*n)**2,z=[],Y=[],W=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,g,s),X=r(s,c,t[t.length-1].pressure,v),H=t[0].vector,J=t[0].point,V=J,Q=J,q=V,K=!1;for(let e=0;e<t.length;e++){let{pressure:n}=t[e],{point:d,vector:y,distance:b,runningLength:M}=t[e],A=e===t.length-1;if(!A&&N-M<3)continue;c?(g&&(n=o(W,b,s)),X=r(s,c,n,v)):X=s/2,void 0===U&&(U=X);let O=M<F?R(M/F):1,T=N-M<_?j((N-M)/_):1;X=Math.max(.01,X*Math.min(O,T));let E=(A?t[e]:t[e+1]).vector,D=A?1:w(y,E),I=null!==D&&D<0;if(w(y,H)<0&&!K||I){p(C,H),f(C,C,X);for(let t=0;t<=1;t+=.07692307692307693)a(S,d,C),k(S,S,d,i*t),Q=[S[0],S[1]],z.push(Q),l(B,d,C),k(B,B,d,i*-t),q=[B[0],B[1]],Y.push(q);J=Q,V=q,I&&(K=!0)}else K=!1,A?(p(C,y),f(C,C,X),z.push(u(d,C)),Y.push(h(d,C))):(x(C,E,y,D),p(C,C),f(C,C,X),a(S,d,C),Q=[S[0],S[1]],(e<=1||m(J,Q)>L)&&(z.push(Q),J=Q),l(B,d,C),q=[B[0],B[1]],(e<=1||m(V,q)>L)&&(Y.push(q),V=q),W=n,H=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(!F&&!_||M)return O(G,U||X)}else{F||_&&1===t.length||(A?tt.push(...T(G,Y[0],13)):tt.push(...E(G,z[0],Y[0])));let e=d(function(t){return[-t[0],-t[1]]}(t[t.length-1].vector));_||F&&1===t.length?et.push(Z):P?et.push(...D(Z,e,X,29)):et.push(...I(Z,e,X))}return z.concat(et,Y.reverse(),tt)}const P=[0,0];function j(t){return null!=t&&t>=0}function U(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 u=[{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=u[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(g(d.point,e))continue;let i=y(e,d.point);if(f+=i,t<p&&!c){if(f<r)continue;c=!0}a(P,d.point,e),d={point:e,pressure:j(l[t][2])?l[t][2]:.5,vector:v(P),distance:i,runningLength:f},u.push(d)}return u[0].vector=u[1]?.vector||[0,0],u}function N(t,e={}){return R(U(t,e),e)}t.default=N,t.getStroke=N,t.getStrokeOutlinePoints=R,t.getStrokePoints=U}(jn)),jn);class Nn{static average(t,e){return(t+e)/2}}class Fn extends s{__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 Fn;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.options=e,i.points=e?.points??[],i.translateX=e?.translateX??0,i.translateY=e?.translateY??0,i.scale=e?.scale??1,i.strokeWidth=e?.strokeWidth??8,i.fill=e?.fill??{light:"#000000",dark:"#ffffff"},i.opacity=e?.opacity??1,i.zIndex=t.store.currentZIndex,i.d=i.generateSvgPath(),i.updateDimensions(),i}resize(t,e,i,s){if(i<=1||s<=1)return;const 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.state.objects.update(this)}rotate(t){this.rotation=t,this._adjustedPoints=null,this._core.store.state.objects.update(this)}move(t,e,i,s){const 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.state.objects.update(this)}hitTest(t,e){const i=this.strokeWidth/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),1===this._adjustedPoints.length){const s=this._adjustedPoints[0];return this.pointToLineSegmentDistance(t,e,s[0],s[1],s[0],s[1])<=i}for(let s=0;s<this._adjustedPoints.length-1;s++){const 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 s=[{x:t.bottomLeft.x,y:t.bottomLeft.y},{x:t.bottomRight.x,y:t.bottomRight.y},{x:t.topRight.x,y:t.topRight.y},{x:t.topLeft.x,y:t.topLeft.y}];for(const[t,e]of this._adjustedPoints)if(i.isPointInPolygon({x:t,y:e},s))return!0;for(const t of s)if(this.hitTest(t.x,t.y))return!0;for(let t=0;t<this._adjustedPoints.length-1;t++){const e={x:this._adjustedPoints[t][0],y:this._adjustedPoints[t][1]},r={x:this._adjustedPoints[t+1][0],y:this._adjustedPoints[t+1][1]};for(let t=0;t<s.length;t++)if(i.intersectLines(e,r,s[t],s[(t+1)%s.length]))return!0}for(let t=0;t<this._adjustedPoints.length-1;t++){const i=this._adjustedPoints[t],r=this._adjustedPoints[t+1];for(let t=0;t<s.length;t++){const n=s[t],o=s[(t+1)%s.length],h=this.pointToLineSegmentDistance(n.x,n.y,i[0],i[1],r[0],r[1]),l=this.pointToLineSegmentDistance(o.x,o.y,i[0],i[1],r[0],r[1]),u=this.pointToLineSegmentDistance(i[0],i[1],n.x,n.y,o.x,o.y),a=this.pointToLineSegmentDistance(r[0],r[1],n.x,n.y,o.x,o.y);if(Math.min(h,l,u,a)<=e)return!0}}return!1}updatePosition(t,e){this.translateX=t,this.translateY=e,this._adjustedPoints=null,this._core.store.state.objects.update(this)}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 u,a,c=-1;0!==l&&(c=((t-i)*o+(e-s)*h)/l),c<0?(u=i,a=s):c>1?(u=r,a=n):(u=i+c*o,a=s+c*h);const f=t-u,d=e-a;return Math.sqrt(f*f+d*d)}updateDimensions(){const t=this.points.map((([t,e])=>[t*Math.cos(this.rotation)-e*Math.sin(this.rotation),t*Math.sin(this.rotation)+e*Math.cos(this.rotation)])),e=Math.min(...t.map((t=>t[0]-this.strokeWidth/2))),i=Math.min(...t.map((t=>t[1]-this.strokeWidth/2))),s=Math.max(...t.map((t=>t[0]+this.strokeWidth/2))),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 Un.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)} ${Nn.average(r[0],n[0]).toFixed(2)},${Nn.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+=`${Nn.average(s[0],r[0]).toFixed(2)},${Nn.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 u=1/0;if(1===this._adjustedPoints.length){const t=this._adjustedPoints[0],e=h-t[0],i=l-t[1];u=Math.sqrt(e*e+i*i)}else for(let t=0;t<this._adjustedPoints.length-1;t++){const e=this._adjustedPoints[t],i=this._adjustedPoints[t+1],s=this.pointToLineSegmentDistance(h,l,e[0],e[1],i[0],i[1]);s<u&&(u=s)}const a=u<=s;if(r&&a){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 u=1/0;if(1===this._adjustedPoints.length){const t=this._adjustedPoints[0],e=o-t[0],i=l-t[1];u=Math.sqrt(e*e+i*i)}else for(let t=0;t<this._adjustedPoints.length-1;t++){const e=this._adjustedPoints[t],i=this._adjustedPoints[t+1],s=this.pointToLineSegmentDistance(o,l,e[0],e[1],i[0],i[1]);s<u&&(u=s)}u<=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=!a}return null}}class _n extends s{__class__="KritzelImage";src="";maxWidth=300;maxHeight=300;maxCompressionSize=300;isDebugInfoVisible=!0;constructor(t){super(),this.src=t?.src||"",this.x=t?.x||0,this.y=t?.y||0,this.translateX=t?.translateX||0,this.translateY=t?.translateY||0,this.scale=t?.scale||1}static create(t){const e=new _n;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.x=0,e.y=0,e.translateX=0,e.translateY=0,e.scale=e._core.store.state.scale,e.zIndex=t.store.currentZIndex,e}resize(t,e,i,s){if(i<=1||s<=1)return;const r=s/this.height;this.width=this.width*r,this.height=this.height*r,this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this)}calculateScaledDimensions(t){let e=t.width,i=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const s=Math.min(this.maxWidth/t.width,this.maxHeight/t.height);e=t.width*s,i=t.height*s}return{scaledWidth:e,scaledHeight:i}}}class Ln extends s{__class__="KritzelLine";startX;startY;endX;endY;controlX;controlY;stroke;strokeWidth;scale=1;options;startAnchor;endAnchor;arrows;isVisible=!0;isDebugInfoVisible=!0;isCompleted=!1;_adjustedPoints=null;_clipInfo=null;get d(){return void 0!==this.controlX&&void 0!==this.controlY?`M ${this.startX} ${this.startY} Q ${this.controlX} ${this.controlY} ${this.endX} ${this.endY}`:`M ${this.startX} ${this.startY} L ${this.endX} ${this.endY}`}get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t){super(),this.options=t,this.startX=t?.startX??0,this.startY=t?.startY??0,this.endX=t?.endX??0,this.endY=t?.endY??0,this.controlX=t?.controlX,this.controlY=t?.controlY,this.translateX=t?.translateX??0,this.translateY=t?.translateY??0,this.scale=t?.scale??1,this.strokeWidth=t?.strokeWidth??4,this.stroke=t?.stroke??{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 Ln;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.options=e,i.startX=e?.startX??0,i.startY=e?.startY??0,i.endX=e?.endX??0,i.endY=e?.endY??0,i.controlX=e?.controlX,i.controlY=e?.controlY,i.translateX=e?.translateX??0,i.translateY=e?.translateY??0,i.scale=e?.scale??1,i.strokeWidth=e?.strokeWidth??4,i.stroke=e?.stroke??{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:u}=this.calculateBoundingBox();this.width=l-o,this.height=u-h,this.x=o,this.y=h,this.translateX=t,this.translateY=e,this._adjustedPoints=null,this._clipInfo=null,this._core.store.state.objects.update(this),this._core.anchorManager.updateAnchorsForObject(this.id),this.startAnchor&&this._core.anchorManager.updateAnchorsForObject(this.startAnchor.objectId),this.endAnchor&&this._core.anchorManager.updateAnchorsForObject(this.endAnchor.objectId)}rotate(t){this.rotation=t,this._adjustedPoints=null,this._clipInfo=null,this._core.store.state.objects.update(this)}move(t,e,i,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.state.objects.update(this)}hitTest(t,e){const i=Math.max(this.strokeWidth,20)/this.scale/2;if(null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints()),void 0!==this.controlX&&void 0!==this.controlY){const s=this.getClipInfo();return this.pointToBezierDistance(t,e,s.start?.t??0,s.end?.t??1)<=i}const s=this.getClipInfo(),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 s=this.getClipInfo(),r=[{x:t.bottomLeft.x,y:t.bottomLeft.y},{x:t.bottomRight.x,y:t.bottomRight.y},{x:t.topRight.x,y:t.topRight.y},{x:t.topLeft.x,y:t.topLeft.y}],n=s.start?[s.start.x,s.start.y]:this._adjustedPoints[0],o=s.end?[s.end.x,s.end.y]:this._adjustedPoints[1],h=[n,o];for(const[t,e]of h)if(i.isPointInPolygon({x:t,y:e},r))return!0;for(const t of r)if(this.hitTest(t.x,t.y))return!0;if(void 0!==this.controlX&&void 0!==this.controlY){const t=this._adjustedPoints[0],n=this._adjustedPoints[1],o=this.computeAdjustedControlPoint(),h=s.start?.t??0,l=s.end?.t??1,u=20;for(let s=0;s<=u;s++){const a=h+s/u*(l-h),c=1-a,f=c*c*t[0]+2*c*a*o[0]+a*a*n[0],d=c*c*t[1]+2*c*a*o[1]+a*a*n[1];if(i.isPointInPolygon({x:f,y:d},r))return!0;for(let t=0;t<r.length;t++){const i=r[t],s=r[(t+1)%r.length];if(this.pointToLineSegmentDistance(f,d,i.x,i.y,s.x,s.y)<=e)return!0}}return!1}const l={x:n[0],y:n[1]},u={x:o[0],y:o[1]};for(let t=0;t<r.length;t++){const s=r[t],n=r[(t+1)%r.length];if(i.intersectLines(l,u,s,n))return!0;const o=this.pointToLineSegmentDistance(s.x,s.y,l.x,l.y,u.x,u.y),h=this.pointToLineSegmentDistance(n.x,n.y,l.x,l.y,u.x,u.y),a=this.pointToLineSegmentDistance(l.x,l.y,s.x,s.y,n.x,n.y),c=this.pointToLineSegmentDistance(u.x,u.y,s.x,s.y,n.x,n.y);if(Math.min(o,h,a,c)<=e)return!0}return!1}updatePosition(t,e){this.translateX=t,this.translateY=e,this._adjustedPoints=null,this._clipInfo=null,this._core.store.state.objects.update(this)}updateEndpoint(t,e,i){"start"===t?(this.startX=e,this.startY=i):(this.endX=e,this.endY=i);const s=this.width,r=this.height,{minX:n,minY:o,maxX:h,maxY:l}=this.calculateBoundingBox(),u=n-this.x,a=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 w=Math.cos(this.rotation),g=Math.sin(this.rotation),m=u+d,v=a+p,y=m*g+v*w-p;this.translateX+=(m*w-v*g-d)/this.scale,this.translateY+=y/this.scale,this._adjustedPoints=null,this._clipInfo=null,this._core.store.state.objects.update(this)}updateControlPoint(t,e){this.controlX=t,this.controlY=e;const i=this.width,s=this.height,{minX:r,minY:n,maxX:o,maxY:h}=this.calculateBoundingBox(),l=r-this.x,u=n-this.y,a=o-r,c=h-n,f=(a-i)/2,d=(c-s)/2;this.x=r,this.y=n,this.width=a,this.height=c;const p=Math.cos(this.rotation),w=Math.sin(this.rotation),g=l+f,m=u+d,v=g*w+m*p-d;this.translateX+=(g*p-m*w-f)/this.scale,this.translateY+=v/this.scale,this._adjustedPoints=null,this._clipInfo=null,this._core.store.state.objects.update(this)}computeAdjustedPoints(){const t=[[this.startX,this.startY],[this.endX,this.endY]],e=this.rotation,i=Math.cos(e),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 u,a,c=-1;0!==l&&(c=((t-i)*o+(e-s)*h)/l),c<0?(u=i,a=s):c>1?(u=r,a=n):(u=i+c*o,a=s+c*h);const f=t-u,d=e-a;return Math.sqrt(f*f+d*d)}pointToBezierDistance(t,e,i=0,s=1){null===this._adjustedPoints&&(this._adjustedPoints=this.computeAdjustedPoints());const r=this._adjustedPoints[0],n=this._adjustedPoints[1],o=this.computeAdjustedControlPoint();let h=1/0;for(let l=0;l<=20;l++){const u=i+l/20*(s-i),a=1-u,c=t-(a*a*r[0]+2*a*u*o[0]+u*u*n[0]),f=e-(a*a*r[1]+2*a*u*o[1]+u*u*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,u=this.controlY-h;return[(o+l*e-u*i-this.x)/this.scale+this.translateX,(h+l*i+u*e-this.y)/this.scale+this.translateY]}get rotatedPolygon(){const t=this.padding,{minX:e,minY:i,maxX:s,maxY:r}=Ln.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,u={x:n,y:o},a={x:h,y:o},c={x:h,y:l},f={x:n,y:l},d=this.totalWidth/2,p=this.totalHeight/2,w=this.rotation,g=Math.cos(w),m=Math.sin(w),v=t=>({x:((t.x-d)*g-(t.y-p)*m+d)/this.scale+this.translateX,y:((t.x-d)*m+(t.y-p)*g+p)/this.scale+this.translateY});return{topLeft:v(u),topRight:v(a),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),u=Math.max(t,i),a=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),u=Math.max(u,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),a=Math.max(a,i)}}}const c=o/2;return{minX:h-c,minY:l-c,maxX:u+c,maxY:a+c}}calculateBoundingBox(){return Ln.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 In.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 zn extends s{__class__="KritzelGroup";childIds=[];unchangedChildSnapshots=new Map;snapshotRotation=0;snapshotTranslateX=0;snapshotTranslateY=0;snapshotTotalWidth=0;snapshotTotalHeight=0;snapshotScale=1;get children(){return this.childIds.map((t=>{const e=this._core.store.state.objects.filter((e=>e.id===t));return e.length>0?e[0]:null})).filter((t=>null!==t))}get length(){return this.childIds.length}static create(t){const e=new zn;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.scale=t.store.state.scale,e.zIndex=t.store.currentZIndex,e}static createFromObjects(t,e){const i=zn.create(t);return e.forEach((t=>{i.childIds.push(t.id)})),i.refreshBoundingBox(),i.captureChildSnapshots(),i}static findParentGroup(t,e){const i=t.store.state.objects.filter((t=>"KritzelGroup"===t.__class__));for(const t of i)if(t.childIds.includes(e))return t;return null}addChild(t){this.childIds.includes(t.id)||(this.childIds.push(t.id),this.refreshBoundingBox(),this.captureChildSnapshots())}removeChild(t){const e=this.childIds.indexOf(t);-1!==e&&(this.childIds.splice(e,1),this.refreshBoundingBox(),this.captureChildSnapshots())}ungroup(){return this.children}finalize(){this.refreshBoundingBox(),this.captureChildSnapshots()}refreshBoundingBox(){if(0===this.children.length)return this.width=0,this.height=0,this.translateX=0,void(this.translateY=0);if(1===this.children.length){const t=this.children[0];return this.translateX=t.boundingBox.x,this.translateY=t.boundingBox.y,this.width=t.boundingBox.width*this.scale,void(this.height=t.boundingBox.height*this.scale)}const t=this.rotation,e=Math.cos(-t),i=Math.sin(-t);let s=1/0,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,u=(n+o)/2,a=Math.cos(t),c=Math.sin(t),f=l*c+u*a;this.translateX=l*a-u*c-(this.width/this.scale+2*this.padding)/2,this.translateY=f-(this.height/this.scale+2*this.padding)/2}captureChildSnapshots(){this.unchangedChildSnapshots.clear(),this.snapshotRotation=this.rotation,this.snapshotTranslateX=this.translateX,this.snapshotTranslateY=this.translateY,this.snapshotTotalWidth=this.totalWidth,this.snapshotTotalHeight=this.totalHeight,this.snapshotScale=this.scale||1,this.children.forEach((t=>{this.unchangedChildSnapshots.set(t.id,{id:t.id,translateX:t.translateX,translateY:t.translateY,rotation:t.rotation,width:t.width,height:t.height,totalWidth:t.totalWidth,totalHeight:t.totalHeight,scale:t.scale})}))}move(t,e,i,s){const 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.state.objects.transaction((()=>{this._core.store.state.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=i/this.width,n=s/this.height,o=this.translateX+this.totalWidth/2/this.scale,h=this.translateY+this.totalHeight/2/this.scale,l=t+(i+2*this.padding)/2/this.scale,u=e+(s+2*this.padding)/2/this.scale,a=this.rotation,c=Math.cos(-a),f=Math.sin(-a),d=Math.cos(a),p=Math.sin(a);this._core.store.state.objects.transaction((()=>{this.children.forEach((t=>{const e=t.translateX+t.totalWidth/2/t.scale-o,i=t.translateY+t.totalHeight/2/t.scale-h,s=(e*c-i*f)*r,w=(e*f+i*c)*n,g=l+(s*d-w*p),m=u+(s*p+w*d),v=t.rotation-a,y=Math.cos(v),b=Math.sin(v),k=Math.sqrt(Math.pow(r*y,2)+Math.pow(n*b,2)),M=Math.sqrt(Math.pow(r*b,2)+Math.pow(n*y,2)),x=t.width*k,A=t.height*M;t.resize(g-(x+2*t.padding)/2/t.scale,m-(A+2*t.padding)/2/t.scale,x,A),this._core.anchorManager.updateAnchorsForObject(t.id)})),this.refreshBoundingBox(),this.captureChildSnapshots(),this._core.store.state.objects.update(this)}))}rotate(t){this.rotation=t;const e=this.translateX+this.totalWidth/2/this.scale,i=this.translateY+this.totalHeight/2/this.scale,s=t-this.snapshotRotation,r=Math.cos(s),n=Math.sin(s);this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.children.forEach((o=>{const h=this.unchangedChildSnapshots.get(o.id);if(!h)return;const l=this.getOffsetXToCenterFromSnapshot(h),u=this.getOffsetYToCenterFromSnapshot(h),a=n*l+r*u;o.translateX=e+(r*l-n*u)-o.totalWidth/2/o.scale,o.translateY=i+a-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=zn.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,...o}=this,h=structuredClone(o);return h.unchangedChildSnapshots=Object.fromEntries(this.unchangedChildSnapshots),h}deserialize(t){return super.deserialize(t),t.unchangedChildSnapshots&&(this.unchangedChildSnapshots=new Map(Object.entries(t.unchangedChildSnapshots))),this}update(){this._core.store.state.objects.update(this)}updateWorkspaceId(t){this.workspaceId=t,this.children.forEach((e=>{e.workspaceId=t,e instanceof zn&&e.updateWorkspaceId(t)}))}}!function(t){t[t.Left=0]="Left",t[t.Middle=1]="Middle",t[t.Right=2]="Right"}(Pn||(Pn={}));class Yn{static isRightClick(t){return t.button===Pn.Right}static isLeftClick(t){return t.button===Pn.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()},u=()=>{h()},a=()=>{h()},c=()=>{n.removeEventListener("pointermove",l),n.removeEventListener("pointerup",u),n.removeEventListener("pointercancel",a)};return n.addEventListener("pointermove",l,{passive:!0}),n.addEventListener("pointerup",u,{once:!0}),n.addEventListener("pointercancel",a,{once:!0}),h}}class Wn{__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 Xn extends Wn{color=Cn[0];size=6;opacity=1;palette=[...Cn];_currentPathId=null;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&Yn.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=Fn.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.state.objects.insert(r)}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=Fn.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.state.objects.insert(o)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&this._currentPathId){const e=this._core.store.state.objects.filter((t=>t.id===this._currentPathId)),i=e.length>0?e[0]:null;if(i){const e=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?e:1,n=Fn.create(this._core,{points:[...i.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:e,fill:this.color,strokeWidth:this.size,opacity:this.opacity});n.id=i.id,n.workspaceId=i.workspaceId,n.zIndex=i.zIndex,n.isCompleted=!1,this._core.store.state.objects.update(n)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length&&this._currentPathId){const e=this._core.store.state.objects.filter((t=>t.id===this._currentPathId)),i=e.length>0?e[0]:null;if(i){const e=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?e:1,n=Math.round((t[0].clientX-this._core.store.offsetX)/r),o=Math.round((t[0].clientY-this._core.store.offsetY)/r),h=Fn.create(this._core,{points:[...i.points,[n,o]],translateX:-this._core.store.state.translateX/r,translateY:-this._core.store.state.translateY/r,scale:s?1:e,fill:this.color,strokeWidth:this.size,opacity:this.opacity});h.id=i.id,h.workspaceId=i.workspaceId,h.zIndex=i.zIndex,h.isCompleted=!1,this._core.store.state.objects.update(h)}}}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentPathId)){const t=this._core.store.state.objects.filter((t=>t.id===this._currentPathId)),e=t.length>0?t[0]:null;e&&(e.isCompleted=!0,this._core.store.state.objects.update(e),this._core.engine.emitObjectsChange()),this._currentPathId=null}if(("touch"===t.pointerType||"pen"===t.pointerType)&&this._core.store.state.isDrawing&&(this._core.store.state.isDrawing=!1,this._currentPathId)){const t=this._core.store.state.objects.filter((t=>t.id===this._currentPathId)),e=t.length>0?t[0]:null;e&&(e.isCompleted=!0,this._core.store.state.objects.update(e),this._core.engine.emitObjectsChange()),this._currentPathId=null}}}class Hn extends s{__class__="KritzelSelectionGroup";objectIds=[];unchangedObjectSnapshots=new Map;snapshotRotation=0;minX;maxX;minY;maxY;get objects(){return this.objectIds.map((t=>{const e=this._core.store.state.objects.filter((e=>e.id===t));return e.length>0?e[0]:null})).filter((t=>null!==t))}get length(){return this.objectIds.length}static create(t){const e=new Hn;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.scale=t.store.state.scale,e.zIndex=99999,e}addOrRemove(t){const e=this.objectIds.findIndex((e=>e===t.id));-1===e?this.objectIds.push(t.id):this.objectIds.splice(e,1),this.captureUnchangedSnapshots(),this.refreshObjectDimensions()}beginTransform(){this.refreshObjectDimensions(),this.captureUnchangedSnapshots(),this.objects.forEach((t=>{t instanceof zn&&t.finalize()}))}deselectAllChildren(){this.objects.forEach((t=>t.isSelected=!1))}updateWorkspaceId(t){this.workspaceId=t,this.objects.forEach((e=>e.workspaceId=t))}updateZIndices(t){this.objects.forEach(((e,i)=>{e.zIndex=t+i}))}updatePosition(t,e){this.objects.forEach((i=>{i.updatePosition(t+(i.translateX-this.translateX),e+(i.translateY-this.translateY))})),this.unchangedObjectSnapshots.forEach((i=>{const s=i.translateY-this.translateY;i.translateX=t+(i.translateX-this.translateX),i.translateY=e+s})),this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this)}captureUnchangedSnapshots(){this.unchangedObjectSnapshots.clear(),this.snapshotRotation=this.rotation,this.objects.forEach((t=>{this.unchangedObjectSnapshots.set(t.id,{id:t.id,translateX:t.translateX,translateY:t.translateY,rotation:t.rotation,width:t.width,height:t.height,totalWidth:t.totalWidth,totalHeight:t.totalHeight,scale:t.scale})}))}serialize(){const{_core:t,_elementRef:e,element:i,totalWidth:s,totalHeight:r,unchangedObjectSnapshots:n,...o}=this,h=structuredClone(o);return i&&"object"==typeof i&&"nodeType"in i&&1===i.nodeType&&(h.element=i.cloneNode(!0)),h.unchangedObjectSnapshots=Object.fromEntries(this.unchangedObjectSnapshots),h}deserialize(t){return super.deserialize(t),t.unchangedObjectSnapshots&&(this.unchangedObjectSnapshots=new Map(Object.entries(t.unchangedObjectSnapshots))),this}update(){this._core.store.state.objects.update(this)}move(t,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.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.objects.forEach((r=>{r.move(t,e,i,s),this._core.anchorManager.updateAnchorsForObject(r.id)}))})),this.unchangedObjectSnapshots.forEach((t=>{t.translateX+=r,t.translateY+=n}))}resize(t,e,i,s){const r=i/this.width,n=s/this.height,o=this.translateX+this.totalWidth/2/this.scale,h=this.translateY+this.totalHeight/2/this.scale,l=t+(i+2*this.padding)/2/this.scale,u=e+(s+2*this.padding)/2/this.scale,a=this.rotation,c=Math.cos(-a),f=Math.sin(-a),d=Math.cos(a),p=Math.sin(a);this._core.store.state.objects.transaction((()=>{this.objects.forEach((t=>{const e=t.translateX+t.totalWidth/2/t.scale-o,i=t.translateY+t.totalHeight/2/t.scale-h,s=(e*c-i*f)*r,w=(e*f+i*c)*n,g=l+(s*d-w*p),m=u+(s*p+w*d),v=t.rotation-a,y=Math.cos(v),b=Math.sin(v),k=Math.sqrt(Math.pow(r*y,2)+Math.pow(n*b,2)),M=Math.sqrt(Math.pow(r*b,2)+Math.pow(n*y,2)),x=t.width*k,A=t.height*M;t.resize(g-(x+2*t.padding)/2/t.scale,m-(A+2*t.padding)/2/t.scale,x,A),this._core.anchorManager.updateAnchorsForObject(t.id)})),this.refreshObjectDimensions(),this.captureUnchangedSnapshots(),this._core.store.state.objects.update(this)}))}rotate(t){this.rotation=t;const e=this.translateX+this.totalWidth/2/this.scale,i=this.translateY+this.totalHeight/2/this.scale,s=t-this.snapshotRotation,r=Math.cos(s),n=Math.sin(s);this._core.store.state.objects.transaction((()=>{this._core.store.state.objects.update(this),this.objects.forEach((o=>{const h=this.unchangedObjectSnapshots.get(o.id);if(!h)return;const l=this.getOffsetXToCenterFromSnapshot(h),u=this.getOffsetYToCenterFromSnapshot(h),a=n*l+r*u;o.translateX=e+(r*l-n*u)-o.totalWidth/2/o.scale,o.translateY=i+a-o.totalHeight/2/o.scale,o.rotate(1===this.objects.length?t:h.rotation+s)}))}))}copy(){const t=Hn.create(this._core);return this.objects.sort(((t,e)=>t.zIndex-e.zIndex)).forEach((e=>{const i=e.copy();t.addOrRemove(i)})),t.captureUnchangedSnapshots(),1===this.objects.length&&(t.rotation=this.objects[0].rotation),t}refreshObjectDimensions(){if(1===this.objects.length){const t=this.objects[0];this.minX=t.boundingBox.x/this.scale,this.maxX=t.boundingBox.x/this.scale+t.boundingBox.width,this.minY=t.boundingBox.y/this.scale,this.maxY=t.boundingBox.y/this.scale+t.boundingBox.height,this.translateX=(this.minX-this.padding)*this.scale,this.translateY=(this.minY-this.padding)*this.scale,this.width=(this.maxX-this.minX-this.padding)*this.scale,this.height=(this.maxY-this.minY-this.padding)*this.scale}else{const t=this.rotation,e=Math.cos(-t),i=Math.sin(-t);let s=1/0,r=-1/0,n=1/0,o=-1/0;this.objects.forEach((t=>{const h=t.rotatedPolygon;[h.topLeft,h.topRight,h.bottomRight,h.bottomLeft].forEach((t=>{const h=t.x*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,u=(n+o)/2,a=Math.cos(t),c=Math.sin(t),f=l*c+u*a;this.translateX=l*a-u*c-(this.width/this.scale+2*this.padding)/2,this.translateY=f-(this.height/this.scale+2*this.padding)/2}this._core.store.state.objects.update(this)}getOffsetXToCenterFromSnapshot(t){return t.translateX+t.totalWidth/t.scale/2-(this.translateX+this.totalWidth/this.scale/2)}getOffsetYToCenterFromSnapshot(t){return t.translateY+t.totalHeight/t.scale/2-(this.translateY+this.totalHeight/this.scale/2)}hitTest(t,e){if(1===this.objects.length&&"KritzelLine"===this.objects[0].__class__)return this.objects[0].hitTest(t,e);const s=this.rotatedPolygon;return!!i.isPointInPolygon({x:t,y:e},[s.topLeft,s.topRight,s.bottomRight,s.bottomLeft])||this.objects.some((i=>i.hitTest(t,e)))}}class Jn extends Wn{color=Cn[0];size=4;opacity=1;palette=[...Cn];arrows;_startX=0;_startY=0;constructor(t){super(t)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&Yn.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=Ln.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._core.store.state.objects.insert(o)}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=Ln.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._core.store.state.objects.insert(o)}}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing){const e=this._core.store.currentLine;if(e){const i=this._core.store.state.scale,s=this._core.store.state.lockDrawingScale,r=s?i:1,n=Ln.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.state.objects.update(n)}}if("touch"===t.pointerType||"pen"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(1===t.length){const e=this._core.store.currentLine;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=Ln.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.state.objects.update(h)}}}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&this._core.store.state.isDrawing){this._core.store.state.isDrawing=!1;const t=this._core.store.currentLine;t&&(t.isCompleted=!0,this._core.store.state.objects.update(t),this._core.engine.emitObjectsChange(),this.selectLineAndSwitchTool(t))}if(("touch"===t.pointerType||"pen"===t.pointerType)&&this._core.store.state.isDrawing){this._core.store.state.isDrawing=!1;const t=this._core.store.currentLine;t&&(t.isCompleted=!0,this._core.store.state.objects.update(t),this._core.engine.emitObjectsChange(),this.selectLineAndSwitchTool(t))}}selectLineAndSwitchTool(e){const i=Hn.create(this._core);i.addOrRemove(e),i.isSelected=!0,i.rotation=e.rotation,this._core.addSelectionGroup(i),this._core.store.setState("activeTool",t.getTool("selection")),this._core.rerender()}}class Vn extends Wn{touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&Yn.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.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)})),t.length>0&&this._core.rerender(),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange()}if(("touch"===t.pointerType||"pen"===t.pointerType)&&(clearTimeout(this.touchStartTimeout),this._core.store.state.isErasing)){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)})),t.length>0&&this._core.rerender(),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange()}}}function Qn(t,e){return new Promise((function(i,s){let r;return qn(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 qn=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),u=n+l+2+12*s.getUint16(n+l,h);for(let t=n+l+2;t<u;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 Kn={},Gn={get exports(){return Kn},set exports(t){Kn=t}};!function(){var t,e,i={};Gn.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 u=s(h,n+=4);s(h,n+=2);var a=r(h,n+=2),c=r(h,n+=4);n+=4,n=c;for(var f=0;f<u;f++){r(h,n),n+=4,n+=4,n+=4,r(h,n+=4),a=r(h,n+=4);var d=r(h,n+=4),p=s(h,n+=4),w=s(h,n+2),g=s(h,n+4);n+=6;var m=r(h,n+=8);n+=4,n+=p+w+g,i._readLocal(h,m,o,a,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 u=h(t,e+=2);l(t,e+=2),l(t,e+=4),e+=4;var a=h(t,e+=8),c=h(t,e+=2),f=i.bin.readUTF8(t,e+=2,a);if(e+=a,e+=c,o)s[f]={size:n,csize:r};else{var d=new Uint8Array(t.buffer,e);if(0==u)s[f]=new Uint8Array(d.buffer.slice(e,e+r));else{if(8!=u)throw"unknown compression method: "+u;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,u=t[h],a=i.crc.crc(u,0,u.length);o[h]={cpr:l,usize:u.length,crc:a,file:l?i.deflateRaw(u):u}}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 w=0,g=f;for(var h in o)p=o[h],d.push(f),f=i._writeHeader(c,f,h,p,1,d[w++]);var m=f-g;return r(c,f,101010256),f+=4,n(c,f+=4,w),n(c,f+=2,w),r(c,f+=2,m),r(c,f+=4,g),f+=4,f+=2,c.buffer},i._noNeed=function(t){var e=t.split(".").pop().toLowerCase();return-1!="png,jpg,jpeg,zip".indexOf(e)},i._writeHeader=function(t,e,s,r,n,o){var h=i.bin.writeUint,l=i.bin.writeUshort,u=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,u.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(u,e),e+=u.length),e},i.crc={table:function(){for(var t=new Uint32Array(256),e=0;e<256;e++){for(var i=e,s=0;s<8;s++)1&i?i=3988292384^i>>>1:i>>>=1;t[e]=i}return t}(),update:function(t,e,s,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,u=0,a=s<<3,c=0,f=t.length;if(0==r){for(;u<f;)l(e,a,u+(A=Math.min(65535,f-u))==f?1:0),a=i.F._copyExact(t,u,A,e,a+8),u+=A;return a>>>3}var d=o.lits,p=o.strt,w=o.prev,g=0,m=0,v=0,y=0,b=0,k=0;for(f>2&&(p[k=i.F._hash(t,0)]=0),u=0;u<f;u++){if(b=k,u+1<f-2){k=i.F._hash(t,u+1);var M=u+1&32767;w[M]=p[k],p[k]=M}if(c<=u){(g>14e3||m>26697)&&f-u>100&&(c<u&&(d[g]=u-c,g+=2,c=u),a=i.F._writeBlock(u==f-1||c==f?1:0,d,g,y,t,v,u-v,e,a),g=m=y=0,v=u);var x=0;u<f-2&&(x=i.F._bestMatch(t,u,w,b,Math.min(n[2],f-u),n[3]));var A=x>>>16,C=65535&x;if(0!=x){C=65535&x;var S=h(A=x>>>16,o.of0);o.lhst[257+S]++;var B=h(C,o.df0);o.dhst[B]++,y+=o.exb[S]+o.dxb[B],d[g]=A<<23|u-c,d[g+1]=C<<16|S<<8|B,g+=2,c=u+A}else o.lhst[t[u]]++;m++}}for(v==u&&0!=t.length||(c<u&&(d[g]=u-c,g+=2,c=u),a=i.F._writeBlock(1,d,g,y,t,v,u-v,e,a),g=0,m=0,g=m=y=0,v=u);7&a;)a++;return a>>>3},i.F._bestMatch=function(t,e,s,r,n,o){var h=32767&e,l=s[h],u=h-l+32768&32767;if(l==h||r!=i.F._hash(t,e-u))return 0;for(var a=0,c=0,f=Math.min(32767,e);u<=f&&0!=--o&&l!=h;){if(0==a||t[e+a]==t[e+a-u]){var d=i.F._howLong(t,e,u);if(d>a){if(c=u,(a=d)>=n)break;u+2<d&&(d=u+2);for(var p=0,w=0;w<d-2;w++){var g=e-u+w+32768&32767,m=g-s[g]+32768&32767;m>p&&(p=m,l=g)}}}u+=(h=l)-(l=s[h])+32768&32767}return a<<16|c},i.F._howLong=function(t,e,i){if(t[e]!=t[e-i]||t[e+1]!=t[e+1-i]||t[e+2]!=t[e+2-i])return 0;var s=e,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,u){var a,c,f,d,p,w,g,m,v,y=i.F.U,b=i.F._putsF,k=i.F._putsE;y.lhst[256]++,c=(a=i.F.getTrees())[0],f=a[1],d=a[2],p=a[3],w=a[4],g=a[5],m=a[6],v=a[7];var M=32+(u+3&7?8-(u+3&7):0)+(h<<3),x=r+i.F.contSize(y.fltree,y.lhst)+i.F.contSize(y.fdtree,y.dhst),A=r+i.F.contSize(y.ltree,y.lhst)+i.F.contSize(y.dtree,y.dhst);A+=14+3*g+i.F.contSize(y.itree,y.ihst)+(2*y.ihst[16]+3*y.ihst[17]+7*y.ihst[18]);for(var C=0;C<286;C++)y.lhst[C]=0;for(C=0;C<30;C++)y.dhst[C]=0;for(C=0;C<19;C++)y.ihst[C]=0;var S=M<x&&M<A?0:x<A?1:2;if(b(l,u,t),b(l,u+1,S),u+=3,0==S){for(;7&u;)u++;u=i.F._copyExact(n,o,h,l,u)}else{var B,O;if(1==S&&(B=y.fltree,O=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,O=y.dtree,k(l,u,p-257),k(l,u+=5,w-1),k(l,u+=5,g-4),u+=4;for(var T=0;T<g;T++)k(l,u+3*T,y.itree[1+(y.ordr[T]<<1)]);u=i.F._codeTiny(m,y.itree,l,u+=3*g),u=i.F._codeTiny(v,y.itree,l,u)}for(var E=o,D=0;D<s;D+=2){for(var I=e[D],$=I>>>23,R=E+(8388607&I);E<R;)u=i.F._writeLit(n[E++],B,l,u);if(0!=$){var P=e[D+1],j=P>>16,U=P>>8&255,N=255&P;k(l,u=i.F._writeLit(257+U,B,l,u),$-y.of0[U]),b(l,u=i.F._writeLit(N,O,l,u+=y.exb[U]),j-y.df0[N]),u+=y.dxb[N],E+=$}}u=i.F._writeLit(256,B,l,u)}return u},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 u=i.F._hufTree(t.ihst,t.itree,7),a=19;a>4&&0==t.itree[1+(t.ordr[a-1]<<1)];)a--;return[e,s,u,n,h,a,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;(u=Math.min(l+1-s>>>1,138))<11?e.push(17,u-3):e.push(18,u-11),s+=2*u-2}else if(r==h&&n==r&&o==r){for(l=s+5;l+2<i&&t[l+2]==r;)l+=2;var u=Math.min(l+1-s>>>1,6);e.push(16,u-3),s+=2*u-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,u=r.slice(0);if(0==l)return 0;if(1==l){var a=r[0].lit;return u=0==a?1:0,e[1+(a<<1)]=1,e[1+(u<<1)]=1,1}r.sort((function(t,e){return t.f-e.f}));var c=r[0],f=r[1],d=0,p=1,w=2;for(r[0]={lit:-1,f:c.f+f.f,l:c,r:f,d:0};p!=l-1;)c=d!=p&&(w==l||r[d].f<r[w].f)?r[d++]:r[w++],f=d!=p&&(w==l||r[d].f<r[w].f)?r[d++]:r[w++],r[p++]={lit:-1,f:c.f+f.f,l:c,r:f};var g=i.F.setDepth(r[p-1],0);for(g>s&&(i.F.restrictDepth(u,s,g),g=s),h=0;h<l;h++)e[1+(u[h].lit<<1)]=u[h].d;return g},i.F.setDepth=function(t,e){return-1!=t.lit?(t.d=e,e):Math.max(i.F.setDepth(t.l,e+1),i.F.setDepth(t.r,e+1))},i.F.restrictDepth=function(t,e,i){var s=0,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,u=r.codes2map,a=r._get17,c=r.U,f=null==e;f&&(e=new s(t.length>>>2<<3));for(var d,p,w=0,g=0,m=0,v=0,y=0,b=0,k=0,M=0,x=0;0==w;)if(w=n(t,x,1),g=n(t,x+1,2),x+=3,0!=g){if(f&&(e=i.F._check(e,M+(1<<17))),1==g&&(d=c.flmap,p=c.fdmap,b=511,k=31),2==g){m=o(t,x,5)+257,v=o(t,x+5,5)+1,y=o(t,x+10,4)+4,x+=14;for(var A=0;A<38;A+=2)c.itree[A]=0,c.itree[A+1]=0;var C=1;for(A=0;A<y;A++){var S=o(t,x+3*A,3);c.itree[1+(c.ordr[A]<<1)]=S,S>C&&(C=S)}x+=3*y,l(c.itree,C),u(c.itree,C,c.imap),d=c.lmap,p=c.dmap,x=h(c.imap,(1<<C)-1,m+v,t,x,c.ttree);var B=r._copyOut(c.ttree,0,m,c.ltree);b=(1<<B)-1;var O=r._copyOut(c.ttree,m,v,c.dtree);k=(1<<O)-1,l(c.ltree,B),u(c.ltree,B,d),l(c.dtree,O),u(c.dtree,O,p)}for(;;){var T=d[a(t,x)&b];x+=15&T;var E=T>>>4;if(E>>>8==0)e[M++]=E;else{if(256==E)break;var D=M+E-254;if(E>264){var I=c.ldef[E-257];D=M+(I>>>3)+o(t,x,7&I),x+=7&I}var $=p[a(t,x)&k],R=c.ddef[$>>>4],P=(R>>>4)+n(t,x+=15&$,15&R);for(x+=15&R,f&&(e=i.F._check(e,M+(1<<17)));M<D;)e[M]=e[M++-P],e[M]=e[M++-P],e[M]=e[M++-P],e[M]=e[M++-P];M=D}}}else{7&x&&(x+=8-(7&x));var j=4+(x>>>3),U=t[j-4]|t[j-3]<<8;f&&(e=i.F._check(e,M+U)),e.set(new s(t.buffer,t.byteOffset+j,U),M),x=j+U<<3,M+=U}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,u=0;u<s;){var a=t[l(r,n)&e];n+=15&a;var c=a>>>4;if(c<=15)o[u]=c,u++;else{var f=0,d=0;16==c?(d=3+h(r,n,2),n+=2,f=o[u-1]):17==c?(d=3+h(r,n,3),n+=3):18==c&&(d=11+h(r,n,7),n+=7);for(var p=u+d;u<p;)o[u]=f,u++}}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,u=h.bl_count,a=0;a<=e;a++)u[a]=0;for(a=1;a<l;a+=2)u[t[a]]++;var c=h.next_code;for(s=0,u[0]=0,r=1;r<=e;r++)c[r]=s=s+u[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,u=e-h,a=t[o]<<u,c=a+(1<<u);a!=c;)s[n[a]>>>15-e]=l,a++},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 Zn=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:Kn},[Kn]);const to=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),u=new Uint8Array(4*o),a=new Uint32Array(u.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)u[p]=e[p],u[p+1]=e[p+1],u[p+2]=e[p+2],u[p+3]=e[p+3];if(16==f)for(p=0;p<t;p++)u[p]=e[p<<1]}else if(2==c){const t=r.tabs.tRNS;if(null==t){if(8==f)for(p=0;p<o;p++){var w=3*p;a[p]=255<<24|e[w+2]<<16|e[w+1]<<8|e[w]}if(16==f)for(p=0;p<o;p++)a[p]=255<<24|e[4+(w=6*p)]<<16|e[w+2]<<8|e[w]}else{var g=t[0];const i=t[1],s=t[2];if(8==f)for(p=0;p<o;p++){var m=p<<2;a[p]=255<<24|e[2+(w=3*p)]<<16|e[w+1]<<8|e[w],e[w]==g&&e[w+1]==i&&e[w+2]==s&&(u[m+3]=0)}if(16==f)for(p=0;p<o;p++)m=p<<2,a[p]=255<<24|e[4+(w=6*p)]<<16|e[w+2]<<8|e[w],d(e,w)==g&&d(e,w+2)==i&&d(e,w+4)==s&&(u[m+3]=0)}}else if(3==c){const t=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,b=v*i;for(p=0;p<i;p++){var k=3*(M=e[y+(p>>3)]>>7-(7&p)&1);u[m=b+p<<2]=t[k],u[m+1]=t[k+1],u[m+2]=t[k+2],u[m+3]=M<h?n[M]:255}}if(2==f)for(v=0;v<s;v++)for(y=v*l,b=v*i,p=0;p<i;p++)k=3*(M=e[y+(p>>2)]>>6-((3&p)<<1)&3),u[m=b+p<<2]=t[k],u[m+1]=t[k+1],u[m+2]=t[k+2],u[m+3]=M<h?n[M]:255;if(4==f)for(v=0;v<s;v++)for(y=v*l,b=v*i,p=0;p<i;p++)k=3*(M=e[y+(p>>1)]>>4-((1&p)<<2)&15),u[m=b+p<<2]=t[k],u[m+1]=t[k+1],u[m+2]=t[k+2],u[m+3]=M<h?n[M]:255;if(8==f)for(p=0;p<o;p++){var M;k=3*(M=e[p]),u[m=p<<2]=t[k],u[m+1]=t[k+1],u[m+2]=t[k+2],u[m+3]=M<h?n[M]:255}}else if(4==c){if(8==f)for(p=0;p<o;p++){var x=e[A=p<<1];u[m=p<<2]=x,u[m+1]=x,u[m+2]=x,u[m+3]=e[A+1]}if(16==f)for(p=0;p<o;p++){var A;x=e[A=p<<2],u[m=p<<2]=x,u[m+1]=x,u[m+2]=x,u[m+3]=e[A+2]}}else if(0==c)for(g=r.tabs.tRNS?r.tabs.tRNS:-1,v=0;v<s;v++){const t=v*l,s=v*i;if(1==f)for(var C=0;C<i;C++){var S=(x=255*(e[t+(C>>>3)]>>>7-(7&C)&1))==255*g?0:255;a[s+C]=S<<24|x<<16|x<<8|x}else if(2==f)for(C=0;C<i;C++)S=(x=85*(e[t+(C>>>2)]>>>6-((3&C)<<1)&3))==85*g?0:255,a[s+C]=S<<24|x<<16|x<<8|x;else if(4==f)for(C=0;C<i;C++)S=(x=17*(e[t+(C>>>1)]>>>4-((1&C)<<2)&15))==17*g?0:255,a[s+C]=S<<24|x<<16|x<<8|x;else if(8==f)for(C=0;C<i;C++)S=(x=e[t+C])==g?0:255,a[s+C]=S<<24|x<<16|x<<8|x;else if(16==f)for(C=0;C<i;C++)x=e[t+(C<<1)],S=d(e,t+(C<<1))==g?0:255,a[s+C]=S<<24|x<<16|x<<8|x}return u}function i(t,e,i,h){const l=n(t),u=Math.ceil(i*l/8),a=new Uint8Array((u+1+t.interlace)*h);return e=t.tabs.CgBI?r(e,a):s(e,a),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),u=new Uint8Array(s*l);let a=0;const c=[0,0,4,0,2,0,1],f=[0,4,0,2,0,1,0],d=[8,8,8,4,4,2,2],p=[8,8,4,4,2,2,1];let w=0;for(;w<7;){const n=d[w],m=p[w];let v=0,y=0,b=c[w];for(;b<s;)b+=n,y++;let k=f[w];for(;k<i;)k+=m,v++;const M=Math.ceil(v*r/8);o(t,e,a,v,y);let x=0,A=c[w];for(;A<s;){let e=f[w],s=a+x*M<<3;for(;e<i;){var g;if(1==r&&(g=(g=t[s>>3])>>7-(7&s)&1,u[A*l+(e>>3)]|=g<<7-(7&e)),2==r&&(g=(g=t[s>>3])>>6-(7&s)&3,u[A*l+(e>>2)]|=g<<6-((3&e)<<1)),4==r&&(g=(g=t[s>>3])>>4-(7&s)&15,u[A*l+(e>>1)]|=g<<4-((1&e)<<2)),r>=8){const i=A*l+e*h;for(let e=0;e<h;e++)u[i+e]=t[(s>>3)+e]}s+=r,e+=m}x++,A+=n}v*y!=0&&(a+=y*(1+M)),w+=1}return u}(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,u=0,a=0,c=0,f=0,d=0,p=0;if(3==e[0]&&0==e[1])return i||new s(0);const w=t.H,g=w.b,m=w.e,v=w.R,y=w.n,b=w.A,k=w.Z,M=w.m,x=null==i;for(x&&(i=new s(e.length>>>2<<5));0==o;)if(o=g(e,p,1),h=g(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,u=m(e,p+5,5)+1,a=m(e,p+10,4)+4,p+=14;let t=1;for(var A=0;A<38;A+=2)M.Q[A]=0,M.Q[A+1]=0;for(A=0;A<a;A++){const i=m(e,p+3*A,3);M.Q[1+(M.X[A]<<1)]=i,i>t&&(t=i)}p+=3*a,y(M.Q,t),b(M.Q,t,M.u),r=M.w,n=M.d,p=v(M.u,(1<<t)-1,l+u,e,p,M.v);const i=w.V(M.v,0,l,M.C);c=(1<<i)-1;const s=w.V(M.v,l,u,M.D);f=(1<<s)-1,y(M.C,i),b(M.C,i,r),y(M.D,s),b(M.D,s,n)}for(;;){const t=r[k(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[k(e,p)&f];p+=15&r;const o=M.c[r>>>4],h=(o>>>4)+g(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 u=0;for(;u<s;){const t=e[l(r,n)&i];n+=15&t;const s=t>>>4;if(s<=15)o[u]=s,u++;else{let t=0,e=0;16==s?(e=3+h(r,n,2),n+=2,t=o[u-1]):17==s?(e=3+h(r,n,3),n+=3):18==s&&(e=11+h(r,n,7),n+=7);const i=u+e;for(;u<i;)o[u]=t,u++}}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 u=s.j;for(var a=0;a<=i;a++)u[a]=0;for(a=1;a<r;a+=2)u[e[a]]++;const c=s.K;for(n=0,u[0]=0,o=1;o<=i;o++)n=n+u[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 u=l+(1<<h);for(;l!=u;)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 u,a;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(u=i+e*l,a=u+e+1,c=t[a-1],f=0,0==c)for(;f<l;f++)t[u+f]=t[a+f];else if(1==c){for(;f<o;f++)t[u+f]=t[a+f];for(;f<l;f++)t[u+f]=t[a+f]+t[u+f-o]}else if(2==c)for(;f<l;f++)t[u+f]=t[a+f]+t[u+f-l];else if(3==c){for(;f<o;f++)t[u+f]=t[a+f]+(t[u+f-l]>>>1);for(;f<l;f++)t[u+f]=t[a+f]+(t[u+f-l]+t[u+f-o]>>>1)}else{for(;f<o;f++)t[u+f]=t[a+f]+h(0,t[u+f-l],0);for(;f<l;f++)t[u+f]=t[a+f]+h(t[u+f-o],t[u+f-l],t[u+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 u(t,e,i,s,r,n,o,h,l){const u=Math.min(e,r),a=Math.min(i,n);let c=0,f=0;for(let i=0;i<a;i++)for(let n=0;n<u;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,w=t[c+1]*d,g=t[c+2]*d,m=s[f+3]*(1/255),v=s[f]*m,y=s[f+1]*m,b=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]=(w+y*e)*r,s[f+2]=(g+b*e)*r}else if(2==l)p=t[c],w=t[c+1],g=t[c+2],v=s[f],y=s[f+1],b=s[f+2],(d=t[c+3])==(m=s[f+3])&&p==v&&w==y&&g==b?(s[f]=0,s[f+1]=0,s[f+2]=0,s[f+3]=0):(s[f]=p,s[f+1]=w,s[f+2]=g,s[f+3]=d);else if(3==l){if(p=t[c],w=t[c+1],g=t[c+2],v=s[f],y=s[f+1],b=s[f+2],(d=t[c+3])==(m=s[f+3])&&p==v&&w==y&&g==b)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,u=h.readUshort,a=h.readUint,c={tabs:{},frames:[]},f=new Uint8Array(n.length);let d,p=0,w=0;const g=[137,80,78,71,13,10,26,10];for(var m=0;m<8;m++)if(n[m]!=g[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:a(n,o),num_plays:a(n,o+4)},d=new Uint8Array(n.length);else if("fcTL"==e){0!=w&&((A=c.frames[c.frames.length-1]).data=i(c,d.slice(0,w),A.rect.width,A.rect.height),w=0);const t={x:a(n,o+12),y:a(n,o+16),width:a(n,o+4),height:a(n,o+8)};let e=u(n,o+22);e=u(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[w+m]=n[o+m+4];w+=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),b=h.readASCII(n,o,y-o),k=o+t-y-1;if("tEXt"==e)x=h.readASCII(n,y+1,k);else{var M=s(n.slice(y+2,y+2+k));x=h.readUTF8(M,0,M.length)}c.tabs[e][b]=x}else if("iTXt"==e){null==c.tabs[e]&&(c.tabs[e]={}),y=0,y=h.nextZero(n,v=o),b=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),k=t-((v=y+1)-o),0==i?x=h.readUTF8(n,v,k):(M=s(n.slice(v,v+k)),x=h.readUTF8(M,0,M.length)),c.tabs[e][b]=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(u(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]=u(n,o):2==c.ctype&&(c.tabs[e]=[u(n,o),u(n,o+2),u(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]=[u(n,o)]:2==c.ctype||6==c.ctype?c.tabs[e]=[u(n,o),u(n,o+2),u(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 A;return 0!=w&&((A=c.frames[c.frames.length-1]).data=i(c,d.slice(0,w),A.rect.width,A.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,w=f.rect.width,g=f.rect.height,m=e(f.data,w,g,t);if(0!=c)for(var a=0;a<n;a++)l[a]=o[a];if(0==f.blend?u(m,w,g,o,i,s,d,p,0):1==f.blend&&u(m,w,g,o,i,s,d,p,1),r.push(o.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)u(h,w,g,o,i,s,d,p,0);else if(2==f.dispose)for(a=0;a<n;a++)o[a]=l[a]}return r},_paeth:h,_copyTile:u,_bin:t}}();!function(){const{_copyTile:t}=to,{_bin:e}=to,i=to._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,u){null==u&&(u=1);const a=s.length,c=[];for(var f=0;f<a;f++){const t=s[f];c.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(f=0;f<a;f++){let t=4294967295;for(var d=0,p=0;p<a;p++){var w=o(c[f],c[p]);p!=f&&w<t&&(t=w,d=p)}}const g=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 b=0;b<e;b++){var y;f=4*(h*e+b),y=2!=u?[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]+(w=v[4*(3&h)+(3&b)])),n(t[f+1]+w),n(t[f+2]+w),n(t[f+3]+w)],d=0;let k=16777215;for(p=0;p<a;p++){const t=o(y,c[p]);t<k&&(k=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==u&&(b!=e-1&&r(x,m,f+4,7),h!=i-1&&(0!=b&&r(x,m,f+4*e-4,3),r(x,m,f+4*e,5),b!=e-1&&r(x,m,f+4*e+4,1))),l[f>>2]=d,g[f>>2]=s[d]}}function l(t,i,r,n,o){null==o&&(o={});const{crc:h}=s,l=e.writeUint,u=e.writeUshort,a=e.writeASCII;let c=8;const f=t.frames.length>1;let d,p=!1,w=33+(f?20:0);if(null!=o.sRGB&&(w+=13),null!=o.pHYs&&(w+=21),null!=o.iCCP&&(d=pako.deflate(o.iCCP),w+=21+d.length+4),3==t.ctype){for(var g=t.plte.length,m=0;m<g;m++)t.plte[m]>>>24!=255&&(p=!0);w+=8+3*g+4+(p?8+1*g+4:0)}for(var v=0;v<t.frames.length;v++)f&&(w+=38),w+=(M=t.frames[v]).cimg.length+12,0!=v&&(w+=4);w+=12;const y=new Uint8Array(w),b=[137,80,78,71,13,10,26,10];for(m=0;m<8;m++)y[m]=b[m];if(l(y,c,13),c+=4,a(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,a(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,a(y,c,"iCCP"),c+=4,a(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,a(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,a(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*(g=t.plte.length)),c+=4,a(y,c,"PLTE"),c+=4,m=0;m<g;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*g,l(y,c,h(y,c-3*g-4,3*g+4)),c+=4,p){for(l(y,c,g),c+=4,a(y,c,"tRNS"),c+=4,m=0;m<g;m++)y[c+m]=t.plte[m]>>>24&255;c+=g,l(y,c,h(y,c-g-4,g+4)),c+=4}}let k=0;for(v=0;v<t.frames.length;v++){var M=t.frames[v];f&&(l(y,c,26),c+=4,a(y,c,"fcTL"),c+=4,l(y,c,k++),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,u(y,c,n[v]),c+=2,u(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,(g=e.length)+(0==v?0:4)),c+=4;const i=c;a(y,c,0==v?"IDAT":"fdAT"),c+=4,0!=v&&(l(y,c,k++),c+=4),y.set(e,c),c+=g,l(y,c,h(y,i,c-i)),c+=4}return l(y,c,0),c+=4,a(y,c,"IEND"),c+=4,l(y,c,h(y,c-4,4)),c+=4,y.buffer}function u(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 a(e,i,s,r,n){const o=n[0],l=n[1],u=n[2],a=n[3],d=n[4],p=n[5];let g=6,m=8,v=255;for(var y=0;y<e.length;y++){const t=new Uint8Array(e[y]);for(var b=t.length,k=0;k<b;k+=4)v&=t[k+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 u;let w=0,g=0,m=i,v=s,y=r?1:0;if(0!=l){const b=o||r||1==l||0!=h[l-2].dispose?1:2;let k=0,M=1e9;for(let t=0;t<b;t++){var a=new Uint8Array(e[l-1-t]);const r=new Uint32Array(e[l-1-t]);let o=i,h=s,u=-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>u&&(u=e),t<h&&(h=t),t>c&&(c=t));-1==u&&(o=h=u=c=0),n&&(!(1&~o)&&o--,!(1&~h)&&h--);const f=(u-o+1)*(c-h+1);f<M&&(M=f,k=t,w=o,g=h,m=u-o+1,v=c-h+1)}a=new Uint8Array(e[l-1-k]),1==k&&(h[l-1].dispose=2),u=new Uint8Array(m*v*4),t(a,i,s,u,m,v,-w,-g,0),y=t(c,i,s,u,m,v,-w,-g,3)?1:0,1==y?f(c,i,s,u,{x:w,y:g,width:m,height:v}):t(c,i,s,u,m,v,-w,-g,0)}else u=c.slice(0);h.push({rect:{x:w,y:g,width:m,height:v},img:u,blend:y,dispose:0})}if(r)for(l=0;l<h.length;l++){if(1==(w=h[l]).blend)continue;const t=w.rect,r=h[l-1].rect,o=Math.min(t.x,r.x),u=Math.min(t.y,r.y),a={x:o,y:u,width:Math.max(t.x+t.width,r.x+r.width)-o,height:Math.max(t.y+t.height,r.y+r.height)-u};h[l-1].dispose=1,l-1!=0&&c(e,i,s,h,l-1,a,n),c(e,i,s,h,l,a,n)}let d=0;if(1!=e.length)for(var p=0;p<h.length;p++){var w;d+=(w=h[p]).rect.width*w.rect.height}return h}(e,i,s,o,l,u),A={},C=[],S=[];if(0!=r){const t=[];for(k=0;k<x.length;k++)t.push(x[k].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=w(e,r);for(k=0;k<i.plte.length;k++)C.push(i.plte[k].est.rgba);let s=0;for(k=0;k<x.length;k++){const t=(O=x[k]).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(O.img,O.rect.width,O.rect.height,C,e,B),O.img.set(e),s+=t}}else for(y=0;y<x.length;y++){var O=x[y];const t=new Uint32Array(O.img.buffer);var T=O.rect.width;for(b=t.length,B=new Uint8Array(b),S.push(B),k=0;k<b;k++){const e=t[k];if(0!=k&&e==t[k-1])B[k]=B[k-1];else if(k>T&&e==t[k-T])B[k]=B[k-T];else{let t=A[e];if(null==t&&(A[e]=t=C.length,C.push(e),C.length>=300))break;B[k]=t}}}const E=C.length;for(E<=256&&0==d&&(m=E<=2?1:E<=4?2:E<=16?4:8,m=Math.max(m,a)),y=0;y<x.length;y++){const t=(O=x[y]).rect.height;let e=O.img,i=4*(T=O.rect.width),s=4;if(E<=256&&0==d){i=Math.ceil(m*T/8);var D=new Uint8Array(i*t);const r=S[y];for(let e=0;e<t;e++){k=e*i;const t=e*T;if(8==m)for(var I=0;I<T;I++)D[k+I]=r[t+I];else if(4==m)for(I=0;I<T;I++)D[k+(I>>1)]|=r[t+I]<<4-4*(1&I);else if(2==m)for(I=0;I<T;I++)D[k+(I>>2)]|=r[t+I]<<6-2*(3&I);else if(1==m)for(I=0;I<T;I++)D[k+(I>>3)]|=r[t+I]<<7-1*(7&I)}e=D,g=3,s=1}else if(0==M&&1==x.length){D=new Uint8Array(T*t*3);const r=T*t;for(k=0;k<r;k++){const t=3*k,i=4*k;D[t]=e[i],D[t+1]=e[i+1],D[t+2]=e[i+2]}e=D,g=2,s=3,i=3*T}O.img=e,O.bpl=i,O.bpp=s}return{ctype:g,depth:m,plte:C,frames:x}}function c(e,i,s,r,n,o,h){const l=Uint8Array,u=Uint32Array,a=new l(e[n-1]),c=new u(e[n-1]),d=n+1<e.length?new l(e[n+1]):null,p=new l(e[n]),w=new u(p.buffer);let g=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,u=w[l];0==u||0==r[n-1].dispose&&c[l]==u&&(null==d||0!=d[4*l+3])||(s<g&&(g=s),s>v&&(v=s),h<m&&(m=h),h>y&&(y=h))}-1==v&&(g=m=v=y=0),h&&(!(1&~g)&&g--,!(1&~m)&&m--);const b=r[n];b.rect=o={x:g,y:m,width:v-g+1,height:y-m+1},b.blend=1,b.img=new Uint8Array(o.width*o.height*4),0==r[n-1].dispose?(t(a,i,s,b.img,o.width,o.height,-o.x,-o.y,0),f(p,i,s,b.img,o)):t(p,i,s,b.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,u=[0,1,2,3,4];-1!=n?u=[n]:(e*s>5e5||1==i)&&(u=[0]),o&&(l={level:0});const a=Zn;for(var c=0;c<u.length;c++){for(let n=0;n<e;n++)p(r,t,n,s,i,u[c]);h.push(a.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 u=0;u<r;u++)t[l+u]=e[h+u];else t.set(new Uint8Array(e.buffer,h,r),l);else if(1==o){for(u=0;u<n;u++)t[l+u]=e[h+u];for(u=n;u<r;u++)t[l+u]=e[h+u]-e[h+u-n]+256&255}else if(0==s){for(u=0;u<n;u++)t[l+u]=e[h+u];if(2==o)for(u=n;u<r;u++)t[l+u]=e[h+u];if(3==o)for(u=n;u<r;u++)t[l+u]=e[h+u]-(e[h+u-n]>>1)+256&255;if(4==o)for(u=n;u<r;u++)t[l+u]=e[h+u]-i(e[h+u-n],0,0)+256&255}else{if(2==o)for(u=0;u<r;u++)t[l+u]=e[h+u]+256-e[h+u-r]&255;if(3==o){for(u=0;u<n;u++)t[l+u]=e[h+u]+256-(e[h+u-r]>>1)&255;for(u=n;u<r;u++)t[l+u]=e[h+u]+256-(e[h+u-r]+e[h+u-n]>>1)&255}if(4==o){for(u=0;u<n;u++)t[l+u]=e[h+u]+256-i(0,e[h+u-r],0)&255;for(u=n;u<r;u++)t[l+u]=e[h+u]+256-i(e[h+u-n],e[h+u-r],e[h+u-n-r])&255}}}function w(t,e){const i=new Uint8Array(t),s=i.slice(0),r=new Uint32Array(s.buffer),n=g(s,e),o=n[0],h=n[1],l=i.length,u=new Uint8Array(l>>2);let a;if(i.length<2e7)for(var c=0;c<l;c+=4)a=m(o,f=i[c]*(1/255),d=i[c+1]*(1/255),p=i[c+2]*(1/255),w=i[c+3]*(1/255)),u[c>>2]=a.ind,r[c>>2]=a.est.rgba;else for(c=0;c<l;c+=4){var f=i[c]*(1/255),d=i[c+1]*(1/255),p=i[c+2]*(1/255),w=i[c+3]*(1/255);for(a=o;a.left;)a=v(a.est,f,d,p,w)<=0?a.left:a.right;u[c>>2]=a.ind,r[c>>2]=a.est.rgba}return{abuf:s.buffer,inds:u,plte:h}}function g(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=k(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 u={i0:h.i0,i1:l,bst:null,est:null,tdst:0,left:null,right:null};u.bst=k(t,u.i0,u.i1),u.est=M(u.bst);const a={i0:l,i1:h.i1,bst:null,est:null,tdst:0,left:null,right:null};for(a.bst={R:[],m:[],N:h.bst.N-u.bst.N},o=0;o<16;o++)a.bst.R[o]=h.bst.R[o]-u.bst.R[o];for(o=0;o<4;o++)a.bst.m[o]=h.bst.m[o]-u.bst.m[o];a.est=M(a.bst),h.left=u,h.right=a,n[r]=u,n.push(a)}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 u=m(h,e,i,s,r);return u.tdst<l.tdst?u: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(;b(t,i,r)<=n;)i+=4;for(;b(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(;b(t,i,r)>n;)i-=4;return i+4}function b(t,e,i){return t[e]*i[0]+t[e+1]*i[1]+t[e+2]*i[2]+t[e+3]*i[3]}function k(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,u=[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],a=u,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(a,f),p=Math.sqrt(c.dot(f,f)),f=c.sml(1/p,f),!(0!=t&&Math.abs(p-d)<1e-9));t++)d=p;const w=[r*l,n*l,o*l,h*l];return{Cov:u,q:w,e:f,L:d,eMq255:c.dot(c.sml(255,w),f),eMq:c.dot(f,w),rgba:(Math.round(255*w[3])<<24|Math.round(255*w[2])<<16|Math.round(255*w[1])<<8|Math.round(255*w[0]))>>>0}}var 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]]};to.encode=function(t,e,i,s,r,n,o){null==s&&(s=0),null==o&&(o=!1);const h=a(t,e,i,s,[!1,!1,!1,0,o,!1]);return u(h,-1),l(h,e,i,r,n)},to.encodeLL=function(t,e,i,s,r,n,o,h){const a={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++)a.frames.push({rect:{x:0,y:0,width:e,height:i},img:new Uint8Array(t[s]),blend:0,dispose:1,bpp:Math.ceil(c/8),bpl:Math.ceil(f/8)});return u(a,0,!0),l(a,e,i,o,h)},to.encode.compress=a,to.encode.dither=h,to.quantize=w,to.quantize.getKDtree=g,to.quantize.getNearest=m}();const eo={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,u=122+l,a=new ArrayBuffer(u),c=new DataView(a),f=1<<20;let d,p,w,g,m=f,v=0,y=0,b=0;function k(t){c.setUint16(y,t,!0),y+=2}function M(t){c.setUint32(y,t,!0),y+=4}function x(t){y+=t}k(19778),M(u),x(4),M(122),M(108),M(i),M(-s>>>0),k(1),k(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(g=122+v*h,d=0;d<r;)m--,p=o[b++],w=p>>>24,c.setUint32(g+d,p<<8|w),d+=4;v++}b<o.length?(m=f,setTimeout(t,eo._dly)):e(a)}()},toBlob(t,e){this.toArrayBuffer(t,(t=>{e(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var io={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},so={[io.CHROME]:16384,[io.FIREFOX]:11180,[io.DESKTOP_SAFARI]:16384,[io.IE]:8192,[io.IOS]:4096,[io.ETC]:8192};const ro="undefined"!=typeof window,no="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,oo=ro&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),ho=(ro||no)&&(oo&&oo.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),lo=(ro||no)&&(oo&&oo.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function uo(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 u=new Blob([l],{type:n});u.name=e,u.lastModified=i,s(u)}))}function ao(t){return new Promise(((e,i)=>{const s=new lo;s.onload=()=>e(s.result),s.onerror=t=>i(t),s.readAsDataURL(t)}))}function co(t){return new Promise(((e,i)=>{const s=new Image;s.onload=()=>e(s),s.onerror=t=>i(t),s.src=t}))}function fo(){if(void 0!==fo.cachedResult)return fo.cachedResult;let t=io.ETC;const{userAgent:e}=navigator;return/Chrom(e|ium)/i.test(e)?t=io.CHROME:/iP(ad|od|hone)/i.test(e)&&/WebKit/i.test(e)?t=io.IOS:/Safari/i.test(e)?t=io.DESKTOP_SAFARI:/Firefox/i.test(e)?t=io.FIREFOX:(/MSIE/i.test(e)||1==!!document.documentMode)&&(t=io.IE),fo.cachedResult=t}function po(t,e){const i=fo(),s=so[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 wo(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 go(t,e){const{width:i,height:s}=po(t.width,t.height),[r,n]=wo(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 mo(){return void 0!==mo.cachedResult||(mo.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),mo.cachedResult}function vo(t,e={}){return new Promise((function(i,s){let r,n;var o=function(){try{return n=go(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 ao(t).then((function(t){try{return i=t,co(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(mo()||[io.DESKTOP_SAFARI,io.MOBILE_SAFARI].includes(fo()))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 yo(t,e,i,s,r=1){return new Promise((function(n,o){let h;if("image/png"===e){let u,a,c;return u=t.getContext("2d"),({data:a}=u.getImageData(0,0,t.width,t.height)),c=to.encode([a.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=>eo.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),uo(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 bo(t){t.width=0,t.height=0}function ko(){return new Promise((function(t,e){let i,s,r,n;return void 0!==ko.cachedResult?t(ko.cachedResult):uo("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return i=o,vo(i).then((function(o){try{return s=o[1],yo(s,i.type,i.name,i.lastModified).then((function(i){try{return r=i,bo(s),vo(r).then((function(i){try{return n=i[0],t(ko.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 Mo(t){return new Promise(((e,i)=>{const s=new lo;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 xo(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]=wo(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),bo(t)),o}function Ao(t,e){const{width:i}=t,{height:s}=t,[r,n]=wo(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),bo(t),r}function Co(t,e,i=0){return new Promise((function(s,r){let n,o,h,l,u,a,c,f,d,p,w,g,m,v,y,b,k,M,x,A;function C(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,C(),vo(t,e).then(function(i){try{return[,l]=i,C(),u=xo(l,e),C(),new Promise((function(i,s){var r;if(!(r=e.exifOrientation))return Mo(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 a=i,C(),ko().then(function(i){try{return c=i?u:Ao(u,a),C(),f=e.initialQuality||1,d=e.fileType||t.type,yo(c,d,t.name,t.lastModified,f).then(function(i){try{{if(p=i,C(),w=p.size>h,g=p.size>t.size,!w&&!g)return S(100),s(p);var n;function a(){if(o--&&(y>h||y>m)){let e,i;return e=A?.95*x.width:x.width,i=A?.95*x.height:x.height,[k,M]=wo(e,i),M.drawImage(x,0,0,e,i),f*="image/png"===d?.85:.95,yo(k,d,t.name,t.lastModified,f).then((function(t){try{return b=t,bo(x),x=k,y=b.size,S(Math.min(99,Math.floor((v-y)/(v-h)*100))),a}catch(t){return r(t)}}),r)}return[1]}return m=t.size,v=p.size,y=v,x=c,A=!e.alwaysKeepResolution&&w,(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=a}else t=t.call(this)}catch(t){return r(t)}}}.bind(this))(a);function B(){return bo(x),bo(k),bo(u),bo(c),bo(l),S(100),s(b)}}}catch(O){return r(O)}}.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 So;function Bo(t,e){return new Promise(((i,s)=>{So||(So=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(So);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 Oo(t,e){return new Promise((function(i,s){let r,n,o,h,l,u;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 ho))return s(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(t.type))return s(new Error("The file given is not an image"));if(u="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!l||"function"!=typeof Worker||u)return Co(t,r).then(function(t){try{return n=t,f.call(this)}catch(t){return s(t)}}.bind(this),s);var a=function(){try{return f.call(this)}catch(t){return s(t)}}.bind(this),c=function(){try{return Co(t,r).then((function(t){try{return n=t,a()}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",Bo(t,r).then((function(t){try{return n=t,a()}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=Qn(t,n))}catch(t){}return i(n)}}))}Oo.getDataUrlFromFile=ao,Oo.getFilefromDataUrl=uo,Oo.loadImage=co,Oo.drawImageInCanvas=go,Oo.drawFileInCanvas=vo,Oo.canvasToFile=yo,Oo.getExifOrientation=Mo,Oo.handleMaxWidthOrHeight=xo,Oo.followExifOrientation=Ao,Oo.cleanupCanvasMemory=bo,Oo.isAutoOrientationInBrowser=ko,Oo.approximateBelowMaximumCanvasSizeOfBrowser=po,Oo.copyExifWithoutOrientation=Qn,Oo.getBrowserName=fo,Oo.version="2.0.2";class To extends Wn{fileInput=null;maxCompressionSize=300;constructor(t){super(t),this.setupFileInput()}onActivate(){this.openFilePicker()}openFilePicker(){this._core.store.isDisabled||this.fileInput.click()}setupFileInput(){this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.accept="image/*",this.fileInput.style.display="none",this.fileInput.addEventListener("change",this.handleFileSelect.bind(this)),this.fileInput.addEventListener("cancel",this.handleCancel.bind(this)),document.body.appendChild(this.fileInput)}handleFileSelect(t){const e=t.target;e.files&&e.files[0]?Oo(e.files[0],{maxWidthOrHeight:this.maxCompressionSize}).then((t=>{this.readFile(t)})).catch((t=>{console.error("Error during image compression or processing:",t),this.handleCancel()})):(console.info("File selection cancelled by user."),this.handleCancel()),e&&(e.value="")}readFile(t){const e=new FileReader;e.onload=t=>{const e=new Image;e.src=t.target?.result,e.onload=()=>this.createKritzelImage(e)},e.readAsDataURL(t)}createKritzelImage(t){const e=_n.create(this._core),{scaledWidth:i,scaledHeight:s}=e.calculateScaledDimensions(t);return e.src=t.src,e.width=i,e.height=s,e.zIndex=this._core.store.currentZIndex,e.centerInViewport(),this.addImageToStore(e),e}addImageToStore(e){this._core.addObject(e),this._core.store.setState("activeTool",t.getTool("selection")),this._core.selectObjects([e]),this._core.engine.emitObjectsChange()}handleCancel(){this._core.store.setState("activeTool",t.getTool("selection"))}}class Eo extends Wn{fontFamily="Arial";fontSize=16;fontColor=Cn[0];opacity=1;palette=[...Cn];constructor(t){super(t)}handlePointerDown(e){if(e.cancelable&&e.preventDefault(),"mouse"===e.pointerType){const i=e.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),s=this._core.findObjectById(i?.id),r=this._core.store.activeText;if(null===r&&s instanceof $n)return void s.edit(e);if(null!==r&&s instanceof $n)return r.save(),void s.edit(e);if(null!==r&&s instanceof $n==0)return this._core.resetActiveText(),void this._core.store.setState("activeTool",t.getTool("selection"));if(!1===Yn.isLeftClick(e))return;const n=e.clientX-this._core.store.offsetX,o=e.clientY-this._core.store.offsetY,h=this._core.store.state.scale,l=$n.create(this._core,this.fontSize,this.fontFamily,this._core.store.state.lockDrawingScale?1:h);l.fontColor=this.fontColor,l.opacity=this.opacity,l.translateX=(n-this._core.store.state.translateX)/h,l.translateY=(o-this._core.store.state.translateY)/h,l.zIndex=this._core.store.currentZIndex,this._core.store.state.objects.insert(l),this._core.rerender(),l.edit(e)}if("touch"===e.pointerType||"pen"===e.pointerType){const i=Array.from(this._core.store.state.pointers.values()),s=e.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),r=this._core.findObjectById(s?.id),n=this._core.store.activeText;if(null===n&&r instanceof $n)return void r.edit(e);if(null!==n&&r instanceof $n)return n.save(),void r.edit(e);if(null!==n&&r instanceof $n==0)return this._core.resetActiveText(),void this._core.store.setState("activeTool",t.getTool("selection"));if(i.length>1)return;const o=Math.round(i[0].clientX-this._core.store.offsetX),h=Math.round(i[0].clientY-this._core.store.offsetY),l=this._core.store.state.scale,u=$n.create(this._core,this.fontSize,this.fontFamily,this._core.store.state.lockDrawingScale?1:l);u.fontColor=this.fontColor,u.opacity=this.opacity,u.translateX=(o-this._core.store.state.translateX)/l,u.translateY=(h-this._core.store.state.translateY)/l,u.zIndex=this._core.store.currentZIndex,this._core.store.state.objects.insert(u),this._core.rerender(),u.edit(e)}}handlePointerUp(t){t.cancelable&&t.preventDefault(),this._core.store.activeText?.edit(t)}}class Do{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)}}Do.registerIcons({cursor:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z"/></svg>',pen:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/></svg>',arrow:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="19" x2="19" y2="5"/><path d="M15 5h4v4"/></svg>',highlighter:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-highlighter-icon lucide-highlighter"><path d="m9 11-6 6v3h9l3-3"/><path d="m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"/></svg>',eraser:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21"/><path d="M22 21H7"/><path d="m5 11 9 9"/></svg>',type:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 7 4 4 20 4 20 7"/><line x1="9" x2="15" y1="20" y2="20"/><line x1="12" x2="12" y1="4" y2="20"/></svg>',shapes:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z"/><rect x="3" y="14" width="7" height="7" rx="1"/><circle cx="17.5" cy="17.5" r="3.5"/></svg>',"shape-rectangle":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/></svg>',"shape-ellipse":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="12" rx="10" ry="8"/></svg>',"shape-triangle":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3L22 21H2L12 3Z"/></svg>',image:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>',"chevron-down":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>',"chevron-up":'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m18 15-6-6-6 6"/></svg>',"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>',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>'});class Io{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=Do.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 $o{_core;constructor(t){this._core=t}}class Ro extends $o{dragStartX;dragStartY;startX;startY;endX;endY;initialDragX=0;initialDragY=0;disconnectedLineIds=new Set;hasMoved=!1;trackedPointerId=null;constructor(t){super(t)}reset(){this.dragStartX=0,this.dragStartY=0,this.startX=0,this.startY=0,this.endX=0,this.endY=0,this.initialDragX=0,this.initialDragY=0,this.disconnectedLineIds.clear(),this.hasMoved=!1,this.trackedPointerId=null}cancelPendingDrag(){this._core.store.state.isDragging=!1,this.reset()}handlePointerDown(t){if("mouse"===t.pointerType)if(Yn.isLeftClick(t)){const e=this._core.store.selectionGroup;if(!e?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected)this.trackedPointerId=null;else{const e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;this._core.store.state.isDragging=!0,this.dragStartX=e,this.dragStartY=i,this.startX=this.dragStartX,this.startY=this.dragStartY,this.initialDragX=e,this.initialDragY=i,this.disconnectedLineIds.clear(),this.trackedPointerId=t.pointerId}}else this.trackedPointerId=null;if("touch"===t.pointerType||"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;if(!i?.isSelected||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected)this.trackedPointerId=null;else{const i=Math.round(e[0].clientX-this._core.store.offsetX),s=Math.round(e[0].clientY-this._core.store.offsetY);this.dragStartX=i,this.dragStartY=s,this.startX=i,this.startY=s,this.initialDragX=i,this.initialDragY=s,this.disconnectedLineIds.clear(),this.trackedPointerId=t.pointerId}}}}handlePointerMove(t){if(null!==this.trackedPointerId&&this.trackedPointerId===t.pointerId){if("mouse"===t.pointerType){const e=this._core.store.selectionGroup;if(this._core.store.state.isDragging&&e){const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this.endX=i,this.endY=s;const 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;(this.hasMoved||r>o||n>o)&&(clearTimeout(this._core.store.state.longTouchTimeout),this.checkAndDisconnectAnchors(i,s),e.move(i,s,this.dragStartX,this.dragStartY),this.dragStartX=i,this.dragStartY=s,this.hasMoved=!0)}}}}handlePointerUp(t){null!==this.trackedPointerId&&this.trackedPointerId===t.pointerId&&("mouse"===t.pointerType&&this._core.store.state.isDragging&&(this._core.store.state.isDragging=!1,this.hasMoved&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0)),"touch"!==t.pointerType&&"pen"!==t.pointerType||this._core.store.state.isDragging&&(this._core.store.state.isDragging=!1,this.hasMoved&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0)),this.reset())}checkAndDisconnectAnchors(t,e){const i=t-this.initialDragX,s=e-this.initialDragY;if(Math.sqrt(i*i+s*s)<30)return;const r=this._core.store.selectionGroup;if(r&&r.objects.every((t=>t instanceof Ln)))for(const t of r.objects)if(!this.disconnectedLineIds.has(t.id)&&t instanceof Ln){const e=t;(e.startAnchor||e.endAnchor)&&(e.startAnchor&&this._core.anchorManager.removeAnchor(e.id,"start"),e.endAnchor&&this._core.anchorManager.removeAnchor(e.id,"end"),this.disconnectedLineIds.add(e.id),this._core.store.state.objects.update(e))}}}var Po,jo;!function(t){t.TopLeft="top-left",t.TopRight="top-right",t.BottomLeft="bottom-left",t.BottomRight="bottom-right"}(Po||(Po={}));class Uo extends $o{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&&Yn.isLeftClick(t)){const e=this._core.store.selectionGroup;if(e&&this._core.store.state.isResizeHandleSelected){const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY;this._core.store.state.isResizing=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialSize.width=e.width,this.initialSize.height=e.height,this.initialSize.x=e.translateX,this.initialSize.y=e.translateY}}if("touch"===t.pointerType||"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){const i=Math.round(e.clientX-this._core.store.offsetX),s=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isResizing=!0,this.initialMouseX=i,this.initialMouseY=s,this.initialSize.width=t.width,this.initialSize.height=t.height,this.initialSize.x=t.translateX,this.initialSize.y=t.translateY,clearTimeout(this._core.store.state.longTouchTimeout)}}}}handlePointerMove(t){if("mouse"===t.pointerType){const e=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&e){const i=t.clientX-this._core.store.offsetX-this.initialMouseX,s=t.clientY-this._core.store.offsetY-this.initialMouseY,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),u=Math.cos(h),a=e.scale||1,c=this._core.store.state.scale,f=(i*u+s*l)/c,d=(-i*l+s*u)/c,p=this.initialSize.x+this.initialSize.width/a/2+i/c/2,w=this.initialSize.y+this.initialSize.height/a/2+s/c/2;switch(this._core.store.state.resizeHandleType){case Po.TopLeft:this.newSize.width=this.initialSize.width-f*a,this.newSize.height=this.initialSize.height-d*a;break;case Po.TopRight:this.newSize.width=this.initialSize.width+f*a,this.newSize.height=this.initialSize.height-d*a;break;case Po.BottomLeft:this.newSize.width=this.initialSize.width-f*a,this.newSize.height=this.initialSize.height+d*a;break;case Po.BottomRight:this.newSize.width=this.initialSize.width+f*a,this.newSize.height=this.initialSize.height+d*a}this.newSize.x=p-this.newSize.width/a/2,this.newSize.y=w-this.newSize.height/a/2,e.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}if("touch"===t.pointerType||"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)&&(clearTimeout(this._core.store.state.longTouchTimeout),this.hasResized=!0),!this.hasResized)return;const u=e.rotation,a=Math.sin(u),c=Math.cos(u),f=e.scale||1,d=this._core.store.state.scale,p=(r*c+n*a)/d,w=(-r*a+n*c)/d,g=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 Po.TopLeft:this.newSize.width=this.initialSize.width-p*f,this.newSize.height=this.initialSize.height-w*f;break;case Po.TopRight:this.newSize.width=this.initialSize.width+p*f,this.newSize.height=this.initialSize.height-w*f;break;case Po.BottomLeft:this.newSize.width=this.initialSize.width-p*f,this.newSize.height=this.initialSize.height+w*f;break;case Po.BottomRight:this.newSize.width=this.initialSize.width+p*f,this.newSize.height=this.initialSize.height+w*f}this.newSize.x=g-this.newSize.width/f/2,this.newSize.y=m-this.newSize.height/f/2,e.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}}handlePointerUp(t){"mouse"===t.pointerType&&this._core.store.state.isResizing&&(this._core.store.state.isResizing=!1,this.hasResized&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0),this.reset()),"touch"!==t.pointerType&&"pen"!==t.pointerType||this._core.store.state.isResizing&&(this._core.store.state.isResizing=!1,this.hasResized&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0),this.reset(),clearTimeout(this._core.store.state.longTouchTimeout))}}class No extends $o{initialRotation=0;rotation=0;unchangedObjects=[];initialSelectionGroupRotation=0;constructor(t){super(t)}reset(){this.initialRotation=0,this.rotation=0,this.unchangedObjects=[]}handlePointerDown(t){if("mouse"===t.pointerType&&Yn.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,this.unchangedObjects=e.objects.map((t=>t.clone()))}}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,this.unchangedObjects=t.objects.map((t=>t.clone())),clearTimeout(this._core.store.state.longTouchTimeout)}}}}handlePointerMove(t){if("mouse"===t.pointerType){const e=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&e){const i=e.scale||1,s=Math.atan2(e.translateY+e.height/2/i-(t.clientY-this._core.store.offsetY-this._core.store.state.translateY)/this._core.store.state.scale,e.translateX+e.width/2/i-(t.clientX-this._core.store.offsetX-this._core.store.state.translateX)/this._core.store.state.scale);this.rotation=s-this.initialRotation,e.rotate(this.rotation)}}if("touch"===t.pointerType||"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),clearTimeout(this._core.store.state.longTouchTimeout)}}}handlePointerUp(t){"mouse"===t.pointerType&&this._core.store.state.isRotating&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.isRotating=!1,this._core.store.state.hasObjectsChanged=!0,this.reset()),"touch"!==t.pointerType&&"pen"!==t.pointerType||this._core.store.state.isRotating&&(this._core.store.selectionGroup.update(),this._core.engine.emitObjectsChange(),this._core.store.state.isRotating=!1,this._core.store.state.hasObjectsChanged=!0,this.reset(),clearTimeout(this._core.store.state.longTouchTimeout))}}class Fo extends s{__class__="KritzelSelectionBox";static create(t){const e=new Fo;return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e.scale=t.store.state.scale,e.zIndex=99999,e.backgroundColor={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 _o extends $o{startX;startY;touchStartX=0;touchStartY=0;touchStartTimeout=null;get isSelectionClick(){const t=this._core.store.selectionBox;return t&&0===t.width&&0===t.height}get isSelectionDrag(){const t=this._core.store.selectionBox;return t&&(t.width>0||t.height>0)}constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&Yn.isLeftClick(t)&&!this._core.store.selectionGroup&&this.startMouseSelection(t),"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||(this.startTouchSelection(),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;(s>n||r>n)&&this._core.store.state.isSelecting&&(this.updateTouchSelection(),clearTimeout(this._core.store.state.longTouchTimeout))}}handlePointerUp(t){if("mouse"===t.pointerType&&Yn.isLeftClick(t)){const e=this._core.store.state.hasObjectsChanged,i=this._core.store.selectionGroup;1===i?.objects.length&&!1===e&&i.objects[0].edit(t),this._core.store.state.hasObjectsChanged=!1,this._core.store.state.isSelecting&&(this.isSelectionClick&&this.handleSelectionClick(t),this.isSelectionDrag&&(this.updateMouseSelection(t),this.addSelectedObjectsToSelectionGroup(),this.removeSelectionBox()),this._core.engine.emitObjectsChange())}if("touch"===t.pointerType||"pen"===t.pointerType){clearTimeout(this.touchStartTimeout);const e=this._core.store.state.hasObjectsChanged,i=this._core.store.selectionGroup;1===i?.objects.length&&!1===e&&i.objects[0].edit(t),this._core.store.state.hasObjectsChanged=!1,this._core.store.state.isSelecting&&(this.isSelectionClick&&this.handleSelectionClick(t),this.isSelectionDrag&&(this.updateTouchSelection(),this.addSelectedObjectsToSelectionGroup(),this.removeSelectionBox()),this._core.engine.emitObjectsChange(),this._core.store.state.skipContextMenu=!1)}}removeSelectionBox(){this._core.store.state.isSelecting=!1,this._core.store.state.objects.remove((t=>t instanceof Fo))}startMouseSelection(t){let e,i;e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;const s=Fo.create(this._core);this.startX=(e-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(i-this._core.store.state.translateY)/this._core.store.state.scale,s.translateX=this.startX,s.translateY=this.startY,this._core.store.state.isSelecting=!0,this._core.store.state.objects.remove((t=>t instanceof Fo||t instanceof Hn)),this._core.store.state.objects.insert(s)}startTouchSelection(){const t=Array.from(this._core.store.state.pointers.values())[0];if(!t)return;let e,i;e=Math.round(t.clientX-this._core.store.offsetX),i=Math.round(t.clientY-this._core.store.offsetY),this.touchStartX=e,this.touchStartY=i;const s=Fo.create(this._core);this.startX=(e-this._core.store.state.translateX)/this._core.store.state.scale,this.startY=(i-this._core.store.state.translateY)/this._core.store.state.scale,s.translateX=this.startX,s.translateY=this.startY,this._core.store.state.isSelecting=!0,this._core.store.state.objects.remove((t=>t instanceof Fo||t instanceof Hn)),this._core.store.state.objects.insert(s)}updateMouseSelection(t){let e,i;e=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;const s=this._core.store.selectionBox;if(s){const t=(e-this._core.store.state.translateX)/s.scale,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),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),n>0||o>0?this.updateSelectedObjects():this.clearSelectionPreview()}}updateSelectedObjects(){const t=this._core.store.selectionBox;t&&this._core.store.allObjects.filter((t=>!(t instanceof Fo))).forEach((e=>e.isSelected=e.hitTestPolygon(t.rotatedPolygon)))}handleSelectionClick(t){const e=this.getTopmostHitObject(t);this.clearSelectionPreview(),this.addObjectToSelectionGroup(e),this.removeSelectionBox()}getTopmostHitObject(t){const e=this._core.store.state.pointerX,i=this._core.store.state.pointerY,s=this._core.getObjectsFromPointerEvent(t,".object");for(const t of s)if(!(t instanceof Fo)&&t.hitTest(e,i))return t;return null}clearSelectionPreview(){this._core.store.allNonSelectionObjects.forEach((t=>{t.isSelected=!1}))}addObjectToSelectionGroup(t){if(!t)return;const e=zn.findParentGroup(this._core,t.id)||t;e.isSelected=!1;const i=Hn.create(this._core);i.addOrRemove(e),i.isSelected=!0,i.rotation=e.rotation,this._core.addSelectionGroup(i),this._core.rerender()}addSelectedObjectsToSelectionGroup(){const t=this._core.store.selectedObjects;if(0===t.length)return;const e=new Map;t.forEach((t=>{const i=zn.findParentGroup(this._core,t.id);i?e.set(i.id,i):e.set(t.id,t),t.isSelected=!1}));const i=Hn.create(this._core);e.forEach((t=>{i.addOrRemove(t)})),i.isSelected=!0,1===i.length&&(i.rotation=i.objects[0].rotation),this._core.addSelectionGroup(i),this._core.rerender()}}class Lo extends $o{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 zo extends $o{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&&Yn.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),clearTimeout(this._core.store.state.longTouchTimeout)}handlePointerMove(t){const e=this.getSelectedLine();if(!e||!this._core.store.state.isLineHandleDragging)return;const i=t.clientX-this._core.store.offsetX,s=t.clientY-this._core.store.offsetY,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,u=r/o,a=n/o,c=Math.cos(-l),f=Math.sin(-l),d=(u*c-a*f)*h,p=(u*f+a*c)*h,w=this._core.store.state.lineHandleType;if("start"===w){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:In.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"===w){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:In.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"===w){const t=(this.initialControlX??(this.initialStartX+this.initialEndX)/2)+2*d,i=(this.initialControlY??(this.initialStartY+this.initialEndY)/2)+2*p,s=e.startX,r=e.startY,n=e.endX,o=e.endY,h=n-s,l=o-r,u=h*h+l*l;let a,c,f=-1;0!==u&&(f=((t-s)*h+(i-r)*l)/u),f<0?(a=s,c=r):f>1?(a=n,c=o):(a=s+f*h,c=r+f*l);const w=t-a,g=i-c;Math.sqrt(w*w+g*g)<15?e.updateControlPoint(void 0,void 0):e.updateControlPoint(t,i)}this._core.rerender()}worldToLineLocal(t,e,i){const s=(e-t.translateX)*t.scale,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}=Ln.calculateBoundingBox(e,i,s,r,t.controlX,t.controlY,t.strokeWidth),u=h-n,a=l-o,{minX:c,minY:f,maxX:d,maxY:p}=Ln.calculateBoundingBox(this.initialStartX,this.initialStartY,this.initialEndX,this.initialEndY,this.initialControlX,this.initialControlY,t.strokeWidth),w=d-c,g=p-f,m=n-c+(u-w)/2,v=o-f+(a-g)/2,y=t.rotation,b=Math.cos(y),k=Math.sin(y),M=1/t.scale,x=this.initialTranslateX+M*(w-u)/2+M*(m*b-v*k),A=this.initialTranslateY+M*(g-a)/2+M*(m*k+v*b);t.startX=e,t.startY=i,t.endX=s,t.endY=r,t.x=n,t.y=o,t.width=u,t.height=a,t.translateX=x,t.translateY=A,t._adjustedPoints=null,this._core.store.state.objects.update(t)}handlePointerUp(t){if(this._core.store.state.isLineHandleDragging){const t=this.getSelectedLine(),e=this._core.store.state.lineHandleType;if(t&&this.hasMoved){!this.currentSnapTarget||"start"!==e&&"end"!==e||this._core.anchorManager.setAnchor(t.id,e,this.currentSnapTarget.objectId);const i=this._core.store.selectionGroup;i&&(i.refreshObjectDimensions(),i.update(),this._core.engine.emitObjectsChange(),this._core.store.state.hasObjectsChanged=!0)}this._core.store.state.isLineHandleDragging=!1,this.reset(),this._core.rerender()}}getSelectedLine(){const t=this._core.store.selectionGroup;if(!t||1!==t.objects.length)return null;const e=t.objects[0];return e instanceof Ln?e:null}}!function(t){t.Rectangle="rectangle",t.Ellipse="ellipse",t.Triangle="triangle"}(jo||(jo={}));class Yo extends s{__class__="KritzelShape";shapeType=jo.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 G({nodes:qr(zr.spec.nodes,"paragraph block*","block"),marks:zr.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??jo.Rectangle,this.fillColor=t.fillColor??{light:"transparent",dark:"transparent"},this.strokeColor=t.strokeColor??{light:"#000000",dark:"#ffffff"},this.strokeWidth=t.strokeWidth??4,this.fontSize=t.fontSize??16,this.fontFamily=t.fontFamily??"Arial",this.fontColor=t.fontColor??In.determineTextColor(this.fillColor),this.scale=t.scale??1,this.scaleFactor=t.scaleX??1)}static create(t,e){const i=new Yo;return i._core=t,i.id=i.generateId(),i.workspaceId=t.store.state.activeWorkspace.id,i.x=e?.x??0,i.y=e?.y??0,i.translateX=e?.translateX??0,i.translateY=e?.translateY??0,i.width=e?.width??100,i.height=e?.height??100,i.shapeType=e?.shapeType??jo.Rectangle,i.fillColor=e?.fillColor??{light:"transparent",dark:"transparent"},i.strokeColor=e?.strokeColor??{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??In.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=In.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 Sr(null,{state:ge.create({doc:t,plugins:[ln(An)]}),editable:()=>!1,dispatchTransaction:t=>{const e=this.editor.state.apply(t);this.editor.updateState(e),t.docChanged&&(this.content=e.doc.toJSON(),t.getMeta("fromRemote")||this._core.store.state.objects.update(this,{temporary:!0}))}})}setContent(t){if(this.content=t,this.editor&&t){const e=this.editor.state.schema.nodeFromJSON(t),i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",!0),this.editor.dispatch(i)}}resize(t,e,i,s){i<=1||s<=1||(this.width=i,this.height=s,this.translateX=t,this.translateY=e,this._core.store.state.objects.update(this))}focus(t){if(this.editor){const e=this.editor.state.doc;if(t?.x&&t?.y){const i=this.editor.posAtCoords({left:t.x,top:t.y});if(i)return this.editor.dispatch(this.editor.state.tr.setSelection(se.create(e,i.pos))),this.editor.focus(),void(r.isIOS()&&this.scrollIntoViewOnIOS())}const i=Math.max(1,e.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(se.create(e,i))),this.editor.focus(),r.isIOS()&&this.scrollIntoViewOnIOS()}}scrollIntoViewOnIOS(){setTimeout((()=>{this.editor&&this.editor.dom&&this.editor.dom.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"})}),300)}edit(e){n.disableInteractiveWidget(),this.uneditedObject=this.clone(),this._core.store.setState("activeTool",t.getTool("shape")),this.editor.setProps({editable:()=>!0}),this.isEditing=!0,this._core.rerender(),this.focus({x:e?.clientX,y:e?.clientY}),n.enableInteractiveWidget()}save(){this.content=this.editor.state.doc.toJSON(),this.editor.setProps({editable:()=>!1}),this.editor.dom.blur(),this.isEditing=!1,this._core.store.state.objects.consolidateTemporaryItems(),this._core.store.state.objects.update(this),this._core.engine.emitObjectsChange()}handlePointerDown(t){this.isEditing&&t.stopPropagation()}handlePointerMove(t){this.isEditing&&t.stopPropagation()}handlePointerUp(t){this.isEditing&&t.stopPropagation()}copy(){const t=super.copy();return t.editor=t.createEditor(),this.content&&t.setContent(this.content),t}serialize(){const{_core:t,_elementRef:e,_schema:i,element:s,totalWidth:r,totalHeight:n,editor:o,uneditedObject:h,...l}=this,u=structuredClone(l);return s&&"object"==typeof s&&"nodeType"in s&&1===s.nodeType&&(u.element=s.cloneNode(!0)),u}deserialize(t){return super.deserialize(t),t.content&&this.setContent(t.content),this}onAfterUpdate(t){t.includes("fillColor")?(this.fontColor=In.determineTextColor(this.fillColor),this.editor?.dom?.parentElement&&(this.editor.dom.parentElement.style.color=In.resolveThemeColor(this.fontColor))):t.includes("fontColor")&&this.editor?.dom?.parentElement&&(this.editor.dom.parentElement.style.color=In.resolveThemeColor(this.fontColor))}getClipPolygon(){const t=this.totalWidth/this.scale,e=this.totalHeight/this.scale,s=this.translateX+t/2,r=this.translateY+e/2,n=this.strokeWidth/this.scale/2;switch(this.shapeType){case jo.Ellipse:return i.getEllipsePolygonApproximation(s,r,t/2+n,e/2+n,32,this.rotation);case jo.Triangle:const o=(t,e)=>{const i=t-s,o=e-r,h=Math.sqrt(i*i+o*o);if(0===h)return{x:t,y:e};const l=(h+n)/h;return{x:s+i*l,y:r+o*l}},h=this.translateX,l=this.translateY+e,u=this.translateX+t,a=this.translateY+e,c=o(this.translateX+t/2,this.translateY),f=o(u,a),d=o(h,l);if(0!==this.rotation){const t=Math.cos(this.rotation),e=Math.sin(this.rotation),i=i=>{const n=i.x-s,o=i.y-r;return{x:s+n*t-o*e,y:r+n*e+o*t}};return[i(c),i(f),i(d)]}return[c,f,d];default:return null}}getSvgPath(){const t=this.width,e=this.height;switch(this.shapeType){case jo.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 jo.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 jo.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`}}}class Wo extends Wn{selectionHandler;moveHandler;hoverHandler;resizeHandler;rotationHandler;lineHandleHandler;palette=[...Cn];hasSelection(){return!!this._core.store.selectionGroup&&this._core.store.selectionGroup.objects.length>0}getSelectedObjects(){return this._core.store.selectionGroup?.objects??[]}flattenObjects(t){let e=[];for(const i of t)i instanceof zn?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 Cn[0];for(const e of t){if(e instanceof Fn)return e.fill;if(e instanceof Ln)return e.stroke;if(e instanceof $n)return e.fontColor;if(e instanceof Yo)return e.strokeColor}return Cn[0]}set color(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Fn&&this._core.updateObject(e,{fill:t}),e instanceof Ln&&this._core.updateObject(e,{stroke:t}),e instanceof $n&&this._core.updateObject(e,{fontColor:t}),e instanceof Yo&&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 Fn)return e.strokeWidth;if(e instanceof Ln)return e.strokeWidth;if(e instanceof $n)return e.fontSize;if(e instanceof Yo)return e.strokeWidth}return 1}set size(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Fn&&this._core.updateObject(e,{strokeWidth:t}),e instanceof Ln&&this._core.updateObject(e,{strokeWidth:t}),e instanceof $n&&this._core.updateObject(e,{fontSize:t}),e instanceof Yo&&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 Yo)return e.fillColor;return{light:"transparent",dark:"transparent"}}set fillColor(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{if(e instanceof Yo){const i=In.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 $n)return e.fontFamily;if(e instanceof Yo)return e.fontFamily}return"Arial"}set fontFamily(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof $n&&this._core.updateObject(e,{fontFamily:t}),e instanceof Yo&&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 Ln)return e.arrows;return{start:{enabled:!1},end:{enabled:!1}}}set arrows(t){this.flattenObjects(this.getSelectedObjects()).forEach((e=>{e instanceof Ln&&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 Yo)),s=t.some((t=>t instanceof $n)),r=t.some((t=>t instanceof Ln)),n=t.some((t=>t instanceof _n)),o=t.some((t=>t instanceof Fn||t instanceof Ln||t instanceof Yo));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 _o(this._core),this.moveHandler=new Ro(this._core),this.hoverHandler=new Lo(this._core),this.resizeHandler=new Uo(this._core),this.rotationHandler=new No(this._core),this.lineHandleHandler=new zo(this._core)}handlePointerDown(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType){if(Yn.isLeftClick(t)){this._core.store.state.isResizeHandleSelected=this.isHandleSelected(t),this._core.store.state.isRotationHandleSelected=this.isRotationHandleSelected(t),this._core.store.state.isLineHandleSelected=this.isLineHandleSelected(t),this._core.store.state.resizeHandleType=this.getHandleType(t),this._core.store.state.lineHandleType=this.getLineHandleType(t);const e=this.getSelectedObject(t),i=this._core.store.selectionGroup;if(null!==e&&!(e&&i&&e.id!==i.id)||!i||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||(this._core.removeSelectionGroup(),this._core.rerender()),e&&!1===e.isSelected&&1===e?.objects.length&&e.objects[0].isInteractive)return}this.lineHandleHandler.handlePointerDown(t),this.moveHandler.handlePointerDown(t),this.selectionHandler.handlePointerDown(t),this.resizeHandler.handlePointerDown(t),this.rotationHandler.handlePointerDown(t),this._core.rerender()}if("touch"===t.pointerType||"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;!i&&e&&(this._core.store.state.skipContextMenu=!0),null!==e&&!s||!i||this._core.store.state.isResizeHandleSelected||this._core.store.state.isRotationHandleSelected||this._core.store.state.isLineHandleSelected||(this._core.removeSelectionGroup(),this._core.rerender())}this.lineHandleHandler.handlePointerDown(t),this.rotationHandler.handlePointerDown(t),this.resizeHandler.handlePointerDown(t),this.moveHandler.handlePointerDown(t),this.selectionHandler.handlePointerDown(t),this._core.rerender()}}handlePointerMove(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&(this.lineHandleHandler.handlePointerMove(t),this.moveHandler.handlePointerMove(t),this.hoverHandler.handlePointerMove(t),this.selectionHandler.handlePointerMove(t),this.resizeHandler.handlePointerMove(t),this.rotationHandler.handlePointerMove(t),this._core.rerender()),"touch"===t.pointerType||"pen"===t.pointerType){if(!0===this._core.store.state.isScaling)return;this.lineHandleHandler.handlePointerMove(t),this.rotationHandler.handlePointerMove(t),this.resizeHandler.handlePointerMove(t),this.moveHandler.handlePointerMove(t),this.selectionHandler.handlePointerMove(t),this._core.rerender()}}handlePointerUp(t){if(t.cancelable&&t.preventDefault(),"mouse"===t.pointerType&&(this.lineHandleHandler.handlePointerUp(t),this.moveHandler.handlePointerUp(t),this.resizeHandler.handlePointerUp(t),this.rotationHandler.handlePointerUp(t),this.selectionHandler.handlePointerUp(t),this._core.rerender()),"touch"===t.pointerType||"pen"===t.pointerType){if(!0===this._core.store.state.isScaling)return;this.lineHandleHandler.handlePointerUp(t),this.rotationHandler.handlePointerUp(t),this.resizeHandler.handlePointerUp(t),this.moveHandler.handlePointerUp(t),this.selectionHandler.handlePointerUp(t),this._core.rerender()}}getSelectedObject(t){const e=t.composedPath().slice(1).find((t=>t.classList&&t.classList.contains("object"))),i=this._core.findObjectById(e?.id);if(!i)return null;const{x:s,y:r}=this._core.getCanvasPoint(t);if(!i.hitTest(s,r))return null;if(i instanceof Hn)return i;{const t=Hn.create(this._core);return t.translateX=0,t.translateY=0,t.addOrRemove(i),t}}getHandleType(t){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=e.elementsFromPoint(t.clientX,t.clientY).find((t=>t.classList.contains("resize-handle-overlay")));return i?.classList[1]}isHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;return!!e&&e.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("resize-handle-overlay")))}isRotationHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;return!!e&&e.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("rotation-handle-overlay")))}isLineHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;return!!e&&e.elementsFromPoint(t.clientX,t.clientY).some((t=>t.classList.contains("selection-line-handle-overlay")))}getLineHandleType(t){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=e.elementsFromPoint(t.clientX,t.clientY).find((t=>t.classList.contains("selection-line-handle-overlay")));return i?.classList[1]}}const Xo=()=>new Map,Ho=t=>{const e=Xo();return t.forEach(((t,i)=>{e.set(i,t)})),e},Jo=(t,e,i)=>{let s=t.get(e);return void 0===s&&t.set(e,s=i()),s},Vo=()=>new Set,Qo=t=>t[t.length-1],qo=(t,e)=>{for(let i=0;i<e.length;i++)t.push(e[i])},Ko=Array.from,Go=(t,e)=>{for(let i=0;i<t.length;i++)if(!e(t[i],i,t))return!1;return!0},Zo=(t,e)=>{for(let i=0;i<t.length;i++)if(e(t[i],i,t))return!0;return!1},th=Array.isArray;class eh{constructor(){this._observers=Xo()}on(t,e){return Jo(this._observers,t,Vo).add(e),e}once(t,e){const i=(...s)=>{this.off(t,i),e(...s)};this.on(t,i)}off(t,e){const i=this._observers.get(t);void 0!==i&&(i.delete(e),0===i.size&&this._observers.delete(t))}emit(t,e){return Ko((this._observers.get(t)||Xo()).values()).forEach((t=>t(...e)))}destroy(){this._observers=Xo()}}let ih=class{constructor(){this._observers=Xo()}on(t,e){Jo(this._observers,t,Vo).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 Ko((this._observers.get(t)||Xo()).values()).forEach((t=>t(...e)))}destroy(){this._observers=Xo()}};const sh=Math.floor,rh=Math.abs,nh=(t,e)=>t<e?t:e,oh=(t,e)=>t>e?t:e,hh=Math.pow,lh=t=>0!==t?t<0:1/t<0,uh=64,ah=128,ch=127,fh=Number.MAX_SAFE_INTEGER,dh=Number.MIN_SAFE_INTEGER,ph=Number.isInteger||(t=>"number"==typeof t&&isFinite(t)&&sh(t)===t),wh=String.fromCharCode,gh=/^\s*/g,mh=/([A-Z])/g,vh=(t,e)=>(t=>t.replace(gh,""))(t.replace(mh,(t=>`${e}${(t=>t.toLowerCase())(t)}`))),yh="undefined"!=typeof TextEncoder?new TextEncoder:null,bh=yh?t=>yh.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 kh="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});kh&&1===kh.decode(new Uint8Array).length&&(kh=null);let Mh=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}};const xh=()=>new Mh,Ah=t=>{let e=t.cpos;for(let i=0;i<t.bufs.length;i++)e+=t.bufs[i].length;return e},Ch=t=>{const e=new Uint8Array(Ah(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},Sh=(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},Bh=Sh,Oh=(t,e)=>{for(;e>ch;)Sh(t,ah|ch&e),e=sh(e/128);Sh(t,ch&e)},Th=(t,e)=>{const i=lh(e);for(i&&(e=-e),Sh(t,(e>63?ah:0)|(i?uh:0)|63&e),e=sh(e/64);e>0;)Sh(t,(e>ch?ah:0)|ch&e),e=sh(e/128)},Eh=new Uint8Array(3e4),Dh=Eh.length/3,Ih=yh&&yh.encodeInto?(t,e)=>{if(e.length<Dh){const i=yh.encodeInto(e,Eh).written||0;Oh(t,i);for(let e=0;e<i;e++)Sh(t,Eh[e])}else Rh(t,bh(e))}:(t,e)=>{const i=unescape(encodeURIComponent(e)),s=i.length;Oh(t,s);for(let e=0;e<s;e++)Sh(t,i.codePointAt(e))},$h=(t,e)=>{const i=t.cbuf.length,s=t.cpos,r=nh(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(oh(2*i,n)),t.cbuf.set(e.subarray(r)),t.cpos=n)},Rh=(t,e)=>{Oh(t,e.byteLength),$h(t,e)},Ph=(t,e)=>{((t,e)=>{const i=t.cbuf.length;i-t.cpos<e&&(t.bufs.push(new Uint8Array(t.cbuf.buffer,0,t.cpos)),t.cbuf=new Uint8Array(2*oh(i,e)),t.cpos=0)})(t,e);const i=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,i},jh=new DataView(new ArrayBuffer(4)),Uh=(t,e)=>{switch(typeof e){case"string":Sh(t,119),Ih(t,e);break;case"number":ph(e)&&rh(e)<=2147483647?(Sh(t,125),Th(t,e)):(jh.setFloat32(0,i=e),jh.getFloat32(0)===i?(Sh(t,124),((t,e)=>{Ph(t,4).setFloat32(0,e,!1)})(t,e)):(Sh(t,123),((t,e)=>{Ph(t,8).setFloat64(0,e,!1)})(t,e)));break;case"bigint":Sh(t,122),((t,e)=>{Ph(t,8).setBigInt64(0,e,!1)})(t,e);break;case"object":if(null===e)Sh(t,126);else if(th(e)){Sh(t,117),Oh(t,e.length);for(let i=0;i<e.length;i++)Uh(t,e[i])}else if(e instanceof Uint8Array)Sh(t,116),Rh(t,e);else{Sh(t,118);const i=Object.keys(e);Oh(t,i.length);for(let s=0;s<i.length;s++){const r=i[s];Ih(t,r),Uh(t,e[r])}}break;case"boolean":Sh(t,e?120:121);break;default:Sh(t,127)}var i};class Nh extends Mh{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&Oh(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const Fh=t=>{t.count>0&&(Th(t.encoder,1===t.count?t.s:-t.s),t.count>1&&Oh(t.encoder,t.count-2))};class _h{constructor(){this.encoder=new Mh,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Fh(this),this.count=1,this.s=t)}toUint8Array(){return Fh(this),Ch(this.encoder)}}const Lh=t=>{t.count>0&&(Th(t.encoder,2*t.diff+(1===t.count?0:1)),t.count>1&&Oh(t.encoder,t.count-2))};class zh{constructor(){this.encoder=new Mh,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Lh(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Lh(this),Ch(this.encoder)}}class Yh{constructor(){this.sarr=[],this.s="",this.lensE=new _h}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Mh;return this.sarr.push(this.s),this.s="",Ih(t,this.sarr.join("")),$h(t,this.lensE.toUint8Array()),Ch(t)}}const Wh=t=>new Error(t),Xh=()=>{throw Wh("Method unimplemented")},Hh=()=>{throw Wh("Unexpected case")},Jh=Wh("Unexpected end of array"),Vh=Wh("Integer out of Range");let Qh=class{constructor(t){this.arr=t,this.pos=0}};const qh=t=>new Qh(t),Kh=t=>((t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,i})(t,Zh(t)),Gh=t=>t.arr[t.pos++],Zh=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<ah)return e;if(e>fh)throw Vh}throw Jh},tl=t=>{let e=t.arr[t.pos++],i=63&e,s=64;const r=(e&uh)>0?-1:1;if(!(e&ah))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<ah)return r*i;if(i>fh)throw Vh}throw Jh},el=kh?t=>kh.decode(Kh(t)):t=>{let e=Zh(t);if(0===e)return"";{let i=String.fromCodePoint(Gh(t));if(--e<100)for(;e--;)i+=String.fromCodePoint(Gh(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))}},il=(t,e)=>{const i=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,i},sl=[()=>{},()=>null,tl,t=>il(t,4).getFloat32(0,!1),t=>il(t,8).getFloat64(0,!1),t=>il(t,8).getBigInt64(0,!1),()=>!1,()=>!0,el,t=>{const e=Zh(t),i={};for(let s=0;s<e;s++)i[el(t)]=rl(t);return i},t=>{const e=Zh(t),i=[];for(let s=0;s<e;s++)i.push(rl(t));return i},Kh],rl=t=>sl[127-Gh(t)](t);class nl extends Qh{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return 0===this.count&&(this.s=this.reader(this),this.count=this.pos!==this.arr.length?Zh(this)+1:-1),this.count--,this.s}}class ol extends Qh{constructor(t){super(t),this.s=0,this.count=0}read(){if(0===this.count){this.s=tl(this);const t=lh(this.s);this.count=1,t&&(this.s=-this.s,this.count=Zh(this)+2)}return this.count--,this.s}}class hl extends Qh{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const t=tl(this),e=1&t;this.diff=sh(t/2),this.count=1,e&&(this.count=Zh(this)+2)}return this.s+=this.diff,this.count--,this.s}}class ll{constructor(t){this.decoder=new ol(t),this.str=el(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),e=this.str.slice(this.spos,t);return this.spos=t,e}}const ul=crypto.getRandomValues.bind(crypto),al=()=>ul(new Uint32Array(1))[0],cl=[1e7]+-1e3+-4e3+-8e3+-1e11,fl=()=>cl.replace(/[018]/g,(t=>(t^al()&15>>t/4).toString(16))),dl=Date.now,pl=t=>new Promise(t);Promise.all.bind(Promise);let wl=new class{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}},gl=!0;try{"undefined"!=typeof localStorage&&localStorage&&(wl=localStorage,gl=!1)}catch(Kn){}const ml=wl,vl=t=>gl||addEventListener("storage",t),yl=t=>gl||removeEventListener("storage",t),bl=Symbol("Equality"),kl=(t,e)=>t===e||!!t?.[bl]?.(e)||!1,Ml=Object.assign,xl=Object.keys,Al=(t,e)=>{const i=[];for(const s in t)i.push(e(t[s],s));return i},Cl=t=>xl(t).length,Sl=(t,e)=>{for(const i in t)if(!e(t[i],i))return!1;return!0},Bl=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Ol=Object.freeze,Tl=t=>{for(const e in t){const i=t[e];"object"!=typeof i&&"function"!=typeof i||Tl(t[e])}return Ol(t)},El=(t,e,i=0)=>{try{for(;i<t.length;i++)t[i](...e)}finally{i<t.length&&El(t,e,i+1)}},Dl=t=>t,Il=(t,e)=>{if(t===e)return!0;if(null==t||null==e||t.constructor!==e.constructor&&(t.constructor||Object)!==(e.constructor||Object))return!1;if(null!=t[bl])return t[bl](e);switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),e=new Uint8Array(e);case Uint8Array:if(t.byteLength!==e.byteLength)return!1;for(let i=0;i<t.length;i++)if(t[i]!==e[i])return!1;break;case Set:if(t.size!==e.size)return!1;for(const i of t)if(!e.has(i))return!1;break;case Map:if(t.size!==e.size)return!1;for(const i of t.keys())if(!e.has(i)||!Il(t.get(i),e.get(i)))return!1;break;case void 0:case Object:if(Cl(t)!==Cl(e))return!1;for(const i in t)if(!Bl(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},$l="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),Rl="undefined"!=typeof window&&"undefined"!=typeof document&&!$l;let Pl;const jl=t=>(()=>{if(void 0===Pl)if($l){Pl=Xo();const t=process.argv;let e=null;for(let i=0;i<t.length;i++){const s=t[i];"-"===s[0]?(null!==e&&Pl.set(e,""),e=s):null!==e&&(Pl.set(e,s),e=null)}null!==e&&Pl.set(e,"")}else"object"==typeof location?(Pl=Xo(),(location.search||"?").slice(1).split("&").forEach((t=>{if(0!==t.length){const[e,i]=t.split("=");Pl.set(`--${vh(e,"-")}`,i),Pl.set(`-${vh(e,"-")}`,i)}}))):Pl=Xo();return Pl})().has(t),Ul=t=>{return void 0===(e=$l?process.env[t.toUpperCase().replaceAll("-","_")]:ml.getItem(t))?null:e;var e},Nl=t=>jl("--"+t)||null!==Ul(t),Fl=Nl("production");var _l;const Ll=$l&&(_l=process.env.FORCE_COLOR,["true","1","2"].includes(_l))||!jl("--no-colors")&&!Nl("no-color")&&(!$l||process.stdout.isTTY)&&(!$l||jl("--color")||null!==Ul("COLORTERM")||(Ul("TERM")||"").includes("color")),zl=t=>new Uint8Array(t),Yl=t=>new Uint8Array(t),Wl=Rl?t=>{let e="";for(let i=0;i<t.byteLength;i++)e+=wh(t[i]);return btoa(e)}:t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),Xl=Rl?t=>{const e=atob(t),i=zl(e.length);for(let t=0;t<e.length;t++)i[t]=e.charCodeAt(t);return i}:t=>{const e=Buffer.from(t,"base64");return((t,e,i)=>new Uint8Array(t,e,i))(e.buffer,e.byteOffset,e.byteLength)};class Hl{constructor(t,e){this.left=t,this.right=e}}const Jl=(t,e)=>new Hl(t,e),Vl=t=>t.next()>=.5,Ql=(t,e,i)=>sh(t.next()*(i+1-e)+e),ql=(t,e,i)=>sh(t.next()*(i+1-e)+e),Kl=(t,e,i)=>ql(t,e,i),Gl=t=>wh(Kl(t,97,122)),Zl=(t,e)=>e[Kl(t,0,e.length-1)],tu=Symbol("0schema");class eu{constructor(){this._rerrs=[]}extend(t,e,i,s=null){this._rerrs.push({path:t,expected:e,has:i,message:s})}toString(){const t=[];for(let i=this._rerrs.length-1;i>0;i--){const s=this._rerrs[i];t.push((e=" ",(t=>{const i=new Array(t);for(let s=0;s<t;s++)i[s]=e;return i})(2*(this._rerrs.length-i)).join("")+`${null!=s.path?`[${s.path}] `:""}${s.has} doesn't match ${s.expected}. ${s.message}`))}var e;return t.join("\n")}}const iu=(t,e)=>t===e||null!=t&&null!=e&&t.constructor===e.constructor&&(t[bl]?kl(t,e):th(t)?Go(t,(t=>Zo(e,(e=>iu(t,e))))):!!(t=>"object"==typeof t)(t)&&Sl(t,((t,i)=>iu(t,e[i]))));class su{static _dilutes=!1;extends(t){let[e,i]=[this.shape,t.shape];return this.constructor._dilutes&&([i,e]=[e,i]),iu(e,i)}equals(t){return this.constructor===t.constructor&&Il(this.shape,t.shape)}[tu](){return!0}[bl](t){return this.equals(t)}validate(t){return this.check(t)}check(t,e){Xh()}get nullable(){return Iu(this,Ju)}get optional(){return new pu(this)}cast(t){return Ku(t,this),t}expect(t){return Ku(t,this),t}}class ru extends su{constructor(t,e){super(),this.shape=t,this._c=e}check(t,e){const i=t?.constructor===this.shape&&(null==this._c||this._c(t));return!i&&e?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),i}}const nu=(t,e=null)=>new ru(t,e);nu(ru);class ou extends su{constructor(t){super(),this.shape=t}check(t,e){const i=this.shape(t);return!i&&e?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),i}}const hu=t=>new ou(t);nu(ou);class lu extends su{constructor(t){super(),this.shape=t}check(t,e){const i=this.shape.some((e=>e===t));return!i&&e?.extend(null,this.shape.join(" | "),t.toString()),i}}const uu=(...t)=>new lu(t),au=nu(lu),cu=RegExp.escape||(t=>t.replace(/[().|&,$^[\]]/g,(t=>"\\"+t))),fu=t=>zu.check(t)?[cu(t)]:au.check(t)?t.shape.map((t=>t+"")):Lu.check(t)?["[+-]?\\d+.?\\d*"]:Yu.check(t)?[".*"]:$u.check(t)?t.shape.map(fu).flat(1):void Hh();nu(class extends su{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(fu).map((t=>`(${t.join("|")})`)).join("")+"$")}check(t,e){const i=null!=this._r.exec(t);return!i&&e?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),i}});const du=Symbol("optional");class pu extends su{constructor(t){super(),this.shape=t}check(t,e){const i=void 0===t||this.shape.check(t);return!i&&e?.extend(null,"undefined (optional)","()"),i}get[du](){return!0}}const wu=nu(pu);nu(class extends su{check(t,e){return e?.extend(null,"never",typeof t),!1}});class gu extends su{constructor(t,e=!1){super(),this.shape=t,this._isPartial=e}static _dilutes=!0;get partial(){return new gu(this.shape,!0)}check(t,e){return null==t?(e?.extend(null,"object","null"),!1):Sl(this.shape,((i,s)=>{const r=this._isPartial&&!Bl(t,s)||i.check(t[s],e);return!r&&e?.extend(s.toString(),i.toString(),typeof t[s],"Object property does not match"),r}))}}const mu=nu(gu),vu=hu((t=>null!=t&&(t.constructor===Object||null==t.constructor)));class yu extends su{constructor(t,e){super(),this.shape={keys:t,values:e}}check(t,e){return null!=t&&Sl(t,((i,s)=>{const r=this.shape.keys.check(s,e);return!r&&e?.extend(s+"","Record",typeof t,r?"Key doesn't match schema":"Value doesn't match value"),r&&this.shape.values.check(i,e)}))}}const bu=(t,e)=>new yu(t,e),ku=nu(yu);class Mu extends su{constructor(t){super(),this.shape=t}check(t,e){return null!=t&&Sl(this.shape,((i,s)=>{const r=i.check(t[s],e);return!r&&e?.extend(s.toString(),"Tuple",typeof i),r}))}}nu(Mu);class xu extends su{constructor(t){super(),this.shape=1===t.length?t[0]:new Du(t)}check(t,e){const i=th(t)&&Go(t,(t=>this.shape.check(t)));return!i&&e?.extend(null,"Array",""),i}}const Au=(...t)=>new xu(t),Cu=nu(xu),Su=hu((t=>th(t)));class Bu extends su{constructor(t,e){super(),this.shape=t,this._c=e}check(t,e){const i=t instanceof this.shape&&(null==this._c||this._c(t));return!i&&e?.extend(null,this.shape.name,t?.constructor.name),i}}nu(Bu);const Ou=((t,e=null)=>new Bu(su,e))(),Tu=nu(class extends su{constructor(t){super(),this.len=t.length-1,this.args=((...t)=>new Mu(t))(...t.slice(-1)),this.res=t[this.len]}check(t,e){const i=t.constructor===Function&&t.length<=this.len;return!i&&e?.extend(null,"function",typeof t),i}}),Eu=hu((t=>"function"==typeof t));nu(class extends su{constructor(t){super(),this.shape=t}check(t,e){const i=Go(this.shape,(i=>i.check(t,e)));return!i&&e?.extend(null,"Intersectinon",typeof t),i}},(t=>t.shape.length>0));class Du extends su{static _dilutes=!0;constructor(t){super(),this.shape=t}check(t,e){const i=Zo(this.shape,(i=>i.check(t,e)));return e?.extend(null,"Union",typeof t),i}}const Iu=(...t)=>t.findIndex((t=>$u.check(t)))>=0?Iu(...t.map((t=>qu(t))).map((t=>$u.check(t)?t.shape:[t])).flat(1)):1===t.length?t[0]:new Du(t),$u=nu(Du),Ru=()=>!0,Pu=hu(Ru),ju=nu(ou,(t=>t.shape===Ru)),Uu=hu((t=>"bigint"==typeof t)),Nu=hu((t=>t===Uu)),Fu=hu((t=>"symbol"==typeof t));hu((t=>t===Fu));const _u=hu((t=>"number"==typeof t)),Lu=hu((t=>t===_u)),zu=hu((t=>"string"==typeof t)),Yu=hu((t=>t===zu)),Wu=hu((t=>"boolean"==typeof t)),Xu=hu((t=>t===Wu)),Hu=uu(void 0);nu(lu,(t=>1===t.shape.length&&void 0===t.shape[0])),uu(void 0);const Ju=uu(null),Vu=nu(lu,(t=>1===t.shape.length&&null===t.shape[0]));nu(Uint8Array),nu(ru,(t=>t.shape===Uint8Array));const Qu=Iu(_u,zu,Ju,Hu,Uu,Wu,Fu);(()=>{const t=Au(Pu),e=bu(zu,Pu),i=Iu(_u,zu,Ju,Wu,t,e);t.shape=i,e.shape.values=i})();const qu=t=>{if(Ou.check(t))return t;if(vu.check(t)){const e={};for(const i in t)e[i]=qu(t[i]);return new gu(e)}return Su.check(t)?Iu(...t.map(qu)):Qu.check(t)?uu(t):Eu.check(t)?nu(t):void Hh()},Ku=Fl?()=>{}:(t,e)=>{const i=new eu;if(!e.check(t,i))throw Wh(`Expected value to be of type ${e.constructor.name}.\n${i.toString()}`)};const Gu=(Zu=Pu,new class{constructor(t){this.patterns=[],this.$state=t}if(t,e){return this.patterns.push({if:qu(t),h:e}),this}else(t){return this.if(Pu,t)}done(){return(t,e)=>{for(let i=0;i<this.patterns.length;i++){const s=this.patterns[i];if(s.if.check(t))return s.h(t,e)}throw Wh("Unhandled pattern")}}}(Zu)).if(Lu,((t,e)=>Ql(e,dh,fh))).if(Yu,((t,e)=>((t,e=0,i=20)=>{const s=Kl(t,e,i);let r="";for(let e=0;e<s;e++)r+=Gl(t);return r})(e))).if(Xu,((t,e)=>Vl(e))).if(Nu,((t,e)=>BigInt(Ql(e,dh,fh)))).if($u,((t,e)=>ta(e,Zl(e,t.shape)))).if(mu,((t,e)=>{const i={};for(const s in t.shape){let r=t.shape[s];if(wu.check(r)){if(Vl(e))continue;r=r.shape}i[s]=Gu(r,e)}return i})).if(Cu,((t,e)=>{const i=[],s=ql(e,0,42);for(let r=0;r<s;r++)i.push(ta(e,t.shape));return i})).if(au,((t,e)=>Zl(e,t.shape))).if(Vu,(()=>null)).if(Tu,((t,e)=>{const i=ta(e,t.res);return()=>i})).if(ju,((t,e)=>ta(e,Zl(e,[_u,zu,Ju,Hu,Uu,Wu,Au(_u),bu(Iu("a","b","c"),_u)])))).if(ku,((t,e)=>{const i={},s=Ql(e,0,3);for(let r=0;r<s;r++){const s=ta(e,t.shape.keys),r=ta(e,t.shape.values);i[s]=r}return i})).done();var Zu;const ta=(t,e)=>Gu(qu(e),t),ea="undefined"!=typeof document?document:{};hu((t=>t.nodeType===na)),"undefined"!=typeof DOMParser&&new DOMParser,hu((t=>t.nodeType===ia)),hu((t=>t.nodeType===sa));const ia=ea.ELEMENT_NODE,sa=ea.TEXT_NODE,ra=ea.DOCUMENT_NODE,na=ea.DOCUMENT_FRAGMENT_NODE;hu((t=>t.nodeType===ra));const oa=Symbol,ha=oa(),la=oa(),ua=oa(),aa=oa(),ca=oa(),fa=oa(),da=oa(),pa=oa(),wa=oa(),ga={[ha]:Jl("font-weight","bold"),[la]:Jl("font-weight","normal"),[ua]:Jl("color","blue"),[ca]:Jl("color","green"),[aa]:Jl("color","grey"),[fa]:Jl("color","red"),[da]:Jl("color","purple"),[pa]:Jl("color","orange"),[wa]:Jl("color","black")},ma=Ll?t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const e=[],i=[],s=Xo();let r=[],n=0;for(;n<t.length;n++){const r=t[n],o=ga[r];if(void 0!==o)s.set(o.left,o.right);else{if(void 0===r)break;if(r.constructor!==String&&r.constructor!==Number)break;{const t=((t,e)=>{const i=[];for(const[s,r]of t)i.push(e(r,s));return i})(s,((t,e)=>`${e}:${t};`)).join("");n>0||t.length>0?(e.push("%c"+r),i.push(t)):e.push(r)}}}for(n>0&&(r=i,r.unshift(e.join("")));n<t.length;n++){const e=t[n];e instanceof Symbol||r.push(e)}return r}:t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const e=[],i=[];let s=0;for(;s<t.length;s++){const i=t[s];if(void 0===i)break;if(i.constructor===String||i.constructor===Number)e.push(i);else if(i.constructor===Object)break}for(s>0&&i.push(e.join(""));s<t.length;s++){const e=t[s];e instanceof Symbol||i.push(e)}return i},va=(...t)=>{console.warn(...ma(t)),t.unshift(pa),ya.forEach((e=>e.print(t)))},ya=Vo(),ba=t=>({[Symbol.iterator](){return this},next:t}),ka=(t,e)=>ba((()=>{const{done:i,value:s}=t.next();return{done:i,value:i?void 0:e(s)}}));class Ma{constructor(t,e){this.clock=t,this.len=e}}class xa{constructor(){this.clients=new Map}}const Aa=(t,e,i)=>e.clients.forEach(((e,s)=>{const r=t.doc.store.clients.get(s);if(null!=r){const s=r[r.length-1],n=s.id.clock+s.length;for(let s=0,o=e[s];s<e.length&&o.clock<n;o=e[++s])gc(t,r,o.clock,o.len,i)}})),Ca=(t,e)=>{const i=t.clients.get(e.client);return void 0!==i&&null!==((t,e)=>{let i=0,s=t.length-1;for(;i<=s;){const r=sh((i+s)/2),n=t[r],o=n.clock;if(o<=e){if(e<o+n.len)return r;i=r+1}else s=r-1}return null})(i,e.clock)},Sa=t=>{t.clients.forEach((t=>{let e,i;for(t.sort(((t,e)=>t.clock-e.clock)),e=1,i=1;e<t.length;e++){const s=t[i-1],r=t[e];s.clock+s.len>=r.clock?s.len=oh(s.len,r.clock+r.len-s.clock):(i<e&&(t[i]=r),i++)}t.length=i}))},Ba=t=>{const e=new xa;for(let i=0;i<t.length;i++)t[i].clients.forEach(((s,r)=>{if(!e.clients.has(r)){const n=s.slice();for(let e=i+1;e<t.length;e++)qo(n,t[e].clients.get(r)||[]);e.clients.set(r,n)}}));return Sa(e),e},Oa=(t,e,i,s)=>{Jo(t.clients,e,(()=>[])).push(new Ma(i,s))},Ta=(t,e)=>{Oh(t.restEncoder,e.clients.size),Ko(e.clients.entries()).sort(((t,e)=>e[0]-t[0])).forEach((([e,i])=>{t.resetDsCurVal(),Oh(t.restEncoder,e);const s=i.length;Oh(t.restEncoder,s);for(let e=0;e<s;e++){const s=i[e];t.writeDsClock(s.clock),t.writeDsLen(s.len)}}))},Ea=t=>{const e=new xa,i=Zh(t.restDecoder);for(let s=0;s<i;s++){t.resetDsCurVal();const i=Zh(t.restDecoder),s=Zh(t.restDecoder);if(s>0){const r=Jo(e.clients,i,(()=>[]));for(let e=0;e<s;e++)r.push(new Ma(t.readDsClock(),t.readDsLen()))}}return e},Da=(t,e,i)=>{const s=new xa,r=Zh(t.restDecoder);for(let n=0;n<r;n++){t.resetDsCurVal();const r=Zh(t.restDecoder),n=Zh(t.restDecoder),o=i.clients.get(r)||[],h=uc(i,r);for(let i=0;i<n;i++){const i=t.readDsClock(),n=i+t.readDsLen();if(i<h){h<n&&Oa(s,r,h,n-h);let t=cc(o,i),l=o[t];for(!l.deleted&&l.id.clock<i&&(o.splice(t+1,0,od(e,l,i-l.id.clock)),t++);t<o.length&&(l=o[t++],l.id.clock<n);)l.deleted||(n<l.id.clock+l.length&&o.splice(t,0,od(e,l,n-l.id.clock)),l.delete(e))}else Oa(s,r,i,n-i)}}if(s.clients.size>0){const t=new La;return Oh(t.restEncoder,0),Ta(t,s),t.toUint8Array()}return null},Ia=al;class $a extends eh{constructor({guid:t=fl(),collectionid:e=null,gc:i=!0,gcFilter:s=()=>!0,meta:r=null,autoLoad:n=!1,shouldLoad:o=!0}={}){super(),this.gc=i,this.gcFilter=s,this.clientID=Ia(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new hc,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=n,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=pl((t=>{this.on("load",(()=>{this.isLoaded=!0,t(this)}))}));const h=()=>pl((t=>{const e=i=>{void 0!==i&&!0!==i||(this.off("sync",e),t())};this.on("sync",e)}));this.on("sync",(t=>{!1===t&&this.isSynced&&(this.whenSynced=h()),this.isSynced=void 0===t||!0===t,this.isSynced&&!this.isLoaded&&this.emit("load",[this])})),this.whenSynced=h()}load(){const t=this._item;null===t||this.shouldLoad||Mc(t.parent.doc,(t=>{t.subdocsLoaded.add(this)}),null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Ko(this.subdocs).map((t=>t.guid)))}transact(t,e=null){return Mc(this,t,e)}get(t,e=Jc){const i=Jo(this.share,t,(()=>{const t=new e;return t._integrate(this,null),t})),s=i.constructor;if(e!==Jc&&s!==e){if(s===Jc){const s=new e;s._map=i._map,i._map.forEach((t=>{for(;null!==t;t=t.left)t.parent=s})),s._start=i._start;for(let t=s._start;null!==t;t=t.right)t.parent=s;return s._length=i._length,this.share.set(t,s),s._integrate(this,null),s}throw new Error(`Type with the name ${t} has already been defined with a different constructor`)}return i}getArray(t=""){return this.get(t,ff)}getText(t=""){return this.get(t,Ef)}getMap(t=""){return this.get(t,pf)}getXmlElement(t=""){return this.get(t,$f)}getXmlFragment(t=""){return this.get(t,If)}toJSON(){const t={};return this.share.forEach(((e,i)=>{t[i]=e.toJSON()})),t}destroy(){this.isDestroyed=!0,Ko(this.subdocs).forEach((t=>t.destroy()));const t=this._item;if(null!==t){this._item=null;const e=t.content;e.doc=new $a({guid:this.guid,...e.opts,shouldLoad:!1}),e.doc._item=t,Mc(t.parent.doc,(i=>{t.deleted||i.subdocsAdded.add(e.doc),i.subdocsRemoved.add(this)}),null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Ra{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return Zh(this.restDecoder)}readDsLen(){return Zh(this.restDecoder)}}class Pa extends Ra{readLeftID(){return sc(Zh(this.restDecoder),Zh(this.restDecoder))}readRightID(){return sc(Zh(this.restDecoder),Zh(this.restDecoder))}readClient(){return Zh(this.restDecoder)}readInfo(){return Gh(this.restDecoder)}readString(){return el(this.restDecoder)}readParentInfo(){return 1===Zh(this.restDecoder)}readTypeRef(){return Zh(this.restDecoder)}readLen(){return Zh(this.restDecoder)}readAny(){return rl(this.restDecoder)}readBuf(){return(t=>{const e=zl(t.byteLength);return e.set(t),e})(Kh(this.restDecoder))}readJSON(){return JSON.parse(el(this.restDecoder))}readKey(){return el(this.restDecoder)}}class ja{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Zh(this.restDecoder),this.dsCurrVal}readDsLen(){const t=Zh(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Ua extends ja{constructor(t){super(t),this.keys=[],Zh(t),this.keyClockDecoder=new hl(Kh(t)),this.clientDecoder=new ol(Kh(t)),this.leftClockDecoder=new hl(Kh(t)),this.rightClockDecoder=new hl(Kh(t)),this.infoDecoder=new nl(Kh(t),Gh),this.stringDecoder=new ll(Kh(t)),this.parentInfoDecoder=new nl(Kh(t),Gh),this.typeRefDecoder=new ol(Kh(t)),this.lenDecoder=new ol(Kh(t))}readLeftID(){return new ec(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ec(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return rl(this.restDecoder)}readBuf(){return Kh(this.restDecoder)}readJSON(){return rl(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const t=this.stringDecoder.read();return this.keys.push(t),t}}}class Na{constructor(){this.restEncoder=xh()}toUint8Array(){return Ch(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){Oh(this.restEncoder,t)}writeDsLen(t){Oh(this.restEncoder,t)}}class Fa extends Na{writeLeftID(t){Oh(this.restEncoder,t.client),Oh(this.restEncoder,t.clock)}writeRightID(t){Oh(this.restEncoder,t.client),Oh(this.restEncoder,t.clock)}writeClient(t){Oh(this.restEncoder,t)}writeInfo(t){Bh(this.restEncoder,t)}writeString(t){Ih(this.restEncoder,t)}writeParentInfo(t){Oh(this.restEncoder,t?1:0)}writeTypeRef(t){Oh(this.restEncoder,t)}writeLen(t){Oh(this.restEncoder,t)}writeAny(t){Uh(this.restEncoder,t)}writeBuf(t){Rh(this.restEncoder,t)}writeJSON(t){Ih(this.restEncoder,JSON.stringify(t))}writeKey(t){Ih(this.restEncoder,t)}}class _a{constructor(){this.restEncoder=xh(),this.dsCurrVal=0}toUint8Array(){return Ch(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const e=t-this.dsCurrVal;this.dsCurrVal=t,Oh(this.restEncoder,e)}writeDsLen(t){0===t&&Hh(),Oh(this.restEncoder,t-1),this.dsCurrVal+=t}}class La extends _a{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new zh,this.clientEncoder=new _h,this.leftClockEncoder=new zh,this.rightClockEncoder=new zh,this.infoEncoder=new Nh(Bh),this.stringEncoder=new Yh,this.parentInfoEncoder=new Nh(Bh),this.typeRefEncoder=new _h,this.lenEncoder=new _h}toUint8Array(){const t=xh();return Oh(t,0),Rh(t,this.keyClockEncoder.toUint8Array()),Rh(t,this.clientEncoder.toUint8Array()),Rh(t,this.leftClockEncoder.toUint8Array()),Rh(t,this.rightClockEncoder.toUint8Array()),Rh(t,Ch(this.infoEncoder)),Rh(t,this.stringEncoder.toUint8Array()),Rh(t,Ch(this.parentInfoEncoder)),Rh(t,this.typeRefEncoder.toUint8Array()),Rh(t,this.lenEncoder.toUint8Array()),$h(t,Ch(this.restEncoder)),Ch(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){Uh(this.restEncoder,t)}writeBuf(t){Rh(this.restEncoder,t)}writeJSON(t){Uh(this.restEncoder,t)}writeKey(t){const e=this.keyMap.get(t);void 0===e?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(e)}}const za=(t,e,i)=>{const s=new Map;i.forEach(((t,i)=>{uc(e,i)>t&&s.set(i,t)})),lc(e).forEach(((t,e)=>{i.has(e)||s.set(e,0)})),Oh(t.restEncoder,s.size),Ko(s.entries()).sort(((t,e)=>e[0]-t[0])).forEach((([i,s])=>{((t,e,i,s)=>{s=oh(s,e[0].id.clock);const r=cc(e,s);Oh(t.restEncoder,e.length-r),t.writeClient(i),Oh(t.restEncoder,s);const n=e[r];n.write(t,s-n.id.clock);for(let i=r+1;i<e.length;i++)e[i].write(t,0)})(t,e.clients.get(i),i,s)}))},Ya=(t,e,i,s=Ua)=>{const r=qh(e);((t,e,i,s=new Ua(t))=>{Mc(e,(t=>{t.local=!1;let e=!1;const i=t.doc,r=i.store,n=((t,e)=>{const i=Xo(),s=Zh(t.restDecoder);for(let r=0;r<s;r++){const s=Zh(t.restDecoder),r=new Array(s),n=t.readClient();let o=Zh(t.restDecoder);i.set(n,{i:0,refs:r});for(let i=0;i<s;i++){const s=t.readInfo();switch(31&s){case 0:{const e=t.readLen();r[i]=new Nf(sc(n,o),e),o+=e;break}case 10:{const e=Zh(t.restDecoder);r[i]=new fd(sc(n,o),e),o+=e;break}default:{const h=!(192&s),l=new ud(sc(n,o),null,(s&ah)===ah?t.readLeftID():null,null,(s&uh)===uh?t.readRightID():null,h?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,!h||32&~s?null:t.readString(),ad(t,s));r[i]=l,o+=l.length}}}}return i})(s,i),o=((t,e,i)=>{const s=[];let r=Ko(i.keys()).sort(((t,e)=>t-e));if(0===r.length)return null;const n=()=>{if(0===r.length)return null;let t=i.get(r[r.length-1]);for(;t.refs.length===t.i;){if(r.pop(),!(r.length>0))return null;t=i.get(r[r.length-1])}return t};let o=n();if(null===o)return null;const h=new hc,l=new Map,u=(t,e)=>{const i=l.get(t);(null==i||i>e)&&l.set(t,e)};let a=o.refs[o.i++];const c=new Map,f=()=>{for(const t of s){const e=t.id.client,s=i.get(e);s?(s.i--,h.clients.set(e,s.refs.slice(s.i)),i.delete(e),s.i=0,s.refs=[]):h.clients.set(e,[t]),r=r.filter((t=>t!==e))}s.length=0};for(;;){if(a.constructor!==fd){const r=Jo(c,a.id.client,(()=>uc(e,a.id.client)))-a.id.clock;if(r<0)s.push(a),u(a.id.client,a.id.clock-1),f();else{const n=a.getMissing(t,e);if(null!==n){s.push(a);const t=i.get(n)||{refs:[],i:0};if(t.refs.length!==t.i){a=t.refs[t.i++];continue}u(n,uc(e,n)),f()}else(0===r||r<a.length)&&(a.integrate(t,r),c.set(a.id.client,a.id.clock+a.length))}}if(s.length>0)a=s.pop();else if(null!==o&&o.i<o.refs.length)a=o.refs[o.i++];else{if(o=n(),null===o)break;a=o.refs[o.i++]}}if(h.clients.size>0){const t=new La;return za(t,h,new Map),Oh(t.restEncoder,0),{missing:l,update:t.toUint8Array()}}return null})(t,r,n),h=r.pendingStructs;if(h){for(const[t,i]of h.missing)if(i<uc(r,t)){e=!0;break}if(o){for(const[t,e]of o.missing){const i=h.missing.get(t);(null==i||i>e)&&h.missing.set(t,e)}h.update=Dc([h.update,o.update])}}else r.pendingStructs=o;const l=Da(s,t,r);if(r.pendingDs){const e=new Ua(qh(r.pendingDs));Zh(e.restDecoder);const i=Da(e,t,r);r.pendingDs=l&&i?Dc([l,i]):l||i}else r.pendingDs=l;if(e){const e=r.pendingStructs.update;r.pendingStructs=null,Ya(t.doc,e)}}),i,!1)})(r,t,i,new s(r))},Wa=(t,e,i)=>Ya(t,e,i,Pa),Xa=(t,e=new Uint8Array([0]),i=new La)=>{((t,e,i=new Map)=>{za(t,e.store,i),Ta(t,(t=>{const e=new xa;return t.clients.forEach(((t,i)=>{const s=[];for(let e=0;e<t.length;e++){const i=t[e];if(i.deleted){const r=i.id.clock;let n=i.length;if(e+1<t.length)for(let i=t[e+1];e+1<t.length&&i.deleted;i=t[1+ ++e])n+=i.length;s.push(new Ma(r,n))}}s.length>0&&e.clients.set(i,s)})),e})(e.store))})(i,t,Ja(e));const s=[i.toUint8Array()];if(t.store.pendingDs&&s.push(t.store.pendingDs),t.store.pendingStructs&&s.push(Ic(t.store.pendingStructs.update,e)),s.length>1){if(i.constructor===Fa)return Tc(s.map(((t,e)=>0===e?t:jc(t))));if(i.constructor===La)return Dc(s)}return s[0]},Ha=(t,e)=>Xa(t,e,new Fa),Ja=t=>(t=>{const e=new Map,i=Zh(t.restDecoder);for(let s=0;s<i;s++){const i=Zh(t.restDecoder),s=Zh(t.restDecoder);e.set(i,s)}return e})(new Ra(qh(t))),Va=(t,e)=>(Oh(t.restEncoder,e.size),Ko(e.entries()).sort(((t,e)=>e[0]-t[0])).forEach((([e,i])=>{Oh(t.restEncoder,e),Oh(t.restEncoder,i)})),t),Qa=t=>((t,e=new _a)=>(t instanceof Map?Va(e,t):((t,e)=>{Va(t,lc(e.store))})(e,t),e.toUint8Array()))(t,new Na);class qa{constructor(){this.l=[]}}const Ka=()=>new qa,Ga=(t,e)=>t.l.push(e),Za=(t,e)=>{const i=t.l,s=i.length;t.l=i.filter((t=>e!==t)),s===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},tc=(t,e,i)=>El(t.l,[e,i]);class ec{constructor(t,e){this.client=t,this.clock=e}}const ic=(t,e)=>t===e||null!==t&&null!==e&&t.client===e.client&&t.clock===e.clock,sc=(t,e)=>new ec(t,e),rc=(t,e)=>{for(;null!==e;){if(e.parent===t)return!0;e=e.parent._item}return!1},nc=(t,e)=>void 0===e?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!Ca(e.ds,t.id),oc=(t,e)=>{const i=Jo(t.meta,oc,Vo),s=t.doc.store;i.has(e)||(e.sv.forEach(((e,i)=>{e<uc(s,i)&&pc(t,sc(i,e))})),Aa(t,e.ds,(()=>{})),i.add(e))};class hc{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const lc=t=>{const e=new Map;return t.clients.forEach(((t,i)=>{const s=t[t.length-1];e.set(i,s.id.clock+s.length)})),e},uc=(t,e)=>{const i=t.clients.get(e);if(void 0===i)return 0;const s=i[i.length-1];return s.id.clock+s.length},ac=(t,e)=>{let i=t.clients.get(e.id.client);if(void 0===i)i=[],t.clients.set(e.id.client,i);else{const t=i[i.length-1];if(t.id.clock+t.length!==e.id.clock)throw Hh()}i.push(e)},cc=(t,e)=>{let i=0,s=t.length-1,r=t[s],n=r.id.clock;if(n===e)return s;let o=sh(e/(n+r.length-1)*s);for(;i<=s;){if(r=t[o],n=r.id.clock,n<=e){if(e<n+r.length)return o;i=o+1}else s=o-1;o=sh((i+s)/2)}throw Hh()},fc=(t,e)=>{const i=t.clients.get(e.client);return i[cc(i,e.clock)]},dc=(t,e,i)=>{const s=cc(e,i),r=e[s];return r.id.clock<i&&r instanceof ud?(e.splice(s+1,0,od(t,r,i-r.id.clock)),s+1):s},pc=(t,e)=>{const i=t.doc.store.clients.get(e.client);return i[dc(t,i,e.clock)]},wc=(t,e,i)=>{const s=e.clients.get(i.client),r=cc(s,i.clock),n=s[r];return i.clock!==n.id.clock+n.length-1&&n.constructor!==Nf&&s.splice(r+1,0,od(t,n,i.clock-n.id.clock+1)),n},gc=(t,e,i,s,r)=>{if(0===s)return;const n=i+s;let o,h=dc(t,e,i);do{o=e[h++],n<o.id.clock+o.length&&dc(t,e,n),r(o)}while(h<e.length&&e[h].id.clock<n)};class mc{constructor(t,e,i){this.doc=t,this.deleteSet=new xa,this.beforeState=lc(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=e,this.meta=new Map,this.local=i,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const vc=(t,e)=>!(0===e.deleteSet.clients.size&&!(t=>{for(const[s,r]of t)if(i=r,e.beforeState.get(s)!==i)return!0;var i;return!1})(e.afterState)||(Sa(e.deleteSet),((t,e)=>{za(t,e.doc.store,e.beforeState)})(t,e),Ta(t,e.deleteSet),0)),yc=(t,e,i)=>{const s=e._item;(null===s||s.id.clock<(t.beforeState.get(s.id.client)||0)&&!s.deleted)&&Jo(t.changed,e,Vo).add(i)},bc=(t,e)=>{let i=t[e],s=t[e-1],r=e;for(;r>0&&s.deleted===i.deleted&&s.constructor===i.constructor&&s.mergeWith(i);i=s,s=t[--r-1])i instanceof ud&&null!==i.parentSub&&i.parent._map.get(i.parentSub)===i&&i.parent._map.set(i.parentSub,s);const n=e-r;return n&&t.splice(e+1-n,n),n},kc=(t,e)=>{if(e<t.length){const i=t[e],s=i.doc,r=s.store,n=i.deleteSet,o=i._mergeStructs;try{Sa(n),i.afterState=lc(i.doc.store),s.emit("beforeObserverCalls",[i,s]);const t=[];i.changed.forEach(((e,s)=>t.push((()=>{null!==s._item&&s._item.deleted||s._callObserver(i,e)})))),t.push((()=>{i.changedParentTypes.forEach(((e,s)=>{s._dEH.l.length>0&&(null===s._item||!s._item.deleted)&&((e=e.filter((t=>null===t.target._item||!t.target._item.deleted))).forEach((t=>{t.currentTarget=s,t._path=null})),e.sort(((t,e)=>t.path.length-e.path.length)),t.push((()=>{tc(s._dEH,e,i)})))})),t.push((()=>s.emit("afterTransaction",[i,s]))),t.push((()=>{i._needFormattingCleanup&&Bf(i)}))})),El(t,[])}finally{s.gc&&((t,e,i)=>{for(const[s,r]of t.clients.entries()){const t=e.clients.get(s);for(let s=r.length-1;s>=0;s--){const n=r[s],o=n.clock+n.len;for(let s=cc(t,n.clock),r=t[s];s<t.length&&r.id.clock<o;r=t[++s]){const r=t[s];if(n.clock+n.len<=r.id.clock)break;r instanceof ud&&r.deleted&&!r.keep&&i(r)&&r.gc(e,!1)}}}})(n,r,s.gcFilter),((t,e)=>{t.clients.forEach(((t,i)=>{const s=e.clients.get(i);for(let e=t.length-1;e>=0;e--){const i=t[e];for(let t=nh(s.length-1,1+cc(s,i.clock+i.len-1)),e=s[t];t>0&&e.id.clock>=i.clock;e=s[t])t-=1+bc(s,t)}}))})(n,r),i.afterState.forEach(((t,e)=>{const s=i.beforeState.get(e)||0;if(s!==t){const t=r.clients.get(e),i=oh(cc(t,s),1);for(let e=t.length-1;e>=i;)e-=1+bc(t,e)}}));for(let t=o.length-1;t>=0;t--){const{client:e,clock:i}=o[t].id,s=r.clients.get(e),n=cc(s,i);n+1<s.length&&bc(s,n+1)>1||n>0&&bc(s,n)}if(i.local||i.afterState.get(s.clientID)===i.beforeState.get(s.clientID)||(((...t)=>{console.log(...ma(t)),ya.forEach((e=>e.print(t)))})(pa,ha,"[yjs] ",la,fa,"Changed the client-id because another client seems to be using it."),s.clientID=Ia()),s.emit("afterTransactionCleanup",[i,s]),s._observers.has("update")){const t=new Fa;vc(t,i)&&s.emit("update",[t.toUint8Array(),i.origin,s,i])}if(s._observers.has("updateV2")){const t=new La;vc(t,i)&&s.emit("updateV2",[t.toUint8Array(),i.origin,s,i])}const{subdocsAdded:h,subdocsLoaded:l,subdocsRemoved:u}=i;(h.size>0||u.size>0||l.size>0)&&(h.forEach((t=>{t.clientID=s.clientID,null==t.collectionid&&(t.collectionid=s.collectionid),s.subdocs.add(t)})),u.forEach((t=>s.subdocs.delete(t))),s.emit("subdocs",[{loaded:l,added:h,removed:u},s,i]),u.forEach((t=>t.destroy()))),t.length<=e+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,t])):kc(t,e+1)}}},Mc=(t,e,i=null,s=!0)=>{const r=t._transactionCleanups;let n=!1,o=null;null===t._transaction&&(n=!0,t._transaction=new mc(t,i,s),r.push(t._transaction),1===r.length&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{o=e(t._transaction)}finally{if(n){const e=t._transaction===r[0];t._transaction=null,e&&kc(r,0)}}return o};class xc{constructor(t,e){this.insertions=e,this.deletions=t,this.meta=new Map}}const Ac=(t,e,i)=>{Aa(t,i.deletions,(i=>{i instanceof ud&&e.scope.some((e=>e===t.doc||rc(e,i)))&&nd(i,!1)}))},Cc=(t,e,i)=>{let s=null;const r=t.doc,n=t.scope;Mc(r,(i=>{for(;e.length>0&&null===t.currStackItem;){const s=r.store,o=e.pop(),h=new Set,l=[];let u=!1;Aa(i,o.insertions,(t=>{if(t instanceof ud){if(null!==t.redone){let{item:e,diff:r}=rd(s,t.id);r>0&&(e=pc(i,sc(e.id.client,e.id.clock+r))),t=e}!t.deleted&&n.some((e=>e===i.doc||rc(e,t)))&&l.push(t)}})),Aa(i,o.deletions,(t=>{t instanceof ud&&n.some((e=>e===i.doc||rc(e,t)))&&!Ca(o.insertions,t.id)&&h.add(t)})),h.forEach((e=>{u=null!==ld(i,e,h,o.insertions,t.ignoreRemoteMapChanges,t)||u}));for(let e=l.length-1;e>=0;e--){const s=l[e];t.deleteFilter(s)&&(s.delete(i),u=!0)}t.currStackItem=u?o:null}i.changed.forEach(((t,e)=>{t.has(null)&&e._searchMarker&&(e._searchMarker.length=0)})),s=i}),t);const o=t.currStackItem;return null!=o&&(t.emit("stack-item-popped",[{stackItem:o,type:i,changedParentTypes:s.changedParentTypes,origin:t},t]),t.currStackItem=null),o};class Sc extends eh{constructor(t,{captureTimeout:e=500,captureTransaction:i=()=>!0,deleteFilter:s=()=>!0,trackedOrigins:r=new Set([null]),ignoreRemoteMapChanges:n=!1,doc:o=(th(t)?t[0].doc:t instanceof $a?t:t.doc)}={}){super(),this.scope=[],this.doc=o,this.addToScope(t),this.deleteFilter=s,r.add(this),this.trackedOrigins=r,this.captureTransaction=i,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=n,this.captureTimeout=e,this.afterTransactionHandler=t=>{if(!(this.captureTransaction(t)&&this.scope.some((e=>t.changedParentTypes.has(e)||e===this.doc))&&(this.trackedOrigins.has(t.origin)||t.origin&&this.trackedOrigins.has(t.origin.constructor))))return;const e=this.undoing,i=this.redoing,s=e?this.redoStack:this.undoStack;e?this.stopCapturing():i||this.clear(!1,!0);const r=new xa;t.afterState.forEach(((e,i)=>{const s=t.beforeState.get(i)||0,n=e-s;n>0&&Oa(r,i,s,n)}));const n=dl();let o=!1;if(this.lastChange>0&&n-this.lastChange<this.captureTimeout&&s.length>0&&!e&&!i){const e=s[s.length-1];e.deletions=Ba([e.deletions,t.deleteSet]),e.insertions=Ba([e.insertions,r])}else s.push(new xc(t.deleteSet,r)),o=!0;e||i||(this.lastChange=n),Aa(t,t.deleteSet,(e=>{e instanceof ud&&this.scope.some((i=>i===t.doc||rc(i,e)))&&nd(e,!0)}));this.emit(o?"stack-item-added":"stack-item-updated",[{stackItem:s[s.length-1],origin:t.origin,type:e?"redo":"undo",changedParentTypes:t.changedParentTypes},this])},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",(()=>{this.destroy()}))}addToScope(t){const e=new Set(this.scope);(t=th(t)?t:[t]).forEach((t=>{e.has(t)||(e.add(t),(t instanceof Jc?t.doc!==this.doc:t!==this.doc)&&va("[yjs#509] Not same Y.Doc"),this.scope.push(t))}))}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,e=!0){(t&&this.canUndo()||e&&this.canRedo())&&this.doc.transact((i=>{t&&(this.undoStack.forEach((t=>Ac(i,this,t))),this.undoStack=[]),e&&(this.redoStack.forEach((t=>Ac(i,this,t))),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:e}])}))}stopCapturing(){this.lastChange=0}undo(){let t;this.undoing=!0;try{t=Cc(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){let t;this.redoing=!0;try{t=Cc(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}class Bc{constructor(t,e){this.gen=function*(t){const e=Zh(t.restDecoder);for(let i=0;i<e;i++){const e=Zh(t.restDecoder),i=t.readClient();let s=Zh(t.restDecoder);for(let r=0;r<e;r++){const e=t.readInfo();if(10===e){const e=Zh(t.restDecoder);yield new fd(sc(i,s),e),s+=e}else if(31&e){const r=!(192&e),n=new ud(sc(i,s),null,(e&ah)===ah?t.readLeftID():null,null,(e&uh)===uh?t.readRightID():null,r?t.readParentInfo()?t.readString():t.readLeftID():null,!r||32&~e?null:t.readString(),ad(t,e));yield n,s+=n.length}else{const e=t.readLen();yield new Nf(sc(i,s),e),s+=e}}}}(t),this.curr=null,this.done=!1,this.filterSkips=e,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===fd);return this.curr}}class Oc{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Tc=t=>Dc(t,Pa,Fa),Ec=(t,e)=>{if(t.constructor===Nf){const{client:i,clock:s}=t.id;return new Nf(sc(i,s+e),t.length-e)}if(t.constructor===fd){const{client:i,clock:s}=t.id;return new fd(sc(i,s+e),t.length-e)}{const i=t,{client:s,clock:r}=i.id;return new ud(sc(s,r+e),null,sc(s,r+e-1),null,i.rightOrigin,i.parent,i.parentSub,i.content.splice(e))}},Dc=(t,e=Ua,i=La)=>{if(1===t.length)return t[0];const s=t.map((t=>new e(qh(t))));let r=s.map((t=>new Bc(t,!0))),n=null;const o=new i,h=new Oc(o);for(;r=r.filter((t=>null!==t.curr)),r.sort(((t,e)=>{if(t.curr.id.client===e.curr.id.client){const i=t.curr.id.clock-e.curr.id.clock;return 0===i?t.curr.constructor===e.curr.constructor?0:t.curr.constructor===fd?1:-1:i}return e.curr.id.client-t.curr.id.client})),0!==r.length;){const t=r[0],e=t.curr.id.client;if(null!==n){let i=t.curr,s=!1;for(;null!==i&&i.id.clock+i.length<=n.struct.id.clock+n.struct.length&&i.id.client>=n.struct.id.client;)i=t.next(),s=!0;if(null===i||i.id.client!==e||s&&i.id.clock>n.struct.id.clock+n.struct.length)continue;if(e!==n.struct.id.client)Rc(h,n.struct,n.offset),n={struct:i,offset:0},t.next();else if(n.struct.id.clock+n.struct.length<i.id.clock)if(n.struct.constructor===fd)n.struct.length=i.id.clock+i.length-n.struct.id.clock;else{Rc(h,n.struct,n.offset);const t=i.id.clock-n.struct.id.clock-n.struct.length;n={struct:new fd(sc(e,n.struct.id.clock+n.struct.length),t),offset:0}}else{const e=n.struct.id.clock+n.struct.length-i.id.clock;e>0&&(n.struct.constructor===fd?n.struct.length-=e:i=Ec(i,e)),n.struct.mergeWith(i)||(Rc(h,n.struct,n.offset),n={struct:i,offset:0},t.next())}}else n={struct:t.curr,offset:0},t.next();for(let i=t.curr;null!==i&&i.id.client===e&&i.id.clock===n.struct.id.clock+n.struct.length&&i.constructor!==fd;i=t.next())Rc(h,n.struct,n.offset),n={struct:i,offset:0}}null!==n&&(Rc(h,n.struct,n.offset),n=null),Pc(h);const l=s.map((t=>Ea(t))),u=Ba(l);return Ta(o,u),o.toUint8Array()},Ic=(t,e,i=Ua,s=La)=>{const r=Ja(e),n=new s,o=new Oc(n),h=new i(qh(t)),l=new Bc(h,!1);for(;l.curr;){const t=l.curr,e=t.id.client,i=r.get(e)||0;if(l.curr.constructor!==fd)if(t.id.clock+t.length>i)for(Rc(o,t,oh(i-t.id.clock,0)),l.next();l.curr&&l.curr.id.client===e;)Rc(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===e&&l.curr.id.clock+l.curr.length<=i;)l.next();else l.next()}Pc(o);const u=Ea(h);return Ta(n,u),n.toUint8Array()},$c=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:Ch(t.encoder.restEncoder)}),t.encoder.restEncoder=xh(),t.written=0)},Rc=(t,e,i)=>{t.written>0&&t.currClient!==e.id.client&&$c(t),0===t.written&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),Oh(t.encoder.restEncoder,e.id.clock+i)),e.write(t.encoder,i),t.written++},Pc=t=>{$c(t);const e=t.encoder.restEncoder;Oh(e,t.clientStructs.length);for(let i=0;i<t.clientStructs.length;i++){const s=t.clientStructs[i];Oh(e,s.written),$h(e,s.restEncoder)}},jc=t=>((t,e,i,s)=>{const r=new Ua(qh(t)),n=new Bc(r,!1),o=new s,h=new Oc(o);for(let t=n.curr;null!==t;t=n.next())Rc(h,e(t),0);Pc(h);const l=Ea(r);return Ta(o,l),o.toUint8Array()})(t,Dl,0,Fa),Uc="You must not compute changes after the event-handler fired.";class Nc{constructor(t,e){this.target=t,this.currentTarget=t,this.transaction=e,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Fc(this.currentTarget,this.target))}deletes(t){return Ca(this.transaction.deleteSet,t.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw Wh(Uc);const t=new Map,e=this.target;this.transaction.changed.get(e).forEach((i=>{if(null!==i){const s=e._map.get(i);let r,n;if(this.adds(s)){let t=s.left;for(;null!==t&&this.adds(t);)t=t.left;if(this.deletes(s)){if(null===t||!this.deletes(t))return;r="delete",n=Qo(t.content.getContent())}else null!==t&&this.deletes(t)?(r="update",n=Qo(t.content.getContent())):(r="add",n=void 0)}else{if(!this.deletes(s))return;r="delete",n=Qo(s.content.getContent())}t.set(i,{action:r,oldValue:n})}})),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(null===t){if(0===this.transaction.doc._transactionCleanups.length)throw Wh(Uc);const e=this.target,i=Vo(),s=Vo(),r=[];if(t={added:i,deleted:s,delta:r,keys:this.keys},this.transaction.changed.get(e).has(null)){let t=null;const n=()=>{t&&r.push(t)};for(let r=e._start;null!==r;r=r.right)r.deleted?this.deletes(r)&&!this.adds(r)&&(null!==t&&void 0!==t.delete||(n(),t={delete:0}),t.delete+=r.length,s.add(r)):this.adds(r)?(null!==t&&void 0!==t.insert||(n(),t={insert:[]}),t.insert=t.insert.concat(r.content.getContent()),i.add(r)):(null!==t&&void 0!==t.retain||(n(),t={retain:0}),t.retain+=r.length);null!==t&&void 0===t.retain&&n()}this._changes=t}return t}}const Fc=(t,e)=>{const i=[];for(;null!==e._item&&e!==t;){if(null!==e._item.parentSub)i.unshift(e._item.parentSub);else{let t=0,s=e._item.parent._start;for(;s!==e._item&&null!==s;)!s.deleted&&s.countable&&(t+=s.length),s=s.right;i.unshift(t)}e=e._item.parent}return i},_c=()=>{va("Invalid access: Add Yjs type to a document before reading data.")};let Lc=0;class zc{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=Lc++}}const Yc=(t,e,i)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=i,t.timestamp=Lc++},Wc=(t,e)=>{if(null===t._start||0===e||null===t._searchMarker)return null;const i=0===t._searchMarker.length?null:t._searchMarker.reduce(((t,i)=>rh(e-t.index)<rh(e-i.index)?t:i));let s=t._start,r=0;for(null!==i&&(s=i.p,r=i.index,(t=>{t.timestamp=Lc++})(i));null!==s.right&&r<e;){if(!s.deleted&&s.countable){if(e<r+s.length)break;r+=s.length}s=s.right}for(;null!==s.left&&r>e;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);for(;null!==s.left&&s.left.id.client===s.id.client&&s.left.id.clock+s.left.length===s.id.clock;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);return null!==i&&rh(i.index-r)<s.parent.length/80?(Yc(i,s,r),i):((t,e,i)=>{if(t.length>=80){const s=t.reduce(((t,e)=>t.timestamp<e.timestamp?t:e));return Yc(s,e,i),s}{const s=new zc(e,i);return t.push(s),s}})(t._searchMarker,s,r)},Xc=(t,e,i)=>{for(let s=t.length-1;s>=0;s--){const r=t[s];if(i>0){let e=r.p;for(e.marker=!1;e&&(e.deleted||!e.countable);)e=e.left,e&&!e.deleted&&e.countable&&(r.index-=e.length);if(null===e||!0===e.marker){t.splice(s,1);continue}r.p=e,e.marker=!0}(e<r.index||i>0&&e===r.index)&&(r.index=oh(e,r.index+i))}},Hc=(t,e,i)=>{const s=t,r=e.changedParentTypes;for(;Jo(r,t,(()=>[])).push(i),null!==t._item;)t=t._item.parent;tc(s._eH,i,e)};class Jc{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Ka(),this._dEH=Ka(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t,this._item=e}_copy(){throw Xh()}clone(){throw Xh()}_write(t){}get _first(){let t=this._start;for(;null!==t&&t.deleted;)t=t.right;return t}_callObserver(t,e){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Ga(this._eH,t)}observeDeep(t){Ga(this._dEH,t)}unobserve(t){Za(this._eH,t)}unobserveDeep(t){Za(this._dEH,t)}toJSON(){}}const Vc=(t,e,i)=>{t.doc??_c(),e<0&&(e=t._length+e),i<0&&(i=t._length+i);let s=i-e;const r=[];let n=t._start;for(;null!==n&&s>0;){if(n.countable&&!n.deleted){const t=n.content.getContent();if(t.length<=e)e-=t.length;else{for(let i=e;i<t.length&&s>0;i++)r.push(t[i]),s--;e=0}}n=n.right}return r},Qc=t=>{t.doc??_c();const e=[];let i=t._start;for(;null!==i;){if(i.countable&&!i.deleted){const t=i.content.getContent();for(let i=0;i<t.length;i++)e.push(t[i])}i=i.right}return e},qc=(t,e)=>{let i=0,s=t._start;for(t.doc??_c();null!==s;){if(s.countable&&!s.deleted){const r=s.content.getContent();for(let s=0;s<r.length;s++)e(r[s],i++,t)}s=s.right}},Kc=(t,e)=>{const i=[];return qc(t,((s,r)=>{i.push(e(s,r,t))})),i},Gc=t=>{let e=t._start,i=null,s=0;return{[Symbol.iterator](){return this},next:()=>{if(null===i){for(;null!==e&&e.deleted;)e=e.right;if(null===e)return{done:!0,value:void 0};i=e.content.getContent(),s=0,e=e.right}const t=i[s++];return i.length<=s&&(i=null),{done:!1,value:t}}}},Zc=(t,e)=>{t.doc??_c();const i=Wc(t,e);let s=t._start;for(null!==i&&(s=i.p,e-=i.index);null!==s;s=s.right)if(!s.deleted&&s.countable){if(e<s.length)return s.content.getContent()[e];e-=s.length}},tf=(t,e,i,s)=>{let r=i;const n=t.doc,o=n.clientID,h=n.store,l=null===i?e._start:i.right;let u=[];const a=()=>{u.length>0&&(r=new ud(sc(o,uc(h,o)),r,r&&r.lastId,l,l&&l.id,e,null,new Jf(u)),r.integrate(t,0),u=[])};s.forEach((i=>{if(null===i)u.push(i);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:u.push(i);break;default:switch(a(),i.constructor){case Uint8Array:case ArrayBuffer:r=new ud(sc(o,uc(h,o)),r,r&&r.lastId,l,l&&l.id,e,null,new Ff(new Uint8Array(i))),r.integrate(t,0);break;case $a:r=new ud(sc(o,uc(h,o)),r,r&&r.lastId,l,l&&l.id,e,null,new zf(i)),r.integrate(t,0);break;default:if(!(i instanceof Jc))throw new Error("Unexpected content type in insert operation");r=new ud(sc(o,uc(h,o)),r,r&&r.lastId,l,l&&l.id,e,null,new sd(i)),r.integrate(t,0)}}})),a()},ef=()=>Wh("Length exceeded!"),sf=(t,e,i,s)=>{if(i>e._length)throw ef();if(0===i)return e._searchMarker&&Xc(e._searchMarker,i,s.length),tf(t,e,null,s);const r=i,n=Wc(e,i);let o=e._start;for(null!==n&&(o=n.p,0==(i-=n.index)&&(o=o.prev,i+=o&&o.countable&&!o.deleted?o.length:0));null!==o;o=o.right)if(!o.deleted&&o.countable){if(i<=o.length){i<o.length&&pc(t,sc(o.id.client,o.id.clock+i));break}i-=o.length}return e._searchMarker&&Xc(e._searchMarker,r,s.length),tf(t,e,o,s)},rf=(t,e,i,s)=>{if(0===s)return;const r=i,n=s,o=Wc(e,i);let h=e._start;for(null!==o&&(h=o.p,i-=o.index);null!==h&&i>0;h=h.right)!h.deleted&&h.countable&&(i<h.length&&pc(t,sc(h.id.client,h.id.clock+i)),i-=h.length);for(;s>0&&null!==h;)h.deleted||(s<h.length&&pc(t,sc(h.id.client,h.id.clock+s)),h.delete(t),s-=h.length),h=h.right;if(s>0)throw ef();e._searchMarker&&Xc(e._searchMarker,r,-n+s)},nf=(t,e,i)=>{const s=e._map.get(i);void 0!==s&&s.delete(t)},of=(t,e,i,s)=>{const r=e._map.get(i)||null,n=t.doc,o=n.clientID;let h;if(null==s)h=new Jf([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:h=new Jf([s]);break;case Uint8Array:h=new Ff(s);break;case $a:h=new zf(s);break;default:if(!(s instanceof Jc))throw new Error("Unexpected content type");h=new sd(s)}new ud(sc(o,uc(n.store,o)),r,r&&r.lastId,null,null,e,i,h).integrate(t,0)},hf=(t,e)=>{t.doc??_c();const i=t._map.get(e);return void 0===i||i.deleted?void 0:i.content.getContent()[i.length-1]},lf=t=>{const e={};return t.doc??_c(),t._map.forEach(((t,i)=>{t.deleted||(e[i]=t.content.getContent()[t.length-1])})),e},uf=(t,e)=>{t.doc??_c();const i=t._map.get(e);return void 0!==i&&!i.deleted},af=t=>{return t.doc??_c(),e=t._map.entries(),i=t=>!t[1].deleted,ba((()=>{let t;do{t=e.next()}while(!t.done&&!i(t.value));return t}));var e,i};class cf extends Nc{}class ff extends Jc{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const e=new ff;return e.push(t),e}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new ff}clone(){const t=new ff;return t.insert(0,this.toArray().map((t=>t instanceof Jc?t.clone():t))),t}get length(){return this.doc??_c(),this._length}_callObserver(t,e){super._callObserver(t,e),Hc(this,t,new cf(this,t))}insert(t,e){null!==this.doc?Mc(this.doc,(i=>{sf(i,this,t,e)})):this._prelimContent.splice(t,0,...e)}push(t){null!==this.doc?Mc(this.doc,(e=>{((t,e,i)=>{let s=(e._searchMarker||[]).reduce(((t,e)=>e.index>t.index?e:t),{index:0,p:e._start}).p;if(s)for(;s.right;)s=s.right;tf(t,e,s,i)})(e,this,t)})):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){null!==this.doc?Mc(this.doc,(i=>{rf(i,this,t,e)})):this._prelimContent.splice(t,e)}get(t){return Zc(this,t)}toArray(){return Qc(this)}slice(t=0,e=this.length){return Vc(this,t,e)}toJSON(){return this.map((t=>t instanceof Jc?t.toJSON():t))}map(t){return Kc(this,t)}forEach(t){qc(this,t)}[Symbol.iterator](){return Gc(this)}_write(t){t.writeTypeRef(qf)}}class df extends Nc{constructor(t,e,i){super(t,e),this.keysChanged=i}}class pf extends Jc{constructor(t){super(),this._prelimContent=null,this._prelimContent=void 0===t?new Map:new Map(t)}_integrate(t,e){super._integrate(t,e),this._prelimContent.forEach(((t,e)=>{this.set(e,t)})),this._prelimContent=null}_copy(){return new pf}clone(){const t=new pf;return this.forEach(((e,i)=>{t.set(i,e instanceof Jc?e.clone():e)})),t}_callObserver(t,e){Hc(this,t,new df(this,t,e))}toJSON(){this.doc??_c();const t={};return this._map.forEach(((e,i)=>{if(!e.deleted){const s=e.content.getContent()[e.length-1];t[i]=s instanceof Jc?s.toJSON():s}})),t}get size(){return[...af(this)].length}keys(){return ka(af(this),(t=>t[0]))}values(){return ka(af(this),(t=>t[1].content.getContent()[t[1].length-1]))}entries(){return ka(af(this),(t=>[t[0],t[1].content.getContent()[t[1].length-1]]))}forEach(t){this.doc??_c(),this._map.forEach(((e,i)=>{e.deleted||t(e.content.getContent()[e.length-1],i,this)}))}[Symbol.iterator](){return this.entries()}delete(t){null!==this.doc?Mc(this.doc,(e=>{nf(e,this,t)})):this._prelimContent.delete(t)}set(t,e){return null!==this.doc?Mc(this.doc,(i=>{of(i,this,t,e)})):this._prelimContent.set(t,e),e}get(t){return hf(this,t)}has(t){return uf(this,t)}clear(){null!==this.doc?Mc(this.doc,(t=>{this.forEach((function(e,i,s){nf(t,s,i)}))})):this._prelimContent.clear()}_write(t){t.writeTypeRef(Kf)}}const wf=(t,e)=>t===e||"object"==typeof t&&"object"==typeof e&&t&&e&&((t,e)=>t===e||Cl(t)===Cl(e)&&Sl(t,((t,i)=>(void 0!==t||Bl(e,i))&&kl(e[i],t))))(t,e);class gf{constructor(t,e,i,s){this.left=t,this.right=e,this.index=i,this.currentAttributes=s}forward(){null===this.right&&Hh(),this.right.content.constructor===Wf?this.right.deleted||bf(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const mf=(t,e,i)=>{for(;null!==e.right&&i>0;)e.right.content.constructor===Wf?e.right.deleted||bf(e.currentAttributes,e.right.content):e.right.deleted||(i<e.right.length&&pc(t,sc(e.right.id.client,e.right.id.clock+i)),e.index+=e.right.length,i-=e.right.length),e.left=e.right,e.right=e.right.right;return e},vf=(t,e,i,s)=>{const r=new Map,n=s?Wc(e,i):null;if(n){const e=new gf(n.p.left,n.p,n.index,r);return mf(t,e,i-n.index)}{const s=new gf(null,e._start,0,r);return mf(t,s,i)}},yf=(t,e,i,s)=>{for(;null!==i.right&&(!0===i.right.deleted||i.right.content.constructor===Wf&&wf(s.get(i.right.content.key),i.right.content.value));)i.right.deleted||s.delete(i.right.content.key),i.forward();const r=t.doc,n=r.clientID;s.forEach(((s,o)=>{const h=i.left,l=i.right,u=new ud(sc(n,uc(r.store,n)),h,h&&h.lastId,l,l&&l.id,e,null,new Wf(o,s));u.integrate(t,0),i.right=u,i.forward()}))},bf=(t,e)=>{const{key:i,value:s}=e;null===s?t.delete(i):t.set(i,s)},kf=(t,e)=>{for(;null!==t.right&&(t.right.deleted||t.right.content.constructor===Wf&&wf(e[t.right.content.key]??null,t.right.content.value));)t.forward()},Mf=(t,e,i,s)=>{const r=t.doc,n=r.clientID,o=new Map;for(const h in s){const l=s[h],u=i.currentAttributes.get(h)??null;if(!wf(u,l)){o.set(h,u);const{left:s,right:a}=i;i.right=new ud(sc(n,uc(r.store,n)),s,s&&s.lastId,a,a&&a.id,e,null,new Wf(h,l)),i.right.integrate(t,0),i.forward()}}return o},xf=(t,e,i,s,r)=>{i.currentAttributes.forEach(((t,e)=>{void 0===r[e]&&(r[e]=null)}));const n=t.doc,o=n.clientID;kf(i,r);const h=Mf(t,e,i,r),l=s.constructor===String?new Vf(s):s instanceof Jc?new sd(s):new Yf(s);let{left:u,right:a,index:c}=i;e._searchMarker&&Xc(e._searchMarker,i.index,l.getLength()),a=new ud(sc(o,uc(n.store,o)),u,u&&u.lastId,a,a&&a.id,e,null,l),a.integrate(t,0),i.right=a,i.index=c,i.forward(),yf(t,e,i,h)},Af=(t,e,i,s,r)=>{const n=t.doc,o=n.clientID;kf(i,r);const h=Mf(t,e,i,r);t:for(;null!==i.right&&(s>0||h.size>0&&(i.right.deleted||i.right.content.constructor===Wf));){if(!i.right.deleted)switch(i.right.content.constructor){case Wf:{const{key:e,value:n}=i.right.content,o=r[e];if(void 0!==o){if(wf(o,n))h.delete(e);else{if(0===s)break t;h.set(e,n)}i.right.delete(t)}else i.currentAttributes.set(e,n);break}default:s<i.right.length&&pc(t,sc(i.right.id.client,i.right.id.clock+s)),s-=i.right.length}i.forward()}if(s>0){let r="";for(;s>0;s--)r+="\n";i.right=new ud(sc(o,uc(n.store,o)),i.left,i.left&&i.left.lastId,i.right,i.right&&i.right.id,e,null,new Vf(r)),i.right.integrate(t,0),i.forward()}yf(t,e,i,h)},Cf=(t,e,i,s,r)=>{let n=e;const o=Xo();for(;n&&(!n.countable||n.deleted);){if(!n.deleted&&n.content.constructor===Wf){const t=n.content;o.set(t.key,t)}n=n.right}let h=0,l=!1;for(;e!==n;){if(i===e&&(l=!0),!e.deleted){const i=e.content;switch(i.constructor){case Wf:{const{key:n,value:u}=i,a=s.get(n)??null;o.get(n)===i&&a!==u||(e.delete(t),h++,l||(r.get(n)??null)!==u||a===u||(null===a?r.delete(n):r.set(n,a))),l||e.deleted||bf(r,i);break}}}e=e.right}return h},Sf=t=>{let e=0;return Mc(t.doc,(i=>{let s=t._start,r=t._start,n=Xo();const o=Ho(n);for(;r;)!1===r.deleted&&(r.content.constructor===Wf?bf(o,r.content):(e+=Cf(i,s,r,n,o),n=Ho(o),s=r)),r=r.right})),e},Bf=t=>{const e=new Set,i=t.doc;for(const[s,r]of t.afterState.entries()){const n=t.beforeState.get(s)||0;r!==n&&gc(t,i.store.clients.get(s),n,r,(t=>{t.deleted||t.content.constructor!==Wf||t.constructor===Nf||e.add(t.parent)}))}Mc(i,(i=>{Aa(t,t.deleteSet,(t=>{t instanceof Nf||!t.parent._hasFormatting||e.has(t.parent)||(t.content.constructor===Wf?e.add(t.parent):((t,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const i=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===Wf){const s=e.content.key;i.has(s)?e.delete(t):i.add(s)}e=e.left}})(i,t))}));for(const t of e)Sf(t)}))},Of=(t,e,i)=>{const s=i,r=Ho(e.currentAttributes),n=e.right;for(;i>0&&null!==e.right;){if(!1===e.right.deleted)switch(e.right.content.constructor){case sd:case Yf:case Vf:i<e.right.length&&pc(t,sc(e.right.id.client,e.right.id.clock+i)),i-=e.right.length,e.right.delete(t)}e.forward()}n&&Cf(t,n,e.right,r,e.currentAttributes);const o=(e.left||e.right).parent;return o._searchMarker&&Xc(o._searchMarker,e.index,-s+i),e};class Tf extends Nc{constructor(t,e,i){super(t,e),this.childListChanged=!1,this.keysChanged=new Set,i.forEach((t=>{null===t?this.childListChanged=!0:this.keysChanged.add(t)}))}get changes(){if(null===this._changes){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(null===this._delta){const t=[];Mc(this.target.doc,(e=>{const i=new Map,s=new Map;let r=this.target._start,n=null;const o={};let h="",l=0,u=0;const a=()=>{if(null!==n){let e=null;switch(n){case"delete":u>0&&(e={delete:u}),u=0;break;case"insert":("object"==typeof h||h.length>0)&&(e={insert:h},i.size>0&&(e.attributes={},i.forEach(((t,i)=>{null!==t&&(e.attributes[i]=t)})))),h="";break;case"retain":l>0&&(e={retain:l},(t=>{for(const e in t)return!1;return!0})(o)||(e.attributes=Ml({},o))),l=0}e&&t.push(e),n=null}};for(;null!==r;){switch(r.content.constructor){case sd:case Yf:this.adds(r)?this.deletes(r)||(a(),n="insert",h=r.content.getContent()[0],a()):this.deletes(r)?("delete"!==n&&(a(),n="delete"),u+=1):r.deleted||("retain"!==n&&(a(),n="retain"),l+=1);break;case Vf:this.adds(r)?this.deletes(r)||("insert"!==n&&(a(),n="insert"),h+=r.content.str):this.deletes(r)?("delete"!==n&&(a(),n="delete"),u+=r.length):r.deleted||("retain"!==n&&(a(),n="retain"),l+=r.length);break;case Wf:{const{key:t,value:h}=r.content;if(this.adds(r)){if(!this.deletes(r)){const l=i.get(t)??null;wf(l,h)?null!==h&&r.delete(e):("retain"===n&&a(),wf(h,s.get(t)??null)?delete o[t]:o[t]=h)}}else if(this.deletes(r)){s.set(t,h);const e=i.get(t)??null;wf(e,h)||("retain"===n&&a(),o[t]=e)}else if(!r.deleted){s.set(t,h);const i=o[t];void 0!==i&&(wf(i,h)?null!==i&&r.delete(e):("retain"===n&&a(),null===h?delete o[t]:o[t]=h))}r.deleted||("insert"===n&&a(),bf(i,r.content));break}}r=r.right}for(a();t.length>0;){const e=t[t.length-1];if(void 0===e.retain||void 0!==e.attributes)break;t.pop()}})),this._delta=t}return this._delta}}class Ef extends Jc{constructor(t){super(),this._pending=void 0!==t?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??_c(),this._length}_integrate(t,e){super._integrate(t,e);try{this._pending.forEach((t=>t()))}catch(t){console.error(t)}this._pending=null}_copy(){return new Ef}clone(){const t=new Ef;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);const i=new Tf(this,t,e);Hc(this,t,i),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??_c();let t="",e=this._start;for(;null!==e;)!e.deleted&&e.countable&&e.content.constructor===Vf&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){null!==this.doc?Mc(this.doc,(i=>{const s=new gf(null,this._start,0,new Map);for(let r=0;r<t.length;r++){const n=t[r];if(void 0!==n.insert){const o=e||"string"!=typeof n.insert||r!==t.length-1||null!==s.right||"\n"!==n.insert.slice(-1)?n.insert:n.insert.slice(0,-1);("string"!=typeof o||o.length>0)&&xf(i,this,s,o,n.attributes||{})}else void 0!==n.retain?Af(i,this,s,n.retain,n.attributes||{}):void 0!==n.delete&&Of(i,s,n.delete)}})):this._pending.push((()=>this.applyDelta(t)))}toDelta(t,e,i){this.doc??_c();const s=[],r=new Map;let n="",o=this._start;function h(){if(n.length>0){const t={};let e=!1;r.forEach(((i,s)=>{e=!0,t[s]=i}));const i={insert:n};e&&(i.attributes=t),s.push(i),n=""}}const l=()=>{for(;null!==o;){if(nc(o,t)||void 0!==e&&nc(o,e))switch(o.content.constructor){case Vf:{const s=r.get("ychange");void 0===t||nc(o,t)?void 0===e||nc(o,e)?void 0!==s&&(h(),r.delete("ychange")):void 0!==s&&s.user===o.id.client&&"added"===s.type||(h(),r.set("ychange",i?i("added",o.id):{type:"added"})):void 0!==s&&s.user===o.id.client&&"removed"===s.type||(h(),r.set("ychange",i?i("removed",o.id):{type:"removed"})),n+=o.content.str;break}case sd:case Yf:{h();const t={insert:o.content.getContent()[0]};if(r.size>0){const e={};t.attributes=e,r.forEach(((t,i)=>{e[i]=t}))}s.push(t);break}case Wf:nc(o,t)&&(h(),bf(r,o.content))}o=o.right}h()};return t||e?Mc(this.doc,(i=>{t&&oc(i,t),e&&oc(i,e),l()}),"cleanup"):l(),s}insert(t,e,i){if(e.length<=0)return;const s=this.doc;null!==s?Mc(s,(s=>{const r=vf(s,this,t,!i);i||(i={},r.currentAttributes.forEach(((t,e)=>{i[e]=t}))),xf(s,this,r,e,i)})):this._pending.push((()=>this.insert(t,e,i)))}insertEmbed(t,e,i){const s=this.doc;null!==s?Mc(s,(s=>{const r=vf(s,this,t,!i);xf(s,this,r,e,i||{})})):this._pending.push((()=>this.insertEmbed(t,e,i||{})))}delete(t,e){if(0===e)return;const i=this.doc;null!==i?Mc(i,(i=>{Of(i,vf(i,this,t,!0),e)})):this._pending.push((()=>this.delete(t,e)))}format(t,e,i){if(0===e)return;const s=this.doc;null!==s?Mc(s,(s=>{const r=vf(s,this,t,!1);null!==r.right&&Af(s,this,r,e,i)})):this._pending.push((()=>this.format(t,e,i)))}removeAttribute(t){null!==this.doc?Mc(this.doc,(e=>{nf(e,this,t)})):this._pending.push((()=>this.removeAttribute(t)))}setAttribute(t,e){null!==this.doc?Mc(this.doc,(i=>{of(i,this,t,e)})):this._pending.push((()=>this.setAttribute(t,e)))}getAttribute(t){return hf(this,t)}getAttributes(){return lf(this)}_write(t){t.writeTypeRef(Gf)}}class Df{constructor(t,e=()=>!0){this._filter=e,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??_c()}[Symbol.iterator](){return this}next(){let t=this._currentNode,e=t&&t.content&&t.content.type;if(null!==t&&(!this._firstCall||t.deleted||!this._filter(e)))do{if(e=t.content.type,t.deleted||e.constructor!==$f&&e.constructor!==If||null===e._start)for(;null!==t;){const e=t.next;if(null!==e){t=e;break}t=t.parent===this._root?null:t.parent._item}else t=e._start}while(null!==t&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,null===t?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class If extends Jc{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new If}clone(){const t=new If;return t.insert(0,this.toArray().map((t=>t instanceof Jc?t.clone():t))),t}get length(){return this.doc??_c(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(t){return new Df(this,t)}querySelector(t){t=t.toUpperCase();const e=new Df(this,(e=>e.nodeName&&e.nodeName.toUpperCase()===t)).next();return e.done?null:e.value}querySelectorAll(t){return t=t.toUpperCase(),Ko(new Df(this,(e=>e.nodeName&&e.nodeName.toUpperCase()===t)))}_callObserver(t,e){Hc(this,t,new Rf(this,e,t))}toString(){return Kc(this,(t=>t.toString())).join("")}toJSON(){return this.toString()}toDOM(t=document,e={},i){const s=t.createDocumentFragment();return void 0!==i&&i._createAssociation(s,this),qc(this,(r=>{s.insertBefore(r.toDOM(t,e,i),null)})),s}insert(t,e){null!==this.doc?Mc(this.doc,(i=>{sf(i,this,t,e)})):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(null!==this.doc)Mc(this.doc,(i=>{tf(i,this,t&&t instanceof Jc?t._item:t,e)}));else{const i=this._prelimContent,s=null===t?0:i.findIndex((e=>e===t))+1;if(0===s&&null!==t)throw Wh("Reference item not found");i.splice(s,0,...e)}}delete(t,e=1){null!==this.doc?Mc(this.doc,(i=>{rf(i,this,t,e)})):this._prelimContent.splice(t,e)}toArray(){return Qc(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Zc(this,t)}slice(t=0,e=this.length){return Vc(this,t,e)}forEach(t){qc(this,t)}_write(t){t.writeTypeRef(td)}}class $f extends If{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,e){super._integrate(t,e),this._prelimAttrs.forEach(((t,e)=>{this.setAttribute(e,t)})),this._prelimAttrs=null}_copy(){return new $f(this.nodeName)}clone(){const t=new $f(this.nodeName);return((t,e)=>{for(const i in t)e(t[i],i)})(this.getAttributes(),((e,i)=>{t.setAttribute(i,e)})),t.insert(0,this.toArray().map((t=>t instanceof Jc?t.clone():t))),t}toString(){const t=this.getAttributes(),e=[],i=[];for(const e in t)i.push(e);i.sort();const s=i.length;for(let r=0;r<s;r++){const s=i[r];e.push(s+'="'+t[s]+'"')}const r=this.nodeName.toLocaleLowerCase();return`<${r}${e.length>0?" "+e.join(" "):""}>${super.toString()}</${r}>`}removeAttribute(t){null!==this.doc?Mc(this.doc,(e=>{nf(e,this,t)})):this._prelimAttrs.delete(t)}setAttribute(t,e){null!==this.doc?Mc(this.doc,(i=>{of(i,this,t,e)})):this._prelimAttrs.set(t,e)}getAttribute(t){return hf(this,t)}hasAttribute(t){return uf(this,t)}getAttributes(t){return t?((t,e)=>{const i={};return this._map.forEach(((t,s)=>{let r=t;for(;null!==r&&(!e.sv.has(r.id.client)||r.id.clock>=(e.sv.get(r.id.client)||0));)r=r.left;null!==r&&nc(r,e)&&(i[s]=r.content.getContent()[r.length-1])})),i})(0,t):lf(this)}toDOM(t=document,e={},i){const s=t.createElement(this.nodeName),r=this.getAttributes();for(const t in r){const e=r[t];"string"==typeof e&&s.setAttribute(t,e)}return qc(this,(r=>{s.appendChild(r.toDOM(t,e,i))})),void 0!==i&&i._createAssociation(s,this),s}_write(t){t.writeTypeRef(Zf),t.writeKey(this.nodeName)}}class Rf extends Nc{constructor(t,e,i){super(t,i),this.childListChanged=!1,this.attributesChanged=new Set,e.forEach((t=>{null===t?this.childListChanged=!0:this.attributesChanged.add(t)}))}}class Pf extends pf{constructor(t){super(),this.hookName=t}_copy(){return new Pf(this.hookName)}clone(){const t=new Pf(this.hookName);return this.forEach(((e,i)=>{t.set(i,e)})),t}toDOM(t=document,e={},i){const s=e[this.hookName];let r;return r=void 0!==s?s.createDom(this):document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),void 0!==i&&i._createAssociation(r,this),r}_write(t){t.writeTypeRef(ed),t.writeKey(this.hookName)}}class jf extends Ef{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new jf}clone(){const t=new jf;return t.applyDelta(this.toDelta()),t}toDOM(t=document,e,i){const s=t.createTextNode(this.toString());return void 0!==i&&i._createAssociation(s,this),s}toString(){return this.toDelta().map((t=>{const e=[];for(const i in t.attributes){const s=[];for(const e in t.attributes[i])s.push({key:e,value:t.attributes[i][e]});s.sort(((t,e)=>t.key<e.key?-1:1)),e.push({nodeName:i,attrs:s})}e.sort(((t,e)=>t.nodeName<e.nodeName?-1:1));let i="";for(let t=0;t<e.length;t++){const s=e[t];i+=`<${s.nodeName}`;for(let t=0;t<s.attrs.length;t++){const e=s.attrs[t];i+=` ${e.key}="${e.value}"`}i+=">"}i+=t.insert;for(let t=e.length-1;t>=0;t--)i+=`</${e[t].nodeName}>`;return i})).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(id)}}class Uf{constructor(t,e){this.id=t,this.length=e}get deleted(){throw Xh()}mergeWith(t){return!1}write(t,e,i){throw Xh()}integrate(t,e){throw Xh()}}class Nf extends Uf{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,e){e>0&&(this.id.clock+=e,this.length-=e),ac(t.doc.store,this)}write(t,e){t.writeInfo(0),t.writeLen(this.length-e)}getMissing(t,e){return null}}class Ff{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Ff(this.content)}splice(t){throw Xh()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeBuf(this.content)}getRef(){return 3}}class _f{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new _f(this.len)}splice(t){const e=new _f(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){Oa(t.deleteSet,e.id.client,e.id.clock,this.len),e.markDeleted()}delete(t){}gc(t){}write(t,e){t.writeLen(this.len-e)}getRef(){return 1}}const Lf=(t,e)=>new $a({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class zf{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const e={};this.opts=e,t.gc||(e.gc=!1),t.autoLoad&&(e.autoLoad=!0),null!==t.meta&&(e.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new zf(Lf(this.doc.guid,this.opts))}splice(t){throw Xh()}mergeWith(t){return!1}integrate(t,e){this.doc._item=e,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,e){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}class Yf{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Yf(this.embed)}splice(t){throw Xh()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeJSON(this.embed)}getRef(){return 5}}class Wf{constructor(t,e){this.key=t,this.value=e}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new Wf(this.key,this.value)}splice(t){throw Xh()}mergeWith(t){return!1}integrate(t,e){const i=e.parent;i._searchMarker=null,i._hasFormatting=!0}delete(t){}gc(t){}write(t,e){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}class Xf{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Xf(this.arr)}splice(t){const e=new Xf(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const i=this.arr.length;t.writeLen(i-e);for(let s=e;s<i;s++){const e=this.arr[s];t.writeString(void 0===e?"undefined":JSON.stringify(e))}}getRef(){return 2}}const Hf="development"===Ul("node_env");class Jf{constructor(t){this.arr=t,Hf&&Tl(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Jf(this.arr)}splice(t){const e=new Jf(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const i=this.arr.length;t.writeLen(i-e);for(let s=e;s<i;s++)t.writeAny(this.arr[s])}getRef(){return 8}}class Vf{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Vf(this.str)}splice(t){const e=new Vf(this.str.slice(t));this.str=this.str.slice(0,t);const i=this.str.charCodeAt(t-1);return i>=55296&&i<=56319&&(this.str=this.str.slice(0,t-1)+"�",e.str="�"+e.str.slice(1)),e}mergeWith(t){return this.str+=t.str,!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeString(0===e?this.str:this.str.slice(e))}getRef(){return 4}}const Qf=[()=>new ff,()=>new pf,()=>new Ef,t=>new $f(t.readKey()),()=>new If,t=>new Pf(t.readKey()),()=>new jf],qf=0,Kf=1,Gf=2,Zf=3,td=4,ed=5,id=6;class sd{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new sd(this.type._copy())}splice(t){throw Xh()}mergeWith(t){return!1}integrate(t,e){this.type._integrate(t.doc,e)}delete(t){let e=this.type._start;for(;null!==e;)e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t),e=e.right;this.type._map.forEach((e=>{e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t)})),t.changed.delete(this.type)}gc(t){let e=this.type._start;for(;null!==e;)e.gc(t,!0),e=e.right;this.type._start=null,this.type._map.forEach((e=>{for(;null!==e;)e.gc(t,!0),e=e.left})),this.type._map=new Map}write(t,e){this.type._write(t)}getRef(){return 7}}const rd=(t,e)=>{let i,s=e,r=0;do{r>0&&(s=sc(s.client,s.clock+r)),i=fc(t,s),r=s.clock-i.id.clock,s=i.redone}while(null!==s&&i instanceof ud);return{item:i,diff:r}},nd=(t,e)=>{for(;null!==t&&t.keep!==e;)t.keep=e,t=t.parent._item},od=(t,e,i)=>{const{client:s,clock:r}=e.id,n=new ud(sc(s,r+i),e,sc(s,r+i-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(i));return e.deleted&&n.markDeleted(),e.keep&&(n.keep=!0),null!==e.redone&&(n.redone=sc(e.redone.client,e.redone.clock+i)),e.right=n,null!==n.right&&(n.right.left=n),t._mergeStructs.push(n),null!==n.parentSub&&null===n.right&&n.parent._map.set(n.parentSub,n),e.length=i,n},hd=(t,e)=>Zo(t,(t=>Ca(t.deletions,e))),ld=(t,e,i,s,r,n)=>{const o=t.doc,h=o.store,l=o.clientID,u=e.redone;if(null!==u)return pc(t,u);let a,c=e.parent._item,f=null;if(null!==c&&!0===c.deleted){if(null===c.redone&&(!i.has(c)||null===ld(t,c,i,s,r,n)))return null;for(;null!==c.redone;)c=pc(t,c.redone)}const d=null===c?e.parent:c.content.type;if(null===e.parentSub){for(f=e.left,a=e;null!==f;){let e=f;for(;null!==e&&e.parent._item!==c;)e=null===e.redone?null:pc(t,e.redone);if(null!==e&&e.parent._item===c){f=e;break}f=f.left}for(;null!==a;){let e=a;for(;null!==e&&e.parent._item!==c;)e=null===e.redone?null:pc(t,e.redone);if(null!==e&&e.parent._item===c){a=e;break}a=a.right}}else if(a=null,e.right&&!r){for(f=e;null!==f&&null!==f.right&&(f.right.redone||Ca(s,f.right.id)||hd(n.undoStack,f.right.id)||hd(n.redoStack,f.right.id));)for(f=f.right;f.redone;)f=pc(t,f.redone);if(f&&null!==f.right)return null}else f=d._map.get(e.parentSub)||null;const p=uc(h,l),w=sc(l,p),g=new ud(w,f,f&&f.lastId,a,a&&a.id,d,e.parentSub,e.content.copy());return e.redone=w,nd(g,!0),g.integrate(t,0),g};class ud extends Uf{constructor(t,e,i,s,r,n,o,h){super(t,h.getLength()),this.origin=i,this.left=e,this.right=s,this.rightOrigin=r,this.parent=n,this.parentSub=o,this.redone=null,this.content=h,this.info=this.content.isCountable()?2:0}set marker(t){(8&this.info)>0!==t&&(this.info^=8)}get marker(){return(8&this.info)>0}get keep(){return(1&this.info)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(2&this.info)>0}get deleted(){return(4&this.info)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=uc(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=uc(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ec&&this.id.client!==this.parent.client&&this.parent.clock>=uc(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=wc(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=pc(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===Nf||this.right&&this.right.constructor===Nf)this.parent=null;else if(this.parent){if(this.parent.constructor===ec){const t=fc(e,this.parent);this.parent=t.constructor===Nf?null:t.content.type}}else this.left&&this.left.constructor===ud?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===ud&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=wc(t,t.doc.store,sc(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(e),this.length-=e),this.parent){if(!this.left&&(!this.right||null!==this.right.left)||this.left&&this.left.right!==this.right){let e,i=this.left;if(null!==i)e=i.right;else if(null!==this.parentSub)for(e=this.parent._map.get(this.parentSub)||null;null!==e&&null!==e.left;)e=e.left;else e=this.parent._start;const s=new Set,r=new Set;for(;null!==e&&e!==this.right;){if(r.add(e),s.add(e),ic(this.origin,e.origin)){if(e.id.client<this.id.client)i=e,s.clear();else if(ic(this.rightOrigin,e.rightOrigin))break}else{if(null===e.origin||!r.has(fc(t.doc.store,e.origin)))break;s.has(fc(t.doc.store,e.origin))||(i=e,s.clear())}e=e.right}this.left=i}if(null!==this.left)this.right=this.left.right,this.left.right=this;else{let t;if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start,this.parent._start=this;this.right=t}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(t)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),ac(t.doc.store,this),this.content.integrate(t,this),yc(t,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(t)}else new Nf(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;null!==t&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;null!==t&&t.deleted;)t=t.left;return t}get lastId(){return 1===this.length?this.id:sc(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&ic(t.origin,this.lastId)&&this.right===t&&ic(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&null===this.redone&&null===t.redone&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const e=this.parent._searchMarker;return e&&e.forEach((e=>{e.p===t&&(e.p=this,!this.deleted&&this.countable&&(e.index-=this.length))})),t.keep&&(this.keep=!0),this.right=t.right,null!==this.right&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const e=this.parent;this.countable&&null===this.parentSub&&(e._length-=this.length),this.markDeleted(),Oa(t.deleteSet,this.id.client,this.id.clock,this.length),yc(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw Hh();this.content.gc(t),e?((t,e,i)=>{const s=t.clients.get(e.id.client);s[cc(s,e.id.clock)]=i})(t,this,new Nf(this.id,this.length)):this.content=new _f(this.length)}write(t,e){const i=e>0?sc(this.id.client,this.id.clock+e-1):this.origin,s=this.rightOrigin,r=this.parentSub,n=31&this.content.getRef()|(null===i?0:ah)|(null===s?0:uh)|(null===r?0:32);if(t.writeInfo(n),null!==i&&t.writeLeftID(i),null!==s&&t.writeRightID(s),null===i&&null===s){const e=this.parent;if(void 0!==e._item){const i=e._item;if(null===i){const i=(t=>{for(const[e,i]of t.doc.share.entries())if(i===t)return e;throw Hh()})(e);t.writeParentInfo(!0),t.writeString(i)}else t.writeParentInfo(!1),t.writeLeftID(i.id)}else e.constructor===String?(t.writeParentInfo(!0),t.writeString(e)):e.constructor===ec?(t.writeParentInfo(!1),t.writeLeftID(e)):Hh();null!==r&&t.writeString(r)}this.content.write(t,e)}}const ad=(t,e)=>cd[31&e](t),cd=[()=>{Hh()},t=>new _f(t.readLen()),t=>{const e=t.readLen(),i=[];for(let s=0;s<e;s++){const e=t.readString();i.push("undefined"===e?void 0:JSON.parse(e))}return new Xf(i)},t=>new Ff(t.readBuf()),t=>new Vf(t.readString()),t=>new Yf(t.readJSON()),t=>new Wf(t.readKey(),t.readJSON()),t=>new sd(Qf[t.readTypeRef()](t)),t=>{const e=t.readLen(),i=[];for(let s=0;s<e;s++)i.push(t.readAny());return new Jf(i)},t=>new zf(Lf(t.readString(),t.readAny())),()=>{Hh()}];class fd extends Uf{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,e){Hh()}write(t,e){t.writeInfo(10),Oh(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const dd="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},pd="__ $YJS$ __";!0===dd[pd]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),dd[pd]=!0;const wd=t=>pl(((e,i)=>{t.onerror=t=>i(new Error(t.target.error)),t.onsuccess=t=>e(t.target.result)})),gd=(t,e,i="readwrite")=>{const s=t.transaction(e,i);return e.map((t=>kd(s,t)))},md=(t,e)=>wd(t.count(e)),vd=(t,e)=>wd(t.delete(e)),yd=(t,e)=>wd(t.add(e)),bd=(t,e,i,s="next")=>((t,e)=>pl(((i,s)=>{t.onerror=s,t.onsuccess=async t=>{const s=t.target.result;if(null===s||!1===await e(s))return i();s.continue()}})))(t.openKeyCursor(e,s),(t=>i(t.key))),kd=(t,e)=>t.objectStore(e),Md="custom",xd="updates",Ad=(t,e=()=>{},i=()=>{})=>{const[s]=gd(t.db,[xd]);return(r=s,o=t._dbref,n=IDBKeyRange.lowerBound(o,false),wd(r.getAll(n,undefined))).then((r=>{t._destroyed||(e(s),Mc(t.doc,(()=>{r.forEach((e=>Wa(t.doc,e)))}),t,!1),i(s))})).then((()=>((t,e=null)=>((t,e)=>{let i=null;return bd(t,e,(t=>(i=t,!1)),"prev").then((()=>i))})(t,e))(s).then((e=>{t._dbref=e+1})))).then((()=>md(s).then((e=>{t._dbsize=e})))).then((()=>s));var r,n,o};class Cd extends ih{constructor(t,e){super(),this.doc=e,this.name=t,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=(t=>pl(((e,i)=>{const s=indexedDB.open(t);s.onupgradeneeded=t=>(t=>[["updates",{autoIncrement:!0}],["custom"]].forEach((e=>t.createObjectStore.apply(t,e))))(t.target.result),s.onerror=t=>i(Wh(t.target.error)),s.onsuccess=t=>{const i=t.target.result;i.onversionchange=()=>{i.close()},e(i)}})))(t),this.whenSynced=pl((t=>this.on("synced",(()=>t(this))))),this._db.then((t=>{this.db=t,Ad(this,(t=>yd(t,Ha(e))),(()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])}))})),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(t,e)=>{if(this.db&&e!==this){const[e]=gd(this.db,[xd]);yd(e,t),++this._dbsize>=500&&(null!==this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout((()=>{((t,e=!0)=>{Ad(t).then((i=>{(e||t._dbsize>=500)&&yd(i,Ha(t.doc)).then((()=>vd(i,IDBKeyRange.upperBound(t._dbref,!0)))).then((()=>md(i).then((e=>{t._dbsize=e}))))}))})(this,!1),this._storeTimeoutId=null}),this._storeTimeout))}},e.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),e.on("destroy",this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off("update",this._storeUpdate),this.doc.off("destroy",this.destroy),this._destroyed=!0,this._db.then((t=>{t.close()}))}clearData(){return this.destroy().then((()=>{wd(indexedDB.deleteDatabase(this.name))}))}get(t){return this._db.then((e=>{const[i]=gd(e,[Md],"readonly");return((t,e)=>wd(t.get(e)))(i,t)}))}set(t,e){return this._db.then((i=>{const[s]=gd(i,[Md]);return((t,e,i)=>wd(t.put(e,i)))(s,e,t)}))}del(t){return this._db.then((e=>{const[i]=gd(e,[Md]);return vd(i,t)}))}}class Sd{provider;isConnected=!1;constructor(t,e,i){this.provider=new Cd(i?.name||t,e)}async connect(){if(!this.isConnected)return new Promise((t=>{this.provider.on("synced",(()=>{this.isConnected=!0,t()}))}))}disconnect(){this.isConnected=!1}destroy(){this.provider&&this.provider.destroy(),this.isConnected=!1}}const Bd=Math.floor,Od=127,Td=Number.MAX_SAFE_INTEGER,Ed="undefined"!=typeof TextEncoder?new TextEncoder:null,Dd=Ed?t=>Ed.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 Id="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Id&&1===Id.decode(new Uint8Array).length&&(Id=null);const $d=(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},Rd=(t,e)=>{for(;e>Od;)$d(t,128|Od&e),e=Bd(e/128);$d(t,Od&e)},Pd=new Uint8Array(3e4),jd=Pd.length/3,Ud=Ed&&Ed.encodeInto?(t,e)=>{if(e.length<jd){const i=Ed.encodeInto(e,Pd).written||0;Rd(t,i);for(let e=0;e<i;e++)$d(t,Pd[e])}else Nd(t,Dd(e))}:(t,e)=>{const i=unescape(encodeURIComponent(e)),s=i.length;Rd(t,s);for(let e=0;e<s;e++)$d(t,i.codePointAt(e))},Nd=(t,e)=>{Rd(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)},Fd=t=>new Error(t),_d=Fd("Unexpected end of array"),Ld=Fd("Integer out of Range"),zd=t=>t.arr[t.pos++],Yd=t=>{let e=0,i=1;const s=t.arr.length;for(;t.pos<s;){const s=t.arr[t.pos++];if(e+=(s&Od)*i,i*=128,s<128)return e;if(e>Td)throw Ld}throw _d},Wd=Id?t=>Id.decode((t=>((t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,i})(t,Yd(t)))(t)):t=>{let e=Yd(t);if(0===e)return"";{let i=String.fromCodePoint(zd(t));if(--e<100)for(;e--;)i+=String.fromCodePoint(zd(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 Xd;!function(t){t[t.Token=0]="Token",t[t.PermissionDenied=1]="PermissionDenied",t[t.Authenticated=2]="Authenticated"}(Xd||(Xd={}));const Hd=t=>Array.from(t.entries()).map((([t,e])=>({clientId:t,...e})));var Jd;async function Vd(t){return new Promise((e=>setTimeout(e,t)))}function Qd(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"}(Jd||(Jd={}));const qd=Math.floor,Kd=128,Gd=127,Zd=Number.MAX_SAFE_INTEGER,tp=()=>new Set,ep=Array.from,ip="undefined"!=typeof TextEncoder?new TextEncoder:null,sp=ip?t=>ip.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 rp="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});rp&&1===rp.decode(new Uint8Array).length&&(rp=null);class np{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const op=()=>new np,hp=t=>{let e=t.cpos;for(let i=0;i<t.bufs.length;i++)e+=t.bufs[i].length;return e},lp=t=>{const e=new Uint8Array(hp(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},up=(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},ap=(t,e)=>{for(;e>Gd;)up(t,Kd|Gd&e),e=qd(e/128);up(t,Gd&e)},cp=new Uint8Array(3e4),fp=cp.length/3,dp=ip&&ip.encodeInto?(t,e)=>{if(e.length<fp){const i=ip.encodeInto(e,cp).written||0;ap(t,i);for(let e=0;e<i;e++)up(t,cp[e])}else pp(t,sp(e))}:(t,e)=>{const i=unescape(encodeURIComponent(e)),s=i.length;ap(t,s);for(let e=0;e<s;e++)up(t,i.codePointAt(e))},pp=(t,e)=>{ap(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)},wp=t=>new Error(t),gp=wp("Unexpected end of array"),mp=wp("Integer out of Range");class vp{constructor(t){this.arr=t,this.pos=0}}const yp=t=>new vp(t),bp=t=>((t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,i})(t,Mp(t)),kp=t=>t.arr[t.pos++],Mp=t=>{let e=0,i=1;const s=t.arr.length;for(;t.pos<s;){const s=t.arr[t.pos++];if(e+=(s&Gd)*i,i*=128,s<Kd)return e;if(e>Zd)throw mp}throw gp},xp=rp?t=>rp.decode(bp(t)):t=>{let e=Mp(t);if(0===e)return"";{let i=String.fromCodePoint(kp(t));if(--e<100)for(;e--;)i+=String.fromCodePoint(kp(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))}},Ap=Date.now,Cp=()=>new Map;class Sp{constructor(){this._observers=Cp()}on(t,e){((t,e,i)=>{let s=t.get(e);return void 0===s&&t.set(e,s=i()),s})(this._observers,t,tp).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 ep((this._observers.get(t)||Cp()).values()).forEach((t=>t(...e)))}destroy(){this._observers=Cp()}}const Bp=Object.keys,Op=t=>Bp(t).length,Tp=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Ep=(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)||!Ep(t.get(i),e.get(i)))return!1;break;case Object:if(Op(t)!==Op(e))return!1;for(const i in t)if(!Tp(t,i)||!Ep(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(!Ep(t[i],e[i]))return!1;break;default:return!1}return!0};class Dp extends Sp{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const t=Ap();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&&Ip(this,e,"timeout")}),qd(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:Ap()});const n=[],o=[],h=[],l=[];null===t?l.push(e):null==r?null!=t&&n.push(e):(o.push(e),Ep(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 Ip=(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:Ap()})}s.push(r)}}s.length>0&&(t.emit("change",[{added:[],updated:[],removed:s},i]),t.emit("update",[{added:[],updated:[],removed:s},i]))},$p=(t,e,i=t.states)=>{const s=e.length,r=op();ap(r,s);for(let n=0;n<s;n++){const s=e[n],o=i.get(s)||null,h=t.meta.get(s).clock;ap(r,s),ap(r,h),dp(r,JSON.stringify(o))}return lp(r)};class Rp{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 Pp{constructor(t){this.data=t,this.encoder=op(),this.decoder=yp(new Uint8Array(this.data))}peekVarString(){return(t=>{const e=t.pos,i=xp(t);return t.pos=e,i})(this.decoder)}readVarUint(){return Mp(this.decoder)}readVarString(){return xp(this.decoder)}readVarUint8Array(){return bp(this.decoder)}writeVarUint(t){return ap(this.encoder,t)}writeVarString(t){return dp(this.encoder,t)}writeVarUint8Array(t){return pp(this.encoder,t)}length(){return hp(this.encoder)}}var jp,Up;!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"}(jp||(jp={})),function(t){t.Connecting="connecting",t.Connected="connected",t.Disconnected="disconnected"}(Up||(Up={}));class Np{constructor(){this.encoder=op()}get(t){return t.encoder}toUint8Array(){return lp(this.encoder)}}class Fp extends Np{constructor(){super(...arguments),this.type=jp.CLOSE,this.description="Ask the server to close the connection"}get(t){return dp(this.encoder,t.documentName),ap(this.encoder,this.type),this.encoder}}class _p extends Rp{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=Up.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=Up.Connected,this.emit("status",{status:Up.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=t}attach(t){this.configuration.providerMap.set(t.configuration.name,t),this.status===Up.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===Up.Connected&&t.onOpen(this.receivedOnOpenPayload)}detach(t){this.configuration.providerMap.has(t.configuration.name)&&(t.send(Fp,{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===Up.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||Qd,n=i.calculateDelay?i.calculateDelay(s,i):i.initialDelay;if(n&&await Vd(n),s.attemptNum<1&&i.initialJitter){const t=r(s,i);t&&await Vd(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 Vd(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=Up.Connecting,this.emit("status",{status:Up.Connecting}),this.connectionAttempt={resolve:t,reject:e}}))}onMessage(t){var e;this.resolveConnectionAttempt(),this.lastMessageReceived=Ap();const i=new Pp(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=Up.Connected,this.emit("status",{status:Up.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===Up.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=Ap()-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)===Jd.Open?this.webSocket.send(t):this.messageQueue.push(t)}onClose({event:t}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=Up.Disconnected,this.emit("status",{status:Up.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 Lp=(t,e,i)=>{try{Wa(e,bp(t),i)}catch(t){console.error("Caught error while handling a Yjs update",t)}},zp=Lp;class Yp{constructor(t){this.message=t}apply(t,e){const{message:i}=this,s=i.readVarUint(),r=i.length();switch(s){case jp.Sync:this.applySyncMessage(t,e);break;case jp.Awareness:this.applyAwarenessMessage(t);break;case jp.Auth:this.applyAuthMessage(t);break;case jp.QueryAwareness:this.applyQueryAwarenessMessage(t);break;case jp.Stateless:t.receiveStateless(xp(i.decoder));break;case jp.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&Kd))return r*i;const n=t.arr.length;for(;t.pos<n;){if(e=t.arr[t.pos++],i+=(e&Gd)*s,s*=128,e<Kd)return r*i;if(i>Zd)throw mp}throw gp})(i.decoder));break;case jp.CLOSE:const r={code:1e3,reason:xp(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(Np,{encoder:i.encoder})}applySyncMessage(t,e){const{message:i}=this;i.writeVarUint(jp.Sync);const s=((t,e,i,s)=>{const r=Mp(t);switch(r){case 0:((t,e,i)=>{((t,e,i)=>{ap(t,1),pp(t,Ha(e,i))})(e,i,bp(t))})(t,e,i);break;case 1:Lp(t,i,s);break;case 2:zp(t,i,s);break;default:throw new Error("Unknown message type")}return r})(i.decoder,i.encoder,t.document,t);e&&1===s&&(t.synced=!0)}applySyncStatusMessage(t,e){e&&t.decrementUnsyncedChanges()}applyAwarenessMessage(t){if(!t.awareness)return;const{message:e}=this;((t,e,i)=>{const s=yp(e),r=Ap(),n=[],o=[],h=[],l=[],u=Mp(s);for(let e=0;e<u;e++){const e=Mp(s);let i=Mp(s);const u=JSON.parse(xp(s)),a=t.meta.get(e),c=t.states.get(e),f=void 0===a?0:a.clock;(f<i||f===i&&null===u&&t.states.has(e))&&(null===u?e===t.clientID&&null!=t.getLocalState()?i++:t.states.delete(e):t.states.set(e,u),t.meta.set(e,{clock:i,lastUpdated:r}),void 0===a&&null!==u?n.push(e):void 0!==a&&null===u?l.push(e):null!==u&&(Ep(u,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(Yd(t)){case Xd.Token:e();break;case Xd.PermissionDenied:i(Wd(t));break;case Xd.Authenticated:s(Wd(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(jp.Awareness),e.writeVarUint8Array($p(t.awareness,Array.from(t.awareness.getStates().keys())))}}class Wp{constructor(t,e={}){this.message=new t,this.encoder=this.message.get(e)}create(){return lp(this.encoder)}send(t){null==t||t.send(this.create())}}class Xp extends Np{constructor(){super(...arguments),this.type=jp.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 dp(this.encoder,t.documentName),ap(this.encoder,this.type),i=t.token,Rd(e=this.encoder,Xd.Token),Ud(e,i),this.encoder}}class Hp extends Np{constructor(){super(...arguments),this.type=jp.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 dp(this.encoder,t.documentName),ap(this.encoder,this.type),e=void 0===t.states?$p(t.awareness,t.clients):$p(t.awareness,t.clients,t.states),pp(this.encoder,e),this.encoder}}class Jp extends Np{constructor(){super(...arguments),this.type=jp.Stateless,this.description="A stateless message"}get(t){var e;return dp(this.encoder,t.documentName),ap(this.encoder,this.type),dp(this.encoder,null!==(e=t.payload)&&void 0!==e?e:""),this.encoder}}class Vp extends Np{constructor(){super(...arguments),this.type=jp.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 dp(this.encoder,t.documentName),ap(this.encoder,this.type),((t,e)=>{ap(t,0);const i=Qa(e);pp(t,i)})(this.encoder,t.document),this.encoder}}class Qp extends Np{constructor(){super(...arguments),this.type=jp.Sync,this.description="A document update"}get(t){var e,i;return dp(this.encoder,t.documentName),ap(this.encoder,this.type),i=t.update,ap(e=this.encoder,2),pp(e,i),this.encoder}}class qp extends Error{constructor(){super(...arguments),this.code=1001}}class Kp extends Rp{constructor(t){var e,i,s;super(),this.configuration={name:"",document:void 0,awareness:void 0,token:null,forceSyncInterval:!1,onAuthenticated:()=>null,onAuthenticationFailed:()=>null,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onSynced:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,onStateless:()=>null,onUnsyncedChanges:()=>null},this.isSynced=!1,this.unsyncedChanges=0,this.isAuthenticated=!1,this.authorizedScope=void 0,this.manageSocket=!1,this._isAttached=!1,this.intervals={forceSync:null},this.boundDocumentUpdateHandler=this.documentUpdateHandler.bind(this),this.boundAwarenessUpdateHandler=this.awarenessUpdateHandler.bind(this),this.boundPageHide=this.pageHide.bind(this),this.boundOnOpen=this.onOpen.bind(this),this.boundOnClose=this.onClose.bind(this),this.forwardConnect=()=>this.emit("connect"),this.forwardStatus=t=>this.emit("status",t),this.forwardClose=t=>this.emit("close",t),this.forwardDisconnect=t=>this.emit("disconnect",t),this.forwardDestroy=()=>this.emit("destroy"),this.setConfiguration(t),this.configuration.document=t.document?t.document:new $a,this.configuration.awareness=void 0!==t.awareness?t.awareness:new Dp(this.document),this.on("open",this.configuration.onOpen),this.on("message",this.configuration.onMessage),this.on("outgoingMessage",this.configuration.onOutgoingMessage),this.on("synced",this.configuration.onSynced),this.on("destroy",this.configuration.onDestroy),this.on("awarenessUpdate",this.configuration.onAwarenessUpdate),this.on("awarenessChange",this.configuration.onAwarenessChange),this.on("stateless",this.configuration.onStateless),this.on("unsyncedChanges",this.configuration.onUnsyncedChanges),this.on("authenticated",this.configuration.onAuthenticated),this.on("authenticationFailed",this.configuration.onAuthenticationFailed),null===(e=this.awareness)||void 0===e||e.on("update",(()=>{this.emit("awarenessUpdate",{states:Hd(this.awareness.getStates())})})),null===(i=this.awareness)||void 0===i||i.on("change",(()=>{this.emit("awarenessChange",{states:Hd(this.awareness.getStates())})})),this.document.on("update",this.boundDocumentUpdateHandler),null===(s=this.awareness)||void 0===s||s.on("update",this.boundAwarenessUpdateHandler),this.registerEventListeners(),this.configuration.forceSyncInterval&&"number"==typeof this.configuration.forceSyncInterval&&(this.intervals.forceSync=setInterval(this.forceSync.bind(this),this.configuration.forceSyncInterval)),this.manageSocket&&this.attach()}setConfiguration(t={}){t.websocketProvider||(this.manageSocket=!0,this.configuration.websocketProvider=new _p(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(Vp,{document:this.document,documentName:this.configuration.name})}pageHide(){this.awareness&&Ip(this.awareness,[this.document.clientID],"page hide")}registerEventListeners(){"undefined"!=typeof window&&"addEventListener"in window&&window.addEventListener("pagehide",this.boundPageHide)}sendStateless(t){this.send(Jp,{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(Xp,{token:null!=t?t:"",documentName:this.configuration.name})}documentUpdateHandler(t,e){e!==this&&(this.incrementUnsyncedChanges(),this.send(Qp,{update:t,documentName:this.configuration.name}))}awarenessUpdateHandler({added:t,updated:e,removed:i},s){const r=t.concat(e).concat(i);this.send(Hp,{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(Vp,{document:this.document,documentName:this.configuration.name}),this.awareness&&null!==this.awareness.getLocalState()&&this.send(Hp,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.configuration.name})}send(t,e){if(!this._isAttached)return;const i=new Wp(t,e);this.emit("outgoingMessage",{message:i.message}),i.send(this.configuration.websocketProvider)}onMessage(t){const e=new Pp(t.data),i=e.readVarString();e.writeVarString(i),this.emit("message",{event:t,message:new Pp(t.data)}),new Yp(e).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&Ip(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&&(Ip(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 qp(`Cannot set awareness field "${t}" to ${JSON.stringify(e)}. You have disabled Awareness for this provider by explicitly passing awareness: null in the provider configuration.`);this.awareness.setLocalStateField(t,e)}}class Gp{__class__="KritzelWorkspace";id;name;createdAt;updatedAt;viewport;_core;constructor(t,e,i={translateX:0,translateY:0,scale:1}){this.id=t,this.name=e,this.createdAt=new Date,this.updatedAt=new Date,this.viewport=i}static create(t,e){const i=new Gp(e.id,e.name,e.viewport);return i._core=t,i}addObject(t){this._core.engine.addObject(t)}serialize(){return{__class__:this.__class__,id:this.id,name:this.name,createdAt:this.createdAt.toISOString(),updatedAt:this.updatedAt.toISOString(),viewport:this.viewport}}deserialize(t){return Object.assign(this,t),this.createdAt=new Date(t.createdAt),this.updatedAt=new Date(t.updatedAt),this}}const Zp={providers:[Sd]};class tw{map;_ydoc=null;_workspacesMap=null;_providers=[];_core=null;_isReady=!1;_onRemoteChangeCallback=null;get isReady(){return this._isReady}constructor(){this.map=new Map}onRemoteChange(t){this._onRemoteChangeCallback=t}async initialize(t,e){this._core=t,this._ydoc=new $a,this._workspacesMap=this._ydoc.getMap("workspaces");const i="kritzel-app-state",s=e??Zp;for(const t of s.providers){let e;e="function"==typeof t?new t(i,this._ydoc):t.create(i,this._ydoc),this._providers.push(e)}this._workspacesMap.observe((t=>{this.handleWorkspacesChange(t)})),await Promise.all(this._providers.map((t=>t.connect()))),this._isReady=!0,this.loadFromYjs()}handleWorkspacesChange(t){if("local"===t.transaction.origin)return void this._core?.rerender();const e=Array.from(t.keysChanged),i=[],s=[];e.forEach((e=>{const r=t.changes.keys.get(e);if(r&&"delete"===r.action)s.push(e);else{const t=this._workspacesMap.get(e);if(t){const e=this.reviveWorkspace(t);i.push(e)}}})),s.forEach((t=>{this.map.delete(t)})),i.forEach((t=>{this.map.set(t.id,t)})),this._core?.store&&(this._core.store.state.workspaces=this.allWorkspaces()),this._onRemoteChangeCallback&&this._onRemoteChangeCallback(),this._core?.rerender()}reviveWorkspace(t){const e=new Gp(t.id,t.name,t.viewport);return e._core=this._core,e.createdAt=new Date(t.createdAt),e.updatedAt=new Date(t.updatedAt),e}transaction(t){this._ydoc&&this._ydoc.transact(t,"local")}loadFromYjs(){this._workspacesMap&&(this.map.clear(),this._workspacesMap.forEach(((t,e)=>{const i=this.reviveWorkspace(t);this.map.set(e,i)})))}reset(){this.map.clear(),this._ydoc.transact((()=>{this._workspacesMap.clear()}),"local")}insert(t){if(!t.id)return!1;if(this.map.set(t.id,t),this._workspacesMap){const e=t.serialize();this._ydoc.transact((()=>{this._workspacesMap.set(t.id,e)}),"local")}return!0}update(t){if(!t.id||!this.map.has(t.id))return!1;if(this.map.set(t.id,t),this._workspacesMap){const e=t.serialize();this._ydoc.transact((()=>{this._workspacesMap.set(t.id,e)}),"local")}return!0}remove(t){const e=Array.from(this.map.values()).find(t);return!!e&&(this.map.delete(e.id),this._workspacesMap&&this._ydoc.transact((()=>{this._workspacesMap.delete(e.id)}),"local"),!0)}get(t){return this.map.get(t)}allWorkspaces(){return Array.from(this.map.values())}filter(t){return Array.from(this.map.values()).filter(t)}find(t){return Array.from(this.map.values()).find(t)}has(t){return this.map.has(t)}destroy(){this._providers.forEach((t=>t.disconnect())),this._providers=[],this.map.clear(),this._workspacesMap=null,this._ydoc&&(this._ydoc.destroy(),this._ydoc=null),this._isReady=!1}}class ew{static isInstanceOf(t,e){return!!t&&t.__class__===e}}class iw{_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.state.objects.update(s)}removeAnchor(t,e){const i=this.getLineById(t);if(!i)return;const s="start"===e?i.startAnchor:i.endAnchor;s&&(this.removeFromIndex(s.objectId,t,e),"start"===e?i.startAnchor=void 0:i.endAnchor=void 0)}getAnchor(t,e){const i=this.getLineById(t);return i?("start"===e?i.startAnchor:i.endAnchor)??null:null}getLinesAnchoredTo(t){const e=this._anchorIndex.get(t);return e?Array.from(e):[]}updateAnchorsForObject(t){const e=this.getLinesAnchoredTo(t);if(0!==e.length&&this.getObjectById(t))for(const i of e){const e=this.getLineById(i.lineId);e&&this.snapEndpointToObject(e,i.endpoint,t)}}snapEndpointToObject(t,e,i){const s=this.getObjectById(i);if(!s)return;const 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,s,r){let n=null,o=-1/0;const h=this._core.store.allNonSelectionObjects;for(const l of h){if(l.id===s)continue;if(r&&l.id===r)continue;if(!this.isAnchorable(l))continue;const h=l.rotatedPolygon;i.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(!ew.isInstanceOf(e,"KritzelLine"))return null;const i=e,s=this.computeAnchorVisualization(i,"start"),r=this.computeAnchorVisualization(i,"end");if(!s&&!r)return null;const n=this._core.store.state.scale,o=i.strokeWidth/i.scale,h=""+2/n,l=Math.max(2*o,4/n);return{lineStrokeWidth:o,indicatorStrokeWidth:h,dashArray:`${l} ${l}`,indicatorRadius:8/n,startAnchorViz:s,endAnchorViz:r}}getSnapIndicatorRenderData(){const t=this.getSnapCandidate();if(!t)return null;const e=this._core.store.state.scale,i=8/e,s=""+2/e,r=t.lineStrokeWidth?`${t.lineStrokeWidth}`:""+4/e,n=Math.max(2*(t.lineStrokeWidth||4/e),4/e),o=`${n} ${n}`,h=t.lineStroke||"#000000";let l,u=t.edgeX,a=t.edgeY;if(t.arrowOffset&&void 0!==t.edgeX&&void 0!==t.edgeY){const e=t.lineEndpointX-t.edgeX,i=t.lineEndpointY-t.edgeY,s=Math.sqrt(e*e+i*i);s>t.arrowOffset&&(u=t.edgeX+e/s*t.arrowOffset,a=t.edgeY+i/s*t.arrowOffset);const r=t.edgeX-t.lineEndpointX,n=t.edgeY-t.lineEndpointY,o=Math.sqrt(r*r+n*n);if(o>0){const e=r/o,i=n/o,s=-i,h=t.arrowOffset,u=t.edgeX,a=t.edgeY,c=u-e*h,f=a-i*h;l=`${u},${a} ${c+s*h/2},${f+e*h/2} ${c-s*h/2},${f-e*h/2}`}}return{indicatorRadius:i,indicatorStrokeWidth:s,lineStrokeWidth:r,dashArray:o,lineStroke:h,centerX:t.centerX,centerY:t.centerY,lineEndpointX:t.lineEndpointX,lineEndpointY:t.lineEndpointY,edgeX:t.edgeX,edgeY:t.edgeY,arrowOffset:t.arrowOffset,arrowStyle:t.arrowStyle,arrowFill:t.arrowFill,solidLineEndX:u,solidLineEndY:a,arrowPoints:l,snapLinePath:(()=>{if(void 0!==t.controlX&&void 0!==t.controlY&&void 0!==t.t){const e="start"===t.endpoint?1-t.t:t.t;if(e>=1)return;const i=this.extractQuadraticSegment({x:t.lineEndpointX,y:t.lineEndpointY},{x:t.controlX,y:t.controlY},{x:t.centerX,y:t.centerY},e,1);return`M ${i.start.x} ${i.start.y} Q ${i.control.x} ${i.control.y} ${i.end.x} ${i.end.y}`}})()}}handleObjectDeleted(t){const e=this.getLinesAnchoredTo(t);for(const t of e){this.removeAnchor(t.lineId,t.endpoint);const e=this.getLineById(t.lineId);e&&this._core.store.state.objects.update(e)}this._anchorIndex.delete(t)}handleLineDeleted(t){const e=this.getLineById(t);e&&(e.startAnchor&&this.removeFromIndex(e.startAnchor.objectId,t,"start"),e.endAnchor&&this.removeFromIndex(e.endAnchor.objectId,t,"end"))}rebuildIndex(){this._anchorIndex.clear();const t=this._core.store.allObjects;for(const e of t)e instanceof Ln&&(e.startAnchor&&this.addToIndex(e.startAnchor.objectId,e.id,"start"),e.endAnchor&&this.addToIndex(e.endAnchor.objectId,e.id,"end"))}addToIndex(t,e,i){this._anchorIndex.has(t)||this._anchorIndex.set(t,new Set);const s=this._anchorIndex.get(t);for(const t of s)if(t.lineId===e&&t.endpoint===i)return;s.add({lineId:e,endpoint:i})}removeFromIndex(t,e,i){const s=this._anchorIndex.get(t);if(s){for(const t of s)if(t.lineId===e&&t.endpoint===i){s.delete(t);break}0===s.size&&this._anchorIndex.delete(t)}}getLineById(t){const e=this._core.store.state.objects.filter((e=>e.id===t));if(0===e.length)return null;const i=e[0];return i instanceof Ln?i:null}getObjectById(t){const e=this._core.store.state.objects.filter((e=>e.id===t));return e.length>0?e[0]:null}findAnchorTarget(t,e){const i="start"===e?t.startAnchor:t.endAnchor;return i?this._core.store.allNonSelectionObjects.find((t=>t.id===i.objectId))??null:null}computeAnchorVisualization(t,e){if(!("start"===e?t.startAnchor:t.endAnchor))return null;const i=this.findAnchorTarget(t,e);if(!i)return null;const s=this.computeAnchorClipInfo(t,e,i);return s?{edgeX:s.worldX,edgeY:s.worldY,centerX:i.centerX,centerY:i.centerY,pathD:this.buildAnchorPath(t,e,s,i)??void 0}:null}computeClippedLinePath(t,e=!1){const i=this.getSnapCandidate(),s=this._core.store.selectionGroup,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 u=e?t.x:0,a=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-u} ${s.start.y-a} Q ${s.control.x-u} ${s.control.y-a} ${s.end.x-u} ${s.end.y-a}`}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-u} ${f-a} L ${d-u} ${p-a}`}computeAnchorClipInfo(t,e,i){return void 0!==t.controlX&&void 0!==t.controlY?this.computeCurvedClipInfo(t,e,i):this.computeStraightClipInfo(t,e,i)}computeStraightClipInfo(t,e,s){const r="start"===e?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY),n=this.getPathClipPoint(s,r);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(s);let h;if(h=o?i.getLinePointsArrayIntersection(r,{x:s.centerX,y:s.centerY},o):i.getLinePolygonIntersection(r,{x:s.centerX,y:s.centerY},s.rotatedPolygon),!h)return null;const l=this.lineWorldToLocal(t,h.x,h.y),u=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),a=Math.sqrt(Math.pow(l.x-t.startX,2)+Math.pow(l.y-t.startY,2));return{localX:l.x,localY:l.y,worldX:h.x,worldY:h.y,t:u>0?a/u:"start"===e?0:1}}computeCurvedClipInfo(t,e,s){if(ew.isInstanceOf(s,"KritzelPath"))return this.findCurveExitPointForPath(t,e,s);const r=this.getClipPolygonForObject(s),n=r??this.getPolygonPoints(s.rotatedPolygon),o=this.findCurveExitPoint(t,e,n);if(o)return o;const h="start"===e?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY);let l;if(l=r?i.getLinePointsArrayIntersection(h,{x:s.centerX,y:s.centerY},r):i.getLinePolygonIntersection(h,{x:s.centerX,y:s.centerY},s.rotatedPolygon),!l)return null;const u=this.lineWorldToLocal(t,l.x,l.y),a=this.approximateParameterForWorldPoint(t,l);return{localX:u.x,localY:u.y,worldX:l.x,worldY:l.y,t:a}}findCurveExitPoint(t,e,s){const r="start"===e?0:1,n=this.evaluateLineAtT(t,r);let o=i.isPointInPolygon({x:n.worldX,y:n.worldY},s),h=r;for(let r=1;r<=64;r++){const n="start"===e?r/64:1-r/64,l=this.evaluateLineAtT(t,n),u=i.isPointInPolygon({x:l.worldX,y:l.worldY},s);if(o&&!u){const e=this.refineCurveExitParameter(t,s,h,n),i=this.evaluateLineAtT(t,e);return{localX:i.localX,localY:i.localY,worldX:i.worldX,worldY:i.worldY,t:e}}o=u,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),u=this.isPointInPathStroke(o.worldX,o.worldY,n,r);if(h&&!u){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=u,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 u=((t-i)*o+(e-s)*h)/l;u=Math.max(0,Math.min(1,u));const a=i+u*o,c=s+u*h;return Math.sqrt((t-a)*(t-a)+(e-c)*(e-c))}refineCurveExitParameter(t,e,s,r){let n=s,o=r;for(let s=0;s<8;s++){const s=(n+o)/2,r=this.evaluateLineAtT(t,s);i.isPointInPolygon({x:r.worldX,y:r.worldY},e)?n=s:o=s}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 ew.isInstanceOf(t,"KritzelShape")?t.getClipPolygon():null}getPathClipPoint(t,e){return ew.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);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}}lineWorldToLocal(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}}isAnchorable(t){return!(t instanceof Fo||t instanceof Hn)&&!(t instanceof Ln)&&t.isVisible}}const sw={type:"pen",color:Cn[0],size:16,palettes:{pen:[...Cn]}},rw={color:Cn[0],size:8,fontFamily:"Arial",palette:[...Cn]},nw={color:Cn[0],size:4,palette:[...Cn],arrows:{end:{enabled:!0,style:"triangle"}}};export{Dn as $,$l as A,nh as B,hh as C,_p as D,Fn as E,_n as F,Ln as G,Kp as H,zn as I,Xn as J,$n as K,Jn as L,Vn as M,To as N,ih as O,Eo as P,Io as Q,Wo as R,Sd as S,tw as T,Gp as U,iw as V,sw as W,rw as X,nw as Y,Sn as Z,Bn as _,Rh as a,In as a0,Wn as a1,jo as a2,Cn as a3,Yo as a4,t as a5,Yn as a6,r as a7,Pn as a8,Do as a9,n as aa,Fo as ab,$o as ac,Hn as ad,s as ae,$a as af,Zp as ag,Sc as ah,e as ai,ew as aj,Kh as b,Wa as c,Qa as d,Ha as e,xh as f,qh as g,Vo as h,Xl as i,Wl as j,Yl as k,yl as l,el as m,sh as n,vl as o,dl as p,Il as q,Zh as r,Jo as s,Ch as t,Ih as u,ml as v,Oh as w,Al as x,eh as y,Ah as z}