kritzel-stencil 0.0.145 → 0.0.147

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 (44) hide show
  1. package/dist/cjs/{default-text-tool.config-D2dP2xyB.js → default-text-tool.config-C0W0noF9.js} +54 -34
  2. package/dist/cjs/default-text-tool.config-C0W0noF9.js.map +1 -0
  3. package/dist/cjs/index.cjs.js +1 -1
  4. package/dist/cjs/kritzel-color_22.cjs.entry.js +16 -41
  5. package/dist/collection/classes/core/viewport.class.js +4 -2
  6. package/dist/collection/classes/core/viewport.class.js.map +1 -1
  7. package/dist/collection/classes/objects/text.class.js +23 -23
  8. package/dist/collection/classes/objects/text.class.js.map +1 -1
  9. package/dist/collection/classes/tools/text-tool.class.js +3 -10
  10. package/dist/collection/classes/tools/text-tool.class.js.map +1 -1
  11. package/dist/collection/configs/default-engine-config.js +1 -2
  12. package/dist/collection/configs/default-engine-config.js.map +1 -1
  13. package/dist/collection/interfaces/debug-info.interface.js.map +1 -1
  14. package/dist/components/index.js +3 -3
  15. package/dist/components/kritzel-controls.js +1 -1
  16. package/dist/components/kritzel-editor.js +3 -3
  17. package/dist/components/kritzel-engine.js +1 -1
  18. package/dist/components/{p-ByRC-aCs.js → p-CrkPot2F.js} +8 -7
  19. package/dist/components/p-CrkPot2F.js.map +1 -0
  20. package/dist/components/{p-BgRGxOIE.js → p-DPN0PZvw.js} +3 -3
  21. package/dist/components/{p-BgRGxOIE.js.map → p-DPN0PZvw.js.map} +1 -1
  22. package/dist/components/{p-COGwCbe1.js → p-G2HGJcNm.js} +28 -34
  23. package/dist/components/p-G2HGJcNm.js.map +1 -0
  24. package/dist/esm/{default-text-tool.config-CsZAW1Cu.js → default-text-tool.config-nXXHSTK9.js} +54 -35
  25. package/dist/esm/default-text-tool.config-nXXHSTK9.js.map +1 -0
  26. package/dist/esm/index.js +2 -2
  27. package/dist/esm/kritzel-color_22.entry.js +6 -31
  28. package/dist/stencil/index.esm.js +1 -1
  29. package/dist/stencil/p-5d9c3f1b.entry.js +2 -0
  30. package/dist/stencil/p-5d9c3f1b.entry.js.map +1 -0
  31. package/dist/stencil/p-nXXHSTK9.js +2 -0
  32. package/dist/stencil/p-nXXHSTK9.js.map +1 -0
  33. package/dist/stencil/stencil.esm.js +1 -1
  34. package/dist/types/classes/objects/text.class.d.ts +1 -0
  35. package/dist/types/interfaces/debug-info.interface.d.ts +0 -1
  36. package/package.json +15 -14
  37. package/dist/cjs/default-text-tool.config-D2dP2xyB.js.map +0 -1
  38. package/dist/components/p-ByRC-aCs.js.map +0 -1
  39. package/dist/components/p-COGwCbe1.js.map +0 -1
  40. package/dist/esm/default-text-tool.config-CsZAW1Cu.js.map +0 -1
  41. package/dist/stencil/p-27adbf9d.entry.js +0 -2
  42. package/dist/stencil/p-27adbf9d.entry.js.map +0 -1
  43. package/dist/stencil/p-CsZAW1Cu.js +0 -2
  44. package/dist/stencil/p-CsZAW1Cu.js.map +0 -1
@@ -1,2 +0,0 @@
1
- class t{static registry={};static registerTool(t,e,i){const s=new e(i);s.name=t;this.registry[t]=s;return s}static getTool(t){const e=this.registry[t];if(!e){console.warn(`Unknown tool: ${t}`);return null}return e}}class e{static generateUUID(){return Math.random().toString(36).substr(2,9)}static isEmpty(t){if(t===null||t===undefined){return true}return Object?.keys(t).length===0&&t?.constructor===Object}}class i{static doPolygonsIntersect(t,e){const i=[t.bottomLeft,t.bottomRight,t.topRight,t.topLeft];const s=[e.bottomLeft,e.bottomRight,e.topRight,e.topLeft];for(const t of i){if(this.isPointInPolygon(t,s)){return true}}for(const t of s){if(this.isPointInPolygon(t,i)){return true}}for(let t=0;t<i.length;t++){const e=i[t];const n=i[(t+1)%i.length];for(let t=0;t<s.length;t++){const i=s[t];const r=s[(t+1)%s.length];if(this.intersectLines(e,n,i,r)){return true}}}return false}static isPointInPolygon(t,e){let i=false;for(let s=0,n=e.length-1;s<e.length;n=s++){const r=e[s].x,o=e[s].y;const l=e[n].x,h=e[n].y;const f=o>t.y!==h>t.y&&t.x<(l-r)*(t.y-o)/(h-o)+r;if(f)i=!i}return i}static intersectLines(t,e,i,s){const n=(e.x-t.x)*(s.y-i.y)-(e.y-t.y)*(s.x-i.x);if(n===0){return false}const r=((i.x-t.x)*(s.y-i.y)-(i.y-t.y)*(s.x-i.x))/n;const o=-((t.x-i.x)*(e.y-t.y)-(t.y-i.y)*(e.x-t.x))/n;return r>=0&&r<=1&&o>=0&&o<=1}}class s{__class__="KritzelBaseObject";_core;_elementRef;id;workspaceId;x;y;translateX;translateY;height;width;backgroundColor;borderColor;borderWidth=0;opacity=1;padding=0;scale;resizing=false;rotation=0;markedForRemoval=false;zIndex=0;isVisible=true;isSelected=false;isHovered=false;isMounted=false;isEditable=false;isInteractive=false;isDebugInfoVisible=false;get totalWidth(){return this.width+this.padding*2}get totalHeight(){return this.height+this.padding*2}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;const e=this.translateY+this.totalHeight/2/this.scale;const i=this.rotation;const s=this.totalWidth/this.scale;const n=this.totalHeight/this.scale;const r={topLeft:{x:this.translateX,y:this.translateY},topRight:{x:this.translateX+s,y:this.translateY},bottomRight:{x:this.translateX+s,y:this.translateY+n},bottomLeft:{x:this.translateX,y:this.translateY+n}};const o=Object.keys(r).reduce(((s,n)=>{const o=r[n];const l=Math.cos(i)*(o.x-t)-Math.sin(i)*(o.y-e)+t;const h=Math.sin(i)*(o.x-t)+Math.cos(i)*(o.y-e)+e;s[n]={x:l,y:h};return s}),{});return o}get minXRotated(){const t=[this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x];return Math.min(...t)}get minYRotated(){const t=[this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y];return Math.min(...t)}get maxXRotated(){const t=[this.rotatedPolygon.topLeft.x,this.rotatedPolygon.topRight.x,this.rotatedPolygon.bottomRight.x,this.rotatedPolygon.bottomLeft.x];return Math.max(...t)}get maxYRotated(){const t=[this.rotatedPolygon.topLeft.y,this.rotatedPolygon.topRight.y,this.rotatedPolygon.bottomRight.y,this.rotatedPolygon.bottomLeft.y];return Math.max(...t)}get transformationMatrix(){const t=1/this.scale;const e=this.translateX;const i=this.translateY;return`matrix(${t}, 0, 0, ${t}, ${e}, ${i})`}get rotationDegrees(){return this.rotation*(180/Math.PI)}get centerX(){return this.translateX+this.totalWidth/2}get centerY(){return this.translateY+this.totalHeight/2}constructor(){this.id=this.generateId()}static create(t){const e=new s;e._core=t;e.zIndex=t.store.currentZIndex;e.workspaceId=t.store.state.activeWorkspace.id;return e}mount(t){if(this.isMounted){return}this.elementRef=t;this.isMounted=true}generateId(){return e.generateUUID()}isInViewport(){const t={x:-this._core.store.state.translateX/this._core.store.state.scale,y:-this._core.store.state.translateY/this._core.store.state.scale,width:this._core.store.state.viewportWidth/this._core.store.state.scale,height:this._core.store.state.viewportHeight/this._core.store.state.scale};return this.rotatedBoundingBox.x<t.x+t.width&&this.rotatedBoundingBox.x+this.rotatedBoundingBox.width>t.x&&this.rotatedBoundingBox.y<t.y+t.height&&this.rotatedBoundingBox.y+this.rotatedBoundingBox.height>t.y}centerInViewport(){const{viewportWidth:t,viewportHeight:e,translateX:i,translateY:s,scale:n}=this._core.store.state;const{x:r,y:o,width:l,height:h}=this.rotatedBoundingBox;const f=r+l/2;const u=o+h/2;const c=(t/2-i)/n;const a=(e/2-s)/n;const d=c-f;const w=a-u;this.updatePosition(this.translateX+d,this.translateY+w)}update(){this._core.store.state.objectsMap.update(this)}move(t,e,i,s){const n=(t-i)/this._core.store.state.scale;const r=(e-s)/this._core.store.state.scale;this.translateX+=n;this.translateY+=r;this._core.store.state.objectsMap.update(this)}resize(t,e,i,s){if(i<=1||s<=1){return}this.width=i;this.height=s;this.translateX=t;this.translateY=e;this._core.store.state.objectsMap.update(this)}rotate(t){this.rotation=t;this._core.store.state.objectsMap.update(this)}clone(){const t=Object.create(Object.getPrototypeOf(this));Object.assign(t,this);t.id=this.id;return t}copy(){const t=Object.create(Object.getPrototypeOf(this));Object.assign(t,this);t.id=this.generateId();t.isMounted=false;return t}serialize(){const{_core:t,_elementRef:e,element:i,totalWidth:s,totalHeight:n,...r}=this;const o=structuredClone(r);if(i&&typeof i==="object"&&"nodeType"in i&&i.nodeType===1){o.element=i.cloneNode(true)}return o}deserialize(t){Object.assign(this,t);return this}isClass(t){return this.__class__===t}edit(t){}hitTest(t,e){return true}hitTestPolygon(t){const e=this.rotatedPolygon;return i.doPolygonsIntersect(e,t)}updatePosition(t,e){this.translateX=t;this.translateY=e;this._core.store.state.objectsMap.update(this)}}class n{static forceHideKeyboard(){if(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");if(!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");let i=e.replace(/\s*interactive-widget=resizes-content\s*[,;]?/g,"");i=i.replace(/,(\s*,)+/g,",").replace(/^,/,"").replace(/,$/,"").trim();t.setAttribute("content",i)}}static onKeyboardVisibleChanged(t){if("visualViewport"in window){const e=.75;const i=i=>{const s=i.target;const n=s.height*s.scale/window.screen.height<e;t(n)};window.visualViewport.addEventListener("resize",i);return()=>window.visualViewport.removeEventListener("resize",i)}else{console.warn("Listening for keyboard visibility changes is not reliably supported in this browser.");return()=>{}}}}function r(t){this.content=t}r.prototype={constructor:r,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 e==-1?undefined:this.content[e+1]},update:function(t,e,i){var s=i&&i!=t?this.remove(i):this;var n=s.find(t),o=s.content.slice();if(n==-1){o.push(i||t,e)}else{o[n+1]=e;if(i)o[n]=i}return new r(o)},remove:function(t){var e=this.find(t);if(e==-1)return this;var i=this.content.slice();i.splice(e,2);return new r(i)},addToStart:function(t,e){return new r([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var i=this.remove(t).content.slice();i.push(t,e);return new r(i)},addBefore:function(t,e,i){var s=this.remove(e),n=s.content.slice();var o=s.find(t);n.splice(o==-1?n.length:o,0,e,i);return new r(n)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){t=r.from(t);if(!t.size)return this;return new r(t.content.concat(this.subtract(t).content))},append:function(t){t=r.from(t);if(!t.size)return this;return new r(this.subtract(t).content.concat(t.content))},subtract:function(t){var e=this;t=r.from(t);for(var i=0;i<t.content.length;i+=2)e=e.remove(t.content[i]);return e},toObject:function(){var t={};this.forEach((function(e,i){t[e]=i}));return t},get size(){return this.content.length>>1}};r.from=function(t){if(t instanceof r)return t;var e=[];if(t)for(var i in t)e.push(i,t[i]);return new r(e)};function o(t,e,i){for(let s=0;;s++){if(s==t.childCount||s==e.childCount)return t.childCount==e.childCount?null:i;let n=t.child(s),r=e.child(s);if(n==r){i+=n.nodeSize;continue}if(!n.sameMarkup(r))return i;if(n.isText&&n.text!=r.text){for(let t=0;n.text[t]==r.text[t];t++)i++;return i}if(n.content.size||r.content.size){let t=o(n.content,r.content,i+1);if(t!=null)return t}i+=n.nodeSize}}function l(t,e,i,s){for(let n=t.childCount,r=e.childCount;;){if(n==0||r==0)return n==r?null:{a:i,b:s};let o=t.child(--n),h=e.child(--r),f=o.nodeSize;if(o==h){i-=f;s-=f;continue}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);while(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-=f;s-=f}}class h{constructor(t,e){this.content=t;this.size=e||0;if(e==null)for(let e=0;e<t.length;e++)this.size+=t[e].nodeSize}nodesBetween(t,e,i,s=0,n){for(let r=0,o=0;o<e;r++){let l=this.content[r],h=o+l.nodeSize;if(h>t&&i(l,s+o,n||null,r)!==false&&l.content.size){let n=o+1;l.nodesBetween(Math.max(0,t-n),Math.min(l.content.size,e-n),i,s+n)}o=h}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,e,i,s){let n="",r=true;this.nodesBetween(t,e,((o,l)=>{let h=o.isText?o.text.slice(Math.max(t,l)-l,e-l):!o.isLeaf?"":s?typeof s==="function"?s(o):s:o.type.spec.leafText?o.type.spec.leafText(o):"";if(o.isBlock&&(o.isLeaf&&h||o.isTextblock)&&i){if(r)r=false;else n+=i}n+=h}),0);return n}append(t){if(!t.size)return this;if(!this.size)return t;let e=this.lastChild,i=t.firstChild,s=this.content.slice(),n=0;if(e.isText&&e.sameMarkup(i)){s[s.length-1]=e.withText(e.text+i.text);n=1}for(;n<t.content.length;n++)s.push(t.content[n]);return new h(s,this.size+t.size)}cut(t,e=this.size){if(t==0&&e==this.size)return this;let i=[],s=0;if(e>t)for(let n=0,r=0;r<e;n++){let o=this.content[n],l=r+o.nodeSize;if(l>t){if(r<t||l>e){if(o.isText)o=o.cut(Math.max(0,t-r),Math.min(o.text.length,e-r));else o=o.cut(Math.max(0,t-r-1),Math.min(o.content.size,e-r-1))}i.push(o);s+=o.nodeSize}r=l}return new h(i,s)}cutByIndex(t,e){if(t==e)return h.empty;if(t==0&&e==this.content.length)return this;return new h(this.content.slice(t,e))}replaceChild(t,e){let i=this.content[t];if(i==e)return this;let s=this.content.slice();let n=this.size+e.nodeSize-i.nodeSize;s[t]=e;return new h(s,n)}addToStart(t){return new h([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new h(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return false;for(let e=0;e<this.content.length;e++)if(!this.content[e].eq(t.content[e]))return false;return true}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(t){let e=this.content[t];if(!e)throw new RangeError("Index "+t+" out of range for "+this);return e}maybeChild(t){return this.content[t]||null}forEach(t){for(let e=0,i=0;e<this.content.length;e++){let s=this.content[e];t(s,i,e);i+=s.nodeSize}}findDiffStart(t,e=0){return o(this,t,e)}findDiffEnd(t,e=this.size,i=t.size){return l(this,t,e,i)}findIndex(t){if(t==0)return u(0,t);if(t==this.size)return u(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=this.child(e),n=i+s.nodeSize;if(n>=t){if(n==t)return u(e+1,n);return u(e,i)}i=n}}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 h.empty;if(!Array.isArray(e))throw new RangeError("Invalid input for Fragment.fromJSON");return new h(e.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return h.empty;let e,i=0;for(let s=0;s<t.length;s++){let n=t[s];i+=n.nodeSize;if(s&&n.isText&&t[s-1].sameMarkup(n)){if(!e)e=t.slice(0,s);e[e.length-1]=n.withText(e[e.length-1].text+n.text)}else if(e){e.push(n)}}return new h(e||t,i)}static from(t){if(!t)return h.empty;if(t instanceof h)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new h([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}h.empty=new h([],0);const f={index:0,offset:0};function u(t,e){f.index=t;f.offset=e;return f}function c(t,e){if(t===e)return true;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return false;let i=Array.isArray(t);if(Array.isArray(e)!=i)return false;if(i){if(t.length!=e.length)return false;for(let i=0;i<t.length;i++)if(!c(t[i],e[i]))return false}else{for(let i in t)if(!(i in e)||!c(t[i],e[i]))return false;for(let i in e)if(!(i in t))return false}return true}class a{constructor(t,e){this.type=t;this.attrs=e}addToSet(t){let e,i=false;for(let s=0;s<t.length;s++){let n=t[s];if(this.eq(n))return t;if(this.type.excludes(n.type)){if(!e)e=t.slice(0,s)}else if(n.type.excludes(this.type)){return t}else{if(!i&&n.type.rank>this.type.rank){if(!e)e=t.slice(0,s);e.push(this);i=true}if(e)e.push(n)}}if(!e)e=t.slice();if(!i)e.push(this);return 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 true;return false}eq(t){return this==t||this.type==t.type&&c(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);i.checkAttrs(s.attrs);return s}static sameSet(t,e){if(t==e)return true;if(t.length!=e.length)return false;for(let i=0;i<t.length;i++)if(!t[i].eq(e[i]))return false;return true}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return a.none;if(t instanceof a)return[t];let e=t.slice();e.sort(((t,e)=>t.type.rank-e.type.rank));return e}}a.none=[];class d 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=g(this.content,t+this.openStart,e);return i&&new w(i,this.openStart,this.openEnd)}removeBetween(t,e){return new w(p(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()};if(this.openStart>0)t.openStart=this.openStart;if(this.openEnd>0)t.openEnd=this.openEnd;return t}static fromJSON(t,e){if(!e)return w.empty;let i=e.openStart||0,s=e.openEnd||0;if(typeof i!="number"||typeof s!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new w(h.fromJSON(t,e.content),i,s)}static maxOpen(t,e=true){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)}}w.empty=new w(h.empty,0,0);function p(t,e,i){let{index:s,offset:n}=t.findIndex(e),r=t.maybeChild(s);let{index:o,offset:l}=t.findIndex(i);if(n==e||r.isText){if(l!=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,r.copy(p(r.content,e-n-1,i-n-1)))}function g(t,e,i,s){let{index:n,offset:r}=t.findIndex(e),o=t.maybeChild(n);if(r==e||o.isText){if(s&&!s.canReplace(n,n,i))return null;return t.cut(0,e).append(i).append(t.cut(e))}let l=g(o.content,e-r-1,i,o);return l&&t.replaceChild(n,o.copy(l))}function m(t,e,i){if(i.openStart>t.depth)throw new d("Inserted content deeper than insertion position");if(t.depth-i.openStart!=e.depth-i.openEnd)throw new d("Inconsistent open depths");return y(t,e,i,0)}function y(t,e,i,s){let n=t.index(s),r=t.node(s);if(n==e.index(s)&&s<t.depth-i.openStart){let o=y(t,e,i,s+1);return r.copy(r.content.replaceChild(n,o))}else if(!i.content.size){return k(r,x(t,e,s))}else if(!i.openStart&&!i.openEnd&&t.depth==s&&e.depth==s){let s=t.parent,n=s.content;return k(s,n.cut(0,t.parentOffset).append(i.content).append(n.cut(e.parentOffset)))}else{let{start:n,end:o}=O(i,t);return k(r,S(t,n,o,e,s))}}function b(t,e){if(!e.type.compatibleContent(t.type))throw new d("Cannot join "+e.type.name+" onto "+t.type.name)}function v(t,e,i){let s=t.node(i);b(s,e.node(i));return s}function A(t,e){let i=e.length-1;if(i>=0&&t.isText&&t.sameMarkup(e[i]))e[i]=t.withText(e[i].text+t.text);else e.push(t)}function M(t,e,i,s){let n=(e||t).node(i);let r=0,o=e?e.index(i):n.childCount;if(t){r=t.index(i);if(t.depth>i){r++}else if(t.textOffset){A(t.nodeAfter,s);r++}}for(let t=r;t<o;t++)A(n.child(t),s);if(e&&e.depth==i&&e.textOffset)A(e.nodeBefore,s)}function k(t,e){t.type.checkContent(e);return t.copy(e)}function S(t,e,i,s,n){let r=t.depth>n&&v(t,e,n+1);let o=s.depth>n&&v(i,s,n+1);let l=[];M(null,t,n,l);if(r&&o&&e.index(n)==i.index(n)){b(r,o);A(k(r,S(t,e,i,s,n+1)),l)}else{if(r)A(k(r,x(t,e,n+1)),l);M(e,i,n,l);if(o)A(k(o,x(i,s,n+1)),l)}M(s,null,n,l);return new h(l)}function x(t,e,i){let s=[];M(null,t,i,s);if(t.depth>i){let n=v(t,e,i+1);A(k(n,x(t,e,i+1)),s)}M(e,null,i,s);return new h(s)}function O(t,e){let i=e.depth-t.openStart,s=e.node(i);let n=s.copy(t.content);for(let t=i-1;t>=0;t--)n=e.node(t).copy(h.from(n));return{start:n.resolveNoCache(t.openStart+i),end:n.resolveNoCache(n.content.size-t.openEnd-i)}}class E{constructor(t,e,i){this.pos=t;this.path=e;this.parentOffset=i;this.depth=e.length/3-1}resolveDepth(t){if(t==null)return this.depth;if(t<0)return this.depth+t;return t}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(t){return this.path[this.resolveDepth(t)*3]}index(t){return this.path[this.resolveDepth(t)*3+1]}indexAfter(t){t=this.resolveDepth(t);return this.index(t)+(t==this.depth&&!this.textOffset?0:1)}start(t){t=this.resolveDepth(t);return t==0?0:this.path[t*3-1]+1}end(t){t=this.resolveDepth(t);return this.start(t)+this.node(t).content.size}before(t){t=this.resolveDepth(t);if(!t)throw new RangeError("There is no position before the top-level node");return t==this.depth+1?this.pos:this.path[t*3-1]}after(t){t=this.resolveDepth(t);if(!t)throw new RangeError("There is no position after the top-level node");return t==this.depth+1?this.pos:this.path[t*3-1]+this.path[t*3].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);let e=this.pos-this.path[this.path.length-1];if(e)return this.parent.child(t).cut(0,e);return t==0?null:this.parent.child(t-1)}posAtIndex(t,e){e=this.resolveDepth(e);let i=this.path[e*3],s=e==0?0:this.path[e*3-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(t.content.size==0)return a.none;if(this.textOffset)return t.child(e).marks;let i=t.maybeChild(e-1),s=t.maybeChild(e);if(!i){let t=i;i=s;s=t}let n=i.marks;for(var r=0;r<n.length;r++)if(n[r].type.spec.inclusive===false&&(!s||!n[r].isInSet(s.marks)))n=n[r--].removeFromSet(n);return n}marksAcross(t){let e=this.parent.maybeChild(this.index());if(!e||!e.isInline)return null;let i=e.marks,s=t.parent.maybeChild(t.index());for(var n=0;n<i.length;n++)if(i[n].type.spec.inclusive===false&&(!s||!i[n].isInSet(s.marks)))i=i[n--].removeFromSet(i);return i}sharedDepth(t){for(let e=this.depth;e>0;e--)if(this.start(e)<=t&&this.end(e)>=t)return e;return 0}blockRange(t=this,e){if(t.pos<this.pos)return t.blockRange(this);for(let i=this.depth-(this.parent.inlineContent||this.pos==t.pos?1:0);i>=0;i--)if(t.pos<=this.end(i)&&(!e||e(this.node(i))))return new R(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=[];let s=0,n=e;for(let e=t;;){let{index:t,offset:r}=e.content.findIndex(n);let o=n-r;i.push(e,t,s+r);if(!o)break;e=e.child(t);if(e.isText)break;n=o-1;s+=r+1}return new E(e,i,n)}static resolveCached(t,e){let i=C.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{C.set(t,i=new D)}let s=i.elts[i.i]=E.resolve(t,e);i.i=(i.i+1)%T;return s}}class D{constructor(){this.elts=[];this.i=0}}const T=12,C=new WeakMap;class R{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 U=Object.create(null);class I{constructor(t,e,i,s=a.none){this.type=t;this.attrs=e;this.marks=s;this.content=i||h.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&&c(this.attrs,e||t.defaultAttrs||U)&&a.sameSet(this.marks,i||a.none)}copy(t=null){if(t==this.content)return this;return new I(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new I(this.type,this.attrs,this.content,t)}cut(t,e=this.content.size){if(t==0&&e==this.content.size)return this;return this.copy(this.content.cut(t,e))}slice(t,e=this.content.size,i=false){if(t==e)return w.empty;let s=this.resolve(t),n=this.resolve(e);let r=i?0:s.sharedDepth(e);let o=s.start(r),l=s.node(r);let h=l.content.cut(s.pos-o,n.pos-o);return new w(h,s.depth-r,n.depth-r)}replace(t,e,i){return m(this.resolve(t),this.resolve(e),i)}nodeAt(t){for(let e=this;;){let{index:i,offset:s}=e.content.findIndex(t);e=e.maybeChild(i);if(!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(t==0)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 E.resolveCached(this,t)}resolveNoCache(t){return E.resolve(this,t)}rangeHasMark(t,e,i){let s=false;if(e>t)this.nodesBetween(t,e,(t=>{if(i.isInSet(t.marks))s=true;return!s}));return 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;if(this.content.size)t+="("+this.content.toStringInner()+")";return 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=h.empty,s=0,n=i.childCount){let r=this.contentMatchAt(t).matchFragment(i,s,n);let o=r&&r.matchFragment(this.content,e);if(!o||!o.validEnd)return false;for(let t=s;t<n;t++)if(!this.type.allowsMarks(i.child(t).marks))return false;return true}canReplaceWith(t,e,i,s){if(s&&!this.type.allowsMarks(s))return false;let n=this.contentMatchAt(t).matchType(i);let r=n&&n.matchFragment(this.content,e);return r?r.validEnd:false}canAppend(t){if(t.content.size)return this.canReplace(this.childCount,this.childCount,t.content);else return this.type.compatibleContent(t.type)}check(){this.type.checkContent(this.content);this.type.checkAttrs(this.attrs);let t=a.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(!a.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}if(this.content.size)t.content=this.content.toJSON();if(this.marks.length)t.marks=this.marks.map((t=>t.toJSON()));return t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Node.fromJSON");let i=undefined;if(e.marks){if(!Array.isArray(e.marks))throw new RangeError("Invalid mark data for Node.fromJSON");i=e.marks.map(t.markFromJSON)}if(e.type=="text"){if(typeof e.text!="string")throw new RangeError("Invalid text node in JSON");return t.text(e.text,i)}let s=h.fromJSON(t,e.content);let n=t.nodeType(e.type).create(e.attrs,s,i);n.type.checkAttrs(n.attrs);return n}}I.prototype.text=undefined;class N extends I{constructor(t,e,i,s){super(t,e,null,s);if(!i)throw new RangeError("Empty text nodes are not allowed");this.text=i}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);return 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 N(this.type,this.attrs,this.text,t)}withText(t){if(t==this.text)return this;return new N(this.type,this.attrs,t,this.marks)}cut(t=0,e=this.text.length){if(t==0&&e==this.text.length)return this;return this.withText(this.text.slice(t,e))}eq(t){return this.sameMarkup(t)&&this.text==t.text}toJSON(){let t=super.toJSON();t.text=this.text;return t}}function P(t,e){for(let i=t.length-1;i>=0;i--)e=t[i].type.name+"("+e+")";return e}class F{constructor(t){this.validEnd=t;this.next=[];this.wrapCache=[]}static parse(t,e){let i=new B(t,e);if(i.next==null)return F.empty;let s=j(i);if(i.next)i.err("Unexpected trailing text");let n=V(Q(s));K(n,i);return n}matchType(t){for(let e=0;e<this.next.length;e++)if(this.next[e].type==t)return this.next[e].next;return null}matchFragment(t,e=0,i=t.childCount){let s=this;for(let n=e;s&&n<i;n++)s=s.matchType(t.child(n).type);return s}get inlineContent(){return this.next.length!=0&&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 true;return false}fillBefore(t,e=false,i=0){let s=[this];function n(r,o){let l=r.matchFragment(t,i);if(l&&(!e||l.validEnd))return h.from(o.map((t=>t.createAndFill())));for(let t=0;t<r.next.length;t++){let{type:e,next:i}=r.next[t];if(!(e.isText||e.hasRequiredAttrs())&&s.indexOf(i)==-1){s.push(i);let t=n(i,o.concat(e));if(t)return t}}return null}return n(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);this.wrapCache.push(t,e);return e}computeWrapping(t){let e=Object.create(null),i=[{match:this,type:null,via:null}];while(i.length){let s=i.shift(),n=s.match;if(n.matchType(t)){let t=[];for(let e=s;e.type;e=e.via)t.push(e.type);return t.reverse()}for(let t=0;t<n.next.length;t++){let{type:r,next:o}=n.next[t];if(!r.isLeaf&&!r.hasRequiredAttrs()&&!(r.name in e)&&(!s.type||o.validEnd)){i.push({match:r.contentMatch,type:r,via:s});e[r.name]=true}}}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=[];function e(i){t.push(i);for(let s=0;s<i.next.length;s++)if(t.indexOf(i.next[s].next)==-1)e(i.next[s].next)}e(this);return 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")}}F.empty=new F(true);class B{constructor(t,e){this.string=t;this.nodeTypes=e;this.inline=null;this.pos=0;this.tokens=t.split(/\s*(?=\b|\W|$)/);if(this.tokens[this.tokens.length-1]=="")this.tokens.pop();if(this.tokens[0]=="")this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(t){return this.next==t&&(this.pos++||true)}err(t){throw new SyntaxError(t+" (in content expression '"+this.string+"')")}}function j(t){let e=[];do{e.push(_(t))}while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function _(t){let e=[];do{e.push($(t))}while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function $(t){let e=W(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("{"))e=z(t,e);else break}return e}function L(t){if(/\D/.test(t.next))t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);t.pos++;return e}function z(t,e){let i=L(t),s=i;if(t.eat(",")){if(t.next!="}")s=L(t);else s=-1}if(!t.eat("}"))t.err("Unclosed braced range");return{type:"range",min:i,max:s,expr:e}}function J(t,e){let i=t.nodeTypes,s=i[e];if(s)return[s];let n=[];for(let t in i){let s=i[t];if(s.isInGroup(e))n.push(s)}if(n.length==0)t.err("No node type or group '"+e+"' found");return n}function W(t){if(t.eat("(")){let e=j(t);if(!t.eat(")"))t.err("Missing closing paren");return e}else if(!/\W/.test(t.next)){let e=J(t,t.next).map((e=>{if(t.inline==null)t.inline=e.isInline;else if(t.inline!=e.isInline)t.err("Mixing inline and block content");return{type:"name",value:e}}));t.pos++;return e.length==1?e[0]:{type:"choice",exprs:e}}else{t.err("Unexpected token '"+t.next+"'")}}function Q(t){let e=[[]];n(r(t,0),i());return e;function i(){return e.push([])-1}function s(t,i,s){let n={term:s,to:i};e[t].push(n);return n}function n(t,e){t.forEach((t=>t.to=e))}function r(t,e){if(t.type=="choice"){return t.exprs.reduce(((t,i)=>t.concat(r(i,e))),[])}else if(t.type=="seq"){for(let s=0;;s++){let o=r(t.exprs[s],e);if(s==t.exprs.length-1)return o;n(o,e=i())}}else if(t.type=="star"){let o=i();s(e,o);n(r(t.expr,o),o);return[s(o)]}else if(t.type=="plus"){let o=i();n(r(t.expr,e),o);n(r(t.expr,o),o);return[s(o)]}else if(t.type=="opt"){return[s(e)].concat(r(t.expr,e))}else if(t.type=="range"){let o=e;for(let e=0;e<t.min;e++){let e=i();n(r(t.expr,o),e);o=e}if(t.max==-1){n(r(t.expr,o),o)}else{for(let e=t.min;e<t.max;e++){let e=i();s(o,e);n(r(t.expr,o),e);o=e}}return[s(o)]}else if(t.type=="name"){return[s(e,undefined,t.value)]}else{throw new Error("Unknown expr type")}}}function H(t,e){return e-t}function q(t,e){let i=[];s(e);return i.sort(H);function s(e){let n=t[e];if(n.length==1&&!n[0].term)return s(n[0].to);i.push(e);for(let t=0;t<n.length;t++){let{term:e,to:r}=n[t];if(!e&&i.indexOf(r)==-1)s(r)}}}function V(t){let e=Object.create(null);return i(q(t,0));function i(s){let n=[];s.forEach((e=>{t[e].forEach((({term:e,to:i})=>{if(!e)return;let s;for(let t=0;t<n.length;t++)if(n[t][0]==e)s=n[t][1];q(t,i).forEach((t=>{if(!s)n.push([e,s=[]]);if(s.indexOf(t)==-1)s.push(t)}))}))}));let r=e[s.join(",")]=new F(s.indexOf(t.length-1)>-1);for(let t=0;t<n.length;t++){let s=n[t][1].sort(H);r.next.push({type:n[t][0],next:e[s.join(",")]||i(s)})}return r}}function K(t,e){for(let i=0,s=[t];i<s.length;i++){let t=s[i],n=!t.validEnd,r=[];for(let e=0;e<t.next.length;e++){let{type:i,next:o}=t.next[e];r.push(i.name);if(n&&!(i.isText||i.hasRequiredAttrs()))n=false;if(s.indexOf(o)==-1)s.push(o)}if(n)e.err("Only non-generatable nodes ("+r.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function Y(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 X(t,e){let i=Object.create(null);for(let s in t){let n=e&&e[s];if(n===undefined){let e=t[s];if(e.hasDefault)n=e.default;else throw new RangeError("No value supplied for attribute "+s)}i[s]=n}return i}function G(t,e,i,s){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];if(s.validate)s.validate(e[i])}}function Z(t,e){let i=Object.create(null);if(e)for(let s in e)i[s]=new it(t,s,e[s]);return i}let tt=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=Z(t,i.attrs);this.defaultAttrs=Y(this.attrs);this.contentMatch=null;this.inlineContent=null;this.isBlock=!(i.inline||t=="text");this.isText=t=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==F.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 true;return false}compatibleContent(t){return this==t||this.contentMatch.compatible(t.contentMatch)}computeAttrs(t){if(!t&&this.defaultAttrs)return this.defaultAttrs;else return X(this.attrs,t)}create(t=null,e,i){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new I(this,this.computeAttrs(t),h.from(e),a.setFrom(i))}createChecked(t=null,e,i){e=h.from(e);this.checkContent(e);return new I(this,this.computeAttrs(t),e,a.setFrom(i))}createAndFill(t=null,e,i){t=this.computeAttrs(t);e=h.from(e);if(e.size){let t=this.contentMatch.fillBefore(e);if(!t)return null;e=t.append(e)}let s=this.contentMatch.matchFragment(e);let n=s&&s.fillBefore(h.empty,true);if(!n)return null;return new I(this,t,e.append(n),a.setFrom(i))}validContent(t){let e=this.contentMatch.matchFragment(t);if(!e||!e.validEnd)return false;for(let e=0;e<t.childCount;e++)if(!this.allowsMarks(t.child(e).marks))return false;return true}checkContent(t){if(!this.validContent(t))throw new RangeError(`Invalid content for node ${this.name}: ${t.toString().slice(0,50)}`)}checkAttrs(t){G(this.attrs,t,"node")}allowsMarkType(t){return this.markSet==null||this.markSet.indexOf(t)>-1}allowsMarks(t){if(this.markSet==null)return true;for(let e=0;e<t.length;e++)if(!this.allowsMarkType(t[e].type))return false;return true}allowedMarks(t){if(this.markSet==null)return t;let e;for(let i=0;i<t.length;i++){if(!this.allowsMarkType(t[i].type)){if(!e)e=t.slice(0,i)}else if(e){e.push(t[i])}}return!e?t:e.length?e:a.none}static compile(e,i){let s=Object.create(null);e.forEach(((e,n)=>s[e]=new t(e,i,n)));let n=i.spec.topNode||"doc";if(!s[n])throw new RangeError("Schema is missing its top node type ('"+n+"')");if(!s.text)throw new RangeError("Every schema needs a 'text' type");for(let t in s.text.attrs)throw new RangeError("The text node type should not have attributes");return s}};function et(t,e,i){let s=i.split("|");return i=>{let n=i===null?"null":typeof i;if(s.indexOf(n)<0)throw new RangeError(`Expected value of type ${s} for attribute ${e} on type ${t}, got ${n}`)}}class it{constructor(t,e,i){this.hasDefault=Object.prototype.hasOwnProperty.call(i,"default");this.default=i.default;this.validate=typeof i.validate=="string"?et(t,e,i.validate):i.validate}get isRequired(){return!this.hasDefault}}class st{constructor(t,e,i,s){this.name=t;this.rank=e;this.schema=i;this.spec=s;this.attrs=Z(t,s.attrs);this.excluded=null;let n=Y(this.attrs);this.instance=n?new a(this,n):null}create(t=null){if(!t&&this.instance)return this.instance;return new a(this,X(this.attrs,t))}static compile(t,e){let i=Object.create(null),s=0;t.forEach(((t,n)=>i[t]=new st(t,s++,e,n)));return i}removeFromSet(t){for(var e=0;e<t.length;e++)if(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){G(this.attrs,t,"mark")}excludes(t){return this.excluded.indexOf(t)>-1}}class nt{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=r.from(t.nodes),e.marks=r.from(t.marks||{}),this.nodes=tt.compile(this.spec.nodes,this);this.marks=st.compile(this.spec.marks,this);let i=Object.create(null);for(let t in this.nodes){if(t in this.marks)throw new RangeError(t+" can not be both a node and a mark");let e=this.nodes[t],s=e.spec.content||"",n=e.spec.marks;e.contentMatch=i[s]||(i[s]=F.parse(s,this.nodes));e.inlineContent=e.contentMatch.inlineContent;if(e.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!e.isInline||!e.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=e}e.markSet=n=="_"?null:n?rt(this,n.split(" ")):n==""||!e.inlineContent?[]:null}for(let t in this.marks){let e=this.marks[t],i=e.spec.excludes;e.excluded=i==null?[e]:i==""?[]:rt(this,i.split(" "))}this.nodeFromJSON=t=>I.fromJSON(this,t);this.markFromJSON=t=>a.fromJSON(this,t);this.topNodeType=this.nodes[this.spec.topNode||"doc"];this.cached.wrappings=Object.create(null)}node(t,e=null,i,s){if(typeof t=="string")t=this.nodeType(t);else if(!(t instanceof tt))throw new RangeError("Invalid node type: "+t);else 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 N(i,i.defaultAttrs,t,a.setFrom(e))}mark(t,e){if(typeof t=="string")t=this.marks[t];return t.create(e)}nodeType(t){let e=this.nodes[t];if(!e)throw new RangeError("Unknown node type: "+t);return e}}function rt(t,e){let i=[];for(let s=0;s<e.length;s++){let n=e[s],r=t.marks[n],o=r;if(r){i.push(r)}else{for(let e in t.marks){let s=t.marks[e];if(n=="_"||s.spec.group&&s.spec.group.split(" ").indexOf(n)>-1)i.push(o=s)}}if(!o)throw new SyntaxError("Unknown mark type: '"+e[s]+"'")}return i}function ot(t){return t.tag!=null}function lt(t){return t.style!=null}let ht=class t{constructor(t,e){this.schema=t;this.rules=e;this.tags=[];this.styles=[];let i=this.matchedStyles=[];e.forEach((t=>{if(ot(t)){this.tags.push(t)}else if(lt(t)){let e=/[^=]*/.exec(t.style)[0];if(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 false;let i=t.nodes[e.node];return i.contentMatch.matchType(i)}))}parse(t,e={}){let i=new mt(this,e,false);i.addAll(t,a.none,e.from,e.to);return i.finish()}parseSlice(t,e={}){let i=new mt(this,e,true);i.addAll(t,a.none,e.from,e.to);return 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(bt(t,i.tag)&&(i.namespace===undefined||t.namespaceURI==i.namespace)&&(!i.context||e.matchesContext(i.context))){if(i.getAttrs){let e=i.getAttrs(t);if(e===false)continue;i.attrs=e||undefined}return i}}}matchStyle(t,e,i,s){for(let n=s?this.styles.indexOf(s)+1:0;n<this.styles.length;n++){let s=this.styles[n],r=s.style;if(r.indexOf(t)!=0||s.context&&!i.matchesContext(s.context)||r.length>t.length&&(r.charCodeAt(t.length)!=61||r.slice(t.length+1)!=e))continue;if(s.getAttrs){let t=s.getAttrs(e);if(t===false)continue;s.attrs=t||undefined}return s}}static schemaRules(t){let e=[];function i(t){let i=t.priority==null?50:t.priority,s=0;for(;s<e.length;s++){let t=e[s],n=t.priority==null?50:t.priority;if(n<i)break}e.splice(s,0,t)}for(let e in t.marks){let s=t.marks[e].spec.parseDOM;if(s)s.forEach((t=>{i(t=vt(t));if(!(t.mark||t.ignore||t.clearMark))t.mark=e}))}for(let e in t.nodes){let s=t.nodes[e].spec.parseDOM;if(s)s.forEach((t=>{i(t=vt(t));if(!(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 ft={address:true,article:true,aside:true,blockquote:true,canvas:true,dd:true,div:true,dl:true,fieldset:true,figcaption:true,figure:true,footer:true,form:true,h1:true,h2:true,h3:true,h4:true,h5:true,h6:true,header:true,hgroup:true,hr:true,li:true,noscript:true,ol:true,output:true,p:true,pre:true,section:true,table:true,tfoot:true,ul:true};const ut={head:true,noscript:true,object:true,script:true,style:true,title:true};const ct={ol:true,ul:true};const at=1,dt=2,wt=4;function pt(t,e,i){if(e!=null)return(e?at:0)|(e==="full"?dt:0);return t&&t.whitespace=="pre"?at|dt:i&-5}class gt{constructor(t,e,i,s,n,r){this.type=t;this.attrs=e;this.marks=i;this.solid=s;this.options=r;this.content=[];this.activeMarks=a.none;this.match=n||(r&wt?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let e=this.type.contentMatch.fillBefore(h.from(t));if(e){this.match=this.type.contentMatch.matchFragment(e)}else{let e=this.type.contentMatch,i;if(i=e.findWrapping(t.type)){this.match=e;return i}else{return null}}}return this.match.findWrapping(t.type)}finish(t){if(!(this.options&at)){let t=this.content[this.content.length-1],e;if(t&&t.isText&&(e=/[ \t\r\n\u000c]+$/.exec(t.text))){let i=t;if(t.text.length==e[0].length)this.content.pop();else this.content[this.content.length-1]=i.withText(i.text.slice(0,i.text.length-e[0].length))}}let e=h.from(this.content);if(!t&&this.match)e=e.append(this.match.fillBefore(h.empty,true));return this.type?this.type.create(this.attrs,e,this.marks):e}inlineContext(t){if(this.type)return this.type.inlineContent;if(this.content.length)return this.content[0].isInline;return t.parentNode&&!ft.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class mt{constructor(t,e,i){this.parser=t;this.options=e;this.isOpen=i;this.open=0;this.localPreserveWS=false;let s=e.topNode,n;let r=pt(null,e.preserveWhitespace,0)|(i?wt:0);if(s)n=new gt(s.type,s.attrs,a.none,true,e.topMatch||s.type.contentMatch,r);else if(i)n=new gt(null,null,a.none,true,null,r);else n=new gt(t.schema.topNodeType,null,a.none,true,null,r);this.nodes=[n];this.find=e.findPositions;this.needsBlock=false}get top(){return this.nodes[this.open]}addDOM(t,e){if(t.nodeType==3)this.addTextNode(t,e);else if(t.nodeType==1)this.addElement(t,e)}addTextNode(t,e){let i=t.nodeValue;let s=this.top,n=s.options&dt?"full":this.localPreserveWS||(s.options&at)>0;let{schema:r}=this.parser;if(n==="full"||s.inlineContext(t)||/[^ \t\r\n\u000c]/.test(i)){if(!n){i=i.replace(/[ \t\r\n\u000c]+/g," ");if(/^[ \t\r\n\u000c]/.test(i)&&this.open==this.nodes.length-1){let e=s.content[s.content.length-1];let n=t.previousSibling;if(!e||n&&n.nodeName=="BR"||e.isText&&/[ \t\r\n\u000c]$/.test(e.text))i=i.slice(1)}}else if(n==="full"){i=i.replace(/\r\n?/g,"\n")}else if(r.linebreakReplacement&&/[\r\n]/.test(i)&&this.top.findWrapping(r.linebreakReplacement.create())){let t=i.split(/\r?\n|\r/);for(let i=0;i<t.length;i++){if(i)this.insertNode(r.linebreakReplacement.create(),e,true);if(t[i])this.insertNode(r.text(t[i]),e,!/\S/.test(t[i]))}i=""}else{i=i.replace(/\r?\n|\r/g," ")}if(i)this.insertNode(r.text(i),e,!/\S/.test(i));this.findInText(t)}else{this.findInside(t)}}addElement(t,e,i){let s=this.localPreserveWS,n=this.top;if(t.tagName=="PRE"||/pre/.test(t.style&&t.style.whiteSpace))this.localPreserveWS=true;let r=t.nodeName.toLowerCase(),o;if(ct.hasOwnProperty(r)&&this.parser.normalizeLists)yt(t);let l=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(o=this.parser.matchTag(t,this,i));t:if(l?l.ignore:ut.hasOwnProperty(r)){this.findInside(t);this.ignoreFallback(t,e)}else if(!l||l.skip||l.closeParent){if(l&&l.closeParent)this.open=Math.max(0,this.open-1);else if(l&&l.skip.nodeType)t=l.skip;let i,s=this.needsBlock;if(ft.hasOwnProperty(r)){if(n.content.length&&n.content[0].isInline&&this.open){this.open--;n=this.top}i=true;if(!n.type)this.needsBlock=true}else if(!t.firstChild){this.leafFallback(t,e);break t}let o=l&&l.skip?e:this.readStyles(t,e);if(o)this.addAll(t,o);if(i)this.sync(n);this.needsBlock=s}else{let i=this.readStyles(t,e);if(i)this.addElementByRule(t,l,i,l.consuming===false?o:undefined)}this.localPreserveWS=s}leafFallback(t,e){if(t.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent)this.addTextNode(t.ownerDocument.createTextNode("\n"),e)}ignoreFallback(t,e){if(t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent))this.findPlace(this.parser.schema.text("-"),e,true)}readStyles(t,e){let i=t.style;if(i&&i.length)for(let t=0;t<this.parser.matchedStyles.length;t++){let s=this.parser.matchedStyles[t],n=i.getPropertyValue(s);if(n)for(let t=undefined;;){let i=this.parser.matchStyle(s,n,this,t);if(!i)break;if(i.ignore)return null;if(i.clearMark)e=e.filter((t=>!i.clearMark(t)));else e=e.concat(this.parser.schema.marks[i.mark].create(i.attrs));if(i.consuming===false)t=i;else break}}return e}addElementByRule(t,e,i,s){let n,r;if(e.node){r=this.parser.schema.nodes[e.node];if(!r.isLeaf){let t=this.enter(r,e.attrs||null,i,e.preserveWhitespace);if(t){n=true;i=t}}else if(!this.insertNode(r.create(e.attrs),i,t.nodeName=="BR")){this.leafFallback(t,i)}}else{let t=this.parser.schema.marks[e.mark];i=i.concat(t.create(e.attrs))}let o=this.top;if(r&&r.isLeaf){this.findInside(t)}else if(s){this.addElement(t,i,s)}else if(e.getContent){this.findInside(t);e.getContent(t,this.parser.schema).forEach((t=>this.insertNode(t,i,false)))}else{let s=t;if(typeof e.contentElement=="string")s=t.querySelector(e.contentElement);else if(typeof e.contentElement=="function")s=e.contentElement(t);else if(e.contentElement)s=e.contentElement;this.findAround(t,s,true);this.addAll(s,i);this.findAround(t,s,false)}if(n&&this.sync(o))this.open--}addAll(t,e,i,s){let n=i||0;for(let r=i?t.childNodes[i]:t.firstChild,o=s==null?null:t.childNodes[s];r!=o;r=r.nextSibling,++n){this.findAtPoint(t,n);this.addDOM(r,e)}this.findAtPoint(t,n)}findPlace(t,e,i){let s,n;for(let e=this.open,r=0;e>=0;e--){let o=this.nodes[e];let l=o.findWrapping(t);if(l&&(!s||s.length>l.length+r)){s=l;n=o;if(!l.length)break}if(o.solid){if(i)break;r+=2}}if(!s)return null;this.sync(n);for(let t=0;t<s.length;t++)e=this.enterInner(s[t],null,e,false);return e}insertNode(t,e,i){if(t.isInline&&this.needsBlock&&!this.top.type){let t=this.textblockFromContext();if(t)e=this.enterInner(t,null,e)}let s=this.findPlace(t,e,i);if(s){this.closeExtra();let e=this.top;if(e.match)e.match=e.match.matchType(t.type);let i=a.none;for(let n of s.concat(t.marks))if(e.type?e.type.allowsMarkType(n.type):At(n.type,t.type))i=n.addToSet(i);e.content.push(t.mark(i));return true}return false}enter(t,e,i,s){let n=this.findPlace(t.create(e),i,false);if(n)n=this.enterInner(t,e,i,true,s);return n}enterInner(t,e,i,s=false,n){this.closeExtra();let r=this.top;r.match=r.match&&r.match.matchType(t);let o=pt(t,n,r.options);if(r.options&wt&&r.content.length==0)o|=wt;let l=a.none;i=i.filter((e=>{if(r.type?r.type.allowsMarkType(e.type):At(e.type,t)){l=e.addToSet(l);return false}return true}));this.nodes.push(new gt(t,e,l,s,null,o));this.open++;return i}closeExtra(t=false){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(){this.open=0;this.closeExtra(this.isOpen);return this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(t){for(let e=this.open;e>=0;e--){if(this.nodes[e]==t){this.open=e;return true}else if(this.localPreserveWS){this.nodes[e].options|=at}}return false}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;if(e)t++}return t}findAtPoint(t,e){if(this.find)for(let i=0;i<this.find.length;i++){if(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++){if(this.find[e].pos==null&&t.nodeType==1&&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++){if(this.find[s].pos==null&&t.nodeType==1&&t.contains(this.find[s].node)){let t=e.compareDocumentPosition(this.find[s].node);if(t&(i?2:4))this.find[s].pos=this.currentPos}}}findInText(t){if(this.find)for(let e=0;e<this.find.length;e++){if(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("/");let i=this.options.context;let s=!this.isOpen&&(!i||i.parent.type==this.nodes[0].type);let n=-(i?i.depth+1:0)+(s?0:1);let r=(t,o)=>{for(;t>=0;t--){let l=e[t];if(l==""){if(t==e.length-1||t==0)continue;for(;o>=n;o--)if(r(t-1,o))return true;return false}else{let t=o>0||o==0&&s?this.nodes[o].type:i&&o>=n?i.node(o-n).type:null;if(!t||t.name!=l&&!t.isInGroup(l))return false;o--}}return true};return r(e.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let e=t.depth;e>=0;e--){let i=t.node(e).contentMatchAt(t.indexAfter(e)).defaultType;if(i&&i.isTextblock&&i.defaultAttrs)return i}for(let t in this.parser.schema.nodes){let e=this.parser.schema.nodes[t];if(e.isTextblock&&e.defaultAttrs)return e}}}function yt(t){for(let e=t.firstChild,i=null;e;e=e.nextSibling){let t=e.nodeType==1?e.nodeName.toLowerCase():null;if(t&&ct.hasOwnProperty(t)&&i){i.appendChild(e);e=i}else if(t=="li"){i=e}else if(t){i=null}}}function bt(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function vt(t){let e={};for(let i in t)e[i]=t[i];return e}function At(t,e){let i=e.schema.nodes;for(let s in i){let n=i[s];if(!n.allowsMarkType(t))continue;let r=[],o=t=>{r.push(t);for(let i=0;i<t.edgeCount;i++){let{type:s,next:n}=t.edge(i);if(s==e)return true;if(r.indexOf(n)<0&&o(n))return true}};if(o(n.contentMatch))return true}}class Mt{constructor(t,e){this.nodes=t;this.marks=e}serializeFragment(t,e={},i){if(!i)i=St(e).createDocumentFragment();let s=i,n=[];t.forEach((t=>{if(n.length||t.marks.length){let i=0,r=0;while(i<n.length&&r<t.marks.length){let e=t.marks[r];if(!this.marks[e.type.name]){r++;continue}if(!e.eq(n[i][0])||e.type.spec.spanning===false)break;i++;r++}while(i<n.length)s=n.pop()[1];while(r<t.marks.length){let i=t.marks[r++];let o=this.serializeMark(i,t.isInline,e);if(o){n.push([i,s]);s.appendChild(o.dom);s=o.contentDOM||o.dom}}}s.appendChild(this.serializeNodeInner(t,e))}));return i}serializeNodeInner(t,e){let{dom:i,contentDOM:s}=Dt(St(e),this.nodes[t.type.name](t),null,t.attrs);if(s){if(t.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(t.content,e,s)}return i}serializeNode(t,e={}){let i=this.serializeNodeInner(t,e);for(let s=t.marks.length-1;s>=0;s--){let n=this.serializeMark(t.marks[s],t.isInline,e);if(n){(n.contentDOM||n.dom).appendChild(i);i=n.dom}}return i}serializeMark(t,e,i={}){let s=this.marks[t.type.name];return s&&Dt(St(i),s(t,e),null,t.attrs)}static renderSpec(t,e,i=null,s){return Dt(t,e,i,s)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new Mt(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(t){let e=kt(t.nodes);if(!e.text)e.text=t=>t.text;return e}static marksFromSchema(t){return kt(t.marks)}}function kt(t){let e={};for(let i in t){let s=t[i].spec.toDOM;if(s)e[i]=s}return e}function St(t){return t.document||window.document}const xt=new WeakMap;function Ot(t){let e=xt.get(t);if(e===undefined)xt.set(t,e=Et(t));return e}function Et(t){let e=null;function i(t){if(t&&typeof t=="object"){if(Array.isArray(t)){if(typeof t[0]=="string"){if(!e)e=[];e.push(t)}else{for(let e=0;e<t.length;e++)i(t[e])}}else{for(let e in t)i(t[e])}}}i(t);return e}function Dt(t,e,i,s){if(typeof e=="string")return{dom:t.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let n=e[0],r;if(typeof n!="string")throw new RangeError("Invalid array passed to renderSpec");if(s&&(r=Ot(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=n.indexOf(" ");if(o>0){i=n.slice(0,o);n=n.slice(o+1)}let l;let h=i?t.createElementNS(i,n):t.createElement(n);let f=e[1],u=1;if(f&&typeof f=="object"&&f.nodeType==null&&!Array.isArray(f)){u=2;for(let t in f)if(f[t]!=null){let e=t.indexOf(" ");if(e>0)h.setAttributeNS(t.slice(0,e),t.slice(e+1),f[t]);else if(t=="style"&&h.style)h.style.cssText=f[t];else h.setAttribute(t,f[t])}}for(let n=u;n<e.length;n++){let r=e[n];if(r===0){if(n<e.length-1||n>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:h,contentDOM:h}}else{let{dom:e,contentDOM:n}=Dt(t,r,i,s);h.appendChild(e);if(n){if(l)throw new RangeError("Multiple content holes");l=n}}}return{dom:h,contentDOM:l}}const Tt=65535;const Ct=Math.pow(2,16);function Rt(t,e){return t+e*Ct}function Ut(t){return t&Tt}function It(t){return(t-(t&Tt))/Ct}const Nt=1,Pt=2,Ft=4,Bt=8;class jt{constructor(t,e,i){this.pos=t;this.delInfo=e;this.recover=i}get deleted(){return(this.delInfo&Bt)>0}get deletedBefore(){return(this.delInfo&(Nt|Ft))>0}get deletedAfter(){return(this.delInfo&(Pt|Ft))>0}get deletedAcross(){return(this.delInfo&Ft)>0}}class _t{constructor(t,e=false){this.ranges=t;this.inverted=e;if(!t.length&&_t.empty)return _t.empty}recover(t){let e=0,i=Ut(t);if(!this.inverted)for(let t=0;t<i;t++)e+=this.ranges[t*3+2]-this.ranges[t*3+1];return this.ranges[i*3]+e+It(t)}mapResult(t,e=1){return this._map(t,e,false)}map(t,e=1){return this._map(t,e,true)}_map(t,e,i){let s=0,n=this.inverted?2:1,r=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let l=this.ranges[o]-(this.inverted?s:0);if(l>t)break;let h=this.ranges[o+n],f=this.ranges[o+r],u=l+h;if(t<=u){let n=!h?e:t==l?-1:t==u?1:e;let r=l+s+(n<0?0:f);if(i)return r;let c=t==(e<0?l:u)?null:Rt(o/3,t-l);let a=t==l?Pt:t==u?Nt:Ft;if(e<0?t!=l:t!=u)a|=Bt;return new jt(r,a,c)}s+=f-h}return i?t+s:new jt(t+s,0,null)}touches(t,e){let i=0,s=Ut(e);let n=this.inverted?2:1,r=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 l=this.ranges[e+n],h=o+l;if(t<=h&&e==s*3)return true;i+=this.ranges[e+r]-l}return false}forEach(t){let e=this.inverted?2:1,i=this.inverted?1:2;for(let s=0,n=0;s<this.ranges.length;s+=3){let r=this.ranges[s],o=r-(this.inverted?n:0),l=r+(this.inverted?0:n);let h=this.ranges[s+e],f=this.ranges[s+i];t(o,o+h,l,l+f);n+=f-h}}invert(){return new _t(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return t==0?_t.empty:new _t(t<0?[0,-t,0]:[0,0,t])}}_t.empty=new _t([]);class $t{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 $t(this._maps,this.mirror,t,e)}appendMap(t,e){if(!this.ownData){this._maps=this._maps.slice();this.mirror=this.mirror&&this.mirror.slice();this.ownData=true}this.to=this._maps.push(t);if(e!=null)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],s!=null&&s<e?i+s:undefined)}}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){if(!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(),s!=null&&s>e?i-s-1:undefined)}}invert(){let t=new $t;t.appendMappingInverted(this);return t}map(t,e=1){if(this.mirror)return this._map(t,e,true);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,false)}_map(t,e,i){let s=0;for(let i=this.from;i<this.to;i++){let n=this._maps[i],r=n.mapResult(t,e);if(r.recover!=null){let e=this.getMirror(i);if(e!=null&&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 jt(t,s,null)}}const Lt=Object.create(null);class zt{getMap(){return _t.empty}merge(t){return null}static fromJSON(t,e){if(!e||!e.stepType)throw new RangeError("Invalid input for Step.fromJSON");let i=Lt[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 Lt)throw new RangeError("Duplicate use of step JSON ID "+t);Lt[t]=e;e.prototype.jsonID=t;return e}}class Jt{constructor(t,e){this.doc=t;this.failed=e}static ok(t){return new Jt(t,null)}static fail(t){return new Jt(null,t)}static fromReplace(t,e,i,s){try{return Jt.ok(t.replace(e,i,s))}catch(t){if(t instanceof d)return Jt.fail(t.message);throw t}}}function Wt(t,e,i){let s=[];for(let n=0;n<t.childCount;n++){let r=t.child(n);if(r.content.size)r=r.copy(Wt(r.content,e,r));if(r.isInline)r=e(r,i,n);s.push(r)}return h.fromArray(s)}class Qt extends zt{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);let s=i.node(i.sharedDepth(this.to));let n=new w(Wt(e.content,((t,e)=>{if(!t.isAtom||!e.type.allowsMarkType(this.mark.type))return t;return t.mark(this.mark.addToSet(t.marks))}),s),e.openStart,e.openEnd);return Jt.fromReplace(t,this.from,this.to,n)}invert(){return new Ht(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);if(e.deleted&&i.deleted||e.pos>=i.pos)return null;return new Qt(e.pos,i.pos,this.mark)}merge(t){if(t instanceof Qt&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from)return new Qt(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark);return null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if(typeof e.from!="number"||typeof e.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Qt(e.from,e.to,t.markFromJSON(e.mark))}}zt.jsonID("addMark",Qt);class Ht extends zt{constructor(t,e,i){super();this.from=t;this.to=e;this.mark=i}apply(t){let e=t.slice(this.from,this.to);let i=new w(Wt(e.content,(t=>t.mark(this.mark.removeFromSet(t.marks))),t),e.openStart,e.openEnd);return Jt.fromReplace(t,this.from,this.to,i)}invert(){return new Qt(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),i=t.mapResult(this.to,-1);if(e.deleted&&i.deleted||e.pos>=i.pos)return null;return new Ht(e.pos,i.pos,this.mark)}merge(t){if(t instanceof Ht&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from)return new Ht(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark);return null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if(typeof e.from!="number"||typeof e.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Ht(e.from,e.to,t.markFromJSON(e.mark))}}zt.jsonID("removeMark",Ht);class qt extends zt{constructor(t,e){super();this.pos=t;this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return Jt.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.addToSet(e.marks));return Jt.fromReplace(t,this.pos,this.pos+1,new w(h.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 qt(this.pos,e.marks[i]);return new qt(this.pos,this.mark)}}return new Vt(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new qt(e.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if(typeof e.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new qt(e.pos,t.markFromJSON(e.mark))}}zt.jsonID("addNodeMark",qt);class Vt extends zt{constructor(t,e){super();this.pos=t;this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return Jt.fail("No node at mark step's position");let i=e.type.create(e.attrs,null,this.mark.removeFromSet(e.marks));return Jt.fromReplace(t,this.pos,this.pos+1,new w(h.from(i),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);if(!e||!this.mark.isInSet(e.marks))return this;return new qt(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new Vt(e.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if(typeof e.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Vt(e.pos,t.markFromJSON(e.mark))}}zt.jsonID("removeNodeMark",Vt);class Kt extends zt{constructor(t,e,i,s=false){super();this.from=t;this.to=e;this.slice=i;this.structure=s}apply(t){if(this.structure&&Xt(t,this.from,this.to))return Jt.fail("Structure replace would overwrite content");return Jt.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new _t([this.from,this.to-this.from,this.slice.size])}invert(t){return new Kt(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);if(e.deletedAcross&&i.deletedAcross)return null;return new Kt(e.pos,Math.max(e.pos,i.pos),this.slice,this.structure)}merge(t){if(!(t instanceof Kt)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){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 Kt(this.from,this.to+(t.to-t.from),e,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){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 Kt(t.from,this.to,e,this.structure)}else{return null}}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};if(this.slice.size)t.slice=this.slice.toJSON();if(this.structure)t.structure=true;return t}static fromJSON(t,e){if(typeof e.from!="number"||typeof e.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Kt(e.from,e.to,w.fromJSON(t,e.slice),!!e.structure)}}zt.jsonID("replace",Kt);class Yt extends zt{constructor(t,e,i,s,n,r,o=false){super();this.from=t;this.to=e;this.gapFrom=i;this.gapTo=s;this.slice=n;this.insert=r;this.structure=o}apply(t){if(this.structure&&(Xt(t,this.from,this.gapFrom)||Xt(t,this.gapTo,this.to)))return Jt.fail("Structure gap-replace would overwrite content");let e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return Jt.fail("Gap is not a flat range");let i=this.slice.insertAt(this.insert,e.content);if(!i)return Jt.fail("Content does not fit in gap");return Jt.fromReplace(t,this.from,this.to,i)}getMap(){return new _t([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 Yt(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);let s=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1);let n=this.to==this.gapTo?i.pos:t.map(this.gapTo,1);if(e.deletedAcross&&i.deletedAcross||s<e.pos||n>i.pos)return null;return new Yt(e.pos,i.pos,s,n,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};if(this.slice.size)t.slice=this.slice.toJSON();if(this.structure)t.structure=true;return t}static fromJSON(t,e){if(typeof e.from!="number"||typeof e.to!="number"||typeof e.gapFrom!="number"||typeof e.gapTo!="number"||typeof e.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Yt(e.from,e.to,e.gapFrom,e.gapTo,w.fromJSON(t,e.slice),e.insert,!!e.structure)}}zt.jsonID("replaceAround",Yt);function Xt(t,e,i){let s=t.resolve(e),n=i-e,r=s.depth;while(n>0&&r>0&&s.indexAfter(r)==s.node(r).childCount){r--;n--}if(n>0){let t=s.node(r).maybeChild(s.indexAfter(r));while(n>0){if(!t||t.isLeaf)return true;t=t.firstChild;n--}}return false}function Gt(t,e,i,s){let n=[],r=[];let o,l;t.doc.nodesBetween(e,i,((t,h,f)=>{if(!t.isInline)return;let u=t.marks;if(!s.isInSet(u)&&f.type.allowsMarkType(s.type)){let f=Math.max(h,e),c=Math.min(h+t.nodeSize,i);let a=s.addToSet(u);for(let t=0;t<u.length;t++){if(!u[t].isInSet(a)){if(o&&o.to==f&&o.mark.eq(u[t]))o.to=c;else n.push(o=new Ht(f,c,u[t]))}}if(l&&l.to==f)l.to=c;else r.push(l=new Qt(f,c,s))}}));n.forEach((e=>t.step(e)));r.forEach((e=>t.step(e)))}function Zt(t,e,i,s){let n=[],r=0;t.doc.nodesBetween(e,i,((t,o)=>{if(!t.isInline)return;r++;let l=null;if(s instanceof st){let e=t.marks,i;while(i=s.isInSet(e)){(l||(l=[])).push(i);e=i.removeFromSet(e)}}else if(s){if(s.isInSet(t.marks))l=[s]}else{l=t.marks}if(l&&l.length){let s=Math.min(o+t.nodeSize,i);for(let t=0;t<l.length;t++){let i=l[t],h;for(let t=0;t<n.length;t++){let e=n[t];if(e.step==r-1&&i.eq(n[t].style))h=e}if(h){h.to=s;h.step=r}else{n.push({style:i,from:Math.max(o,e),to:s,step:r})}}}}));n.forEach((e=>t.step(new Ht(e.from,e.to,e.style))))}function te(t,e,i,s=i.contentMatch,n=true){let r=t.doc.nodeAt(e);let o=[],l=e+1;for(let e=0;e<r.childCount;e++){let f=r.child(e),u=l+f.nodeSize;let c=s.matchType(f.type);if(!c){o.push(new Kt(l,u,w.empty))}else{s=c;for(let e=0;e<f.marks.length;e++)if(!i.allowsMarkType(f.marks[e].type))t.step(new Ht(l,u,f.marks[e]));if(n&&f.isText&&i.whitespace!="pre"){let t,e=/\r?\n|\r/g,s;while(t=e.exec(f.text)){if(!s)s=new w(h.from(i.schema.text(" ",i.allowedMarks(f.marks))),0,0);o.push(new Kt(l+t.index,l+t.index+t[0].length,s))}}}l=u}if(!s.validEnd){let e=s.fillBefore(h.empty,true);t.replace(l,l,new w(e,0,0))}for(let e=o.length-1;e>=0;e--)t.step(o[e])}function ee(t,e,i){return(e==0||t.canReplace(e,t.childCount))&&(i==t.childCount||t.canReplace(0,i))}function ie(t){let e=t.parent;let i=e.content.cutByIndex(t.startIndex,t.endIndex);for(let e=t.depth,s=0,n=0;;--e){let r=t.$from.node(e);let o=t.$from.index(e)+s,l=t.$to.indexAfter(e)-n;if(e<t.depth&&r.canReplace(o,l,i))return e;if(e==0||r.type.spec.isolating||!ee(r,o,l))break;if(o)s=1;if(l<r.childCount)n=1}return null}function se(t,e,i){let{$from:s,$to:n,depth:r}=e;let o=s.before(r+1),l=n.after(r+1);let f=o,u=l;let c=h.empty,a=0;for(let t=r,e=false;t>i;t--)if(e||s.index(t)>0){e=true;c=h.from(s.node(t).copy(c));a++}else{f--}let d=h.empty,p=0;for(let t=r,e=false;t>i;t--)if(e||n.after(t+1)<n.end(t)){e=true;d=h.from(n.node(t).copy(d));p++}else{u++}t.step(new Yt(f,u,o,l,new w(c.append(d),a,p),c.size-a,true))}function ne(t,e,i){let s=h.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=h.from(i[t].type.create(i[t].attrs,s))}let n=e.start,r=e.end;t.step(new Yt(n,r,n,r,new w(s,0,0),i.length,true))}function re(t,e,i,s,n){if(!s.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let r=t.steps.length;t.doc.nodesBetween(e,i,((e,i)=>{let o=typeof n=="function"?n(e):n;if(e.isTextblock&&!e.hasMarkup(s,o)&&he(t.doc,t.mapping.slice(r).map(i),s)){let n=null;if(s.schema.linebreakReplacement){let t=s.whitespace=="pre",e=!!s.contentMatch.matchType(s.schema.linebreakReplacement);if(t&&!e)n=false;else if(!t&&e)n=true}if(n===false)le(t,e,i,r);te(t,t.mapping.slice(r).map(i,1),s,undefined,n===null);let l=t.mapping.slice(r);let f=l.map(i,1),u=l.map(i+e.nodeSize,1);t.step(new Yt(f,u,f+1,u-1,new w(h.from(s.create(o,null,e.marks)),0,0),1,true));if(n===true)oe(t,e,i,r);return false}}))}function oe(t,e,i,s){e.forEach(((n,r)=>{if(n.isText){let o,l=/\r?\n|\r/g;while(o=l.exec(n.text)){let n=t.mapping.slice(s).map(i+1+r+o.index);t.replaceWith(n,n+1,e.type.schema.linebreakReplacement.create())}}}))}function le(t,e,i,s){e.forEach(((n,r)=>{if(n.type==n.type.schema.linebreakReplacement){let n=t.mapping.slice(s).map(i+1+r);t.replaceWith(n,n+1,e.type.schema.text("\n"))}}))}function he(t,e,i){let s=t.resolve(e),n=s.index();return s.parent.canReplaceWith(n,n+1,i)}function fe(t,e,i,s,n){let r=t.doc.nodeAt(e);if(!r)throw new RangeError("No node at given position");if(!i)i=r.type;let o=i.create(s,null,n||r.marks);if(r.isLeaf)return t.replaceWith(e,e+r.nodeSize,o);if(!i.validContent(r.content))throw new RangeError("Invalid content for node type "+i.name);t.step(new Yt(e,e+r.nodeSize,e+1,e+r.nodeSize-1,new w(h.from(o),0,0),1,true))}function ue(t,e,i=1,s){let n=t.resolve(e),r=n.depth-i;let o=s&&s[s.length-1]||n.parent;if(r<0||n.parent.type.spec.isolating||!n.parent.canReplace(n.index(),n.parent.childCount)||!o.type.validContent(n.parent.content.cutByIndex(n.index(),n.parent.childCount)))return false;for(let t=n.depth-1,e=i-2;t>r;t--,e--){let i=n.node(t),r=n.index(t);if(i.type.spec.isolating)return false;let o=i.content.cutByIndex(r,i.childCount);let l=s&&s[e+1];if(l)o=o.replaceChild(0,l.type.create(l.attrs));let h=s&&s[e]||i;if(!i.canReplace(r+1,i.childCount)||!h.type.validContent(o))return false}let l=n.indexAfter(r);let h=s&&s[0];return n.node(r).canReplaceWith(l,l,h?h.type:n.node(r+1).type)}function ce(t,e,i=1,s){let n=t.doc.resolve(e),r=h.empty,o=h.empty;for(let t=n.depth,e=n.depth-i,l=i-1;t>e;t--,l--){r=h.from(n.node(t).copy(r));let e=s&&s[l];o=h.from(e?e.type.create(e.attrs,o):n.node(t).copy(o))}t.step(new Kt(e,e,new w(r.append(o),i,i),true))}function ae(t,e){let i=t.resolve(e),s=i.index();return we(i.nodeBefore,i.nodeAfter)&&i.parent.canReplace(s,s+1)}function de(t,e){if(!e.content.size)t.type.compatibleContent(e.type);let i=t.contentMatchAt(t.childCount);let{linebreakReplacement:s}=t.type.schema;for(let n=0;n<e.childCount;n++){let r=e.child(n);let o=r.type==s?t.type.schema.nodes.text:r.type;i=i.matchType(o);if(!i)return false;if(!t.type.allowsMarks(r.marks))return false}return i.validEnd}function we(t,e){return!!(t&&e&&!t.isLeaf&&de(t,e))}function pe(t,e,i){let s=null;let{linebreakReplacement:n}=t.doc.type.schema;let r=t.doc.resolve(e-i),o=r.node().type;if(n&&o.inlineContent){let t=o.whitespace=="pre";let e=!!o.contentMatch.matchType(n);if(t&&!e)s=false;else if(!t&&e)s=true}let l=t.steps.length;if(s===false){let s=t.doc.resolve(e+i);le(t,s.node(),s.before(),l)}if(o.inlineContent)te(t,e+i-1,o,r.node().contentMatchAt(r.index()),s==null);let h=t.mapping.slice(l),f=h.map(e-i);t.step(new Kt(f,h.map(e+i,-1),w.empty,true));if(s===true){let e=t.doc.resolve(f);oe(t,e.node(),e.before(),t.steps.length)}return t}function ge(t,e,i){let s=t.resolve(e);if(s.parent.canReplaceWith(s.index(),s.index(),i))return e;if(s.parentOffset==0)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}function me(t,e,i){let s=t.resolve(e);if(!i.content.size)return e;let n=i.content;for(let t=0;t<i.openStart;t++)n=n.firstChild.content;for(let t=1;t<=(i.openStart==0&&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;let r=s.index(e)+(i>0?1:0);let o=s.node(e),l=false;if(t==1){l=o.canReplace(r,r,n)}else{let t=o.contentMatchAt(r).findWrapping(n.firstChild.type);l=t&&o.canReplaceWith(r,r,t[0])}if(l)return i==0?s.pos:i<0?s.before(e+1):s.after(e+1)}}return null}function ye(t,e,i=e,s=w.empty){if(e==i&&!s.size)return null;let n=t.resolve(e),r=t.resolve(i);if(be(n,r,s))return new Kt(e,i,s);return new ve(n,r,s).fit()}function be(t,e,i){return!i.openStart&&!i.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),i.content)}class ve{constructor(t,e,i){this.$from=t;this.$to=e;this.unplaced=i;this.frontier=[];this.placed=h.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=h.from(t.node(e).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){while(this.unplaced.size){let t=this.findFittable();if(t)this.placeNodes(t);else this.openMore()||this.dropNode()}let t=this.mustMoveInline(),e=this.placed.size-this.depth-this.$from.depth;let i=this.$from,s=this.close(t<0?this.$to:i.doc.resolve(t));if(!s)return null;let n=this.placed,r=i.depth,o=s.depth;while(r&&o&&n.childCount==1){n=n.firstChild.content;r--;o--}let l=new w(n,r,o);if(t>-1)return new Yt(i.pos,t,this.$to.pos,this.$to.end(),l,e);if(l.size||i.pos!=this.$to.pos)return new Kt(i.pos,s.pos,l);return null}findFittable(){let t=this.unplaced.openStart;for(let e=this.unplaced.content,i=0,s=this.unplaced.openEnd;i<t;i++){let n=e.firstChild;if(e.childCount>1)s=0;if(n.type.spec.isolating&&s<=i){t=i;break}e=n.content}for(let e=1;e<=2;e++){for(let i=e==1?t:this.unplaced.openStart;i>=0;i--){let t,s=null;if(i){s=ke(this.unplaced.content,i-1).firstChild;t=s.content}else{t=this.unplaced.content}let n=t.firstChild;for(let t=this.depth;t>=0;t--){let{type:r,match:o}=this.frontier[t],l,f=null;if(e==1&&(n?o.matchType(n.type)||(f=o.fillBefore(h.from(n),false)):s&&r.compatibleContent(s.type)))return{sliceDepth:i,frontierDepth:t,parent:s,inject:f};else if(e==2&&n&&(l=o.findWrapping(n.type)))return{sliceDepth:i,frontierDepth:t,parent:s,wrap:l};if(s&&o.matchType(s.type))break}}}}openMore(){let{content:t,openStart:e,openEnd:i}=this.unplaced;let s=ke(t,e);if(!s.childCount||s.firstChild.isLeaf)return false;this.unplaced=new w(t,e+1,Math.max(i,s.size+e>=t.size-i?e+1:0));return true}dropNode(){let{content:t,openStart:e,openEnd:i}=this.unplaced;let s=ke(t,e);if(s.childCount<=1&&e>0){let n=t.size-e<=e+s.size;this.unplaced=new w(Ae(t,e-1,1),e-1,n?e-1:i)}else{this.unplaced=new w(Ae(t,e,1),e,i)}}placeNodes({sliceDepth:t,frontierDepth:e,parent:i,inject:s,wrap:n}){while(this.depth>e)this.closeFrontierNode();if(n)for(let t=0;t<n.length;t++)this.openFrontierNode(n[t]);let r=this.unplaced,o=i?i.content:r.content;let l=r.openStart-t;let f=0,u=[];let{match:c,type:a}=this.frontier[e];if(s){for(let t=0;t<s.childCount;t++)u.push(s.child(t));c=c.matchFragment(s)}let d=o.size+t-(r.content.size-r.openEnd);while(f<o.childCount){let t=o.child(f),e=c.matchType(t.type);if(!e)break;f++;if(f>1||l==0||t.content.size){c=e;u.push(Se(t.mark(a.allowedMarks(t.marks)),f==1?l:0,f==o.childCount?d:-1))}}let p=f==o.childCount;if(!p)d=-1;this.placed=Me(this.placed,e,h.from(u));this.frontier[e].match=c;if(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?new w(Ae(r.content,t,f),r.openStart,r.openEnd):t==0?w.empty:new w(Ae(r.content,t-1,1),t-1,d<0?r.openEnd:t-1)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let t=this.frontier[this.depth],e;if(!t.type.isTextblock||!xe(this.$to,this.$to.depth,t.type,t.match,false)||this.$to.depth==this.depth&&(e=this.findCloseLevel(this.$to))&&e.depth==this.depth)return-1;let{depth:i}=this.$to,s=this.$to.after(i);while(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];let n=e<t.depth&&t.end(e+1)==t.pos+(t.depth-(e+1));let r=xe(t,e,s,i,n);if(!r)continue;for(let i=e-1;i>=0;i--){let{match:e,type:s}=this.frontier[i];let n=xe(t,i,s,e,true);if(!n||n.childCount)continue t}return{depth:e,fit:r,move:n?t.doc.resolve(t.after(e+1)):t}}}close(t){let e=this.findCloseLevel(t);if(!e)return null;while(this.depth>e.depth)this.closeFrontierNode();if(e.fit.childCount)this.placed=Me(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,true,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=Me(this.placed,this.depth,h.from(t.create(e,i)));this.frontier.push({type:t,match:t.contentMatch})}closeFrontierNode(){let t=this.frontier.pop();let e=t.match.fillBefore(h.empty,true);if(e.childCount)this.placed=Me(this.placed,this.frontier.length,e)}}function Ae(t,e,i){if(e==0)return t.cutByIndex(i,t.childCount);return t.replaceChild(0,t.firstChild.copy(Ae(t.firstChild.content,e-1,i)))}function Me(t,e,i){if(e==0)return t.append(i);return t.replaceChild(t.childCount-1,t.lastChild.copy(Me(t.lastChild.content,e-1,i)))}function ke(t,e){for(let i=0;i<e;i++)t=t.firstChild.content;return t}function Se(t,e,i){if(e<=0)return t;let s=t.content;if(e>1)s=s.replaceChild(0,Se(s.firstChild,e-1,s.childCount==1?i-1:0));if(e>0){s=t.type.contentMatch.fillBefore(s).append(s);if(i<=0)s=s.append(t.type.contentMatch.matchFragment(s).fillBefore(h.empty,true))}return t.copy(s)}function xe(t,e,i,s,n){let r=t.node(e),o=n?t.indexAfter(e):t.index(e);if(o==r.childCount&&!i.compatibleContent(r.type))return null;let l=s.fillBefore(r.content,true,o);return l&&!Oe(i,r.content,o)?l:null}function Oe(t,e,i){for(let s=i;s<e.childCount;s++)if(!t.allowsMarks(e.child(s).marks))return true;return false}function Ee(t){return t.spec.defining||t.spec.definingForContent}function De(t,e,i,s){if(!s.size)return t.deleteRange(e,i);let n=t.doc.resolve(e),r=t.doc.resolve(i);if(be(n,r,s))return t.step(new Kt(e,i,s));let o=Ue(n,r);if(o[o.length-1]==0)o.pop();let l=-(n.depth+1);o.unshift(l);for(let t=n.depth,e=n.pos-1;t>0;t--,e--){let i=n.node(t).type.spec;if(i.defining||i.definingAsContext||i.isolating)break;if(o.indexOf(t)>-1)l=t;else if(n.before(t)==e)o.splice(1,0,-t)}let h=o.indexOf(l);let f=[],u=s.openStart;for(let t=s.content,e=0;;e++){let i=t.firstChild;f.push(i);if(e==s.openStart)break;t=i.content}for(let t=u-1;t>=0;t--){let e=f[t],i=Ee(e.type);if(i&&!e.sameMarkup(n.node(Math.abs(l)-1)))u=t;else if(i||!e.type.isTextblock)break}for(let e=s.openStart;e>=0;e--){let l=(e+u+1)%(s.openStart+1);let c=f[l];if(!c)continue;for(let e=0;e<o.length;e++){let f=o[(e+h)%o.length],u=true;if(f<0){u=false;f=-f}let a=n.node(f-1),d=n.index(f-1);if(a.canReplaceWith(d,d,c.type,c.marks))return t.replace(n.before(f),u?r.after(f):i,new w(Te(s.content,0,s.openStart,l),l,s.openEnd))}}let c=t.steps.length;for(let l=o.length-1;l>=0;l--){t.replace(e,i,s);if(t.steps.length>c)break;let h=o[l];if(h<0)continue;e=n.before(h);i=r.after(h)}}function Te(t,e,i,s,n){if(e<i){let n=t.firstChild;t=t.replaceChild(0,n.copy(Te(n.content,e+1,i,s,n)))}if(e>s){let e=n.contentMatchAt(0);let i=e.fillBefore(t).append(t);t=i.append(e.matchFragment(i).fillBefore(h.empty,true))}return t}function Ce(t,e,i,s){if(!s.isInline&&e==i&&t.doc.resolve(e).parent.content.size){let n=ge(t.doc,e,s.type);if(n!=null)e=i=n}t.replaceRange(e,i,new w(h.from(s),0,0))}function Re(t,e,i){let s=t.doc.resolve(e),n=t.doc.resolve(i);let r=Ue(s,n);for(let e=0;e<r.length;e++){let i=r[e],o=e==r.length-1;if(o&&i==0||s.node(i).type.contentMatch.validEnd)return t.delete(s.start(i),n.end(i));if(i>0&&(o||s.node(i-1).canReplace(s.index(i-1),n.indexAfter(i-1))))return t.delete(s.before(i),n.after(i))}for(let r=1;r<=s.depth&&r<=n.depth;r++){if(e-s.start(r)==s.depth-r&&i>s.end(r)&&n.end(r)-i!=n.depth-r&&s.start(r-1)==n.start(r-1)&&s.node(r-1).canReplace(s.index(r-1),n.index(r-1)))return t.delete(s.before(r),i)}t.delete(e,i)}function Ue(t,e){let i=[],s=Math.min(t.depth,e.depth);for(let n=s;n>=0;n--){let s=t.start(n);if(s<t.pos-(t.depth-n)||e.end(n)>e.pos+(e.depth-n)||t.node(n).type.spec.isolating||e.node(n).type.spec.isolating)break;if(s==e.start(n)||n==t.depth&&n==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&n&&e.start(n-1)==s-1)i.push(n)}return i}class Ie extends zt{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 Jt.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 Jt.fromReplace(t,this.pos,this.pos+1,new w(h.from(s),0,e.isLeaf?0:1))}getMap(){return _t.empty}invert(t){return new Ie(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 Ie(e.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,e){if(typeof e.pos!="number"||typeof e.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Ie(e.pos,e.attr,e.value)}}zt.jsonID("attr",Ie);class Ne extends zt{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 Jt.ok(i)}getMap(){return _t.empty}invert(t){return new Ne(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(typeof e.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Ne(e.attr,e.value)}}zt.jsonID("docAttr",Ne);let Pe=class extends Error{};Pe=function t(e){let i=Error.call(this,e);i.__proto__=t.prototype;return i};Pe.prototype=Object.create(Error.prototype);Pe.prototype.constructor=Pe;Pe.prototype.name="TransformError";class Fe{constructor(t){this.doc=t;this.steps=[];this.docs=[];this.mapping=new $t}get before(){return this.docs.length?this.docs[0]:this.doc}step(t){let e=this.maybeStep(t);if(e.failed)throw new Pe(e.failed);return this}maybeStep(t){let e=t.apply(this.doc);if(!e.failed)this.addStep(t,e.doc);return e}get docChanged(){return this.steps.length>0}addStep(t,e){this.docs.push(this.doc);this.steps.push(t);this.mapping.appendMap(t.getMap());this.doc=e}replace(t,e=t,i=w.empty){let s=ye(this.doc,t,e,i);if(s)this.step(s);return this}replaceWith(t,e,i){return this.replace(t,e,new w(h.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){De(this,t,e,i);return this}replaceRangeWith(t,e,i){Ce(this,t,e,i);return this}deleteRange(t,e){Re(this,t,e);return this}lift(t,e){se(this,t,e);return this}join(t,e=1){pe(this,t,e);return this}wrap(t,e){ne(this,t,e);return this}setBlockType(t,e=t,i,s=null){re(this,t,e,i,s);return this}setNodeMarkup(t,e,i=null,s){fe(this,t,e,i,s);return this}setNodeAttribute(t,e,i){this.step(new Ie(t,e,i));return this}setDocAttribute(t,e){this.step(new Ne(t,e));return this}addNodeMark(t,e){this.step(new qt(t,e));return this}removeNodeMark(t,e){let i=this.doc.nodeAt(t);if(!i)throw new RangeError("No node at position "+t);if(e instanceof a){if(e.isInSet(i.marks))this.step(new Vt(t,e))}else{let s=i.marks,n,r=[];while(n=e.isInSet(s)){r.push(new Vt(t,n));s=n.removeFromSet(s)}for(let t=r.length-1;t>=0;t--)this.step(r[t])}return this}split(t,e=1,i){ce(this,t,e,i);return this}addMark(t,e,i){Gt(this,t,e,i);return this}removeMark(t,e,i){Zt(this,t,e,i);return this}clearIncompatible(t,e,i){te(this,t,e,i);return this}}const Be=Object.create(null);class je{constructor(t,e,i){this.$anchor=t;this.$head=e;this.ranges=i||[new _e(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 false;return true}content(){return this.$from.doc.slice(this.from,this.to,true)}replace(t,e=w.empty){let i=e.content.lastChild,s=null;for(let t=0;t<e.openEnd;t++){s=i;i=i.lastChild}let n=t.steps.length,r=this.ranges;for(let o=0;o<r.length;o++){let{$from:l,$to:h}=r[o],f=t.mapping.slice(n);t.replaceRange(f.map(l.pos),f.map(h.pos),o?w.empty:e);if(o==0)Ke(t,n,(i?i.isInline:s&&s.isTextblock)?-1:1)}}replaceWith(t,e){let i=t.steps.length,s=this.ranges;for(let n=0;n<s.length;n++){let{$from:r,$to:o}=s[n],l=t.mapping.slice(i);let h=l.map(r.pos),f=l.map(o.pos);if(n){t.deleteRange(h,f)}else{t.replaceRangeWith(h,f,e);Ke(t,i,e.isInline?-1:1)}}}static findFrom(t,e,i=false){let s=t.parent.inlineContent?new ze(t):Ve(t.node(0),t.parent,t.pos,t.index(),e,i);if(s)return s;for(let s=t.depth-1;s>=0;s--){let n=e<0?Ve(t.node(0),t.node(s),t.before(s+1),t.index(s),e,i):Ve(t.node(0),t.node(s),t.after(s+1),t.index(s)+1,e,i);if(n)return n}return null}static near(t,e=1){return this.findFrom(t,e)||this.findFrom(t,-e)||new He(t.node(0))}static atStart(t){return Ve(t,t,0,0,1)||new He(t)}static atEnd(t){return Ve(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=Be[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 Be)throw new RangeError("Duplicate use of selection JSON ID "+t);Be[t]=e;e.prototype.jsonID=t;return e}getBookmark(){return ze.between(this.$anchor,this.$head).getBookmark()}}je.prototype.visible=true;class _e{constructor(t,e){this.$from=t;this.$to=e}}let $e=false;function Le(t){if(!$e&&!t.parent.inlineContent){$e=true;console["warn"]("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")")}}class ze extends je{constructor(t,e=t){Le(t);Le(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 je.near(i);let s=t.resolve(e.map(this.anchor));return new ze(s.parent.inlineContent?s:i,i)}replace(t,e=w.empty){super.replace(t,e);if(e==w.empty){let e=this.$from.marksAcross(this.$to);if(e)t.ensureMarks(e)}}eq(t){return t instanceof ze&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Je(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,e){if(typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new ze(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;if(!e.parent.inlineContent){let t=je.findFrom(e,i,true)||je.findFrom(e,-i,true);if(t)e=t.$head;else return je.near(e,i)}if(!t.parent.inlineContent){if(s==0){t=e}else{t=(je.findFrom(t,-i,true)||je.findFrom(t,i,true)).$anchor;if(t.pos<e.pos!=s<0)t=e}}return new ze(t,e)}}je.jsonID("text",ze);class Je{constructor(t,e){this.anchor=t;this.head=e}map(t){return new Je(t.map(this.anchor),t.map(this.head))}resolve(t){return ze.between(t.resolve(this.anchor),t.resolve(this.head))}}class We extends je{constructor(t){let e=t.nodeAfter;let 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);let n=t.resolve(s);if(i)return je.near(n);return new We(n)}content(){return new w(h.from(this.node),0,0)}eq(t){return t instanceof We&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Qe(this.anchor)}static fromJSON(t,e){if(typeof e.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new We(t.resolve(e.anchor))}static create(t,e){return new We(t.resolve(e))}static isSelectable(t){return!t.isText&&t.type.spec.selectable!==false}}We.prototype.visible=false;je.jsonID("node",We);class Qe{constructor(t){this.anchor=t}map(t){let{deleted:e,pos:i}=t.mapResult(this.anchor);return e?new Je(i,i):new Qe(i)}resolve(t){let e=t.resolve(this.anchor),i=e.nodeAfter;if(i&&We.isSelectable(i))return new We(e);return je.near(e)}}class He extends je{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=je.atStart(t.doc);if(!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 qe}}je.jsonID("all",He);const qe={map(){return this},resolve(t){return new He(t)}};function Ve(t,e,i,s,n,r=false){if(e.inlineContent)return ze.create(t,i);for(let o=s-(n>0?0:1);n>0?o<e.childCount:o>=0;o+=n){let s=e.child(o);if(!s.isAtom){let e=Ve(t,s,i+n,n<0?s.childCount:0,n,r);if(e)return e}else if(!r&&We.isSelectable(s)){return We.create(t,i-(n<0?s.nodeSize:0))}i+=s.nodeSize*n}return null}function Ke(t,e,i){let s=t.steps.length-1;if(s<e)return;let n=t.steps[s];if(!(n instanceof Kt||n instanceof Yt))return;let r=t.mapping.maps[s],o;r.forEach(((t,e,i,s)=>{if(o==null)o=s}));t.setSelection(je.near(t.doc.resolve(o),i))}const Ye=1,Xe=2,Ge=4;let Ze=class t extends Fe{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(){if(this.curSelectionFor<this.steps.length){this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor));this.curSelectionFor=this.steps.length}return this.curSelection}setSelection(t){if(t.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");this.curSelection=t;this.curSelectionFor=this.steps.length;this.updated=(this.updated|Ye)&-3;this.storedMarks=null;return this}get selectionSet(){return(this.updated&Ye)>0}setStoredMarks(t){this.storedMarks=t;this.updated|=Xe;return this}ensureMarks(t){if(!a.sameSet(this.storedMarks||this.selection.$from.marks(),t))this.setStoredMarks(t);return 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(this.updated&Xe)>0}addStep(t,e){super.addStep(t,e);this.updated=this.updated&-3;this.storedMarks=null}setTime(t){this.time=t;return this}replaceSelection(t){this.selection.replace(this,t);return this}replaceSelectionWith(t,e=true){let i=this.selection;if(e)t=t.mark(this.storedMarks||(i.empty?i.$from.marks():i.$from.marksAcross(i.$to)||a.none));i.replaceWith(this,t);return this}deleteSelection(){this.selection.replace(this);return this}insertText(t,e,i){let s=this.doc.type.schema;if(e==null){if(!t)return this.deleteSelection();return this.replaceSelectionWith(s.text(t),true)}else{if(i==null)i=e;if(!t)return this.deleteRange(e,i);let n=this.storedMarks;if(!n){let t=this.doc.resolve(e);n=i==e?t.marks():t.marksAcross(this.doc.resolve(i))}this.replaceRangeWith(e,i,s.text(t,n));if(!this.selection.empty&&this.selection.to==e+t.length)this.setSelection(je.near(this.selection.$to));return this}}setMeta(t,e){this.meta[typeof t=="string"?t:t.key]=e;return this}getMeta(t){return this.meta[typeof t=="string"?t:t.key]}get isGeneric(){for(let t in this.meta)return false;return true}scrollIntoView(){this.updated|=Ge;return this}get scrolledIntoView(){return(this.updated&Ge)>0}};function ti(t,e){return!e||!t?t:t.bind(e)}class ei{constructor(t,e,i){this.name=t;this.init=ti(e.init,i);this.apply=ti(e.apply,i)}}const ii=[new ei("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new ei("selection",{init(t,e){return t.selection||je.atStart(e.doc)},apply(t){return t.selection}}),new ei("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,i,s){return s.selection.$cursor?t.storedMarks:null}}),new ei("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class si{constructor(t,e){this.schema=t;this.plugins=[];this.pluginsByKey=Object.create(null);this.fields=ii.slice();if(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;if(t.spec.state)this.fields.push(new ei(t.key,t.spec.state,t))}))}}class ni{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 false}return true}applyTransaction(t){if(!this.filterTransaction(t))return{state:this,transactions:[]};let e=[t],i=this.applyInner(t),s=null;for(;;){let n=false;for(let r=0;r<this.config.plugins.length;r++){let o=this.config.plugins[r];if(o.spec.appendTransaction){let l=s?s[r].n:0,h=s?s[r].state:this;let f=l<e.length&&o.spec.appendTransaction.call(o,l?e.slice(l):e,h,i);if(f&&i.filterTransaction(f,r)){f.setMeta("appendedTransaction",t);if(!s){s=[];for(let t=0;t<this.config.plugins.length;t++)s.push(t<r?{state:i,n:e.length}:{state:this,n:0})}e.push(f);i=i.applyInner(f);n=true}if(s)s[r]={state:i,n:e.length}}}if(!n)return{state:i,transactions:e}}}applyInner(t){if(!t.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let e=new ni(this.config),i=this.config.fields;for(let s=0;s<i.length;s++){let n=i[s];e[n.name]=n.apply(t,this[n.name],this,e)}return e}get tr(){return new Ze(this)}static create(t){let e=new si(t.doc?t.doc.type.schema:t.schema,t.plugins);let i=new ni(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 si(this.schema,t.plugins);let i=e.fields,s=new ni(e);for(let e=0;e<i.length;e++){let n=i[e].name;s[n]=this.hasOwnProperty(n)?this[n]:i[e].init(t,s)}return s}toJSON(t){let e={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks)e.storedMarks=this.storedMarks.map((t=>t.toJSON()));if(t&&typeof t=="object")for(let i in t){if(i=="doc"||i=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let s=t[i],n=s.spec.state;if(n&&n.toJSON)e[i]=n.toJSON.call(s,this[s.key])}return e}static fromJSON(t,e,i){if(!e)throw new RangeError("Invalid input for EditorState.fromJSON");if(!t.schema)throw new RangeError("Required config field 'schema' missing");let s=new si(t.schema,t.plugins);let n=new ni(s);s.fields.forEach((s=>{if(s.name=="doc"){n.doc=I.fromJSON(t.schema,e.doc)}else if(s.name=="selection"){n.selection=je.fromJSON(n.doc,e.selection)}else if(s.name=="storedMarks"){if(e.storedMarks)n.storedMarks=e.storedMarks.map(t.schema.markFromJSON)}else{if(i)for(let r in i){let o=i[r],l=o.spec.state;if(o.key==s.name&&l&&l.fromJSON&&Object.prototype.hasOwnProperty.call(e,r)){n[s.name]=l.fromJSON.call(o,t,e[r],n);return}}n[s.name]=s.init(t,n)}}));return n}}function ri(t,e,i){for(let s in t){let n=t[s];if(n instanceof Function)n=n.bind(e);else if(s=="handleDOMEvents")n=ri(n,e,{});i[s]=n}return i}class oi{constructor(t){this.spec=t;this.props={};if(t.props)ri(t.props,this,this.props);this.key=t.key?t.key.key:hi("plugin")}getState(t){return t[this.key]}}const li=Object.create(null);function hi(t){if(t in li)return t+"$"+ ++li[t];li[t]=0;return t+"$"}const fi=function(t){for(var e=0;;e++){t=t.previousSibling;if(!t)return e}};const ui=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let ci=null;const ai=function(t,e,i){let s=ci||(ci=document.createRange());s.setEnd(t,i==null?t.nodeValue.length:i);s.setStart(t,e||0);return s};const di=function(){ci=null};const wi=function(t,e,i,s){return i&&(gi(t,e,i,s,-1)||gi(t,e,i,s,1))};const pi=/^(img|br|input|textarea|hr)$/i;function gi(t,e,i,s,n){var r;for(;;){if(t==i&&e==s)return true;if(e==(n<0?0:mi(t))){let i=t.parentNode;if(!i||i.nodeType!=1||Ai(t)||pi.test(t.nodeName)||t.contentEditable=="false")return false;e=fi(t)+(n<0?0:1);t=i}else if(t.nodeType==1){let i=t.childNodes[e+(n<0?-1:0)];if(i.nodeType==1&&i.contentEditable=="false"){if((r=i.pmViewDesc)===null||r===void 0?void 0:r.ignoreForSelection)e+=n;else return false}else{t=i;e=n<0?mi(t):0}}else{return false}}}function mi(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function yi(t,e){for(;;){if(t.nodeType==3&&e)return t;if(t.nodeType==1&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1];e=mi(t)}else if(t.parentNode&&!Ai(t)){e=fi(t);t=t.parentNode}else{return null}}}function bi(t,e){for(;;){if(t.nodeType==3&&e<t.nodeValue.length)return t;if(t.nodeType==1&&e<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[e];e=0}else if(t.parentNode&&!Ai(t)){e=fi(t)+1;t=t.parentNode}else{return null}}}function vi(t,e,i){for(let s=e==0,n=e==mi(t);s||n;){if(t==i)return true;let e=fi(t);t=t.parentNode;if(!t)return false;s=s&&e==0;n=n&&e==mi(t)}}function Ai(t){let e;for(let i=t;i;i=i.parentNode)if(e=i.pmViewDesc)break;return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const Mi=function(t){return t.focusNode&&wi(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function ki(t,e){let i=document.createEvent("Event");i.initEvent("keydown",true,true);i.keyCode=t;i.key=i.code=e;return i}function Si(t){let e=t.activeElement;while(e&&e.shadowRoot)e=e.shadowRoot.activeElement;return e}function xi(t,e,i){if(t.caretPositionFromPoint){try{let s=t.caretPositionFromPoint(e,i);if(s)return{node:s.offsetNode,offset:Math.min(mi(s.offsetNode),s.offset)}}catch(t){}}if(t.caretRangeFromPoint){let s=t.caretRangeFromPoint(e,i);if(s)return{node:s.startContainer,offset:Math.min(mi(s.startContainer),s.startOffset)}}}const Oi=typeof navigator!="undefined"?navigator:null;const Ei=typeof document!="undefined"?document:null;const Di=Oi&&Oi.userAgent||"";const Ti=/Edge\/(\d+)/.exec(Di);const Ci=/MSIE \d/.exec(Di);const Ri=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Di);const Ui=!!(Ci||Ri||Ti);const Ii=Ci?document.documentMode:Ri?+Ri[1]:Ti?+Ti[1]:0;const Ni=!Ui&&/gecko\/(\d+)/i.test(Di);const Pi=!Ui&&/Chrome\/(\d+)/.exec(Di);const Fi=!!Pi;const Bi=Pi?+Pi[1]:0;const ji=!Ui&&!!Oi&&/Apple Computer/.test(Oi.vendor);const _i=ji&&(/Mobile\/\w+/.test(Di)||!!Oi&&Oi.maxTouchPoints>2);const $i=_i||(Oi?/Mac/.test(Oi.platform):false);const Li=Oi?/Win/.test(Oi.platform):false;const zi=/Android \d/.test(Di);const Ji=!!Ei&&"webkitFontSmoothing"in Ei.documentElement.style;const Wi=Ji?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Qi(t){let e=t.defaultView&&t.defaultView.visualViewport;if(e)return{left:0,right:e.width,top:0,bottom:e.height};return{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function Hi(t,e){return typeof t=="number"?t:t[e]}function qi(t){let e=t.getBoundingClientRect();let i=e.width/t.offsetWidth||1;let s=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*i,top:e.top,bottom:e.top+t.clientHeight*s}}function Vi(t,e,i){let s=t.someProp("scrollThreshold")||0,n=t.someProp("scrollMargin")||5;let r=t.dom.ownerDocument;for(let o=i||t.dom;;){if(!o)break;if(o.nodeType!=1){o=ui(o);continue}let t=o;let i=t==r.body;let l=i?Qi(r):qi(t);let h=0,f=0;if(e.top<l.top+Hi(s,"top"))f=-(l.top-e.top+Hi(n,"top"));else if(e.bottom>l.bottom-Hi(s,"bottom"))f=e.bottom-e.top>l.bottom-l.top?e.top+Hi(n,"top")-l.top:e.bottom-l.bottom+Hi(n,"bottom");if(e.left<l.left+Hi(s,"left"))h=-(l.left-e.left+Hi(n,"left"));else if(e.right>l.right-Hi(s,"right"))h=e.right-l.right+Hi(n,"right");if(h||f){if(i){r.defaultView.scrollBy(h,f)}else{let i=t.scrollLeft,s=t.scrollTop;if(f)t.scrollTop+=f;if(h)t.scrollLeft+=h;let n=t.scrollLeft-i,r=t.scrollTop-s;e={left:e.left-n,top:e.top-r,right:e.right-n,bottom:e.bottom-r}}}let u=i?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(u))break;o=u=="absolute"?o.offsetParent:ui(o)}}function Ki(t){let e=t.dom.getBoundingClientRect(),i=Math.max(0,e.top);let s,n;for(let r=(e.left+e.right)/2,o=i+1;o<Math.min(innerHeight,e.bottom);o+=5){let e=t.root.elementFromPoint(r,o);if(!e||e==t.dom||!t.dom.contains(e))continue;let l=e.getBoundingClientRect();if(l.top>=i-20){s=e;n=l.top;break}}return{refDOM:s,refTop:n,stack:Yi(t.dom)}}function Yi(t){let e=[],i=t.ownerDocument;for(let s=t;s;s=ui(s)){e.push({dom:s,top:s.scrollTop,left:s.scrollLeft});if(t==i)break}return e}function Xi({refDOM:t,refTop:e,stack:i}){let s=t?t.getBoundingClientRect().top:0;Gi(i,s==0?0:s-e)}function Gi(t,e){for(let i=0;i<t.length;i++){let{dom:s,top:n,left:r}=t[i];if(s.scrollTop!=n+e)s.scrollTop=n+e;if(s.scrollLeft!=r)s.scrollLeft=r}}let Zi=null;function ts(t){if(t.setActive)return t.setActive();if(Zi)return t.focus(Zi);let e=Yi(t);t.focus(Zi==null?{get preventScroll(){Zi={preventScroll:true};return true}}:undefined);if(!Zi){Zi=false;Gi(e,0)}}function es(t,e){let i,s=2e8,n,r=0;let o=e.top,l=e.top;let h,f;for(let u=t.firstChild,c=0;u;u=u.nextSibling,c++){let t;if(u.nodeType==1)t=u.getClientRects();else if(u.nodeType==3)t=ai(u).getClientRects();else continue;for(let a=0;a<t.length;a++){let d=t[a];if(d.top<=o&&d.bottom>=l){o=Math.max(d.bottom,o);l=Math.min(d.top,l);let t=d.left>e.left?d.left-e.left:d.right<e.left?e.left-d.right:0;if(t<s){i=u;s=t;n=t&&i.nodeType==3?{left:d.right<e.left?d.right:d.left,top:e.top}:e;if(u.nodeType==1&&t)r=c+(e.left>=(d.left+d.right)/2?1:0);continue}}else if(d.top>e.top&&!h&&d.left<=e.left&&d.right>=e.left){h=u;f={left:Math.max(d.left,Math.min(d.right,e.left)),top:d.top}}if(!i&&(e.left>=d.right&&e.top>=d.top||e.left>=d.left&&e.top>=d.bottom))r=c+1}}if(!i&&h){i=h;n=f;s=0}if(i&&i.nodeType==3)return is(i,n);if(!i||s&&i.nodeType==1)return{node:t,offset:r};return es(i,n)}function is(t,e){let i=t.nodeValue.length;let s=document.createRange();for(let n=0;n<i;n++){s.setEnd(t,n+1);s.setStart(t,n);let i=cs(s,1);if(i.top==i.bottom)continue;if(ss(e,i))return{node:t,offset:n+(e.left>=(i.left+i.right)/2?1:0)}}return{node:t,offset:0}}function ss(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function ns(t,e){let i=t.parentNode;if(i&&/^li$/i.test(i.nodeName)&&e.left<t.getBoundingClientRect().left)return i;return t}function rs(t,e,i){let{node:s,offset:n}=es(e,i),r=-1;if(s.nodeType==1&&!s.firstChild){let t=s.getBoundingClientRect();r=t.left!=t.right&&i.left>(t.left+t.right)/2?1:-1}return t.docView.posFromDOM(s,n,r)}function ls(t,e,i,s){let n=-1;for(let i=e,r=false;;){if(i==t.dom)break;let e=t.docView.nearestDesc(i,true),o;if(!e)return null;if(e.dom.nodeType==1&&(e.node.isBlock&&e.parent||!e.contentDOM)&&((o=e.dom.getBoundingClientRect()).width||o.height)){if(e.node.isBlock&&e.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(e.dom.nodeName)){if(!r&&o.left>s.left||o.top>s.top)n=e.posBefore;else if(!r&&o.right<s.left||o.bottom<s.top)n=e.posAfter;r=true}if(!e.contentDOM&&n<0&&!e.node.isText){let t=e.node.isBlock?s.top<(o.top+o.bottom)/2:s.left<(o.left+o.right)/2;return t?e.posBefore:e.posAfter}}i=e.dom.parentNode}return n>-1?n:t.docView.posFromDOM(e,i,-1)}function hs(t,e,i){let s=t.childNodes.length;if(s&&i.top<i.bottom){for(let n=Math.max(0,Math.min(s-1,Math.floor(s*(e.top-i.top)/(i.bottom-i.top))-2)),r=n;;){let i=t.childNodes[r];if(i.nodeType==1){let t=i.getClientRects();for(let s=0;s<t.length;s++){let n=t[s];if(ss(e,n))return hs(i,e,n)}}if((r=(r+1)%s)==n)break}}return t}function fs(t,e){let i=t.dom.ownerDocument,s,n=0;let r=xi(i,e.left,e.top);if(r)({node:s,offset:n}=r);let o=(t.root.elementFromPoint?t.root:i).elementFromPoint(e.left,e.top);let l;if(!o||!t.dom.contains(o.nodeType!=1?o.parentNode:o)){let i=t.dom.getBoundingClientRect();if(!ss(e,i))return null;o=hs(t.dom,e,i);if(!o)return null}if(ji){for(let t=o;s&&t;t=ui(t))if(t.draggable)s=undefined}o=ns(o,e);if(s){if(Ni&&s.nodeType==1){n=Math.min(n,s.childNodes.length);if(n<s.childNodes.length){let t=s.childNodes[n],i;if(t.nodeName=="IMG"&&(i=t.getBoundingClientRect()).right<=e.left&&i.bottom>e.top)n++}}let i;if(Ji&&n&&s.nodeType==1&&(i=s.childNodes[n-1]).nodeType==1&&i.contentEditable=="false"&&i.getBoundingClientRect().top>=e.top)n--;if(s==t.dom&&n==s.childNodes.length-1&&s.lastChild.nodeType==1&&e.top>s.lastChild.getBoundingClientRect().bottom)l=t.state.doc.content.size;else if(n==0||s.nodeType!=1||s.childNodes[n-1].nodeName!="BR")l=ls(t,s,n,e)}if(l==null)l=rs(t,o,e);let h=t.docView.nearestDesc(o,true);return{pos:l,inside:h?h.posAtStart-h.border:-1}}function us(t){return t.top<t.bottom||t.left<t.right}function cs(t,e){let i=t.getClientRects();if(i.length){let t=i[e<0?0:i.length-1];if(us(t))return t}return Array.prototype.find.call(i,us)||t.getBoundingClientRect()}const as=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function ds(t,e,i){let{node:s,offset:n,atom:r}=t.docView.domFromPos(e,i<0?-1:1);let o=Ji||Ni;if(s.nodeType==3){if(o&&(as.test(s.nodeValue)||(i<0?!n:n==s.nodeValue.length))){let t=cs(ai(s,n,n),i);if(Ni&&n&&/\s/.test(s.nodeValue[n-1])&&n<s.nodeValue.length){let e=cs(ai(s,n-1,n-1),-1);if(e.top==t.top){let i=cs(ai(s,n,n+1),-1);if(i.top!=t.top)return ws(i,i.left<e.left)}}return t}else{let t=n,e=n,r=i<0?1:-1;if(i<0&&!n){e++;r=-1}else if(i>=0&&n==s.nodeValue.length){t--;r=1}else if(i<0){t--}else{e++}return ws(cs(ai(s,t,e),r),r<0)}}let l=t.state.doc.resolve(e-(r||0));if(!l.parent.inlineContent){if(r==null&&n&&(i<0||n==mi(s))){let t=s.childNodes[n-1];if(t.nodeType==1)return ps(t.getBoundingClientRect(),false)}if(r==null&&n<mi(s)){let t=s.childNodes[n];if(t.nodeType==1)return ps(t.getBoundingClientRect(),true)}return ps(s.getBoundingClientRect(),i>=0)}if(r==null&&n&&(i<0||n==mi(s))){let t=s.childNodes[n-1];let e=t.nodeType==3?ai(t,mi(t)-(o?0:1)):t.nodeType==1&&(t.nodeName!="BR"||!t.nextSibling)?t:null;if(e)return ws(cs(e,1),false)}if(r==null&&n<mi(s)){let t=s.childNodes[n];while(t.pmViewDesc&&t.pmViewDesc.ignoreForCoords)t=t.nextSibling;let e=!t?null:t.nodeType==3?ai(t,0,o?0:1):t.nodeType==1?t:null;if(e)return ws(cs(e,-1),true)}return ws(cs(s.nodeType==3?ai(s):s,-i),i>=0)}function ws(t,e){if(t.width==0)return t;let i=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:i,right:i}}function ps(t,e){if(t.height==0)return t;let i=e?t.top:t.bottom;return{top:i,bottom:i,left:t.left,right:t.right}}function gs(t,e,i){let s=t.state,n=t.root.activeElement;if(s!=e)t.updateState(e);if(n!=t.dom)t.focus();try{return i()}finally{if(s!=e)t.updateState(s);if(n!=t.dom&&n)n.focus()}}function ms(t,e,i){let s=e.selection;let n=i=="up"?s.$from:s.$to;return gs(t,e,(()=>{let{node:e}=t.docView.domFromPos(n.pos,i=="up"?-1:1);for(;;){let i=t.docView.nearestDesc(e,true);if(!i)break;if(i.node.isBlock){e=i.contentDOM||i.dom;break}e=i.dom.parentNode}let s=ds(t,n.pos,1);for(let t=e.firstChild;t;t=t.nextSibling){let e;if(t.nodeType==1)e=t.getClientRects();else if(t.nodeType==3)e=ai(t,0,t.nodeValue.length).getClientRects();else continue;for(let t=0;t<e.length;t++){let n=e[t];if(n.bottom>n.top+1&&(i=="up"?s.top-n.top>(n.bottom-s.top)*2:n.bottom-s.bottom>(s.bottom-n.top)*2))return false}}return true}))}const ys=/[\u0590-\u08ac]/;function bs(t,e,i){let{$head:s}=e.selection;if(!s.parent.isTextblock)return false;let n=s.parentOffset,r=!n,o=n==s.parent.content.size;let l=t.domSelection();if(!l)return s.pos==s.start()||s.pos==s.end();if(!ys.test(s.parent.textContent)||!l.modify)return i=="left"||i=="backward"?r:o;return gs(t,e,(()=>{let{focusNode:e,focusOffset:n,anchorNode:r,anchorOffset:o}=t.domSelectionRange();let h=l.caretBidiLevel;l.modify("move",i,"character");let f=s.depth?t.docView.domAfterPos(s.before()):t.dom;let{focusNode:u,focusOffset:c}=t.domSelectionRange();let a=u&&!f.contains(u.nodeType==1?u:u.parentNode)||e==u&&n==c;try{l.collapse(r,o);if(e&&(e!=r||n!=o)&&l.extend)l.extend(e,n)}catch(t){}if(h!=null)l.caretBidiLevel=h;return a}))}let vs=null;let As=null;let Ms=false;function ks(t,e,i){if(vs==e&&As==i)return Ms;vs=e;As=i;return Ms=i=="up"||i=="down"?ms(t,e,i):bs(t,e,i)}const Ss=0,xs=1,Os=2,Es=3;class Ds{constructor(t,e,i,s){this.parent=t;this.children=e;this.dom=i;this.contentDOM=s;this.dirty=Ss;i.pmViewDesc=this}matchesWidget(t){return false}matchesMark(t){return false}matchesNode(t,e,i){return false}matchesHack(t){return false}parseRule(){return null}stopEvent(t){return false}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=undefined;if(this.dom.pmViewDesc==this)this.dom.pmViewDesc=undefined;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(t.nodeType==1?t:t.parentNode)){if(i<0){let i,s;if(t==this.contentDOM){i=t.childNodes[e-1]}else{while(t.parentNode!=this.contentDOM)t=t.parentNode;i=t.previousSibling}while(i&&!((s=i.pmViewDesc)&&s.parent==this))i=i.previousSibling;return i?this.posBeforeChild(s)+s.size:this.posAtStart}else{let i,s;if(t==this.contentDOM){i=t.childNodes[e]}else{while(t.parentNode!=this.contentDOM)t=t.parentNode;i=t.nextSibling}while(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>fi(this.contentDOM)}else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM)){s=t.compareDocumentPosition(this.contentDOM)&2}else if(this.dom.firstChild){if(e==0)for(let e=t;;e=e.parentNode){if(e==this.dom){s=false;break}if(e.previousSibling)break}if(s==null&&e==t.childNodes.length)for(let e=t;;e=e.parentNode){if(e==this.dom){s=true;break}if(e.nextSibling)break}}return(s==null?i>0:s)?this.posAtEnd:this.posAtStart}nearestDesc(t,e=false){for(let i=true,s=t;s;s=s.parentNode){let n=this.getDesc(s),r;if(n&&(!e||n.node)){if(i&&(r=n.nodeDOM)&&!(r.nodeType==1?r.contains(t.nodeType==1?t:t.parentNode):r==t))i=false;else return n}}}getDesc(t){let e=t.pmViewDesc;for(let t=e;t;t=t.parent)if(t==this)return e}posFromDOM(t,e,i){for(let s=t;s;s=s.parentNode){let n=this.getDesc(s);if(n)return n.localPosFromDOM(t,e,i)}return-1}descAt(t){for(let e=0,i=0;e<this.children.length;e++){let s=this.children[e],n=i+s.size;if(i==t&&n!=i){while(!s.border&&s.children.length){for(let t=0;t<s.children.length;t++){let e=s.children[t];if(e.size){s=e;break}}}return s}if(t<n)return s.descAt(t-i-s.border);i=n}}domFromPos(t,e){if(!this.contentDOM)return{node:this.dom,offset:0,atom:t+1};let i=0,s=0;for(let e=0;i<this.children.length;i++){let n=this.children[i],r=e+n.size;if(r>t||n instanceof Ps){s=t-e;break}e=r}if(s)return this.children[i].domFromPos(s-this.children[i].border,e);for(let t;i&&!(t=this.children[i-1]).size&&t instanceof Ts&&t.side>=0;i--){}if(e<=0){let t,s=true;for(;;i--,s=false){t=i?this.children[i-1]:null;if(!t||t.dom.parentNode==this.contentDOM)break}if(t&&e&&s&&!t.border&&!t.domAtom)return t.domFromPos(t.size,e);return{node:this.contentDOM,offset:t?fi(t.dom)+1:0}}else{let t,s=true;for(;;i++,s=false){t=i<this.children.length?this.children[i]:null;if(!t||t.dom.parentNode==this.contentDOM)break}if(t&&s&&!t.border&&!t.domAtom)return t.domFromPos(0,e);return{node:this.contentDOM,offset:t?fi(t.dom):this.contentDOM.childNodes.length}}}parseRange(t,e,i=0){if(this.children.length==0)return{node:this.contentDOM,from:t,to:e,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let s=-1,n=-1;for(let r=i,o=0;;o++){let i=this.children[o],l=r+i.size;if(s==-1&&t<=l){let n=r+i.border;if(t>=n&&e<=l-i.border&&i.node&&i.contentDOM&&this.contentDOM.contains(i.contentDOM))return i.parseRange(t,e,n);t=r;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=fi(i.dom)+1;break}t-=i.size}if(s==-1)s=0}if(s>-1&&(l>e||o==this.children.length-1)){e=l;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)){n=fi(i.dom);break}e+=i.size}if(n==-1)n=this.contentDOM.childNodes.length;break}r=l}return{node:this.contentDOM,from:t,to:e,fromOffset:s,toOffset:n}}emptyChildAt(t){if(this.border||!this.contentDOM||!this.children.length)return false;let e=this.children[t<0?0:this.children.length-1];return e.size==0||e.emptyChildAt(t)}domAfterPos(t){let{node:e,offset:i}=this.domFromPos(t,0);if(e.nodeType!=1||i==e.childNodes.length)throw new RangeError("No node after pos "+t);return e.childNodes[i]}setSelection(t,e,i,s=false){let n=Math.min(t,e),r=Math.max(t,e);for(let o=0,l=0;o<this.children.length;o++){let h=this.children[o],f=l+h.size;if(n>l&&r<f)return h.setSelection(t-l-h.border,e-l-h.border,i,s);l=f}let o=this.domFromPos(t,t?-1:1);let l=e==t?o:this.domFromPos(e,e?-1:1);let h=i.root.getSelection();let f=i.domSelectionRange();let u=false;if((Ni||ji)&&t==e){let{node:t,offset:e}=o;if(t.nodeType==3){u=!!(e&&t.nodeValue[e-1]=="\n");if(u&&e==t.nodeValue.length){for(let e=t,i;e;e=e.parentNode){if(i=e.nextSibling){if(i.nodeName=="BR")o=l={node:i.parentNode,offset:fi(i)+1};break}let t=e.pmViewDesc;if(t&&t.node&&t.node.isBlock)break}}}else{let i=t.childNodes[e-1];u=i&&(i.nodeName=="BR"||i.contentEditable=="false")}}if(Ni&&f.focusNode&&f.focusNode!=l.node&&f.focusNode.nodeType==1){let t=f.focusNode.childNodes[f.focusOffset];if(t&&t.contentEditable=="false")s=true}if(!(s||u&&ji)&&wi(o.node,o.offset,f.anchorNode,f.anchorOffset)&&wi(l.node,l.offset,f.focusNode,f.focusOffset))return;let c=false;if((h.extend||t==e)&&!(u&&Ni)){h.collapse(o.node,o.offset);try{if(t!=e)h.extend(l.node,l.offset);c=true}catch(t){}}if(!c){if(t>e){let t=o;o=l;l=t}let i=document.createRange();i.setEnd(l.node,l.offset);i.setStart(o.node,o.offset);h.removeAllRanges();h.addRange(i)}}ignoreMutation(t){return!this.contentDOM&&t.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(t,e){for(let i=0,s=0;s<this.children.length;s++){let n=this.children[s],r=i+n.size;if(i==r?t<=r&&e>=i:t<r&&e>i){let s=i+n.border,o=r-n.border;if(t>=s&&e<=o){this.dirty=t==i||e==r?Os:xs;if(t==s&&e==o&&(n.contentLost||n.dom.parentNode!=this.contentDOM))n.dirty=Es;else n.markDirty(t-s,e-s);return}else{n.dirty=n.dom==n.contentDOM&&n.dom.parentNode==this.contentDOM&&!n.children.length?Os:Es}}i=r}this.dirty=Os}markParentsDirty(){let t=1;for(let e=this.parent;e;e=e.parent,t++){let i=t==1?Os:xs;if(e.dirty<i)e.dirty=i}}get domAtom(){return false}get ignoreForCoords(){return false}get ignoreForSelection(){return false}isText(t){return false}}class Ts extends Ds{constructor(t,e,i,s){let n,r=e.type.toDOM;if(typeof r=="function")r=r(i,(()=>{if(!n)return s;if(n.parent)return n.parent.posBeforeChild(n)}));if(!e.type.spec.raw){if(r.nodeType!=1){let t=document.createElement("span");t.appendChild(r);r=t}r.contentEditable="false";r.classList.add("ProseMirror-widget")}super(t,[],r,null);this.widget=e;this.widget=e;n=this}matchesWidget(t){return this.dirty==Ss&&t.type.eq(this.widget.type)}parseRule(){return{ignore:true}}stopEvent(t){let e=this.widget.spec.stopEvent;return e?e(t):false}ignoreMutation(t){return t.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom);super.destroy()}get domAtom(){return true}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class Cs extends Ds{constructor(t,e,i,s){super(t,[],e,null);this.textDOM=i;this.text=s}get size(){return this.text.length}localPosFromDOM(t,e){if(t!=this.textDOM)return this.posAtStart+(e?this.size:0);return this.posAtStart+e}domFromPos(t){return{node:this.textDOM,offset:t}}ignoreMutation(t){return t.type==="characterData"&&t.target.nodeValue==t.oldValue}}class Rs extends Ds{constructor(t,e,i,s,n){super(t,[],i,s);this.mark=e;this.spec=n}static create(t,e,i,s){let n=s.nodeViews[e.type.name];let r=n&&n(e,s,i);if(!r||!r.dom)r=Mt.renderSpec(document,e.type.spec.toDOM(e,i),null,e.attrs);return new Rs(t,e,r.dom,r.contentDOM||r.dom,r)}parseRule(){if(this.dirty&Es||this.mark.type.spec.reparseInView)return null;return{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(t){return this.dirty!=Es&&this.mark.eq(t)}markDirty(t,e){super.markDirty(t,e);if(this.dirty!=Ss){let t=this.parent;while(!t.node)t=t.parent;if(t.dirty<this.dirty)t.dirty=this.dirty;this.dirty=Ss}}slice(t,e,i){let s=Rs.create(this.parent,this.mark,true,i);let n=this.children,r=this.size;if(e<r)n=Gs(n,e,r,i);if(t>0)n=Gs(n,0,t,i);for(let t=0;t<n.length;t++)n[t].parent=s;s.children=n;return s}ignoreMutation(t){return this.spec.ignoreMutation?this.spec.ignoreMutation(t):super.ignoreMutation(t)}destroy(){if(this.spec.destroy)this.spec.destroy();super.destroy()}}class Us extends Ds{constructor(t,e,i,s,n,r,o,l,h){super(t,[],n,r);this.node=e;this.outerDeco=i;this.innerDeco=s;this.nodeDOM=o}static create(t,e,i,s,n,r){let o=n.nodeViews[e.type.name],l;let h=o&&o(e,n,(()=>{if(!l)return r;if(l.parent)return l.parent.posBeforeChild(l)}),i,s);let f=h&&h.dom,u=h&&h.contentDOM;if(e.isText){if(!f)f=document.createTextNode(e.text);else if(f.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else if(!f){let t=Mt.renderSpec(document,e.type.spec.toDOM(e),null,e.attrs);({dom:f,contentDOM:u}=t)}if(!u&&!e.isText&&f.nodeName!="BR"){if(!f.hasAttribute("contenteditable"))f.contentEditable="false";if(e.type.spec.draggable)f.draggable=true}let c=f;f=Js(f,i,e);if(h)return l=new Fs(t,e,i,s,f,u||null,c,h,n,r+1);else if(e.isText)return new Ns(t,e,i,s,f,c,n);else return new Us(t,e,i,s,f,u||null,c,n,r+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre")t.preserveWhitespace="full";if(!this.contentDOM){t.getContent=()=>this.node.content}else if(!this.contentLost){t.contentElement=this.contentDOM}else{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}}if(!t.contentElement)t.getContent=()=>h.empty}return t}matchesNode(t,e,i){return this.dirty==Ss&&t.eq(this.node)&&Ws(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;let n=t.composing?this.localCompositionInfo(t,e):null;let r=n&&n.pos>-1?n:null;let o=n&&n.pos<0;let l=new Hs(this,r&&r.node,t);Ks(this.node,this.innerDeco,((e,n,r)=>{if(e.spec.marks)l.syncToMarks(e.spec.marks,i,t);else if(e.type.side>=0&&!r)l.syncToMarks(n==this.node.childCount?a.none:this.node.child(n).marks,i,t);l.placeWidget(e,t,s)}),((e,r,h,f)=>{l.syncToMarks(e.marks,i,t);let u;if(l.findNodeMatch(e,r,h,f));else if(o&&t.state.selection.from>s&&t.state.selection.to<s+e.nodeSize&&(u=l.findIndexWithChild(n.node))>-1&&l.updateNodeAt(e,r,h,u,t));else if(l.updateNextNode(e,r,h,t,f,s));else{l.addNode(e,r,h,t,s)}s+=e.nodeSize}));l.syncToMarks([],i,t);if(this.node.isTextblock)l.addTextblockHacks();l.destroyRest();if(l.changed||this.dirty==Os){if(r)this.protectLocalComposition(t,r);Bs(this.contentDOM,this.children,t);if(_i)Ys(this.dom)}}localCompositionInfo(t,e){let{from:i,to:s}=t.state.selection;if(!(t.state.selection instanceof ze)||i<e||s>e+this.node.content.size)return null;let n=t.input.compositionNode;if(!n||!this.dom.contains(n.parentNode))return null;if(this.node.inlineContent){let t=n.nodeValue;let r=Xs(this.node.content,t,i-e,s-e);return r<0?null:{node:n,pos:r,text:t}}else{return{node:n,pos:-1,text:""}}}protectLocalComposition(t,{node:e,pos:i,text:s}){if(this.getDesc(e))return;let n=e;for(;;n=n.parentNode){if(n.parentNode==this.contentDOM)break;while(n.previousSibling)n.parentNode.removeChild(n.previousSibling);while(n.nextSibling)n.parentNode.removeChild(n.nextSibling);if(n.pmViewDesc)n.pmViewDesc=undefined}let r=new Cs(this,n,e,s);t.input.compositionNodes.push(r);this.children=Gs(this.children,i,i+s.length,t,r)}update(t,e,i,s){if(this.dirty==Es||!t.sameMarkup(this.node))return false;this.updateInner(t,e,i,s);return true}updateInner(t,e,i,s){this.updateOuterDeco(e);this.node=t;this.innerDeco=i;if(this.contentDOM)this.updateChildren(s,this.posAtStart);this.dirty=Ss}updateOuterDeco(t){if(Ws(t,this.outerDeco))return;let e=this.nodeDOM.nodeType!=1;let i=this.dom;this.dom=Ls(this.dom,this.nodeDOM,$s(this.outerDeco,this.node,e),$s(t,this.node,e));if(this.dom!=i){i.pmViewDesc=undefined;this.dom.pmViewDesc=this}this.outerDeco=t}selectNode(){if(this.nodeDOM.nodeType==1){this.nodeDOM.classList.add("ProseMirror-selectednode");if(this.contentDOM||!this.node.type.spec.draggable)this.nodeDOM.draggable=true}}deselectNode(){if(this.nodeDOM.nodeType==1){this.nodeDOM.classList.remove("ProseMirror-selectednode");if(this.contentDOM||!this.node.type.spec.draggable)this.nodeDOM.removeAttribute("draggable")}}get domAtom(){return this.node.isAtom}}function Is(t,e,i,s,n){Js(s,e,t);let r=new Us(undefined,t,e,i,s,s,s,n,0);if(r.contentDOM)r.updateChildren(n,0);return r}class Ns extends Us{constructor(t,e,i,s,n,r,o){super(t,e,i,s,n,null,r,o,0)}parseRule(){let t=this.nodeDOM.parentNode;while(t&&t!=this.dom&&!t.pmIsDeco)t=t.parentNode;return{skip:t||true}}update(t,e,i,s){if(this.dirty==Es||this.dirty!=Ss&&!this.inParent()||!t.sameMarkup(this.node))return false;this.updateOuterDeco(e);if((this.dirty!=Ss||t.text!=this.node.text)&&t.text!=this.nodeDOM.nodeValue){this.nodeDOM.nodeValue=t.text;if(s.trackWrites==this.nodeDOM)s.trackWrites=null}this.node=t;this.dirty=Ss;return true}inParent(){let t=this.parent.contentDOM;for(let e=this.nodeDOM;e;e=e.parentNode)if(e==t)return true;return false}domFromPos(t){return{node:this.nodeDOM,offset:t}}localPosFromDOM(t,e,i){if(t==this.nodeDOM)return this.posAtStart+Math.min(e,this.node.text.length);return super.localPosFromDOM(t,e,i)}ignoreMutation(t){return t.type!="characterData"&&t.type!="selection"}slice(t,e,i){let s=this.node.cut(t,e),n=document.createTextNode(s.text);return new Ns(this.parent,s,this.outerDeco,this.innerDeco,n,n,i)}markDirty(t,e){super.markDirty(t,e);if(this.dom!=this.nodeDOM&&(t==0||e==this.nodeDOM.nodeValue.length))this.dirty=Es}get domAtom(){return false}isText(t){return this.node.text==t}}class Ps extends Ds{parseRule(){return{ignore:true}}matchesHack(t){return this.dirty==Ss&&this.dom.nodeName==t}get domAtom(){return true}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class Fs extends Us{constructor(t,e,i,s,n,r,o,l,h,f){super(t,e,i,s,n,r,o,h,f);this.spec=l}update(t,e,i,s){if(this.dirty==Es)return false;if(this.spec.update&&(this.node.type==t.type||this.spec.multiType)){let n=this.spec.update(t,e,i);if(n)this.updateInner(t,e,i,s);return n}else if(!this.contentDOM&&!t.isLeaf){return false}else{return 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(){if(this.spec.destroy)this.spec.destroy();super.destroy()}stopEvent(t){return this.spec.stopEvent?this.spec.stopEvent(t):false}ignoreMutation(t){return this.spec.ignoreMutation?this.spec.ignoreMutation(t):super.ignoreMutation(t)}}function Bs(t,e,i){let s=t.firstChild,n=false;for(let r=0;r<e.length;r++){let o=e[r],l=o.dom;if(l.parentNode==t){while(l!=s){s=Qs(s);n=true}s=s.nextSibling}else{n=true;t.insertBefore(l,s)}if(o instanceof Rs){let e=s?s.previousSibling:t.lastChild;Bs(o.contentDOM,o.children,i);s=e?e.nextSibling:t.firstChild}}while(s){s=Qs(s);n=true}if(n&&i.trackWrites==t)i.trackWrites=null}const js=function(t){if(t)this.nodeName=t};js.prototype=Object.create(null);const _s=[new js];function $s(t,e,i){if(t.length==0)return _s;let s=i?_s[0]:new js,n=[s];for(let r=0;r<t.length;r++){let o=t[r].type.attrs;if(!o)continue;if(o.nodeName)n.push(s=new js(o.nodeName));for(let t in o){let r=o[t];if(r==null)continue;if(i&&n.length==1)n.push(s=new js(e.isInline?"span":"div"));if(t=="class")s.class=(s.class?s.class+" ":"")+r;else if(t=="style")s.style=(s.style?s.style+";":"")+r;else if(t!="nodeName")s[t]=r}}return n}function Ls(t,e,i,s){if(i==_s&&s==_s)return e;let n=e;for(let e=0;e<s.length;e++){let r=s[e],o=i[e];if(e){let e;if(o&&o.nodeName==r.nodeName&&n!=t&&(e=n.parentNode)&&e.nodeName.toLowerCase()==r.nodeName){n=e}else{e=document.createElement(r.nodeName);e.pmIsDeco=true;e.appendChild(n);o=_s[0];n=e}}zs(n,o||_s[0],r)}return n}function zs(t,e,i){for(let s in e)if(s!="class"&&s!="style"&&s!="nodeName"&&!(s in i))t.removeAttribute(s);for(let s in i)if(s!="class"&&s!="style"&&s!="nodeName"&&i[s]!=e[s])t.setAttribute(s,i[s]);if(e.class!=i.class){let s=e.class?e.class.split(" ").filter(Boolean):[];let n=i.class?i.class.split(" ").filter(Boolean):[];for(let e=0;e<s.length;e++)if(n.indexOf(s[e])==-1)t.classList.remove(s[e]);for(let e=0;e<n.length;e++)if(s.indexOf(n[e])==-1)t.classList.add(n[e]);if(t.classList.length==0)t.removeAttribute("class")}if(e.style!=i.style){if(e.style){let i=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,s;while(s=i.exec(e.style))t.style.removeProperty(s[1])}if(i.style)t.style.cssText+=i.style}}function Js(t,e,i){return Ls(t,t,_s,$s(e,i,t.nodeType!=1))}function Ws(t,e){if(t.length!=e.length)return false;for(let i=0;i<t.length;i++)if(!t[i].type.eq(e[i].type))return false;return true}function Qs(t){let e=t.nextSibling;t.parentNode.removeChild(t);return e}class Hs{constructor(t,e,i){this.lock=e;this.view=i;this.index=0;this.stack=[];this.changed=false;this.top=t;this.preMatch=qs(t.node.content,t)}destroyBetween(t,e){if(t==e)return;for(let i=t;i<e;i++)this.top.children[i].destroy();this.top.children.splice(t,e-t);this.changed=true}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(t,e,i){let s=0,n=this.stack.length>>1;let r=Math.min(n,t.length);while(s<r&&(s==n-1?this.top:this.stack[s+1<<1]).matchesMark(t[s])&&t[s].type.spec.spanning!==false)s++;while(s<n){this.destroyRest();this.top.dirty=Ss;this.index=this.stack.pop();this.top=this.stack.pop();n--}while(n<t.length){this.stack.push(this.top,this.index+1);let s=-1;for(let e=this.index;e<Math.min(this.index+3,this.top.children.length);e++){let i=this.top.children[e];if(i.matchesMark(t[n])&&!this.isLocked(i.dom)){s=e;break}}if(s>-1){if(s>this.index){this.changed=true;this.destroyBetween(this.index,s)}this.top=this.top.children[this.index]}else{let s=Rs.create(this.top,t[n],e,i);this.top.children.splice(this.index,0,s);this.top=s;this.changed=true}this.index=0;n++}}findNodeMatch(t,e,i,s){let n=-1,r;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}}}if(n<0)return false;this.destroyBetween(this.index,n);this.index++;return true}updateNodeAt(t,e,i,s,n){let r=this.top.children[s];if(r.dirty==Es&&r.dom==r.contentDOM)r.dirty=Os;if(!r.update(t,e,i,n))return false;this.destroyBetween(this.index,s);this.index++;return true}findIndexWithChild(t){for(;;){let e=t.parentNode;if(!e)return-1;if(e==this.top.contentDOM){let e=t.pmViewDesc;if(e)for(let t=this.index;t<this.top.children.length;t++){if(this.top.children[t]==e)return t}return-1}t=e}}updateNextNode(t,e,i,s,n,r){for(let o=this.index;o<this.top.children.length;o++){let l=this.top.children[o];if(l instanceof Us){let h=this.preMatch.matched.get(l);if(h!=null&&h!=n)return false;let f=l.dom,u;let c=this.isLocked(f)&&!(t.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==t.text&&l.dirty!=Es&&Ws(e,l.outerDeco));if(!c&&l.update(t,e,i,s)){this.destroyBetween(this.index,o);if(l.dom!=f)this.changed=true;this.index++;return true}else if(!c&&(u=this.recreateWrapper(l,t,e,i,s,r))){this.destroyBetween(this.index,o);this.top.children[this.index]=u;if(u.contentDOM){u.dirty=Os;u.updateChildren(s,r+1);u.dirty=Ss}this.changed=true;this.index++;return true}break}}return false}recreateWrapper(t,e,i,s,n,r){if(t.dirty||e.isAtom||!t.children.length||!t.node.content.eq(e.content)||!Ws(i,t.outerDeco)||!s.eq(t.innerDeco))return null;let o=Us.create(this.top,e,i,s,n,r);if(o.contentDOM){o.children=t.children;t.children=[];for(let t of o.children)t.parent=o}t.destroy();return o}addNode(t,e,i,s,n){let r=Us.create(this.top,t,e,i,s,n);if(r.contentDOM)r.updateChildren(s,n+1);this.top.children.splice(this.index++,0,r);this.changed=true}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)){this.index++}else{let s=new Ts(this.top,t,e,i);this.top.children.splice(this.index++,0,s);this.changed=true}}addTextblockHacks(){let t=this.top.children[this.index-1],e=this.top;while(t instanceof Rs){e=t;t=e.children[e.children.length-1]}if(!t||!(t instanceof Ns)||/\n$/.test(t.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(t.node.text)){if((ji||Fi)&&t&&t.dom.contentEditable=="false")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);if(t=="IMG"){i.className="ProseMirror-separator";i.alt=""}if(t=="BR")i.className="ProseMirror-trailingBreak";let s=new Ps(this.top,[],i,null);if(e!=this.top)e.children.push(s);else e.children.splice(this.index++,0,s);this.changed=true}}isLocked(t){return this.lock&&(t==this.lock||t.nodeType==1&&t.contains(this.lock.parentNode))}}function qs(t,e){let i=e,s=i.children.length;let n=t.childCount,r=new Map,o=[];t:while(n>0){let l;for(;;){if(s){let t=i.children[s-1];if(t instanceof Rs){i=t;s=t.children.length}else{l=t;s--;break}}else if(i==e){break t}else{s=i.parent.children.indexOf(i);i=i.parent}}let h=l.node;if(!h)continue;if(h!=t.child(n-1))break;--n;r.set(l,n);o.push(l)}return{index:n,matched:r,matches:o.reverse()}}function Vs(t,e){return t.type.side-e.type.side}function Ks(t,e,i,s){let n=e.locals(t),r=0;if(n.length==0){for(let i=0;i<t.childCount;i++){let o=t.child(i);s(o,n,e.forChild(r,o),i);r+=o.nodeSize}return}let o=0,l=[],h=null;for(let f=0;;){let u,c;while(o<n.length&&n[o].to==r){let t=n[o++];if(t.widget){if(!u)u=t;else(c||(c=[u])).push(t)}}if(u){if(c){c.sort(Vs);for(let t=0;t<c.length;t++)i(c[t],f,!!h)}else{i(u,f,!!h)}}let a,d;if(h){d=-1;a=h;h=null}else if(f<t.childCount){d=f;a=t.child(f++)}else{break}for(let t=0;t<l.length;t++)if(l[t].to<=r)l.splice(t--,1);while(o<n.length&&n[o].from<=r&&n[o].to>r)l.push(n[o++]);let w=r+a.nodeSize;if(a.isText){let t=w;if(o<n.length&&n[o].from<t)t=n[o].from;for(let e=0;e<l.length;e++)if(l[e].to<t)t=l[e].to;if(t<w){h=a.cut(t-r);a=a.cut(0,t-r);w=t;d=-1}}else{while(o<n.length&&n[o].to<w)o++}let p=a.isInline&&!a.isLeaf?l.filter((t=>!t.inline)):l.slice();s(a,p,e.forChild(r,a),d);r=w}}function Ys(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important";window.getComputedStyle(t).listStyle;t.style.cssText=e}}function Xs(t,e,i,s){for(let n=0,r=0;n<t.childCount&&r<=s;){let o=t.child(n++),l=r;r+=o.nodeSize;if(!o.isText)continue;let h=o.text;while(n<t.childCount){let e=t.child(n++);r+=e.nodeSize;if(!e.isText)break;h+=e.text}if(r>=i){if(r>=s&&h.slice(s-e.length-l,s-l)==e)return s-e.length;let t=l<s?h.lastIndexOf(e,s-l-1):-1;if(t>=0&&t+e.length+l>=i)return l+t;if(i==s&&h.length>=s+e.length-l&&h.slice(s-l,s-l+e.length)==e)return s}}return-1}function Gs(t,e,i,s,n){let r=[];for(let o=0,l=0;o<t.length;o++){let h=t[o],f=l,u=l+=h.size;if(f>=i||u<=e){r.push(h)}else{if(f<e)r.push(h.slice(0,e-f,s));if(n){r.push(n);n=undefined}if(u>i)r.push(h.slice(i-f,h.size,s))}}return r}function Zs(t,e=null){let i=t.domSelectionRange(),s=t.state.doc;if(!i.focusNode)return null;let n=t.docView.nearestDesc(i.focusNode),r=n&&n.size==0;let o=t.docView.posFromDOM(i.focusNode,i.focusOffset,1);if(o<0)return null;let l=s.resolve(o),h,f;if(Mi(i)){h=o;while(n&&!n.node)n=n.parent;let t=n.node;if(n&&t.isAtom&&We.isSelectable(t)&&n.parent&&!(t.isInline&&vi(i.focusNode,i.focusOffset,n.dom))){let t=n.posBefore;f=new We(o==t?l:s.resolve(t))}}else{if(i instanceof t.dom.ownerDocument.defaultView.Selection&&i.rangeCount>1){let e=o,n=o;for(let s=0;s<i.rangeCount;s++){let r=i.getRangeAt(s);e=Math.min(e,t.docView.posFromDOM(r.startContainer,r.startOffset,1));n=Math.max(n,t.docView.posFromDOM(r.endContainer,r.endOffset,-1))}if(e<0)return null;[h,o]=n==t.state.selection.anchor?[n,e]:[e,n];l=s.resolve(o)}else{h=t.docView.posFromDOM(i.anchorNode,i.anchorOffset,1)}if(h<0)return null}let u=s.resolve(h);if(!f){let i=e=="pointer"||t.state.selection.head<l.pos&&!r?1:-1;f=cn(t,u,l,i)}return f}function tn(t){return t.editable?t.hasFocus():dn(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function en(t,e=false){let i=t.state.selection;fn(t,i);if(!tn(t))return;if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&Fi){let e=t.domSelectionRange(),i=t.domObserver.currentSelection;if(e.anchorNode&&i.anchorNode&&wi(e.anchorNode,e.anchorOffset,i.anchorNode,i.anchorOffset)){t.input.mouseDown.delayedSelectionSync=true;t.domObserver.setCurSelection();return}}t.domObserver.disconnectSelection();if(t.cursorWrapper){hn(t)}else{let{anchor:s,head:n}=i,r,o;if(sn&&!(i instanceof ze)){if(!i.$from.parent.inlineContent)r=nn(t,i.from);if(!i.empty&&!i.$from.parent.inlineContent)o=nn(t,i.to)}t.docView.setSelection(s,n,t,e);if(sn){if(r)on(r);if(o)on(o)}if(i.visible){t.dom.classList.remove("ProseMirror-hideselection")}else{t.dom.classList.add("ProseMirror-hideselection");if("onselectionchange"in document)ln(t)}}t.domObserver.setCurSelection();t.domObserver.connectSelection()}const sn=ji||Fi&&Bi<63;function nn(t,e){let{node:i,offset:s}=t.docView.domFromPos(e,0);let n=s<i.childNodes.length?i.childNodes[s]:null;let r=s?i.childNodes[s-1]:null;if(ji&&n&&n.contentEditable=="false")return rn(n);if((!n||n.contentEditable=="false")&&(!r||r.contentEditable=="false")){if(n)return rn(n);else if(r)return rn(r)}}function rn(t){t.contentEditable="true";if(ji&&t.draggable){t.draggable=false;t.wasDraggable=true}return t}function on(t){t.contentEditable="false";if(t.wasDraggable){t.draggable=true;t.wasDraggable=null}}function ln(t){let e=t.dom.ownerDocument;e.removeEventListener("selectionchange",t.input.hideSelectionGuard);let i=t.domSelectionRange();let s=i.anchorNode,n=i.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{if(i.anchorNode!=s||i.anchorOffset!=n){e.removeEventListener("selectionchange",t.input.hideSelectionGuard);setTimeout((()=>{if(!tn(t)||t.state.selection.visible)t.dom.classList.remove("ProseMirror-hideselection")}),20)}})}function hn(t){let e=t.domSelection();if(!e)return;let i=t.cursorWrapper.dom,s=i.nodeName=="IMG";if(s)e.collapse(i.parentNode,fi(i)+1);else e.collapse(i,0);if(!s&&!t.state.selection.visible&&Ui&&Ii<=11){i.disabled=true;i.disabled=false}}function fn(t,e){if(e instanceof We){let i=t.docView.descAt(e.from);if(i!=t.lastSelectedViewDesc){un(t);if(i)i.selectNode();t.lastSelectedViewDesc=i}}else{un(t)}}function un(t){if(t.lastSelectedViewDesc){if(t.lastSelectedViewDesc.parent)t.lastSelectedViewDesc.deselectNode();t.lastSelectedViewDesc=undefined}}function cn(t,e,i,s){return t.someProp("createSelectionBetween",(s=>s(t,e,i)))||ze.between(e,i,s)}function an(t){if(t.editable&&!t.hasFocus())return false;return dn(t)}function dn(t){let e=t.domSelectionRange();if(!e.anchorNode)return false;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch(t){return false}}function wn(t){let e=t.docView.domFromPos(t.state.selection.anchor,0);let i=t.domSelectionRange();return wi(e.node,e.offset,i.anchorNode,i.anchorOffset)}function pn(t,e){let{$anchor:i,$head:s}=t.selection;let n=e>0?i.max(s):i.min(s);let r=!n.parent.inlineContent?n:n.depth?t.doc.resolve(e>0?n.after():n.before()):null;return r&&je.findFrom(r,e)}function gn(t,e){t.dispatch(t.state.tr.setSelection(e).scrollIntoView());return true}function mn(t,e,i){let s=t.state.selection;if(s instanceof ze){if(i.indexOf("s")>-1){let{$head:i}=s,n=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!n||n.isText||!n.isLeaf)return false;let r=t.state.doc.resolve(i.pos+n.nodeSize*(e<0?-1:1));return gn(t,new ze(s.$anchor,r))}else if(!s.empty){return false}else if(t.endOfTextblock(e>0?"forward":"backward")){let i=pn(t.state,e);if(i&&i instanceof We)return gn(t,i);return false}else if(!($i&&i.indexOf("m")>-1)){let i=s.$head,n=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,r;if(!n||n.isText)return false;let o=e<0?i.pos-n.nodeSize:i.pos;if(!(n.isAtom||(r=t.docView.descAt(o))&&!r.contentDOM))return false;if(We.isSelectable(n)){return gn(t,new We(e<0?t.state.doc.resolve(i.pos-n.nodeSize):i))}else if(Ji){return gn(t,new ze(t.state.doc.resolve(e<0?o:o+n.nodeSize)))}else{return false}}}else if(s instanceof We&&s.node.isInline){return gn(t,new ze(e>0?s.$to:s.$from))}else{let i=pn(t.state,e);if(i)return gn(t,i);return false}}function yn(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function bn(t,e){let i=t.pmViewDesc;return i&&i.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function vn(t,e){return e<0?An(t):Mn(t)}function An(t){let e=t.domSelectionRange();let i=e.focusNode,s=e.focusOffset;if(!i)return;let n,r,o=false;if(Ni&&i.nodeType==1&&s<yn(i)&&bn(i.childNodes[s],-1))o=true;for(;;){if(s>0){if(i.nodeType!=1){break}else{let t=i.childNodes[s-1];if(bn(t,-1)){n=i;r=--s}else if(t.nodeType==3){i=t;s=i.nodeValue.length}else break}}else if(kn(i)){break}else{let e=i.previousSibling;while(e&&bn(e,-1)){n=i.parentNode;r=fi(e);e=e.previousSibling}if(!e){i=i.parentNode;if(i==t.dom)break;s=0}else{i=e;s=yn(i)}}}if(o)On(t,i,s);else if(n)On(t,n,r)}function Mn(t){let e=t.domSelectionRange();let i=e.focusNode,s=e.focusOffset;if(!i)return;let n=yn(i);let r,o;for(;;){if(s<n){if(i.nodeType!=1)break;let t=i.childNodes[s];if(bn(t,1)){r=i;o=++s}else break}else if(kn(i)){break}else{let e=i.nextSibling;while(e&&bn(e,1)){r=e.parentNode;o=fi(e)+1;e=e.nextSibling}if(!e){i=i.parentNode;if(i==t.dom)break;s=n=0}else{i=e;s=0;n=yn(i)}}}if(r)On(t,r,o)}function kn(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function Sn(t,e){while(t&&e==t.childNodes.length&&!Ai(t)){e=fi(t)+1;t=t.parentNode}while(t&&e<t.childNodes.length){let i=t.childNodes[e];if(i.nodeType==3)return i;if(i.nodeType==1&&i.contentEditable=="false")break;t=i;e=0}}function xn(t,e){while(t&&!e&&!Ai(t)){e=fi(t);t=t.parentNode}while(t&&e){let i=t.childNodes[e-1];if(i.nodeType==3)return i;if(i.nodeType==1&&i.contentEditable=="false")break;t=i;e=t.childNodes.length}}function On(t,e,i){if(e.nodeType!=3){let t,s;if(s=Sn(e,i)){e=s;i=0}else if(t=xn(e,i)){e=t;i=t.nodeValue.length}}let s=t.domSelection();if(!s)return;if(Mi(s)){let t=document.createRange();t.setEnd(e,i);t.setStart(e,i);s.removeAllRanges();s.addRange(t)}else if(s.extend){s.extend(e,i)}t.domObserver.setCurSelection();let{state:n}=t;setTimeout((()=>{if(t.state==n)en(t)}),50)}function En(t,e){let i=t.state.doc.resolve(e);if(!(Fi||Li)&&i.parent.inlineContent){let s=t.coordsAtPos(e);if(e>i.start()){let i=t.coordsAtPos(e-1);let n=(i.top+i.bottom)/2;if(n>s.top&&n<s.bottom&&Math.abs(i.left-s.left)>1)return i.left<s.left?"ltr":"rtl"}if(e<i.end()){let i=t.coordsAtPos(e+1);let n=(i.top+i.bottom)/2;if(n>s.top&&n<s.bottom&&Math.abs(i.left-s.left)>1)return i.left>s.left?"ltr":"rtl"}}let s=getComputedStyle(t.dom).direction;return s=="rtl"?"rtl":"ltr"}function Dn(t,e,i){let s=t.state.selection;if(s instanceof ze&&!s.empty||i.indexOf("s")>-1)return false;if($i&&i.indexOf("m")>-1)return false;let{$from:n,$to:r}=s;if(!n.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let i=pn(t.state,e);if(i&&i instanceof We)return gn(t,i)}if(!n.parent.inlineContent){let i=e<0?n:r;let o=s instanceof He?je.near(i,e):je.findFrom(i,e);return o?gn(t,o):false}return false}function Tn(t,e){if(!(t.state.selection instanceof ze))return true;let{$head:i,$anchor:s,empty:n}=t.state.selection;if(!i.sameParent(s))return true;if(!n)return false;if(t.endOfTextblock(e>0?"forward":"backward"))return true;let r=!i.textOffset&&(e<0?i.nodeBefore:i.nodeAfter);if(r&&!r.isText){let s=t.state.tr;if(e<0)s.delete(i.pos-r.nodeSize,i.pos);else s.delete(i.pos,i.pos+r.nodeSize);t.dispatch(s);return true}return false}function Cn(t,e,i){t.domObserver.stop();e.contentEditable=i;t.domObserver.start()}function Rn(t){if(!ji||t.state.selection.$head.parentOffset>0)return false;let{focusNode:e,focusOffset:i}=t.domSelectionRange();if(e&&e.nodeType==1&&i==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let i=e.firstChild;Cn(t,i,"true");setTimeout((()=>Cn(t,i,"false")),20)}return false}function Un(t){let e="";if(t.ctrlKey)e+="c";if(t.metaKey)e+="m";if(t.altKey)e+="a";if(t.shiftKey)e+="s";return e}function In(t,e){let i=e.keyCode,s=Un(e);if(i==8||$i&&i==72&&s=="c"){return Tn(t,-1)||vn(t,-1)}else if(i==46&&!e.shiftKey||$i&&i==68&&s=="c"){return Tn(t,1)||vn(t,1)}else if(i==13||i==27){return true}else if(i==37||$i&&i==66&&s=="c"){let e=i==37?En(t,t.state.selection.from)=="ltr"?-1:1:-1;return mn(t,e,s)||vn(t,e)}else if(i==39||$i&&i==70&&s=="c"){let e=i==39?En(t,t.state.selection.from)=="ltr"?1:-1:1;return mn(t,e,s)||vn(t,e)}else if(i==38||$i&&i==80&&s=="c"){return Dn(t,-1,s)||vn(t,-1)}else if(i==40||$i&&i==78&&s=="c"){return Rn(t)||Dn(t,1,s)||vn(t,1)}else if(s==($i?"m":"c")&&(i==66||i==73||i==89||i==90)){return true}return false}function Nn(t,e){t.someProp("transformCopied",(i=>{e=i(e,t)}));let i=[],{content:s,openStart:n,openEnd:r}=e;while(n>1&&r>1&&s.childCount==1&&s.firstChild.childCount==1){n--;r--;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")||Mt.fromSchema(t.state.schema);let l=Qn(),h=l.createElement("div");h.appendChild(o.serializeFragment(s,{document:l}));let f=h.firstChild,u,c=0;while(f&&f.nodeType==1&&(u=Jn[f.nodeName.toLowerCase()])){for(let t=u.length-1;t>=0;t--){let e=l.createElement(u[t]);while(h.firstChild)e.appendChild(h.firstChild);h.appendChild(e);c++}f=h.firstChild}if(f&&f.nodeType==1)f.setAttribute("data-pm-slice",`${n} ${r}${c?` -${c}`:""} ${JSON.stringify(i)}`);let a=t.someProp("clipboardTextSerializer",(i=>i(e,t)))||e.content.textBetween(0,e.content.size,"\n\n");return{dom:h,text:a,slice:e}}function Pn(t,e,i,s,n){let r=n.parent.type.spec.code;let o,l;if(!i&&!e)return null;let f=!!e&&(s||r||!i);if(f){t.someProp("transformPastedText",(i=>{e=i(e,r||s,t)}));if(r){l=new w(h.from(t.state.schema.text(e.replace(/\r\n?/g,"\n"))),0,0);t.someProp("transformPasted",(e=>{l=e(l,t,true)}));return l}let i=t.someProp("clipboardTextParser",(i=>i(e,n,s,t)));if(i){l=i}else{let i=n.marks();let{schema:s}=t.state,r=Mt.fromSchema(s);o=document.createElement("div");e.split(/(?:\r\n?|\n)+/).forEach((t=>{let e=o.appendChild(document.createElement("p"));if(t)e.appendChild(r.serializeNode(s.text(t,i)))}))}}else{t.someProp("transformPastedHTML",(e=>{i=e(i,t)}));o=Vn(i);if(Ji)Kn(o)}let u=o&&o.querySelector("[data-pm-slice]");let c=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let t=+c[3];t>0;t--){let t=o.firstChild;while(t&&t.nodeType!=1)t=t.nextSibling;if(!t)break;o=t}if(!l){let e=t.someProp("clipboardParser")||t.someProp("domParser")||ht.fromSchema(t.state.schema);l=e.parseSlice(o,{preserveWhitespace:!!(f||c),context:n,ruleFromNode(t){if(t.nodeName=="BR"&&!t.nextSibling&&t.parentNode&&!Fn.test(t.parentNode.nodeName))return{ignore:true};return null}})}if(c){l=Yn(zn(l,+c[1],+c[2]),c[4])}else{l=w.maxOpen(Bn(l.content,n),true);if(l.openStart||l.openEnd){let t=0,e=0;for(let e=l.content.firstChild;t<l.openStart&&!e.type.spec.isolating;t++,e=e.firstChild){}for(let t=l.content.lastChild;e<l.openEnd&&!t.type.spec.isolating;e++,t=t.lastChild){}l=zn(l,t,e)}}t.someProp("transformPasted",(e=>{l=e(l,t,f)}));return l}const Fn=/^(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 Bn(t,e){if(t.childCount<2)return t;for(let i=e.depth;i>=0;i--){let s=e.node(i);let n=s.contentMatchAt(e.index(i));let r,o=[];t.forEach((t=>{if(!o)return;let e=n.findWrapping(t.type),i;if(!e)return o=null;if(i=o.length&&r.length&&_n(e,r,t,o[o.length-1],0)){o[o.length-1]=i}else{if(o.length)o[o.length-1]=$n(o[o.length-1],r.length);let i=jn(t,e);o.push(i);n=n.matchType(i.type);r=e}}));if(o)return h.from(o)}return t}function jn(t,e,i=0){for(let s=e.length-1;s>=i;s--)t=e[s].create(null,h.from(t));return t}function _n(t,e,i,s,n){if(n<t.length&&n<e.length&&t[n]==e[n]){let r=_n(t,e,i,s.lastChild,n+1);if(r)return s.copy(s.content.replaceChild(s.childCount-1,r));let o=s.contentMatchAt(s.childCount);if(o.matchType(n==t.length-1?i.type:t[n+1]))return s.copy(s.content.append(h.from(jn(i,t,n+1))))}}function $n(t,e){if(e==0)return t;let i=t.content.replaceChild(t.childCount-1,$n(t.lastChild,e-1));let s=t.contentMatchAt(t.childCount).fillBefore(h.empty,true);return t.copy(i.append(s))}function Ln(t,e,i,s,n,r){let o=e<0?t.firstChild:t.lastChild,l=o.content;if(t.childCount>1)r=0;if(n<s-1)l=Ln(l,e,i,s,n+1,r);if(n>=i)l=e<0?o.contentMatchAt(0).fillBefore(l,r<=n).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(h.empty,true));return t.replaceChild(e<0?0:t.childCount-1,o.copy(l))}function zn(t,e,i){if(e<t.openStart)t=new w(Ln(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd);if(i<t.openEnd)t=new w(Ln(t.content,1,i,t.openEnd,0,0),t.openStart,i);return t}const Jn={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 Wn=null;function Qn(){return Wn||(Wn=document.implementation.createHTMLDocument("title"))}let Hn=null;function qn(t){let e=window.trustedTypes;if(!e)return t;if(!Hn)Hn=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t});return Hn.createHTML(t)}function Vn(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);if(e)t=t.slice(e[0].length);let i=Qn().createElement("div");let s=/<([a-z][^>\s]+)/i.exec(t),n;if(n=s&&Jn[s[1].toLowerCase()])t=n.map((t=>"<"+t+">")).join("")+t+n.map((t=>"</"+t+">")).reverse().join("");i.innerHTML=qn(t);if(n)for(let t=0;t<n.length;t++)i=i.querySelector(n[t])||i;return i}function Kn(t){let e=t.querySelectorAll(Fi?"span:not([class]):not([style])":"span.Apple-converted-space");for(let i=0;i<e.length;i++){let s=e[i];if(s.childNodes.length==1&&s.textContent==" "&&s.parentNode)s.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),s)}}function Yn(t,e){if(!t.size)return t;let i=t.content.firstChild.type.schema,s;try{s=JSON.parse(e)}catch(e){return t}let{content:n,openStart:r,openEnd:o}=t;for(let t=s.length-2;t>=0;t-=2){let e=i.nodes[s[t]];if(!e||e.hasRequiredAttrs())break;n=h.from(e.create(s[t+1],n));r++;o++}return new w(n,r,o)}const Xn={};const Gn={};const Zn={touchstart:true,touchmove:true};class tr{constructor(){this.shiftKey=false;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=false;this.compositionNode=null;this.composingTimeout=-1;this.compositionNodes=[];this.compositionEndedAt=-2e8;this.compositionID=1;this.compositionPendingChanges=0;this.domChangeCount=0;this.eventHandlers=Object.create(null);this.hideSelectionGuard=null}}function er(t){for(let e in Xn){let i=Xn[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=e=>{if(or(t,e)&&!rr(t,e)&&(t.editable||!(e.type in Gn)))i(t,e)},Zn[e]?{passive:true}:undefined)}if(ji)t.dom.addEventListener("input",(()=>null));nr(t)}function ir(t,e){t.input.lastSelectionOrigin=e;t.input.lastSelectionTime=Date.now()}function sr(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)}function nr(t){t.someProp("handleDOMEvents",(e=>{for(let i in e)if(!t.input.eventHandlers[i])t.dom.addEventListener(i,t.input.eventHandlers[i]=e=>rr(t,e))}))}function rr(t,e){return t.someProp("handleDOMEvents",(i=>{let s=i[e.type];return s?s(t,e)||e.defaultPrevented:false}))}function or(t,e){if(!e.bubbles)return true;if(e.defaultPrevented)return false;for(let i=e.target;i!=t.dom;i=i.parentNode)if(!i||i.nodeType==11||i.pmViewDesc&&i.pmViewDesc.stopEvent(e))return false;return true}function lr(t,e){if(!rr(t,e)&&Xn[e.type]&&(t.editable||!(e.type in Gn)))Xn[e.type](t,e)}Gn.keydown=(t,e)=>{let i=e;t.input.shiftKey=i.keyCode==16||i.shiftKey;if(Ar(t,i))return;t.input.lastKeyCode=i.keyCode;t.input.lastKeyCodeTime=Date.now();if(zi&&Fi&&i.keyCode==13)return;if(i.keyCode!=229)t.domObserver.forceFlush();if(_i&&i.keyCode==13&&!i.ctrlKey&&!i.altKey&&!i.metaKey){let e=Date.now();t.input.lastIOSEnter=e;t.input.lastIOSEnterFallbackTimeout=setTimeout((()=>{if(t.input.lastIOSEnter==e){t.someProp("handleKeyDown",(e=>e(t,ki(13,"Enter"))));t.input.lastIOSEnter=0}}),200)}else if(t.someProp("handleKeyDown",(e=>e(t,i)))||In(t,i)){i.preventDefault()}else{ir(t,"key")}};Gn.keyup=(t,e)=>{if(e.keyCode==16)t.input.shiftKey=false};Gn.keypress=(t,e)=>{let i=e;if(Ar(t,i)||!i.charCode||i.ctrlKey&&!i.altKey||$i&&i.metaKey)return;if(t.someProp("handleKeyPress",(e=>e(t,i)))){i.preventDefault();return}let s=t.state.selection;if(!(s instanceof ze)||!s.$from.sameParent(s.$to)){let e=String.fromCharCode(i.charCode);let n=()=>t.state.tr.insertText(e).scrollIntoView();if(!/[\r\n]/.test(e)&&!t.someProp("handleTextInput",(i=>i(t,s.$from.pos,s.$to.pos,e,n))))t.dispatch(n());i.preventDefault()}};function hr(t){return{left:t.clientX,top:t.clientY}}function fr(t,e){let i=e.x-t.clientX,s=e.y-t.clientY;return i*i+s*s<100}function ur(t,e,i,s,n){if(s==-1)return false;let r=t.state.doc.resolve(s);for(let s=r.depth+1;s>0;s--){if(t.someProp(e,(e=>s>r.depth?e(t,i,r.nodeAfter,r.before(s),n,true):e(t,i,r.node(s),r.before(s),n,false))))return true}return false}function cr(t,e,i){if(!t.focused)t.focus();if(t.state.selection.eq(e))return;let s=t.state.tr.setSelection(e);s.setMeta("pointer",true);t.dispatch(s)}function ar(t,e){if(e==-1)return false;let i=t.state.doc.resolve(e),s=i.nodeAfter;if(s&&s.isAtom&&We.isSelectable(s)){cr(t,new We(i));return true}return false}function dr(t,e){if(e==-1)return false;let i=t.state.selection,s,n;if(i instanceof We)s=i.node;let r=t.state.doc.resolve(e);for(let t=r.depth+1;t>0;t--){let e=t>r.depth?r.nodeAfter:r.node(t);if(We.isSelectable(e)){if(s&&i.$from.depth>0&&t>=i.$from.depth&&r.before(i.$from.depth+1)==i.$from.pos)n=r.before(i.$from.depth);else n=r.before(t);break}}if(n!=null){cr(t,We.create(t.state.doc,n));return true}else{return false}}function wr(t,e,i,s,n){return ur(t,"handleClickOn",e,i,s)||t.someProp("handleClick",(i=>i(t,e,s)))||(n?dr(t,i):ar(t,i))}function pr(t,e,i,s){return ur(t,"handleDoubleClickOn",e,i,s)||t.someProp("handleDoubleClick",(i=>i(t,e,s)))}function gr(t,e,i,s){return ur(t,"handleTripleClickOn",e,i,s)||t.someProp("handleTripleClick",(i=>i(t,e,s)))||mr(t,i,s)}function mr(t,e,i){if(i.button!=0)return false;let s=t.state.doc;if(e==-1){if(s.inlineContent){cr(t,ze.create(s,0,s.content.size));return true}return false}let n=s.resolve(e);for(let e=n.depth+1;e>0;e--){let i=e>n.depth?n.nodeAfter:n.node(e);let r=n.before(e);if(i.inlineContent)cr(t,ze.create(s,r+1,r+1+i.content.size));else if(We.isSelectable(i))cr(t,We.create(s,r));else continue;return true}}function yr(t){return Er(t)}const br=$i?"metaKey":"ctrlKey";Xn.mousedown=(t,e)=>{let i=e;t.input.shiftKey=i.shiftKey;let s=yr(t);let n=Date.now(),r="singleClick";if(n-t.input.lastClick.time<500&&fr(i,t.input.lastClick)&&!i[br]&&t.input.lastClick.button==i.button){if(t.input.lastClick.type=="singleClick")r="doubleClick";else if(t.input.lastClick.type=="doubleClick")r="tripleClick"}t.input.lastClick={time:n,x:i.clientX,y:i.clientY,type:r,button:i.button};let o=t.posAtCoords(hr(i));if(!o)return;if(r=="singleClick"){if(t.input.mouseDown)t.input.mouseDown.done();t.input.mouseDown=new vr(t,o,i,!!s)}else if((r=="doubleClick"?pr:gr)(t,o.pos,o.inside,i)){i.preventDefault()}else{ir(t,"pointer")}};class vr{constructor(t,e,i,s){this.view=t;this.pos=e;this.event=i;this.flushed=s;this.delayedSelectionSync=false;this.mightDrag=null;this.startDoc=t.state.doc;this.selectNode=!!i[br];this.allowDefault=i.shiftKey;let n,r;if(e.inside>-1){n=t.state.doc.nodeAt(e.inside);r=e.inside}else{let i=t.state.doc.resolve(e.pos);n=i.parent;r=i.depth?i.before():0}const o=s?null:i.target;const l=o?t.docView.nearestDesc(o,true):null;this.target=l&&l.nodeDOM.nodeType==1?l.nodeDOM:null;let{selection:h}=t.state;if(i.button==0&&n.type.spec.draggable&&n.type.spec.selectable!==false||h instanceof We&&h.from<=r&&h.to>r)this.mightDrag={node:n,pos:r,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Ni&&!this.target.hasAttribute("contentEditable"))};if(this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)){this.view.domObserver.stop();if(this.mightDrag.addAttr)this.target.draggable=true;if(this.mightDrag.setUneditable)setTimeout((()=>{if(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));ir(t,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up);this.view.root.removeEventListener("mousemove",this.move);if(this.mightDrag&&this.target){this.view.domObserver.stop();if(this.mightDrag.addAttr)this.target.removeAttribute("draggable");if(this.mightDrag.setUneditable)this.target.removeAttribute("contentEditable");this.view.domObserver.start()}if(this.delayedSelectionSync)setTimeout((()=>en(this.view)));this.view.input.mouseDown=null}up(t){this.done();if(!this.view.dom.contains(t.target))return;let e=this.pos;if(this.view.state.doc!=this.startDoc)e=this.view.posAtCoords(hr(t));this.updateAllowDefault(t);if(this.allowDefault||!e){ir(this.view,"pointer")}else if(wr(this.view,e.pos,e.inside,t,this.selectNode)){t.preventDefault()}else if(t.button==0&&(this.flushed||ji&&this.mightDrag&&!this.mightDrag.node.isAtom||Fi&&!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)){cr(this.view,je.near(this.view.state.doc.resolve(e.pos)));t.preventDefault()}else{ir(this.view,"pointer")}}move(t){this.updateAllowDefault(t);ir(this.view,"pointer");if(t.buttons==0)this.done()}updateAllowDefault(t){if(!this.allowDefault&&(Math.abs(this.event.x-t.clientX)>4||Math.abs(this.event.y-t.clientY)>4))this.allowDefault=true}}Xn.touchstart=t=>{t.input.lastTouch=Date.now();yr(t);ir(t,"pointer")};Xn.touchmove=t=>{t.input.lastTouch=Date.now();ir(t,"pointer")};Xn.contextmenu=t=>yr(t);function Ar(t,e){if(t.composing)return true;if(ji&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500){t.input.compositionEndedAt=-2e8;return true}return false}const Mr=zi?5e3:-1;Gn.compositionstart=Gn.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,i=e.selection.$to;if(e.selection instanceof ze&&(e.storedMarks||!i.textOffset&&i.parentOffset&&i.nodeBefore.marks.some((t=>t.type.spec.inclusive===false)))){t.markCursor=t.state.storedMarks||i.marks();Er(t,true);t.markCursor=null}else{Er(t,!e.selection.empty);if(Ni&&e.selection.empty&&i.parentOffset&&!i.textOffset&&i.nodeBefore.marks.length){let e=t.domSelectionRange();for(let i=e.focusNode,s=e.focusOffset;i&&i.nodeType==1&&s!=0;){let e=s<0?i.lastChild:i.childNodes[s-1];if(!e)break;if(e.nodeType==3){let i=t.domSelection();if(i)i.collapse(e,e.nodeValue.length);break}else{i=e;s=-1}}}}t.input.composing=true}kr(t,Mr)};Gn.compositionend=(t,e)=>{if(t.composing){t.input.composing=false;t.input.compositionEndedAt=e.timeStamp;t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0;t.input.compositionNode=null;if(t.input.compositionPendingChanges)Promise.resolve().then((()=>t.domObserver.flush()));t.input.compositionID++;kr(t,20)}};function kr(t,e){clearTimeout(t.input.composingTimeout);if(e>-1)t.input.composingTimeout=setTimeout((()=>Er(t)),e)}function Sr(t){if(t.composing){t.input.composing=false;t.input.compositionEndedAt=Or()}while(t.input.compositionNodes.length>0)t.input.compositionNodes.pop().markParentsDirty()}function xr(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let i=yi(e.focusNode,e.focusOffset);let s=bi(e.focusNode,e.focusOffset);if(i&&s&&i!=s){let e=s.pmViewDesc,n=t.domObserver.lastChangedTextNode;if(i==n||s==n)return n;if(!e||!e.isText(s.nodeValue)){return s}else if(t.input.compositionNode==s){let t=i.pmViewDesc;if(!(!t||!t.isText(i.nodeValue)))return s}}return i||s}function Or(){let t=document.createEvent("Event");t.initEvent("event",true,true);return t.timeStamp}function Er(t,e=false){if(zi&&t.domObserver.flushingSoon>=0)return;t.domObserver.forceFlush();Sr(t);if(e||t.docView&&t.docView.dirty){let i=Zs(t),s=t.state.selection;if(i&&!i.eq(s))t.dispatch(t.state.tr.setSelection(i));else if((t.markCursor||e)&&!s.$from.node(s.$from.sharedDepth(s.to)).inlineContent)t.dispatch(t.state.tr.deleteSelection());else t.updateState(t.state);return true}return false}function Dr(t,e){if(!t.dom.parentNode)return;let i=t.dom.parentNode.appendChild(document.createElement("div"));i.appendChild(e);i.style.cssText="position: fixed; left: -10000px; top: 10px";let s=getSelection(),n=document.createRange();n.selectNodeContents(e);t.dom.blur();s.removeAllRanges();s.addRange(n);setTimeout((()=>{if(i.parentNode)i.parentNode.removeChild(i);t.focus()}),50)}const Tr=Ui&&Ii<15||_i&&Wi<604;Xn.copy=Gn.cut=(t,e)=>{let i=e;let s=t.state.selection,n=i.type=="cut";if(s.empty)return;let r=Tr?null:i.clipboardData;let o=s.content(),{dom:l,text:h}=Nn(t,o);if(r){i.preventDefault();r.clearData();r.setData("text/html",l.innerHTML);r.setData("text/plain",h)}else{Dr(t,l)}if(n)t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Cr(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function Rr(t,e){if(!t.dom.parentNode)return;let i=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code;let s=t.dom.parentNode.appendChild(document.createElement(i?"textarea":"div"));if(!i)s.contentEditable="true";s.style.cssText="position: fixed; left: -10000px; top: 10px";s.focus();let n=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout((()=>{t.focus();if(s.parentNode)s.parentNode.removeChild(s);if(i)Ur(t,s.value,null,n,e);else Ur(t,s.textContent,s.innerHTML,n,e)}),50)}function Ur(t,e,i,s,n){let r=Pn(t,e,i,s,t.state.selection.$from);if(t.someProp("handlePaste",(e=>e(t,n,r||w.empty))))return true;if(!r)return false;let o=Cr(r);let l=o?t.state.tr.replaceSelectionWith(o,s):t.state.tr.replaceSelection(r);t.dispatch(l.scrollIntoView().setMeta("paste",true).setMeta("uiEvent","paste"));return true}function Ir(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," "):""}Gn.paste=(t,e)=>{let i=e;if(t.composing&&!zi)return;let s=Tr?null:i.clipboardData;let n=t.input.shiftKey&&t.input.lastKeyCode!=45;if(s&&Ur(t,Ir(s),s.getData("text/html"),n,i))i.preventDefault();else Rr(t,i)};class Nr{constructor(t,e,i){this.slice=t;this.move=e;this.node=i}}const Pr=$i?"altKey":"ctrlKey";function Fr(t,e){let i=t.someProp("dragCopies",(t=>!t(e)));return i!=null?i:!e[Pr]}Xn.dragstart=(t,e)=>{let i=e;let s=t.input.mouseDown;if(s)s.done();if(!i.dataTransfer)return;let n=t.state.selection;let r=n.empty?null:t.posAtCoords(hr(i));let o;if(r&&r.pos>=n.from&&r.pos<=(n instanceof We?n.to-1:n.to));else if(s&&s.mightDrag){o=We.create(t.state.doc,s.mightDrag.pos)}else if(i.target&&i.target.nodeType==1){let e=t.docView.nearestDesc(i.target,true);if(e&&e.node.type.spec.draggable&&e!=t.docView)o=We.create(t.state.doc,e.posBefore)}let l=(o||t.state.selection).content();let{dom:h,text:f,slice:u}=Nn(t,l);if(!i.dataTransfer.files.length||!Fi||Bi>120)i.dataTransfer.clearData();i.dataTransfer.setData(Tr?"Text":"text/html",h.innerHTML);i.dataTransfer.effectAllowed="copyMove";if(!Tr)i.dataTransfer.setData("text/plain",f);t.dragging=new Nr(u,Fr(t,i),o)};Xn.dragend=t=>{let e=t.dragging;window.setTimeout((()=>{if(t.dragging==e)t.dragging=null}),50)};Gn.dragover=Gn.dragenter=(t,e)=>e.preventDefault();Gn.drop=(t,e)=>{let i=e;let s=t.dragging;t.dragging=null;if(!i.dataTransfer)return;let n=t.posAtCoords(hr(i));if(!n)return;let r=t.state.doc.resolve(n.pos);let o=s&&s.slice;if(o){t.someProp("transformPasted",(e=>{o=e(o,t,false)}))}else{o=Pn(t,Ir(i.dataTransfer),Tr?null:i.dataTransfer.getData("text/html"),false,r)}let l=!!(s&&Fr(t,i));if(t.someProp("handleDrop",(e=>e(t,i,o||w.empty,l)))){i.preventDefault();return}if(!o)return;i.preventDefault();let h=o?me(t.state.doc,r.pos,o):r.pos;if(h==null)h=r.pos;let f=t.state.tr;if(l){let{node:t}=s;if(t)t.replace(f);else f.deleteSelection()}let u=f.mapping.map(h);let c=o.openStart==0&&o.openEnd==0&&o.content.childCount==1;let a=f.doc;if(c)f.replaceRangeWith(u,u,o.content.firstChild);else f.replaceRange(u,u,o);if(f.doc.eq(a))return;let d=f.doc.resolve(u);if(c&&We.isSelectable(o.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(o.content.firstChild)){f.setSelection(new We(d))}else{let e=f.mapping.map(h);f.mapping.maps[f.mapping.maps.length-1].forEach(((t,i,s,n)=>e=n));f.setSelection(cn(t,d,f.doc.resolve(e)))}t.focus();t.dispatch(f.setMeta("uiEvent","drop"))};Xn.focus=t=>{t.input.lastFocus=Date.now();if(!t.focused){t.domObserver.stop();t.dom.classList.add("ProseMirror-focused");t.domObserver.start();t.focused=true;setTimeout((()=>{if(t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange()))en(t)}),20)}};Xn.blur=(t,e)=>{let i=e;if(t.focused){t.domObserver.stop();t.dom.classList.remove("ProseMirror-focused");t.domObserver.start();if(i.relatedTarget&&t.dom.contains(i.relatedTarget))t.domObserver.currentSelection.clear();t.focused=false}};Xn.beforeinput=(t,e)=>{let i=e;if(Fi&&zi&&i.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:e}=t.input;setTimeout((()=>{if(t.input.domChangeCount!=e)return;t.dom.blur();t.focus();if(t.someProp("handleKeyDown",(e=>e(t,ki(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;if(i&&i.pos>0)t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())}),50)}};for(let t in Gn)Xn[t]=Gn[t];function Br(t,e){if(t==e)return true;for(let i in t)if(t[i]!==e[i])return false;for(let i in e)if(!(i in t))return false;return true}class jr{constructor(t,e){this.toDOM=t;this.spec=e||Jr;this.side=this.spec.side||0}map(t,e,i,s){let{pos:n,deleted:r}=t.mapResult(e.from+s,this.side<0?-1:1);return r?null:new Lr(n-i,n-i,this)}valid(){return true}eq(t){return this==t||t instanceof jr&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&Br(this.spec,t.spec))}destroy(t){if(this.spec.destroy)this.spec.destroy(t)}}class _r{constructor(t,e){this.attrs=t;this.spec=e||Jr}map(t,e,i,s){let n=t.map(e.from+s,this.spec.inclusiveStart?-1:1)-i;let r=t.map(e.to+s,this.spec.inclusiveEnd?1:-1)-i;return n>=r?null:new Lr(n,r,this)}valid(t,e){return e.from<e.to}eq(t){return this==t||t instanceof _r&&Br(this.attrs,t.attrs)&&Br(this.spec,t.spec)}static is(t){return t.type instanceof _r}destroy(){}}class $r{constructor(t,e){this.attrs=t;this.spec=e||Jr}map(t,e,i,s){let n=t.mapResult(e.from+s,1);if(n.deleted)return null;let r=t.mapResult(e.to+s,-1);if(r.deleted||r.pos<=n.pos)return null;return new Lr(n.pos-i,r.pos-i,this)}valid(t,e){let{index:i,offset:s}=t.content.findIndex(e.from),n;return s==e.from&&!(n=t.child(i)).isText&&s+n.nodeSize==e.to}eq(t){return this==t||t instanceof $r&&Br(this.attrs,t.attrs)&&Br(this.spec,t.spec)}destroy(){}}class Lr{constructor(t,e,i){this.from=t;this.to=e;this.type=i}copy(t,e){return new Lr(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 Lr(t,t,new jr(e,i))}static inline(t,e,i,s){return new Lr(t,e,new _r(i,s))}static node(t,e,i,s){return new Lr(t,e,new $r(i,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof _r}get widget(){return this.type instanceof jr}}const zr=[],Jr={};class Wr{constructor(t,e){this.local=t.length?t:zr;this.children=e.length?e:zr}static create(t,e){return e.length?Gr(e,t,0,Jr):Qr}find(t,e,i){let s=[];this.findInner(t==null?0:t,e==null?1e9:e,s,0,i);return s}findInner(t,e,i,s,n){for(let r=0;r<this.local.length;r++){let o=this.local[r];if(o.from<=e&&o.to>=t&&(!n||n(o.spec)))i.push(o.copy(o.from+s,o.to+s))}for(let r=0;r<this.children.length;r+=3){if(this.children[r]<e&&this.children[r+1]>t){let o=this.children[r]+1;this.children[r+2].findInner(t-o,e-o,i,s+o,n)}}}map(t,e,i){if(this==Qr||t.maps.length==0)return this;return this.mapInner(t,e,0,0,i||Jr)}mapInner(t,e,i,s,n){let r;for(let o=0;o<this.local.length;o++){let l=this.local[o].map(t,i,s);if(l&&l.type.valid(e,l))(r||(r=[])).push(l);else if(n.onRemove)n.onRemove(this.local[o].spec)}if(this.children.length)return qr(this.children,r||[],t,e,i,s,n);else return r?new Wr(r.sort(Zr),zr):Qr}add(t,e){if(!e.length)return this;if(this==Qr)return Wr.create(t,e);return this.addInner(t,e,0)}addInner(t,e,i){let s,n=0;t.forEach(((t,r)=>{let o=r+i,l;if(!(l=Yr(e,t,o)))return;if(!s)s=this.children.slice();while(n<s.length&&s[n]<r)n+=3;if(s[n]==r)s[n+2]=s[n+2].addInner(t,l,o+1);else s.splice(n,0,r,r+t.nodeSize,Gr(l,t,o+1,Jr));n+=3}));let r=Vr(n?Xr(e):e,-i);for(let e=0;e<r.length;e++)if(!r[e].type.valid(t,r[e]))r.splice(e--,1);return new Wr(r.length?this.local.concat(r).sort(Zr):this.local,s||this.children)}remove(t){if(t.length==0||this==Qr)return this;return this.removeInner(t,0)}removeInner(t,e){let i=this.children,s=this.local;for(let s=0;s<i.length;s+=3){let n;let r=i[s]+e,o=i[s+1]+e;for(let e=0,i;e<t.length;e++)if(i=t[e]){if(i.from>r&&i.to<o){t[e]=null;(n||(n=[])).push(i)}}if(!n)continue;if(i==this.children)i=this.children.slice();let l=i[s+2].removeInner(n,r+1);if(l!=Qr){i[s+2]=l}else{i.splice(s,3);s-=3}}if(s.length)for(let i=0,n;i<t.length;i++)if(n=t[i]){for(let t=0;t<s.length;t++)if(s[t].eq(n,e)){if(s==this.local)s=this.local.slice();s.splice(t--,1)}}if(i==this.children&&s==this.local)return this;return s.length||i.length?new Wr(s,i):Qr}forChild(t,e){if(this==Qr)return this;if(e.isLeaf)return Wr.empty;let i,s;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){if(this.children[e]==t)i=this.children[e+2];break}let n=t+1,r=n+e.content.size;for(let t=0;t<this.local.length;t++){let e=this.local[t];if(e.from<r&&e.to>n&&e.type instanceof _r){let t=Math.max(n,e.from)-n,i=Math.min(r,e.to)-n;if(t<i)(s||(s=[])).push(e.copy(t,i))}}if(s){let t=new Wr(s.sort(Zr),zr);return i?new Hr([t,i]):t}return i||Qr}eq(t){if(this==t)return true;if(!(t instanceof Wr)||this.local.length!=t.local.length||this.children.length!=t.children.length)return false;for(let e=0;e<this.local.length;e++)if(!this.local[e].eq(t.local[e]))return false;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 false;return true}locals(t){return to(this.localsInner(t))}localsInner(t){if(this==Qr)return zr;if(t.inlineContent||!this.local.some(_r.is))return this.local;let e=[];for(let t=0;t<this.local.length;t++){if(!(this.local[t].type instanceof _r))e.push(this.local[t])}return e}forEachSet(t){t(this)}}Wr.empty=new Wr([],[]);Wr.removeOverlap=to;const Qr=Wr.empty;class Hr{constructor(t){this.members=t}map(t,e){const i=this.members.map((i=>i.map(t,e,Jr)));return Hr.from(i)}forChild(t,e){if(e.isLeaf)return Wr.empty;let i=[];for(let s=0;s<this.members.length;s++){let n=this.members[s].forChild(t,e);if(n==Qr)continue;if(n instanceof Hr)i=i.concat(n.members);else i.push(n)}return Hr.from(i)}eq(t){if(!(t instanceof Hr)||t.members.length!=this.members.length)return false;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return false;return true}locals(t){let e,i=true;for(let s=0;s<this.members.length;s++){let n=this.members[s].localsInner(t);if(!n.length)continue;if(!e){e=n}else{if(i){e=e.slice();i=false}for(let t=0;t<n.length;t++)e.push(n[t])}}return e?to(i?e:e.sort(Zr)):zr}static from(t){switch(t.length){case 0:return Qr;case 1:return t[0];default:return new Hr(t.every((t=>t instanceof Wr))?t:t.reduce(((t,e)=>t.concat(e instanceof Wr?e:e.members)),[]))}}forEachSet(t){for(let e=0;e<this.members.length;e++)this.members[e].forEachSet(t)}}function qr(t,e,i,s,n,r,o){let l=t.slice();for(let t=0,e=r;t<i.maps.length;t++){let s=0;i.maps[t].forEach(((t,i,n,r)=>{let o=r-n-(i-t);for(let n=0;n<l.length;n+=3){let r=l[n+1];if(r<0||t>r+e-s)continue;let h=l[n]+e-s;if(i>=h){l[n+1]=t<=h?-2:-1}else if(t>=e&&o){l[n]+=o;l[n+1]+=o}}s+=o}));e=i.maps[t].map(e,-1)}let h=false;for(let e=0;e<l.length;e+=3)if(l[e+1]<0){if(l[e+1]==-2){h=true;l[e+1]=-1;continue}let f=i.map(t[e]+r),u=f-n;if(u<0||u>=s.content.size){h=true;continue}let c=i.map(t[e+1]+r,-1),a=c-n;let{index:d,offset:w}=s.content.findIndex(u);let p=s.maybeChild(d);if(p&&w==u&&w+p.nodeSize==a){let s=l[e+2].mapInner(i,p,f+1,t[e]+r+1,o);if(s!=Qr){l[e]=u;l[e+1]=a;l[e+2]=s}else{l[e+1]=-2;h=true}}else{h=true}}if(h){let h=Kr(l,t,e,i,n,r,o);let f=Gr(h,s,0,o);e=f.local;for(let t=0;t<l.length;t+=3)if(l[t+1]<0){l.splice(t,3);t-=3}for(let t=0,e=0;t<f.children.length;t+=3){let i=f.children[t];while(e<l.length&&l[e]<i)e+=3;l.splice(e,0,f.children[t],f.children[t+1],f.children[t+2])}}return new Wr(e.sort(Zr),l)}function Vr(t,e){if(!e||!t.length)return t;let i=[];for(let s=0;s<t.length;s++){let n=t[s];i.push(new Lr(n.from+e,n.to+e,n.type))}return i}function Kr(t,e,i,s,n,r,o){function l(t,e){for(let r=0;r<t.local.length;r++){let l=t.local[r].map(s,n,e);if(l)i.push(l);else if(o.onRemove)o.onRemove(t.local[r].spec)}for(let i=0;i<t.children.length;i+=3)l(t.children[i+2],t.children[i]+e+1)}for(let i=0;i<t.length;i+=3)if(t[i+1]==-1)l(t[i+2],e[i]+r+1);return i}function Yr(t,e,i){if(e.isLeaf)return null;let s=i+e.nodeSize,n=null;for(let e=0,r;e<t.length;e++){if((r=t[e])&&r.from>i&&r.to<s){(n||(n=[])).push(r);t[e]=null}}return n}function Xr(t){let e=[];for(let i=0;i<t.length;i++)if(t[i]!=null)e.push(t[i]);return e}function Gr(t,e,i,s){let n=[],r=false;e.forEach(((e,o)=>{let l=Yr(t,e,o+i);if(l){r=true;let t=Gr(l,e,i+o+1,s);if(t!=Qr)n.push(o,o+e.nodeSize,t)}}));let o=Vr(r?Xr(t):t,-i).sort(Zr);for(let t=0;t<o.length;t++)if(!o[t].type.valid(e,o[t])){if(s.onRemove)s.onRemove(o[t].spec);o.splice(t--,1)}return o.length||n.length?new Wr(o,n):Qr}function Zr(t,e){return t.from-e.from||t.to-e.to}function to(t){let e=t;for(let i=0;i<e.length-1;i++){let s=e[i];if(s.from!=s.to)for(let n=i+1;n<e.length;n++){let r=e[n];if(r.from==s.from){if(r.to!=s.to){if(e==t)e=t.slice();e[n]=r.copy(r.from,s.to);eo(e,n+1,r.copy(s.to,r.to))}continue}else{if(r.from<s.to){if(e==t)e=t.slice();e[i]=s.copy(s.from,r.from);eo(e,n,s.copy(r.from,s.to))}break}}}return e}function eo(t,e,i){while(e<t.length&&Zr(i,t[e])>0)e++;t.splice(e,0,i)}function io(t){let e=[];t.someProp("decorations",(i=>{let s=i(t.state);if(s&&s!=Qr)e.push(s)}));if(t.cursorWrapper)e.push(Wr.create(t.state.doc,[t.cursorWrapper.deco]));return Hr.from(e)}const so={childList:true,characterData:true,characterDataOldValue:true,attributes:true,attributeOldValue:true,subtree:true};const no=Ui&&Ii<=11;class ro{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 oo{constructor(t,e){this.view=t;this.handleDOMChange=e;this.queue=[];this.flushingSoon=-1;this.observer=null;this.currentSelection=new ro;this.onCharData=null;this.suppressingSelectionUpdates=false;this.lastChangedTextNode=null;this.observer=window.MutationObserver&&new window.MutationObserver((t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);if(Ui&&Ii<=11&&t.some((t=>t.type=="childList"&&t.removedNodes.length||t.type=="characterData"&&t.oldValue.length>t.target.nodeValue.length)))this.flushSoon();else this.flush()}));if(no){this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue});this.flushSoon()}}this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){if(this.flushingSoon<0)this.flushingSoon=window.setTimeout((()=>{this.flushingSoon=-1;this.flush()}),20)}forceFlush(){if(this.flushingSoon>-1){window.clearTimeout(this.flushingSoon);this.flushingSoon=-1;this.flush()}}start(){if(this.observer){this.observer.takeRecords();this.observer.observe(this.view.dom,so)}if(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()}if(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=true;setTimeout((()=>this.suppressingSelectionUpdates=false),50)}onSelectionChange(){if(!an(this.view))return;if(this.suppressingSelectionUpdates)return en(this.view);if(Ui&&Ii<=11&&!this.view.state.selection.empty){let t=this.view.domSelectionRange();if(t.focusNode&&wi(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 true;let e=new Set,i;for(let i=t.focusNode;i;i=ui(i))e.add(i);for(let s=t.anchorNode;s;s=ui(s))if(e.has(s)){i=s;break}let s=i&&this.view.docView.nearestDesc(i);if(s&&s.ignoreMutation({type:"selection",target:i.nodeType==3?i.parentNode:i})){this.setCurSelection();return true}}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();if(e.length)this.queue=[];let i=t.domSelectionRange();let s=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(i)&&an(t)&&!this.ignoreSelectionChange(i);let n=-1,r=-1,o=false,l=[];if(t.editable){for(let t=0;t<e.length;t++){let i=this.registerMutation(e[t],l);if(i){n=n<0?i.from:Math.min(i.from,n);r=r<0?i.to:Math.max(i.to,r);if(i.typeOver)o=true}}}if(Ni&&l.length){let e=l.filter((t=>t.nodeName=="BR"));if(e.length==2){let[t,i]=e;if(t.parentNode&&t.parentNode.parentNode==i.parentNode)i.remove();else t.remove()}else{let{focusNode:i}=this.currentSelection;for(let s of e){let e=s.parentNode;if(e&&e.nodeName=="LI"&&(!i||ao(t,i)!=e))s.remove()}}}let h=null;if(n<0&&s&&t.input.lastFocus>Date.now()-200&&Math.max(t.input.lastTouch,t.input.lastClick.time)<Date.now()-300&&Mi(i)&&(h=Zs(t))&&h.eq(je.near(t.state.doc.resolve(0),1))){t.input.lastFocus=0;en(t);this.currentSelection.set(i);t.scrollToSelection()}else if(n>-1||s){if(n>-1){t.docView.markDirty(n,r);fo(t)}this.handleDOMChange(n,r,o,l);if(t.docView&&t.docView.dirty)t.updateState(t.state);else if(!this.currentSelection.eq(i))en(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(t.type=="attributes"&&(i==this.view.docView||t.attributeName=="contenteditable"||t.attributeName=="style"&&!t.oldValue&&!t.target.getAttribute("style")))return null;if(!i||i.ignoreMutation(t))return null;if(t.type=="childList"){for(let i=0;i<t.addedNodes.length;i++){let s=t.addedNodes[i];e.push(s);if(s.nodeType==3)this.lastChangedTextNode=s}if(i.contentDOM&&i.contentDOM!=i.dom&&!i.contentDOM.contains(t.target))return{from:i.posBefore,to:i.posAfter};let s=t.previousSibling,n=t.nextSibling;if(Ui&&Ii<=11&&t.addedNodes.length){for(let e=0;e<t.addedNodes.length;e++){let{previousSibling:i,nextSibling:r}=t.addedNodes[e];if(!i||Array.prototype.indexOf.call(t.addedNodes,i)<0)s=i;if(!r||Array.prototype.indexOf.call(t.addedNodes,r)<0)n=r}}let r=s&&s.parentNode==t.target?fi(s)+1:0;let o=i.localPosFromDOM(t.target,r,-1);let l=n&&n.parentNode==t.target?fi(n):t.target.childNodes.length;let h=i.localPosFromDOM(t.target,l,1);return{from:o,to:h}}else if(t.type=="attributes"){return{from:i.posAtStart-i.border,to:i.posAtEnd+i.border}}else{this.lastChangedTextNode=t.target;return{from:i.posAtStart,to:i.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}}}}let lo=new WeakMap;let ho=false;function fo(t){if(lo.has(t))return;lo.set(t,null);if(["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace)!==-1){t.requiresGeckoHackNode=Ni;if(ho)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.");ho=true}}function uo(t,e){let i=e.startContainer,s=e.startOffset;let n=e.endContainer,r=e.endOffset;let o=t.domAtPos(t.state.selection.anchor);if(wi(o.node,o.offset,n,r))[i,s,n,r]=[n,r,i,s];return{anchorNode:i,anchorOffset:s,focusNode:n,focusOffset:r}}function co(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return uo(t,i)}let i;function s(t){t.preventDefault();t.stopImmediatePropagation();i=t.getTargetRanges()[0]}t.dom.addEventListener("beforeinput",s,true);document.execCommand("indent");t.dom.removeEventListener("beforeinput",s,true);return i?uo(t,i):null}function ao(t,e){for(let i=e.parentNode;i&&i!=t.dom;i=i.parentNode){let e=t.docView.nearestDesc(i,true);if(e&&e.node.isBlock)return i}return null}function wo(t,e,i){let{node:s,fromOffset:n,toOffset:r,from:o,to:l}=t.docView.parseRange(e,i);let h=t.domSelectionRange();let f;let u=h.anchorNode;if(u&&t.dom.contains(u.nodeType==1?u:u.parentNode)){f=[{node:u,offset:h.anchorOffset}];if(!Mi(h))f.push({node:h.focusNode,offset:h.focusOffset})}if(Fi&&t.input.lastKeyCode===8){for(let t=r;t>n;t--){let e=s.childNodes[t-1],i=e.pmViewDesc;if(e.nodeName=="BR"&&!i){r=t;break}if(!i||i.size)break}}let c=t.state.doc;let a=t.someProp("domParser")||ht.fromSchema(t.state.schema);let d=c.resolve(o);let w=null,p=a.parse(s,{topNode:d.parent,topMatch:d.parent.contentMatchAt(d.index()),topOpen:true,from:n,to:r,preserveWhitespace:d.parent.type.whitespace=="pre"?"full":true,findPositions:f,ruleFromNode:po,context:d});if(f&&f[0].pos!=null){let t=f[0].pos,e=f[1]&&f[1].pos;if(e==null)e=t;w={anchor:t+o,head:e+o}}return{doc:p,sel:w,from:o,to:l}}function po(t){let e=t.pmViewDesc;if(e){return e.parseRule()}else if(t.nodeName=="BR"&&t.parentNode){if(ji&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let t=document.createElement("div");t.appendChild(document.createElement("li"));return{skip:t}}else if(t.parentNode.lastChild==t||ji&&/^(tr|table)$/i.test(t.parentNode.nodeName)){return{ignore:true}}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder")){return{ignore:true}}return null}const go=/^(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 mo(t,e,i,s,n){let r=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);t.input.compositionPendingChanges=0;if(e<0){let e=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null;let i=Zs(t,e);if(i&&!t.state.selection.eq(i)){if(Fi&&zi&&t.input.lastKeyCode===13&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",(e=>e(t,ki(13,"Enter")))))return;let s=t.state.tr.setSelection(i);if(e=="pointer")s.setMeta("pointer",true);else if(e=="key")s.scrollIntoView();if(r)s.setMeta("composition",r);t.dispatch(s)}return}let o=t.state.doc.resolve(e);let l=o.sharedDepth(i);e=o.before(l+1);i=t.state.doc.resolve(i).after(l+1);let h=t.state.selection;let f=wo(t,e,i);let u=t.state.doc,c=u.slice(f.from,f.to);let a,d;if(t.input.lastKeyCode===8&&Date.now()-100<t.input.lastKeyCodeTime){a=t.state.selection.to;d="end"}else{a=t.state.selection.from;d="start"}t.input.lastKeyCode=null;let w=Mo(c.content,f.doc.content,f.from,a,d);if(w)t.input.domChangeCount++;if((_i&&t.input.lastIOSEnter>Date.now()-225||zi)&&n.some((t=>t.nodeType==1&&!go.test(t.nodeName)))&&(!w||w.endA>=w.endB)&&t.someProp("handleKeyDown",(e=>e(t,ki(13,"Enter"))))){t.input.lastIOSEnter=0;return}if(!w){if(s&&h instanceof ze&&!h.empty&&h.$head.sameParent(h.$anchor)&&!t.composing&&!(f.sel&&f.sel.anchor!=f.sel.head)){w={start:h.from,endA:h.to,endB:h.to}}else{if(f.sel){let e=yo(t,t.state.doc,f.sel);if(e&&!e.eq(t.state.selection)){let i=t.state.tr.setSelection(e);if(r)i.setMeta("composition",r);t.dispatch(i)}}return}}if(t.state.selection.from<t.state.selection.to&&w.start==w.endB&&t.state.selection instanceof ze){if(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}else if(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}}if(Ui&&Ii<=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 p=f.doc.resolveNoCache(w.start-f.from);let g=f.doc.resolveNoCache(w.endB-f.from);let m=u.resolve(w.start);let y=p.sameParent(g)&&p.parent.inlineContent&&m.end()>=w.endA;if((_i&&t.input.lastIOSEnter>Date.now()-225&&(!y||n.some((t=>t.nodeName=="DIV"||t.nodeName=="P")))||!y&&p.pos<f.doc.content.size&&(!p.sameParent(g)||!p.parent.inlineContent)&&p.pos<g.pos&&!/\S/.test(f.doc.textBetween(p.pos,g.pos,"","")))&&t.someProp("handleKeyDown",(e=>e(t,ki(13,"Enter"))))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>w.start&&vo(u,w.start,w.endA,p,g)&&t.someProp("handleKeyDown",(e=>e(t,ki(8,"Backspace"))))){if(zi&&Fi)t.domObserver.suppressSelectionUpdates();return}if(Fi&&w.endB==w.start)t.input.lastChromeDelete=Date.now();if(zi&&!y&&p.start()!=g.start()&&g.parentOffset==0&&p.depth==g.depth&&f.sel&&f.sel.anchor==f.sel.head&&f.sel.head==w.endA){w.endB-=2;g=f.doc.resolveNoCache(w.endB-f.from);setTimeout((()=>{t.someProp("handleKeyDown",(function(e){return e(t,ki(13,"Enter"))}))}),20)}let b=w.start,v=w.endA;let A=e=>{let i=e||t.state.tr.replace(b,v,f.doc.slice(w.start-f.from,w.endB-f.from));if(f.sel){let e=yo(t,i.doc,f.sel);if(e&&!(Fi&&t.composing&&e.empty&&(w.start!=w.endB||t.input.lastChromeDelete<Date.now()-100)&&(e.head==b||e.head==i.mapping.map(v)-1)||Ui&&e.empty&&e.head==b))i.setSelection(e)}if(r)i.setMeta("composition",r);return i.scrollIntoView()};let M;if(y){if(p.pos==g.pos){if(Ui&&Ii<=11&&p.parentOffset==0){t.domObserver.suppressSelectionUpdates();setTimeout((()=>en(t)),20)}let e=A(t.state.tr.delete(b,v));let i=u.resolve(w.start).marksAcross(u.resolve(w.endA));if(i)e.ensureMarks(i);t.dispatch(e)}else if(w.endA==w.endB&&(M=bo(p.parent.content.cut(p.parentOffset,g.parentOffset),m.parent.content.cut(m.parentOffset,w.endA-m.start())))){let e=A(t.state.tr);if(M.type=="add")e.addMark(b,v,M.mark);else e.removeMark(b,v,M.mark);t.dispatch(e)}else if(p.parent.child(p.index()).isText&&p.index()==g.index()-(g.textOffset?0:1)){let e=p.parent.textBetween(p.parentOffset,g.parentOffset);let i=()=>A(t.state.tr.insertText(e,b,v));if(!t.someProp("handleTextInput",(s=>s(t,b,v,e,i))))t.dispatch(i())}else{t.dispatch(A())}}else{t.dispatch(A())}}function yo(t,e,i){if(Math.max(i.anchor,i.head)>e.content.size)return null;return cn(t,e.resolve(i.anchor),e.resolve(i.head))}function bo(t,e){let i=t.firstChild.marks,s=e.firstChild.marks;let n=i,r=s,o,l,f;for(let t=0;t<s.length;t++)n=s[t].removeFromSet(n);for(let t=0;t<i.length;t++)r=i[t].removeFromSet(r);if(n.length==1&&r.length==0){l=n[0];o="add";f=t=>t.mark(l.addToSet(t.marks))}else if(n.length==0&&r.length==1){l=r[0];o="remove";f=t=>t.mark(l.removeFromSet(t.marks))}else{return null}let u=[];for(let t=0;t<e.childCount;t++)u.push(f(e.child(t)));if(h.from(u).eq(t))return{mark:l,type:o}}function vo(t,e,i,s,n){if(i-e<=n.pos-s.pos||Ao(s,true,false)<n.pos)return false;let r=t.resolve(e);if(!s.parent.isTextblock){let t=r.nodeAfter;return t!=null&&i==e+t.nodeSize}if(r.parentOffset<r.parent.content.size||!r.parent.isTextblock)return false;let o=t.resolve(Ao(r,true,true));if(!o.parent.isTextblock||o.pos>i||Ao(o,true,false)<i)return false;return s.parent.content.cut(s.parentOffset).eq(o.parent.content)}function Ao(t,e,i){let s=t.depth,n=e?t.end():t.pos;while(s>0&&(e||t.indexAfter(s)==t.node(s).childCount)){s--;n++;e=false}if(i){let e=t.node(s).maybeChild(t.indexAfter(s));while(e&&!e.isLeaf){e=e.firstChild;n++}}return n}function Mo(t,e,i,s,n){let r=t.findDiffStart(e,i);if(r==null)return null;let{a:o,b:l}=t.findDiffEnd(e,i+t.size,i+e.size);if(n=="end"){let t=Math.max(0,r-Math.min(o,l));s-=o+t-r}if(o<r&&t.size<e.size){let t=s<=r&&s>=o?r-s:0;r-=t;if(r&&r<e.size&&ko(e.textBetween(r-1,r+1)))r+=t?1:-1;l=r+(l-o);o=r}else if(l<r){let e=s<=r&&s>=l?r-s:0;r-=e;if(r&&r<t.size&&ko(t.textBetween(r-1,r+1)))r+=e?1:-1;o=r+(o-l);l=r}return{start:r,endA:o,endB:l}}function ko(t){if(t.length!=2)return false;let e=t.charCodeAt(0),i=t.charCodeAt(1);return e>=56320&&e<=57343&&i>=55296&&i<=56319}class So{constructor(t,e){this._root=null;this.focused=false;this.trackWrites=null;this.mounted=false;this.markCursor=null;this.cursorWrapper=null;this.lastSelectedViewDesc=undefined;this.input=new tr;this.prevDirectPlugins=[];this.pluginViews=[];this.requiresGeckoHackNode=false;this.dragging=null;this._props=e;this.state=e.state;this.directPlugins=e.plugins||[];this.directPlugins.forEach(Ro);this.dispatch=this.dispatch.bind(this);this.dom=t&&t.mount||document.createElement("div");if(t){if(t.appendChild)t.appendChild(this.dom);else if(typeof t=="function")t(this.dom);else if(t.mount)this.mounted=true}this.editable=Eo(this);Oo(this);this.nodeViews=To(this);this.docView=Is(this.state.doc,xo(this),io(this),this.dom,this);this.domObserver=new oo(this,((t,e,i,s)=>mo(this,t,e,i,s)));this.domObserver.start();er(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){if(t.handleDOMEvents!=this._props.handleDOMEvents)nr(this);let e=this._props;this._props=t;if(t.plugins){t.plugins.forEach(Ro);this.directPlugins=t.plugins}this.updateStateInner(t.state,e)}setProps(t){let e={};for(let t in this._props)e[t]=this._props[t];e.state=this.state;for(let i in t)e[i]=t[i];this.update(e)}updateState(t){this.updateStateInner(t,this._props)}updateStateInner(t,e){var i;let s=this.state,n=false,r=false;if(t.storedMarks&&this.composing){Sr(this);r=true}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=To(this);if(Co(t,this.nodeViews)){this.nodeViews=t;n=true}}if(o||e.handleDOMEvents!=this._props.handleDOMEvents){nr(this)}this.editable=Eo(this);Oo(this);let l=io(this),h=xo(this);let f=s.plugins!=t.plugins&&!s.doc.eq(t.doc)?"reset":t.scrollToSelection>s.scrollToSelection?"to selection":"preserve";let u=n||!this.docView.matchesNode(t.doc,h,l);if(u||!t.selection.eq(s.selection))r=true;let c=f=="preserve"&&r&&this.dom.style.overflowAnchor==null&&Ki(this);if(r){this.domObserver.stop();let e=u&&(Ui||Fi)&&!this.composing&&!s.selection.empty&&!t.selection.empty&&Do(s.selection,t.selection);if(u){let i=Fi?this.trackWrites=this.domSelectionRange().focusNode:null;if(this.composing)this.input.compositionNode=xr(this);if(n||!this.docView.update(t.doc,h,l,this)){this.docView.updateOuterDeco(h);this.docView.destroy();this.docView=Is(t.doc,h,l,this.dom,this)}if(i&&!this.trackWrites)e=true}if(e||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&wn(this))){en(this,e)}else{fn(this,t.selection);this.domObserver.setCurSelection()}this.domObserver.start()}this.updatePluginViews(s);if(((i=this.dragging)===null||i===void 0?void 0:i.node)&&!s.doc.eq(t.doc))this.updateDraggedNode(this.dragging,s);if(f=="reset"){this.dom.scrollTop=0}else if(f=="to selection"){this.scrollToSelection()}else if(c){Xi(c)}}scrollToSelection(){let t=this.domSelectionRange().focusNode;if(!t||!this.dom.contains(t.nodeType==1?t:t.parentNode));else if(this.someProp("handleScrollToSelection",(t=>t(this))));else if(this.state.selection instanceof We){let e=this.docView.domAfterPos(this.state.selection.from);if(e.nodeType==1)Vi(this,e.getBoundingClientRect(),t)}else{Vi(this,this.coordsAtPos(this.state.selection.head,1),t)}}destroyPluginViews(){let t;while(t=this.pluginViews.pop())if(t.destroy)t.destroy()}updatePluginViews(t){if(!t||t.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins;this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let e=this.directPlugins[t];if(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];if(e.spec.view)this.pluginViews.push(e.spec.view(this))}}else{for(let e=0;e<this.pluginViews.length;e++){let i=this.pluginViews[e];if(i.update)i.update(this,t)}}}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);let n=t>0&&this.state.doc.nodeAt(t);if(n==i.node)s=t}this.dragging=new Nr(t.slice,t.move,s<0?undefined:We.create(this.state.doc,s))}someProp(t,e){let i=this._props&&this._props[t],s;if(i!=null&&(s=e?e(i):i))return s;for(let i=0;i<this.directPlugins.length;i++){let n=this.directPlugins[i].props[t];if(n!=null&&(s=e?e(n):n))return s}let n=this.state.plugins;if(n)for(let i=0;i<n.length;i++){let r=n[i].props[t];if(r!=null&&(s=e?e(r):r))return s}}hasFocus(){if(Ui){let t=this.root.activeElement;if(t==this.dom)return true;if(!t||!this.dom.contains(t))return false;while(t&&this.dom!=t&&this.dom.contains(t)){if(t.contentEditable=="false")return false;t=t.parentElement}return true}return this.root.activeElement==this.dom}focus(){this.domObserver.stop();if(this.editable)ts(this.dom);en(this);this.domObserver.start()}get root(){let t=this._root;if(t==null)for(let t=this.dom.parentNode;t;t=t.parentNode){if(t.nodeType==9||t.nodeType==11&&t.host){if(!t.getSelection)Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection();return this._root=t}}return t||document}updateRoot(){this._root=null}posAtCoords(t){return fs(this,t)}coordsAtPos(t,e=1){return ds(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(s==null)throw new RangeError("DOM position not inside the editor");return s}endOfTextblock(t,e){return ks(this,e||this.state,t)}pasteHTML(t,e){return Ur(this,"",t,false,e||new ClipboardEvent("paste"))}pasteText(t,e){return Ur(this,t,null,true,e||new ClipboardEvent("paste"))}serializeForClipboard(t){return Nn(this,t)}destroy(){if(!this.docView)return;sr(this);this.destroyPluginViews();if(this.mounted){this.docView.update(this.state.doc,[],io(this),this);this.dom.textContent=""}else if(this.dom.parentNode){this.dom.parentNode.removeChild(this.dom)}this.docView.destroy();this.docView=null;di()}get isDestroyed(){return this.docView==null}dispatchEvent(t){return lr(this,t)}domSelectionRange(){let t=this.domSelection();if(!t)return{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0};return ji&&this.root.nodeType===11&&Si(this.dom.ownerDocument)==this.dom&&co(this,t)||t}domSelection(){return this.root.getSelection()}}So.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;if(e)e.call(this,t);else this.updateState(this.state.apply(t))};function xo(t){let e=Object.create(null);e.class="ProseMirror";e.contenteditable=String(t.editable);t.someProp("attributes",(i=>{if(typeof i=="function")i=i(t.state);if(i)for(let t in i){if(t=="class")e.class+=" "+i[t];else if(t=="style")e.style=(e.style?e.style+";":"")+i[t];else if(!e[t]&&t!="contenteditable"&&t!="nodeName")e[t]=String(i[t])}}));if(!e.translate)e.translate="no";return[Lr.node(0,t.state.doc.content.size,e)]}function Oo(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:Lr.widget(t.state.selection.from,e,{raw:true,marks:t.markCursor})}}else{t.cursorWrapper=null}}function Eo(t){return!t.someProp("editable",(e=>e(t.state)===false))}function Do(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)}function To(t){let e=Object.create(null);function i(t){for(let i in t)if(!Object.prototype.hasOwnProperty.call(e,i))e[i]=t[i]}t.someProp("nodeViews",i);t.someProp("markViews",i);return e}function Co(t,e){let i=0,s=0;for(let s in t){if(t[s]!=e[s])return true;i++}for(let t in e)s++;return i!=s}function Ro(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")}const Uo=["p",0],Io=["blockquote",0],No=["hr"],Po=["pre",["code",0]],Fo=["br"];const Bo={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Uo}},blockquote:{content:"block+",group:"block",defining:true,parseDOM:[{tag:"blockquote"}],toDOM(){return Io}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return No}},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:true,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){return["h"+t.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:true,defining:true,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return Po}},text:{group:"inline"},image:{inline:true,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:true,parseDOM:[{tag:"img[src]",getAttrs(t){return{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:true,group:"inline",selectable:false,parseDOM:[{tag:"br"}],toDOM(){return Fo}}};const jo=["em",0],_o=["strong",0],$o=["code",0];const Lo={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:false,parseDOM:[{tag:"a[href]",getAttrs(t){return{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=>t.type.name=="em"}],toDOM(){return jo}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:t=>t.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:t=>t.type.name=="strong"},{style:"font-weight",getAttrs:t=>/^(bold(er)?|[5-9]\d{2,})$/.test(t)&&null}],toDOM(){return _o}},code:{code:true,parseDOM:[{tag:"code"}],toDOM(){return $o}}};const zo=new nt({nodes:Bo,marks:Lo});const Jo=["ol",0],Wo=["ul",0],Qo=["li",0];const Ho={attrs:{order:{default:1,validate:"number"}},parseDOM:[{tag:"ol",getAttrs(t){return{order:t.hasAttribute("start")?+t.getAttribute("start"):1}}}],toDOM(t){return t.attrs.order==1?Jo:["ol",{start:t.attrs.order},0]}};const qo={parseDOM:[{tag:"ul"}],toDOM(){return Wo}};const Vo={parseDOM:[{tag:"li"}],toDOM(){return Qo},defining:true};function Ko(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 Yo(t,e,i){return t.append({ordered_list:Ko(Ho,{content:"list_item+",group:i}),bullet_list:Ko(qo,{content:"list_item+",group:i}),list_item:Ko(Vo,{content:e})})}var Xo={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:"'"};var Go={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'};var Zo=typeof navigator!="undefined"&&/Mac/.test(navigator.platform);var tl=typeof navigator!="undefined"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var el=0;el<10;el++)Xo[48+el]=Xo[96+el]=String(el);for(var el=1;el<=24;el++)Xo[el+111]="F"+el;for(var el=65;el<=90;el++){Xo[el]=String.fromCharCode(el+32);Go[el]=String.fromCharCode(el)}for(var il in Xo)if(!Go.hasOwnProperty(il))Go[il]=Xo[il];function sl(t){var e=Zo&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||tl&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified";var i=!e&&t.key||(t.shiftKey?Go:Xo)[t.keyCode]||t.key||"Unidentified";if(i=="Esc")i="Escape";if(i=="Del")i="Delete";if(i=="Left")i="ArrowLeft";if(i=="Up")i="ArrowUp";if(i=="Right")i="ArrowRight";if(i=="Down")i="ArrowDown";return i}const nl=typeof navigator!="undefined"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform);const rl=typeof navigator!="undefined"&&/Win/.test(navigator.platform);function ol(t){let e=t.split(/-(?!$)/),i=e[e.length-1];if(i=="Space")i=" ";let s,n,r,o;for(let t=0;t<e.length-1;t++){let i=e[t];if(/^(cmd|meta|m)$/i.test(i))o=true;else if(/^a(lt)?$/i.test(i))s=true;else if(/^(c|ctrl|control)$/i.test(i))n=true;else if(/^s(hift)?$/i.test(i))r=true;else if(/^mod$/i.test(i)){if(nl)o=true;else n=true}else throw new Error("Unrecognized modifier name: "+i)}if(s)i="Alt-"+i;if(n)i="Ctrl-"+i;if(o)i="Meta-"+i;if(r)i="Shift-"+i;return i}function ll(t){let e=Object.create(null);for(let i in t)e[ol(i)]=t[i];return e}function hl(t,e,i=true){if(e.altKey)t="Alt-"+t;if(e.ctrlKey)t="Ctrl-"+t;if(e.metaKey)t="Meta-"+t;if(i&&e.shiftKey)t="Shift-"+t;return t}function fl(t){return new oi({props:{handleKeyDown:ul(t)}})}function ul(t){let e=ll(t);return function(t,i){let s=sl(i),n,r=e[hl(s,i)];if(r&&r(t.state,t.dispatch,t))return true;if(s.length==1&&s!=" "){if(i.shiftKey){let n=e[hl(s,i,false)];if(n&&n(t.state,t.dispatch,t))return true}if((i.altKey||i.metaKey||i.ctrlKey)&&!(rl&&i.ctrlKey&&i.altKey)&&(n=Xo[i.keyCode])&&n!=s){let s=e[hl(n,i)];if(s&&s(t.state,t.dispatch,t))return true}}return false}}const cl=(t,e)=>{if(t.selection.empty)return false;if(e)e(t.tr.deleteSelection().scrollIntoView());return true};function al(t,e){let{$cursor:i}=t.selection;if(!i||(e?!e.endOfTextblock("backward",t):i.parentOffset>0))return null;return i}const dl=(t,e,i)=>{let s=al(t,i);if(!s)return false;let n=gl(s);if(!n){let i=s.blockRange(),n=i&&ie(i);if(n==null)return false;if(e)e(t.tr.lift(i,n).scrollIntoView());return true}let r=n.nodeBefore;if(Cl(t,n,e,-1))return true;if(s.parent.content.size==0&&(wl(r,"end")||We.isSelectable(r))){for(let i=s.depth;;i--){let o=ye(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(wl(r,"end")?je.findFrom(i.doc.resolve(i.mapping.map(n.pos,-1)),-1):We.create(i.doc,n.pos-r.nodeSize));e(i.scrollIntoView())}return true}if(i==1||s.node(i-1).childCount>1)break}}if(r.isAtom&&n.depth==s.depth-1){if(e)e(t.tr.delete(n.pos-r.nodeSize,n.pos).scrollIntoView());return true}return false};function wl(t,e,i=false){for(let s=t;s;s=e=="start"?s.firstChild:s.lastChild){if(s.isTextblock)return true;if(i&&s.childCount!=1)return false}return false}const pl=(t,e,i)=>{let{$head:s,empty:n}=t.selection,r=s;if(!n)return false;if(s.parent.isTextblock){if(i?!i.endOfTextblock("backward",t):s.parentOffset>0)return false;r=gl(s)}let o=r&&r.nodeBefore;if(!o||!We.isSelectable(o))return false;if(e)e(t.tr.setSelection(We.create(t.doc,r.pos-o.nodeSize)).scrollIntoView());return true};function gl(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 ml(t,e){let{$cursor:i}=t.selection;if(!i||(e?!e.endOfTextblock("forward",t):i.parentOffset<i.parent.content.size))return null;return i}const yl=(t,e,i)=>{let s=ml(t,i);if(!s)return false;let n=vl(s);if(!n)return false;let r=n.nodeAfter;if(Cl(t,n,e,1))return true;if(s.parent.content.size==0&&(wl(r,"start")||We.isSelectable(r))){let i=ye(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(wl(r,"start")?je.findFrom(s.doc.resolve(s.mapping.map(n.pos)),1):We.create(s.doc,s.mapping.map(n.pos)));e(s.scrollIntoView())}return true}}if(r.isAtom&&n.depth==s.depth-1){if(e)e(t.tr.delete(n.pos,n.pos+r.nodeSize).scrollIntoView());return true}return false};const bl=(t,e,i)=>{let{$head:s,empty:n}=t.selection,r=s;if(!n)return false;if(s.parent.isTextblock){if(i?!i.endOfTextblock("forward",t):s.parentOffset<s.parent.content.size)return false;r=vl(s)}let o=r&&r.nodeAfter;if(!o||!We.isSelectable(o))return false;if(e)e(t.tr.setSelection(We.create(t.doc,r.pos)).scrollIntoView());return true};function vl(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}const Al=(t,e)=>{let{$head:i,$anchor:s}=t.selection;if(!i.parent.type.spec.code||!i.sameParent(s))return false;if(e)e(t.tr.insertText("\n").scrollIntoView());return true};function Ml(t){for(let e=0;e<t.edgeCount;e++){let{type:i}=t.edge(e);if(i.isTextblock&&!i.hasRequiredAttrs())return i}return null}const kl=(t,e)=>{let{$head:i,$anchor:s}=t.selection;if(!i.parent.type.spec.code||!i.sameParent(s))return false;let n=i.node(-1),r=i.indexAfter(-1),o=Ml(n.contentMatchAt(r));if(!o||!n.canReplaceWith(r,r,o))return false;if(e){let s=i.after(),n=t.tr.replaceWith(s,s,o.createAndFill());n.setSelection(je.near(n.doc.resolve(s),1));e(n.scrollIntoView())}return true};const Sl=(t,e)=>{let i=t.selection,{$from:s,$to:n}=i;if(i instanceof He||s.parent.inlineContent||n.parent.inlineContent)return false;let r=Ml(n.parent.contentMatchAt(n.indexAfter()));if(!r||!r.isTextblock)return false;if(e){let i=(!s.parentOffset&&n.index()<n.parent.childCount?s:n).pos;let o=t.tr.insert(i,r.createAndFill());o.setSelection(ze.create(o.doc,i+1));e(o.scrollIntoView())}return true};const xl=(t,e)=>{let{$cursor:i}=t.selection;if(!i||i.parent.content.size)return false;if(i.depth>1&&i.after()!=i.end(-1)){let s=i.before();if(ue(t.doc,s)){if(e)e(t.tr.split(s).scrollIntoView());return true}}let s=i.blockRange(),n=s&&ie(s);if(n==null)return false;if(e)e(t.tr.lift(s,n).scrollIntoView());return true};function Ol(t){return(t,e)=>{let{$from:i}=t.selection;if(t.selection instanceof We&&t.selection.node.isBlock){if(!i.parentOffset||!ue(t.doc,i.pos))return false;if(e)e(t.tr.split(i.pos).scrollIntoView());return true}if(!i.depth)return false;let s=[];let n,r,o=false,l=false;for(let t=i.depth;;t--){let e=i.node(t);if(e.isBlock){o=i.end(t)==i.pos+(i.depth-t);l=i.start(t)==i.pos-(i.depth-t);r=Ml(i.node(t-1).contentMatchAt(i.indexAfter(t-1)));s.unshift(o&&r?{type:r}:null);n=t;break}else{if(t==1)return false;s.unshift(null)}}let h=t.tr;if(t.selection instanceof ze||t.selection instanceof He)h.deleteSelection();let f=h.mapping.map(i.pos);let u=ue(h.doc,f,s.length,s);if(!u){s[0]=r?{type:r}:null;u=ue(h.doc,f,s.length,s)}if(!u)return false;h.split(f,s.length,s);if(!o&&l&&i.node(n).type!=r){let t=h.mapping.map(i.before(n)),e=h.doc.resolve(t);if(r&&i.node(n-1).canReplaceWith(e.index(),e.index()+1,r))h.setNodeMarkup(h.mapping.map(i.before(n)),r)}if(e)e(h.scrollIntoView());return true}}const El=Ol();const Dl=(t,e)=>{if(e)e(t.tr.setSelection(new He(t.doc)));return true};function Tl(t,e,i){let s=e.nodeBefore,n=e.nodeAfter,r=e.index();if(!s||!n||!s.type.compatibleContent(n.type))return false;if(!s.content.size&&e.parent.canReplace(r-1,r)){if(i)i(t.tr.delete(e.pos-s.nodeSize,e.pos).scrollIntoView());return true}if(!e.parent.canReplace(r,r+1)||!(n.isTextblock||ae(t.doc,e.pos)))return false;if(i)i(t.tr.join(e.pos).scrollIntoView());return true}function Cl(t,e,i,s){let n=e.nodeBefore,r=e.nodeAfter,o,l;let f=n.type.spec.isolating||r.type.spec.isolating;if(!f&&Tl(t,e,i))return true;let u=!f&&e.parent.canReplace(e.index(),e.index()+1);if(u&&(o=(l=n.contentMatchAt(n.childCount)).findWrapping(r.type))&&l.matchType(o[0]||r.type).validEnd){if(i){let s=e.pos+r.nodeSize,l=h.empty;for(let t=o.length-1;t>=0;t--)l=h.from(o[t].create(null,l));l=h.from(n.copy(l));let f=t.tr.step(new Yt(e.pos-1,s,e.pos,s,new w(l,1,0),o.length,true));let u=f.doc.resolve(s+2*o.length);if(u.nodeAfter&&u.nodeAfter.type==n.type&&ae(f.doc,u.pos))f.join(u.pos);i(f.scrollIntoView())}return true}let c=r.type.spec.isolating||s>0&&f?null:je.findFrom(e,1);let a=c&&c.$from.blockRange(c.$to),d=a&&ie(a);if(d!=null&&d>=e.depth){if(i)i(t.tr.lift(a,d).scrollIntoView());return true}if(u&&wl(r,"start",true)&&wl(n,"end")){let s=n,o=[];for(;;){o.push(s);if(s.isTextblock)break;s=s.lastChild}let l=r,f=1;for(;!l.isTextblock;l=l.firstChild)f++;if(s.canReplace(s.childCount,s.childCount,l.content)){if(i){let s=h.empty;for(let t=o.length-1;t>=0;t--)s=h.from(o[t].copy(s));let n=t.tr.step(new Yt(e.pos-o.length,e.pos+r.nodeSize,e.pos+f,e.pos+r.nodeSize-f,new w(s,o.length,0),0,true));i(n.scrollIntoView())}return true}}return false}function Rl(t){return function(e,i){let s=e.selection,n=t<0?s.$from:s.$to;let r=n.depth;while(n.node(r).isInline){if(!r)return false;r--}if(!n.node(r).isTextblock)return false;if(i)i(e.tr.setSelection(ze.create(e.doc,t<0?n.start(r):n.end(r))));return true}}const Ul=Rl(-1);const Il=Rl(1);function Nl(...t){return function(e,i,s){for(let n=0;n<t.length;n++)if(t[n](e,i,s))return true;return false}}let Pl=Nl(cl,dl,pl);let Fl=Nl(cl,yl,bl);const Bl={Enter:Nl(Al,Sl,xl,El),"Mod-Enter":kl,Backspace:Pl,"Mod-Backspace":Pl,"Shift-Backspace":Pl,Delete:Fl,"Mod-Delete":Fl,"Mod-a":Dl};const jl={"Ctrl-h":Bl["Backspace"],"Alt-Backspace":Bl["Mod-Backspace"],"Ctrl-d":Bl["Delete"],"Ctrl-Alt-Backspace":Bl["Mod-Delete"],"Alt-Delete":Bl["Mod-Delete"],"Alt-d":Bl["Mod-Delete"],"Ctrl-a":Ul,"Ctrl-e":Il};for(let t in Bl)jl[t]=Bl[t];const _l=typeof navigator!="undefined"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os!="undefined"&&os.platform?os.platform()=="darwin":false;const $l=_l?jl:Bl;class Ll extends s{__class__="KritzelText";fontFamily="Arial";fontSize=8;fontColor="#000000";initialWidth=1;initialHeight=1;scale=1;scaleFactor=1;isDebugInfoVisible=true;isEditable=true;isEditing=false;editor=null;content=null;_schema=new nt({nodes:Yo(zo.spec.nodes,"paragraph block*","block"),marks:zo.spec.marks});uneditedObject=null;rows=1;get isEmpty(){if(!this.editor){return true}const t=this.editor.state.doc;if(t.content.size===0){return true}const e=t.textContent.trim();return e.length===0}constructor(t){super();if(t){this.translateX=t.translateX||0;this.translateY=t.translateY||0;this.fontSize=t.fontSize||8;this.fontFamily=t.fontFamily||"Arial";this.fontColor=t.fontColor||"#000000";this.width=this.initialWidth/(this._core.store.state.scale<0?this._core.store.state.scale:1);this.height=this.fontSize*1.2/(this._core.store.state.scale<0?this._core.store.state.scale:1);this.scale=t.scale||1;this.scaleFactor=t.scaleX??1}}static create(t,e,i){const s=new Ll;s._core=t;s.id=s.generateId();s.workspaceId=t.store.state.activeWorkspace.id;s.fontSize=e;s.fontFamily=i;s.translateX=0;s.translateY=0;s.width=s.initialWidth/(s._core.store.state.scale<0?s._core.store.state.scale:1);s.height=s.fontSize*1.2/(s._core.store.state.scale<0?s._core.store.state.scale:1);s.backgroundColor="transparent";s.initialWidth=s.width;s.initialHeight=s.height;s.scaleFactor=1;s.scale=s._core.store.state.scale;s.zIndex=t.store.currentZIndex;s.editor=s.createEditor();return s}mount(t){if(t===null||this.isInViewport()===false){return}if(this.isMounted&&this.elementRef===t&&this.editor.dom.parentElement===t){return}this.elementRef=t;this.elementRef.style.fontFamily=this.fontFamily;this.elementRef.style.fontSize=`${this.fontSize}pt`;this.elementRef.style.color=this.fontColor;this.elementRef.style.whiteSpace="pre-wrap";this.elementRef.style.wordWrap="break-word";this.elementRef.innerHTML="";this.elementRef.appendChild(this.editor.dom);this.isMounted=true;requestAnimationFrame((()=>this.adjustSizeOnInput()))}createEditor(){const t=this._schema.node("doc",null,[this._schema.node("paragraph")]);return new So(null,{state:ni.create({doc:t,plugins:[fl($l)]}),editable:()=>false,dispatchTransaction:t=>{const e=this.editor.state.apply(t);this.editor.updateState(e);if(t.docChanged){this.content=e.doc.toJSON();this.adjustSizeOnInput();if(!t.getMeta("fromRemote")){this._core.store.state.objectsMap.update(this,{temporary:true})}}}})}setContent(t){this.content=t;if(this.editor&&t){const e=this.editor.state.schema.nodeFromJSON(t);const i=this.editor.state.tr.replaceWith(0,this.editor.state.doc.content.size,e.content);i.setMeta("fromRemote",true);this.editor.dispatch(i)}}adjustSizeOnInput(){const t=this.elementRef;if(t&&this.isMounted&&t.scrollWidth>0){const e=this.totalWidth;const i=this.totalHeight;const s=t.scrollWidth;const n=t.scrollHeight;this.width=s*this.scaleFactor;this.height=n*this.scaleFactor;if(this.rotation!==0){const t=this.totalWidth;const s=this.totalHeight;const n=(t-e)/2/this.scale;const r=(s-i)/2/this.scale;if(n!==0||r!==0){const t=Math.cos(this.rotation);const e=Math.sin(this.rotation);const i=t*n-e*r;const s=e*n+t*r;this.translateX+=i-n;this.translateY+=s-r}}}}resize(t,e,i,s){if(i<=1||s<=1){return}const n=this.width/this.scaleFactor;const r=this.height/this.scaleFactor;const o=i/n;const l=s/r;this.scaleFactor=Math.min(o,l);this.width=n*this.scaleFactor;this.height=r*this.scaleFactor;this.translateX=t;this.translateY=e;this._core.store.state.objectsMap.update(this)}focus(t){if(this.editor){const e=this.editor.state.doc;if(t){const i=this.editor.posAtCoords({left:t.x,top:t.y});if(i){this.editor.dispatch(this.editor.state.tr.setSelection(ze.create(e,i.pos)));this.editor.focus();return}}const i=Math.max(1,e.content.size-1);this.editor.dispatch(this.editor.state.tr.setSelection(ze.create(e,i)));this.editor.focus()}}edit(e){n.disableInteractiveWidget();this.uneditedObject=this.clone();this._core.store.setState("activeTool",t.getTool("text"));if(this.editor){this.editor.setProps({editable:()=>true})}this.isEditing=true;this._core.rerender();requestAnimationFrame((()=>{this.adjustSizeOnInput();if(e){this.focus({x:e.clientX,y:e.clientY})}else{this.focus()}n.enableInteractiveWidget()}))}save(){requestAnimationFrame((()=>this.adjustSizeOnInput()));this.content=this.editor.state.doc.toJSON();this.editor.setProps({editable:()=>false});this.editor.dom.blur();this.isEditing=false;this._core.store.state.objectsMap.consolidateTemporaryItems();this._core.store.state.objectsMap.update(this)}handlePointerDown(t){if(!this.isEditing){return}t.stopPropagation()}handlePointerMove(t){if(!this.isEditing){return}t.stopPropagation()}handlePointerUp(t){if(!this.isEditing){return}t.stopPropagation()}copy(){const t=super.copy();t.editor=t.createEditor();if(this.content){t.setContent(this.content)}return t}serialize(){const{_core:t,_elementRef:e,_schema:i,element:s,totalWidth:n,totalHeight:r,editor:o,uneditedObject:l,...h}=this;const f=structuredClone(h);if(s&&typeof s==="object"&&"nodeType"in s&&s.nodeType===1){f.element=s.cloneNode(true)}return f}deserialize(t){super.deserialize(t);if(t.content){this.setContent(t.content)}return this}}var zl={};var Jl;function Wl(){if(Jl)return zl;Jl=1;(function(t){var e=Object.defineProperty;var i=t=>e(t,"__esModule",{value:true});var s=(t,s)=>{i(t);for(var n in s)e(t,n,{get:s[n],enumerable:true})};s(t,{default:()=>D,getStroke:()=>E,getStrokeOutlinePoints:()=>x,getStrokePoints:()=>O});function n(t,e,i,s=t=>t){return t*s(.5-e*(.5-i))}function r(t){return[-t[0],-t[1]]}function o(t,e){return[t[0]+e[0],t[1]+e[1]]}function l(t,e){return[t[0]-e[0],t[1]-e[1]]}function h(t,e){return[t[0]*e,t[1]*e]}function f(t,e){return[t[0]/e,t[1]/e]}function u(t){return[t[1],-t[0]]}function c(t,e){return t[0]*e[0]+t[1]*e[1]}function a(t,e){return t[0]===e[0]&&t[1]===e[1]}function d(t){return Math.hypot(t[0],t[1])}function w(t){return t[0]*t[0]+t[1]*t[1]}function p(t,e){return w(l(t,e))}function g(t){return f(t,d(t))}function m(t,e){return Math.hypot(t[1]-e[1],t[0]-e[0])}function y(t,e,i){let s=Math.sin(i),n=Math.cos(i),r=t[0]-e[0],o=t[1]-e[1],l=r*n-o*s,h=r*s+o*n;return[l+e[0],h+e[1]]}function b(t,e,i){return o(t,h(l(e,t),i))}function v(t,e,i){return o(t,h(e,i))}var{min:A,PI:M}=Math,k=.275,S=M+1e-4;function x(t,e={}){let{size:i=16,smoothing:s=.5,thinning:f=.5,simulatePressure:a=true,easing:d=t=>t,start:w={},end:m={},last:M=false}=e,{cap:x=true,easing:O=t=>t*(2-t)}=w,{cap:E=true,easing:D=t=>--t*t*t+1}=m;if(t.length===0||i<=0)return[];let T=t[t.length-1].runningLength,C=w.taper===false?0:w.taper===true?Math.max(i,T):w.taper,R=m.taper===false?0:m.taper===true?Math.max(i,T):m.taper,U=Math.pow(i*s,2),I=[],N=[],P=t.slice(0,10).reduce(((t,e)=>{let s=e.pressure;if(a){let n=A(1,e.distance/i),r=A(1,1-n);s=A(1,t+(r-t)*(n*k))}return(t+s)/2}),t[0].pressure),F=n(i,f,t[t.length-1].pressure,d),B,j=t[0].vector,_=t[0].point,$=_,L=_,z=$,J=false;for(let e=0;e<t.length;e++){let{pressure:s}=t[e],{point:r,vector:w,distance:g,runningLength:m}=t[e];if(e<t.length-1&&T-m<3)continue;if(f){if(a){let t=A(1,g/i),e=A(1,1-t);s=A(1,P+(e-P)*(t*k))}F=n(i,f,s,d)}else F=i/2;B===void 0&&(B=F);let v=m<C?O(m/C):1,M=T-m<R?D((T-m)/R):1;F=Math.max(.01,F*Math.min(v,M));let x=(e<t.length-1?t[e+1]:t[e]).vector,E=e<t.length-1?c(w,x):1,W=c(w,j)<0&&!J,Q=E!==null&&E<0;if(W||Q){let t=h(u(j),F);for(let e=1/13,i=0;i<=1;i+=e)L=y(l(r,t),r,S*i),I.push(L),z=y(o(r,t),r,S*-i),N.push(z);_=L,$=z,Q&&(J=true);continue}if(J=false,e===t.length-1){let t=h(u(w),F);I.push(l(r,t)),N.push(o(r,t));continue}let H=h(u(b(x,w,E)),F);L=l(r,H),(e<=1||p(_,L)>U)&&(I.push(L),_=L),z=o(r,H),(e<=1||p($,z)>U)&&(N.push(z),$=z),P=s,j=w}let W=t[0].point.slice(0,2),Q=t.length>1?t[t.length-1].point.slice(0,2):o(t[0].point,[1,1]),H=[],q=[];if(t.length===1){if(!(C||R)||M){let t=v(W,g(u(l(W,Q))),-(B||F)),e=[];for(let i=1/13,s=i;s<=1;s+=i)e.push(y(t,W,S*2*s));return e}}else{if(!(C||R&&t.length===1))if(x)for(let t=1/13,e=t;e<=1;e+=t){let t=y(N[0],W,S*e);H.push(t)}else{let t=l(I[0],N[0]),e=h(t,.5),i=h(t,.51);H.push(l(W,e),l(W,i),o(W,i),o(W,e))}let e=u(r(t[t.length-1].vector));if(R||C&&t.length===1)q.push(Q);else if(E){let t=v(Q,e,F);for(let e=1/29,i=e;i<1;i+=e)q.push(y(t,Q,S*3*i))}else q.push(o(Q,h(e,F)),o(Q,h(e,F*.99)),l(Q,h(e,F*.99)),l(Q,h(e,F)))}return I.concat(q,N.reverse(),H)}function O(t,e={}){var i;let{streamline:s=.5,size:n=16,last:r=false}=e;if(t.length===0)return[];let h=.15+(1-s)*.85,f=Array.isArray(t[0])?t:t.map((({x:t,y:e,pressure:i=.5})=>[t,e,i]));if(f.length===2){let t=f[1];f=f.slice(0,-1);for(let e=1;e<5;e++)f.push(b(f[0],t,e/4))}f.length===1&&(f=[...f,[...o(f[0],[1,1]),...f[0].slice(2)]]);let u=[{point:[f[0][0],f[0][1]],pressure:f[0][2]>=0?f[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],c=false,d=0,w=u[0],p=f.length-1;for(let t=1;t<f.length;t++){let e=r&&t===p?f[t].slice(0,2):b(w.point,f[t],h);if(a(w.point,e))continue;let i=m(e,w.point);if(d+=i,t<p&&!c){if(d<n)continue;c=true}w={point:e,pressure:f[t][2]>=0?f[t][2]:.5,vector:g(l(w.point,e)),distance:i,runningLength:d},u.push(w)}return u[0].vector=((i=u[1])==null?void 0:i.vector)||[0,0],u}function E(t,e={}){return x(O(t,e),e)}var D=E})(zl);return zl}var Ql=Wl();class Hl{static average(t,e){return(t+e)/2}}class ql extends s{__class__="KritzelPath";points;d;stroke="none";strokeWidth;lineSlack=.5;fill;x=0;y=0;height=0;width=0;scale=1;options;isVisible=true;isDebugInfoVisible=true;isCompleted=false;_adjustedPoints=null;get viewBox(){return`${this.x} ${this.y} ${this.width} ${this.height}`}constructor(t){super();this.options=t;this.points=t?.points??[];this.translateX=t?.translateX??0;this.translateY=t?.translateY??0;this.scale=t?.scale??1;this.strokeWidth=t?.strokeWidth??8;this.fill=t?.fill??"#000000";this.d=this.generateSvgPath();this.updateDimensions()}static create(t,e){const i=new ql;i._core=t;i.id=i.generateId();i.workspaceId=t.store.state.activeWorkspace.id;i.options=e;i.points=e?.points??[];i.translateX=e?.translateX??0;i.translateY=e?.translateY??0;i.scale=e?.scale??1;i.strokeWidth=e?.strokeWidth??8;i.fill=e?.fill??"#000000";i.zIndex=t.store.currentZIndex;i.d=i.generateSvgPath();i.updateDimensions();return i}resize(t,e,i,s){if(i<=1||s<=1){return}const n=i/this.width;const r=s/this.height;this.width=i;this.height=s;this.points=this.points.map((([t,e])=>[t*n,e*r]));this.d=this.generateSvgPath();this.width=Math.max(...this.points.map((t=>t[0])))-Math.min(...this.points.map((t=>t[0])))+this.strokeWidth;this.height=Math.max(...this.points.map((t=>t[1])))-Math.min(...this.points.map((t=>t[1])))+this.strokeWidth;this.x=Math.min(...this.points.map((t=>t[0])))-this.strokeWidth/2;this.y=Math.min(...this.points.map((t=>t[1])))-this.strokeWidth/2;this.translateX=t;this.translateY=e;this._adjustedPoints=null;this._core.store.state.objectsMap.update(this)}rotate(t){this.rotation=t;this._adjustedPoints=null;this._core.store.state.objectsMap.update(this)}move(t,e,i,s){const n=(t-i)/this._core.store.state.scale;const r=(e-s)/this._core.store.state.scale;this.translateX+=n;this.translateY+=r;this._adjustedPoints=null;this._core.store.state.objectsMap.update(this)}hitTest(t,e){const i=this.strokeWidth/this.scale/2;if(this._adjustedPoints===null){this._adjustedPoints=this.computeAdjustedPoints()}if(this._adjustedPoints.length===1){const s=this._adjustedPoints[0];const n=this.pointToLineSegmentDistance(t,e,s[0],s[1],s[0],s[1]);return n<=i}for(let s=0;s<this._adjustedPoints.length-1;s++){const n=this._adjustedPoints[s];const r=this._adjustedPoints[s+1];const o=this.pointToLineSegmentDistance(t,e,n[0],n[1],r[0],r[1]);if(o<=i){return true}}return false}hitTestPolygon(t){const e=this.strokeWidth/this.scale/2;if(this._adjustedPoints===null){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 true}}for(const t of s){if(this.hitTest(t.x,t.y)){return true}}for(let t=0;t<this._adjustedPoints.length-1;t++){const e={x:this._adjustedPoints[t][0],y:this._adjustedPoints[t][1]};const n={x:this._adjustedPoints[t+1][0],y:this._adjustedPoints[t+1][1]};for(let t=0;t<s.length;t++){const r=s[t];const o=s[(t+1)%s.length];if(i.intersectLines(e,n,r,o)){return true}}}for(let t=0;t<this._adjustedPoints.length-1;t++){const i=this._adjustedPoints[t];const n=this._adjustedPoints[t+1];for(let t=0;t<s.length;t++){const r=s[t];const o=s[(t+1)%s.length];const l=this.pointToLineSegmentDistance(r.x,r.y,i[0],i[1],n[0],n[1]);const h=this.pointToLineSegmentDistance(o.x,o.y,i[0],i[1],n[0],n[1]);const f=this.pointToLineSegmentDistance(i[0],i[1],r.x,r.y,o.x,o.y);const u=this.pointToLineSegmentDistance(n[0],n[1],r.x,r.y,o.x,o.y);const c=Math.min(l,h,f,u);if(c<=e){return true}}}return false}updatePosition(t,e){this.translateX=t;this.translateY=e;this._adjustedPoints=null;this._core.store.state.objectsMap.update(this)}computeAdjustedPoints(){if(!this.points?.length){return[]}const t=this.rotation;const e=Math.cos(t);const i=Math.sin(t);const s=this.points.map((t=>t[0]));const n=this.points.map((t=>t[1]));const r={x:(Math.min(...s)+Math.max(...s))/2,y:(Math.min(...n)+Math.max(...n))/2};const{x:o,y:l}=r;const h=this.points.map((([t,s])=>{const n=t-o;const r=s-l;return[o+n*e-r*i,l+n*i+r*e]}));return h.map((([t,e])=>[Math.abs(t-this.x)/this.scale+this.translateX,Math.abs(e-this.y)/this.scale+this.translateY]))}pointToLineSegmentDistance(t,e,i,s,n,r){const o=t-i;const l=e-s;const h=n-i;const f=r-s;const u=o*h+l*f;const c=h*h+f*f;let a=-1;if(c!==0){a=u/c}let d,w;if(a<0){d=i;w=s}else if(a>1){d=n;w=r}else{d=i+a*h;w=s+a*f}const p=t-d;const g=e-w;return Math.sqrt(p*p+g*g)}updateDimensions(){const t=this.points.map((([t,e])=>{const i=t*Math.cos(this.rotation)-e*Math.sin(this.rotation);const s=t*Math.sin(this.rotation)+e*Math.cos(this.rotation);return[i,s]}));const e=Math.min(...t.map((t=>t[0]-this.strokeWidth/2)));const i=Math.min(...t.map((t=>t[1]-this.strokeWidth/2)));const s=Math.max(...t.map((t=>t[0]+this.strokeWidth/2)));const n=Math.max(...t.map((t=>t[1]+this.strokeWidth/2)));this.width=s-e+this.lineSlack;this.height=n-i+this.lineSlack;this.x=e;this.y=i;this.translateX=(this.x+this.translateX)/this.scale;this.translateY=(this.y+this.translateY)/this.scale}generateSvgPath(){const t=this.getStrokeFromPoints(this.points,this.strokeWidth);return this.getSvgPathFromStroke(t)}getStrokeFromPoints(t,e){return Ql.getStroke(t,{size:e,thinning:.5,smoothing:.5,streamline:.5,easing:t=>t,simulatePressure:true,last:true,start:{cap:true,taper:0,easing:t=>t},end:{cap:true,taper:0,easing:t=>t}})}getSvgPathFromStroke(t,e=true){const i=t.length;if(i<4){return``}let s=t[0];let n=t[1];const r=t[2];let o=`M${s[0].toFixed(2)},${s[1].toFixed(2)} Q${n[0].toFixed(2)},${n[1].toFixed(2)} ${Hl.average(n[0],r[0]).toFixed(2)},${Hl.average(n[1],r[1]).toFixed(2)} T`;for(let e=2,r=i-1;e<r;e++){s=t[e];n=t[e+1];o+=`${Hl.average(s[0],n[0]).toFixed(2)},${Hl.average(s[1],n[1]).toFixed(2)} `}if(e){o+="Z"}return o}}class Vl extends s{__class__="KritzelImage";src="";maxWidth=300;maxHeight=300;maxCompressionSize=300;isDebugInfoVisible=true;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 Vl;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;return e}resize(t,e,i,s){if(i<=1||s<=1){return}const n=s/this.height;this.width=this.width*n;this.height=this.height*n;this.translateX=t;this.translateY=e;this._core.store.state.objectsMap.update(this)}calculateScaledDimensions(t){let e=t.width;let i=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const s=this.maxWidth/t.width;const n=this.maxHeight/t.height;const r=Math.min(s,n);e=t.width*r;i=t.height*r}return{scaledWidth:e,scaledHeight:i}}}var Kl;(function(t){t[t["Left"]=0]="Left";t[t["Middle"]=1]="Middle";t[t["Right"]=2]="Right"})(Kl||(Kl={}));class Yl{static isRightClick(t){return t.button===Kl.Right}static isLeftClick(t){return t.button===Kl.Left}static isPointerEventOnContextMenu(t){const e=t.composedPath();const i=e.find((t=>t.classList&&t.classList.contains("context-menu")));return!!i}static onLongPress(t,e,i){const s=400;const n=10;const r=t.clientX;const o=t.clientY;const l=t.target;const h=setTimeout((()=>{d();e(t)}),s);const f=()=>{clearTimeout(h);d();i?.()};const u=t=>{if(Math.abs(t.clientX-r)>n||Math.abs(t.clientY-o)>n){f()}};const c=()=>{f()};const a=()=>{f()};const d=()=>{l.removeEventListener("pointermove",u);l.removeEventListener("pointerup",c);l.removeEventListener("pointercancel",a)};l.addEventListener("pointermove",u,{passive:true});l.addEventListener("pointerup",c,{once:true});l.addEventListener("pointercancel",a,{once:true});return f}}class Xl{__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){Object.assign(this,t);return this}}class Gl extends Xl{type="pen";color="#000000";size=6;palettes={pen:["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#808080","#C0C0C0","#800000","#008000","#000080","#808000","#800080"],highlighter:["#ffff00","#ffb347","#b4ffb4"]};constructor(t){super(t)}handlePointerDown(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){if(Yl.isLeftClick(t)){this._core.store.state.isDrawing=true;const e=t.clientX-this._core.store.offsetX;const i=t.clientY-this._core.store.offsetY;const s=ql.create(this._core,{points:[[e,i]],translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,fill:this.color,strokeWidth:this.size});s.isCompleted=false;this._core.store.state.objectsMap.insert(s)}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());if(t.length===1){const e=Math.round(t[0].clientX-this._core.store.offsetX);const i=Math.round(t[0].clientY-this._core.store.offsetY);this._core.store.state.isDrawing=true;const s=ql.create(this._core,{points:[[e,i]],translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,fill:this.color,strokeWidth:this.size});s.isCompleted=false;this._core.store.state.objectsMap.insert(s)}}}handlePointerMove(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){if(this._core.store.state.isDrawing){const e=this._core.store.currentPath;if(e){const i=t.clientX-this._core.store.offsetX;const s=t.clientY-this._core.store.offsetY;const n=ql.create(this._core,{points:[...e.points,[i,s]],translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,fill:this.color,strokeWidth:this.size});n.id=e.id;n.workspaceId=e.workspaceId;n.isCompleted=false;this._core.store.state.objectsMap.update(n)}}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());if(t.length===1){const e=this._core.store.currentPath;if(e){const i=Math.round(t[0].clientX-this._core.store.offsetX);const s=Math.round(t[0].clientY-this._core.store.offsetY);const n=ql.create(this._core,{points:[...e.points,[i,s]],translateX:-this._core.store.state.translateX,translateY:-this._core.store.state.translateY,scale:this._core.store.state.scale,fill:this.color,strokeWidth:this.size});n.id=e.id;n.workspaceId=e.workspaceId;n.isCompleted=false;this._core.store.state.objectsMap.update(n)}}}}handlePointerUp(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){if(this._core.store.state.isDrawing){this._core.store.state.isDrawing=false;const t=this._core.store.currentPath;if(t){t.isCompleted=true;t.zIndex=this._core.store.currentZIndex;this._core.store.state.objectsMap.update(t)}}}if(t.pointerType==="touch"){if(this._core.store.state.isDrawing){this._core.store.state.isDrawing=false;const t=this._core.store.currentPath;if(t){t.isCompleted=true;t.zIndex=this._core.store.currentZIndex;this._core.store.state.objectsMap.update(t)}}}}}class Zl extends Xl{touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){if(t.pointerType==="mouse"){if(Yl.isLeftClick(t)){this._core.store.state.isErasing=true}}if(t.pointerType==="touch"){this.touchStartTimeout=setTimeout((()=>{if(this._core.store.state.pointers.size===1&&!this._core.store.state.isScaling){this._core.store.state.isErasing=true}}),80)}}handlePointerMove(t){if(t.pointerType==="mouse"){if(this._core.store.state.isErasing){const e=this._core.getObjectsFromPointerEvent(t,".object");if(e.length===0)return;const i=this._core.store.state.pointerX;const s=this._core.store.state.pointerY;e.forEach((t=>{t.markedForRemoval=t.hitTest(i,s)}));this._core.rerender()}}if(t.pointerType==="touch"){if(this._core.store.state.pointers.size===1&&this._core.store.state.isErasing){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=this._core.getObjectsFromPointerEvent(t,".object");if(i.length===0)return;const s=this._core.store.state.pointerX;const n=this._core.store.state.pointerY;i.forEach((t=>{t.markedForRemoval=t.hitTest(s,n)}));this._core.rerender()}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._core.store.state.isErasing){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.forEach((t=>{t.markedForRemoval=false;this._core.removeObject(t)}));if(t.length>0){this._core.rerender()}this._core.store.state.isErasing=false}}if(t.pointerType==="touch"){clearTimeout(this.touchStartTimeout);if(this._core.store.state.isErasing){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.forEach((t=>{t.markedForRemoval=false;this._core.removeObject(t)}));if(t.length>0){this._core.rerender()}this._core.store.state.isErasing=false}}}}function th(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:true,get:function(){return e[i]}})}}))})),Object.freeze(t)}function eh(t,e){return new Promise((function(i,s){let n;return ih(t).then((function(t){try{return n=t,i(new Blob([e.slice(0,2),n,e.slice(2)],{type:"image/jpeg"}))}catch(t){return s(t)}}),s)}))}const ih=t=>new Promise(((e,i)=>{const s=new FileReader;s.addEventListener("load",(({target:{result:t}})=>{const s=new DataView(t);let n=0;if(65496!==s.getUint16(n))return i("not a valid JPEG");for(n+=2;;){const r=s.getUint16(n);if(65498===r)break;const o=s.getUint16(n+2);if(65505===r&&1165519206===s.getUint32(n+4)){const r=n+10;let l;switch(s.getUint16(r)){case 18761:l=true;break;case 19789:l=false;break;default:return i("TIFF header contains invalid endian")}if(42!==s.getUint16(r+2,l))return i("TIFF header contains invalid version");const h=s.getUint32(r+4,l),f=r+h+2+12*s.getUint16(r+h,l);for(let t=r+h+2;t<f;t+=12){if(274==s.getUint16(t,l)){if(3!==s.getUint16(t+2,l))return i("Orientation data type is invalid");if(1!==s.getUint32(t+4,l))return i("Orientation data count is invalid");s.setUint16(t+8,1,l);break}}return e(t.slice(n,n+2+o))}n+=2+o}return e(new Blob)})),s.readAsArrayBuffer(t)}));var sh={},nh={get exports(){return sh},set exports(t){sh=t}};!function(t){var e,i,s={};nh.exports=s,s.parse=function(t,e){for(var i=s.bin.readUshort,n=s.bin.readUint,r=0,o={},l=new Uint8Array(t),h=l.length-4;101010256!=n(l,h);)h--;r=h;r+=4;var f=i(l,r+=4);i(l,r+=2);var u=n(l,r+=2),c=n(l,r+=4);r+=4,r=c;for(var a=0;a<f;a++){n(l,r),r+=4,r+=4,r+=4,n(l,r+=4);u=n(l,r+=4);var d=n(l,r+=4),w=i(l,r+=4),p=i(l,r+2),g=i(l,r+4);r+=6;var m=n(l,r+=8);r+=4,r+=w+p+g,s._readLocal(l,m,o,u,d,e)}return o},s._readLocal=function(t,e,i,n,r,o){var l=s.bin.readUshort,h=s.bin.readUint;h(t,e),l(t,e+=4),l(t,e+=2);var f=l(t,e+=2);h(t,e+=2),h(t,e+=4),e+=4;var u=l(t,e+=8),c=l(t,e+=2);e+=2;var a=s.bin.readUTF8(t,e,u);if(e+=u,e+=c,o)i[a]={size:r,csize:n};else{var d=new Uint8Array(t.buffer,e);if(0==f)i[a]=new Uint8Array(d.buffer.slice(e,e+n));else{if(8!=f)throw"unknown compression method: "+f;var w=new Uint8Array(r);s.inflateRaw(d,w),i[a]=w}}},s.inflateRaw=function(t,e){return s.F.inflate(t,e)},s.inflate=function(t,e){return s.inflateRaw(new Uint8Array(t.buffer,t.byteOffset+2,t.length-6),e)},s.deflate=function(t,e){null==e&&(e={level:6});var i=0,n=new Uint8Array(50+Math.floor(1.1*t.length));n[i]=120,n[i+1]=156,i+=2,i=s.F.deflateRaw(t,n,i,e.level);var r=s.adler(t,0,t.length);return n[i+0]=r>>>24&255,n[i+1]=r>>>16&255,n[i+2]=r>>>8&255,n[i+3]=r>>>0&255,new Uint8Array(n.buffer,0,i+4)},s.deflateRaw=function(t,e){null==e&&(e={level:6});var i=new Uint8Array(50+Math.floor(1.1*t.length)),n=s.F.deflateRaw(t,i,n,e.level);return new Uint8Array(i.buffer,0,n)},s.encode=function(t,e){null==e&&(e=false);var i=0,n=s.bin.writeUint,r=s.bin.writeUshort,o={};for(var l in t){var h=!s._noNeed(l)&&!e,f=t[l],u=s.crc.crc(f,0,f.length);o[l]={cpr:h,usize:f.length,crc:u,file:h?s.deflateRaw(f):f}}for(var l in o)i+=o[l].file.length+30+46+2*s.bin.sizeUTF8(l);i+=22;var c=new Uint8Array(i),a=0,d=[];for(var l in o){var w=o[l];d.push(a),a=s._writeHeader(c,a,l,w,0)}var p=0,g=a;for(var l in o){w=o[l];d.push(a),a=s._writeHeader(c,a,l,w,1,d[p++])}var m=a-g;return n(c,a,101010256),a+=4,r(c,a+=4,p),r(c,a+=2,p),n(c,a+=2,m),n(c,a+=4,g),a+=4,a+=2,c.buffer},s._noNeed=function(t){var e=t.split(".").pop().toLowerCase();return-1!="png,jpg,jpeg,zip".indexOf(e)},s._writeHeader=function(t,e,i,n,r,o){var l=s.bin.writeUint,h=s.bin.writeUshort,f=n.file;return l(t,e,0==r?67324752:33639248),e+=4,1==r&&(e+=2),h(t,e,20),h(t,e+=2,0),h(t,e+=2,n.cpr?8:0),l(t,e+=2,0),l(t,e+=4,n.crc),l(t,e+=4,f.length),l(t,e+=4,n.usize),h(t,e+=4,s.bin.sizeUTF8(i)),h(t,e+=2,0),e+=2,1==r&&(e+=2,e+=2,l(t,e+=6,o),e+=4),e+=s.bin.writeUTF8(t,e,i),0==r&&(t.set(f,e),e+=f.length),e},s.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,i,n){for(var r=0;r<n;r++)t=s.crc.table[255&(t^e[i+r])]^t>>>8;return t},crc:function(t,e,i){return 4294967295^s.crc.update(4294967295,t,e,i)}},s.adler=function(t,e,i){for(var s=1,n=0,r=e,o=e+i;r<o;){for(var l=Math.min(r+5552,o);r<l;)n+=s+=t[r++];s%=65521,n%=65521}return n<<16|s},s.bin={readUshort:function(t,e){return t[e]|t[e+1]<<8},writeUshort:function(t,e,i){t[e]=255&i,t[e+1]=i>>8&255},readUint:function(t,e){return 16777216*t[e+3]+(t[e+2]<<16|t[e+1]<<8|t[e])},writeUint:function(t,e,i){t[e]=255&i,t[e+1]=i>>8&255,t[e+2]=i>>16&255,t[e+3]=i>>24&255},readASCII:function(t,e,i){for(var s="",n=0;n<i;n++)s+=String.fromCharCode(t[e+n]);return s},writeASCII:function(t,e,i){for(var s=0;s<i.length;s++)t[e+s]=i.charCodeAt(s)},pad:function(t){return t.length<2?"0"+t:t},readUTF8:function(t,e,i){for(var n,r="",o=0;o<i;o++)r+="%"+s.bin.pad(t[e+o].toString(16));try{n=decodeURIComponent(r)}catch(n){return s.bin.readASCII(t,e,i)}return n},writeUTF8:function(t,e,i){for(var s=i.length,n=0,r=0;r<s;r++){var o=i.charCodeAt(r);if(0==(4294967168&o))t[e+n]=o,n++;else if(0==(4294965248&o))t[e+n]=192|o>>6,t[e+n+1]=128|o>>0&63,n+=2;else if(0==(4294901760&o))t[e+n]=224|o>>12,t[e+n+1]=128|o>>6&63,t[e+n+2]=128|o>>0&63,n+=3;else{if(0!=(4292870144&o))throw"e";t[e+n]=240|o>>18,t[e+n+1]=128|o>>12&63,t[e+n+2]=128|o>>6&63,t[e+n+3]=128|o>>0&63,n+=4}}return n},sizeUTF8:function(t){for(var e=t.length,i=0,s=0;s<e;s++){var n=t.charCodeAt(s);if(0==(4294967168&n))i++;else if(0==(4294965248&n))i+=2;else if(0==(4294901760&n))i+=3;else{if(0!=(4292870144&n))throw"e";i+=4}}return i}},s.F={},s.F.deflateRaw=function(t,e,i,n){var r=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]][n],o=s.F.U,l=s.F._goodIndex;var h=s.F._putsE,f=0,u=i<<3,c=0,a=t.length;if(0==n){for(;f<a;){h(e,u,f+(S=Math.min(65535,a-f))==a?1:0),u=s.F._copyExact(t,f,S,e,u+8),f+=S}return u>>>3}var d=o.lits,w=o.strt,p=o.prev,g=0,m=0,y=0,b=0,v=0,A=0;for(a>2&&(w[A=s.F._hash(t,0)]=0),f=0;f<a;f++){if(v=A,f+1<a-2){A=s.F._hash(t,f+1);var M=f+1&32767;p[M]=w[A],w[A]=M}if(c<=f){(g>14e3||m>26697)&&a-f>100&&(c<f&&(d[g]=f-c,g+=2,c=f),u=s.F._writeBlock(f==a-1||c==a?1:0,d,g,b,t,y,f-y,e,u),g=m=b=0,y=f);var k=0;f<a-2&&(k=s.F._bestMatch(t,f,p,v,Math.min(r[2],a-f),r[3]));var S=k>>>16,x=65535&k;if(0!=k){x=65535&k;var O=l(S=k>>>16,o.of0);o.lhst[257+O]++;var E=l(x,o.df0);o.dhst[E]++,b+=o.exb[O]+o.dxb[E],d[g]=S<<23|f-c,d[g+1]=x<<16|O<<8|E,g+=2,c=f+S}else o.lhst[t[f]]++;m++}}for(y==f&&0!=t.length||(c<f&&(d[g]=f-c,g+=2,c=f),u=s.F._writeBlock(1,d,g,b,t,y,f-y,e,u),g=0,m=0,g=m=b=0,y=f);0!=(7&u);)u++;return u>>>3},s.F._bestMatch=function(t,e,i,n,r,o){var l=32767&e,h=i[l],f=l-h+32768&32767;if(h==l||n!=s.F._hash(t,e-f))return 0;for(var u=0,c=0,a=Math.min(32767,e);f<=a&&0!=--o&&h!=l;){if(0==u||t[e+u]==t[e+u-f]){var d=s.F._howLong(t,e,f);if(d>u){if(c=f,(u=d)>=r)break;f+2<d&&(d=f+2);for(var w=0,p=0;p<d-2;p++){var g=e-f+p+32768&32767,m=g-i[g]+32768&32767;m>w&&(w=m,h=g)}}}f+=(l=h)-(h=i[l])+32768&32767}return u<<16|c},s.F._howLong=function(t,e,i){if(t[e]!=t[e-i]||t[e+1]!=t[e+1-i]||t[e+2]!=t[e+2-i])return 0;var s=e,n=Math.min(t.length,e+258);for(e+=3;e<n&&t[e]==t[e-i];)e++;return e-s},s.F._hash=function(t,e){return(t[e]<<8|t[e+1])+(t[e+2]<<4)&65535},s.saved=0,s.F._writeBlock=function(t,e,i,n,r,o,l,h,f){var u,c,a,d,w,p,g,m,y,b=s.F.U,v=s.F._putsF,A=s.F._putsE;b.lhst[256]++,c=(u=s.F.getTrees())[0],a=u[1],d=u[2],w=u[3],p=u[4],g=u[5],m=u[6],y=u[7];var M=32+(0==(f+3&7)?0:8-(f+3&7))+(l<<3),k=n+s.F.contSize(b.fltree,b.lhst)+s.F.contSize(b.fdtree,b.dhst),S=n+s.F.contSize(b.ltree,b.lhst)+s.F.contSize(b.dtree,b.dhst);S+=14+3*g+s.F.contSize(b.itree,b.ihst)+(2*b.ihst[16]+3*b.ihst[17]+7*b.ihst[18]);for(var x=0;x<286;x++)b.lhst[x]=0;for(x=0;x<30;x++)b.dhst[x]=0;for(x=0;x<19;x++)b.ihst[x]=0;var O=M<k&&M<S?0:k<S?1:2;if(v(h,f,t),v(h,f+1,O),f+=3,0==O){for(;0!=(7&f);)f++;f=s.F._copyExact(r,o,l,h,f)}else{var E,D;if(1==O&&(E=b.fltree,D=b.fdtree),2==O){s.F.makeCodes(b.ltree,c),s.F.revCodes(b.ltree,c),s.F.makeCodes(b.dtree,a),s.F.revCodes(b.dtree,a),s.F.makeCodes(b.itree,d),s.F.revCodes(b.itree,d),E=b.ltree,D=b.dtree,A(h,f,w-257),A(h,f+=5,p-1),A(h,f+=5,g-4),f+=4;for(var T=0;T<g;T++)A(h,f+3*T,b.itree[1+(b.ordr[T]<<1)]);f+=3*g,f=s.F._codeTiny(m,b.itree,h,f),f=s.F._codeTiny(y,b.itree,h,f)}for(var C=o,R=0;R<i;R+=2){for(var U=e[R],I=U>>>23,N=C+(8388607&U);C<N;)f=s.F._writeLit(r[C++],E,h,f);if(0!=I){var P=e[R+1],F=P>>16,B=P>>8&255,j=255&P;A(h,f=s.F._writeLit(257+B,E,h,f),I-b.of0[B]),f+=b.exb[B],v(h,f=s.F._writeLit(j,D,h,f),F-b.df0[j]),f+=b.dxb[j],C+=I}}f=s.F._writeLit(256,E,h,f)}return f},s.F._copyExact=function(t,e,i,s,n){var r=n>>>3;return s[r]=i,s[r+1]=i>>>8,s[r+2]=255-s[r],s[r+3]=255-s[r+1],r+=4,s.set(new Uint8Array(t.buffer,e,i),r),n+(i+4<<3)},s.F.getTrees=function(){for(var t=s.F.U,e=s.F._hufTree(t.lhst,t.ltree,15),i=s.F._hufTree(t.dhst,t.dtree,15),n=[],r=s.F._lenCodes(t.ltree,n),o=[],l=s.F._lenCodes(t.dtree,o),h=0;h<n.length;h+=2)t.ihst[n[h]]++;for(h=0;h<o.length;h+=2)t.ihst[o[h]]++;for(var f=s.F._hufTree(t.ihst,t.itree,7),u=19;u>4&&0==t.itree[1+(t.ordr[u-1]<<1)];)u--;return[e,i,f,r,l,u,n,o]},s.F.getSecond=function(t){for(var e=[],i=0;i<t.length;i+=2)e.push(t[i+1]);return e},s.F.nonZero=function(t){for(var e="",i=0;i<t.length;i+=2)0!=t[i+1]&&(e+=(i>>1)+",");return e},s.F.contSize=function(t,e){for(var i=0,s=0;s<e.length;s++)i+=e[s]*t[1+(s<<1)];return i},s.F._codeTiny=function(t,e,i,n){for(var r=0;r<t.length;r+=2){var o=t[r],l=t[r+1];n=s.F._writeLit(o,e,i,n);var h=16==o?2:17==o?3:7;o>15&&(s.F._putsE(i,n,l,h),n+=h)}return n},s.F._lenCodes=function(t,e){for(var i=t.length;2!=i&&0==t[i-1];)i-=2;for(var s=0;s<i;s+=2){var n=t[s+1],r=s+3<i?t[s+3]:-1,o=s+5<i?t[s+5]:-1,l=0==s?-1:t[s-1];if(0==n&&r==n&&o==n){for(var h=s+5;h+2<i&&t[h+2]==n;)h+=2;(f=Math.min(h+1-s>>>1,138))<11?e.push(17,f-3):e.push(18,f-11),s+=2*f-2}else if(n==l&&r==n&&o==n){for(h=s+5;h+2<i&&t[h+2]==n;)h+=2;var f=Math.min(h+1-s>>>1,6);e.push(16,f-3),s+=2*f-2}else e.push(n,0)}return i>>>1},s.F._hufTree=function(t,e,i){var n=[],r=t.length,o=e.length,l=0;for(l=0;l<o;l+=2)e[l]=0,e[l+1]=0;for(l=0;l<r;l++)0!=t[l]&&n.push({lit:l,f:t[l]});var h=n.length,f=n.slice(0);if(0==h)return 0;if(1==h){var u=n[0].lit;f=0==u?1:0;return e[1+(u<<1)]=1,e[1+(f<<1)]=1,1}n.sort((function(t,e){return t.f-e.f}));var c=n[0],a=n[1],d=0,w=1,p=2;for(n[0]={lit:-1,f:c.f+a.f,l:c,r:a,d:0};w!=h-1;)c=d!=w&&(p==h||n[d].f<n[p].f)?n[d++]:n[p++],a=d!=w&&(p==h||n[d].f<n[p].f)?n[d++]:n[p++],n[w++]={lit:-1,f:c.f+a.f,l:c,r:a};var g=s.F.setDepth(n[w-1],0);for(g>i&&(s.F.restrictDepth(f,i,g),g=i),l=0;l<h;l++)e[1+(f[l].lit<<1)]=f[l].d;return g},s.F.setDepth=function(t,e){return-1!=t.lit?(t.d=e,e):Math.max(s.F.setDepth(t.l,e+1),s.F.setDepth(t.r,e+1))},s.F.restrictDepth=function(t,e,i){var s=0,n=1<<i-e,r=0;for(t.sort((function(t,e){return e.d==t.d?t.f-e.f:e.d-t.d})),s=0;s<t.length&&t[s].d>e;s++){var o=t[s].d;t[s].d=e,r+=n-(1<<i-o)}for(r>>>=i-e;r>0;){(o=t[s].d)<e?(t[s].d++,r-=1<<e-o-1):s++}for(;s>=0;s--)t[s].d==e&&r<0&&(t[s].d--,r++);0!=r&&console.log("debt left")},s.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},s.F._writeLit=function(t,e,i,n){return s.F._putsF(i,n,e[t<<1]),n+e[1+(t<<1)]},s.F.inflate=function(t,e){var i=Uint8Array;if(3==t[0]&&0==t[1])return e||new i(0);var n=s.F,r=n._bitsF,o=n._bitsE,l=n._decodeTiny,h=n.makeCodes,f=n.codes2map,u=n._get17,c=n.U,a=null==e;a&&(e=new i(t.length>>>2<<3));for(var d,w,p=0,g=0,m=0,y=0,b=0,v=0,A=0,M=0,k=0;0==p;)if(p=r(t,k,1),g=r(t,k+1,2),k+=3,0!=g){if(a&&(e=s.F._check(e,M+(1<<17))),1==g&&(d=c.flmap,w=c.fdmap,v=511,A=31),2==g){m=o(t,k,5)+257,y=o(t,k+5,5)+1,b=o(t,k+10,4)+4,k+=14;for(var S=0;S<38;S+=2)c.itree[S]=0,c.itree[S+1]=0;var x=1;for(S=0;S<b;S++){var O=o(t,k+3*S,3);c.itree[1+(c.ordr[S]<<1)]=O,O>x&&(x=O)}k+=3*b,h(c.itree,x),f(c.itree,x,c.imap),d=c.lmap,w=c.dmap,k=l(c.imap,(1<<x)-1,m+y,t,k,c.ttree);var E=n._copyOut(c.ttree,0,m,c.ltree);v=(1<<E)-1;var D=n._copyOut(c.ttree,m,y,c.dtree);A=(1<<D)-1,h(c.ltree,E),f(c.ltree,E,d),h(c.dtree,D),f(c.dtree,D,w)}for(;;){var T=d[u(t,k)&v];k+=15&T;var C=T>>>4;if(C>>>8==0)e[M++]=C;else{if(256==C)break;var R=M+C-254;if(C>264){var U=c.ldef[C-257];R=M+(U>>>3)+o(t,k,7&U),k+=7&U}var I=w[u(t,k)&A];k+=15&I;var N=I>>>4,P=c.ddef[N],F=(P>>>4)+r(t,k,15&P);for(k+=15&P,a&&(e=s.F._check(e,M+(1<<17)));M<R;)e[M]=e[M++-F],e[M]=e[M++-F],e[M]=e[M++-F],e[M]=e[M++-F];M=R}}}else{0!=(7&k)&&(k+=8-(7&k));var B=4+(k>>>3),j=t[B-4]|t[B-3]<<8;a&&(e=s.F._check(e,M+j)),e.set(new i(t.buffer,t.byteOffset+B,j),M),k=B+j<<3,M+=j}return e.length==M?e:e.slice(0,M)},s.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},s.F._decodeTiny=function(t,e,i,n,r,o){for(var l=s.F._bitsE,h=s.F._get17,f=0;f<i;){var u=t[h(n,r)&e];r+=15&u;var c=u>>>4;if(c<=15)o[f]=c,f++;else{var a=0,d=0;16==c?(d=3+l(n,r,2),r+=2,a=o[f-1]):17==c?(d=3+l(n,r,3),r+=3):18==c&&(d=11+l(n,r,7),r+=7);for(var w=f+d;f<w;)o[f]=a,f++}}return r},s.F._copyOut=function(t,e,i,s){for(var n=0,r=0,o=s.length>>>1;r<i;){var l=t[r+e];s[r<<1]=0,s[1+(r<<1)]=l,l>n&&(n=l),r++}for(;r<o;)s[r<<1]=0,s[1+(r<<1)]=0,r++;return n},s.F.makeCodes=function(t,e){for(var i,n,r,o,l=s.F.U,h=t.length,f=l.bl_count,u=0;u<=e;u++)f[u]=0;for(u=1;u<h;u+=2)f[t[u]]++;var c=l.next_code;for(i=0,f[0]=0,n=1;n<=e;n++)i=i+f[n-1]<<1,c[n]=i;for(r=0;r<h;r+=2)0!=(o=t[r+1])&&(t[r]=c[o],c[o]++)},s.F.codes2map=function(t,e,i){for(var n=t.length,r=s.F.U.rev15,o=0;o<n;o+=2)if(0!=t[o+1])for(var l=o>>1,h=t[o+1],f=l<<4|h,u=e-h,c=t[o]<<u,a=c+(1<<u);c!=a;){i[r[c]>>>15-e]=f,c++}},s.F.revCodes=function(t,e){for(var i=s.F.U.rev15,n=15-e,r=0;r<t.length;r+=2){var o=t[r]<<e-t[r+1];t[r]=i[o]>>>n}},s.F._putsE=function(t,e,i){i<<=7&e;var s=e>>>3;t[s]|=i,t[s+1]|=i>>>8},s.F._putsF=function(t,e,i){i<<=7&e;var s=e>>>3;t[s]|=i,t[s+1]|=i>>>8,t[s+2]|=i>>>16},s.F._bitsE=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<i)-1},s.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},s.F._get17=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},s.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)},s.F.U=(e=Uint16Array,i=Uint32Array,{next_code:new e(16),bl_count:new e(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 e(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 i(32),flmap:new e(512),fltree:[],fdmap:new e(32),fdtree:[],lmap:new e(32768),ltree:[],ttree:[],dmap:new e(32768),dtree:[],imap:new e(512),itree:[],rev15:new e(32768),lhst:new i(286),dhst:new i(30),ihst:new i(19),lits:new i(15e3),strt:new e(65536),prev:new e(32768)}),function(){for(var t=s.F.U,e=0;e<32768;e++){var i=e;i=(4278255360&(i=(4042322160&(i=(3435973836&(i=(2863311530&i)>>>1|(1431655765&i)<<1))>>>2|(858993459&i)<<2))>>>4|(252645135&i)<<4))>>>8|(16711935&i)<<8,t.rev15[e]=(i>>>16|i<<16)>>>17}function n(t,e,i){for(;0!=e--;)t.push(0,i)}for(e=0;e<32;e++)t.ldef[e]=t.of0[e]<<3|t.exb[e],t.ddef[e]=t.df0[e]<<4|t.dxb[e];n(t.fltree,144,8),n(t.fltree,112,9),n(t.fltree,24,7),n(t.fltree,8,8),s.F.makeCodes(t.fltree,9),s.F.codes2map(t.fltree,9,t.flmap),s.F.revCodes(t.fltree,9),n(t.fdtree,32,5),s.F.makeCodes(t.fdtree,5),s.F.codes2map(t.fdtree,5,t.fdmap),s.F.revCodes(t.fdtree,5),n(t.itree,19,0),n(t.ltree,286,0),n(t.dtree,30,0),n(t.ttree,320,0)}()}();var rh=th({__proto__:null,default:sh},[sh]);const oh=function(){var t={nextZero(t,e){for(;0!=t[e];)e++;return e},readUshort:(t,e)=>t[e]<<8|t[e+1],writeUshort(t,e,i){t[e]=i>>8&255,t[e+1]=255&i},readUint:(t,e)=>16777216*t[e]+(t[e+1]<<16|t[e+2]<<8|t[e+3]),writeUint(t,e,i){t[e]=i>>24&255,t[e+1]=i>>16&255,t[e+2]=i>>8&255,t[e+3]=255&i},readASCII(t,e,i){let s="";for(let n=0;n<i;n++)s+=String.fromCharCode(t[e+n]);return s},writeASCII(t,e,i){for(let s=0;s<i.length;s++)t[e+s]=i.charCodeAt(s)},readBytes(t,e,i){const s=[];for(let n=0;n<i;n++)s.push(t[e+n]);return s},pad:t=>t.length<2?`0${t}`:t,readUTF8(e,i,s){let n,r="";for(let n=0;n<s;n++)r+=`%${t.pad(e[i+n].toString(16))}`;try{n=decodeURIComponent(r)}catch(n){return t.readASCII(e,i,s)}return n}};function e(e,i,s,n){const o=i*s,l=r(n),h=Math.ceil(i*l/8),f=new Uint8Array(4*o),u=new Uint32Array(f.buffer),{ctype:c}=n,{depth:a}=n,d=t.readUshort;if(6==c){const t=o<<2;if(8==a)for(var w=0;w<t;w+=4)f[w]=e[w],f[w+1]=e[w+1],f[w+2]=e[w+2],f[w+3]=e[w+3];if(16==a)for(w=0;w<t;w++)f[w]=e[w<<1]}else if(2==c){const t=n.tabs.tRNS;if(null==t){if(8==a)for(w=0;w<o;w++){var p=3*w;u[w]=255<<24|e[p+2]<<16|e[p+1]<<8|e[p]}if(16==a)for(w=0;w<o;w++){p=6*w;u[w]=255<<24|e[p+4]<<16|e[p+2]<<8|e[p]}}else{var g=t[0];const i=t[1],s=t[2];if(8==a)for(w=0;w<o;w++){var m=w<<2;p=3*w;u[w]=255<<24|e[p+2]<<16|e[p+1]<<8|e[p],e[p]==g&&e[p+1]==i&&e[p+2]==s&&(f[m+3]=0)}if(16==a)for(w=0;w<o;w++){m=w<<2,p=6*w;u[w]=255<<24|e[p+4]<<16|e[p+2]<<8|e[p],d(e,p)==g&&d(e,p+2)==i&&d(e,p+4)==s&&(f[m+3]=0)}}}else if(3==c){const t=n.tabs.PLTE,r=n.tabs.tRNS,l=r?r.length:0;if(1==a)for(var y=0;y<s;y++){var b=y*h,v=y*i;for(w=0;w<i;w++){m=v+w<<2;var A=3*(M=e[b+(w>>3)]>>7-((7&w)<<0)&1);f[m]=t[A],f[m+1]=t[A+1],f[m+2]=t[A+2],f[m+3]=M<l?r[M]:255}}if(2==a)for(y=0;y<s;y++)for(b=y*h,v=y*i,w=0;w<i;w++){m=v+w<<2,A=3*(M=e[b+(w>>2)]>>6-((3&w)<<1)&3);f[m]=t[A],f[m+1]=t[A+1],f[m+2]=t[A+2],f[m+3]=M<l?r[M]:255}if(4==a)for(y=0;y<s;y++)for(b=y*h,v=y*i,w=0;w<i;w++){m=v+w<<2,A=3*(M=e[b+(w>>1)]>>4-((1&w)<<2)&15);f[m]=t[A],f[m+1]=t[A+1],f[m+2]=t[A+2],f[m+3]=M<l?r[M]:255}if(8==a)for(w=0;w<o;w++){var M;m=w<<2,A=3*(M=e[w]);f[m]=t[A],f[m+1]=t[A+1],f[m+2]=t[A+2],f[m+3]=M<l?r[M]:255}}else if(4==c){if(8==a)for(w=0;w<o;w++){m=w<<2;var k=e[S=w<<1];f[m]=k,f[m+1]=k,f[m+2]=k,f[m+3]=e[S+1]}if(16==a)for(w=0;w<o;w++){var S;m=w<<2,k=e[S=w<<2];f[m]=k,f[m+1]=k,f[m+2]=k,f[m+3]=e[S+2]}}else if(0==c)for(g=n.tabs.tRNS?n.tabs.tRNS:-1,y=0;y<s;y++){const t=y*h,s=y*i;if(1==a)for(var x=0;x<i;x++){var O=(k=255*(e[t+(x>>>3)]>>>7-(7&x)&1))==255*g?0:255;u[s+x]=O<<24|k<<16|k<<8|k}else if(2==a)for(x=0;x<i;x++){O=(k=85*(e[t+(x>>>2)]>>>6-((3&x)<<1)&3))==85*g?0:255;u[s+x]=O<<24|k<<16|k<<8|k}else if(4==a)for(x=0;x<i;x++){O=(k=17*(e[t+(x>>>1)]>>>4-((1&x)<<2)&15))==17*g?0:255;u[s+x]=O<<24|k<<16|k<<8|k}else if(8==a)for(x=0;x<i;x++){O=(k=e[t+x])==g?0:255;u[s+x]=O<<24|k<<16|k<<8|k}else if(16==a)for(x=0;x<i;x++){k=e[t+(x<<1)],O=d(e,t+(x<<1))==g?0:255;u[s+x]=O<<24|k<<16|k<<8|k}}return f}function i(t,e,i,l){const h=r(t),f=Math.ceil(i*h/8),u=new Uint8Array((f+1+t.interlace)*l);return e=t.tabs.CgBI?n(e,u):s(e,u),0==t.interlace?e=o(e,t,0,i,l):1==t.interlace&&(e=function t(e,i){const s=i.width,n=i.height,l=r(i),h=l>>3,f=Math.ceil(s*l/8),u=new Uint8Array(n*f);let c=0;const a=[0,0,4,0,2,0,1],d=[0,4,0,2,0,1,0],w=[8,8,8,4,4,2,2],p=[8,8,4,4,2,2,1];let g=0;for(;g<7;){const t=w[g],r=p[g];let y=0,b=0,v=a[g];for(;v<n;)v+=t,b++;let A=d[g];for(;A<s;)A+=r,y++;const M=Math.ceil(y*l/8);o(e,i,c,y,b);let k=0,S=a[g];for(;S<n;){let i=d[g],n=c+k*M<<3;for(;i<s;){var m;if(1==l)m=(m=e[n>>3])>>7-(7&n)&1,u[S*f+(i>>3)]|=m<<7-((7&i)<<0);if(2==l)m=(m=e[n>>3])>>6-(7&n)&3,u[S*f+(i>>2)]|=m<<6-((3&i)<<1);if(4==l)m=(m=e[n>>3])>>4-(7&n)&15,u[S*f+(i>>1)]|=m<<4-((1&i)<<2);if(l>=8){const t=S*f+i*h;for(let i=0;i<h;i++)u[t+i]=e[(n>>3)+i]}n+=l,i+=r}k++,S+=t}y*b!=0&&(c+=b*(1+M)),g+=1}return u}(e,t)),e}function s(t,e){return n(new Uint8Array(t.buffer,2,t.length-6),e)}var n=function(){const t={H:{}};return t.H.N=function(e,i){const s=Uint8Array;let n,r,o=0,l=0,h=0,f=0,u=0,c=0,a=0,d=0,w=0;if(3==e[0]&&0==e[1])return i||new s(0);const p=t.H,g=p.b,m=p.e,y=p.R,b=p.n,v=p.A,A=p.Z,M=p.m,k=null==i;for(k&&(i=new s(e.length>>>2<<5));0==o;)if(o=g(e,w,1),l=g(e,w+1,2),w+=3,0!=l){if(k&&(i=t.H.W(i,d+(1<<17))),1==l&&(n=M.J,r=M.h,c=511,a=31),2==l){h=m(e,w,5)+257,f=m(e,w+5,5)+1,u=m(e,w+10,4)+4,w+=14;let t=1;for(var S=0;S<38;S+=2)M.Q[S]=0,M.Q[S+1]=0;for(S=0;S<u;S++){const i=m(e,w+3*S,3);M.Q[1+(M.X[S]<<1)]=i,i>t&&(t=i)}w+=3*u,b(M.Q,t),v(M.Q,t,M.u),n=M.w,r=M.d,w=y(M.u,(1<<t)-1,h+f,e,w,M.v);const i=p.V(M.v,0,h,M.C);c=(1<<i)-1;const s=p.V(M.v,h,f,M.D);a=(1<<s)-1,b(M.C,i),v(M.C,i,n),b(M.D,s),v(M.D,s,r)}for(;;){const t=n[A(e,w)&c];w+=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,w,7&i),w+=7&i}const n=r[A(e,w)&a];w+=15&n;const o=n>>>4,l=M.c[o],h=(l>>>4)+g(e,w,15&l);for(w+=15&l;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{0!=(7&w)&&(w+=8-(7&w));const n=4+(w>>>3),r=e[n-4]|e[n-3]<<8;k&&(i=t.H.W(i,d+r)),i.set(new s(e.buffer,e.byteOffset+n,r),d),w=n+r<<3,d+=r}return i.length==d?i:i.slice(0,d)},t.H.W=function(t,e){const i=t.length;if(e<=i)return t;const s=new Uint8Array(i<<1);return s.set(t,0),s},t.H.R=function(e,i,s,n,r,o){const l=t.H.e,h=t.H.Z;let f=0;for(;f<s;){const t=e[h(n,r)&i];r+=15&t;const s=t>>>4;if(s<=15)o[f]=s,f++;else{let t=0,e=0;16==s?(e=3+l(n,r,2),r+=2,t=o[f-1]):17==s?(e=3+l(n,r,3),r+=3):18==s&&(e=11+l(n,r,7),r+=7);const i=f+e;for(;f<i;)o[f]=t,f++}}return r},t.H.V=function(t,e,i,s){let n=0,r=0;const o=s.length>>>1;for(;r<i;){const i=t[r+e];s[r<<1]=0,s[1+(r<<1)]=i,i>n&&(n=i),r++}for(;r<o;)s[r<<1]=0,s[1+(r<<1)]=0,r++;return n},t.H.n=function(e,i){const s=t.H.m,n=e.length;let r,o,l;let h;const f=s.j;for(var u=0;u<=i;u++)f[u]=0;for(u=1;u<n;u+=2)f[e[u]]++;const c=s.K;for(r=0,f[0]=0,o=1;o<=i;o++)r=r+f[o-1]<<1,c[o]=r;for(l=0;l<n;l+=2)h=e[l+1],0!=h&&(e[l]=c[h],c[h]++)},t.H.A=function(e,i,s){const n=e.length,r=t.H.m.r;for(let t=0;t<n;t+=2)if(0!=e[t+1]){const n=t>>1,o=e[t+1],l=n<<4|o,h=i-o;let f=e[t]<<h;const u=f+(1<<h);for(;f!=u;){s[r[f]>>>15-i]=l,f++}}},t.H.l=function(e,i){const s=t.H.m.r,n=15-i;for(let t=0;t<e.length;t+=2){const r=e[t]<<i-e[t+1];e[t]=s[r]>>>n}},t.H.M=function(t,e,i){i<<=7&e;const s=e>>>3;t[s]|=i,t[s+1]|=i>>>8},t.H.I=function(t,e,i){i<<=7&e;const s=e>>>3;t[s]|=i,t[s+1]|=i>>>8,t[s+2]|=i>>>16},t.H.e=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8)>>>(7&e)&(1<<i)-1},t.H.b=function(t,e,i){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)&(1<<i)-1},t.H.Z=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16)>>>(7&e)},t.H.i=function(t,e){return(t[e>>>3]|t[1+(e>>>3)]<<8|t[2+(e>>>3)]<<16|t[3+(e>>>3)]<<24)>>>(7&e)},t.H.m=function(){const t=Uint16Array,e=Uint32Array;return{K:new t(16),j:new t(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new t(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new e(32),J:new t(512),_:[],h:new t(32),$:[],w:new t(32768),C:[],v:[],d:new t(32768),D:[],u:new t(512),Q:[],r:new t(32768),s:new e(286),Y:new e(30),a:new e(19),t:new e(15e3),k:new t(65536),g:new t(32768)}}(),function(){const e=t.H.m;for(var i=0;i<32768;i++){let t=i;t=(2863311530&t)>>>1|(1431655765&t)<<1,t=(3435973836&t)>>>2|(858993459&t)<<2,t=(4042322160&t)>>>4|(252645135&t)<<4,t=(4278255360&t)>>>8|(16711935&t)<<8,e.r[i]=(t>>>16|t<<16)>>>17}function s(t,e,i){for(;0!=e--;)t.push(0,i)}for(i=0;i<32;i++)e.q[i]=e.S[i]<<3|e.T[i],e.c[i]=e.p[i]<<4|e.z[i];s(e._,144,8),s(e._,112,9),s(e._,24,7),s(e._,8,8),t.H.n(e._,9),t.H.A(e._,9,e.J),t.H.l(e._,9),s(e.$,32,5),t.H.n(e.$,5),t.H.A(e.$,5,e.h),t.H.l(e.$,5),s(e.Q,19,0),s(e.C,286,0),s(e.D,30,0),s(e.v,320,0)}(),t.H.N}();function r(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function o(t,e,i,s,n){let o=r(e);const h=Math.ceil(s*o/8);let f,u;o=Math.ceil(o/8);let c=t[i],a=0;if(c>1&&(t[i]=[0,0,1][c-2]),3==c)for(a=o;a<h;a++)t[a+1]=t[a+1]+(t[a+1-o]>>>1)&255;for(let e=0;e<n;e++)if(f=i+e*h,u=f+e+1,c=t[u-1],a=0,0==c)for(;a<h;a++)t[f+a]=t[u+a];else if(1==c){for(;a<o;a++)t[f+a]=t[u+a];for(;a<h;a++)t[f+a]=t[u+a]+t[f+a-o]}else if(2==c)for(;a<h;a++)t[f+a]=t[u+a]+t[f+a-h];else if(3==c){for(;a<o;a++)t[f+a]=t[u+a]+(t[f+a-h]>>>1);for(;a<h;a++)t[f+a]=t[u+a]+(t[f+a-h]+t[f+a-o]>>>1)}else{for(;a<o;a++)t[f+a]=t[u+a]+l(0,t[f+a-h],0);for(;a<h;a++)t[f+a]=t[u+a]+l(t[f+a-o],t[f+a-h],t[f+a-o-h])}return t}function l(t,e,i){const s=t+e-i,n=s-t,r=s-e,o=s-i;return n*n<=r*r&&n*n<=o*o?t:r*r<=o*o?e:i}function h(e,i,s){s.width=t.readUint(e,i),i+=4,s.height=t.readUint(e,i),i+=4,s.depth=e[i],i++,s.ctype=e[i],i++,s.compress=e[i],i++,s.filter=e[i],i++,s.interlace=e[i],i++}function f(t,e,i,s,n,r,o,l,h){const f=Math.min(e,n),u=Math.min(i,r);let c=0,a=0;for(let i=0;i<u;i++)for(let r=0;r<f;r++)if(o>=0&&l>=0?(c=i*e+r<<2,a=(l+i)*n+o+r<<2):(c=(-l+i)*e-o+r<<2,a=i*n+r<<2),0==h)s[a]=t[c],s[a+1]=t[c+1],s[a+2]=t[c+2],s[a+3]=t[c+3];else if(1==h){var d=t[c+3]*(1/255),w=t[c]*d,p=t[c+1]*d,g=t[c+2]*d,m=s[a+3]*(1/255),y=s[a]*m,b=s[a+1]*m,v=s[a+2]*m;const e=1-d,i=d+m*e,n=0==i?0:1/i;s[a+3]=255*i,s[a+0]=(w+y*e)*n,s[a+1]=(p+b*e)*n,s[a+2]=(g+v*e)*n}else if(2==h){d=t[c+3],w=t[c],p=t[c+1],g=t[c+2],m=s[a+3],y=s[a],b=s[a+1],v=s[a+2];d==m&&w==y&&p==b&&g==v?(s[a]=0,s[a+1]=0,s[a+2]=0,s[a+3]=0):(s[a]=w,s[a+1]=p,s[a+2]=g,s[a+3]=d)}else if(3==h){d=t[c+3],w=t[c],p=t[c+1],g=t[c+2],m=s[a+3],y=s[a],b=s[a+1],v=s[a+2];if(d==m&&w==y&&p==b&&g==v)continue;if(d<220&&m>20)return false}return true}return{decode:function e(r){const o=new Uint8Array(r);let l=8;const f=t,u=f.readUshort,c=f.readUint,a={tabs:{},frames:[]},d=new Uint8Array(o.length);let w,p=0,g=0;const m=[137,80,78,71,13,10,26,10];for(var y=0;y<8;y++)if(o[y]!=m[y])throw"The input is not a PNG file!";for(;l<o.length;){const t=f.readUint(o,l);l+=4;const e=f.readASCII(o,l,4);if(l+=4,"IHDR"==e)h(o,l,a);else if("iCCP"==e){for(var b=l;0!=o[b];)b++;f.readASCII(o,l,b-l);const i=o.slice(b+2,l+t);let r=null;try{r=s(i)}catch(t){r=n(i)}a.tabs[e]=r}else if("CgBI"==e)a.tabs[e]=o.slice(l,l+4);else if("IDAT"==e){for(y=0;y<t;y++)d[p+y]=o[l+y];p+=t}else if("acTL"==e)a.tabs[e]={num_frames:c(o,l),num_plays:c(o,l+4)},w=new Uint8Array(o.length);else if("fcTL"==e){if(0!=g)(x=a.frames[a.frames.length-1]).data=i(a,w.slice(0,g),x.rect.width,x.rect.height),g=0;const t={x:c(o,l+12),y:c(o,l+16),width:c(o,l+4),height:c(o,l+8)};let e=u(o,l+22);e=u(o,l+20)/(0==e?100:e);const s={rect:t,delay:Math.round(1e3*e),dispose:o[l+24],blend:o[l+25]};a.frames.push(s)}else if("fdAT"==e){for(y=0;y<t-4;y++)w[g+y]=o[l+y+4];g+=t-4}else if("pHYs"==e)a.tabs[e]=[f.readUint(o,l),f.readUint(o,l+4),o[l+8]];else if("cHRM"==e){a.tabs[e]=[];for(y=0;y<8;y++)a.tabs[e].push(f.readUint(o,l+4*y))}else if("tEXt"==e||"zTXt"==e){null==a.tabs[e]&&(a.tabs[e]={});var v=f.nextZero(o,l),A=f.readASCII(o,l,v-l),M=l+t-v-1;if("tEXt"==e)S=f.readASCII(o,v+1,M);else{var k=s(o.slice(v+2,v+2+M));S=f.readUTF8(k,0,k.length)}a.tabs[e][A]=S}else if("iTXt"==e){null==a.tabs[e]&&(a.tabs[e]={});v=0,b=l;v=f.nextZero(o,b);A=f.readASCII(o,b,v-b);const i=o[b=v+1];var S;b+=2,v=f.nextZero(o,b),f.readASCII(o,b,v-b),b=v+1,v=f.nextZero(o,b),f.readUTF8(o,b,v-b);M=t-((b=v+1)-l);if(0==i)S=f.readUTF8(o,b,M);else{k=s(o.slice(b,b+M));S=f.readUTF8(k,0,k.length)}a.tabs[e][A]=S}else if("PLTE"==e)a.tabs[e]=f.readBytes(o,l,t);else if("hIST"==e){const t=a.tabs.PLTE.length/3;a.tabs[e]=[];for(y=0;y<t;y++)a.tabs[e].push(u(o,l+2*y))}else if("tRNS"==e)3==a.ctype?a.tabs[e]=f.readBytes(o,l,t):0==a.ctype?a.tabs[e]=u(o,l):2==a.ctype&&(a.tabs[e]=[u(o,l),u(o,l+2),u(o,l+4)]);else if("gAMA"==e)a.tabs[e]=f.readUint(o,l)/1e5;else if("sRGB"==e)a.tabs[e]=o[l];else if("bKGD"==e)0==a.ctype||4==a.ctype?a.tabs[e]=[u(o,l)]:2==a.ctype||6==a.ctype?a.tabs[e]=[u(o,l),u(o,l+2),u(o,l+4)]:3==a.ctype&&(a.tabs[e]=o[l]);else if("IEND"==e)break;l+=t,f.readUint(o,l),l+=4}var x;return 0!=g&&((x=a.frames[a.frames.length-1]).data=i(a,w.slice(0,g),x.rect.width,x.rect.height)),a.data=i(a,d,a.width,a.height),delete a.compress,delete a.interlace,delete a.filter,a},toRGBA8:function t(i){const s=i.width,n=i.height;if(null==i.tabs.acTL)return[e(i.data,s,n,i).buffer];const r=[];null==i.frames[0].data&&(i.frames[0].data=i.data);const o=s*n*4,l=new Uint8Array(o),h=new Uint8Array(o),u=new Uint8Array(o);for(let t=0;t<i.frames.length;t++){const a=i.frames[t],d=a.rect.x,w=a.rect.y,p=a.rect.width,g=a.rect.height,m=e(a.data,p,g,i);if(0!=t)for(var c=0;c<o;c++)u[c]=l[c];if(0==a.blend?f(m,p,g,l,s,n,d,w,0):1==a.blend&&f(m,p,g,l,s,n,d,w,1),r.push(l.buffer.slice(0)),0==a.dispose);else if(1==a.dispose)f(h,p,g,l,s,n,d,w,0);else if(2==a.dispose)for(c=0;c<o;c++)l[c]=u[c]}return r},_paeth:l,_copyTile:f,_bin:t}}();!function(){const{_copyTile:t}=oh,{_bin:e}=oh,i=oh._paeth;var s={table:function(){const t=new Uint32Array(256);for(let e=0;e<256;e++){let i=e;for(let t=0;t<8;t++)1&i?i=3988292384^i>>>1:i>>>=1;t[e]=i}return t}(),update(t,e,i,n){for(let r=0;r<n;r++)t=s.table[255&(t^e[i+r])]^t>>>8;return t},crc:(t,e,i)=>4294967295^s.update(4294967295,t,e,i)};function n(t,e,i,s){e[i]+=t[0]*s>>4,e[i+1]+=t[1]*s>>4,e[i+2]+=t[2]*s>>4,e[i+3]+=t[3]*s>>4}function r(t){return Math.max(0,Math.min(255,t))}function o(t,e){const i=t[0]-e[0],s=t[1]-e[1],n=t[2]-e[2],r=t[3]-e[3];return i*i+s*s+n*n+r*r}function l(t,e,i,s,l,h,f){null==f&&(f=1);const u=s.length,c=[];for(var a=0;a<u;a++){const t=s[a];c.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(a=0;a<u;a++){let t=4294967295;for(var d=0,w=0;w<u;w++){var p=o(c[a],c[w]);w!=a&&p<t&&(t=p,d=w)}}const g=new Uint32Array(l.buffer),m=new Int16Array(e*i*4),y=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(a=0;a<y.length;a++)y[a]=255*((y[a]+.5)/16-.5);for(let l=0;l<i;l++)for(let v=0;v<e;v++){var b;a=4*(l*e+v);if(2!=f)b=[r(t[a]+m[a]),r(t[a+1]+m[a+1]),r(t[a+2]+m[a+2]),r(t[a+3]+m[a+3])];else{p=y[4*(3&l)+(3&v)];b=[r(t[a]+p),r(t[a+1]+p),r(t[a+2]+p),r(t[a+3]+p)]}d=0;let A=16777215;for(w=0;w<u;w++){const t=o(b,c[w]);t<A&&(A=t,d=w)}const M=c[d],k=[b[0]-M[0],b[1]-M[1],b[2]-M[2],b[3]-M[3]];1==f&&(v!=e-1&&n(k,m,a+4,7),l!=i-1&&(0!=v&&n(k,m,a+4*e-4,3),n(k,m,a+4*e,5),v!=e-1&&n(k,m,a+4*e+4,1))),h[a>>2]=d,g[a>>2]=s[d]}}function h(t,i,n,r,o){null==o&&(o={});const{crc:l}=s,h=e.writeUint,f=e.writeUshort,u=e.writeASCII;let c=8;const a=t.frames.length>1;let d,w=false,p=33+(a?20:0);if(null!=o.sRGB&&(p+=13),null!=o.pHYs&&(p+=21),null!=o.iCCP&&(d=pako.deflate(o.iCCP),p+=21+d.length+4),3==t.ctype){for(var g=t.plte.length,m=0;m<g;m++)t.plte[m]>>>24!=255&&(w=true);p+=8+3*g+4+(w?8+1*g+4:0)}for(var y=0;y<t.frames.length;y++){a&&(p+=38),p+=(M=t.frames[y]).cimg.length+12,0!=y&&(p+=4)}p+=12;const b=new Uint8Array(p),v=[137,80,78,71,13,10,26,10];for(m=0;m<8;m++)b[m]=v[m];if(h(b,c,13),c+=4,u(b,c,"IHDR"),c+=4,h(b,c,i),c+=4,h(b,c,n),c+=4,b[c]=t.depth,c++,b[c]=t.ctype,c++,b[c]=0,c++,b[c]=0,c++,b[c]=0,c++,h(b,c,l(b,c-17,17)),c+=4,null!=o.sRGB&&(h(b,c,1),c+=4,u(b,c,"sRGB"),c+=4,b[c]=o.sRGB,c++,h(b,c,l(b,c-5,5)),c+=4),null!=o.iCCP){const t=13+d.length;h(b,c,t),c+=4,u(b,c,"iCCP"),c+=4,u(b,c,"ICC profile"),c+=11,c+=2,b.set(d,c),c+=d.length,h(b,c,l(b,c-(t+4),t+4)),c+=4}if(null!=o.pHYs&&(h(b,c,9),c+=4,u(b,c,"pHYs"),c+=4,h(b,c,o.pHYs[0]),c+=4,h(b,c,o.pHYs[1]),c+=4,b[c]=o.pHYs[2],c++,h(b,c,l(b,c-13,13)),c+=4),a&&(h(b,c,8),c+=4,u(b,c,"acTL"),c+=4,h(b,c,t.frames.length),c+=4,h(b,c,null!=o.loop?o.loop:0),c+=4,h(b,c,l(b,c-12,12)),c+=4),3==t.ctype){h(b,c,3*(g=t.plte.length)),c+=4,u(b,c,"PLTE"),c+=4;for(m=0;m<g;m++){const e=3*m,i=t.plte[m],s=255&i,n=i>>>8&255,r=i>>>16&255;b[c+e+0]=s,b[c+e+1]=n,b[c+e+2]=r}if(c+=3*g,h(b,c,l(b,c-3*g-4,3*g+4)),c+=4,w){h(b,c,g),c+=4,u(b,c,"tRNS"),c+=4;for(m=0;m<g;m++)b[c+m]=t.plte[m]>>>24&255;c+=g,h(b,c,l(b,c-g-4,g+4)),c+=4}}let A=0;for(y=0;y<t.frames.length;y++){var M=t.frames[y];a&&(h(b,c,26),c+=4,u(b,c,"fcTL"),c+=4,h(b,c,A++),c+=4,h(b,c,M.rect.width),c+=4,h(b,c,M.rect.height),c+=4,h(b,c,M.rect.x),c+=4,h(b,c,M.rect.y),c+=4,f(b,c,r[y]),c+=2,f(b,c,1e3),c+=2,b[c]=M.dispose,c++,b[c]=M.blend,c++,h(b,c,l(b,c-30,30)),c+=4);const e=M.cimg;h(b,c,(g=e.length)+(0==y?0:4)),c+=4;const i=c;u(b,c,0==y?"IDAT":"fdAT"),c+=4,0!=y&&(h(b,c,A++),c+=4),b.set(e,c),c+=g,h(b,c,l(b,i,c-i)),c+=4}return h(b,c,0),c+=4,u(b,c,"IEND"),c+=4,h(b,c,l(b,c-4,4)),c+=4,b.buffer}function f(t,e,i){for(let s=0;s<t.frames.length;s++){const n=t.frames[s];const r=n.rect.height,o=new Uint8Array(r*n.bpl+r);n.cimg=d(n.img,r,n.bpp,n.bpl,o,e,i)}}function u(e,i,s,n,r){const o=r[0],h=r[1],f=r[2],u=r[3],d=r[4],w=r[5];let g=6,m=8,y=255;for(var b=0;b<e.length;b++){const t=new Uint8Array(e[b]);for(var v=t.length,A=0;A<v;A+=4)y&=t[A+3]}const M=255!=y,k=function e(i,s,n,r,o,l){const h=[];for(var f=0;f<i.length;f++){const e=new Uint8Array(i[f]),c=new Uint32Array(e.buffer);var u;let w=0,g=0,m=s,y=n,b=r?1:0;if(0!=f){const v=l||r||1==f||0!=h[f-2].dispose?1:2;let A=0,M=1e9;for(let t=0;t<v;t++){var d=new Uint8Array(i[f-1-t]);const e=new Uint32Array(i[f-1-t]);let r=s,l=n,h=-1,u=-1;for(let t=0;t<n;t++)for(let i=0;i<s;i++){c[p=t*s+i]!=e[p]&&(i<r&&(r=i),i>h&&(h=i),t<l&&(l=t),t>u&&(u=t))}-1==h&&(r=l=h=u=0),o&&(1==(1&r)&&r--,1==(1&l)&&l--);const a=(h-r+1)*(u-l+1);a<M&&(M=a,A=t,w=r,g=l,m=h-r+1,y=u-l+1)}d=new Uint8Array(i[f-1-A]);1==A&&(h[f-1].dispose=2),u=new Uint8Array(m*y*4),t(d,s,n,u,m,y,-w,-g,0),b=t(e,s,n,u,m,y,-w,-g,3)?1:0,1==b?a(e,s,n,u,{x:w,y:g,width:m,height:y}):t(e,s,n,u,m,y,-w,-g,0)}else u=e.slice(0);h.push({rect:{x:w,y:g,width:m,height:y},img:u,blend:b,dispose:0})}if(r)for(f=0;f<h.length;f++){if(1==(g=h[f]).blend)continue;const t=g.rect,e=h[f-1].rect,r=Math.min(t.x,e.x),l=Math.min(t.y,e.y),u={x:r,y:l,width:Math.max(t.x+t.width,e.x+e.width)-r,height:Math.max(t.y+t.height,e.y+e.height)-l};h[f-1].dispose=1,f-1!=0&&c(i,s,n,h,f-1,u,o),c(i,s,n,h,f,u,o)}let w=0;if(1!=i.length)for(var p=0;p<h.length;p++){var g;w+=(g=h[p]).rect.width*g.rect.height}return h}(e,i,s,o,h,f),S={},x=[],O=[];if(0!=n){const t=[];for(A=0;A<k.length;A++)t.push(k[A].img.buffer);const e=function t(e){let i=0;for(var s=0;s<e.length;s++)i+=e[s].byteLength;const n=new Uint8Array(i);let r=0;for(s=0;s<e.length;s++){const t=new Uint8Array(e[s]),i=t.length;for(let e=0;e<i;e+=4){let i=t[e],s=t[e+1],o=t[e+2];const l=t[e+3];0==l&&(i=s=o=0),n[r+e]=i,n[r+e+1]=s,n[r+e+2]=o,n[r+e+3]=l}r+=i}return n.buffer}(t),i=p(e,n);for(A=0;A<i.plte.length;A++)x.push(i.plte[A].est.rgba);let s=0;for(A=0;A<k.length;A++){const t=(D=k[A]).img.length;var E=new Uint8Array(i.inds.buffer,s>>2,t>>2);O.push(E);const e=new Uint8Array(i.abuf,s,t);w&&l(D.img,D.rect.width,D.rect.height,x,e,E),D.img.set(e),s+=t}}else for(b=0;b<k.length;b++){var D=k[b];const t=new Uint32Array(D.img.buffer);var T=D.rect.width;v=t.length,E=new Uint8Array(v);O.push(E);for(A=0;A<v;A++){const e=t[A];if(0!=A&&e==t[A-1])E[A]=E[A-1];else if(A>T&&e==t[A-T])E[A]=E[A-T];else{let t=S[e];if(null==t&&(S[e]=t=x.length,x.push(e),x.length>=300))break;E[A]=t}}}const C=x.length;C<=256&&0==d&&(m=C<=2?1:C<=4?2:C<=16?4:8,m=Math.max(m,u));for(b=0;b<k.length;b++){(D=k[b]).rect.x;T=D.rect.width;const t=D.rect.height;let e=D.img;let i=4*T,s=4;if(C<=256&&0==d){i=Math.ceil(m*T/8);var R=new Uint8Array(i*t);const n=O[b];for(let e=0;e<t;e++){A=e*i;const t=e*T;if(8==m)for(var U=0;U<T;U++)R[A+U]=n[t+U];else if(4==m)for(U=0;U<T;U++)R[A+(U>>1)]|=n[t+U]<<4-4*(1&U);else if(2==m)for(U=0;U<T;U++)R[A+(U>>2)]|=n[t+U]<<6-2*(3&U);else if(1==m)for(U=0;U<T;U++)R[A+(U>>3)]|=n[t+U]<<7-1*(7&U)}e=R,g=3,s=1}else if(0==M&&1==k.length){R=new Uint8Array(T*t*3);const n=T*t;for(A=0;A<n;A++){const t=3*A,i=4*A;R[t]=e[i],R[t+1]=e[i+1],R[t+2]=e[i+2]}e=R,g=2,s=3,i=3*T}D.img=e,D.bpl=i,D.bpp=s}return{ctype:g,depth:m,plte:x,frames:k}}function c(e,i,s,n,r,o,l){const h=Uint8Array,f=Uint32Array,u=new h(e[r-1]),c=new f(e[r-1]),d=r+1<e.length?new h(e[r+1]):null,w=new h(e[r]),p=new f(w.buffer);let g=i,m=s,y=-1,b=-1;for(let t=0;t<o.height;t++)for(let e=0;e<o.width;e++){const s=o.x+e,l=o.y+t,h=l*i+s,f=p[h];0==f||0==n[r-1].dispose&&c[h]==f&&(null==d||0!=d[4*h+3])||(s<g&&(g=s),s>y&&(y=s),l<m&&(m=l),l>b&&(b=l))}-1==y&&(g=m=y=b=0),l&&(1==(1&g)&&g--,1==(1&m)&&m--),o={x:g,y:m,width:y-g+1,height:b-m+1};const v=n[r];v.rect=o,v.blend=1,v.img=new Uint8Array(o.width*o.height*4),0==n[r-1].dispose?(t(u,i,s,v.img,o.width,o.height,-o.x,-o.y,0),a(w,i,s,v.img,o)):t(w,i,s,v.img,o.width,o.height,-o.x,-o.y,0)}function a(e,i,s,n,r){t(e,i,s,n,r.width,r.height,-r.x,-r.y,2)}function d(t,e,i,s,n,r,o){const l=[];let h,f=[0,1,2,3,4];-1!=r?f=[r]:(e*s>5e5||1==i)&&(f=[0]),o&&(h={level:0});const u=rh;for(var c=0;c<f.length;c++){for(let r=0;r<e;r++)w(n,t,r,s,i,f[c]);l.push(u.deflate(n,h))}let a,d=1e9;for(c=0;c<l.length;c++)l[c].length<d&&(a=c,d=l[c].length);return l[a]}function w(t,e,s,n,r,o){const l=s*n;let h=l+s;if(t[h]=o,h++,0==o)if(n<500)for(var f=0;f<n;f++)t[h+f]=e[l+f];else t.set(new Uint8Array(e.buffer,l,n),h);else if(1==o){for(f=0;f<r;f++)t[h+f]=e[l+f];for(f=r;f<n;f++)t[h+f]=e[l+f]-e[l+f-r]+256&255}else if(0==s){for(f=0;f<r;f++)t[h+f]=e[l+f];if(2==o)for(f=r;f<n;f++)t[h+f]=e[l+f];if(3==o)for(f=r;f<n;f++)t[h+f]=e[l+f]-(e[l+f-r]>>1)+256&255;if(4==o)for(f=r;f<n;f++)t[h+f]=e[l+f]-i(e[l+f-r],0,0)+256&255}else{if(2==o)for(f=0;f<n;f++)t[h+f]=e[l+f]+256-e[l+f-n]&255;if(3==o){for(f=0;f<r;f++)t[h+f]=e[l+f]+256-(e[l+f-n]>>1)&255;for(f=r;f<n;f++)t[h+f]=e[l+f]+256-(e[l+f-n]+e[l+f-r]>>1)&255}if(4==o){for(f=0;f<r;f++)t[h+f]=e[l+f]+256-i(0,e[l+f-n],0)&255;for(f=r;f<n;f++)t[h+f]=e[l+f]+256-i(e[l+f-r],e[l+f-n],e[l+f-r-n])&255}}}function p(t,e){const i=new Uint8Array(t),s=i.slice(0),n=new Uint32Array(s.buffer),r=g(s,e),o=r[0],l=r[1],h=i.length,f=new Uint8Array(h>>2);let u;if(i.length<2e7)for(var c=0;c<h;c+=4){u=m(o,a=i[c]*(1/255),d=i[c+1]*(1/255),w=i[c+2]*(1/255),p=i[c+3]*(1/255)),f[c>>2]=u.ind,n[c>>2]=u.est.rgba}else for(c=0;c<h;c+=4){var a=i[c]*(1/255),d=i[c+1]*(1/255),w=i[c+2]*(1/255),p=i[c+3]*(1/255);for(u=o;u.left;)u=y(u.est,a,d,w,p)<=0?u.left:u.right;f[c>>2]=u.ind,n[c>>2]=u.est.rgba}return{abuf:s.buffer,inds:f,plte:l}}function g(t,e,i){null==i&&(i=1e-4);const s=new Uint32Array(t.buffer),n={i0:0,i1:t.length,bst:null,est:null,tdst:0,left:null,right:null};n.bst=A(t,n.i0,n.i1),n.est=M(n.bst);const r=[n];for(;r.length<e;){let e=0,n=0;for(var o=0;o<r.length;o++)r[o].est.L>e&&(e=r[o].est.L,n=o);if(e<i)break;const l=r[n],h=b(t,s,l.i0,l.i1,l.est.e,l.est.eMq255);if(l.i0>=h||l.i1<=h){l.est.L=0;continue}const f={i0:l.i0,i1:h,bst:null,est:null,tdst:0,left:null,right:null};f.bst=A(t,f.i0,f.i1),f.est=M(f.bst);const u={i0:h,i1:l.i1,bst:null,est:null,tdst:0,left:null,right:null};u.bst={R:[],m:[],N:l.bst.N-f.bst.N};for(o=0;o<16;o++)u.bst.R[o]=l.bst.R[o]-f.bst.R[o];for(o=0;o<4;o++)u.bst.m[o]=l.bst.m[o]-f.bst.m[o];u.est=M(u.bst),l.left=f,l.right=u,r[n]=f,r.push(u)}r.sort(((t,e)=>e.bst.N-t.bst.N));for(o=0;o<r.length;o++)r[o].ind=o;return[n,r]}function m(t,e,i,s,n){if(null==t.left)return t.tdst=function t(e,i,s,n,r){const o=i-e[0],l=s-e[1],h=n-e[2],f=r-e[3];return o*o+l*l+h*h+f*f}(t.est.q,e,i,s,n),t;const r=y(t.est,e,i,s,n);let o=t.left,l=t.right;r>0&&(o=t.right,l=t.left);const h=m(o,e,i,s,n);if(h.tdst<=r*r)return h;const f=m(l,e,i,s,n);return f.tdst<h.tdst?f:h}function y(t,e,i,s,n){const{e:r}=t;return r[0]*e+r[1]*i+r[2]*s+r[3]*n-t.eMq}function b(t,e,i,s,n,r){for(s-=4;i<s;){for(;v(t,i,n)<=r;)i+=4;for(;v(t,s,n)>r;)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(;v(t,i,n)>r;)i-=4;return i+4}function v(t,e,i){return t[e]*i[0]+t[e+1]*i[1]+t[e+2]*i[2]+t[e+3]*i[3]}function A(t,e,i){const s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=[0,0,0,0],r=i-e>>2;for(let r=e;r<i;r+=4){const e=t[r]*(1/255),i=t[r+1]*(1/255),o=t[r+2]*(1/255),l=t[r+3]*(1/255);n[0]+=e,n[1]+=i,n[2]+=o,n[3]+=l,s[0]+=e*e,s[1]+=e*i,s[2]+=e*o,s[3]+=e*l,s[5]+=i*i,s[6]+=i*o,s[7]+=i*l,s[10]+=o*o,s[11]+=o*l,s[15]+=l*l}return s[4]=s[1],s[8]=s[2],s[9]=s[6],s[12]=s[3],s[13]=s[7],s[14]=s[11],{R:s,m:n,N:r}}function M(t){const{R:e}=t,{m:i}=t,{N:s}=t,n=i[0],r=i[1],o=i[2],l=i[3],h=0==s?0:1/s,f=[e[0]-n*n*h,e[1]-n*r*h,e[2]-n*o*h,e[3]-n*l*h,e[4]-r*n*h,e[5]-r*r*h,e[6]-r*o*h,e[7]-r*l*h,e[8]-o*n*h,e[9]-o*r*h,e[10]-o*o*h,e[11]-o*l*h,e[12]-l*n*h,e[13]-l*r*h,e[14]-l*o*h,e[15]-l*l*h],u=f,c=k;let a=[Math.random(),Math.random(),Math.random(),Math.random()],d=0,w=0;if(0!=s)for(let t=0;t<16&&(a=c.multVec(u,a),w=Math.sqrt(c.dot(a,a)),a=c.sml(1/w,a),!(0!=t&&Math.abs(w-d)<1e-9));t++)d=w;const p=[n*h,r*h,o*h,l*h];return{Cov:f,q:p,e:a,L:d,eMq255:c.dot(c.sml(255,p),a),eMq:c.dot(a,p),rgba:(Math.round(255*p[3])<<24|Math.round(255*p[2])<<16|Math.round(255*p[1])<<8|Math.round(255*p[0])<<0)>>>0}}var k={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]]};oh.encode=function t(e,i,s,n,r,o,l){null==n&&(n=0),null==l&&(l=false);const c=u(e,i,s,n,[false,false,false,0,l,false]);return f(c,-1),h(c,i,s,r,o)},oh.encodeLL=function t(e,i,s,n,r,o,l,u){const c={ctype:0+(1==n?0:2)+(0==r?0:4),depth:o,frames:[]},a=(n+r)*o,d=a*i;for(let t=0;t<e.length;t++)c.frames.push({rect:{x:0,y:0,width:i,height:s},img:new Uint8Array(e[t]),blend:0,dispose:1,bpp:Math.ceil(a/8),bpl:Math.ceil(d/8)});return f(c,0,true),h(c,i,s,l,u)},oh.encode.compress=u,oh.encode.dither=l,oh.quantize=p,oh.quantize.getKDtree=g,oh.quantize.getNearest=m}();const lh={toArrayBuffer(t,e){const i=t.width,s=t.height,n=i<<2,r=t.getContext("2d").getImageData(0,0,i,s),o=new Uint32Array(r.data.buffer),l=(32*i+31)/32<<2,h=l*s,f=122+h,u=new ArrayBuffer(f),c=new DataView(u),a=1<<20;let d,w,p,g,m=a,y=0,b=0,v=0;function A(t){c.setUint16(b,t,true),b+=2}function M(t){c.setUint32(b,t,true),b+=4}function k(t){b+=t}A(19778),M(f),k(4),M(122),M(108),M(i),M(-s>>>0),A(1),A(32),M(3),M(h),M(2835),M(2835),k(8),M(16711680),M(65280),M(255),M(4278190080),M(1466527264),function t(){for(;y<s&&m>0;){for(g=122+y*l,d=0;d<n;)m--,w=o[v++],p=w>>>24,c.setUint32(g+d,w<<8|p),d+=4;y++}v<o.length?(m=a,setTimeout(t,lh._dly)):e(u)}()},toBlob(t,e){this.toArrayBuffer(t,(t=>{e(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var hh={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},fh={[hh.CHROME]:16384,[hh.FIREFOX]:11180,[hh.DESKTOP_SAFARI]:16384,[hh.IE]:8192,[hh.IOS]:4096,[hh.ETC]:8192};const uh="undefined"!=typeof window,ch="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,ah=uh&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),dh=(uh||ch)&&(ah&&ah.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),wh=(uh||ch)&&(ah&&ah.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function ph(t,e,i=Date.now()){return new Promise((s=>{const n=t.split(","),r=n[0].match(/:(.*?);/)[1],o=globalThis.atob(n[1]);let l=o.length;const h=new Uint8Array(l);for(;l--;)h[l]=o.charCodeAt(l);const f=new Blob([h],{type:r});f.name=e,f.lastModified=i,s(f)}))}function gh(t){return new Promise(((e,i)=>{const s=new wh;s.onload=()=>e(s.result),s.onerror=t=>i(t),s.readAsDataURL(t)}))}function mh(t){return new Promise(((e,i)=>{const s=new Image;s.onload=()=>e(s),s.onerror=t=>i(t),s.src=t}))}function yh(){if(void 0!==yh.cachedResult)return yh.cachedResult;let t=hh.ETC;const{userAgent:e}=navigator;return/Chrom(e|ium)/i.test(e)?t=hh.CHROME:/iP(ad|od|hone)/i.test(e)&&/WebKit/i.test(e)?t=hh.IOS:/Safari/i.test(e)?t=hh.DESKTOP_SAFARI:/Firefox/i.test(e)?t=hh.FIREFOX:(/MSIE/i.test(e)||true==!!document.documentMode)&&(t=hh.IE),yh.cachedResult=t,yh.cachedResult}function bh(t,e){const i=yh(),s=fh[i];let n=t,r=e,o=n*r;const l=n>r?r/n:n/r;for(;o>s*s;){const t=(s+n)/2,e=(s+r)/2;t<e?(r=e,n=e*l):(r=t*l,n=t),o=n*r}return{width:n,height:r}}function vh(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 Ah(t,e){const{width:i,height:s}=bh(t.width,t.height),[n,r]=vh(i,s);return e&&/jpe?g/.test(e)&&(r.fillStyle="white",r.fillRect(0,0,n.width,n.height)),r.drawImage(t,0,0,n.width,n.height),n}function Mh(){return void 0!==Mh.cachedResult||(Mh.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),Mh.cachedResult}function kh(t,e={}){return new Promise((function(i,s){let n,r;var o=function(){try{return r=Ah(n,e.fileType||t.type),i([n,r])}catch(t){return s(t)}},l=function(e){try{var i=function(t){try{throw t}catch(t){return s(t)}};try{let e;return gh(t).then((function(t){try{return e=t,mh(e).then((function(t){try{return n=t,function(){try{return o()}catch(t){return s(t)}}()}catch(t){return i(t)}}),i)}catch(t){return i(t)}}),i)}catch(t){i(t)}}catch(t){return s(t)}};try{if(Mh()||[hh.DESKTOP_SAFARI,hh.MOBILE_SAFARI].includes(yh()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return n=t,o()}catch(t){return l()}}),l)}catch(t){l()}}))}function Sh(t,e,i,s,n=1){return new Promise((function(r,o){let l;if("image/png"===e){let f,u,c;return f=t.getContext("2d"),({data:u}=f.getImageData(0,0,t.width,t.height)),c=oh.encode([u.buffer],t.width,t.height,4096*n),l=new Blob([c],{type:e}),l.name=i,l.lastModified=s,h.call(this)}{if("image/bmp"===e)return new Promise((e=>lh.toBlob(t,e))).then(function(t){try{return l=t,l.name=i,l.lastModified=s,a.call(this)}catch(t){return o(t)}}.bind(this),o);{if("function"==typeof OffscreenCanvas&&t instanceof OffscreenCanvas)return t.convertToBlob({type:e,quality:n}).then(function(t){try{return l=t,l.name=i,l.lastModified=s,d.call(this)}catch(t){return o(t)}}.bind(this),o);{let w;return w=t.toDataURL(e,n),ph(w,i,s).then(function(t){try{return l=t,d.call(this)}catch(t){return o(t)}}.bind(this),o)}function d(){return a.call(this)}}function a(){return h.call(this)}}function h(){return r(l)}}))}function xh(t){t.width=0,t.height=0}function Oh(){return new Promise((function(t,e){let i,s,n,r;return void 0!==Oh.cachedResult?t(Oh.cachedResult):ph("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return i=o,kh(i).then((function(o){try{return s=o[1],Sh(s,i.type,i.name,i.lastModified).then((function(i){try{return n=i,xh(s),kh(n).then((function(i){try{return r=i[0],Oh.cachedResult=1===r.width&&2===r.height,t(Oh.cachedResult)}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 Eh(t){return new Promise(((e,i)=>{const s=new wh;s.onload=t=>{const i=new DataView(t.target.result);if(65496!=i.getUint16(0,false))return e(-2);const s=i.byteLength;let n=2;for(;n<s;){if(i.getUint16(n+2,false)<=8)return e(-1);const t=i.getUint16(n,false);if(n+=2,65505==t){if(1165519206!=i.getUint32(n+=2,false))return e(-1);const t=18761==i.getUint16(n+=6,false);n+=i.getUint32(n+4,t);const s=i.getUint16(n,t);n+=2;for(let r=0;r<s;r++)if(274==i.getUint16(n+12*r,t))return e(i.getUint16(n+12*r+8,t))}else{if(65280!=(65280&t))break;n+=i.getUint16(n,false)}}return e(-1)},s.onerror=t=>i(t),s.readAsArrayBuffer(t)}))}function Dh(t,e){const{width:i}=t,{height:s}=t,{maxWidthOrHeight:n}=e;let r,o=t;return isFinite(n)&&(i>n||s>n)&&([o,r]=vh(i,s),i>s?(o.width=n,o.height=s/i*n):(o.width=i/s*n,o.height=n),r.drawImage(t,0,0,o.width,o.height),xh(t)),o}function Th(t,e){const{width:i}=t,{height:s}=t,[n,r]=vh(i,s);switch(e>4&&e<9?(n.width=s,n.height=i):(n.width=i,n.height=s),e){case 2:r.transform(-1,0,0,1,i,0);break;case 3:r.transform(-1,0,0,-1,i,s);break;case 4:r.transform(1,0,0,-1,0,s);break;case 5:r.transform(0,1,1,0,0,0);break;case 6:r.transform(0,1,-1,0,s,0);break;case 7:r.transform(0,-1,-1,0,s,i);break;case 8:r.transform(0,-1,1,0,0,i)}return r.drawImage(t,0,0,i,s),xh(t),n}function Ch(t,e,i=0){return new Promise((function(s,n){let r,o,l,h,f,u,c,a,d,w,p,g,m,y,b,v,A,M,k,S;function x(t=5){if(e.signal&&e.signal.aborted)throw e.signal.reason;r+=t,e.onProgress(Math.min(r,100))}function O(t){if(e.signal&&e.signal.aborted)throw e.signal.reason;r=Math.min(Math.max(t,r),100),e.onProgress(r)}return r=i,o=e.maxIteration||10,l=1024*e.maxSizeMB*1024,x(),kh(t,e).then(function(i){try{return[,h]=i,x(),f=Dh(h,e),x(),new Promise((function(i,s){var n;if(!(n=e.exifOrientation))return Eh(t).then(function(t){try{return n=t,r.call(this)}catch(t){return s(t)}}.bind(this),s);function r(){return i(n)}return r.call(this)})).then(function(i){try{return u=i,x(),Oh().then(function(i){try{return c=i?f:Th(f,u),x(),a=e.initialQuality||1,d=e.fileType||t.type,Sh(c,d,t.name,t.lastModified,a).then(function(i){try{{if(w=i,x(),p=w.size>l,g=w.size>t.size,!p&&!g)return O(100),s(w);var r;function u(){if(o--&&(b>l||b>m)){let e,i;return e=S?.95*k.width:k.width,i=S?.95*k.height:k.height,[A,M]=vh(e,i),M.drawImage(k,0,0,e,i),a*="image/png"===d?.85:.95,Sh(A,d,t.name,t.lastModified,a).then((function(t){try{return v=t,xh(k),k=A,b=v.size,O(Math.min(99,Math.floor((y-b)/(y-l)*100))),u}catch(t){return n(t)}}),n)}return[1]}return m=t.size,y=w.size,b=y,k=c,S=!e.alwaysKeepResolution&&p,(r=function(t){for(;t;){if(t.then)return void t.then(r,n);try{if(t.pop){if(t.length)return t.pop()?E.call(this):t;t=u}else t=t.call(this)}catch(t){return n(t)}}}.bind(this))(u);function E(){return xh(k),xh(A),xh(f),xh(c),xh(h),O(100),s(v)}}}catch(D){return n(D)}}.bind(this),n)}catch(t){return n(t)}}.bind(this),n)}catch(t){return n(t)}}.bind(this),n)}catch(t){return n(t)}}.bind(this),n)}))}const Rh="\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";let Uh;function Ih(t,e){return new Promise(((i,s)=>{Uh||(Uh=function t(e){const i=[];return i.push(e),URL.createObjectURL(new Blob(i))}(Rh));const n=new Worker(Uh);n.addEventListener("message",(function t(r){if(e.signal&&e.signal.aborted)n.terminate();else if(void 0===r.data.progress){if(r.data.error)return s(new Error(r.data.error)),void n.terminate();i(r.data.file),n.terminate()}else e.onProgress(r.data.progress)})),n.addEventListener("error",s),e.signal&&e.signal.addEventListener("abort",(()=>{s(e.signal.reason),n.terminate()})),n.postMessage({file:t,imageCompressionLibUrl:e.libURL,options:{...e,onProgress:void 0,signal:void 0}})}))}function Nh(t,e){return new Promise((function(i,s){let n,r,o,l,h,f;if(n={...e},o=0,({onProgress:l}=n),n.maxSizeMB=n.maxSizeMB||Number.POSITIVE_INFINITY,h="boolean"!=typeof n.useWebWorker||n.useWebWorker,delete n.useWebWorker,n.onProgress=t=>{o=t,"function"==typeof l&&l(o)},!(t instanceof Blob||t instanceof dh))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(f="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!h||"function"!=typeof Worker||f)return Ch(t,n).then(function(t){try{return r=t,a.call(this)}catch(t){return s(t)}}.bind(this),s);var u=function(){try{return a.call(this)}catch(t){return s(t)}}.bind(this),c=function(e){try{return Ch(t,n).then((function(t){try{return r=t,u()}catch(t){return s(t)}}),s)}catch(t){return s(t)}};try{return n.libURL=n.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",Ih(t,n).then((function(t){try{return r=t,u()}catch(t){return c()}}),c)}catch(t){c()}function a(){try{r.name=t.name,r.lastModified=t.lastModified}catch(t){}try{n.preserveExif&&"image/jpeg"===t.type&&(!n.fileType||n.fileType&&n.fileType===t.type)&&(r=eh(t,r))}catch(t){}return i(r)}}))}Nh.getDataUrlFromFile=gh,Nh.getFilefromDataUrl=ph,Nh.loadImage=mh,Nh.drawImageInCanvas=Ah,Nh.drawFileInCanvas=kh,Nh.canvasToFile=Sh,Nh.getExifOrientation=Eh,Nh.handleMaxWidthOrHeight=Dh,Nh.followExifOrientation=Th,Nh.cleanupCanvasMemory=xh,Nh.isAutoOrientationInBrowser=Oh,Nh.approximateBelowMaximumCanvasSizeOfBrowser=bh,Nh.copyExifWithoutOrientation=eh,Nh.getBrowserName=yh,Nh.version="2.0.2";class Ph extends Xl{fileInput=null;maxCompressionSize=300;constructor(t){super(t);this.setupFileInput()}onActivate(){this.openFilePicker()}openFilePicker(){if(this._core.store.isDisabled){return}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;if(e.files&&e.files[0]){const t=e.files[0];Nh(t,{maxWidthOrHeight:this.maxCompressionSize}).then((t=>{this.readFile(t)})).catch((t=>{console.error("Error during image compression or processing:",t);this.handleCancel()}))}else{console.info("File selection cancelled by user.");this.handleCancel()}if(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=Vl.create(this._core);const{scaledWidth:i,scaledHeight:s}=e.calculateScaledDimensions(t);e.src=t.src;e.width=i;e.height=s;e.zIndex=this._core.store.currentZIndex;e.centerInViewport();this.addImageToStore(e);return e}addImageToStore(e){this._core.addObject(e);this._core.store.setState("activeTool",t.getTool("selection"));this._core.selectObjects([e])}handleCancel(){this._core.store.setState("activeTool",t.getTool("selection"))}}class Fh extends Xl{fontFamily="Arial";fontSize=16;fontColor="#000000";palette=["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#808080","#C0C0C0","#800000","#008000","#000080","#808000","#800080"];constructor(t){super(t)}handlePointerDown(e){if(e.cancelable){e.preventDefault()}if(e.pointerType==="mouse"){const i=e.composedPath().slice(1);const s=i.find((t=>t.classList&&t.classList.contains("object")));const n=this._core.findObjectById(s?.id);const r=this._core.store.activeText;if(r===null&&n instanceof Ll){n.edit(e);return}if(r!==null&&n instanceof Ll){r.save();n.edit(e);return}if(r!==null&&n instanceof Ll===false){this._core.resetActiveText();this._core.store.setState("activeTool",t.getTool("selection"));return}if(Yl.isLeftClick(e)===false){return}const o=e.clientX-this._core.store.offsetX;const l=e.clientY-this._core.store.offsetY;const h=Ll.create(this._core,this.fontSize,this.fontFamily);h.fontColor=this.fontColor;h.translateX=(o-this._core.store.state.translateX)/this._core.store.state.scale;h.translateY=(l-this._core.store.state.translateY)/this._core.store.state.scale;h.zIndex=this._core.store.currentZIndex;this._core.store.state.objectsMap.insert(h);this._core.rerender();requestAnimationFrame((()=>h.edit(e)))}if(e.pointerType==="touch"){const i=Array.from(this._core.store.state.pointers.values());const s=e.composedPath().slice(1);const r=s.find((t=>t.classList&&t.classList.contains("object")));const o=this._core.findObjectById(r?.id);const l=this._core.store.activeText;if(l===null&&o instanceof Ll){o.edit(e);return}if(l!==null&&o instanceof Ll){l.save();o.edit(e);return}if(l!==null&&o instanceof Ll===false){this._core.resetActiveText();this._core.store.setState("activeTool",t.getTool("selection"));return}if(i.length>1){return}n.disableInteractiveWidget();const h=Math.round(i[0].clientX-this._core.store.offsetX);const f=Math.round(i[0].clientY-this._core.store.offsetY);const u=Ll.create(this._core,this.fontSize,this.fontFamily);u.fontColor=this.fontColor;u.translateX=(h-this._core.store.state.translateX)/this._core.store.state.scale;u.translateY=(f-this._core.store.state.translateY)/this._core.store.state.scale;u.zIndex=this._core.store.currentZIndex;this._core.store.state.objectsMap.insert(u);this._core.rerender()}}handlePointerUp(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){this._core.store.activeText?.edit(t)}if(t.pointerType==="touch"){this._core.store.activeText?.edit(t);n.enableInteractiveWidget()}}}class Bh{_core;constructor(t){this._core=t}}class jh extends Bh{dragStartX;dragStartY;startX;startY;endX;endY;hasMoved=false;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.hasMoved=false;this.trackedPointerId=null}cancelPendingDrag(){this._core.store.state.isDragging=false;this.reset()}handlePointerDown(t){if(t.pointerType==="mouse"){if(Yl.isLeftClick(t)){const e=this._core.store.selectionGroup;if(e?.isSelected&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected){const e=t.clientX-this._core.store.offsetX;const i=t.clientY-this._core.store.offsetY;this._core.store.state.isDragging=true;this.dragStartX=e;this.dragStartY=i;this.startX=this.dragStartX;this.startY=this.dragStartY;this.trackedPointerId=t.pointerId}else{this.trackedPointerId=null}}else{this.trackedPointerId=null}}if(t.pointerType==="touch"){const e=Array.from(this._core.store.state.pointers.values());if(this._core.store.state.pointers.size===1){if(this._core.store.state.isScaling){this.trackedPointerId=null;return}const i=this._core.store.selectionGroup;if(i?.isSelected&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected){const i=Math.round(e[0].clientX-this._core.store.offsetX);const s=Math.round(e[0].clientY-this._core.store.offsetY);this.dragStartX=i;this.dragStartY=s;this.startX=i;this.startY=s;this.trackedPointerId=t.pointerId}else{this.trackedPointerId=null}}}}handlePointerMove(t){if(this.trackedPointerId===null||this.trackedPointerId!==t.pointerId){return}if(t.pointerType==="mouse"){const e=this._core.store.selectionGroup;if(this._core.store.state.isDragging&&e){const i=t.clientX-this._core.store.offsetX;const s=t.clientY-this._core.store.offsetY;this.endX=i;this.endY=s;const n=Math.abs(i-this.startX);const r=Math.abs(s-this.startY);const o=5;if(n>o||r>o){e.move(i,s,this.dragStartX,this.dragStartY);this.dragStartX=i;this.dragStartY=s;this.hasMoved=true}}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());const e=this._core.store.selectionGroup;if(this._core.store.state.pointers.size===1&&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);const s=Math.round(t[0].clientY-this._core.store.offsetY);this._core.store.state.isDragging=true;this.endX=i;this.endY=s;const n=Math.abs(i-this.startX);const r=Math.abs(s-this.startY);const o=5;if(n>o||r>o){clearTimeout(this._core.store.state.longTouchTimeout);e.move(i,s,this.dragStartX,this.dragStartY);this.dragStartX=i;this.dragStartY=s;this.hasMoved=true}}}}handlePointerUp(t){if(this.trackedPointerId===null||this.trackedPointerId!==t.pointerId){return}if(t.pointerType==="mouse"){if(this._core.store.state.isDragging){this._core.store.state.isDragging=false;if(this.hasMoved){this._core.store.selectionGroup.update();this._core.store.state.hasObjectsChanged=true}}}if(t.pointerType==="touch"){if(this._core.store.state.isDragging){this._core.store.state.isDragging=false;if(this.hasMoved){this._core.store.selectionGroup.update();this._core.store.state.hasObjectsChanged=true}}}this.reset()}}var _h;(function(t){t["TopLeft"]="top-left";t["TopRight"]="top-right";t["BottomLeft"]="bottom-left";t["BottomRight"]="bottom-right"})(_h||(_h={}));class $h extends Bh{initialMouseX=0;initialMouseY=0;initialSize={x:0,y:0,width:0,height:0};newSize={x:0,y:0,width:0,height:0};hasResized=false;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=false}handlePointerDown(t){if(t.pointerType==="mouse"){if(Yl.isLeftClick(t)){const e=this._core.store.selectionGroup;if(e&&this._core.store.state.isResizeHandleSelected){const i=t.clientX-this._core.store.offsetX;const s=t.clientY-this._core.store.offsetY;this._core.store.state.isResizing=true;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(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());const e=t[0];if(!e){return}if(t.length===1){const t=this._core.store.selectionGroup;if(t&&this._core.store.state.isResizeHandleSelected){const i=Math.round(e.clientX-this._core.store.offsetX);const s=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isResizing=true;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(t.pointerType==="mouse"){const e=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&e){const i=t.clientX-this._core.store.offsetX;const s=t.clientY-this._core.store.offsetY;const n=i-this.initialMouseX;const r=s-this.initialMouseY;const o=Math.abs(n);const l=Math.abs(r);const h=5;if(o>h||l>h){this.hasResized=true}if(!this.hasResized){return}switch(this._core.store.state.resizeHandleType){case _h.TopLeft:this.newSize.width=this.initialSize.width-n;this.newSize.height=this.initialSize.height-r;this.newSize.x=n/this._core.store.state.scale+this.initialSize.x;this.newSize.y=r/this._core.store.state.scale+this.initialSize.y;break;case _h.TopRight:this.newSize.width=this.initialSize.width+n;this.newSize.height=this.initialSize.height-r;this.newSize.x=this.initialSize.x;this.newSize.y=r/this._core.store.state.scale+this.initialSize.y;break;case _h.BottomLeft:this.newSize.width=this.initialSize.width-n;this.newSize.height=this.initialSize.height+r;this.newSize.x=n/this._core.store.state.scale+this.initialSize.x;this.newSize.y=this.initialSize.y;break;case _h.BottomRight:this.newSize.width=this.initialSize.width+n;this.newSize.height=this.initialSize.height+r;this.newSize.x=this.initialSize.x;this.newSize.y=this.initialSize.y;break}e.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());const e=t[0];if(!e){return}const i=this._core.store.selectionGroup;if(this._core.store.state.isResizing&&i){const t=Math.round(e.clientX-this._core.store.offsetX);const s=Math.round(e.clientY-this._core.store.offsetY);const n=t-this.initialMouseX;const r=s-this.initialMouseY;const o=Math.abs(n);const l=Math.abs(r);const h=5;if(o>h||l>h){clearTimeout(this._core.store.state.longTouchTimeout);this.hasResized=true}if(!this.hasResized){return}switch(this._core.store.state.resizeHandleType){case _h.TopLeft:this.newSize.width=this.initialSize.width-n;this.newSize.height=this.initialSize.height-r;this.newSize.x=n/this._core.store.state.scale+this.initialSize.x;this.newSize.y=r/this._core.store.state.scale+this.initialSize.y;break;case _h.TopRight:this.newSize.width=this.initialSize.width+n;this.newSize.height=this.initialSize.height-r;this.newSize.x=this.initialSize.x;this.newSize.y=r/this._core.store.state.scale+this.initialSize.y;break;case _h.BottomLeft:this.newSize.width=this.initialSize.width-n;this.newSize.height=this.initialSize.height+r;this.newSize.x=n/this._core.store.state.scale+this.initialSize.x;this.newSize.y=this.initialSize.y;break;case _h.BottomRight:this.newSize.width=this.initialSize.width+n;this.newSize.height=this.initialSize.height+r;this.newSize.x=this.initialSize.x;this.newSize.y=this.initialSize.y;break}i.resize(this.newSize.x,this.newSize.y,this.newSize.width,this.newSize.height)}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._core.store.state.isResizing){this._core.store.state.isResizing=false;if(this.hasResized){this._core.store.selectionGroup.update();this._core.store.state.hasObjectsChanged=true}this.reset()}}if(t.pointerType==="touch"){if(this._core.store.state.isResizing){this._core.store.state.isResizing=false;if(this.hasResized){this._core.store.selectionGroup.update();this._core.store.state.hasObjectsChanged=true}this.reset();clearTimeout(this._core.store.state.longTouchTimeout)}}}}class Lh extends Bh{initialRotation=0;rotation=0;unchangedObjects=[];initialSelectionGroupRotation=0;constructor(t){super(t)}reset(){this.initialRotation=0;this.rotation=0;this.unchangedObjects=[]}handlePointerDown(t){if(t.pointerType==="mouse"){if(Yl.isLeftClick(t)){const e=this._core.store.selectionGroup;if(e&&this._core.store.state.isRotationHandleSelected){const i=t.clientX-this._core.store.offsetX;const s=t.clientY-this._core.store.offsetY;this._core.store.state.isRotating=true;const n=e.translateX+e.width/2/this._core.store.state.scale;const r=e.translateY+e.height/2/this._core.store.state.scale;const o=(i-this._core.store.state.translateX)/this._core.store.state.scale;const l=(s-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=e.rotation;this.initialRotation=Math.atan2(r-l,n-o)-e.rotation;this.unchangedObjects=e.objects.map((t=>t.clone()))}}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());const e=t[0];if(!e){return}if(t.length===1){const t=this._core.store.selectionGroup;if(t&&this._core.store.state.isRotationHandleSelected){const i=Math.round(e.clientX-this._core.store.offsetX);const s=Math.round(e.clientY-this._core.store.offsetY);this._core.store.state.isRotating=true;const n=t.translateX+t.width/2/this._core.store.state.scale;const r=t.translateY+t.height/2/this._core.store.state.scale;const o=(i-this._core.store.state.translateX)/this._core.store.state.scale;const l=(s-this._core.store.state.translateY)/this._core.store.state.scale;this.initialSelectionGroupRotation=t.rotation;this.initialRotation=Math.atan2(r-l,n-o)-t.rotation;this.unchangedObjects=t.objects.map((t=>t.clone()));clearTimeout(this._core.store.state.longTouchTimeout)}}}}handlePointerMove(t){if(t.pointerType==="mouse"){const e=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&e){const i=t.clientX-this._core.store.offsetX;const s=t.clientY-this._core.store.offsetY;const n=e.translateX+e.width/2/this._core.store.state.scale;const r=e.translateY+e.height/2/this._core.store.state.scale;const o=(i-this._core.store.state.translateX)/this._core.store.state.scale;const l=(s-this._core.store.state.translateY)/this._core.store.state.scale;const h=Math.atan2(r-l,n-o);this.rotation=h-this.initialRotation;e.rotate(this.rotation)}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());const e=t[0];if(!e){return}const i=this._core.store.selectionGroup;if(this._core.store.state.isRotating&&i){const t=Math.round(e.clientX-this._core.store.offsetX);const s=Math.round(e.clientY-this._core.store.offsetY);const n=i.translateX+i.width/2/this._core.store.state.scale;const r=i.translateY+i.height/2/this._core.store.state.scale;const o=(t-this._core.store.state.translateX)/this._core.store.state.scale;const l=(s-this._core.store.state.translateY)/this._core.store.state.scale;const h=Math.atan2(r-l,n-o);this.rotation=h-this.initialRotation;i.rotate(this.rotation);clearTimeout(this._core.store.state.longTouchTimeout)}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(this._core.store.state.isRotating){this._core.store.selectionGroup.update();this._core.store.state.isRotating=false;this._core.store.state.hasObjectsChanged=true;this.reset()}}if(t.pointerType==="touch"){if(this._core.store.state.isRotating){this._core.store.selectionGroup.update();this._core.store.state.isRotating=false;this._core.store.state.hasObjectsChanged=true;this.reset();clearTimeout(this._core.store.state.longTouchTimeout)}}}}class zh extends s{__class__="KritzelSelectionBox";static create(t){const e=new zh;e._core=t;e.id=e.generateId();e.workspaceId=t.store.state.activeWorkspace.id;e.scale=t.store.state.scale;e.zIndex=99999;e.backgroundColor="var(--kritzel-selection-box-background-color, rgba(0, 122, 255, 0.2))";e.borderColor="var(--kritzel-selection-box-border-color, rgba(0, 122, 255, 0.5))";e.borderWidth=2;e.height=0;e.width=0;return e}}class Jh extends s{__class__="KritzelSelectionGroup";objectIds=[];unchangedObjectSnapshots=new Map;minX;maxX;minY;maxY;get objects(){return this.objectIds.map((t=>{const e=this._core.store.state.objectsMap.filter((e=>e.id===t));return e.length>0?e[0]:null})).filter((t=>t!==null))}get length(){return this.objectIds.length}static create(t){const e=new Jh;e._core=t;e.id=e.generateId();e.workspaceId=t.store.state.activeWorkspace.id;e.scale=t.store.state.scale;e.zIndex=99999;return e}addOrRemove(t){const e=this.objectIds.findIndex((e=>e===t.id));if(e===-1){this.objectIds.push(t.id)}else{this.objectIds.splice(e,1)}this.captureUnchangedSnapshots();this.refreshObjectDimensions()}deselectAllChildren(){this.objects.forEach((t=>t.isSelected=false))}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=>{const s=i.translateX-this.translateX;const n=i.translateY-this.translateY;i.updatePosition(t+s,e+n)}));this.unchangedObjectSnapshots.forEach((e=>{const i=e.translateX-this.translateX;const s=e.translateY-this.translateY;e.translateX=t+i;e.translateY=t+s}));this.translateX=t;this.translateY=e;this._core.store.state.objectsMap.update(this)}captureUnchangedSnapshots(){this.unchangedObjectSnapshots.clear();this.objects.forEach((t=>{this.unchangedObjectSnapshots.set(t.id,{id:t.id,translateX:t.translateX,translateY:t.translateY,rotation:t.rotation,width:t.width,height:t.height,totalWidth:t.totalWidth,totalHeight:t.totalHeight,scale:t.scale})}))}serialize(){const{_core:t,_elementRef:e,element:i,totalWidth:s,totalHeight:n,unchangedObjectSnapshots:r,...o}=this;const l=structuredClone(o);if(i&&typeof i==="object"&&"nodeType"in i&&i.nodeType===1){l.element=i.cloneNode(true)}l.unchangedObjectSnapshots=Object.fromEntries(this.unchangedObjectSnapshots);return l}deserialize(t){super.deserialize(t);if(t.unchangedObjectSnapshots){this.unchangedObjectSnapshots=new Map(Object.entries(t.unchangedObjectSnapshots))}return this}update(){this._core.store.state.objectsMap.update(this)}move(t,e,i,s){const n=(t-i)/this._core.store.state.scale;const r=(e-s)/this._core.store.state.scale;this.translateX+=n;this.translateY+=r;this._core.store.state.objectsMap.transaction((()=>{this._core.store.state.objectsMap.update(this);this.objects.forEach((n=>{n.move(t,e,i,s)}))}));this.unchangedObjectSnapshots.forEach((t=>{t.translateX+=n;t.translateY+=r}))}resize(t,e,i,s){const n=i/this.width;const r=s/this.height;const o=t-this.translateX;const l=e-this.translateY;this._core.store.state.objectsMap.transaction((()=>{this.objects.forEach((t=>{const e=t.width*n;const i=t.height*r;const s=t.translateX+o+(t.translateX-this.translateX)*(n-1);const h=t.translateY+l+(t.translateY-this.translateY)*(r-1);t.resize(s,h,e,i)}));this.refreshObjectDimensions();this.captureUnchangedSnapshots();this._core.store.state.objectsMap.update(this)}))}rotate(t){this.rotation=t;const e=this.translateX+this.totalWidth/2/this.scale;const i=this.translateY+this.totalHeight/2/this.scale;const s=t;const n=Math.cos(s);const r=Math.sin(s);this._core.store.state.objectsMap.transaction((()=>{this._core.store.state.objectsMap.update(this);this.objects.forEach((s=>{const o=this.unchangedObjectSnapshots.get(s.id);if(!o)return;const l=this.getOffsetXToCenterFromSnapshot(o);const h=this.getOffsetYToCenterFromSnapshot(o);const f=n*l-r*h;const u=r*l+n*h;s.translateX=e+f-s.totalWidth/2/s.scale;s.translateY=i+u-s.totalHeight/2/s.scale;s.rotate(this.objects.length===1?t:t+o.rotation)}))}))}copy(){const t=Jh.create(this._core);this.objects.sort(((t,e)=>t.zIndex-e.zIndex)).forEach((e=>{const i=e.copy();t.addOrRemove(i)}));t.captureUnchangedSnapshots();if(this.objects.length===1){t.rotation=this.objects[0].rotation}return t}refreshObjectDimensions(){if(this.objects.length===1){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{this.minX=Math.min(...this.objects.map((t=>t.minXRotated)));this.maxX=Math.max(...this.objects.map((t=>t.maxXRotated)));this.minY=Math.min(...this.objects.map((t=>t.minYRotated)));this.maxY=Math.max(...this.objects.map((t=>t.maxYRotated)));this.translateX=this.minX-this.padding;this.translateY=this.minY-this.padding;this.width=(this.maxX-this.minX-this.padding)*this.scale;this.height=(this.maxY-this.minY-this.padding)*this.scale}this._core.store.state.objectsMap.update(this)}getOffsetXToCenterFromSnapshot(t){const e=t.translateX+t.totalWidth/t.scale/2;const i=this.translateX+this.totalWidth/this.scale/2;return e-i}getOffsetYToCenterFromSnapshot(t){const e=t.translateY+t.totalHeight/t.scale/2;const i=this.translateY+this.totalHeight/this.scale/2;return e-i}}class Wh extends Bh{startX;startY;touchStartX=0;touchStartY=0;touchStartTimeout=null;get isSelectionClick(){const t=this._core.store.selectionBox;return t&&t.width===0&&t.height===0}get isSelectionDrag(){const t=this._core.store.selectionBox;return t&&(t.width>0||t.height>0)}constructor(t){super(t)}handlePointerDown(t){if(t.pointerType==="mouse"){if(Yl.isLeftClick(t)&&!this._core.store.selectionGroup){this.startMouseSelection(t)}}if(t.pointerType==="touch"){this.touchStartTimeout=setTimeout((()=>{if(this._core.store.state.pointers.size===1&&!this._core.store.state.isScaling&&!this._core.store.selectionGroup){this.startTouchSelection();this.updateTouchSelection()}}),80)}}handlePointerMove(t){if(t.pointerType==="mouse"){if(this._core.store.state.isSelecting){this.updateMouseSelection(t)}}if(t.pointerType==="touch"){const t=Array.from(this._core.store.state.pointers.values());const e=Math.round(t[0].clientX-this._core.store.offsetX);const i=Math.round(t[0].clientY-this._core.store.offsetY);const s=Math.abs(e-this.touchStartX);const n=Math.abs(i-this.touchStartY);const r=5;if((s>r||n>r)&&this._core.store.state.isSelecting){this.updateTouchSelection();clearTimeout(this._core.store.state.longTouchTimeout)}}}handlePointerUp(t){if(t.pointerType==="mouse"){if(Yl.isLeftClick(t)){const e=this._core.store.state.hasObjectsChanged;const i=this._core.store.selectionGroup;if(i?.objects.length===1&&e===false){i.objects[0].edit(t)}this._core.store.state.hasObjectsChanged=false;if(this._core.store.state.isSelecting){if(this.isSelectionClick){this.handleSelectionClick(t)}if(this.isSelectionDrag){this.updateMouseSelection(t);this.addSelectedObjectsToSelectionGroup();this.removeSelectionBox()}}}}if(t.pointerType==="touch"){clearTimeout(this.touchStartTimeout);const e=this._core.store.state.hasObjectsChanged;const i=this._core.store.selectionGroup;if(i?.objects.length===1&&e===false){i.objects[0].edit(t)}this._core.store.state.hasObjectsChanged=false;if(this._core.store.state.isSelecting){if(this.isSelectionClick){this.handleSelectionClick(t)}if(this.isSelectionDrag){this.updateTouchSelection();this.addSelectedObjectsToSelectionGroup();this.removeSelectionBox()}this._core.store.state.skipContextMenu=false}}}removeSelectionBox(){this._core.store.state.isSelecting=false;this._core.store.state.objectsMap.remove((t=>t instanceof zh))}startMouseSelection(t){let e,i;e=t.clientX-this._core.store.offsetX;i=t.clientY-this._core.store.offsetY;const s=zh.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=true;this._core.store.state.objectsMap.remove((t=>t instanceof zh||t instanceof Jh));this._core.store.state.objectsMap.insert(s)}startTouchSelection(){const t=Array.from(this._core.store.state.pointers.values());const e=t[0];if(!e){return}let i,s;i=Math.round(e.clientX-this._core.store.offsetX);s=Math.round(e.clientY-this._core.store.offsetY);this.touchStartX=i;this.touchStartY=s;const n=zh.create(this._core);this.startX=(i-this._core.store.state.translateX)/this._core.store.state.scale;this.startY=(s-this._core.store.state.translateY)/this._core.store.state.scale;n.translateX=this.startX;n.translateY=this.startY;this._core.store.state.isSelecting=true;this._core.store.state.objectsMap.remove((t=>t instanceof zh||t instanceof Jh));this._core.store.state.objectsMap.insert(n)}updateMouseSelection(t){let e,i;e=t.clientX-this._core.store.offsetX;i=t.clientY-this._core.store.offsetY;const s=this._core.store.selectionBox;if(s){const t=(e-this._core.store.state.translateX)/s.scale;const n=(i-this._core.store.state.translateY)/s.scale;const r=Math.abs(t-this.startX)*s.scale;const o=Math.abs(n-this.startY)*s.scale;s.width=r;s.height=o;s.translateX=Math.min(t,this.startX);s.translateY=Math.min(n,this.startY);if(r>0||o>0){this.updateSelectedObjects()}else{this.clearSelectionPreview()}}}updateTouchSelection(){const t=Array.from(this._core.store.state.pointers.values());const e=t[0];if(!e){return}let i,s;i=Math.round(e.clientX-this._core.store.offsetX);s=Math.round(e.clientY-this._core.store.offsetY);const n=this._core.store.selectionBox;if(n){const t=(i-this._core.store.state.translateX)/n.scale;const e=(s-this._core.store.state.translateY)/n.scale;const r=Math.abs(t-this.startX)*n.scale;const o=Math.abs(e-this.startY)*n.scale;n.width=r;n.height=o;n.translateX=Math.min(t,this.startX);n.translateY=Math.min(e,this.startY);if(r>0||o>0){this.updateSelectedObjects()}else{this.clearSelectionPreview()}}}updateSelectedObjects(){const t=this._core.store.selectionBox;if(t){this._core.store.allObjects.filter((t=>!(t instanceof zh))).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;const i=this._core.store.state.pointerY;const s=this._core.getObjectsFromPointerEvent(t,".object");for(const t of s){if(t.hitTest(e,i)){return t}}return null}clearSelectionPreview(){this._core.store.allNonSelectionObjects.forEach((t=>{t.isSelected=false}))}addObjectToSelectionGroup(t){if(!t){return}t.isSelected=false;const e=Jh.create(this._core);e.addOrRemove(t);e.isSelected=true;e.rotation=t.rotation;this._core.addSelectionGroup(e);this._core.rerender()}addSelectedObjectsToSelectionGroup(){const t=this._core.store.selectedObjects;if(t.length===0){return}const e=Jh.create(this._core);t.forEach((t=>{e.addOrRemove(t);t.isSelected=false}));e.isSelected=true;if(e.length===1){e.rotation=e.objects[0].rotation}this._core.addSelectionGroup(e);this._core.rerender()}}class Qh extends Bh{constructor(t){super(t)}handlePointerMove(t){if(t.pointerType==="mouse"){const e=this._core.getObjectFromPointerEvent(t,".object");if(!e)return;const i=this._core.store.state.pointerX;const s=this._core.store.state.pointerY;e.isHovered=e.hitTest(i,s)}}}class Hh extends Xl{selectionHandler;moveHandler;hoverHandler;resizeHandler;rotationHandler;constructor(t){super(t);this.selectionHandler=new Wh(this._core);this.moveHandler=new jh(this._core);this.hoverHandler=new Qh(this._core);this.resizeHandler=new $h(this._core);this.rotationHandler=new Lh(this._core)}handlePointerDown(t){if(t.cancelable){t.preventDefault()}if(t.pointerType==="mouse"){if(Yl.isLeftClick(t)){this._core.store.state.isResizeHandleSelected=this.isHandleSelected(t);this._core.store.state.isRotationHandleSelected=this.isRotationHandleSelected(t);this._core.store.state.resizeHandleType=this.getHandleType(t);const e=this.getSelectedObject(t);const i=this._core.store.selectionGroup;const s=e&&i&&e.id!==i.id;if((e===null||s)&&i&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected){this._core.removeSelectionGroup();this._core.rerender()}if(e&&e.isSelected===false&&e?.objects.length===1&&e.objects[0].isInteractive){return}}this.moveHandler.handlePointerDown(t);this.selectionHandler.handlePointerDown(t);this.resizeHandler.handlePointerDown(t);this.rotationHandler.handlePointerDown(t);this._core.rerender()}if(t.pointerType==="touch"){if(this._core.store.state.isScaling===true){return}if(this._core.store.state.pointers.size===1){this._core.store.state.isResizeHandleSelected=this.isHandleSelected(t);this._core.store.state.isRotationHandleSelected=this.isRotationHandleSelected(t);this._core.store.state.resizeHandleType=this.getHandleType(t);const e=this.getSelectedObject(t);const i=this._core.store.selectionGroup;const s=e&&i&&e.id!==i.id;if(!i&&e){this._core.store.state.skipContextMenu=true}if((e===null||s)&&i&&!this._core.store.state.isResizeHandleSelected&&!this._core.store.state.isRotationHandleSelected){this._core.removeSelectionGroup();this._core.rerender()}}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()}if(t.pointerType==="mouse"){this.moveHandler.handlePointerMove(t);this.hoverHandler.handlePointerMove(t);this.selectionHandler.handlePointerMove(t);this.resizeHandler.handlePointerMove(t);this.rotationHandler.handlePointerMove(t);this._core.rerender()}if(t.pointerType==="touch"){if(this._core.store.state.isScaling===true){return}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()}if(t.pointerType==="mouse"){this.moveHandler.handlePointerUp(t);this.resizeHandler.handlePointerUp(t);this.rotationHandler.handlePointerUp(t);this.selectionHandler.handlePointerUp(t);this._core.rerender()}if(t.pointerType==="touch"){if(this._core.store.state.isScaling===true){return}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);const i=e.find((t=>t.classList&&t.classList.contains("object")));const s=this._core.findObjectById(i?.id);if(!s){return null}if(s instanceof Jh){return s}else{const t=Jh.create(this._core);t.translateX=0;t.translateY=0;t.addOrRemove(s);return t}}getHandleType(t){const e=this._core.store.state.host?.shadowRoot;if(!e)return;const i=e.elementFromPoint(t.clientX,t.clientY);const s=i?.closest(".resize-handle-overlay");return s?.classList[1]}isHandleSelected(t){const e=this._core.store.state.host?.shadowRoot;if(!e)return false;const i=e.elementFromPoint(t.clientX,t.clientY);return!!i?.classList.contains("resize-handle-overlay")}isRotationHandleSelected(t){const e=t.composedPath();return!!e.find((t=>t.classList&&t.classList.contains("rotation-handle-overlay")))}}const qh=()=>new Map;const Vh=t=>{const e=qh();t.forEach(((t,i)=>{e.set(i,t)}));return e};const Kh=(t,e,i)=>{let s=t.get(e);if(s===undefined){t.set(e,s=i())}return s};const Yh=(t,e)=>{const i=[];for(const[s,n]of t){i.push(e(n,s))}return i};const Xh=(t,e)=>{for(const[i,s]of t){if(e(s,i)){return true}}return false};const Gh=()=>new Set;const Zh=t=>t[t.length-1];const tf=(t,e)=>{for(let i=0;i<e.length;i++){t.push(e[i])}};const ef=Array.from;const sf=(t,e)=>{for(let i=0;i<t.length;i++){if(e(t[i],i,t)){return true}}return false};const nf=Array.isArray;class rf{constructor(){this._observers=qh()}on(t,e){Kh(this._observers,t,Gh).add(e);return 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);if(i!==undefined){i.delete(e);if(i.size===0){this._observers.delete(t)}}}emit(t,e){return ef((this._observers.get(t)||qh()).values()).forEach((t=>t(...e)))}destroy(){this._observers=qh()}}let of=class t{constructor(){this._observers=qh()}on(t,e){Kh(this._observers,t,Gh).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);if(i!==undefined){i.delete(e);if(i.size===0){this._observers.delete(t)}}}emit(t,e){return ef((this._observers.get(t)||qh()).values()).forEach((t=>t(...e)))}destroy(){this._observers=qh()}};const lf=Math.floor;const hf=Math.abs;const ff=(t,e)=>t<e?t:e;const uf=(t,e)=>t>e?t:e;const cf=Math.pow;const af=t=>t!==0?t<0:1/t<0;const df=1;const wf=2;const pf=4;const gf=8;const mf=32;const yf=64;const bf=128;const vf=31;const Af=63;const Mf=127;const kf=2147483647;const Sf=Number.MAX_SAFE_INTEGER;const xf=Number.isInteger||(t=>typeof t==="number"&&isFinite(t)&&lf(t)===t);const Of=String.fromCharCode;const Ef=t=>t.toLowerCase();const Df=/^\s*/g;const Tf=t=>t.replace(Df,"");const Cf=/([A-Z])/g;const Rf=(t,e)=>Tf(t.replace(Cf,(t=>`${e}${Ef(t)}`)));const Uf=t=>{const e=unescape(encodeURIComponent(t));const i=e.length;const s=new Uint8Array(i);for(let t=0;t<i;t++){s[t]=e.codePointAt(t)}return s};const If=typeof TextEncoder!=="undefined"?new TextEncoder:null;const Nf=t=>If.encode(t);const Pf=If?Nf:Uf;let Ff=typeof TextDecoder==="undefined"?null:new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});if(Ff&&Ff.decode(new Uint8Array).length===1){Ff=null}let Bf=class t{constructor(){this.cpos=0;this.cbuf=new Uint8Array(100);this.bufs=[]}};const jf=()=>new Bf;const _f=t=>{let e=t.cpos;for(let i=0;i<t.bufs.length;i++){e+=t.bufs[i].length}return e};const $f=t=>{const e=new Uint8Array(_f(t));let i=0;for(let s=0;s<t.bufs.length;s++){const n=t.bufs[s];e.set(n,i);i+=n.length}e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),i);return e};const Lf=(t,e)=>{const i=t.cbuf.length;if(i-t.cpos<e){t.bufs.push(new Uint8Array(t.cbuf.buffer,0,t.cpos));t.cbuf=new Uint8Array(uf(i,e)*2);t.cpos=0}};const zf=(t,e)=>{const i=t.cbuf.length;if(t.cpos===i){t.bufs.push(t.cbuf);t.cbuf=new Uint8Array(i*2);t.cpos=0}t.cbuf[t.cpos++]=e};const Jf=zf;const Wf=(t,e)=>{while(e>Mf){zf(t,bf|Mf&e);e=lf(e/128)}zf(t,Mf&e)};const Qf=(t,e)=>{const i=af(e);if(i){e=-e}zf(t,(e>Af?bf:0)|(i?yf:0)|Af&e);e=lf(e/64);while(e>0){zf(t,(e>Mf?bf:0)|Mf&e);e=lf(e/128)}};const Hf=new Uint8Array(3e4);const qf=Hf.length/3;const Vf=(t,e)=>{if(e.length<qf){const i=If.encodeInto(e,Hf).written||0;Wf(t,i);for(let e=0;e<i;e++){zf(t,Hf[e])}}else{Gf(t,Pf(e))}};const Kf=(t,e)=>{const i=unescape(encodeURIComponent(e));const s=i.length;Wf(t,s);for(let e=0;e<s;e++){zf(t,i.codePointAt(e))}};const Yf=If&&If.encodeInto?Vf:Kf;const Xf=(t,e)=>{const i=t.cbuf.length;const s=t.cpos;const n=ff(i-s,e.length);const r=e.length-n;t.cbuf.set(e.subarray(0,n),s);t.cpos+=n;if(r>0){t.bufs.push(t.cbuf);t.cbuf=new Uint8Array(uf(i*2,r));t.cbuf.set(e.subarray(n));t.cpos=r}};const Gf=(t,e)=>{Wf(t,e.byteLength);Xf(t,e)};const Zf=(t,e)=>{Lf(t,e);const i=new DataView(t.cbuf.buffer,t.cpos,e);t.cpos+=e;return i};const tu=(t,e)=>Zf(t,4).setFloat32(0,e,false);const eu=(t,e)=>Zf(t,8).setFloat64(0,e,false);const iu=(t,e)=>Zf(t,8).setBigInt64(0,e,false);const su=new DataView(new ArrayBuffer(4));const nu=t=>{su.setFloat32(0,t);return su.getFloat32(0)===t};const ru=(t,e)=>{switch(typeof e){case"string":zf(t,119);Yf(t,e);break;case"number":if(xf(e)&&hf(e)<=kf){zf(t,125);Qf(t,e)}else if(nu(e)){zf(t,124);tu(t,e)}else{zf(t,123);eu(t,e)}break;case"bigint":zf(t,122);iu(t,e);break;case"object":if(e===null){zf(t,126)}else if(nf(e)){zf(t,117);Wf(t,e.length);for(let i=0;i<e.length;i++){ru(t,e[i])}}else if(e instanceof Uint8Array){zf(t,116);Gf(t,e)}else{zf(t,118);const i=Object.keys(e);Wf(t,i.length);for(let s=0;s<i.length;s++){const n=i[s];Yf(t,n);ru(t,e[n])}}break;case"boolean":zf(t,e?120:121);break;default:zf(t,127)}};class ou extends Bf{constructor(t){super();this.w=t;this.s=null;this.count=0}write(t){if(this.s===t){this.count++}else{if(this.count>0){Wf(this,this.count-1)}this.count=1;this.w(this,t);this.s=t}}}const lu=t=>{if(t.count>0){Qf(t.encoder,t.count===1?t.s:-t.s);if(t.count>1){Wf(t.encoder,t.count-2)}}};class hu{constructor(){this.encoder=new Bf;this.s=0;this.count=0}write(t){if(this.s===t){this.count++}else{lu(this);this.count=1;this.s=t}}toUint8Array(){lu(this);return $f(this.encoder)}}const fu=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);Qf(t.encoder,e);if(t.count>1){Wf(t.encoder,t.count-2)}}};class uu{constructor(){this.encoder=new Bf;this.s=0;this.count=0;this.diff=0}write(t){if(this.diff===t-this.s){this.s=t;this.count++}else{fu(this);this.count=1;this.diff=t-this.s;this.s=t}}toUint8Array(){fu(this);return $f(this.encoder)}}class cu{constructor(){this.sarr=[];this.s="";this.lensE=new hu}write(t){this.s+=t;if(this.s.length>19){this.sarr.push(this.s);this.s=""}this.lensE.write(t.length)}toUint8Array(){const t=new Bf;this.sarr.push(this.s);this.s="";Yf(t,this.sarr.join(""));Xf(t,this.lensE.toUint8Array());return $f(t)}}const au=t=>new Error(t);const du=()=>{throw au("Method unimplemented")};const wu=()=>{throw au("Unexpected case")};const pu=au("Unexpected end of array");const gu=au("Integer out of Range");let mu=class t{constructor(t){this.arr=t;this.pos=0}};const yu=t=>new mu(t);const bu=t=>t.pos!==t.arr.length;const vu=(t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);t.pos+=e;return i};const Au=t=>vu(t,ku(t));const Mu=t=>t.arr[t.pos++];const ku=t=>{let e=0;let i=1;const s=t.arr.length;while(t.pos<s){const s=t.arr[t.pos++];e=e+(s&Mf)*i;i*=128;if(s<bf){return e}if(e>Sf){throw gu}}throw pu};const Su=t=>{let e=t.arr[t.pos++];let i=e&Af;let s=64;const n=(e&yf)>0?-1:1;if((e&bf)===0){return n*i}const r=t.arr.length;while(t.pos<r){e=t.arr[t.pos++];i=i+(e&Mf)*s;s*=128;if(e<bf){return n*i}if(i>Sf){throw gu}}throw pu};const xu=t=>{let e=ku(t);if(e===0){return""}else{let i=String.fromCodePoint(Mu(t));if(--e<100){while(e--){i+=String.fromCodePoint(Mu(t))}}else{while(e>0){const s=e<1e4?e:1e4;const n=t.arr.subarray(t.pos,t.pos+s);t.pos+=s;i+=String.fromCodePoint.apply(null,n);e-=s}}return decodeURIComponent(escape(i))}};const Ou=t=>Ff.decode(Au(t));const Eu=Ff?Ou:xu;const Du=(t,e)=>{const i=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);t.pos+=e;return i};const Tu=t=>Du(t,4).getFloat32(0,false);const Cu=t=>Du(t,8).getFloat64(0,false);const Ru=t=>Du(t,8).getBigInt64(0,false);const Uu=[t=>undefined,t=>null,Su,Tu,Cu,Ru,t=>false,t=>true,Eu,t=>{const e=ku(t);const i={};for(let s=0;s<e;s++){const e=Eu(t);i[e]=Iu(t)}return i},t=>{const e=ku(t);const i=[];for(let s=0;s<e;s++){i.push(Iu(t))}return i},Au];const Iu=t=>Uu[127-Mu(t)](t);class Nu extends mu{constructor(t,e){super(t);this.reader=e;this.s=null;this.count=0}read(){if(this.count===0){this.s=this.reader(this);if(bu(this)){this.count=ku(this)+1}else{this.count=-1}}this.count--;return this.s}}class Pu extends mu{constructor(t){super(t);this.s=0;this.count=0}read(){if(this.count===0){this.s=Su(this);const t=af(this.s);this.count=1;if(t){this.s=-this.s;this.count=ku(this)+2}}this.count--;return this.s}}class Fu extends mu{constructor(t){super(t);this.s=0;this.count=0;this.diff=0}read(){if(this.count===0){const t=Su(this);const e=t&1;this.diff=lf(t/2);this.count=1;if(e){this.count=ku(this)+2}}this.s+=this.diff;this.count--;return this.s}}class Bu{constructor(t){this.decoder=new Pu(t);this.str=Eu(this.decoder);this.spos=0}read(){const t=this.spos+this.decoder.read();const e=this.str.slice(this.spos,t);this.spos=t;return e}}const ju=crypto.getRandomValues.bind(crypto);const _u=()=>ju(new Uint32Array(1))[0];const $u=[1e7]+-1e3+-4e3+-8e3+-1e11;const Lu=()=>$u.replace(/[018]/g,(t=>(t^_u()&15>>t/4).toString(16)));const zu=Date.now;const Ju=t=>new Promise(t);Promise.all.bind(Promise);const Wu=t=>t===undefined?null:t;class Qu{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}}let Hu=new Qu;let qu=true;try{if(typeof localStorage!=="undefined"&&localStorage){Hu=localStorage;qu=false}}catch(sh){}const Vu=Hu;const Ku=t=>qu||addEventListener("storage",t);const Yu=t=>qu||removeEventListener("storage",t);const Xu=Object.assign;const Gu=Object.keys;const Zu=(t,e)=>{for(const i in t){e(t[i],i)}};const tc=(t,e)=>{const i=[];for(const s in t){i.push(e(t[s],s))}return i};const ec=t=>Gu(t).length;const ic=t=>Gu(t).length;const sc=t=>{for(const e in t){return false}return true};const nc=(t,e)=>{for(const i in t){if(!e(t[i],i)){return false}}return true};const rc=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const oc=(t,e)=>t===e||ic(t)===ic(e)&&nc(t,((t,i)=>(t!==undefined||rc(e,i))&&e[i]===t));const lc=Object.freeze;const hc=t=>{for(const e in t){const i=t[e];if(typeof i==="object"||typeof i==="function"){hc(t[e])}}return lc(t)};const fc=Symbol("Equality");const uc=(t,e,i=0)=>{try{for(;i<t.length;i++){t[i](...e)}}finally{if(i<t.length){uc(t,e,i+1)}}};const cc=t=>t;const ac=(t,e)=>{if(t===e){return true}if(t==null||e==null||t.constructor!==e.constructor){return false}if(t[fc]!=null){return t[fc](e)}switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t);e=new Uint8Array(e);case Uint8Array:{if(t.byteLength!==e.byteLength){return false}for(let i=0;i<t.length;i++){if(t[i]!==e[i]){return false}}break}case Set:{if(t.size!==e.size){return false}for(const i of t){if(!e.has(i)){return false}}break}case Map:{if(t.size!==e.size){return false}for(const i of t.keys()){if(!e.has(i)||!ac(t.get(i),e.get(i))){return false}}break}case Object:if(ec(t)!==ec(e)){return false}for(const i in t){if(!rc(t,i)||!ac(t[i],e[i])){return false}}break;case Array:if(t.length!==e.length){return false}for(let i=0;i<t.length;i++){if(!ac(t[i],e[i])){return false}}break;default:return false}return true};const dc=(t,e)=>e.includes(t);const wc=typeof process!=="undefined"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process!=="undefined"?process:0)==="[object process]";const pc=typeof window!=="undefined"&&typeof document!=="undefined"&&!wc;let gc;const mc=()=>{if(gc===undefined){if(wc){gc=qh();const t=process.argv;let e=null;for(let i=0;i<t.length;i++){const s=t[i];if(s[0]==="-"){if(e!==null){gc.set(e,"")}e=s}else{if(e!==null){gc.set(e,s);e=null}}}if(e!==null){gc.set(e,"")}}else if(typeof location==="object"){gc=qh();(location.search||"?").slice(1).split("&").forEach((t=>{if(t.length!==0){const[e,i]=t.split("=");gc.set(`--${Rf(e,"-")}`,i);gc.set(`-${Rf(e,"-")}`,i)}}))}else{gc=qh()}}return gc};const yc=t=>mc().has(t);const bc=t=>wc?Wu(process.env[t.toUpperCase().replaceAll("-","_")]):Wu(Vu.getItem(t));const vc=t=>yc("--"+t)||bc(t)!==null;vc("production");const Ac=wc&&dc(process.env.FORCE_COLOR,["true","1","2"]);const Mc=Ac||!yc("--no-colors")&&!vc("no-color")&&(!wc||process.stdout.isTTY)&&(!wc||yc("--color")||bc("COLORTERM")!==null||(bc("TERM")||"").includes("color"));const kc=t=>new Uint8Array(t);const Sc=(t,e,i)=>new Uint8Array(t,e,i);const xc=t=>new Uint8Array(t);const Oc=t=>{let e="";for(let i=0;i<t.byteLength;i++){e+=Of(t[i])}return btoa(e)};const Ec=t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64");const Dc=t=>{const e=atob(t);const i=kc(e.length);for(let t=0;t<e.length;t++){i[t]=e.charCodeAt(t)}return i};const Tc=t=>{const e=Buffer.from(t,"base64");return Sc(e.buffer,e.byteOffset,e.byteLength)};const Cc=pc?Oc:Ec;const Rc=pc?Dc:Tc;const Uc=t=>{const e=kc(t.byteLength);e.set(t);return e};class Ic{constructor(t,e){this.left=t;this.right=e}}const Nc=(t,e)=>new Ic(t,e);typeof DOMParser!=="undefined"?new DOMParser:null;const Pc=t=>Yh(t,((t,e)=>`${e}:${t};`)).join("");const Fc=Symbol;const Bc=Fc();const jc=Fc();const _c=Fc();const $c=Fc();const Lc=Fc();const zc=Fc();const Jc=Fc();const Wc=Fc();const Qc=Fc();const Hc=t=>{if(t.length===1&&t[0]?.constructor===Function){t=t[0]()}const e=[];const i=[];let s=0;for(;s<t.length;s++){const i=t[s];if(i===undefined){break}else if(i.constructor===String||i.constructor===Number){e.push(i)}else if(i.constructor===Object){break}}if(s>0){i.push(e.join(""))}for(;s<t.length;s++){const e=t[s];if(!(e instanceof Symbol)){i.push(e)}}return i};const qc={[Bc]:Nc("font-weight","bold"),[jc]:Nc("font-weight","normal"),[_c]:Nc("color","blue"),[Lc]:Nc("color","green"),[$c]:Nc("color","grey"),[zc]:Nc("color","red"),[Jc]:Nc("color","purple"),[Wc]:Nc("color","orange"),[Qc]:Nc("color","black")};const Vc=t=>{if(t.length===1&&t[0]?.constructor===Function){t=t[0]()}const e=[];const i=[];const s=qh();let n=[];let r=0;for(;r<t.length;r++){const n=t[r];const o=qc[n];if(o!==undefined){s.set(o.left,o.right)}else{if(n===undefined){break}if(n.constructor===String||n.constructor===Number){const t=Pc(s);if(r>0||t.length>0){e.push("%c"+n);i.push(t)}else{e.push(n)}}else{break}}}if(r>0){n=i;n.unshift(e.join(""))}for(;r<t.length;r++){const e=t[r];if(!(e instanceof Symbol)){n.push(e)}}return n};const Kc=Mc?Vc:Hc;const Yc=(...t)=>{console.log(...Kc(t));Gc.forEach((e=>e.print(t)))};const Xc=(...t)=>{console.warn(...Kc(t));t.unshift(Wc);Gc.forEach((e=>e.print(t)))};const Gc=Gh();const Zc=t=>({[Symbol.iterator](){return this},next:t});const ta=(t,e)=>Zc((()=>{let i;do{i=t.next()}while(!i.done&&!e(i.value));return i}));const ea=(t,e)=>Zc((()=>{const{done:i,value:s}=t.next();return{done:i,value:i?undefined:e(s)}}));class ia{constructor(t,e){this.clock=t;this.len=e}}class sa{constructor(){this.clients=new Map}}const na=(t,e,i)=>e.clients.forEach(((e,s)=>{const n=t.doc.store.clients.get(s);if(n!=null){const s=n[n.length-1];const r=s.id.clock+s.length;for(let s=0,o=e[s];s<e.length&&o.clock<r;o=e[++s]){cd(t,n,o.clock,o.len,i)}}}));const ra=(t,e)=>{let i=0;let s=t.length-1;while(i<=s){const n=lf((i+s)/2);const r=t[n];const o=r.clock;if(o<=e){if(e<o+r.len){return n}i=n+1}else{s=n-1}}return null};const oa=(t,e)=>{const i=t.clients.get(e.client);return i!==undefined&&ra(i,e.clock)!==null};const la=t=>{t.clients.forEach((t=>{t.sort(((t,e)=>t.clock-e.clock));let e,i;for(e=1,i=1;e<t.length;e++){const s=t[i-1];const n=t[e];if(s.clock+s.len>=n.clock){s.len=uf(s.len,n.clock+n.len-s.clock)}else{if(i<e){t[i]=n}i++}}t.length=i}))};const ha=t=>{const e=new sa;for(let i=0;i<t.length;i++){t[i].clients.forEach(((s,n)=>{if(!e.clients.has(n)){const r=s.slice();for(let e=i+1;e<t.length;e++){tf(r,t[e].clients.get(n)||[])}e.clients.set(n,r)}}))}la(e);return e};const fa=(t,e,i,s)=>{Kh(t.clients,e,(()=>[])).push(new ia(i,s))};const ua=()=>new sa;const ca=t=>{const e=ua();t.clients.forEach(((t,i)=>{const s=[];for(let e=0;e<t.length;e++){const i=t[e];if(i.deleted){const n=i.id.clock;let r=i.length;if(e+1<t.length){for(let i=t[e+1];e+1<t.length&&i.deleted;i=t[++e+1]){r+=i.length}}s.push(new ia(n,r))}}if(s.length>0){e.clients.set(i,s)}}));return e};const aa=(t,e)=>{Wf(t.restEncoder,e.clients.size);ef(e.clients.entries()).sort(((t,e)=>e[0]-t[0])).forEach((([e,i])=>{t.resetDsCurVal();Wf(t.restEncoder,e);const s=i.length;Wf(t.restEncoder,s);for(let e=0;e<s;e++){const s=i[e];t.writeDsClock(s.clock);t.writeDsLen(s.len)}}))};const da=t=>{const e=new sa;const i=ku(t.restDecoder);for(let s=0;s<i;s++){t.resetDsCurVal();const i=ku(t.restDecoder);const s=ku(t.restDecoder);if(s>0){const n=Kh(e.clients,i,(()=>[]));for(let e=0;e<s;e++){n.push(new ia(t.readDsClock(),t.readDsLen()))}}}return e};const wa=(t,e,i)=>{const s=new sa;const n=ku(t.restDecoder);for(let r=0;r<n;r++){t.resetDsCurVal();const n=ku(t.restDecoder);const r=ku(t.restDecoder);const o=i.clients.get(n)||[];const l=id(i,n);for(let i=0;i<r;i++){const i=t.readDsClock();const r=i+t.readDsLen();if(i<l){if(l<r){fa(s,n,l,r-l)}let t=nd(o,i);let h=o[t];if(!h.deleted&&h.id.clock<i){o.splice(t+1,0,Ep(e,h,i-h.id.clock));t++}while(t<o.length){h=o[t++];if(h.id.clock<r){if(!h.deleted){if(r<h.id.clock+h.length){o.splice(t,0,Ep(e,h,r-h.id.clock))}h.delete(e)}}else{break}}}else{fa(s,n,i,r-i)}}}if(s.clients.size>0){const t=new Sa;Wf(t.restEncoder,0);aa(t,s);return t.toUint8Array()}return null};const pa=_u;class ga extends rf{constructor({guid:t=Lu(),collectionid:e=null,gc:i=true,gcFilter:s=()=>true,meta:n=null,autoLoad:r=false,shouldLoad:o=true}={}){super();this.gc=i;this.gcFilter=s;this.clientID=pa();this.guid=t;this.collectionid=e;this.share=new Map;this.store=new td;this._transaction=null;this._transactionCleanups=[];this.subdocs=new Set;this._item=null;this.shouldLoad=o;this.autoLoad=r;this.meta=n;this.isLoaded=false;this.isSynced=false;this.isDestroyed=false;this.whenLoaded=Ju((t=>{this.on("load",(()=>{this.isLoaded=true;t(this)}))}));const l=()=>Ju((t=>{const e=i=>{if(i===undefined||i===true){this.off("sync",e);t()}};this.on("sync",e)}));this.on("sync",(t=>{if(t===false&&this.isSynced){this.whenSynced=l()}this.isSynced=t===undefined||t===true;if(this.isSynced&&!this.isLoaded){this.emit("load",[this])}}));this.whenSynced=l()}load(){const t=this._item;if(t!==null&&!this.shouldLoad){bd(t.parent.doc,(t=>{t.subdocsLoaded.add(this)}),null,true)}this.shouldLoad=true}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(ef(this.subdocs).map((t=>t.guid)))}transact(t,e=null){return bd(this,t,e)}get(t,e=Kd){const i=Kh(this.share,t,(()=>{const t=new e;t._integrate(this,null);return t}));const s=i.constructor;if(e!==Kd&&s!==e){if(s===Kd){const s=new e;s._map=i._map;i._map.forEach((t=>{for(;t!==null;t=t.left){t.parent=s}}));s._start=i._start;for(let t=s._start;t!==null;t=t.right){t.parent=s}s._length=i._length;this.share.set(t,s);s._integrate(this,null);return s}else{throw new Error(`Type with the name ${t} has already been defined with a different constructor`)}}return i}getArray(t=""){return this.get(t,pw)}getText(t=""){return this.get(t,Fw)}getMap(t=""){return this.get(t,yw)}getXmlElement(t=""){return this.get(t,Lw)}getXmlFragment(t=""){return this.get(t,_w)}toJSON(){const t={};this.share.forEach(((e,i)=>{t[i]=e.toJSON()}));return t}destroy(){this.isDestroyed=true;ef(this.subdocs).forEach((t=>t.destroy()));const t=this._item;if(t!==null){this._item=null;const e=t.content;e.doc=new ga({guid:this.guid,...e.opts,shouldLoad:false});e.doc._item=t;bd(t.parent.doc,(i=>{const s=e.doc;if(!t.deleted){i.subdocsAdded.add(s)}i.subdocsRemoved.add(this)}),null,true)}this.emit("destroyed",[true]);this.emit("destroy",[this]);super.destroy()}}class ma{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return ku(this.restDecoder)}readDsLen(){return ku(this.restDecoder)}}class ya extends ma{readLeftID(){return Ka(ku(this.restDecoder),ku(this.restDecoder))}readRightID(){return Ka(ku(this.restDecoder),ku(this.restDecoder))}readClient(){return ku(this.restDecoder)}readInfo(){return Mu(this.restDecoder)}readString(){return Eu(this.restDecoder)}readParentInfo(){return ku(this.restDecoder)===1}readTypeRef(){return ku(this.restDecoder)}readLen(){return ku(this.restDecoder)}readAny(){return Iu(this.restDecoder)}readBuf(){return Uc(Au(this.restDecoder))}readJSON(){return JSON.parse(Eu(this.restDecoder))}readKey(){return Eu(this.restDecoder)}}class ba{constructor(t){this.dsCurrVal=0;this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){this.dsCurrVal+=ku(this.restDecoder);return this.dsCurrVal}readDsLen(){const t=ku(this.restDecoder)+1;this.dsCurrVal+=t;return t}}class va extends ba{constructor(t){super(t);this.keys=[];ku(t);this.keyClockDecoder=new Fu(Au(t));this.clientDecoder=new Pu(Au(t));this.leftClockDecoder=new Fu(Au(t));this.rightClockDecoder=new Fu(Au(t));this.infoDecoder=new Nu(Au(t),Mu);this.stringDecoder=new Bu(Au(t));this.parentInfoDecoder=new Nu(Au(t),Mu);this.typeRefDecoder=new Pu(Au(t));this.lenDecoder=new Pu(Au(t))}readLeftID(){return new qa(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new qa(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Iu(this.restDecoder)}readBuf(){return Au(this.restDecoder)}readJSON(){return Iu(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length){return this.keys[t]}else{const t=this.stringDecoder.read();this.keys.push(t);return t}}}class Aa{constructor(){this.restEncoder=jf()}toUint8Array(){return $f(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){Wf(this.restEncoder,t)}writeDsLen(t){Wf(this.restEncoder,t)}}class Ma extends Aa{writeLeftID(t){Wf(this.restEncoder,t.client);Wf(this.restEncoder,t.clock)}writeRightID(t){Wf(this.restEncoder,t.client);Wf(this.restEncoder,t.clock)}writeClient(t){Wf(this.restEncoder,t)}writeInfo(t){Jf(this.restEncoder,t)}writeString(t){Yf(this.restEncoder,t)}writeParentInfo(t){Wf(this.restEncoder,t?1:0)}writeTypeRef(t){Wf(this.restEncoder,t)}writeLen(t){Wf(this.restEncoder,t)}writeAny(t){ru(this.restEncoder,t)}writeBuf(t){Gf(this.restEncoder,t)}writeJSON(t){Yf(this.restEncoder,JSON.stringify(t))}writeKey(t){Yf(this.restEncoder,t)}}class ka{constructor(){this.restEncoder=jf();this.dsCurrVal=0}toUint8Array(){return $f(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const e=t-this.dsCurrVal;this.dsCurrVal=t;Wf(this.restEncoder,e)}writeDsLen(t){if(t===0){wu()}Wf(this.restEncoder,t-1);this.dsCurrVal+=t}}class Sa extends ka{constructor(){super();this.keyMap=new Map;this.keyClock=0;this.keyClockEncoder=new uu;this.clientEncoder=new hu;this.leftClockEncoder=new uu;this.rightClockEncoder=new uu;this.infoEncoder=new ou(Jf);this.stringEncoder=new cu;this.parentInfoEncoder=new ou(Jf);this.typeRefEncoder=new hu;this.lenEncoder=new hu}toUint8Array(){const t=jf();Wf(t,0);Gf(t,this.keyClockEncoder.toUint8Array());Gf(t,this.clientEncoder.toUint8Array());Gf(t,this.leftClockEncoder.toUint8Array());Gf(t,this.rightClockEncoder.toUint8Array());Gf(t,$f(this.infoEncoder));Gf(t,this.stringEncoder.toUint8Array());Gf(t,$f(this.parentInfoEncoder));Gf(t,this.typeRefEncoder.toUint8Array());Gf(t,this.lenEncoder.toUint8Array());Xf(t,$f(this.restEncoder));return $f(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){ru(this.restEncoder,t)}writeBuf(t){Gf(this.restEncoder,t)}writeJSON(t){ru(this.restEncoder,t)}writeKey(t){const e=this.keyMap.get(t);if(e===undefined){this.keyClockEncoder.write(this.keyClock++);this.stringEncoder.write(t)}else{this.keyClockEncoder.write(e)}}}const xa=(t,e,i,s)=>{s=uf(s,e[0].id.clock);const n=nd(e,s);Wf(t.restEncoder,e.length-n);t.writeClient(i);Wf(t.restEncoder,s);const r=e[n];r.write(t,s-r.id.clock);for(let i=n+1;i<e.length;i++){e[i].write(t,0)}};const Oa=(t,e,i)=>{const s=new Map;i.forEach(((t,i)=>{if(id(e,i)>t){s.set(i,t)}}));ed(e).forEach(((t,e)=>{if(!i.has(e)){s.set(e,0)}}));Wf(t.restEncoder,s.size);ef(s.entries()).sort(((t,e)=>e[0]-t[0])).forEach((([i,s])=>{xa(t,e.clients.get(i),i,s)}))};const Ea=(t,e)=>{const i=qh();const s=ku(t.restDecoder);for(let n=0;n<s;n++){const s=ku(t.restDecoder);const n=new Array(s);const r=t.readClient();let o=ku(t.restDecoder);i.set(r,{i:0,refs:n});for(let i=0;i<s;i++){const s=t.readInfo();switch(vf&s){case 0:{const e=t.readLen();n[i]=new Yw(Ka(r,o),e);o+=e;break}case 10:{const e=ku(t.restDecoder);n[i]=new Np(Ka(r,o),e);o+=e;break}default:{const l=(s&(yf|bf))===0;const h=new Cp(Ka(r,o),null,(s&bf)===bf?t.readLeftID():null,null,(s&yf)===yf?t.readRightID():null,l?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,l&&(s&mf)===mf?t.readString():null,Rp(t,s));n[i]=h;o+=h.length}}}}return i};const Da=(t,e,i)=>{const s=[];let n=ef(i.keys()).sort(((t,e)=>t-e));if(n.length===0){return null}const r=()=>{if(n.length===0){return null}let t=i.get(n[n.length-1]);while(t.refs.length===t.i){n.pop();if(n.length>0){t=i.get(n[n.length-1])}else{return null}}return t};let o=r();if(o===null){return null}const l=new td;const h=new Map;const f=(t,e)=>{const i=h.get(t);if(i==null||i>e){h.set(t,e)}};let u=o.refs[o.i++];const c=new Map;const a=()=>{for(const t of s){const e=t.id.client;const s=i.get(e);if(s){s.i--;l.clients.set(e,s.refs.slice(s.i));i.delete(e);s.i=0;s.refs=[]}else{l.clients.set(e,[t])}n=n.filter((t=>t!==e))}s.length=0};while(true){if(u.constructor!==Np){const n=Kh(c,u.id.client,(()=>id(e,u.id.client)));const r=n-u.id.clock;if(r<0){s.push(u);f(u.id.client,u.id.clock-1);a()}else{const n=u.getMissing(t,e);if(n!==null){s.push(u);const t=i.get(n)||{refs:[],i:0};if(t.refs.length===t.i){f(n,id(e,n));a()}else{u=t.refs[t.i++];continue}}else if(r===0||r<u.length){u.integrate(t,r);c.set(u.id.client,u.id.clock+u.length)}}}if(s.length>0){u=s.pop()}else if(o!==null&&o.i<o.refs.length){u=o.refs[o.i++]}else{o=r();if(o===null){break}else{u=o.refs[o.i++]}}}if(l.clients.size>0){const t=new Sa;Oa(t,l,new Map);Wf(t.restEncoder,0);return{missing:h,update:t.toUint8Array()}}return null};const Ta=(t,e)=>Oa(t,e.doc.store,e.beforeState);const Ca=(t,e,i,s=new va(t))=>bd(e,(t=>{t.local=false;let e=false;const i=t.doc;const n=i.store;const r=Ea(s,i);const o=Da(t,n,r);const l=n.pendingStructs;if(l){for(const[t,i]of l.missing){if(i<id(n,t)){e=true;break}}if(o){for(const[t,e]of o.missing){const i=l.missing.get(t);if(i==null||i>e){l.missing.set(t,e)}}l.update=Td([l.update,o.update])}}else{n.pendingStructs=o}const h=wa(s,t,n);if(n.pendingDs){const e=new va(yu(n.pendingDs));ku(e.restDecoder);const i=wa(e,t,n);if(h&&i){n.pendingDs=Td([h,i])}else{n.pendingDs=h||i}}else{n.pendingDs=h}if(e){const e=n.pendingStructs.update;n.pendingStructs=null;Ra(t.doc,e)}}),i,false);const Ra=(t,e,i,s=va)=>{const n=yu(e);Ca(n,t,i,new s(n))};const Ua=(t,e,i)=>Ra(t,e,i,ya);const Ia=(t,e,i=new Map)=>{Oa(t,e.store,i);aa(t,ca(e.store))};const Na=(t,e=new Uint8Array([0]),i=new Sa)=>{const s=Ba(e);Ia(i,t,s);const n=[i.toUint8Array()];if(t.store.pendingDs){n.push(t.store.pendingDs)}if(t.store.pendingStructs){n.push(Cd(t.store.pendingStructs.update,e))}if(n.length>1){if(i.constructor===Ma){return Ed(n.map(((t,e)=>e===0?t:Pd(t))))}else if(i.constructor===Sa){return Td(n)}}return n[0]};const Pa=(t,e)=>Na(t,e,new Ma);const Fa=t=>{const e=new Map;const i=ku(t.restDecoder);for(let s=0;s<i;s++){const i=ku(t.restDecoder);const s=ku(t.restDecoder);e.set(i,s)}return e};const Ba=t=>Fa(new ma(yu(t)));const ja=(t,e)=>{Wf(t.restEncoder,e.size);ef(e.entries()).sort(((t,e)=>e[0]-t[0])).forEach((([e,i])=>{Wf(t.restEncoder,e);Wf(t.restEncoder,i)}));return t};const _a=(t,e)=>ja(t,ed(e.store));const $a=(t,e=new ka)=>{if(t instanceof Map){ja(e,t)}else{_a(e,t)}return e.toUint8Array()};const La=t=>$a(t,new Aa);class za{constructor(){this.l=[]}}const Ja=()=>new za;const Wa=(t,e)=>t.l.push(e);const Qa=(t,e)=>{const i=t.l;const s=i.length;t.l=i.filter((t=>e!==t));if(s===t.l.length){console.error("[yjs] Tried to remove event handler that doesn't exist.")}};const Ha=(t,e,i)=>uc(t.l,[e,i]);class qa{constructor(t,e){this.client=t;this.clock=e}}const Va=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock;const Ka=(t,e)=>new qa(t,e);const Ya=t=>{for(const[e,i]of t.doc.share.entries()){if(i===t){return e}}throw wu()};const Xa=(t,e)=>{while(e!==null){if(e.parent===t){return true}e=e.parent._item}return false};const Ga=(t,e)=>e===undefined?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!oa(e.ds,t.id);const Za=(t,e)=>{const i=Kh(t.meta,Za,Gh);const s=t.doc.store;if(!i.has(e)){e.sv.forEach(((e,i)=>{if(e<id(s,i)){hd(t,Ka(i,e))}}));na(t,e.ds,(t=>{}));i.add(e)}};class td{constructor(){this.clients=new Map;this.pendingStructs=null;this.pendingDs=null}}const ed=t=>{const e=new Map;t.clients.forEach(((t,i)=>{const s=t[t.length-1];e.set(i,s.id.clock+s.length)}));return e};const id=(t,e)=>{const i=t.clients.get(e);if(i===undefined){return 0}const s=i[i.length-1];return s.id.clock+s.length};const sd=(t,e)=>{let i=t.clients.get(e.id.client);if(i===undefined){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 wu()}}i.push(e)};const nd=(t,e)=>{let i=0;let s=t.length-1;let n=t[s];let r=n.id.clock;if(r===e){return s}let o=lf(e/(r+n.length-1)*s);while(i<=s){n=t[o];r=n.id.clock;if(r<=e){if(e<r+n.length){return o}i=o+1}else{s=o-1}o=lf((i+s)/2)}throw wu()};const rd=(t,e)=>{const i=t.clients.get(e.client);return i[nd(i,e.clock)]};const od=rd;const ld=(t,e,i)=>{const s=nd(e,i);const n=e[s];if(n.id.clock<i&&n instanceof Cp){e.splice(s+1,0,Ep(t,n,i-n.id.clock));return s+1}return s};const hd=(t,e)=>{const i=t.doc.store.clients.get(e.client);return i[ld(t,i,e.clock)]};const fd=(t,e,i)=>{const s=e.clients.get(i.client);const n=nd(s,i.clock);const r=s[n];if(i.clock!==r.id.clock+r.length-1&&r.constructor!==Yw){s.splice(n+1,0,Ep(t,r,i.clock-r.id.clock+1))}return r};const ud=(t,e,i)=>{const s=t.clients.get(e.id.client);s[nd(s,e.id.clock)]=i};const cd=(t,e,i,s,n)=>{if(s===0){return}const r=i+s;let o=ld(t,e,i);let l;do{l=e[o++];if(r<l.id.clock+l.length){ld(t,e,r)}n(l)}while(o<e.length&&e[o].id.clock<r)};class ad{constructor(t,e,i){this.doc=t;this.deleteSet=new sa;this.beforeState=ed(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=false}}const dd=(t,e)=>{if(e.deleteSet.clients.size===0&&!Xh(e.afterState,((t,i)=>e.beforeState.get(i)!==t))){return false}la(e.deleteSet);Ta(t,e);aa(t,e.deleteSet);return true};const wd=(t,e,i)=>{const s=e._item;if(s===null||s.id.clock<(t.beforeState.get(s.id.client)||0)&&!s.deleted){Kh(t.changed,e,Gh).add(i)}};const pd=(t,e)=>{let i=t[e];let s=t[e-1];let n=e;for(;n>0;i=s,s=t[--n-1]){if(s.deleted===i.deleted&&s.constructor===i.constructor){if(s.mergeWith(i)){if(i instanceof Cp&&i.parentSub!==null&&i.parent._map.get(i.parentSub)===i){i.parent._map.set(i.parentSub,s)}continue}}break}const r=e-n;if(r){t.splice(e+1-r,r)}return r};const gd=(t,e,i)=>{for(const[s,n]of t.clients.entries()){const t=e.clients.get(s);for(let s=n.length-1;s>=0;s--){const r=n[s];const o=r.clock+r.len;for(let s=nd(t,r.clock),n=t[s];s<t.length&&n.id.clock<o;n=t[++s]){const n=t[s];if(r.clock+r.len<=n.id.clock){break}if(n instanceof Cp&&n.deleted&&!n.keep&&i(n)){n.gc(e,false)}}}}};const md=(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];const n=ff(s.length-1,1+nd(s,i.clock+i.len-1));for(let t=n,e=s[t];t>0&&e.id.clock>=i.clock;e=s[t]){t-=1+pd(s,t)}}}))};const yd=(t,e)=>{if(e<t.length){const i=t[e];const s=i.doc;const n=s.store;const r=i.deleteSet;const o=i._mergeStructs;try{la(r);i.afterState=ed(i.doc.store);s.emit("beforeObserverCalls",[i,s]);const t=[];i.changed.forEach(((e,s)=>t.push((()=>{if(s._item===null||!s._item.deleted){s._callObserver(i,e)}}))));t.push((()=>{i.changedParentTypes.forEach(((t,e)=>{if(e._dEH.l.length>0&&(e._item===null||!e._item.deleted)){t=t.filter((t=>t.target._item===null||!t.target._item.deleted));t.forEach((t=>{t.currentTarget=e;t._path=null}));t.sort(((t,e)=>t.path.length-e.path.length));Ha(e._dEH,t,i)}}))}));t.push((()=>s.emit("afterTransaction",[i,s])));uc(t,[]);if(i._needFormattingCleanup){Iw(i)}}finally{if(s.gc){gd(r,n,s.gcFilter)}md(r,n);i.afterState.forEach(((t,e)=>{const s=i.beforeState.get(e)||0;if(s!==t){const t=n.clients.get(e);const i=uf(nd(t,s),1);for(let e=t.length-1;e>=i;){e-=1+pd(t,e)}}}));for(let t=o.length-1;t>=0;t--){const{client:e,clock:i}=o[t].id;const s=n.clients.get(e);const r=nd(s,i);if(r+1<s.length){if(pd(s,r+1)>1){continue}}if(r>0){pd(s,r)}}if(!i.local&&i.afterState.get(s.clientID)!==i.beforeState.get(s.clientID)){Yc(Wc,Bc,"[yjs] ",jc,zc,"Changed the client-id because another client seems to be using it.");s.clientID=pa()}s.emit("afterTransactionCleanup",[i,s]);if(s._observers.has("update")){const t=new Ma;const e=dd(t,i);if(e){s.emit("update",[t.toUint8Array(),i.origin,s,i])}}if(s._observers.has("updateV2")){const t=new Sa;const e=dd(t,i);if(e){s.emit("updateV2",[t.toUint8Array(),i.origin,s,i])}}const{subdocsAdded:l,subdocsLoaded:h,subdocsRemoved:f}=i;if(l.size>0||f.size>0||h.size>0){l.forEach((t=>{t.clientID=s.clientID;if(t.collectionid==null){t.collectionid=s.collectionid}s.subdocs.add(t)}));f.forEach((t=>s.subdocs.delete(t)));s.emit("subdocs",[{loaded:h,added:l,removed:f},s,i]);f.forEach((t=>t.destroy()))}if(t.length<=e+1){s._transactionCleanups=[];s.emit("afterAllTransactions",[s,t])}else{yd(t,e+1)}}}};const bd=(t,e,i=null,s=true)=>{const n=t._transactionCleanups;let r=false;let o=null;if(t._transaction===null){r=true;t._transaction=new ad(t,i,s);n.push(t._transaction);if(n.length===1){t.emit("beforeAllTransactions",[t])}t.emit("beforeTransaction",[t._transaction,t])}try{o=e(t._transaction)}finally{if(r){const e=t._transaction===n[0];t._transaction=null;if(e){yd(n,0)}}}return o};class vd{constructor(t,e){this.insertions=e;this.deletions=t;this.meta=new Map}}const Ad=(t,e,i)=>{na(t,i.deletions,(i=>{if(i instanceof Cp&&e.scope.some((e=>e===t.doc||Xa(e,i)))){Op(i,false)}}))};const Md=(t,e,i)=>{let s=null;const n=t.doc;const r=t.scope;bd(n,(i=>{while(e.length>0&&t.currStackItem===null){const s=n.store;const o=e.pop();const l=new Set;const h=[];let f=false;na(i,o.insertions,(t=>{if(t instanceof Cp){if(t.redone!==null){let{item:e,diff:n}=xp(s,t.id);if(n>0){e=hd(i,Ka(e.id.client,e.id.clock+n))}t=e}if(!t.deleted&&r.some((e=>e===i.doc||Xa(e,t)))){h.push(t)}}}));na(i,o.deletions,(t=>{if(t instanceof Cp&&r.some((e=>e===i.doc||Xa(e,t)))&&!oa(o.insertions,t.id)){l.add(t)}}));l.forEach((e=>{f=Tp(i,e,l,o.insertions,t.ignoreRemoteMapChanges,t)!==null||f}));for(let e=h.length-1;e>=0;e--){const s=h[e];if(t.deleteFilter(s)){s.delete(i);f=true}}t.currStackItem=f?o:null}i.changed.forEach(((t,e)=>{if(t.has(null)&&e._searchMarker){e._searchMarker.length=0}}));s=i}),t);const o=t.currStackItem;if(o!=null){const e=s.changedParentTypes;t.emit("stack-item-popped",[{stackItem:o,type:i,changedParentTypes:e,origin:t},t]);t.currStackItem=null}return o};class kd extends rf{constructor(t,{captureTimeout:e=500,captureTransaction:i=t=>true,deleteFilter:s=()=>true,trackedOrigins:n=new Set([null]),ignoreRemoteMapChanges:r=false,doc:o=(nf(t)?t[0].doc:t instanceof ga?t:t.doc)}={}){super();this.scope=[];this.doc=o;this.addToScope(t);this.deleteFilter=s;n.add(this);this.trackedOrigins=n;this.captureTransaction=i;this.undoStack=[];this.redoStack=[];this.undoing=false;this.redoing=false;this.currStackItem=null;this.lastChange=0;this.ignoreRemoteMapChanges=r;this.captureTimeout=e;this.afterTransactionHandler=t=>{if(!this.captureTransaction(t)||!this.scope.some((e=>t.changedParentTypes.has(e)||e===this.doc))||!this.trackedOrigins.has(t.origin)&&(!t.origin||!this.trackedOrigins.has(t.origin.constructor))){return}const e=this.undoing;const i=this.redoing;const s=e?this.redoStack:this.undoStack;if(e){this.stopCapturing()}else if(!i){this.clear(false,true)}const n=new sa;t.afterState.forEach(((e,i)=>{const s=t.beforeState.get(i)||0;const r=e-s;if(r>0){fa(n,i,s,r)}}));const r=zu();let o=false;if(this.lastChange>0&&r-this.lastChange<this.captureTimeout&&s.length>0&&!e&&!i){const e=s[s.length-1];e.deletions=ha([e.deletions,t.deleteSet]);e.insertions=ha([e.insertions,n])}else{s.push(new vd(t.deleteSet,n));o=true}if(!e&&!i){this.lastChange=r}na(t,t.deleteSet,(e=>{if(e instanceof Cp&&this.scope.some((i=>i===t.doc||Xa(i,e)))){Op(e,true)}}));const l=[{stackItem:s[s.length-1],origin:t.origin,type:e?"redo":"undo",changedParentTypes:t.changedParentTypes},this];if(o){this.emit("stack-item-added",l)}else{this.emit("stack-item-updated",l)}};this.doc.on("afterTransaction",this.afterTransactionHandler);this.doc.on("destroy",(()=>{this.destroy()}))}addToScope(t){const e=new Set(this.scope);t=nf(t)?t:[t];t.forEach((t=>{if(!e.has(t)){e.add(t);if(t instanceof Kd?t.doc!==this.doc:t!==this.doc)Xc("[yjs#509] Not same Y.Doc");this.scope.push(t)}}))}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=true,e=true){if(t&&this.canUndo()||e&&this.canRedo()){this.doc.transact((i=>{if(t){this.undoStack.forEach((t=>Ad(i,this,t)));this.undoStack=[]}if(e){this.redoStack.forEach((t=>Ad(i,this,t)));this.redoStack=[]}this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:e}])}))}}stopCapturing(){this.lastChange=0}undo(){this.undoing=true;let t;try{t=Md(this,this.undoStack,"undo")}finally{this.undoing=false}return t}redo(){this.redoing=true;let t;try{t=Md(this,this.redoStack,"redo")}finally{this.redoing=false}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()}}function*Sd(t){const e=ku(t.restDecoder);for(let i=0;i<e;i++){const e=ku(t.restDecoder);const i=t.readClient();let s=ku(t.restDecoder);for(let n=0;n<e;n++){const e=t.readInfo();if(e===10){const e=ku(t.restDecoder);yield new Np(Ka(i,s),e);s+=e}else if((vf&e)!==0){const n=(e&(yf|bf))===0;const r=new Cp(Ka(i,s),null,(e&bf)===bf?t.readLeftID():null,null,(e&yf)===yf?t.readRightID():null,n?t.readParentInfo()?t.readString():t.readLeftID():null,n&&(e&mf)===mf?t.readString():null,Rp(t,e));yield r;s+=r.length}else{const e=t.readLen();yield new Yw(Ka(i,s),e);s+=e}}}}class xd{constructor(t,e){this.gen=Sd(t);this.curr=null;this.done=false;this.filterSkips=e;this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&this.curr!==null&&this.curr.constructor===Np);return this.curr}}class Od{constructor(t){this.currClient=0;this.startClock=0;this.written=0;this.encoder=t;this.clientStructs=[]}}const Ed=t=>Td(t,ya,Ma);const Dd=(t,e)=>{if(t.constructor===Yw){const{client:i,clock:s}=t.id;return new Yw(Ka(i,s+e),t.length-e)}else if(t.constructor===Np){const{client:i,clock:s}=t.id;return new Np(Ka(i,s+e),t.length-e)}else{const i=t;const{client:s,clock:n}=i.id;return new Cp(Ka(s,n+e),null,Ka(s,n+e-1),null,i.rightOrigin,i.parent,i.parentSub,i.content.splice(e))}};const Td=(t,e=va,i=Sa)=>{if(t.length===1){return t[0]}const s=t.map((t=>new e(yu(t))));let n=s.map((t=>new xd(t,true)));let r=null;const o=new i;const l=new Od(o);while(true){n=n.filter((t=>t.curr!==null));n.sort(((t,e)=>{if(t.curr.id.client===e.curr.id.client){const i=t.curr.id.clock-e.curr.id.clock;if(i===0){return t.curr.constructor===e.curr.constructor?0:t.curr.constructor===Np?1:-1}else{return i}}else{return e.curr.id.client-t.curr.id.client}}));if(n.length===0){break}const t=n[0];const e=t.curr.id.client;if(r!==null){let i=t.curr;let s=false;while(i!==null&&i.id.clock+i.length<=r.struct.id.clock+r.struct.length&&i.id.client>=r.struct.id.client){i=t.next();s=true}if(i===null||i.id.client!==e||s&&i.id.clock>r.struct.id.clock+r.struct.length){continue}if(e!==r.struct.id.client){Ud(l,r.struct,r.offset);r={struct:i,offset:0};t.next()}else{if(r.struct.id.clock+r.struct.length<i.id.clock){if(r.struct.constructor===Np){r.struct.length=i.id.clock+i.length-r.struct.id.clock}else{Ud(l,r.struct,r.offset);const t=i.id.clock-r.struct.id.clock-r.struct.length;const s=new Np(Ka(e,r.struct.id.clock+r.struct.length),t);r={struct:s,offset:0}}}else{const e=r.struct.id.clock+r.struct.length-i.id.clock;if(e>0){if(r.struct.constructor===Np){r.struct.length-=e}else{i=Dd(i,e)}}if(!r.struct.mergeWith(i)){Ud(l,r.struct,r.offset);r={struct:i,offset:0};t.next()}}}}else{r={struct:t.curr,offset:0};t.next()}for(let i=t.curr;i!==null&&i.id.client===e&&i.id.clock===r.struct.id.clock+r.struct.length&&i.constructor!==Np;i=t.next()){Ud(l,r.struct,r.offset);r={struct:i,offset:0}}}if(r!==null){Ud(l,r.struct,r.offset);r=null}Id(l);const h=s.map((t=>da(t)));const f=ha(h);aa(o,f);return o.toUint8Array()};const Cd=(t,e,i=va,s=Sa)=>{const n=Ba(e);const r=new s;const o=new Od(r);const l=new i(yu(t));const h=new xd(l,false);while(h.curr){const t=h.curr;const e=t.id.client;const i=n.get(e)||0;if(h.curr.constructor===Np){h.next();continue}if(t.id.clock+t.length>i){Ud(o,t,uf(i-t.id.clock,0));h.next();while(h.curr&&h.curr.id.client===e){Ud(o,h.curr,0);h.next()}}else{while(h.curr&&h.curr.id.client===e&&h.curr.id.clock+h.curr.length<=i){h.next()}}}Id(o);const f=da(l);aa(r,f);return r.toUint8Array()};const Rd=t=>{if(t.written>0){t.clientStructs.push({written:t.written,restEncoder:$f(t.encoder.restEncoder)});t.encoder.restEncoder=jf();t.written=0}};const Ud=(t,e,i)=>{if(t.written>0&&t.currClient!==e.id.client){Rd(t)}if(t.written===0){t.currClient=e.id.client;t.encoder.writeClient(e.id.client);Wf(t.encoder.restEncoder,e.id.clock+i)}e.write(t.encoder,i);t.written++};const Id=t=>{Rd(t);const e=t.encoder.restEncoder;Wf(e,t.clientStructs.length);for(let i=0;i<t.clientStructs.length;i++){const s=t.clientStructs[i];Wf(e,s.written);Xf(e,s.restEncoder)}};const Nd=(t,e,i,s)=>{const n=new i(yu(t));const r=new xd(n,false);const o=new s;const l=new Od(o);for(let t=r.curr;t!==null;t=r.next()){Ud(l,e(t),0)}Id(l);const h=da(n);aa(o,h);return o.toUint8Array()};const Pd=t=>Nd(t,cc,va,Ma);const Fd="You must not compute changes after the event-handler fired.";class Bd{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=jd(this.currentTarget,this.target))}deletes(t){return oa(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0){throw au(Fd)}const t=new Map;const e=this.target;const i=this.transaction.changed.get(e);i.forEach((i=>{if(i!==null){const s=e._map.get(i);let n;let r;if(this.adds(s)){let t=s.left;while(t!==null&&this.adds(t)){t=t.left}if(this.deletes(s)){if(t!==null&&this.deletes(t)){n="delete";r=Zh(t.content.getContent())}else{return}}else{if(t!==null&&this.deletes(t)){n="update";r=Zh(t.content.getContent())}else{n="add";r=undefined}}}else{if(this.deletes(s)){n="delete";r=Zh(s.content.getContent())}else{return}}t.set(i,{action:n,oldValue:r})}}));this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0){throw au(Fd)}const e=this.target;const i=Gh();const s=Gh();const n=[];t={added:i,deleted:s,delta:n,keys:this.keys};const r=this.transaction.changed.get(e);if(r.has(null)){let t=null;const r=()=>{if(t){n.push(t)}};for(let n=e._start;n!==null;n=n.right){if(n.deleted){if(this.deletes(n)&&!this.adds(n)){if(t===null||t.delete===undefined){r();t={delete:0}}t.delete+=n.length;s.add(n)}}else{if(this.adds(n)){if(t===null||t.insert===undefined){r();t={insert:[]}}t.insert=t.insert.concat(n.content.getContent());i.add(n)}else{if(t===null||t.retain===undefined){r();t={retain:0}}t.retain+=n.length}}}if(t!==null&&t.retain===undefined){r()}}this._changes=t}return t}}const jd=(t,e)=>{const i=[];while(e._item!==null&&e!==t){if(e._item.parentSub!==null){i.unshift(e._item.parentSub)}else{let t=0;let s=e._item.parent._start;while(s!==e._item&&s!==null){if(!s.deleted&&s.countable){t+=s.length}s=s.right}i.unshift(t)}e=e._item.parent}return i};const _d=()=>{Xc("Invalid access: Add Yjs type to a document before reading data.")};const $d=80;let Ld=0;class zd{constructor(t,e){t.marker=true;this.p=t;this.index=e;this.timestamp=Ld++}}const Jd=t=>{t.timestamp=Ld++};const Wd=(t,e,i)=>{t.p.marker=false;t.p=e;e.marker=true;t.index=i;t.timestamp=Ld++};const Qd=(t,e,i)=>{if(t.length>=$d){const s=t.reduce(((t,e)=>t.timestamp<e.timestamp?t:e));Wd(s,e,i);return s}else{const s=new zd(e,i);t.push(s);return s}};const Hd=(t,e)=>{if(t._start===null||e===0||t._searchMarker===null){return null}const i=t._searchMarker.length===0?null:t._searchMarker.reduce(((t,i)=>hf(e-t.index)<hf(e-i.index)?t:i));let s=t._start;let n=0;if(i!==null){s=i.p;n=i.index;Jd(i)}while(s.right!==null&&n<e){if(!s.deleted&&s.countable){if(e<n+s.length){break}n+=s.length}s=s.right}while(s.left!==null&&n>e){s=s.left;if(!s.deleted&&s.countable){n-=s.length}}while(s.left!==null&&s.left.id.client===s.id.client&&s.left.id.clock+s.left.length===s.id.clock){s=s.left;if(!s.deleted&&s.countable){n-=s.length}}if(i!==null&&hf(i.index-n)<s.parent.length/$d){Wd(i,s,n);return i}else{return Qd(t._searchMarker,s,n)}};const qd=(t,e,i)=>{for(let s=t.length-1;s>=0;s--){const n=t[s];if(i>0){let e=n.p;e.marker=false;while(e&&(e.deleted||!e.countable)){e=e.left;if(e&&!e.deleted&&e.countable){n.index-=e.length}}if(e===null||e.marker===true){t.splice(s,1);continue}n.p=e;e.marker=true}if(e<n.index||i>0&&e===n.index){n.index=uf(e,n.index+i)}}};const Vd=(t,e,i)=>{const s=t;const n=e.changedParentTypes;while(true){Kh(n,t,(()=>[])).push(i);if(t._item===null){break}t=t._item.parent}Ha(s._eH,i,e)};class Kd{constructor(){this._item=null;this._map=new Map;this._start=null;this.doc=null;this._length=0;this._eH=Ja();this._dEH=Ja();this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t;this._item=e}_copy(){throw du()}clone(){throw du()}_write(t){}get _first(){let t=this._start;while(t!==null&&t.deleted){t=t.right}return t}_callObserver(t,e){if(!t.local&&this._searchMarker){this._searchMarker.length=0}}observe(t){Wa(this._eH,t)}observeDeep(t){Wa(this._dEH,t)}unobserve(t){Qa(this._eH,t)}unobserveDeep(t){Qa(this._dEH,t)}toJSON(){}}const Yd=(t,e,i)=>{t.doc??_d();if(e<0){e=t._length+e}if(i<0){i=t._length+i}let s=i-e;const n=[];let r=t._start;while(r!==null&&s>0){if(r.countable&&!r.deleted){const t=r.content.getContent();if(t.length<=e){e-=t.length}else{for(let i=e;i<t.length&&s>0;i++){n.push(t[i]);s--}e=0}}r=r.right}return n};const Xd=t=>{t.doc??_d();const e=[];let i=t._start;while(i!==null){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};const Gd=(t,e)=>{let i=0;let s=t._start;t.doc??_d();while(s!==null){if(s.countable&&!s.deleted){const n=s.content.getContent();for(let s=0;s<n.length;s++){e(n[s],i++,t)}}s=s.right}};const Zd=(t,e)=>{const i=[];Gd(t,((s,n)=>{i.push(e(s,n,t))}));return i};const tw=t=>{let e=t._start;let i=null;let s=0;return{[Symbol.iterator](){return this},next:()=>{if(i===null){while(e!==null&&e.deleted){e=e.right}if(e===null){return{done:true,value:undefined}}i=e.content.getContent();s=0;e=e.right}const t=i[s++];if(i.length<=s){i=null}return{done:false,value:t}}}};const ew=(t,e)=>{t.doc??_d();const i=Hd(t,e);let s=t._start;if(i!==null){s=i.p;e-=i.index}for(;s!==null;s=s.right){if(!s.deleted&&s.countable){if(e<s.length){return s.content.getContent()[e]}e-=s.length}}};const iw=(t,e,i,s)=>{let n=i;const r=t.doc;const o=r.clientID;const l=r.store;const h=i===null?e._start:i.right;let f=[];const u=()=>{if(f.length>0){n=new Cp(Ka(o,id(l,o)),n,n&&n.lastId,h,h&&h.id,e,null,new cp(f));n.integrate(t,0);f=[]}};s.forEach((i=>{if(i===null){f.push(i)}else{switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:f.push(i);break;default:u();switch(i.constructor){case Uint8Array:case ArrayBuffer:n=new Cp(Ka(o,id(l,o)),n,n&&n.lastId,h,h&&h.id,e,null,new Xw(new Uint8Array(i)));n.integrate(t,0);break;case ga:n=new Cp(Ka(o,id(l,o)),n,n&&n.lastId,h,h&&h.id,e,null,new ip(i));n.integrate(t,0);break;default:if(i instanceof Kd){n=new Cp(Ka(o,id(l,o)),n,n&&n.lastId,h,h&&h.id,e,null,new kp(i));n.integrate(t,0)}else{throw new Error("Unexpected content type in insert operation")}}}}}));u()};const sw=()=>au("Length exceeded!");const nw=(t,e,i,s)=>{if(i>e._length){throw sw()}if(i===0){if(e._searchMarker){qd(e._searchMarker,i,s.length)}return iw(t,e,null,s)}const n=i;const r=Hd(e,i);let o=e._start;if(r!==null){o=r.p;i-=r.index;if(i===0){o=o.prev;i+=o&&o.countable&&!o.deleted?o.length:0}}for(;o!==null;o=o.right){if(!o.deleted&&o.countable){if(i<=o.length){if(i<o.length){hd(t,Ka(o.id.client,o.id.clock+i))}break}i-=o.length}}if(e._searchMarker){qd(e._searchMarker,n,s.length)}return iw(t,e,o,s)};const rw=(t,e,i)=>{const s=(e._searchMarker||[]).reduce(((t,e)=>e.index>t.index?e:t),{index:0,p:e._start});let n=s.p;if(n){while(n.right){n=n.right}}return iw(t,e,n,i)};const ow=(t,e,i,s)=>{if(s===0){return}const n=i;const r=s;const o=Hd(e,i);let l=e._start;if(o!==null){l=o.p;i-=o.index}for(;l!==null&&i>0;l=l.right){if(!l.deleted&&l.countable){if(i<l.length){hd(t,Ka(l.id.client,l.id.clock+i))}i-=l.length}}while(s>0&&l!==null){if(!l.deleted){if(s<l.length){hd(t,Ka(l.id.client,l.id.clock+s))}l.delete(t);s-=l.length}l=l.right}if(s>0){throw sw()}if(e._searchMarker){qd(e._searchMarker,n,-r+s)}};const lw=(t,e,i)=>{const s=e._map.get(i);if(s!==undefined){s.delete(t)}};const hw=(t,e,i,s)=>{const n=e._map.get(i)||null;const r=t.doc;const o=r.clientID;let l;if(s==null){l=new cp([s])}else{switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new cp([s]);break;case Uint8Array:l=new Xw(s);break;case ga:l=new ip(s);break;default:if(s instanceof Kd){l=new kp(s)}else{throw new Error("Unexpected content type")}}}new Cp(Ka(o,id(r.store,o)),n,n&&n.lastId,null,null,e,i,l).integrate(t,0)};const fw=(t,e)=>{t.doc??_d();const i=t._map.get(e);return i!==undefined&&!i.deleted?i.content.getContent()[i.length-1]:undefined};const uw=t=>{const e={};t.doc??_d();t._map.forEach(((t,i)=>{if(!t.deleted){e[i]=t.content.getContent()[t.length-1]}}));return e};const cw=(t,e)=>{t.doc??_d();const i=t._map.get(e);return i!==undefined&&!i.deleted};const aw=(t,e)=>{const i={};t._map.forEach(((t,s)=>{let n=t;while(n!==null&&(!e.sv.has(n.id.client)||n.id.clock>=(e.sv.get(n.id.client)||0))){n=n.left}if(n!==null&&Ga(n,e)){i[s]=n.content.getContent()[n.length-1]}}));return i};const dw=t=>{t.doc??_d();return ta(t._map.entries(),(t=>!t[1].deleted))};class ww extends Bd{}class pw extends Kd{constructor(){super();this._prelimContent=[];this._searchMarker=[]}static from(t){const e=new pw;e.push(t);return e}_integrate(t,e){super._integrate(t,e);this.insert(0,this._prelimContent);this._prelimContent=null}_copy(){return new pw}clone(){const t=new pw;t.insert(0,this.toArray().map((t=>t instanceof Kd?t.clone():t)));return t}get length(){this.doc??_d();return this._length}_callObserver(t,e){super._callObserver(t,e);Vd(this,t,new ww(this,t))}insert(t,e){if(this.doc!==null){bd(this.doc,(i=>{nw(i,this,t,e)}))}else{this._prelimContent.splice(t,0,...e)}}push(t){if(this.doc!==null){bd(this.doc,(e=>{rw(e,this,t)}))}else{this._prelimContent.push(...t)}}unshift(t){this.insert(0,t)}delete(t,e=1){if(this.doc!==null){bd(this.doc,(i=>{ow(i,this,t,e)}))}else{this._prelimContent.splice(t,e)}}get(t){return ew(this,t)}toArray(){return Xd(this)}slice(t=0,e=this.length){return Yd(this,t,e)}toJSON(){return this.map((t=>t instanceof Kd?t.toJSON():t))}map(t){return Zd(this,t)}forEach(t){Gd(this,t)}[Symbol.iterator](){return tw(this)}_write(t){t.writeTypeRef(gp)}}const gw=t=>new pw;class mw extends Bd{constructor(t,e,i){super(t,e);this.keysChanged=i}}class yw extends Kd{constructor(t){super();this._prelimContent=null;if(t===undefined){this._prelimContent=new Map}else{this._prelimContent=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 yw}clone(){const t=new yw;this.forEach(((e,i)=>{t.set(i,e instanceof Kd?e.clone():e)}));return t}_callObserver(t,e){Vd(this,t,new mw(this,t,e))}toJSON(){this.doc??_d();const t={};this._map.forEach(((e,i)=>{if(!e.deleted){const s=e.content.getContent()[e.length-1];t[i]=s instanceof Kd?s.toJSON():s}}));return t}get size(){return[...dw(this)].length}keys(){return ea(dw(this),(t=>t[0]))}values(){return ea(dw(this),(t=>t[1].content.getContent()[t[1].length-1]))}entries(){return ea(dw(this),(t=>[t[0],t[1].content.getContent()[t[1].length-1]]))}forEach(t){this.doc??_d();this._map.forEach(((e,i)=>{if(!e.deleted){t(e.content.getContent()[e.length-1],i,this)}}))}[Symbol.iterator](){return this.entries()}delete(t){if(this.doc!==null){bd(this.doc,(e=>{lw(e,this,t)}))}else{this._prelimContent.delete(t)}}set(t,e){if(this.doc!==null){bd(this.doc,(i=>{hw(i,this,t,e)}))}else{this._prelimContent.set(t,e)}return e}get(t){return fw(this,t)}has(t){return cw(this,t)}clear(){if(this.doc!==null){bd(this.doc,(t=>{this.forEach((function(e,i,s){lw(t,s,i)}))}))}else{this._prelimContent.clear()}}_write(t){t.writeTypeRef(mp)}}const bw=t=>new yw;const vw=(t,e)=>t===e||typeof t==="object"&&typeof e==="object"&&t&&e&&oc(t,e);class Aw{constructor(t,e,i,s){this.left=t;this.right=e;this.index=i;this.currentAttributes=s}forward(){if(this.right===null){wu()}switch(this.right.content.constructor){case op:if(!this.right.deleted){xw(this.currentAttributes,this.right.content)}break;default:if(!this.right.deleted){this.index+=this.right.length}break}this.left=this.right;this.right=this.right.right}}const Mw=(t,e,i)=>{while(e.right!==null&&i>0){switch(e.right.content.constructor){case op:if(!e.right.deleted){xw(e.currentAttributes,e.right.content)}break;default:if(!e.right.deleted){if(i<e.right.length){hd(t,Ka(e.right.id.client,e.right.id.clock+i))}e.index+=e.right.length;i-=e.right.length}break}e.left=e.right;e.right=e.right.right}return e};const kw=(t,e,i,s)=>{const n=new Map;const r=s?Hd(e,i):null;if(r){const e=new Aw(r.p.left,r.p,r.index,n);return Mw(t,e,i-r.index)}else{const s=new Aw(null,e._start,0,n);return Mw(t,s,i)}};const Sw=(t,e,i,s)=>{while(i.right!==null&&(i.right.deleted===true||i.right.content.constructor===op&&vw(s.get(i.right.content.key),i.right.content.value))){if(!i.right.deleted){s.delete(i.right.content.key)}i.forward()}const n=t.doc;const r=n.clientID;s.forEach(((s,o)=>{const l=i.left;const h=i.right;const f=new Cp(Ka(r,id(n.store,r)),l,l&&l.lastId,h,h&&h.id,e,null,new op(o,s));f.integrate(t,0);i.right=f;i.forward()}))};const xw=(t,e)=>{const{key:i,value:s}=e;if(s===null){t.delete(i)}else{t.set(i,s)}};const Ow=(t,e)=>{while(true){if(t.right===null){break}else if(t.right.deleted||t.right.content.constructor===op&&vw(e[t.right.content.key]??null,t.right.content.value));else{break}t.forward()}};const Ew=(t,e,i,s)=>{const n=t.doc;const r=n.clientID;const o=new Map;for(const l in s){const h=s[l];const f=i.currentAttributes.get(l)??null;if(!vw(f,h)){o.set(l,f);const{left:s,right:u}=i;i.right=new Cp(Ka(r,id(n.store,r)),s,s&&s.lastId,u,u&&u.id,e,null,new op(l,h));i.right.integrate(t,0);i.forward()}}return o};const Dw=(t,e,i,s,n)=>{i.currentAttributes.forEach(((t,e)=>{if(n[e]===undefined){n[e]=null}}));const r=t.doc;const o=r.clientID;Ow(i,n);const l=Ew(t,e,i,n);const h=s.constructor===String?new dp(s):s instanceof Kd?new kp(s):new np(s);let{left:f,right:u,index:c}=i;if(e._searchMarker){qd(e._searchMarker,i.index,h.getLength())}u=new Cp(Ka(o,id(r.store,o)),f,f&&f.lastId,u,u&&u.id,e,null,h);u.integrate(t,0);i.right=u;i.index=c;i.forward();Sw(t,e,i,l)};const Tw=(t,e,i,s,n)=>{const r=t.doc;const o=r.clientID;Ow(i,n);const l=Ew(t,e,i,n);t:while(i.right!==null&&(s>0||l.size>0&&(i.right.deleted||i.right.content.constructor===op))){if(!i.right.deleted){switch(i.right.content.constructor){case op:{const{key:e,value:r}=i.right.content;const o=n[e];if(o!==undefined){if(vw(o,r)){l.delete(e)}else{if(s===0){break t}l.set(e,r)}i.right.delete(t)}else{i.currentAttributes.set(e,r)}break}default:if(s<i.right.length){hd(t,Ka(i.right.id.client,i.right.id.clock+s))}s-=i.right.length;break}}i.forward()}if(s>0){let n="";for(;s>0;s--){n+="\n"}i.right=new Cp(Ka(o,id(r.store,o)),i.left,i.left&&i.left.lastId,i.right,i.right&&i.right.id,e,null,new dp(n));i.right.integrate(t,0);i.forward()}Sw(t,e,i,l)};const Cw=(t,e,i,s,n)=>{let r=e;const o=qh();while(r&&(!r.countable||r.deleted)){if(!r.deleted&&r.content.constructor===op){const t=r.content;o.set(t.key,t)}r=r.right}let l=0;let h=false;while(e!==r){if(i===e){h=true}if(!e.deleted){const i=e.content;switch(i.constructor){case op:{const{key:r,value:f}=i;const u=s.get(r)??null;if(o.get(r)!==i||u===f){e.delete(t);l++;if(!h&&(n.get(r)??null)===f&&u!==f){if(u===null){n.delete(r)}else{n.set(r,u)}}}if(!h&&!e.deleted){xw(n,i)}break}}}e=e.right}return l};const Rw=(t,e)=>{while(e&&e.right&&(e.right.deleted||!e.right.countable)){e=e.right}const i=new Set;while(e&&(e.deleted||!e.countable)){if(!e.deleted&&e.content.constructor===op){const s=e.content.key;if(i.has(s)){e.delete(t)}else{i.add(s)}}e=e.left}};const Uw=t=>{let e=0;bd(t.doc,(i=>{let s=t._start;let n=t._start;let r=qh();const o=Vh(r);while(n){if(n.deleted===false){switch(n.content.constructor){case op:xw(o,n.content);break;default:e+=Cw(i,s,n,r,o);r=Vh(o);s=n;break}}n=n.right}}));return e};const Iw=t=>{const e=new Set;const i=t.doc;for(const[s,n]of t.afterState.entries()){const r=t.beforeState.get(s)||0;if(n===r){continue}cd(t,i.store.clients.get(s),r,n,(t=>{if(!t.deleted&&t.content.constructor===op&&t.constructor!==Yw){e.add(t.parent)}}))}bd(i,(i=>{na(t,t.deleteSet,(t=>{if(t instanceof Yw||!t.parent._hasFormatting||e.has(t.parent)){return}const s=t.parent;if(t.content.constructor===op){e.add(s)}else{Rw(i,t)}}));for(const t of e){Uw(t)}}))};const Nw=(t,e,i)=>{const s=i;const n=Vh(e.currentAttributes);const r=e.right;while(i>0&&e.right!==null){if(e.right.deleted===false){switch(e.right.content.constructor){case kp:case np:case dp:if(i<e.right.length){hd(t,Ka(e.right.id.client,e.right.id.clock+i))}i-=e.right.length;e.right.delete(t);break}}e.forward()}if(r){Cw(t,r,e.right,n,e.currentAttributes)}const o=(e.left||e.right).parent;if(o._searchMarker){qd(o._searchMarker,e.index,-s+i)}return e};class Pw extends Bd{constructor(t,e,i){super(t,e);this.childListChanged=false;this.keysChanged=new Set;i.forEach((t=>{if(t===null){this.childListChanged=true}else{this.keysChanged.add(t)}}))}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc;const e=[];bd(t,(t=>{const i=new Map;const s=new Map;let n=this.target._start;let r=null;const o={};let l="";let h=0;let f=0;const u=()=>{if(r!==null){let t=null;switch(r){case"delete":if(f>0){t={delete:f}}f=0;break;case"insert":if(typeof l==="object"||l.length>0){t={insert:l};if(i.size>0){t.attributes={};i.forEach(((e,i)=>{if(e!==null){t.attributes[i]=e}}))}}l="";break;case"retain":if(h>0){t={retain:h};if(!sc(o)){t.attributes=Xu({},o)}}h=0;break}if(t)e.push(t);r=null}};while(n!==null){switch(n.content.constructor){case kp:case np:if(this.adds(n)){if(!this.deletes(n)){u();r="insert";l=n.content.getContent()[0];u()}}else if(this.deletes(n)){if(r!=="delete"){u();r="delete"}f+=1}else if(!n.deleted){if(r!=="retain"){u();r="retain"}h+=1}break;case dp:if(this.adds(n)){if(!this.deletes(n)){if(r!=="insert"){u();r="insert"}l+=n.content.str}}else if(this.deletes(n)){if(r!=="delete"){u();r="delete"}f+=n.length}else if(!n.deleted){if(r!=="retain"){u();r="retain"}h+=n.length}break;case op:{const{key:e,value:l}=n.content;if(this.adds(n)){if(!this.deletes(n)){const h=i.get(e)??null;if(!vw(h,l)){if(r==="retain"){u()}if(vw(l,s.get(e)??null)){delete o[e]}else{o[e]=l}}else if(l!==null){n.delete(t)}}}else if(this.deletes(n)){s.set(e,l);const t=i.get(e)??null;if(!vw(t,l)){if(r==="retain"){u()}o[e]=t}}else if(!n.deleted){s.set(e,l);const i=o[e];if(i!==undefined){if(!vw(i,l)){if(r==="retain"){u()}if(l===null){delete o[e]}else{o[e]=l}}else if(i!==null){n.delete(t)}}}if(!n.deleted){if(r==="insert"){u()}xw(i,n.content)}break}}n=n.right}u();while(e.length>0){const t=e[e.length-1];if(t.retain!==undefined&&t.attributes===undefined){e.pop()}else{break}}}));this._delta=e}return this._delta}}class Fw extends Kd{constructor(t){super();this._pending=t!==undefined?[()=>this.insert(0,t)]:[];this._searchMarker=[];this._hasFormatting=false}get length(){this.doc??_d();return 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 Fw}clone(){const t=new Fw;t.applyDelta(this.toDelta());return t}_callObserver(t,e){super._callObserver(t,e);const i=new Pw(this,t,e);Vd(this,t,i);if(!t.local&&this._hasFormatting){t._needFormattingCleanup=true}}toString(){this.doc??_d();let t="";let e=this._start;while(e!==null){if(!e.deleted&&e.countable&&e.content.constructor===dp){t+=e.content.str}e=e.right}return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=true}={}){if(this.doc!==null){bd(this.doc,(i=>{const s=new Aw(null,this._start,0,new Map);for(let n=0;n<t.length;n++){const r=t[n];if(r.insert!==undefined){const o=!e&&typeof r.insert==="string"&&n===t.length-1&&s.right===null&&r.insert.slice(-1)==="\n"?r.insert.slice(0,-1):r.insert;if(typeof o!=="string"||o.length>0){Dw(i,this,s,o,r.attributes||{})}}else if(r.retain!==undefined){Tw(i,this,s,r.retain,r.attributes||{})}else if(r.delete!==undefined){Nw(i,s,r.delete)}}}))}else{this._pending.push((()=>this.applyDelta(t)))}}toDelta(t,e,i){this.doc??_d();const s=[];const n=new Map;const r=this.doc;let o="";let l=this._start;function h(){if(o.length>0){const t={};let e=false;n.forEach(((i,s)=>{e=true;t[s]=i}));const i={insert:o};if(e){i.attributes=t}s.push(i);o=""}}const f=()=>{while(l!==null){if(Ga(l,t)||e!==undefined&&Ga(l,e)){switch(l.content.constructor){case dp:{const s=n.get("ychange");if(t!==undefined&&!Ga(l,t)){if(s===undefined||s.user!==l.id.client||s.type!=="removed"){h();n.set("ychange",i?i("removed",l.id):{type:"removed"})}}else if(e!==undefined&&!Ga(l,e)){if(s===undefined||s.user!==l.id.client||s.type!=="added"){h();n.set("ychange",i?i("added",l.id):{type:"added"})}}else if(s!==undefined){h();n.delete("ychange")}o+=l.content.str;break}case kp:case np:{h();const t={insert:l.content.getContent()[0]};if(n.size>0){const e={};t.attributes=e;n.forEach(((t,i)=>{e[i]=t}))}s.push(t);break}case op:if(Ga(l,t)){h();xw(n,l.content)}break}}l=l.right}h()};if(t||e){bd(r,(i=>{if(t){Za(i,t)}if(e){Za(i,e)}f()}),"cleanup")}else{f()}return s}insert(t,e,i){if(e.length<=0){return}const s=this.doc;if(s!==null){bd(s,(s=>{const n=kw(s,this,t,!i);if(!i){i={};n.currentAttributes.forEach(((t,e)=>{i[e]=t}))}Dw(s,this,n,e,i)}))}else{this._pending.push((()=>this.insert(t,e,i)))}}insertEmbed(t,e,i){const s=this.doc;if(s!==null){bd(s,(s=>{const n=kw(s,this,t,!i);Dw(s,this,n,e,i||{})}))}else{this._pending.push((()=>this.insertEmbed(t,e,i||{})))}}delete(t,e){if(e===0){return}const i=this.doc;if(i!==null){bd(i,(i=>{Nw(i,kw(i,this,t,true),e)}))}else{this._pending.push((()=>this.delete(t,e)))}}format(t,e,i){if(e===0){return}const s=this.doc;if(s!==null){bd(s,(s=>{const n=kw(s,this,t,false);if(n.right===null){return}Tw(s,this,n,e,i)}))}else{this._pending.push((()=>this.format(t,e,i)))}}removeAttribute(t){if(this.doc!==null){bd(this.doc,(e=>{lw(e,this,t)}))}else{this._pending.push((()=>this.removeAttribute(t)))}}setAttribute(t,e){if(this.doc!==null){bd(this.doc,(i=>{hw(i,this,t,e)}))}else{this._pending.push((()=>this.setAttribute(t,e)))}}getAttribute(t){return fw(this,t)}getAttributes(){return uw(this)}_write(t){t.writeTypeRef(yp)}}const Bw=t=>new Fw;class jw{constructor(t,e=()=>true){this._filter=e;this._root=t;this._currentNode=t._start;this._firstCall=true;t.doc??_d()}[Symbol.iterator](){return this}next(){let t=this._currentNode;let e=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(e))){do{e=t.content.type;if(!t.deleted&&(e.constructor===Lw||e.constructor===_w)&&e._start!==null){t=e._start}else{while(t!==null){const e=t.next;if(e!==null){t=e;break}else if(t.parent===this._root){t=null}else{t=t.parent._item}}}}while(t!==null&&(t.deleted||!this._filter(t.content.type)))}this._firstCall=false;if(t===null){return{value:undefined,done:true}}this._currentNode=t;return{value:t.content.type,done:false}}}class _w extends Kd{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 _w}clone(){const t=new _w;t.insert(0,this.toArray().map((t=>t instanceof Kd?t.clone():t)));return t}get length(){this.doc??_d();return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new jw(this,t)}querySelector(t){t=t.toUpperCase();const e=new jw(this,(e=>e.nodeName&&e.nodeName.toUpperCase()===t));const i=e.next();if(i.done){return null}else{return i.value}}querySelectorAll(t){t=t.toUpperCase();return ef(new jw(this,(e=>e.nodeName&&e.nodeName.toUpperCase()===t)))}_callObserver(t,e){Vd(this,t,new Jw(this,e,t))}toString(){return Zd(this,(t=>t.toString())).join("")}toJSON(){return this.toString()}toDOM(t=document,e={},i){const s=t.createDocumentFragment();if(i!==undefined){i._createAssociation(s,this)}Gd(this,(n=>{s.insertBefore(n.toDOM(t,e,i),null)}));return s}insert(t,e){if(this.doc!==null){bd(this.doc,(i=>{nw(i,this,t,e)}))}else{this._prelimContent.splice(t,0,...e)}}insertAfter(t,e){if(this.doc!==null){bd(this.doc,(i=>{const s=t&&t instanceof Kd?t._item:t;iw(i,this,s,e)}))}else{const i=this._prelimContent;const s=t===null?0:i.findIndex((e=>e===t))+1;if(s===0&&t!==null){throw au("Reference item not found")}i.splice(s,0,...e)}}delete(t,e=1){if(this.doc!==null){bd(this.doc,(i=>{ow(i,this,t,e)}))}else{this._prelimContent.splice(t,e)}}toArray(){return Xd(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return ew(this,t)}slice(t=0,e=this.length){return Yd(this,t,e)}forEach(t){Gd(this,t)}_write(t){t.writeTypeRef(vp)}}const $w=t=>new _w;class Lw extends _w{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 Lw(this.nodeName)}clone(){const t=new Lw(this.nodeName);const e=this.getAttributes();Zu(e,((e,i)=>{if(typeof e==="string"){t.setAttribute(i,e)}}));t.insert(0,this.toArray().map((t=>t instanceof Kd?t.clone():t)));return t}toString(){const t=this.getAttributes();const e=[];const i=[];for(const e in t){i.push(e)}i.sort();const s=i.length;for(let n=0;n<s;n++){const s=i[n];e.push(s+'="'+t[s]+'"')}const n=this.nodeName.toLocaleLowerCase();const r=e.length>0?" "+e.join(" "):"";return`<${n}${r}>${super.toString()}</${n}>`}removeAttribute(t){if(this.doc!==null){bd(this.doc,(e=>{lw(e,this,t)}))}else{this._prelimAttrs.delete(t)}}setAttribute(t,e){if(this.doc!==null){bd(this.doc,(i=>{hw(i,this,t,e)}))}else{this._prelimAttrs.set(t,e)}}getAttribute(t){return fw(this,t)}hasAttribute(t){return cw(this,t)}getAttributes(t){return t?aw(this,t):uw(this)}toDOM(t=document,e={},i){const s=t.createElement(this.nodeName);const n=this.getAttributes();for(const t in n){const e=n[t];if(typeof e==="string"){s.setAttribute(t,e)}}Gd(this,(n=>{s.appendChild(n.toDOM(t,e,i))}));if(i!==undefined){i._createAssociation(s,this)}return s}_write(t){t.writeTypeRef(bp);t.writeKey(this.nodeName)}}const zw=t=>new Lw(t.readKey());class Jw extends Bd{constructor(t,e,i){super(t,i);this.childListChanged=false;this.attributesChanged=new Set;e.forEach((t=>{if(t===null){this.childListChanged=true}else{this.attributesChanged.add(t)}}))}}class Ww extends yw{constructor(t){super();this.hookName=t}_copy(){return new Ww(this.hookName)}clone(){const t=new Ww(this.hookName);this.forEach(((e,i)=>{t.set(i,e)}));return t}toDOM(t=document,e={},i){const s=e[this.hookName];let n;if(s!==undefined){n=s.createDom(this)}else{n=document.createElement(this.hookName)}n.setAttribute("data-yjs-hook",this.hookName);if(i!==undefined){i._createAssociation(n,this)}return n}_write(t){t.writeTypeRef(Ap);t.writeKey(this.hookName)}}const Qw=t=>new Ww(t.readKey());class Hw extends Fw{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 Hw}clone(){const t=new Hw;t.applyDelta(this.toDelta());return t}toDOM(t=document,e,i){const s=t.createTextNode(this.toString());if(i!==undefined){i._createAssociation(s,this)}return 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(Mp)}}const qw=t=>new Hw;class Vw{constructor(t,e){this.id=t;this.length=e}get deleted(){throw du()}mergeWith(t){return false}write(t,e,i){throw du()}integrate(t,e){throw du()}}const Kw=0;class Yw extends Vw{get deleted(){return true}delete(){}mergeWith(t){if(this.constructor!==t.constructor){return false}this.length+=t.length;return true}integrate(t,e){if(e>0){this.id.clock+=e;this.length-=e}sd(t.doc.store,this)}write(t,e){t.writeInfo(Kw);t.writeLen(this.length-e)}getMissing(t,e){return null}}class Xw{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return true}copy(){return new Xw(this.content)}splice(t){throw du()}mergeWith(t){return false}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeBuf(this.content)}getRef(){return 3}}const Gw=t=>new Xw(t.readBuf());class Zw{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return false}copy(){return new Zw(this.len)}splice(t){const e=new Zw(this.len-t);this.len=t;return e}mergeWith(t){this.len+=t.len;return true}integrate(t,e){fa(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 tp=t=>new Zw(t.readLen());const ep=(t,e)=>new ga({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||false});class ip{constructor(t){if(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;if(!t.gc){e.gc=false}if(t.autoLoad){e.autoLoad=true}if(t.meta!==null){e.meta=t.meta}}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return true}copy(){return new ip(ep(this.doc.guid,this.opts))}splice(t){throw du()}mergeWith(t){return false}integrate(t,e){this.doc._item=e;t.subdocsAdded.add(this.doc);if(this.doc.shouldLoad){t.subdocsLoaded.add(this.doc)}}delete(t){if(t.subdocsAdded.has(this.doc)){t.subdocsAdded.delete(this.doc)}else{t.subdocsRemoved.add(this.doc)}}gc(t){}write(t,e){t.writeString(this.doc.guid);t.writeAny(this.opts)}getRef(){return 9}}const sp=t=>new ip(ep(t.readString(),t.readAny()));class np{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return true}copy(){return new np(this.embed)}splice(t){throw du()}mergeWith(t){return false}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeJSON(this.embed)}getRef(){return 5}}const rp=t=>new np(t.readJSON());class op{constructor(t,e){this.key=t;this.value=e}getLength(){return 1}getContent(){return[]}isCountable(){return false}copy(){return new op(this.key,this.value)}splice(t){throw du()}mergeWith(t){return false}integrate(t,e){const i=e.parent;i._searchMarker=null;i._hasFormatting=true}delete(t){}gc(t){}write(t,e){t.writeKey(this.key);t.writeJSON(this.value)}getRef(){return 6}}const lp=t=>new op(t.readKey(),t.readJSON());class hp{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return true}copy(){return new hp(this.arr)}splice(t){const e=new hp(this.arr.slice(t));this.arr=this.arr.slice(0,t);return e}mergeWith(t){this.arr=this.arr.concat(t.arr);return true}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(e===undefined?"undefined":JSON.stringify(e))}}getRef(){return 2}}const fp=t=>{const e=t.readLen();const i=[];for(let s=0;s<e;s++){const e=t.readString();if(e==="undefined"){i.push(undefined)}else{i.push(JSON.parse(e))}}return new hp(i)};const up=bc("node_env")==="development";class cp{constructor(t){this.arr=t;up&&hc(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return true}copy(){return new cp(this.arr)}splice(t){const e=new cp(this.arr.slice(t));this.arr=this.arr.slice(0,t);return e}mergeWith(t){this.arr=this.arr.concat(t.arr);return true}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.writeAny(e)}}getRef(){return 8}}const ap=t=>{const e=t.readLen();const i=[];for(let s=0;s<e;s++){i.push(t.readAny())}return new cp(i)};class dp{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return true}copy(){return new dp(this.str)}splice(t){const e=new dp(this.str.slice(t));this.str=this.str.slice(0,t);const i=this.str.charCodeAt(t-1);if(i>=55296&&i<=56319){this.str=this.str.slice(0,t-1)+"�";e.str="�"+e.str.slice(1)}return e}mergeWith(t){this.str+=t.str;return true}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeString(e===0?this.str:this.str.slice(e))}getRef(){return 4}}const wp=t=>new dp(t.readString());const pp=[gw,bw,Bw,zw,$w,Qw,qw];const gp=0;const mp=1;const yp=2;const bp=3;const vp=4;const Ap=5;const Mp=6;class kp{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return true}copy(){return new kp(this.type._copy())}splice(t){throw du()}mergeWith(t){return false}integrate(t,e){this.type._integrate(t.doc,e)}delete(t){let e=this.type._start;while(e!==null){if(!e.deleted){e.delete(t)}else if(e.id.clock<(t.beforeState.get(e.id.client)||0)){t._mergeStructs.push(e)}e=e.right}this.type._map.forEach((e=>{if(!e.deleted){e.delete(t)}else if(e.id.clock<(t.beforeState.get(e.id.client)||0)){t._mergeStructs.push(e)}}));t.changed.delete(this.type)}gc(t){let e=this.type._start;while(e!==null){e.gc(t,true);e=e.right}this.type._start=null;this.type._map.forEach((e=>{while(e!==null){e.gc(t,true);e=e.left}}));this.type._map=new Map}write(t,e){this.type._write(t)}getRef(){return 7}}const Sp=t=>new kp(pp[t.readTypeRef()](t));const xp=(t,e)=>{let i=e;let s=0;let n;do{if(s>0){i=Ka(i.client,i.clock+s)}n=od(t,i);s=i.clock-n.id.clock;i=n.redone}while(i!==null&&n instanceof Cp);return{item:n,diff:s}};const Op=(t,e)=>{while(t!==null&&t.keep!==e){t.keep=e;t=t.parent._item}};const Ep=(t,e,i)=>{const{client:s,clock:n}=e.id;const r=new Cp(Ka(s,n+i),e,Ka(s,n+i-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(i));if(e.deleted){r.markDeleted()}if(e.keep){r.keep=true}if(e.redone!==null){r.redone=Ka(e.redone.client,e.redone.clock+i)}e.right=r;if(r.right!==null){r.right.left=r}t._mergeStructs.push(r);if(r.parentSub!==null&&r.right===null){r.parent._map.set(r.parentSub,r)}e.length=i;return r};const Dp=(t,e)=>sf(t,(t=>oa(t.deletions,e)));const Tp=(t,e,i,s,n,r)=>{const o=t.doc;const l=o.store;const h=o.clientID;const f=e.redone;if(f!==null){return hd(t,f)}let u=e.parent._item;let c=null;let a;if(u!==null&&u.deleted===true){if(u.redone===null&&(!i.has(u)||Tp(t,u,i,s,n,r)===null)){return null}while(u.redone!==null){u=hd(t,u.redone)}}const d=u===null?e.parent:u.content.type;if(e.parentSub===null){c=e.left;a=e;while(c!==null){let e=c;while(e!==null&&e.parent._item!==u){e=e.redone===null?null:hd(t,e.redone)}if(e!==null&&e.parent._item===u){c=e;break}c=c.left}while(a!==null){let e=a;while(e!==null&&e.parent._item!==u){e=e.redone===null?null:hd(t,e.redone)}if(e!==null&&e.parent._item===u){a=e;break}a=a.right}}else{a=null;if(e.right&&!n){c=e;while(c!==null&&c.right!==null&&(c.right.redone||oa(s,c.right.id)||Dp(r.undoStack,c.right.id)||Dp(r.redoStack,c.right.id))){c=c.right;while(c.redone)c=hd(t,c.redone)}if(c&&c.right!==null){return null}}else{c=d._map.get(e.parentSub)||null}}const w=id(l,h);const p=Ka(h,w);const g=new Cp(p,c,c&&c.lastId,a,a&&a.id,d,e.parentSub,e.content.copy());e.redone=p;Op(g,true);g.integrate(t,0);return g};class Cp extends Vw{constructor(t,e,i,s,n,r,o,l){super(t,l.getLength());this.origin=i;this.left=e;this.right=s;this.rightOrigin=n;this.parent=r;this.parentSub=o;this.redone=null;this.content=l;this.info=this.content.isCountable()?wf:0}set marker(t){if((this.info&gf)>0!==t){this.info^=gf}}get marker(){return(this.info&gf)>0}get keep(){return(this.info&df)>0}set keep(t){if(this.keep!==t){this.info^=df}}get countable(){return(this.info&wf)>0}get deleted(){return(this.info&pf)>0}set deleted(t){if(this.deleted!==t){this.info^=pf}}markDeleted(){this.info|=pf}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=id(e,this.origin.client)){return this.origin.client}if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=id(e,this.rightOrigin.client)){return this.rightOrigin.client}if(this.parent&&this.parent.constructor===qa&&this.id.client!==this.parent.client&&this.parent.clock>=id(e,this.parent.client)){return this.parent.client}if(this.origin){this.left=fd(t,e,this.origin);this.origin=this.left.lastId}if(this.rightOrigin){this.right=hd(t,this.rightOrigin);this.rightOrigin=this.right.id}if(this.left&&this.left.constructor===Yw||this.right&&this.right.constructor===Yw){this.parent=null}else if(!this.parent){if(this.left&&this.left.constructor===Cp){this.parent=this.left.parent;this.parentSub=this.left.parentSub}else if(this.right&&this.right.constructor===Cp){this.parent=this.right.parent;this.parentSub=this.right.parentSub}}else if(this.parent.constructor===qa){const t=od(e,this.parent);if(t.constructor===Yw){this.parent=null}else{this.parent=t.content.type}}return null}integrate(t,e){if(e>0){this.id.clock+=e;this.left=fd(t,t.doc.store,Ka(this.id.client,this.id.clock-1));this.origin=this.left.lastId;this.content=this.content.splice(e);this.length-=e}if(this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let e=this.left;let i;if(e!==null){i=e.right}else if(this.parentSub!==null){i=this.parent._map.get(this.parentSub)||null;while(i!==null&&i.left!==null){i=i.left}}else{i=this.parent._start}const s=new Set;const n=new Set;while(i!==null&&i!==this.right){n.add(i);s.add(i);if(Va(this.origin,i.origin)){if(i.id.client<this.id.client){e=i;s.clear()}else if(Va(this.rightOrigin,i.rightOrigin)){break}}else if(i.origin!==null&&n.has(od(t.doc.store,i.origin))){if(!s.has(od(t.doc.store,i.origin))){e=i;s.clear()}}else{break}i=i.right}this.left=e}if(this.left!==null){const t=this.left.right;this.right=t;this.left.right=this}else{let t;if(this.parentSub!==null){t=this.parent._map.get(this.parentSub)||null;while(t!==null&&t.left!==null){t=t.left}}else{t=this.parent._start;this.parent._start=this}this.right=t}if(this.right!==null){this.right.left=this}else if(this.parentSub!==null){this.parent._map.set(this.parentSub,this);if(this.left!==null){this.left.delete(t)}}if(this.parentSub===null&&this.countable&&!this.deleted){this.parent._length+=this.length}sd(t.doc.store,this);this.content.integrate(t,this);wd(t,this.parent,this.parentSub);if(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null){this.delete(t)}}else{new Yw(this.id,this.length).integrate(t,0)}}get next(){let t=this.right;while(t!==null&&t.deleted){t=t.right}return t}get prev(){let t=this.left;while(t!==null&&t.deleted){t=t.left}return t}get lastId(){return this.length===1?this.id:Ka(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Va(t.origin,this.lastId)&&this.right===t&&Va(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const e=this.parent._searchMarker;if(e){e.forEach((e=>{if(e.p===t){e.p=this;if(!this.deleted&&this.countable){e.index-=this.length}}}))}if(t.keep){this.keep=true}this.right=t.right;if(this.right!==null){this.right.left=this}this.length+=t.length;return true}return false}delete(t){if(!this.deleted){const e=this.parent;if(this.countable&&this.parentSub===null){e._length-=this.length}this.markDeleted();fa(t.deleteSet,this.id.client,this.id.clock,this.length);wd(t,e,this.parentSub);this.content.delete(t)}}gc(t,e){if(!this.deleted){throw wu()}this.content.gc(t);if(e){ud(t,this,new Yw(this.id,this.length))}else{this.content=new Zw(this.length)}}write(t,e){const i=e>0?Ka(this.id.client,this.id.clock+e-1):this.origin;const s=this.rightOrigin;const n=this.parentSub;const r=this.content.getRef()&vf|(i===null?0:bf)|(s===null?0:yf)|(n===null?0:mf);t.writeInfo(r);if(i!==null){t.writeLeftID(i)}if(s!==null){t.writeRightID(s)}if(i===null&&s===null){const e=this.parent;if(e._item!==undefined){const i=e._item;if(i===null){const i=Ya(e);t.writeParentInfo(true);t.writeString(i)}else{t.writeParentInfo(false);t.writeLeftID(i.id)}}else if(e.constructor===String){t.writeParentInfo(true);t.writeString(e)}else if(e.constructor===qa){t.writeParentInfo(false);t.writeLeftID(e)}else{wu()}if(n!==null){t.writeString(n)}}this.content.write(t,e)}}const Rp=(t,e)=>Up[e&vf](t);const Up=[()=>{wu()},tp,fp,Gw,wp,rp,lp,Sp,ap,sp,()=>{wu()}];const Ip=10;class Np extends Vw{get deleted(){return true}delete(){}mergeWith(t){if(this.constructor!==t.constructor){return false}this.length+=t.length;return true}integrate(t,e){wu()}write(t,e){t.writeInfo(Ip);Wf(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const Pp=typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:typeof global!=="undefined"?global:{};const Fp="__ $YJS$ __";if(Pp[Fp]===true){console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438")}Pp[Fp]=true;class Bp{doc;channel;_synced=false;constructor(t,e,i){this.doc=e;this.channel=new BroadcastChannel(t);this.channel.onmessage=t=>{this.handleMessage(t.data)};this.doc.on("update",this.handleDocUpdate);this.broadcastSync();setTimeout((()=>{this._synced=true}),100);console.info(`BroadcastChannel Provider initialized: ${t}`)}handleDocUpdate=(t,e)=>{if(e!==this){const e=jf();Wf(e,0);Gf(e,t);this.channel.postMessage($f(e))}};handleMessage(t){const e=yu(new Uint8Array(t));const i=ku(e);switch(i){case 0:const t=Au(e);Ua(this.doc,t,this);break;case 1:this.broadcastSync();break;case 2:const i=Au(e);const s=Pa(this.doc,i);if(s.length>0){const t=jf();Wf(t,0);Gf(t,s);this.channel.postMessage($f(t))}break}}broadcastSync(){const t=jf();Wf(t,2);Gf(t,La(this.doc));this.channel.postMessage($f(t))}async connect(){if(this._synced){return}return new Promise((t=>{const e=()=>{if(this._synced){t()}else{setTimeout(e,50)}};e()}))}disconnect(){}destroy(){this.doc.off("update",this.handleDocUpdate);this.channel.close()}}const jp=t=>Ju(((e,i)=>{t.onerror=t=>i(new Error(t.target.error));t.onsuccess=t=>e(t.target.result)}));const _p=(t,e)=>Ju(((i,s)=>{const n=indexedDB.open(t);n.onupgradeneeded=t=>e(t.target.result);n.onerror=t=>s(au(t.target.error));n.onsuccess=t=>{const e=t.target.result;e.onversionchange=()=>{e.close()};i(e)}}));const $p=t=>jp(indexedDB.deleteDatabase(t));const Lp=(t,e)=>e.forEach((e=>t.createObjectStore.apply(t,e)));const zp=(t,e,i="readwrite")=>{const s=t.transaction(e,i);return e.map((t=>Zp(s,t)))};const Jp=(t,e)=>jp(t.count(e));const Wp=(t,e)=>jp(t.get(e));const Qp=(t,e)=>jp(t.delete(e));const Hp=(t,e,i)=>jp(t.put(e,i));const qp=(t,e)=>jp(t.add(e));const Vp=(t,e,i)=>jp(t.getAll(e,i));const Kp=(t,e,i)=>{let s=null;return Gp(t,e,(t=>{s=t;return false}),i).then((()=>s))};const Yp=(t,e=null)=>Kp(t,e,"prev");const Xp=(t,e)=>Ju(((i,s)=>{t.onerror=s;t.onsuccess=async t=>{const s=t.target.result;if(s===null||await e(s)===false){return i()}s.continue()}}));const Gp=(t,e,i,s="next")=>Xp(t.openKeyCursor(e,s),(t=>i(t.key)));const Zp=(t,e)=>t.objectStore(e);const tg=(t,e)=>IDBKeyRange.upperBound(t,e);const eg=(t,e)=>IDBKeyRange.lowerBound(t,e);const ig="custom";const sg="updates";const ng=500;const rg=(t,e=()=>{},i=()=>{})=>{const[s]=zp(t.db,[sg]);return Vp(s,eg(t._dbref,false)).then((n=>{if(!t._destroyed){e(s);bd(t.doc,(()=>{n.forEach((e=>Ua(t.doc,e)))}),t,false);i(s)}})).then((()=>Yp(s).then((e=>{t._dbref=e+1})))).then((()=>Jp(s).then((e=>{t._dbsize=e})))).then((()=>s))};const og=(t,e=true)=>rg(t).then((i=>{if(e||t._dbsize>=ng){qp(i,Pa(t.doc)).then((()=>Qp(i,tg(t._dbref,true)))).then((()=>Jp(i).then((e=>{t._dbsize=e}))))}}));class lg extends of{constructor(t,e){super();this.doc=e;this.name=t;this._dbref=0;this._dbsize=0;this._destroyed=false;this.db=null;this.synced=false;this._db=_p(t,(t=>Lp(t,[["updates",{autoIncrement:true}],["custom"]])));this.whenSynced=Ju((t=>this.on("synced",(()=>t(this)))));this._db.then((t=>{this.db=t;const i=t=>qp(t,Pa(e));const s=()=>{if(this._destroyed)return this;this.synced=true;this.emit("synced",[this])};rg(this,i,s)}));this._storeTimeout=1e3;this._storeTimeoutId=null;this._storeUpdate=(t,e)=>{if(this.db&&e!==this){const[e]=zp(this.db,[sg]);qp(e,t);if(++this._dbsize>=ng){if(this._storeTimeoutId!==null){clearTimeout(this._storeTimeoutId)}this._storeTimeoutId=setTimeout((()=>{og(this,false);this._storeTimeoutId=null}),this._storeTimeout)}}};e.on("update",this._storeUpdate);this.destroy=this.destroy.bind(this);e.on("destroy",this.destroy)}destroy(){if(this._storeTimeoutId){clearTimeout(this._storeTimeoutId)}this.doc.off("update",this._storeUpdate);this.doc.off("destroy",this.destroy);this._destroyed=true;return this._db.then((t=>{t.close()}))}clearData(){return this.destroy().then((()=>{$p(this.name)}))}get(t){return this._db.then((e=>{const[i]=zp(e,[ig],"readonly");return Wp(i,t)}))}set(t,e){return this._db.then((i=>{const[s]=zp(i,[ig]);return Hp(s,e,t)}))}del(t){return this._db.then((e=>{const[i]=zp(e,[ig]);return Qp(i,t)}))}}class hg{provider;isConnected=false;constructor(t,e,i){const s=i?.name||t;this.provider=new lg(s,e);console.info(`IndexedDB Persistence initialized: ${s}`)}async connect(){if(this.isConnected){return}return new Promise((t=>{this.provider.on("synced",(()=>{this.isConnected=true;t()}))}))}disconnect(){this.isConnected=false}destroy(){if(this.provider){this.provider.destroy()}this.isConnected=false}}const fg=Math.floor;const ug=(t,e)=>t<e?t:e;const cg=(t,e)=>t>e?t:e;const ag=128;const dg=127;const wg=Number.MAX_SAFE_INTEGER;const pg=t=>{const e=unescape(encodeURIComponent(t));const i=e.length;const s=new Uint8Array(i);for(let t=0;t<i;t++){s[t]=e.codePointAt(t)}return s};const gg=typeof TextEncoder!=="undefined"?new TextEncoder:null;const mg=t=>gg.encode(t);const yg=gg?mg:pg;let bg=typeof TextDecoder==="undefined"?null:new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});if(bg&&bg.decode(new Uint8Array).length===1){bg=null}const vg=(t,e)=>{const i=t.cbuf.length;if(t.cpos===i){t.bufs.push(t.cbuf);t.cbuf=new Uint8Array(i*2);t.cpos=0}t.cbuf[t.cpos++]=e};const Ag=(t,e)=>{while(e>dg){vg(t,ag|dg&e);e=fg(e/128)}vg(t,dg&e)};const Mg=new Uint8Array(3e4);const kg=Mg.length/3;const Sg=(t,e)=>{if(e.length<kg){const i=gg.encodeInto(e,Mg).written||0;Ag(t,i);for(let e=0;e<i;e++){vg(t,Mg[e])}}else{Dg(t,yg(e))}};const xg=(t,e)=>{const i=unescape(encodeURIComponent(e));const s=i.length;Ag(t,s);for(let e=0;e<s;e++){vg(t,i.codePointAt(e))}};const Og=gg&&gg.encodeInto?Sg:xg;const Eg=(t,e)=>{const i=t.cbuf.length;const s=t.cpos;const n=ug(i-s,e.length);const r=e.length-n;t.cbuf.set(e.subarray(0,n),s);t.cpos+=n;if(r>0){t.bufs.push(t.cbuf);t.cbuf=new Uint8Array(cg(i*2,r));t.cbuf.set(e.subarray(n));t.cpos=r}};const Dg=(t,e)=>{Ag(t,e.byteLength);Eg(t,e)};const Tg=t=>new Error(t);const Cg=Tg("Unexpected end of array");const Rg=Tg("Integer out of Range");const Ug=(t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);t.pos+=e;return i};const Ig=t=>Ug(t,Pg(t));const Ng=t=>t.arr[t.pos++];const Pg=t=>{let e=0;let i=1;const s=t.arr.length;while(t.pos<s){const s=t.arr[t.pos++];e=e+(s&dg)*i;i*=128;if(s<ag){return e}if(e>wg){throw Rg}}throw Cg};const Fg=t=>{let e=Pg(t);if(e===0){return""}else{let i=String.fromCodePoint(Ng(t));if(--e<100){while(e--){i+=String.fromCodePoint(Ng(t))}}else{while(e>0){const s=e<1e4?e:1e4;const n=t.arr.subarray(t.pos,t.pos+s);t.pos+=s;i+=String.fromCodePoint.apply(null,n);e-=s}}return decodeURIComponent(escape(i))}};const Bg=t=>bg.decode(Ig(t));const jg=bg?Bg:Fg;var _g;(function(t){t[t["Token"]=0]="Token";t[t["PermissionDenied"]=1]="PermissionDenied";t[t["Authenticated"]=2]="Authenticated"})(_g||(_g={}));const $g=(t,e)=>{Ag(t,_g.Token);Og(t,e)};const Lg=(t,e,i,s)=>{switch(Pg(t)){case _g.Token:{e();break}case _g.PermissionDenied:{i(jg(t));break}case _g.Authenticated:{s(jg(t));break}}};const zg=t=>Array.from(t.entries()).map((([t,e])=>({clientId:t,...e})));var Jg;(function(t){t[t["Connecting"]=0]="Connecting";t[t["Open"]=1]="Open";t[t["Closing"]=2]="Closing";t[t["Closed"]=3]="Closed"})(Jg||(Jg={}));function Wg(t){if(!t){t={}}return{delay:t.delay===undefined?200:t.delay,initialDelay:t.initialDelay===undefined?0:t.initialDelay,minDelay:t.minDelay===undefined?0:t.minDelay,maxDelay:t.maxDelay===undefined?0:t.maxDelay,factor:t.factor===undefined?0:t.factor,maxAttempts:t.maxAttempts===undefined?3:t.maxAttempts,timeout:t.timeout===undefined?0:t.timeout,jitter:t.jitter===true,initialJitter:t.initialJitter===true,handleError:t.handleError===undefined?null:t.handleError,handleTimeout:t.handleTimeout===undefined?null:t.handleTimeout,beforeAttempt:t.beforeAttempt===undefined?null:t.beforeAttempt,calculateDelay:t.calculateDelay===undefined?null:t.calculateDelay}}async function Qg(t){return new Promise((e=>setTimeout(e,t)))}function Hg(t,e){let i=e.delay;if(i===0){return 0}if(e.factor){i*=Math.pow(e.factor,t.attemptNum-1);if(e.maxDelay!==0){i=Math.min(i,e.maxDelay)}}if(e.jitter){const t=Math.ceil(e.minDelay);const s=Math.floor(i);i=Math.floor(Math.random()*(s-t+1))+t}return Math.round(i)}async function qg(t,e){const i=Wg(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:false,abort(){s.aborted=true}};const n=i.calculateDelay||Hg;async function r(){if(i.beforeAttempt){i.beforeAttempt(s,i)}if(s.aborted){const t=new Error(`Attempt aborted`);t.code="ATTEMPT_ABORTED";throw t}const e=async t=>{if(i.handleError){await i.handleError(t,s,i)}if(s.aborted||s.attemptsRemaining===0){throw t}s.attemptNum++;const e=n(s,i);if(e){await Qg(e)}return r()};if(s.attemptsRemaining>0){s.attemptsRemaining--}if(i.timeout){return new Promise(((n,r)=>{const o=setTimeout((()=>{if(i.handleTimeout){try{n(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);n(t)})).catch((t=>{clearTimeout(o);e(t).then(n).catch(r)}))}))}else{return t(s,i).catch(e)}}const o=i.calculateDelay?i.calculateDelay(s,i):i.initialDelay;if(o){await Qg(o)}if(s.attemptNum<1&&i.initialJitter){const t=n(s,i);if(t){await Qg(t)}}return r()}const Vg=Math.floor;const Kg=(t,e)=>t<e?t:e;const Yg=(t,e)=>t>e?t:e;const Xg=64;const Gg=128;const Zg=63;const tm=127;const em=Number.MAX_SAFE_INTEGER;const im=()=>new Set;const sm=Array.from;const nm=t=>{const e=unescape(encodeURIComponent(t));const i=e.length;const s=new Uint8Array(i);for(let t=0;t<i;t++){s[t]=e.codePointAt(t)}return s};const rm=typeof TextEncoder!=="undefined"?new TextEncoder:null;const om=t=>rm.encode(t);const lm=rm?om:nm;let hm=typeof TextDecoder==="undefined"?null:new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});if(hm&&hm.decode(new Uint8Array).length===1){hm=null}class fm{constructor(){this.cpos=0;this.cbuf=new Uint8Array(100);this.bufs=[]}}const um=()=>new fm;const cm=t=>{let e=t.cpos;for(let i=0;i<t.bufs.length;i++){e+=t.bufs[i].length}return e};const am=t=>{const e=new Uint8Array(cm(t));let i=0;for(let s=0;s<t.bufs.length;s++){const n=t.bufs[s];e.set(n,i);i+=n.length}e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),i);return e};const dm=(t,e)=>{const i=t.cbuf.length;if(t.cpos===i){t.bufs.push(t.cbuf);t.cbuf=new Uint8Array(i*2);t.cpos=0}t.cbuf[t.cpos++]=e};const wm=(t,e)=>{while(e>tm){dm(t,Gg|tm&e);e=Vg(e/128)}dm(t,tm&e)};const pm=new Uint8Array(3e4);const gm=pm.length/3;const mm=(t,e)=>{if(e.length<gm){const i=rm.encodeInto(e,pm).written||0;wm(t,i);for(let e=0;e<i;e++){dm(t,pm[e])}}else{Am(t,lm(e))}};const ym=(t,e)=>{const i=unescape(encodeURIComponent(e));const s=i.length;wm(t,s);for(let e=0;e<s;e++){dm(t,i.codePointAt(e))}};const bm=rm&&rm.encodeInto?mm:ym;const vm=(t,e)=>{const i=t.cbuf.length;const s=t.cpos;const n=Kg(i-s,e.length);const r=e.length-n;t.cbuf.set(e.subarray(0,n),s);t.cpos+=n;if(r>0){t.bufs.push(t.cbuf);t.cbuf=new Uint8Array(Yg(i*2,r));t.cbuf.set(e.subarray(n));t.cpos=r}};const Am=(t,e)=>{wm(t,e.byteLength);vm(t,e)};const Mm=t=>new Error(t);const km=Mm("Unexpected end of array");const Sm=Mm("Integer out of Range");class xm{constructor(t){this.arr=t;this.pos=0}}const Om=t=>new xm(t);const Em=(t,e)=>{const i=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);t.pos+=e;return i};const Dm=t=>Em(t,Cm(t));const Tm=t=>t.arr[t.pos++];const Cm=t=>{let e=0;let i=1;const s=t.arr.length;while(t.pos<s){const s=t.arr[t.pos++];e=e+(s&tm)*i;i*=128;if(s<Gg){return e}if(e>em){throw Sm}}throw km};const Rm=t=>{let e=t.arr[t.pos++];let i=e&Zg;let s=64;const n=(e&Xg)>0?-1:1;if((e&Gg)===0){return n*i}const r=t.arr.length;while(t.pos<r){e=t.arr[t.pos++];i=i+(e&tm)*s;s*=128;if(e<Gg){return n*i}if(i>em){throw Sm}}throw km};const Um=t=>{let e=Cm(t);if(e===0){return""}else{let i=String.fromCodePoint(Tm(t));if(--e<100){while(e--){i+=String.fromCodePoint(Tm(t))}}else{while(e>0){const s=e<1e4?e:1e4;const n=t.arr.subarray(t.pos,t.pos+s);t.pos+=s;i+=String.fromCodePoint.apply(null,n);e-=s}}return decodeURIComponent(escape(i))}};const Im=t=>hm.decode(Dm(t));const Nm=hm?Im:Um;const Pm=t=>{const e=t.pos;const i=Nm(t);t.pos=e;return i};const Fm=Date.now;const Bm=()=>new Map;const jm=(t,e,i)=>{let s=t.get(e);if(s===undefined){t.set(e,s=i())}return s};class _m{constructor(){this._observers=Bm()}on(t,e){jm(this._observers,t,im).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);if(i!==undefined){i.delete(e);if(i.size===0){this._observers.delete(t)}}}emit(t,e){return sm((this._observers.get(t)||Bm()).values()).forEach((t=>t(...e)))}destroy(){this._observers=Bm()}}const $m=Object.keys;const Lm=t=>$m(t).length;const zm=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const Jm=(t,e)=>t===e;const Wm=(t,e)=>{if(t==null||e==null){return Jm(t,e)}if(t.constructor!==e.constructor){return false}if(t===e){return true}switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t);e=new Uint8Array(e);case Uint8Array:{if(t.byteLength!==e.byteLength){return false}for(let i=0;i<t.length;i++){if(t[i]!==e[i]){return false}}break}case Set:{if(t.size!==e.size){return false}for(const i of t){if(!e.has(i)){return false}}break}case Map:{if(t.size!==e.size){return false}for(const i of t.keys()){if(!e.has(i)||!Wm(t.get(i),e.get(i))){return false}}break}case Object:if(Lm(t)!==Lm(e)){return false}for(const i in t){if(!zm(t,i)||!Wm(t[i],e[i])){return false}}break;case Array:if(t.length!==e.length){return false}for(let i=0;i<t.length;i++){if(!Wm(t[i],e[i])){return false}}break;default:return false}return true};const Qm=3e4;class Hm extends _m{constructor(t){super();this.doc=t;this.clientID=t.clientID;this.states=new Map;this.meta=new Map;this._checkInterval=setInterval((()=>{const t=Fm();if(this.getLocalState()!==null&&Qm/2<=t-this.meta.get(this.clientID).lastUpdated){this.setLocalState(this.getLocalState())}const e=[];this.meta.forEach(((i,s)=>{if(s!==this.clientID&&Qm<=t-i.lastUpdated&&this.states.has(s)){e.push(s)}}));if(e.length>0){qm(this,e,"timeout")}}),Vg(Qm/10));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;const i=this.meta.get(e);const s=i===undefined?0:i.clock+1;const n=this.states.get(e);if(t===null){this.states.delete(e)}else{this.states.set(e,t)}this.meta.set(e,{clock:s,lastUpdated:Fm()});const r=[];const o=[];const l=[];const h=[];if(t===null){h.push(e)}else if(n==null){if(t!=null){r.push(e)}}else{o.push(e);if(!Wm(n,t)){l.push(e)}}if(r.length>0||l.length>0||h.length>0){this.emit("change",[{added:r,updated:l,removed:h},"local"])}this.emit("update",[{added:r,updated:o,removed:h},"local"])}setLocalStateField(t,e){const i=this.getLocalState();if(i!==null){this.setLocalState({...i,[t]:e})}}getStates(){return this.states}}const qm=(t,e,i)=>{const s=[];for(let i=0;i<e.length;i++){const n=e[i];if(t.states.has(n)){t.states.delete(n);if(n===t.clientID){const e=t.meta.get(n);t.meta.set(n,{clock:e.clock+1,lastUpdated:Fm()})}s.push(n)}}if(s.length>0){t.emit("change",[{added:[],updated:[],removed:s},i]);t.emit("update",[{added:[],updated:[],removed:s},i])}};const Vm=(t,e,i=t.states)=>{const s=e.length;const n=um();wm(n,s);for(let r=0;r<s;r++){const s=e[r];const o=i.get(s)||null;const l=t.meta.get(s).clock;wm(n,s);wm(n,l);bm(n,JSON.stringify(o))}return am(n)};const Km=(t,e,i)=>{const s=Om(e);const n=Fm();const r=[];const o=[];const l=[];const h=[];const f=Cm(s);for(let e=0;e<f;e++){const e=Cm(s);let i=Cm(s);const f=JSON.parse(Nm(s));const u=t.meta.get(e);const c=t.states.get(e);const a=u===undefined?0:u.clock;if(a<i||a===i&&f===null&&t.states.has(e)){if(f===null){if(e===t.clientID&&t.getLocalState()!=null){i++}else{t.states.delete(e)}}else{t.states.set(e,f)}t.meta.set(e,{clock:i,lastUpdated:n});if(u===undefined&&f!==null){r.push(e)}else if(u!==undefined&&f===null){h.push(e)}else if(f!==null){if(!Wm(f,c)){l.push(e)}o.push(e)}}}if(r.length>0||l.length>0||h.length>0){t.emit("change",[{added:r,updated:l,removed:h},i])}if(r.length>0||o.length>0||h.length>0){t.emit("update",[{added:r,updated:o,removed:h},i])}};class Ym{constructor(){this.callbacks={}}on(t,e){if(!this.callbacks[t]){this.callbacks[t]=[]}this.callbacks[t].push(e);return this}emit(t,...e){const i=this.callbacks[t];if(i){i.forEach((t=>t.apply(this,e)))}return this}off(t,e){const i=this.callbacks[t];if(i){if(e){this.callbacks[t]=i.filter((t=>t!==e))}else{delete this.callbacks[t]}}return this}removeAllListeners(){this.callbacks={}}}class Xm{constructor(t){this.data=t;this.encoder=um();this.decoder=Om(new Uint8Array(this.data))}peekVarString(){return Pm(this.decoder)}readVarUint(){return Cm(this.decoder)}readVarString(){return Nm(this.decoder)}readVarUint8Array(){return Dm(this.decoder)}writeVarUint(t){return wm(this.encoder,t)}writeVarString(t){return bm(this.encoder,t)}writeVarUint8Array(t){return Am(this.encoder,t)}length(){return cm(this.encoder)}}var Gm;(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"})(Gm||(Gm={}));var Zm;(function(t){t["Connecting"]="connecting";t["Connected"]="connected";t["Disconnected"]="disconnected"})(Zm||(Zm={}));class ty{constructor(){this.encoder=um()}get(t){return t.encoder}toUint8Array(){return am(this.encoder)}}class ey extends ty{constructor(){super(...arguments);this.type=Gm.CLOSE;this.description="Ask the server to close the connection"}get(t){bm(this.encoder,t.documentName);wm(this.encoder,this.type);return this.encoder}}class iy extends Ym{constructor(t){super();this.messageQueue=[];this.configuration={url:"",autoConnect:true,document:undefined,WebSocketPolyfill:undefined,messageReconnectTimeout:3e4,delay:1e3,initialDelay:0,factor:2,maxAttempts:0,minDelay:1e3,maxDelay:3e4,jitter:true,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=true;this.status=Zm.Disconnected;this.lastMessageReceived=0;this.identifier=0;this.intervals={connectionChecker:null};this.connectionAttempt=null;this.receivedOnOpenPayload=undefined;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);if(this.shouldConnect){this.connect()}}async onOpen(t){this.status=Zm.Connected;this.emit("status",{status:Zm.Connected});this.cancelWebsocketRetry=undefined;this.receivedOnOpenPayload=t}attach(t){this.configuration.providerMap.set(t.configuration.name,t);if(this.status===Zm.Disconnected&&this.shouldConnect){this.connect()}if(this.receivedOnOpenPayload&&this.status===Zm.Connected){t.onOpen(this.receivedOnOpenPayload)}}detach(t){if(this.configuration.providerMap.has(t.configuration.name)){t.send(ey,{documentName:t.configuration.name});this.configuration.providerMap.delete(t.configuration.name)}}setConfiguration(t={}){this.configuration={...this.configuration,...t};if(!this.configuration.autoConnect){this.shouldConnect=false}}async connect(){if(this.status===Zm.Connected){return}if(this.cancelWebsocketRetry){this.cancelWebsocketRetry();this.cancelWebsocketRetry=undefined}this.receivedOnOpenPayload=undefined;this.shouldConnect=true;const t=()=>{let t=false;const e=qg(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=>{if(!this.shouldConnect||t){e.abort()}}}).catch((t=>{if(t&&t.code!=="ATTEMPT_ABORTED"){throw t}}));return{retryPromise:e,cancelFunc:()=>{t=true}}};const{retryPromise:e,cancelFunc:i}=t();this.cancelWebsocketRetry=i;return e}attachWebSocketListeners(t,e){const{identifier:i}=t;const s=t=>this.emit("message",t);const n=t=>this.emit("close",{event:t});const r=t=>this.emit("open",t);const o=t=>{e(t)};this.webSocketHandlers[i]={message:s,close:n,open:r,error:o};const l=this.webSocketHandlers[t.identifier];Object.keys(l).forEach((e=>{t.addEventListener(e,l[e])}))}cleanupWebSocket(){if(!this.webSocket){return}const{identifier:t}=this.webSocket;const e=this.webSocketHandlers[t];Object.keys(e).forEach((i=>{var s;(s=this.webSocket)===null||s===void 0?void 0:s.removeEventListener(i,e[i]);delete this.webSocketHandlers[t]}));this.webSocket.close();this.webSocket=null}createWebSocketConnection(){return new Promise(((t,e)=>{if(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=Zm.Connecting;this.emit("status",{status:Zm.Connecting});this.connectionAttempt={resolve:t,reject:e}}))}onMessage(t){var e;this.resolveConnectionAttempt();this.lastMessageReceived=Fm();const i=new Xm(t.data);const s=i.peekVarString();(e=this.configuration.providerMap.get(s))===null||e===void 0?void 0:e.onMessage(t)}resolveConnectionAttempt(){if(this.connectionAttempt){this.connectionAttempt.resolve();this.connectionAttempt=null;this.status=Zm.Connected;this.emit("status",{status:Zm.Connected});this.emit("connect");this.messageQueue.forEach((t=>this.send(t)));this.messageQueue=[]}}stopConnectionAttempt(){this.connectionAttempt=null}rejectConnectionAttempt(){var t;(t=this.connectionAttempt)===null||t===void 0?void 0:t.reject();this.connectionAttempt=null}checkConnection(){var t;if(this.status!==Zm.Connected){return}if(!this.lastMessageReceived){return}if(this.configuration.messageReconnectTimeout>=Fm()-this.lastMessageReceived){return}this.closeTries+=1;if(this.closeTries>2){this.onClose({event:{code:4408,reason:"forced"}});this.closeTries=0}else{(t=this.webSocket)===null||t===void 0?void 0:t.close();this.messageQueue=[]}}get serverUrl(){while(this.configuration.url[this.configuration.url.length-1]==="/"){return this.configuration.url.slice(0,this.configuration.url.length-1)}return this.configuration.url}get url(){return this.serverUrl}disconnect(){this.shouldConnect=false;if(this.webSocket===null){return}try{this.webSocket.close();this.messageQueue=[]}catch(t){console.error(t)}}send(t){var e;if(((e=this.webSocket)===null||e===void 0?void 0:e.readyState)===Jg.Open){this.webSocket.send(t)}else{this.messageQueue.push(t)}}onClose({event:t}){this.closeTries=0;this.cleanupWebSocket();if(this.connectionAttempt){this.rejectConnectionAttempt()}this.status=Zm.Disconnected;this.emit("status",{status:Zm.Disconnected});this.emit("disconnect",{event:t});if(!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 sy=0;const ny=1;const ry=2;const oy=(t,e)=>{wm(t,sy);const i=La(e);Am(t,i)};const ly=(t,e,i)=>{wm(t,ny);Am(t,Pa(e,i))};const hy=(t,e,i)=>ly(e,i,Dm(t));const fy=(t,e,i)=>{try{Ua(e,Dm(t),i)}catch(t){console.error("Caught error while handling a Yjs update",t)}};const uy=(t,e)=>{wm(t,ry);Am(t,e)};const cy=fy;const ay=(t,e,i,s)=>{const n=Cm(t);switch(n){case sy:hy(t,e,i);break;case ny:fy(t,i,s);break;case ry:cy(t,i,s);break;default:throw new Error("Unknown message type")}return n};class dy{constructor(t){this.message=t}apply(t,e){const{message:i}=this;const s=i.readVarUint();const n=i.length();switch(s){case Gm.Sync:this.applySyncMessage(t,e);break;case Gm.Awareness:this.applyAwarenessMessage(t);break;case Gm.Auth:this.applyAuthMessage(t);break;case Gm.QueryAwareness:this.applyQueryAwarenessMessage(t);break;case Gm.Stateless:t.receiveStateless(Nm(i.decoder));break;case Gm.SyncStatus:this.applySyncStatusMessage(t,Rm(i.decoder)===1);break;case Gm.CLOSE:const n={code:1e3,reason:Nm(i.decoder),target:t.configuration.websocketProvider.webSocket,type:"close"};t.onClose();t.configuration.onClose({event:n});t.forwardClose(n);break;default:throw new Error(`Can’t apply message of unknown type: ${s}`)}if(i.length()>n+1){t.send(ty,{encoder:i.encoder})}}applySyncMessage(t,e){const{message:i}=this;i.writeVarUint(Gm.Sync);const s=ay(i.decoder,i.encoder,t.document,t);if(e&&s===ny){t.synced=true}}applySyncStatusMessage(t,e){if(e){t.decrementUnsyncedChanges()}}applyAwarenessMessage(t){if(!t.awareness)return;const{message:e}=this;Km(t.awareness,e.readVarUint8Array(),t)}applyAuthMessage(t){const{message:e}=this;Lg(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(Gm.Awareness);e.writeVarUint8Array(Vm(t.awareness,Array.from(t.awareness.getStates().keys())))}}class wy{constructor(t,e={}){this.message=new t;this.encoder=this.message.get(e)}create(){return am(this.encoder)}send(t){t===null||t===void 0?void 0:t.send(this.create())}}class py extends ty{constructor(){super(...arguments);this.type=Gm.Auth;this.description="Authentication"}get(t){if(typeof t.token==="undefined"){throw new Error("The authentication message requires `token` as an argument.")}bm(this.encoder,t.documentName);wm(this.encoder,this.type);$g(this.encoder,t.token);return this.encoder}}class gy extends ty{constructor(){super(...arguments);this.type=Gm.Awareness;this.description="Awareness states update"}get(t){if(typeof t.awareness==="undefined"){throw new Error("The awareness message requires awareness as an argument")}if(typeof t.clients==="undefined"){throw new Error("The awareness message requires clients as an argument")}bm(this.encoder,t.documentName);wm(this.encoder,this.type);let e;if(t.states===undefined){e=Vm(t.awareness,t.clients)}else{e=Vm(t.awareness,t.clients,t.states)}Am(this.encoder,e);return this.encoder}}class my extends ty{constructor(){super(...arguments);this.type=Gm.Stateless;this.description="A stateless message"}get(t){var e;bm(this.encoder,t.documentName);wm(this.encoder,this.type);bm(this.encoder,(e=t.payload)!==null&&e!==void 0?e:"");return this.encoder}}class yy extends ty{constructor(){super(...arguments);this.type=Gm.Sync;this.description="First sync step"}get(t){if(typeof t.document==="undefined"){throw new Error("The sync step one message requires document as an argument")}bm(this.encoder,t.documentName);wm(this.encoder,this.type);oy(this.encoder,t.document);return this.encoder}}class by extends ty{constructor(){super(...arguments);this.type=Gm.Sync;this.description="A document update"}get(t){bm(this.encoder,t.documentName);wm(this.encoder,this.type);uy(this.encoder,t.update);return this.encoder}}class vy extends Error{constructor(){super(...arguments);this.code=1001}}class Ay extends Ym{constructor(t){var e,i,s;super();this.configuration={name:"",document:undefined,awareness:undefined,token:null,forceSyncInterval:false,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=false;this.unsyncedChanges=0;this.isAuthenticated=false;this.authorizedScope=undefined;this.manageSocket=false;this._isAttached=false;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 ga;this.configuration.awareness=t.awareness!==undefined?t.awareness:new Hm(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);(e=this.awareness)===null||e===void 0?void 0:e.on("update",(()=>{this.emit("awarenessUpdate",{states:zg(this.awareness.getStates())})}));(i=this.awareness)===null||i===void 0?void 0:i.on("change",(()=>{this.emit("awarenessChange",{states:zg(this.awareness.getStates())})}));this.document.on("update",this.boundDocumentUpdateHandler);(s=this.awareness)===null||s===void 0?void 0:s.on("update",this.boundAwarenessUpdateHandler);this.registerEventListeners();if(this.configuration.forceSyncInterval&&typeof this.configuration.forceSyncInterval==="number"){this.intervals.forceSync=setInterval(this.forceSync.bind(this),this.configuration.forceSyncInterval)}if(this.manageSocket){this.attach()}}setConfiguration(t={}){if(!t.websocketProvider){const e=t;this.manageSocket=true;this.configuration.websocketProvider=new iy({url:e.url})}this.configuration={...this.configuration,...t}}get document(){return this.configuration.document}get isAttached(){return this._isAttached}get awareness(){return this.configuration.awareness}get hasUnsyncedChanges(){return this.unsyncedChanges>0}resetUnsyncedChanges(){this.unsyncedChanges=1;this.emit("unsyncedChanges",{number:this.unsyncedChanges})}incrementUnsyncedChanges(){this.unsyncedChanges+=1;this.emit("unsyncedChanges",{number:this.unsyncedChanges})}decrementUnsyncedChanges(){if(this.unsyncedChanges>0){this.unsyncedChanges-=1}if(this.unsyncedChanges===0){this.synced=true}this.emit("unsyncedChanges",{number:this.unsyncedChanges})}forceSync(){this.resetUnsyncedChanges();this.send(yy,{document:this.document,documentName:this.configuration.name})}pageHide(){if(this.awareness){qm(this.awareness,[this.document.clientID],"page hide")}}registerEventListeners(){if(typeof window==="undefined"||!("addEventListener"in window)){return}window.addEventListener("pagehide",this.boundPageHide)}sendStateless(t){this.send(my,{documentName:this.configuration.name,payload:t})}async sendToken(){let t;try{t=await this.getToken()}catch(t){this.permissionDeniedHandler(`Failed to get token during sendToken(): ${t}`);return}this.send(py,{token:t!==null&&t!==void 0?t:"",documentName:this.configuration.name})}documentUpdateHandler(t,e){if(e===this){return}this.incrementUnsyncedChanges();this.send(by,{update:t,documentName:this.configuration.name})}awarenessUpdateHandler({added:t,updated:e,removed:i},s){const n=t.concat(e).concat(i);this.send(gy,{awareness:this.awareness,clients:n,documentName:this.configuration.name})}get synced(){return this.isSynced}set synced(t){if(this.isSynced===t){return}this.isSynced=t;if(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=false;this.emit("open",{event:t});await this.sendToken();this.startSync()}async getToken(){if(typeof this.configuration.token==="function"){const t=await this.configuration.token();return t}return this.configuration.token}startSync(){this.resetUnsyncedChanges();this.send(yy,{document:this.document,documentName:this.configuration.name});if(this.awareness&&this.awareness.getLocalState()!==null){this.send(gy,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.configuration.name})}}send(t,e){if(!this._isAttached)return;const i=new wy(t,e);this.emit("outgoingMessage",{message:i.message});i.send(this.configuration.websocketProvider)}onMessage(t){const e=new Xm(t.data);const i=e.readVarString();e.writeVarString(i);this.emit("message",{event:t,message:new Xm(t.data)});new dy(e).apply(this,true)}onClose(){this.isAuthenticated=false;this.synced=false;if(this.awareness){qm(this.awareness,Array.from(this.awareness.getStates().keys()).filter((t=>t!==this.document.clientID)),this)}}destroy(){this.emit("destroy");if(this.intervals.forceSync){clearInterval(this.intervals.forceSync)}if(this.awareness){qm(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();if(this.manageSocket){this.configuration.websocketProvider.destroy()}if(typeof window==="undefined"||!("removeEventListener"in window)){return}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=false}attach(){if(this._isAttached)return;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=true}permissionDeniedHandler(t){this.emit("authenticationFailed",{reason:t});this.isAuthenticated=false}authenticatedHandler(t){this.isAuthenticated=true;this.authorizedScope=t;this.emit("authenticated",{scope:t})}setAwarenessField(t,e){if(!this.awareness){throw new vy(`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 My{__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 My(e.id,e.name,e.viewport);i._core=t;return 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){Object.assign(this,t);this.createdAt=new Date(t.createdAt);this.updatedAt=new Date(t.updatedAt);return this}}const ky={providers:[hg,Bp]};class Sy{map;_ydoc=null;_workspacesMap=null;_providers=[];_core=null;_isReady=false;_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 ga;this._workspacesMap=this._ydoc.getMap("workspaces");const i="kritzel-app-state";const s=e??ky;for(const t of s.providers){let e;if(typeof t==="function"){e=new t(i,this._ydoc)}else{e=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=true;this.loadFromYjs()}handleWorkspacesChange(t){if(t.transaction.origin==="local"){this._core?.rerender();return}const e=Array.from(t.keysChanged);const i=[];const s=[];e.forEach((e=>{const n=t.changes.keys.get(e);if(n&&n.action==="delete"){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)}));if(this._core?.store){this._core.store.state.workspaces=this.allWorkspaces()}if(this._onRemoteChangeCallback){this._onRemoteChangeCallback()}this._core?.rerender()}reviveWorkspace(t){const e=new My(t.id,t.name,t.viewport);e._core=this._core;e.createdAt=new Date(t.createdAt);e.updatedAt=new Date(t.updatedAt);return e}transaction(t){if(this._ydoc){this._ydoc.transact(t,"local")}}loadFromYjs(){if(!this._workspacesMap){return}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 false}this.map.set(t.id,t);if(this._workspacesMap){const e=t.serialize();this._ydoc.transact((()=>{this._workspacesMap.set(t.id,e)}),"local")}return true}update(t){if(!t.id||!this.map.has(t.id)){return false}this.map.set(t.id,t);if(this._workspacesMap){const e=t.serialize();this._ydoc.transact((()=>{this._workspacesMap.set(t.id,e)}),"local")}return true}remove(t){const e=Array.from(this.map.values()).find(t);if(!e){return false}this.map.delete(e.id);if(this._workspacesMap){this._ydoc.transact((()=>{this._workspacesMap.delete(e.id)}),"local")}return true}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;if(this._ydoc){this._ydoc.destroy();this._ydoc=null}this._isReady=false}}const xy={type:"pen",color:"#000000",size:16,palettes:{pen:["#000000","#ff5252","#ffbc00","#00c853","#0000FF","#d500f9","#fafafa","#a52714","#ee8100","#558b2f","#01579b","#8e24aa","#90a4ae","#ff4081","#ff6e40","#aeea00","#304ffe","#7c4dff","#cfd8dc","#f8bbd0","#ffccbc","#f0f4c3","#9fa8da","#d1c4e9"],highlighter:["#0000006e","#ff52526e","#ffbb006e","#00c8536e","#0000FF6e","#d500f96e","#fafafa6e","#a527146e","#ee81006e","#558b2f6e","#01579b6e","#8e24aa6e","#90a4ae6e","#ff40816e","#ff6e406e","#aeea006e","#304ffe6e","#7c4dff6e","#cfd8dc6e","#f8bbd06e","#ffccbc6e","#f0f4c36e","#9fa8da6e","#d1c4e96e"]}};const Oy={color:"#000000",size:8,fontFamily:"Arial",palette:["#000000","#ff5252","#ffbc00","#00c853","#0000FF","#d500f9","#fafafa","#a52714","#ee8100","#558b2f","#01579b","#8e24aa","#90a4ae","#ff4081","#ff6e40","#aeea00","#304ffe","#7c4dff","#cfd8dc","#f8bbd0","#ffccbc","#f0f4c3","#9fa8da","#d1c4e9"]};export{ga as $,wc as A,ff as B,cf as C,iy as D,ql as E,Vl as F,Gl as G,Ay as H,Zl as I,Ph as J,Ll as K,Fh as L,Hh as M,Bp as N,of as O,hg as P,Sy as Q,My as R,xy as S,Oy as T,Kl as U,n as V,Bh as W,t as X,zh as Y,Jh as Z,s as _,xc as a,ky as a0,kd as a1,e as a2,Yl as a3,Xl as a4,Yu as b,Gh as c,Gf as d,La as e,Rc as f,Pa as g,Ua as h,Au as i,Eu as j,lf as k,zu as l,ac as m,Yf as n,Ku as o,$f as p,jf as q,ku as r,Kh as s,Cc as t,yu as u,Vu as v,Wf as w,tc as x,rf as y,_f as z};
2
- //# sourceMappingURL=p-CsZAW1Cu.js.map