diff --git a/blocks/edit/prose/index.js b/blocks/edit/prose/index.js index 6daf0e5f..0b704a31 100644 --- a/blocks/edit/prose/index.js +++ b/blocks/edit/prose/index.js @@ -42,6 +42,7 @@ import { handleUndo, handleRedo, } from './plugins/keyHandlers.js'; +import tableHeaderFix from './plugins/tableHeaderFix.js'; let sendUpdates = false; let hasChanged = 0; @@ -290,6 +291,7 @@ export default function initProse({ path, permissions }) { }), gapCursor(), tableEditing(), + tableHeaderFix(), ]; if (canWrite) plugins.push(menu); diff --git a/blocks/edit/prose/plugins/tableHeaderFix.js b/blocks/edit/prose/plugins/tableHeaderFix.js new file mode 100644 index 00000000..1d8ab48b --- /dev/null +++ b/blocks/edit/prose/plugins/tableHeaderFix.js @@ -0,0 +1,67 @@ +import { Plugin, TableMap } from 'da-y-wrapper'; + +// auto-fix table header colspan when columns are added +export default function tableHeaderFix() { + return new Plugin({ + appendTransaction(transactions, oldState, newState) { + if (!transactions.some((tr) => tr.docChanged)) return null; + + const tablesToCheck = new Map(); + newState.doc.descendants((node, pos) => { + if (node.type.name === 'table') { + const newMap = TableMap.get(node); + const newColCount = newMap.width; + + try { + const oldNode = oldState.doc.nodeAt(pos); + if (oldNode && oldNode.type.name === 'table') { + const oldMap = TableMap.get(oldNode); + const oldColCount = oldMap.width; + + if (oldColCount < newColCount) { + tablesToCheck.set(pos, node); + } + } + } catch (e) { + // no op + } + } + }); + + if (tablesToCheck.size === 0) return null; + + const { tr } = newState; + tablesToCheck.forEach((table, tablePos) => { + const firstRow = table.child(0); + const map = TableMap.get(table); + const totalCols = map.width; + + let blockName; + for (let i = 0; i < firstRow.childCount && !blockName; i += 1) { + const cell = firstRow.child(i); + if (cell.textContent) { + blockName = cell.textContent; + } + } + + if (blockName) { + const cellType = firstRow.child(0).type; + const para = newState.schema.nodes.paragraph.create( + null, + newState.schema.text(blockName), + ); + const newCell = cellType.create({ colspan: totalCols, rowspan: 1 }, para); + const newRow = newState.schema.nodes.table_row.create(null, newCell); + + // Map position through previous transaction steps + const mappedTablePos = tr.mapping.map(tablePos); + const firstCellPos = mappedTablePos + 1; + const firstRowEnd = firstCellPos + firstRow.nodeSize - 1; + tr.replaceWith(firstCellPos, firstRowEnd, newRow); + } + }); + + return tr.docChanged ? tr : null; + }, + }); +} diff --git a/deps/da-y-wrapper/dist/index.js b/deps/da-y-wrapper/dist/index.js index 30ec4a16..3b3d4006 100644 --- a/deps/da-y-wrapper/dist/index.js +++ b/deps/da-y-wrapper/dist/index.js @@ -6,8 +6,8 @@ var hp=Object.defineProperty;var dp=(n,e)=>{for(var t in e)hp(n,t,{get:e[t],enum `),h&&u==f.nodeValue.length)for(let p=f,m;p;p=p.parentNode){if(m=p.nextSibling){m.nodeName=="BR"&&(l=c={node:m.parentNode,offset:te(m)+1});break}let g=p.pmViewDesc;if(g&&g.node&&g.node.isBlock)break}}else{let p=f.childNodes[u-1];h=p&&(p.nodeName=="BR"||p.contentEditable=="false")}}if(qe&&a.focusNode&&a.focusNode!=c.node&&a.focusNode.nodeType==1){let f=a.focusNode.childNodes[a.focusOffset];f&&f.contentEditable=="false"&&(i=!0)}if(!(i||h&&me)&&fn(l.node,l.offset,a.anchorNode,a.anchorOffset)&&fn(c.node,c.offset,a.focusNode,a.focusOffset))return;let d=!1;if((a.extend||e==t)&&!h){a.collapse(l.node,l.offset);try{e!=t&&a.extend(c.node,c.offset),d=!0}catch{}}if(!d){if(e>t){let u=l;l=c,c=u}let f=document.createRange();f.setEnd(c.node,c.offset),f.setStart(l.node,l.offset),a.removeAllRanges(),a.addRange(f)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+s.border,c=o-s.border;if(e>=l&&t<=c){this.dirty=e==r||t==o?ln:Ga,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Ge:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?ln:Ge}r=o}this.dirty=ln}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?ln:Ga;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==Ue&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},Wo=class extends un{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Yn=class n extends un{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=It.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&Ge||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Ge&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Ue){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Go(s,0,e,r));for(let l=0;l{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),h=a&&a.dom,d=a&&a.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:d}=It.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!d&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let f=h;return h=Rh(h,r,t),a?c=new jo(e,t,r,i,h,d||null,f,a,s,o+1):t.isText?new ts(e,t,r,i,h,f,s):new n(e,t,r,i,h,d||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>w.empty)}return e}matchesNode(e,t,r){return this.dirty==Ue&&e.eq(this.node)&&rs(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,c=new Yo(this,o&&o.node,e);Om(this.node,this.innerDeco,(a,h,d)=>{a.spec.marks?c.syncToMarks(a.spec.marks,r,e):a.type.side>=0&&!d&&c.syncToMarks(h==this.node.childCount?D.none:this.node.child(h).marks,r,e),c.placeWidget(a,e,i)},(a,h,d,f)=>{c.syncToMarks(a.marks,r,e);let u;c.findNodeMatch(a,h,d,f)||l&&e.state.selection.from>i&&e.state.selection.to-1&&c.updateNodeAt(a,h,d,u,e)||c.updateNextNode(a,h,d,e,f,i)||c.addNode(a,h,d,e,i),i+=a.nodeSize}),c.syncToMarks([],r,e),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==ln)&&(o&&this.protectLocalComposition(e,o),Nh(this.contentDOM,this.children,e),Kn&&Nm(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof A)||rt+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Im(this.node.content,o,r-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new Wo(this,s,t,i);e.input.compositionNodes.push(o),this.children=Go(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==Ge||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Ue}updateOuterDeco(e){if(rs(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Ih(this.dom,this.nodeDOM,Ko(this.outerDeco,this.node,t),Ko(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}};function Xa(n,e,t,r,i){Rh(r,e,n);let s=new Pt(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var ts=class n extends Pt{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==Ge||this.dirty!=Ue&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Ue||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=Ue,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Ge)}get domAtom(){return!1}isText(e){return this.node.text==e}},ns=class extends un{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Ue&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},jo=class extends Pt{constructor(e,t,r,i,s,o,l,c,a,h){super(e,t,r,i,s,o,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==Ge)return!1;if(this.spec.update){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Nh(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let c=Yn.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,c=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let a=t.children[r-1];if(a instanceof Yn)t=a,r=a.children.length;else{l=a,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function Dm(n,e){return n.type.side-e.type.side}function Om(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let a=0;as;)l.push(i[o++]);let p=s+f.nodeSize;if(f.isText){let g=p;o!g.inline):l.slice();r(f,m,e.forChild(s,f),u),s=p}}function Nm(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Im(n,e,t,r){for(let i=0,s=0;i=t){if(s>=r&&c.slice(r-e.length-l,r-l)==e)return r-e.length;let a=l=0&&a+e.length+l>=t)return l+a;if(t==r&&c.length>=r+e.length-l&&c.slice(r-l,r-l+e.length)==e)return r}}return-1}function Go(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||h<=e?s.push(c):(at&&s.push(c.slice(t-a,c.size,r)))}return s}function cl(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),c,a;if(ds(t)){for(c=o;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&C.isSelectable(d)&&i.parent&&!(d.isInline&&om(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;a=new C(o==f?l:r.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=o,f=o;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!vh(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function vm(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,te(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&ke&&Bt<=11&&(r.disabled=!0,r.disabled=!1)}function _h(n,e){if(e instanceof C){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(nh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else nh(n)}function nh(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function al(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function rh(n){return n.editable&&!n.hasFocus()?!1:Uh(n)}function Uh(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function _m(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return fn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Xo(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&S.findFrom(s,e)}function Ut(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function ih(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Ut(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Xo(n.state,e);return i&&i instanceof C?Ut(n,i):!1}else if(!(ve&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?C.isSelectable(s)?Ut(n,new C(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):$r?Ut(n,new A(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof C&&r.node.isInline)return Ut(n,new A(e>0?r.$to:r.$from));{let i=Xo(n.state,e);return i?Ut(n,i):!1}}}function is(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Lr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function $n(n,e){return e<0?Um(n):Vm(n)}function Um(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(qe&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Lr(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Vh(t))break;{let l=t.previousSibling;for(;l&&Lr(l,-1);)i=t.parentNode,s=te(l),l=l.previousSibling;if(l)t=l,r=is(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?Qo(n,t,r):i&&Qo(n,i,s)}function Vm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=is(t),s,o;for(;;)if(r{n.state==i&&mt(n)},50)}function sh(n,e){let t=n.state.doc.resolve(e);if(!(ae||am)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function oh(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||ve&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=Xo(n.state,e);if(o&&o instanceof C)return Ut(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof Te?S.near(o,e):S.findFrom(o,e);return l?Ut(n,l):!1}return!1}function lh(n,e){if(!(n.state.selection instanceof A))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function ch(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Lm(n){if(!me||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;ch(n,r,"true"),setTimeout(()=>ch(n,r,"false"),20)}return!1}function zm(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Fm(n,e){let t=e.keyCode,r=zm(e);if(t==8||ve&&t==72&&r=="c")return lh(n,-1)||$n(n,-1);if(t==46&&!e.shiftKey||ve&&t==68&&r=="c")return lh(n,1)||$n(n,1);if(t==13||t==27)return!0;if(t==37||ve&&t==66&&r=="c"){let i=t==37?sh(n,n.state.selection.from)=="ltr"?-1:1:-1;return ih(n,i,r)||$n(n,i)}else if(t==39||ve&&t==70&&r=="c"){let i=t==39?sh(n,n.state.selection.from)=="ltr"?1:-1:1;return ih(n,i,r)||$n(n,i)}else{if(t==38||ve&&t==80&&r=="c")return oh(n,-1,r)||$n(n,-1);if(t==40||ve&&t==78&&r=="c")return Lm(n)||oh(n,1,r)||$n(n,1);if(r==(ve?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Bh(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let o=n.someProp("clipboardSerializer")||It.fromSchema(n.state.schema),l=Hh(),c=l.createElement("div");c.appendChild(o.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=qh[a.nodeName.toLowerCase()]);){for(let u=h.length-1;u>=0;u--){let p=l.createElement(h[u]);for(;c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p),d++}a=c.firstChild}a&&a.nodeType==1&&a.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,` `);return{dom:c,text:f,slice:e}}function Ph(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let c=e&&(r||s||!t);if(c){if(n.someProp("transformPastedText",f=>{e=f(e,s||r,n)}),s)return e?new b(w.from(n.state.schema.text(e.replace(/\r\n?/g,` -`))),0,0):b.empty;let d=n.someProp("clipboardTextParser",f=>f(e,i,r,n));if(d)l=d;else{let f=i.marks(),{schema:u}=n.state,p=It.fromSchema(u);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),o=$m(t),$r&&Wm(o);let a=o&&o.querySelector("[data-pm-slice]"),h=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let d=+h[3];d>0;d--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!qm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=jm(ah(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Hm(l.content,i),!0),l.openStart||l.openEnd){let d=0,f=0;for(let u=l.content.firstChild;d{l=d(l,n)}),l}var qm=/^(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 Hm(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let c=i.findWrapping(l.type),a;if(!c)return o=null;if(a=o.length&&s.length&&zh(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=Fh(o[o.length-1],s.length));let h=Lh(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return w.from(o)}return n}function Lh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function zh(n,e,t,r,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function ah(n,e,t){return et}).createHTML(n):n}function $m(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Hh().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&qh[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"").reverse().join("")),t.innerHTML=Jm(n),i)for(let s=0;s=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),s++,o++}return new b(i,s,o)}var ge={},ye={},Km={touchstart:!0,touchmove:!0},el=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Ym(n){for(let e in ge){let t=ge[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Xm(n,r)&&!hl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},Km[e]?{passive:!0}:void 0)}me&&n.dom.addEventListener("input",()=>null),tl(n)}function Vt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Gm(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function tl(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>hl(n,r))})}function hl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Xm(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Qm(n,e){!hl(n,e)&&ge[e.type]&&(n.editable||!(e.type in ye))&&ge[e.type](n,e)}ye.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!$h(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Fe&&ae&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),Kn&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,on(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Fm(n,t)?t.preventDefault():Vt(n,"key")};ye.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ye.keypress=(n,e)=>{let t=e;if($h(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||ve&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof A)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function fs(n){return{left:n.clientX,top:n.clientY}}function Zm(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function dl(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function jn(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function eg(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&C.isSelectable(r)?(jn(n,new C(t),"pointer"),!0):!1}function tg(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof C&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(C.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(jn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function ng(n,e,t,r,i){return dl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?tg(n,t):eg(n,t))}function rg(n,e,t,r){return dl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function ig(n,e,t,r){return dl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||sg(n,t,r)}function sg(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(jn(n,A.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)jn(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(C.isSelectable(o))jn(n,C.create(r,l),"pointer");else continue;return!0}}function fl(n){return ss(n)}var Jh=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=fl(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&Zm(t,n.input.lastClick)&&!t[Jh]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(fs(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new nl(n,o,t,!!r)):(s=="doubleClick"?rg:ig)(n,o.pos,o.inside,t)?t.preventDefault():Vt(n,"pointer"))};var nl=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Jh],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}let l=i?null:r.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c&&c.dom.nodeType==1?c.dom:null;let{selection:a}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||a instanceof C&&a.from<=o&&a.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&qe&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),Vt(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>mt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(fs(e))),this.updateAllowDefault(e),this.allowDefault||!t?Vt(this.view,"pointer"):ng(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||me&&this.mightDrag&&!this.mightDrag.node.isAtom||ae&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(jn(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Vt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Vt(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};ge.touchstart=n=>{n.input.lastTouch=Date.now(),fl(n),Vt(n,"pointer")};ge.touchmove=n=>{n.input.lastTouch=Date.now(),Vt(n,"pointer")};ge.contextmenu=n=>fl(n);function $h(n,e){return n.composing?!0:me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var og=Fe?5e3:-1;ye.compositionstart=ye.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof A&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),ss(n,!0),n.markCursor=null;else if(ss(n,!e.selection.empty),qe&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}Wh(n,og)};ye.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Wh(n,20))};function Wh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>ss(n),e))}function jh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=cg());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function lg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=im(e.focusNode,e.focusOffset),r=sm(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function cg(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function ss(n,e=!1){if(!(Fe&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),jh(n),e||n.docView&&n.docView.dirty){let t=cl(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function ag(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var Fr=ke&&Bt<15||Kn&&hm<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=Fr?null:t.clipboardData,o=r.content(),{dom:l,text:c}=Bh(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):ag(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function hg(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function dg(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?qr(n,r.value,null,i,e):qr(n,r.textContent,r.innerHTML,i,e)},50)}function qr(n,e,t,r,i){let s=Ph(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,s||b.empty)))return!0;if(!s)return!1;let o=hg(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Kh(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ye.paste=(n,e)=>{let t=e;if(n.composing&&!Fe)return;let r=Fr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&qr(n,Kh(r),r.getData("text/html"),i,t)?t.preventDefault():dg(n,t)};var ls=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Yh=ve?"altKey":"ctrlKey";ge.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(fs(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof C?i.to-1:i.to))){if(r&&r.mightDrag)o=C.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let d=n.docView.nearestDesc(t.target,!0);d&&d.node.type.spec.draggable&&d!=n.docView&&(o=C.create(n.state.doc,d.posBefore))}}let l=(o||n.state.selection).content(),{dom:c,text:a,slice:h}=Bh(n,l);(!t.dataTransfer.files.length||!ae||Ch>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Fr?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",Fr||t.dataTransfer.setData("text/plain",a),n.dragging=new ls(h,!t[Yh],o)};ge.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ye.dragover=ye.dragenter=(n,e)=>e.preventDefault();ye.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(fs(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",p=>{o=p(o,n)}):o=Ph(n,Kh(t.dataTransfer),Fr?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[Yh]);if(n.someProp("handleDrop",p=>p(n,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let c=o?Na(n.state.doc,s.pos,o):s.pos;c==null&&(c=s.pos);let a=n.state.tr;if(l){let{node:p}=r;p?p.replace(a):a.deleteSelection()}let h=a.mapping.map(c),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,o.content.firstChild):a.replaceRange(h,h,o),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&C.isSelectable(o.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new C(u));else{let p=a.mapping.map(c);a.mapping.maps[a.mapping.maps.length-1].forEach((m,g,y,E)=>p=E),a.setSelection(al(n,u,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))};ge.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&mt(n)},20))};ge.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};ge.beforeinput=(n,e)=>{if(ae&&Fe&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,on(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in ye)ge[n]=ye[n];function Hr(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var cs=class n{constructor(e,t){this.toDOM=e,this.spec=t||hn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new ne(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Hr(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},an=class n{constructor(e,t){this.attrs=e,this.spec=t||hn}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new ne(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==ce||e.maps.length==0?this:this.mapInner(e,t,0,0,r||hn)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let a=c+r,h;if(h=Xh(t,l,a)){for(i||(i=this.children.slice());sl&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&c.type instanceof an){let a=Math.max(s,c.from)-s,h=Math.min(o,c.to)-s;ai.map(e,t,hn));return n.from(r)}forChild(e,t){if(t.isLeaf)return L.empty;let r=[];for(let i=0;it instanceof L)?e:e.reduce((t,r)=>t.concat(r instanceof L?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-p-(u-f);for(let y=0;yE+h-d)continue;let N=l[y]+h-d;u>=N?l[y+1]=f<=N?-2:-1:f>=h&&g&&(l[y]+=g,l[y+1]+=g)}d+=g}),h=t.maps[a].map(h,-1)}let c=!1;for(let a=0;a=r.content.size){c=!0;continue}let f=t.map(n[a+1]+s,-1),u=f-i,{index:p,offset:m}=r.content.findIndex(d),g=r.maybeChild(p);if(g&&m==d&&m+g.nodeSize==u){let y=l[a+2].mapInner(t,g,h+1,n[a]+s+1,o);y!=ce?(l[a]=d,l[a+1]=u,l[a+2]=y):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=ug(l,n,e,t,i,s,o),h=hs(a,r,0,o);e=h.local;for(let d=0;dt&&o.to{let a=Xh(n,l,c+t);if(a){s=!0;let h=hs(a,l,t+c+1,r);h!=ce&&i.push(c,c+l.nodeSize,h)}});let o=Gh(s?Qh(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function zo(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=ce&&e.push(r)}),n.cursorWrapper&&e.push(L.create(n.state.doc,[n.cursorWrapper.deco])),as.from(e)}var pg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},mg=ke&&Bt<=11,il=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},sl=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new il,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),mg&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,pg)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(rh(this.view)){if(this.suppressingSelectionUpdates)return mt(this.view);if(ke&&Bt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&fn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=zr(s))t.add(s);for(let s=e.anchorNode;s;s=zr(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&rh(this.view)&&!this.ignoreSelectionChange(e)}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=this.selectionChanged(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let h=0;hd.nodeName=="BR");if(h.length==2){let[d,f]=h;d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.remove()}else{let{focusNode:d}=this.currentSelection;for(let f of h){let u=f.parentNode;u&&u.nodeName=="LI"&&(!d||wg(e,d)!=u)&&f.remove()}}}let a=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),gg(e)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||mt(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let h=0;hi;g--){let y=r.childNodes[g-1],E=y.pmViewDesc;if(y.nodeName=="BR"&&!E){s=g;break}if(!E||E.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(o),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:xg,context:u});if(a&&a[0].pos!=null){let g=a[0].pos,y=a[1]&&a[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function xg(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(me&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||me&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var Sg=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function kg(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let T=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,Nt=cl(n,T);if(Nt&&!n.state.selection.eq(Nt)){if(ae&&Fe&&n.input.lastKeyCode===13&&Date.now()-100ap(n,on(13,"Enter"))))return;let Bi=n.state.tr.setSelection(Nt);T=="pointer"?Bi.setMeta("pointer",!0):T=="key"&&Bi.scrollIntoView(),s&&Bi.setMeta("composition",s),n.dispatch(Bi)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=bg(n,e,t),h=n.state.doc,d=h.slice(a.from,a.to),f,u;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||Fe)&&i.some(T=>T.nodeType==1&&!Sg.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&c instanceof A&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(a.sel&&a.sel.anchor!=a.sel.head))p={start:c.from,endA:c.to,endB:c.to};else{if(a.sel){let T=mh(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let Nt=n.state.tr.setSelection(T);s&&Nt.setMeta("composition",s),n.dispatch(Nt)}}return}n.state.selection.fromn.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=a.from?p.start=n.state.selection.from:p.endA=n.state.selection.to-2&&n.state.selection.to<=a.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),ke&&Bt<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>a.from&&a.doc.textBetween(p.start-a.from-1,p.start-a.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=a.doc.resolveNoCache(p.start-a.from),g=a.doc.resolveNoCache(p.endB-a.from),y=h.resolve(p.start),E=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,N;if((Kn&&n.input.lastIOSEnter>Date.now()-225&&(!E||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!E&&m.posT(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Mg(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,on(8,"Backspace")))){Fe&&ae&&n.domObserver.suppressSelectionUpdates();return}ae&&Fe&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),Fe&&!E&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==p.endA&&(p.endB-=2,g=a.doc.resolveNoCache(p.endB-a.from),setTimeout(()=>{n.someProp("handleKeyDown",function(T){return T(n,on(13,"Enter"))})},20));let Se=p.start,pe=p.endA,Y,dt,Ot;if(E){if(m.pos==g.pos)ke&&Bt<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>mt(n),20)),Y=n.state.tr.delete(Se,pe),dt=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(Ot=Cg(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))Y=n.state.tr,Ot.type=="add"?Y.addMark(Se,pe,Ot.mark):Y.removeMark(Se,pe,Ot.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",Nt=>Nt(n,Se,pe,T)))return;Y=n.state.tr.insertText(T,Se,pe)}}if(Y||(Y=n.state.tr.replace(Se,pe,a.doc.slice(p.start-a.from,p.endB-a.from))),a.sel){let T=mh(n,Y.doc,a.sel);T&&!(ae&&Fe&&n.composing&&T.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:al(n,e.resolve(t.anchor),e.resolve(t.head))}function Cg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||Fo(o,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function Ag(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,s-Math.min(o,l));r-=o+c-s}if(o=o?s-r:0;s-=c,s&&s=l?s-r:0;s-=c,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var ol=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new el,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Sh),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=bh(this),wh(this),this.nodeViews=xh(this),this.docView=Xa(this.state.doc,yh(this),zo(this),this.dom,this),this.domObserver=new sl(this,(r,i,s,o)=>kg(this,r,i,s,o)),this.domObserver.start(),Ym(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&tl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Sh),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(jh(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let u=xh(this);Tg(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&tl(this),this.editable=bh(this),wh(this);let c=zo(this),a=yh(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=s||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(o=!0);let f=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&um(this);if(o){this.domObserver.stop();let u=d&&(ke||ae)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Eg(i.selection,e.selection);if(d){let p=ae?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=lg(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Xa(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&_m(this))?mt(this,u):(_h(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():f&&pm(f)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof C){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&$a(this,t.getBoundingClientRect(),e)}else $a(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new ls(e.slice,e.move,i<0?void 0:C.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return xm(this,e)}coordsAtPos(e,t=1){return Dh(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Am(this,t||this.state,e)}pasteHTML(e,t){return qr(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return qr(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Gm(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],zo(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,nm())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Qm(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?me&&this.root.nodeType===11&&lm(this.dom.ownerDocument)==this.dom&&yg(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function yh(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[ne.node(0,n.state.doc.content.size,e)]}function wh(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:ne.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function bh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Eg(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function xh(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Tg(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function Sh(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Dg=["p",0],Og=["blockquote",0],Ng=["hr"],Ig=["pre",["code",0]],Rg=["br"],vg={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Dg}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Og}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Ng}},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return Ig}},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return Rg}}},_g=["em",0],Ug=["strong",0],Vg=["code",0],Bg={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return _g}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return Ug}},code:{parseDOM:[{tag:"code"}],toDOM(){return Vg}}},Pg=new Dr({nodes:vg,marks:Bg});var ed=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Lg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var zg=(n,e,t)=>{let r=Lg(n,t);if(!r)return!1;let i=td(r);if(!i){let o=r.blockRange(),l=o&&nn(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(id(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Gn(s,"end")||C.isSelectable(s)))for(let o=r.depth;;o--){let l=Xi(n.doc,r.before(o),r.after(o),b.empty);if(l&&l.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function Gn(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}var Fg=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=td(r)}let o=s&&s.nodeBefore;return!o||!C.isSelectable(o)?!1:(e&&e(n.tr.setSelection(C.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function td(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function qg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=qg(n,t);if(!r)return!1;let i=nd(r);if(!i)return!1;let s=i.nodeAfter;if(id(n,i,e,1))return!0;if(r.parent.content.size==0&&(Gn(s,"start")||C.isSelectable(s))){let o=Xi(n.doc,r.before(),r.after(),b.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof C,i;if(r){if(t.node.isTextblock||!rn(n.doc,t.from))return!1;i=t.from}else if(i=Ro(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(C.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},rd=(n,e)=>{let t=n.selection,r;if(t instanceof C){if(t.node.isTextblock||!rn(n.doc,t.to))return!1;r=t.to}else if(r=Ro(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},jr=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&nn(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},$g=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` -`).scrollIntoView()),!0)};function ml(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=ml(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,o.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},Wg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Te||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=ml(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(Rt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Kg(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof C&&e.selection.node.isBlock)return!r.parentOffset||!Rt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;let s=i.parentOffset==i.parent.content.size,o=e.tr;(e.selection instanceof A||e.selection instanceof Te)&&o.deleteSelection();let l=r.depth==0?null:ml(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,s,r),a=c?[c]:s&&l?[{type:l}]:void 0,h=Rt(o.doc,o.mapping.map(r.pos),1,a);if(!a&&!h&&Rt(o.doc,o.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(o.split(o.mapping.map(r.pos),1,a),!s&&!r.parentOffset&&r.parent.type!=l){let d=o.mapping.map(r.before()),f=o.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&o.setNodeMarkup(o.mapping.map(r.before()),l)}return t&&t(o.scrollIntoView()),!0}}var Yg=Kg();var Kr=(n,e)=>{let{$from:t,to:r}=n.selection,i,s=t.sharedDepth(r);return s==0?!1:(i=t.before(s),e&&e(n.tr.setSelection(C.create(n.doc,i))),!0)},Gg=(n,e)=>(e&&e(n.tr.setSelection(new Te(n.doc))),!0);function Xg(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||rn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function id(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&Xg(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let u=e.pos+s.nodeSize,p=w.empty;for(let y=o.length-1;y>=0;y--)p=w.from(o[y].create(null,p));p=w.from(i.copy(p));let m=n.tr.step(new X(e.pos-1,u,e.pos,u,new b(p,1,0),o.length,!0)),g=m.doc.resolve(u+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&rn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||r>0&&c?null:S.findFrom(e,1),d=h&&h.$from.blockRange(h.$to),f=d&&nn(d);if(f!=null&&f>=e.depth)return t&&t(n.tr.lift(d,f).scrollIntoView()),!0;if(a&&Gn(s,"start",!0)&&Gn(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(u.canReplace(u.childCount,u.childCount,m.content)){if(t){let y=w.empty;for(let N=p.length-1;N>=0;N--)y=w.from(p[N].copy(y));let E=n.tr.step(new X(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new b(y,p.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function sd(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var Qg=sd(-1),Zg=sd(1);function Xn(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Gi(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function pn(n,e=null){return function(t,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)i=!0;else{let h=t.doc.resolve(a),d=h.index();i=h.parent.canReplaceWith(d,d+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o{if(l||!r&&c.isAtom&&c.isInline&&a>=s.pos&&a+c.nodeSize<=o.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function ty(n){let e=[];for(let t=0;t{if(s.isAtom&&s.content.size&&s.isInline&&o>=r.pos&&o+s.nodeSize<=i.pos)return o+1>r.pos&&e.push(new vt(r,r.doc.resolve(o+1))),r=r.doc.resolve(o+1+s.content.size),!1}),r.poss.doc.rangeHasMark(f.$from.pos,f.$to.pos,n)):h=!a.every(f=>{let u=!1;return d.doc.nodesBetween(f.$from.pos,f.$to.pos,(p,m,g)=>{if(u)return!1;u=!n.isInSet(p.marks)&&!!g&&g.type.allowsMarkType(n)&&!(p.isText&&/^\s*$/.test(p.textBetween(Math.max(0,f.$from.pos-m),Math.min(p.nodeSize,f.$to.pos-m))))}),!u});for(let f=0;f=2&&i.node(o.depth-1).type.compatibleContent(n)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let h=t.doc.resolve(o.start-2);c=new Zt(h,h,o.depth),o.endIndex=0;h--)s=w.from(t[h].type.create(t[h].attrs,s));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(s,0,0),t.length,!0));let o=0;for(let h=0;h=i.depth-3;y--)d=w.from(i.node(y).copy(d));let u=i.indexAfter(-1){if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=E+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let c=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,s.pos),h=c?[e?{type:n,attrs:e}:null,{type:c}]:void 0;return Rt(a.doc,i.pos,2,h)?(r&&r(a.split(i.pos,2,h).scrollIntoView()),!0):!1}}function bl(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,o=>o.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?dy(e,t,n,s):fy(e,t,s):!0:!1}}function dy(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);sm;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=s.node(-1),h=s.index(-1);if(!a.canReplace(h+(l?0:1),h+1,o.content.append(c?w.empty:w.from(i))))return!1;let d=s.pos,f=d+o.nodeSize;return r.step(new X(d-(l?1:0),f+(c?1:0),d+1,f-1,new b((l?w.empty:w.from(i.copy(w.empty))).append(c?w.empty:w.from(i.copy(w.empty))),l?0:1,c?0:1),l?0:1)),e(r.scrollIntoView()),!0}function xl(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,c=l.child(o-1);if(c.type!=n)return!1;if(t){let a=c.lastChild&&c.lastChild.type==l.type,h=w.from(a?n.create():null),d=new b(w.from(n.create(null,w.from(l.type.create(null,h)))),a?3:1,0),f=s.start,u=s.end;t(e.tr.step(new X(f-(a?3:1),u,f,u,d,1,!0)).scrollIntoView())}return!0}}var yt={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:"'"},ms={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},uy=typeof navigator<"u"&&/Mac/.test(navigator.platform),py=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(J=0;J<10;J++)yt[48+J]=yt[96+J]=String(J);var J;for(J=1;J<=24;J++)yt[J+111]="F"+J;var J;for(J=65;J<=90;J++)yt[J]=String.fromCharCode(J+32),ms[J]=String.fromCharCode(J);var J;for(ps in yt)ms.hasOwnProperty(ps)||(ms[ps]=yt[ps]);var ps;function cd(n){var e=uy&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||py&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?ms:yt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var my=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function gy(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l127)&&(s=yt[r.keyCode])&&s!=i){let l=e[Sl(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var gs=200,re=function(){};re.prototype.append=function(e){return e.length?(e=re.from(e),!this.length&&e||e.length=t?re.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};re.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};re.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};re.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i};re.from=function(e){return e instanceof re?e:e&&e.length?new ad(e):re.empty};var ad=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var c=s;c=o;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=gs)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=gs)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(re);re.empty=new ad([]);var by=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(re),kl=re;var xy=500,ys=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,s;t&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,c,a=[],h=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),s=i.maps.length),s--,h.push(d);return}if(i){h.push(new Xe(d.map));let u=d.step.map(i.slice(s)),p;u&&o.maybeStep(u).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],a.push(new Xe(p,void 0,void 0,a.length+h.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(s)):d.selection,c=new n(this.items.slice(0,r).append(h.reverse().concat(a)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:l}}addTransform(e,t,r,i){let s=[],o=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hky&&(l=Sy(l,a),o-=a),new n(l.append(s),o)}remapping(e,t){let r=new Rr;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new Xe(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let c=t;this.items.forEach(f=>{let u=s.getMirror(--c);if(u==null)return;o=Math.min(o,u);let p=s.maps[u];if(f.step){let m=e.steps[u].invert(e.docs[u]),g=f.selection&&f.selection.map(s.slice(c+1,u));g&&l++,r.push(new Xe(p,m,g))}else r.push(new Xe(p))},i);let a=[];for(let f=t;fxy&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let c=o.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=o.selection&&o.selection.map(t.slice(r));h&&s++;let d=new Xe(a.invert(),c,h),f,u=i.length-1;(f=i.length&&i[u].merge(d))?i[u]=f:i.push(d)}}else o.map&&r--},this.items.length,0),new n(kl.from(i.reverse()),s)}};ys.empty=new ys(kl.empty,0);function Sy(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var Xe=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},Ml=class{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}},ky=20;function Cy(n,e,t){let r=My(e),i=Al.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,r);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),i,r),c=new Ml(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(Al,{redo:t,historyState:c})}var Cl=!1,hd=null;function My(n){let e=n.plugins;if(hd!=e){Cl=!1,hd=e;for(let t=0;t{let i=Al.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=Cy(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}var Xr=ws(!1,!0),Qn=ws(!0,!0),yx=ws(!1,!1),wx=ws(!0,!1);var he=class n extends S{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return n.valid(r)?new n(r):S.near(r)}content(){return b.empty}eq(e){return e instanceof n&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new n(e.resolve(t.pos))}getBookmark(){return new El(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Ay(e)||!Ey(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&n.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!C.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),r=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(n.valid(l))return l}return null}}};he.prototype.visible=!1;he.findFrom=he.findGapCursorFrom;S.jsonID("gapcursor",he);var El=class n{constructor(e){this.pos=e}map(e){return new n(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return he.valid(t)?new he(t):S.near(t)}};function Ay(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Ey(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Ty(){return new H({props:{decorations:Iy,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:Oy,handleKeyDown:Dy,handleDOMEvents:{beforeinput:Ny}}})}var Dy=Gr({ArrowLeft:bs("horiz",-1),ArrowRight:bs("horiz",1),ArrowUp:bs("vert",-1),ArrowDown:bs("vert",1)});function bs(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,s){let o=r.selection,l=e>0?o.$to:o.$from,c=o.empty;if(o instanceof A){if(!s.endOfTextblock(t)||l.depth==0)return!1;c=!1,l=r.doc.resolve(e>0?l.after():l.before())}let a=he.findGapCursorFrom(l,e,c);return a?(i&&i(r.tr.setSelection(new he(a))),!0):!1}}function Oy(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!he.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&C.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new he(r))),!0)}function Ny(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof he))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=w.empty;for(let o=r.length-1;o>=0;o--)i=w.from(r[o].createAndFill(null,i));let s=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return s.setSelection(A.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function Iy(n){if(!(n.selection instanceof he))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",L.create(n.doc,[ne.widget(n.selection.head,e,{key:"gapcursor"})])}function wt(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];typeof i=="string"?n.setAttribute(r,i):i!=null&&(n[r]=i)}e++}for(;e0&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}var vy=500;function ud({rules:n}){let e=new H({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,s){return fd(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&fd(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function fd(n,e,t,r,i,s){if(n.composing)return!1;let o=n.state,l=o.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-vy),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a{let t=n.plugins;for(let r=0;r=0;c--)o.step(l.steps[c].invert(l.docs[c]));if(s.text){let c=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,c))}else o.delete(s.from,s.to);e(o)}return!0}}return!1},_y=new bt(/--$/,"\u2014"),Uy=new bt(/\.\.\.$/,"\u2026"),Tx=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Dx=new bt(/"$/,"\u201D"),Ox=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),Nx=new bt(/'$/,"\u2019");var md=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Vy(n,e){let t={},r;function i(s,o){if(e){let l=e[s];if(l===!1)return;l&&(s=l)}t[s]=o}if(i("Mod-z",Xr),i("Shift-Mod-z",Qn),i("Backspace",pd),md||i("Mod-y",Qn),i("Alt-ArrowUp",Wr),i("Alt-ArrowDown",rd),i("Mod-BracketLeft",jr),i("Escape",Kr),(r=n.marks.strong)&&(i("Mod-b",mn(r)),i("Mod-B",mn(r))),(r=n.marks.em)&&(i("Mod-i",mn(r)),i("Mod-I",mn(r))),(r=n.marks.code)&&i("Mod-`",mn(r)),(r=n.nodes.bullet_list)&&i("Shift-Ctrl-8",us(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",us(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Xn(r)),r=n.nodes.hard_break){let s=r,o=Yr(gl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0));i("Mod-Enter",o),i("Shift-Enter",o),md&&i("Ctrl-Enter",o)}if((r=n.nodes.list_item)&&(i("Enter",wl(r)),i("Mod-[",bl(r)),i("Mod-]",xl(r))),(r=n.nodes.paragraph)&&i("Shift-Ctrl-0",pn(r)),(r=n.nodes.code_block)&&i("Shift-Ctrl-\\",pn(r)),r=n.nodes.heading)for(let s=1;s<=6;s++)i("Shift-Ctrl-"+s,pn(r,{level:s}));if(r=n.nodes.horizontal_rule){let s=r;i("Mod-_",(o,l)=>(l&&l(o.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0))}return t}var Dl,Ol;if(typeof WeakMap<"u"){let n=new WeakMap;Dl=e=>n.get(e),Ol=(e,t)=>(n.set(e,t),t)}else{let n=[],t=0;Dl=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var z=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e=t){(s||(s=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Se=i+N*e;for(let pe=0;per&&(s+=a.attrs.colspan)}}for(let o=0;o1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function Ly(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(o)):null,i=Number(n.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let o in e){let l=e[o].getFromDOM,c=l&&l(n);c!=null&&(s[o]=c)}return s}function yd(n,e){let t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(let r in e){let i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function Fy(n){let e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(let r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>gd(r,e)}],toDOM(r){return["td",yd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>gd(r,e)}],toDOM(r){return["th",yd(r,e),0]}}}}function de(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(let t in n.nodes){let r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var zt=new le("selectingCells");function Zn(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function qy(n){for(let e=n.depth;e>0;e--){let t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function He(n){let e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function vl(n){let e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;let t=Zn(e.$head)||Hy(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Hy(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function Nl(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Jy(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function _l(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function Ed(n,e,t){let r=n.node(-1),i=z.get(r),s=n.start(-1),o=i.nextCell(n.pos-s,e,t);return o==null?null:n.node(0).resolve(s+o)}function gn(n,e,t=1){let r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function Td(n,e,t=1){let r={...n,colspan:n.colspan+t};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;ih!=t.pos-s);c.unshift(t.pos-s);let a=c.map(h=>{let d=r.nodeAt(h);if(!d)throw RangeError(`No cell with offset ${h} found`);let f=s+h+1;return new vt(l.resolve(f),l.resolve(f+d.content.size))});super(a[0].$from,a[0].$to,a),this.$anchorCell=e,this.$headCell=t}map(e,t){let r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Nl(r)&&Nl(i)&&_l(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?xt.rowSelection(r,i):s&&this.isColSelection()?xt.colSelection(r,i):new xt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=z.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let c=i.top;c0||g>0){let y=p.attrs;if(m>0&&(y=gn(y,0,m)),g>0&&(y=gn(y,y.colspan-g,g)),u.lefti.bottom){let y={...p.attrs,rowspan:Math.min(u.bottom,i.bottom)-Math.max(u.top,i.top)};u.top0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){let r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.top<=l.top?(o.top>0&&(e=c.resolve(s+i.map[o.left])),l.bottom0&&(t=c.resolve(s+i.map[l.left])),o.bottom0)return!1;let o=i+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof xt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.left<=l.left?(o.left>0&&(e=c.resolve(s+i.map[o.top*i.width])),l.right0&&(t=c.resolve(s+i.map[l.top*i.width])),o.right{e.push(ne.node(r,r+t.nodeSize,{class:"selectedCell"}))}),L.create(n.doc,e)}function Ky({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Yy({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){let s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function Gy(n,e,t){let r=(e||n).selection,i=(e||n).doc,s,o;if(r instanceof C&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=V.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=V.rowSelection(l,l)}else if(!t){let l=z.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];s=V.create(i,c+1,a)}}else r instanceof A&&Ky(r)?s=A.create(i,r.from):r instanceof A&&Yy(r)&&(s=A.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}var Xy=new le("fix-tables");function Od(n,e,t,r){let i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o{i.type.spec.tableRole=="table"&&(t=Qy(n,i,s,t))};return e?e.doc!=n.doc&&Od(e.doc,n.doc,0,r):n.doc.descendants(r),t}function Qy(n,e,t,r){let i=z.get(e);if(!i.problems)return r;r||(r=n.tr);let s=[];for(let c=0;c0){let u="cell";h.firstChild&&(u=h.firstChild.type.spec.tableRole);let p=[];for(let g=0;g0?-1:0;$y(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o0&&i0&&e.map[l-1]==c||i0?-1:0;r0(e,r,i+c)&&(c=i==0||i==e.height?null:0);for(let a=0,h=e.width*i;a0&&i0&&d==e.map[h-e.width]){let f=t.nodeAt(d).attrs;n.setNodeMarkup(n.mapping.slice(l).map(d+r),null,{...f,rowspan:f.rowspan-1}),a+=f.colspan-1}else if(i0&&t[s]==t[s-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function d0(n){return(e,t)=>{var r;let i=e.selection,s,o;if(i instanceof V){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;s=i.$anchorCell.nodeAfter,o=i.$anchorCell.pos}else{if(s=qy(i.$from),!s)return!1;o=(r=Zn(i.$from))==null?void 0:r.pos}if(s==null||o==null||s.attrs.colspan==1&&s.attrs.rowspan==1)return!1;if(t){let l=s.attrs,c=[],a=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});let h=Je(e),d=e.tr;for(let u=0;ui.table.nodeAt(c));for(let c=0;c{let p=u+s.tableStart,m=o.doc.nodeAt(p);m&&o.setNodeMarkup(p,f,m.attrs)}),r(o)}return!0}}var Qx=Ul("row",{useDeprecatedLogic:!0}),Zx=Ul("column",{useDeprecatedLogic:!0}),eS=Ul("cell",{useDeprecatedLogic:!0});function u0(n,e){if(e<0){let t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){let s=n.node(-1).child(r),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(n.index()0;r--)if(t.node(r).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(r),t.after(r)).scrollIntoView()),!0;return!1}function xs(n,e){let t=n.selection;if(!(t instanceof V))return!1;if(e){let r=n.tr,i=de(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function g0(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;let i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let c=0;c=0;o--){let{rowspan:l,colspan:c}=s.child(o).attrs;for(let a=i;a=e.length&&e.push(w.empty),t[i]r&&(f=f.type.createChecked(gn(f.attrs,f.attrs.colspan,h+f.attrs.colspan-r),f.content)),a.push(f),h+=f.attrs.colspan;for(let u=1;ui&&(d=d.type.create({...d.attrs,rowspan:Math.max(1,i-d.attrs.rowspan)},d.content)),c.push(d)}s.push(w.from(c))}t=s,e=i}return{width:n,height:e,rows:t}}function b0(n,e,t,r,i,s,o){let l=n.doc.type.schema,c=de(l),a,h;if(i>e.width)for(let d=0,f=0;de.height){let d=[];for(let p=0,m=(e.height-1)*e.width;p=e.width?!1:t.nodeAt(e.map[m+p]).type==c.header_cell;d.push(g?h||(h=c.header_cell.createAndFill()):a||(a=c.cell.createAndFill()))}let f=c.row.create(null,w.from(d)),u=[];for(let p=e.height;p{if(!i)return!1;let s=t.selection;if(s instanceof V)return Cs(t,r,S.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=vd(i,n,e);if(o==null)return!1;if(n=="horiz")return Cs(t,r,S.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),c=Ed(l,n,e),a;return c?a=S.near(c,1):e<0?a=S.near(t.doc.resolve(l.before(-1)),-1):a=S.near(t.doc.resolve(l.after(-1)),1),Cs(t,r,a)}}}function ks(n,e){return(t,r,i)=>{if(!i)return!1;let s=t.selection,o;if(s instanceof V)o=s;else{let c=vd(i,n,e);if(c==null)return!1;o=new V(t.doc.resolve(c))}let l=Ed(o.$headCell,n,e);return l?Cs(t,r,new V(o.$anchorCell,l)):!1}}function S0(n,e){let t=n.state.doc,r=Zn(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new V(r))),!0):!1}function k0(n,e,t){if(!He(n.state))return!1;let r=g0(t),i=n.state.selection;if(i instanceof V){r||(r={width:1,height:1,rows:[w.from(Il(de(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=z.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=w0(r,l.right-l.left,l.bottom-l.top),kd(n.state,n.dispatch,o,l,r),!0}else if(r){let s=vl(n.state),o=s.start(-1);return kd(n.state,n.dispatch,o,z.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function C0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Cd(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof V)s(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Zn(n.state.selection.$anchor))!=null&&((t=Tl(n,e))==null?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(c,a){let h=Tl(n,a),d=zt.getState(n.state)==null;if(!h||!_l(c,h))if(d)h=c;else return;let f=new V(c,h);if(d||!n.state.selection.eq(f)){let u=n.state.tr.setSelection(f);d&&u.setMeta(zt,c.pos),n.dispatch(u)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),zt.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(zt,-1))}function l(c){let a=c,h=zt.getState(n.state),d;if(h!=null)d=n.state.doc.resolve(h);else if(Cd(n,a.target)!=r&&(d=Tl(n,e),!d))return o();d&&s(d,a)}n.root.addEventListener("mouseup",o),n.root.addEventListener("dragstart",o),n.root.addEventListener("mousemove",l)}function vd(n,e,t){if(!(n.state.selection instanceof A))return null;let{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){let l=r.before(i),c=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(c)?l:null}}return null}function Cd(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Tl(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Zn(n.state.doc.resolve(t.pos)):null}var M0=class{constructor(n,e){this.node=n,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Rl(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,Rl(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function Rl(n,e,t,r,i,s){var o;let l=0,c=!0,a=e.firstChild,h=n.firstChild;if(h){for(let d=0,f=0;dnew t(d,e,f)),new E0(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes:s=>{let o=Ve.getState(s);return o&&o.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,o)=>{T0(s,o,n,e,r)},mouseleave:s=>{D0(s)},mousedown:(s,o)=>{O0(s,o,e)}},decorations:s=>{let o=Ve.getState(s);if(o&&o.activeHandle>-1)return U0(s,o.activeHandle)},nodeViews:{}}});return i}var E0=class Ms{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(Ve);if(r&&r.setHandle!=null)return new Ms(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Ms(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Nl(e.doc.resolve(i))||(i=-1),new Ms(i,t.dragging)}return t}};function T0(n,e,t,r,i){let s=Ve.getState(n.state);if(s&&!s.dragging){let o=I0(e.target),l=-1;if(o){let{left:c,right:a}=o.getBoundingClientRect();e.clientX-c<=t?l=Md(n,e,"left",t):a-e.clientX<=t&&(l=Md(n,e,"right",t))}if(l!=s.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=z.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}_d(n,l)}}}function D0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&_d(n,-1)}function O0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,s=Ve.getState(n.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let o=n.state.doc.nodeAt(s.activeHandle),l=N0(n,s.activeHandle,o.attrs);n.dispatch(n.state.tr.setMeta(Ve,{setDragging:{startX:e.clientX,startWidth:l}}));function c(h){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",a);let d=Ve.getState(n.state);d?.dragging&&(R0(n,d.activeHandle,Ad(d.dragging,h,t)),n.dispatch(n.state.tr.setMeta(Ve,{setDragging:null})))}function a(h){if(!h.which)return c(h);let d=Ve.getState(n.state);if(d&&d.dragging){let f=Ad(d.dragging,h,t);v0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function N0(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,c=t;if(r)for(let a=0;ajs,AbstractConnector:()=>ac,AbstractStruct:()=>yr,AbstractType:()=>W,Array:()=>On,ContentAny:()=>Kt,ContentBinary:()=>In,ContentDeleted:()=>wr,ContentDoc:()=>Rn,ContentEmbed:()=>Et,ContentFormat:()=>P,ContentJSON:()=>ki,ContentString:()=>Re,ContentType:()=>Ae,Doc:()=>We,GC:()=>ue,ID:()=>Mt,Item:()=>O,Map:()=>Nn,PermanentUserData:()=>dc,RelativePosition:()=>ot,Skip:()=>ie,Snapshot:()=>jt,Text:()=>ct,Transaction:()=>Ys,UndoManager:()=>Tn,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>st,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>at,XmlHook:()=>Si,XmlText:()=>xe,YArrayEvent:()=>Qs,YEvent:()=>Dn,YMapEvent:()=>Zs,YTextEvent:()=>eo,YXmlEvent:()=>to,applyUpdate:()=>kc,applyUpdateV2:()=>vn,cleanupYTextFormatting:()=>Ou,compareIDs:()=>kn,compareRelativePositions:()=>ro,convertUpdateFormatV1ToV2:()=>h1,convertUpdateFormatV2ToV1:()=>fu,createAbsolutePositionFromRelativePosition:()=>Tc,createDeleteSet:()=>br,createDeleteSetFromStructStore:()=>bc,createDocFromSnapshot:()=>Yw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>Ci,createSnapshot:()=>Mi,decodeRelativePosition:()=>Jw,decodeSnapshot:()=>jw,decodeSnapshotV2:()=>Zf,decodeStateVector:()=>Mc,decodeUpdate:()=>r1,decodeUpdateV2:()=>ou,diffUpdate:()=>l1,diffUpdateV2:()=>Dc,emptySnapshot:()=>Kw,encodeRelativePosition:()=>qw,encodeSnapshot:()=>Ww,encodeSnapshotV2:()=>Qf,encodeStateAsUpdate:()=>Cc,encodeStateAsUpdateV2:()=>Yf,encodeStateVector:()=>Ec,encodeStateVectorFromUpdate:()=>i1,encodeStateVectorFromUpdateV2:()=>cu,equalDeleteSets:()=>jf,equalSnapshots:()=>$w,findIndexSS:()=>ze,findRootTypeKey:()=>_n,getItem:()=>Cn,getState:()=>B,getTypeChildren:()=>p1,isDeleted:()=>Tt,isParentOf:()=>En,iterateDeletedStructs:()=>rt,logType:()=>Pw,logUpdate:()=>n1,logUpdateV2:()=>su,mergeDeleteSets:()=>Mn,mergeUpdates:()=>lu,mergeUpdatesV2:()=>yi,obfuscateUpdate:()=>c1,obfuscateUpdateV2:()=>a1,parseUpdateMeta:()=>s1,parseUpdateMetaV2:()=>au,readUpdate:()=>_w,readUpdateV2:()=>Sc,relativePositionToJSON:()=>Lw,snapshot:()=>Ai,snapshotContainsUpdate:()=>Xw,transact:()=>R,tryGc:()=>e1,typeListToArraySnapshot:()=>lo,typeMapGetAllSnapshot:()=>Mu,typeMapGetSnapshot:()=>y1});var _=()=>new Map,As=n=>{let e=_();return n.forEach((t,r)=>{e.set(r,t)}),e},$=(n,e,t)=>{let r=n.get(e);return r===void 0&&n.set(e,r=t()),r},Ud=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Vd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var Es=n=>n[n.length-1];var Bd=(n,e)=>{for(let t=0;t{for(let t=0;t{let t=new Array(n);for(let r=0;r{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}},tr=class{constructor(){this._observers=_()}on(e,t){$(this._observers,e,Ce).add(t)}once(e,t){let r=(...i)=>{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}};var fe=Math.floor;var nr=Math.abs;var De=(n,e)=>nn>e?n:e,aS=Number.isNaN,zd=Math.pow;var Ds=n=>n!==0?n<0:1/n<0;var Vl=Number.MAX_SAFE_INTEGER,hS=Number.MIN_SAFE_INTEGER,dS=1<<31;var Fd=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&fe(n)===n),fS=Number.isNaN,uS=Number.parseInt;var Bl=String.fromCharCode,pS=String.fromCodePoint,mS=Bl(65535),B0=n=>n.toLowerCase(),P0=/^\s*/g,L0=n=>n.replace(P0,""),z0=/([A-Z])/g,Pl=(n,e)=>L0(n.replace(z0,t=>`${e}${B0(t)}`));var F0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;iir.encode(n),Hd=ir?q0:F0;var rr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});rr&&rr.decode(new Uint8Array).length===1&&(rr=null);var Jd=(n,e)=>Ld(e,()=>n).join("");var wn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},F=()=>new wn;var Ns=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(Ns(n)),t=0;for(let r=0;r{let t=n.cbuf.length;t-n.cpos{let t=n.cbuf.length;n.cpos===t&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(t*2),n.cpos=0),n.cbuf[n.cpos++]=e};var cr=Q;var x=(n,e)=>{for(;e>127;)Q(n,128|127&e),e=fe(e/128);Q(n,127&e)},ni=(n,e)=>{let t=Ds(e);for(t&&(e=-e),Q(n,(e>63?128:0)|(t?64:0)|63&e),e=fe(e/64);e>0;)Q(n,(e>127?128:0)|127&e),e=fe(e/128)},Ll=new Uint8Array(3e4),J0=Ll.length/3,$0=(n,e)=>{if(e.length{let t=unescape(encodeURIComponent(e)),r=t.length;x(n,r);for(let i=0;iar(n,I(e)),ar=(n,e)=>{let t=n.cbuf.length,r=n.cpos,i=De(t-r,e.length),s=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,s>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Be(t*2,s)),n.cbuf.set(e.subarray(i)),n.cpos=s)},U=(n,e)=>{x(n,e.byteLength),ar(n,e)},zl=(n,e)=>{H0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},j0=(n,e)=>zl(n,4).setFloat32(0,e,!1),K0=(n,e)=>zl(n,8).setFloat64(0,e,!1),Y0=(n,e)=>zl(n,8).setBigInt64(0,e,!1);var Wd=new DataView(new ArrayBuffer(4)),G0=n=>(Wd.setFloat32(0,n),Wd.getFloat32(0)===n),or=(n,e)=>{switch(typeof e){case"string":Q(n,119),Qe(n,e);break;case"number":Fd(e)&&nr(e)<=2147483647?(Q(n,125),ni(n,e)):G0(e)?(Q(n,124),j0(n,e)):(Q(n,123),K0(n,e));break;case"bigint":Q(n,122),Y0(n,e);break;case"object":if(e===null)Q(n,126);else if(Zr(e)){Q(n,117),x(n,e.length);for(let t=0;t0&&x(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}};var jd=n=>{n.count>0&&(ni(n.encoder,n.count===1?n.s:-n.s),n.count>1&&x(n.encoder,n.count-2))},bn=class{constructor(){this.encoder=new wn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(jd(this),this.count=1,this.s=e)}toUint8Array(){return jd(this),I(this.encoder)}};var Kd=n=>{if(n.count>0){let e=n.diff*2+(n.count===1?0:1);ni(n.encoder,e),n.count>1&&x(n.encoder,n.count-2)}},lr=class{constructor(){this.encoder=new wn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Kd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Kd(this),I(this.encoder)}},Os=class{constructor(){this.sarr=[],this.s="",this.lensE=new bn}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){let e=new wn;return this.sarr.push(this.s),this.s="",Qe(e,this.sarr.join("")),ar(e,this.lensE.toUint8Array()),I(e)}};var Ze=n=>new Error(n),Oe=()=>{throw Ze("Method unimplemented")},j=()=>{throw Ze("Unexpected case")};var Gd=Ze("Unexpected end of array"),Xd=Ze("Integer out of Range"),hr=class{constructor(e){this.arr=e,this.pos=0}},q=n=>new hr(n),Fl=n=>n.pos!==n.arr.length;var X0=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>X0(n,k(n));var xn=n=>n.arr[n.pos++];var k=n=>{let e=0,t=1,r=n.arr.length;for(;n.posVl)throw Xd}throw Gd},ii=n=>{let e=n.arr[n.pos++],t=e&63,r=64,i=(e&64)>0?-1:1;if(!(e&128))return i*t;let s=n.arr.length;for(;n.posVl)throw Xd}throw Gd};var Q0=n=>{let e=k(n);if(e===0)return"";{let t=String.fromCodePoint(xn(n));if(--e<100)for(;e--;)t+=String.fromCodePoint(xn(n));else for(;e>0;){let r=e<1e4?e:1e4,i=n.arr.subarray(n.pos,n.pos+r);n.pos+=r,t+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(t))}},Z0=n=>rr.decode(K(n)),Le=rr?Z0:Q0;var ql=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},ew=n=>ql(n,4).getFloat32(0,!1),tw=n=>ql(n,8).getFloat64(0,!1),nw=n=>ql(n,8).getBigInt64(0,!1);var rw=[n=>{},n=>null,ii,ew,tw,nw,n=>!1,n=>!0,Le,n=>{let e=k(n),t={};for(let r=0;r{let e=k(n),t=[];for(let r=0;rrw[127-xn(n)](n),ri=class extends hr{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Fl(this)?this.count=k(this)+1:this.count=-1),this.count--,this.s}};var Sn=class extends hr{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=ii(this);let e=Ds(this.s);this.count=1,e&&(this.s=-this.s,this.count=k(this)+2)}return this.count--,this.s}};var fr=class extends hr{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=ii(this),t=e&1;this.diff=fe(e/2),this.count=1,t&&(this.count=k(this)+2)}return this.s+=this.diff,this.count--,this.s}},vs=class{constructor(e){this.decoder=new Sn(e),this.str=Le(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};var wS=crypto.subtle,Qd=crypto.getRandomValues.bind(crypto);var iw=Math.random,Hl=()=>Qd(new Uint32Array(1))[0];var Zd=n=>n[fe(iw()*n.length)],sw="10000000-1000-4000-8000"+-1e11,ef=()=>sw.replace(/[018]/g,n=>(n^Hl()&15>>n/4).toString(16));var Ne=Date.now;var Jl=n=>new Promise(n);var SS=Promise.all.bind(Promise);var $l=n=>n===void 0?null:n;var Wl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},nf=new Wl,jl=!0;try{typeof localStorage<"u"&&localStorage&&(nf=localStorage,jl=!1)}catch{}var Us=nf,rf=n=>jl||addEventListener("storage",n),sf=n=>jl||removeEventListener("storage",n);var cf=Object.assign,Vs=Object.keys,af=(n,e)=>{for(let t in n)e(n[t],t)},hf=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Kl=n=>Vs(n).length,lf=n=>Vs(n).length;var df=n=>{for(let e in n)return!1;return!0},cw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Yl=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Gl=(n,e)=>n===e||lf(n)===lf(e)&&cw(n,(t,r)=>(t!==void 0||Yl(e,r))&&e[r]===t),aw=Object.freeze,Xl=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&Xl(n[e])}return aw(n)};var oi=(n,e,t=0)=>{try{for(;tn,hw=(n,e)=>n===e;var ur=(n,e)=>{if(n==null||e==null)return hw(n,e);if(n.constructor!==e.constructor)return!1;if(n===e)return!0;switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),e=new Uint8Array(e);case Uint8Array:{if(n.byteLength!==e.byteLength)return!1;for(let t=0;te.includes(n);var kt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",pr=typeof window<"u"&&typeof document<"u"&&!kt,kS=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,et,dw=[],fw=()=>{if(et===void 0)if(kt){et=_();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");et.set(`--${Pl(e,"-")}`,t),et.set(`-${Pl(e,"-")}`,t)}})):et=_();return et},ec=n=>fw().has(n);var li=n=>kt?$l(process.env[n.toUpperCase().replaceAll("-","_")]):$l(Us.getItem(n));var uf=n=>ec("--"+n)||li(n)!==null,CS=uf("production"),uw=kt&&ff(process.env.FORCE_COLOR,["true","1","2"]),pf=uw||!ec("--no-colors")&&!uf("no-color")&&(!kt||process.stdout.isTTY)&&(!kt||ec("--color")||li("COLORTERM")!==null||(li("TERM")||"").includes("color"));var mf=n=>new Uint8Array(n),pw=(n,e,t)=>new Uint8Array(n,e,t),gf=n=>new Uint8Array(n),mw=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),yw=n=>{let e=atob(n),t=mf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return pw(e.buffer,e.byteOffset,e.byteLength)},yf=pr?mw:gw,wf=pr?yw:ww;var bf=n=>{let e=mf(n.byteLength);return e.set(n),e};var tc=class{constructor(e,t){this.left=e,this.right=t}},tt=(n,e)=>new tc(n,e);var Ct=typeof document<"u"?document:{};var MS=typeof DOMParser<"u"?new DOMParser:null;var Sf=n=>Ud(n,(e,t)=>`${t}:${e};`).join("");var AS=Ct.ELEMENT_NODE,ES=Ct.TEXT_NODE,TS=Ct.CDATA_SECTION_NODE,DS=Ct.COMMENT_NODE,OS=Ct.DOCUMENT_NODE,NS=Ct.DOCUMENT_TYPE_NODE,IS=Ct.DOCUMENT_FRAGMENT_NODE;var Ps=n=>class{constructor(t){this._=t}destroy(){n(this._)}},xw=Ps(clearTimeout),ai=(n,e)=>new xw(setTimeout(e,n)),vS=Ps(clearInterval);var _S=Ps(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var US=Ps(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var nt=Symbol;var hi=nt(),di=nt(),nc=nt(),rc=nt(),ic=nt(),fi=nt(),sc=nt(),mr=nt(),oc=nt(),Mf=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=0;for(;r0&&t.push(e.join(""));r{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=_(),i=[],s=0;for(;s0||c.length>0?(e.push("%c"+o),t.push(c)):e.push(o)}else break}}for(s>0&&(i=t,i.unshift(e.join("")));s{console.log(...Af(n)),Ef.forEach(e=>e.print(n))},lc=(...n)=>{console.warn(...Af(n)),n.unshift(mr),Ef.forEach(e=>e.print(n))};var Ef=Ce();var Tf=n=>({[Symbol.iterator](){return this},next:n}),Df=(n,e)=>Tf(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),zs=(n,e)=>Tf(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var ac=class extends er{constructor(e,t){super(),this.doc=e,this.awareness=t}},pi=class{constructor(e,t){this.clock=e,this.len=t}},$t=class{constructor(){this.clients=new Map}},rt=(n,e,t)=>e.clients.forEach((r,i)=>{let s=n.doc.store.clients.get(i);for(let o=0;o{let t=0,r=n.length-1;for(;t<=r;){let i=fe((t+r)/2),s=n[i],o=s.clock;if(o<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&Ow(t,e.clock)!==null},wc=n=>{n.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let t,r;for(t=1,r=1;t=s.clock?i.len=Be(i.len,s.clock+s.len-i.clock):(r{let e=new $t;for(let t=0;t{if(!e.clients.has(i)){let s=r.slice();for(let o=t+1;o{$(n.clients,e,()=>[]).push(new pi(t,r))},br=()=>new $t,bc=n=>{let e=br();return n.clients.forEach((t,r)=>{let i=[];for(let s=0;s0&&e.clients.set(r,i)}),e},it=(n,e)=>{x(n.restEncoder,e.clients.size),$e(e.clients.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{n.resetDsCurVal(),x(n.restEncoder,t);let i=r.length;x(n.restEncoder,i);for(let s=0;s{let e=new $t,t=k(n.restDecoder);for(let r=0;r0){let o=$(e.clients,i,()=>[]);for(let l=0;l{let r=new $t,i=k(n.restDecoder);for(let s=0;s0){let s=new Ie;return x(s.restEncoder,0),it(s,r),s.toUint8Array()}return null},jf=(n,e)=>{if(n.clients.size!==e.clients.size)return!1;for(let[t,r]of n.clients.entries()){let i=e.clients.get(t);if(i===void 0||r.length!==i.length)return!1;for(let s=0;s!0,meta:s=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Kf(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ks,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Jl(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>Jl(a=>{let h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){let e=this._item;e!==null&&!this.shouldLoad&&R(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set($e(this.subdocs).map(e=>e.guid))}transact(e,t=null){return R(this,e,t)}get(e,t=W){let r=$(this.share,e,()=>{let s=new t;return s._integrate(this,null),s}),i=r.constructor;if(t!==W&&i!==t)if(i===W){let s=new t;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,On)}getText(e=""){return this.get(e,ct)}getMap(e=""){return this.get(e,Nn)}getXmlElement(e=""){return this.get(e,Z)}getXmlFragment(e=""){return this.get(e,at)}toJSON(){let e={};return this.share.forEach((t,r)=>{e[r]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,$e(this.subdocs).forEach(t=>t.destroy());let e=this._item;if(e!==null){this._item=null;let t=e.content;t.doc=new n({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,R(e.parent.doc,r=>{let i=t.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},An=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return k(this.restDecoder)}readDsLen(){return k(this.restDecoder)}},Me=class extends An{readLeftID(){return M(k(this.restDecoder),k(this.restDecoder))}readRightID(){return M(k(this.restDecoder),k(this.restDecoder))}readClient(){return k(this.restDecoder)}readInfo(){return xn(this.restDecoder)}readString(){return Le(this.restDecoder)}readParentInfo(){return k(this.restDecoder)===1}readTypeRef(){return k(this.restDecoder)}readLen(){return k(this.restDecoder)}readAny(){return dr(this.restDecoder)}readBuf(){return bf(K(this.restDecoder))}readJSON(){return JSON.parse(Le(this.restDecoder))}readKey(){return Le(this.restDecoder)}},Ws=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=k(this.restDecoder),this.dsCurrVal}readDsLen(){let e=k(this.restDecoder)+1;return this.dsCurrVal+=e,e}},be=class extends Ws{constructor(e){super(e),this.keys=[],k(e),this.keyClockDecoder=new fr(K(e)),this.clientDecoder=new Sn(K(e)),this.leftClockDecoder=new fr(K(e)),this.rightClockDecoder=new fr(K(e)),this.infoDecoder=new ri(K(e),xn),this.stringDecoder=new vs(K(e)),this.parentInfoDecoder=new ri(K(e),xn),this.typeRefDecoder=new Sn(K(e)),this.lenDecoder=new Sn(K(e))}readLeftID(){return new Mt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Mt(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 dr(this.restDecoder)}readBuf(){return K(this.restDecoder)}readJSON(){return dr(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=Be(r,e[0].id.clock);let i=ze(e,r);x(n.restEncoder,e.length-i),n.writeClient(t),x(n.restEncoder,r);let s=e[i];s.write(n,r-s.id.clock);for(let o=i+1;o{let r=new Map;t.forEach((i,s)=>{B(e,s)>i&&r.set(s,i)}),Ei(e).forEach((i,s)=>{t.has(s)||r.set(s,0)}),x(n.restEncoder,r.size),$e(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{Nw(n,e.clients.get(i),i,s)})},Iw=(n,e)=>{let t=_(),r=k(n.restDecoder);for(let i=0;i{let r=[],i=$e(t.keys()).sort((u,p)=>u-p);if(i.length===0)return null;let s=()=>{if(i.length===0)return null;let u=t.get(i[i.length-1]);for(;u.refs.length===u.i;)if(i.pop(),i.length>0)u=t.get(i[i.length-1]);else return null;return u},o=s();if(o===null)return null;let l=new Ks,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=o.refs[o.i++],d=new Map,f=()=>{for(let u of r){let p=u.id.client,m=t.get(p);m?(m.i--,l.clients.set(p,m.refs.slice(m.i)),t.delete(p),m.i=0,m.refs=[]):l.clients.set(p,[u]),i=i.filter(g=>g!==p)}r.length=0};for(;;){if(h.constructor!==ie){let p=$(d,h.id.client,()=>B(e,h.id.client))-h.id.clock;if(p<0)r.push(h),a(h.id.client,h.id.clock-1),f();else{let m=h.getMissing(n,e);if(m!==null){r.push(h);let g=t.get(m)||{refs:[],i:0};if(g.refs.length===g.i)a(m,B(e,m)),f();else{h=g.refs[g.i++];continue}}else(p===0||p0)h=r.pop();else if(o!==null&&o.i0){let u=new Ie;return xc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},vw=(n,e)=>xc(n,e.doc.store,e.beforeState),Sc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let s=!1,o=i.doc,l=o.store,c=Iw(r,o),a=Rw(i,l,c),h=l.pendingStructs;if(h){for(let[f,u]of h.missing)if(uu)&&h.missing.set(f,u)}h.update=yi([h.update,a.update])}}else l.pendingStructs=a;let d=If(r,i,l);if(l.pendingDs){let f=new be(q(l.pendingDs));k(f.restDecoder);let u=If(f,i,l);d&&u?l.pendingDs=yi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(s){let f=l.pendingStructs.update;l.pendingStructs=null,vn(i.doc,f)}},t,!1),_w=(n,e,t)=>Sc(n,e,t,new Me(n)),vn=(n,e,t,r=be)=>{let i=q(e);Sc(i,n,t,new r(i))},kc=(n,e,t)=>vn(n,e,t,Me),Uw=(n,e,t=new Map)=>{xc(n,e.store,t),it(n,bc(e.store))},Yf=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Mc(e);Uw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Dc(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===st)return lu(i.map((s,o)=>o===0?s:fu(s)));if(t.constructor===Ie)return yi(i)}return i[0]},Cc=(n,e)=>Yf(n,e,new st),Gf=n=>{let e=new Map,t=k(n.restDecoder);for(let r=0;rGf(new An(q(n))),Ac=(n,e)=>(x(n.restEncoder,e.size),$e(e.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{x(n.restEncoder,t),x(n.restEncoder,r)}),n),Vw=(n,e)=>Ac(n,Ei(e.store)),Bw=(n,e=new gr)=>(n instanceof Map?Ac(e,n):Vw(e,n),e.toUint8Array()),Ec=n=>Bw(n,new Wt),hc=class{constructor(){this.l=[]}},Rf=()=>new hc,vf=(n,e)=>n.l.push(e),_f=(n,e)=>{let t=n.l,r=t.length;n.l=t.filter(i=>e!==i),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Xf=(n,e,t)=>oi(n.l,[e,t]),Mt=class{constructor(e,t){this.client=e,this.clock=t}},kn=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,M=(n,e)=>new Mt(n,e),Uf=(n,e)=>{x(n,e.client),x(n,e.clock)},Vf=n=>M(k(n),k(n)),_n=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw j()},En=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1},Pw=n=>{let e=[],t=n._start;for(;t;)e.push(t),t=t.right;console.log("Children: ",e),console.log("Children content: ",e.filter(r=>!r.deleted).map(r=>r.content))},dc=class{constructor(e,t=e.getMap("users")){let r=new Map;this.yusers=t,this.doc=e,this.clients=new Map,this.dss=r;let i=(s,o)=>{let l=s.get("ds"),c=s.get("ids"),a=h=>this.clients.set(h,o);l.observe(h=>{h.changes.added.forEach(d=>{d.content.getContent().forEach(f=>{f instanceof Uint8Array&&this.dss.set(o,Mn([this.dss.get(o)||br(),At(new An(q(f)))]))})})}),this.dss.set(o,Mn(l.map(h=>At(new An(q(h)))))),c.observe(h=>h.changes.added.forEach(d=>d.content.getContent().forEach(a))),c.forEach(a)};t.observe(s=>{s.keysChanged.forEach(o=>i(t.get(o),o))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let s=this.yusers,o=s.get(r);o||(o=new Nn,o.set("ids",new On),o.set("ds",new On),s.set(r,o)),o.get("ids").push([t]),s.observe(l=>{setTimeout(()=>{let c=s.get(r);if(c!==o){o=c,this.clients.forEach((d,f)=>{r===d&&o.get("ids").push([f])});let a=new Wt,h=this.dss.get(r);h&&(it(a,h),o.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=o.get("ds"),a=l.deleteSet;if(l.local&&a.clients.size>0&&i(l,a)){let h=new Wt;it(h,a),c.push([h.toUint8Array()])}})})}getUserByClientId(e){return this.clients.get(e)||null}getUserByDeletedId(e){for(let[t,r]of this.dss.entries())if(Tt(r,e))return t;return null}},ot=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},Lw=n=>{let e={};return n.type&&(e.type=n.type),n.tname&&(e.tname=n.tname),n.item&&(e.item=n.item),n.assoc!=null&&(e.assoc=n.assoc),e},Un=n=>new ot(n.type==null?null:M(n.type.client,n.type.clock),n.tname??null,n.item==null?null:M(n.item.client,n.item.clock),n.assoc==null?0:n.assoc),js=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},zw=(n,e,t=0)=>new js(n,e,t),Fs=(n,e,t)=>{let r=null,i=null;return n._item===null?i=_n(n):r=M(n._item.id.client,n._item.id.clock),new ot(r,i,e,t)},Ci=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return Fs(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Fs(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Fs(n,r.lastId,t);r=r.right}return Fs(n,null,t)},Fw=(n,e)=>{let{type:t,tname:r,item:i,assoc:s}=e;if(i!==null)x(n,0),Uf(n,i);else if(r!==null)cr(n,1),Qe(n,r);else if(t!==null)cr(n,2),Uf(n,t);else throw j();return ni(n,s),n},qw=n=>{let e=F();return Fw(e,n),I(e)},Hw=n=>{let e=null,t=null,r=null;switch(k(n)){case 0:r=Vf(n);break;case 1:t=Le(n);break;case 2:e=Vf(n)}let i=Fl(n)?ii(n):0;return new ot(e,t,r,i)},Jw=n=>Hw(q(n)),Tc=(n,e,t=!0)=>{let r=e.store,i=n.item,s=n.type,o=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(B(r,i.client)<=i.clock)return null;let h=t?gc(r,i):{item:Cn(r,i),diff:0},d=h.item;if(!(d instanceof O))return null;if(c=d.parent,c._item===null||!c._item.deleted){a=d.deleted||!d.countable?0:h.diff+(l>=0?0:1);let f=d.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(o!==null)c=e.get(o);else if(s!==null){if(B(r,s.client)<=s.clock)return null;let{item:h}=t?gc(r,s):{item:Cn(r,s)};if(h instanceof O&&h.content instanceof Ae)c=h.content.type;else return null}else throw j();l>=0?a=c._length:a=0}return zw(c,a,n.assoc)},ro=(n,e)=>n===e||n!==null&&e!==null&&n.tname===e.tname&&kn(n.item,e.item)&&kn(n.type,e.type)&&n.assoc===e.assoc,jt=class{constructor(e,t){this.ds=e,this.sv=t}},$w=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,s=e.sv;if(i.size!==s.size||t.size!==r.size)return!1;for(let[o,l]of i.entries())if(s.get(o)!==l)return!1;for(let[o,l]of t.entries()){let c=r.get(o)||[];if(l.length!==c.length)return!1;for(let a=0;a(it(e,n.ds),Ac(e,n.sv),e.toUint8Array()),Ww=n=>Qf(n,new Wt),Zf=(n,e=new Ws(q(n)))=>new jt(At(e),Gf(e)),jw=n=>Zf(n,new An(q(n))),Mi=(n,e)=>new jt(n,e),Kw=Mi(br(),new Map),Ai=n=>Mi(bc(n.store),Ei(n.store)),qt=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!Tt(e.ds,n.id),fc=(n,e)=>{let t=$(n.meta,fc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i{}),t.add(e))},Yw=(n,e,t=new We)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,s=new Ie;return n.transact(o=>{let l=0;r.forEach(c=>{c>0&&l++}),x(s.restEncoder,l);for(let[c,a]of r){if(a===0)continue;a{let r=new t(q(e)),i=new lt(r,!1);for(let o=i.curr;o!==null;o=i.next())if((n.sv.get(o.id.client)||0)Gw(n,e,Me),Ks=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ei=n=>{let e=new Map;return n.clients.forEach((t,r)=>{let i=t[t.length-1];e.set(r,i.id.clock+i.length)}),e},B=(n,e)=>{let t=n.clients.get(e);if(t===void 0)return 0;let r=t[t.length-1];return r.id.clock+r.length},eu=(n,e)=>{let t=n.clients.get(e.id.client);if(t===void 0)t=[],n.clients.set(e.id.client,t);else{let r=t[t.length-1];if(r.id.clock+r.length!==e.id.clock)throw j()}t.push(e)},ze=(n,e)=>{let t=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===e)return r;let o=fe(e/(s+i.length-1)*r);for(;t<=r;){if(i=n[o],s=i.id.clock,s<=e){if(e{let t=n.clients.get(e.client);return t[ze(t,e.clock)]},Cn=Qw,uc=(n,e,t)=>{let r=ze(e,t),i=e[r];return i.id.clock{let t=n.doc.store.clients.get(e.client);return t[uc(n,t,e.clock)]},Bf=(n,e,t)=>{let r=e.clients.get(t.client),i=ze(r,t.clock),s=r[i];return t.clock!==s.id.clock+s.length-1&&s.constructor!==ue&&r.splice(i+1,0,no(n,s,t.clock-s.id.clock+1)),s},Zw=(n,e,t)=>{let r=n.clients.get(e.id.client);r[ze(r,e.id.clock)]=t},tu=(n,e,t,r,i)=>{if(r===0)return;let s=t+r,o=uc(n,e,t),l;do l=e[o++],se.deleteSet.clients.size===0&&!Vd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(wc(e.deleteSet),vw(n,e),it(n,e.deleteSet),!0),Lf=(n,e,t)=>{let r=e._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&$(n.changed,e,Ce).add(t)},Js=(n,e)=>{let t=n[e],r=n[e-1],i=e;for(;i>0;t=r,r=n[--i-1]){if(r.deleted===t.deleted&&r.constructor===t.constructor&&r.mergeWith(t)){t instanceof O&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,r);continue}break}let s=e-i;return s&&n.splice(e+1-s,s),s},nu=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){let l=i[o],c=l.clock+l.len;for(let a=ze(s,l.clock),h=s[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let s=t.length-1;s>=0;s--){let o=t[s],l=De(i.length-1,1+ze(i,o.clock+o.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=o.clock;a=i[c])c-=1+Js(i,c)}})},e1=(n,e,t)=>{nu(n,e,t),ru(n,e)},iu=(n,e)=>{if(el.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(t,c)})),l.push(()=>{t.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,d)=>h.path.length-d.path.length),Xf(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),oi(l,[]),t._needFormattingCleanup&&S1(t)}finally{r.gc&&nu(s,i,r.gcFilter),ru(s,i),t.afterState.forEach((h,d)=>{let f=t.beforeState.get(d)||0;if(f!==h){let u=i.clients.get(d),p=Be(ze(u,f),1);for(let m=u.length-1;m>=p;)m-=1+Js(u,m)}});for(let h=o.length-1;h>=0;h--){let{client:d,clock:f}=o[h].id,u=i.clients.get(d),p=ze(u,f);p+11||p>0&&Js(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(Ls(mr,hi,"[yjs] ",di,fi,"Changed the client-id because another client seems to be using it."),r.clientID=Kf()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new st;Pf(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;Pf(h,t)&&r.emit("updateV2",[h.toUint8Array(),t.origin,r,t])}let{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=t;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=r.clientID,h.collectionid==null&&(h.collectionid=r.collectionid),r.subdocs.add(h)}),a.forEach(h=>r.subdocs.delete(h)),r.emit("subdocs",[{loaded:c,added:l,removed:a},r,t]),a.forEach(h=>h.destroy())),n.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):iu(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new Ys(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=e(n._transaction)}finally{if(s){let l=n._transaction===i[0];n._transaction=null,l&&iu(i,0)}}return o},pc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},zf=(n,e,t)=>{rt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>En(i,r))&&vc(r,!1)})},Ff=(n,e,t)=>{let r=null,i=n.doc,s=n.scope;R(i,l=>{for(;e.length>0&&n.currStackItem===null;){let c=i.store,a=e.pop(),h=new Set,d=[],f=!1;rt(l,a.insertions,u=>{if(u instanceof O){if(u.redone!==null){let{item:p,diff:m}=gc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&s.some(p=>En(p,u))&&d.push(u)}}),rt(l,a.deletions,u=>{u instanceof O&&s.some(p=>En(p,u))&&!Tt(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=Iu(l,u,h,a.insertions,n.ignoreRemoteMapChanges,n)!==null||f});for(let u=d.length-1;u>=0;u--){let p=d[u];n.deleteFilter(p)&&(p.delete(l),f=!0)}n.currStackItem=f?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=l},n);let o=n.currStackItem;if(o!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:o,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return o},Tn=class extends er{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=Zr(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,s.add(this),this.trackedOrigins=s,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=t,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(g=>c.changedParentTypes.has(g))||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;let a=this.undoing,h=this.redoing,d=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);let f=new $t;c.afterState.forEach((g,y)=>{let E=c.beforeState.get(y)||0,N=g-E;N>0&&mi(f,y,E,N)});let u=Ne(),p=!1;if(this.lastChange>0&&u-this.lastChange0&&!a&&!h){let g=d[d.length-1];g.deletions=Mn([g.deletions,c.deleteSet]),g.insertions=Mn([g.insertions,f])}else d.push(new pc(c.deleteSet,f)),p=!0;!a&&!h&&(this.lastChange=u),rt(c,c.deleteSet,g=>{g instanceof O&&this.scope.some(y=>En(y,g))&&vc(g,!0)});let m=[{stackItem:d[d.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];p?this.emit("stack-item-added",m):this.emit("stack-item-updated",m)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){e=Zr(e)?e:[e],e.forEach(t=>{this.scope.every(r=>r!==t)&&(t.doc!==this.doc&&lc("[yjs#509] Not same Y.Doc"),this.scope.push(t))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(r=>{e&&(this.undoStack.forEach(i=>zf(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>zf(r,this,i)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Ff(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Ff(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}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*t1(n){let e=k(n.restDecoder);for(let t=0;tsu(n,Me),su=(n,e=be)=>{let t=[],r=new e(q(n)),i=new lt(r,!1);for(let o=i.curr;o!==null;o=i.next())t.push(o);Ls("Structs: ",t);let s=At(r);Ls("DeleteSet: ",s)},r1=n=>ou(n,Me),ou=(n,e=be)=>{let t=[],r=new e(q(n)),i=new lt(r,!1);for(let s=i.curr;s!==null;s=i.next())t.push(s);return{structs:t,ds:At(r)}},gi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},lu=n=>yi(n,Me,st),cu=(n,e=gr,t=be)=>{let r=new e,i=new lt(new t(q(n)),!1),s=i.curr;if(s!==null){let o=0,l=s.id.client,c=s.id.clock!==0,a=c?0:s.id.clock+s.length;for(;s!==null;s=i.next())l!==s.id.client&&(a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a)),l=s.id.client,a=0,c=s.id.clock!==0),s.constructor===ie&&(c=!0),c||(a=s.id.clock+s.length);a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a));let h=F();return x(h,o),Yd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},i1=n=>cu(n,Wt,Me),au=(n,e=be)=>{let t=new Map,r=new Map,i=new lt(new e(q(n)),!1),s=i.curr;if(s!==null){let o=s.id.client,l=s.id.clock;for(t.set(o,l);s!==null;s=i.next())o!==s.id.client&&(r.set(o,l),t.set(s.id.client,s.id.clock),o=s.id.client),l=s.id.clock+s.length;r.set(o,l)}return{from:t,to:r}},s1=n=>au(n,Me),o1=(n,e)=>{if(n.constructor===ue){let{client:t,clock:r}=n.id;return new ue(M(t,r+e),n.length-e)}else if(n.constructor===ie){let{client:t,clock:r}=n.id;return new ie(M(t,r+e),n.length-e)}else{let t=n,{client:r,clock:i}=t.id;return new O(M(r,i+e),null,M(r,i+e-1),null,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e))}},yi=(n,e=be,t=Ie)=>{if(n.length===1)return n[0];let r=n.map(h=>new e(q(h))),i=r.map(h=>new lt(h,!0)),s=null,o=new t,l=new gi(o);for(;i=i.filter(f=>f.curr!==null),i.sort((f,u)=>{if(f.curr.id.client===u.curr.id.client){let p=f.curr.id.clock-u.curr.id.clock;return p===0?f.curr.constructor===u.curr.constructor?0:f.curr.constructor===ie?1:-1:p}else return u.curr.id.client-f.curr.id.client}),i.length!==0;){let h=i[0],d=h.curr.id.client;if(s!==null){let f=h.curr,u=!1;for(;f!==null&&f.id.clock+f.length<=s.struct.id.clock+s.struct.length&&f.id.client>=s.struct.id.client;)f=h.next(),u=!0;if(f===null||f.id.client!==d||u&&f.id.clock>s.struct.id.clock+s.struct.length)continue;if(d!==s.struct.id.client)Ht(l,s.struct,s.offset),s={struct:f,offset:0},h.next();else if(s.struct.id.clock+s.struct.length0&&(s.struct.constructor===ie?s.struct.length-=p:f=o1(f,p)),s.struct.mergeWith(f)||(Ht(l,s.struct,s.offset),s={struct:f,offset:0},h.next())}}else s={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===s.struct.id.clock+s.struct.length&&f.constructor!==ie;f=h.next())Ht(l,s.struct,s.offset),s={struct:f,offset:0}}s!==null&&(Ht(l,s.struct,s.offset),s=null),Oc(l);let c=r.map(h=>At(h)),a=Mn(c);return it(o,a),o.toUint8Array()},Dc=(n,e,t=be,r=Ie)=>{let i=Mc(e),s=new r,o=new gi(s),l=new t(q(n)),c=new lt(l,!1);for(;c.curr;){let h=c.curr,d=h.id.client,f=i.get(d)||0;if(c.curr.constructor===ie){c.next();continue}if(h.id.clock+h.length>f)for(Ht(o,h,Be(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Ht(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=f;)c.next()}Oc(o);let a=At(l);return it(s,a),s.toUint8Array()},l1=(n,e)=>Dc(n,e,Me,st),hu=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:I(n.encoder.restEncoder)}),n.encoder.restEncoder=F(),n.written=0)},Ht=(n,e,t)=>{n.written>0&&n.currClient!==e.id.client&&hu(n),n.written===0&&(n.currClient=e.id.client,n.encoder.writeClient(e.id.client),x(n.encoder.restEncoder,e.id.clock+t)),e.write(n.encoder,t),n.written++},Oc=n=>{hu(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(q(n)),s=new lt(i,!1),o=new r,l=new gi(o);for(let a=s.curr;a!==null;a=s.next())Ht(l,e(a),0);Oc(l);let c=At(i);return it(o,c),o.toUint8Array()},du=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=_(),s=_(),o=_(),l=_();return l.set(null,null),c=>{switch(c.constructor){case ue:case ie:return c;case O:{let a=c,h=a.content;switch(h.constructor){case wr:break;case Ae:{if(t){let d=h.type;d instanceof Z&&(d.nodeName=$(s,d.nodeName,()=>"node-"+r)),d instanceof Si&&(d.hookName=$(s,d.hookName,()=>"hook-"+r))}break}case Kt:{let d=h;d.arr=d.arr.map(()=>r);break}case In:{let d=h;d.content=new Uint8Array([r]);break}case Rn:{let d=h;e&&(d.opts={},d.doc.guid=r+"");break}case Et:{let d=h;d.embed={};break}case P:{let d=h;n&&(d.key=$(o,d.key,()=>r+""),d.value=$(l,d.value,()=>({i:r})));break}case ki:{let d=h;d.arr=d.arr.map(()=>r);break}case Re:{let d=h;d.str=Jd(r%10+"",d.str.length);break}default:j()}return a.parentSub&&(a.parentSub=$(i,a.parentSub,()=>r+"")),r++,c}default:j()}}},c1=(n,e)=>io(n,du(e),Me,st),a1=(n,e)=>io(n,du(e),be,Ie),h1=n=>io(n,Ql,Me,Ie),fu=n=>io(n,Ql,be,st),qf="You must not compute changes after the event-handler fired.",Dn=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=d1(this.currentTarget,this.target))}deletes(e){return Tt(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ze(qf);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let s=t._map.get(i),o,l;if(this.adds(s)){let c=s.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(s))if(c!==null&&this.deletes(c))o="delete",l=Es(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Es(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(s))o="delete",l=Es(s.content.getContent());else return;e.set(i,{action:o,oldValue:l})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ze(qf);let t=this.target,r=Ce(),i=Ce(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&s.push(l)};for(let a=t._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,i.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),r.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=e}return e}},d1=(n,e)=>{let t=[];for(;e._item!==null&&e!==n;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)!i.deleted&&i.countable&&(r+=i.length),i=i.right;t.unshift(r)}e=e._item.parent}return t},se=()=>{lc("Invalid access: Add Yjs type to a document before reading data.")},uu=80,Nc=0,mc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Nc++}},f1=n=>{n.timestamp=Nc++},pu=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Nc++},u1=(n,e,t)=>{if(n.length>=uu){let r=n.reduce((i,s)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((s,o)=>nr(e-s.index)e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return t!==null&&nr(t.index-i){for(let r=n.length-1;r>=0;r--){let i=n[r];if(t>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){n.splice(r,1);continue}i.p=s,s.marker=!0}(e0&&e===i.index)&&(i.index=Be(e,i.index+t))}},p1=n=>{n.doc??se();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},oo=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Xf(r._eH,t,e)},W=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Rf(),this._dEH=Rf(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Oe()}clone(){throw Oe()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){vf(this._eH,e)}observeDeep(e){vf(this._dEH,e)}unobserve(e){_f(this._eH,e)}unobserveDeep(e){_f(this._dEH,e)}toJSON(){}},mu=(n,e,t)=>{n.doc??se(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],s=n._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){let o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let l=e;l0;l++)i.push(o[l]),r--;e=0}}s=s.right}return i},gu=n=>{n.doc??se();let e=[],t=n._start;for(;t!==null;){if(t.countable&&!t.deleted){let r=t.content.getContent();for(let i=0;i{let t=[],r=n._start;for(;r!==null;){if(r.countable&&qt(r,e)){let i=r.content.getContent();for(let s=0;s{let t=0,r=n._start;for(n.doc??se();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let s=0;s{let t=[];return bi(n,(r,i)=>{t.push(e(r,i,n))}),t},m1=n=>{let e=n._start,t=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),r=0,e=e.right}let i=t[r++];return t.length<=r&&(t=null),{done:!1,value:i}}}},wu=(n,e)=>{n.doc??se();let t=so(n,e),r=n._start;for(t!==null&&(r=t.p,e-=t.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e{let i=t,s=n.doc,o=s.clientID,l=s.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Kt(a)),i.integrate(n,0),a=[])};r.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new In(new Uint8Array(d))),i.integrate(n,0);break;case We:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Rn(d)),i.integrate(n,0);break;default:if(d instanceof W)i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Ae(d)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},bu=()=>Ze("Length exceeded!"),xu=(n,e,t,r)=>{if(t>e._length)throw bu();if(t===0)return e._searchMarker&&wi(e._searchMarker,t,r.length),Gs(n,e,null,r);let i=t,s=so(e,t),o=e._start;for(s!==null&&(o=s.p,t-=s.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Gs(n,e,i,t)},Su=(n,e,t,r)=>{if(r===0)return;let i=t,s=r,o=so(e,t),l=e._start;for(o!==null&&(l=o.p,t-=o.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw bu();e._searchMarker&&wi(e._searchMarker,i,-s+r)},Xs=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},Ic=(n,e,t,r)=>{let i=e._map.get(t)||null,s=n.doc,o=s.clientID,l;if(r==null)l=new Kt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:l=new Kt([r]);break;case Uint8Array:l=new In(r);break;case We:l=new Rn(r);break;default:if(r instanceof W)l=new Ae(r);else throw new Error("Unexpected content type")}new O(M(o,B(s.store,o)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},Rc=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},ku=n=>{let e={};return n.doc??se(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Cu=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted},y1=(n,e,t)=>{let r=n._map.get(e)||null;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;return r!==null&&qt(r,t)?r.content.getContent()[r.length-1]:void 0},Mu=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&qt(s,e)&&(t[i]=s.content.getContent()[s.length-1])}),t},qs=n=>(n.doc??se(),Df(n._map.entries(),e=>!e[1].deleted)),Qs=class extends Dn{},On=class n extends W{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){let t=new n;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof W?t.clone():t)),e}get length(){return this.doc??se(),this._length}_callObserver(e,t){super._callObserver(e,t),oo(this,e,new Qs(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{xu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{g1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Su(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return wu(this,e)}toArray(){return gu(this)}slice(e=0,t=this.length){return mu(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return yu(this,e)}forEach(e){bi(this,e)}[Symbol.iterator](){return m1(this)}_write(e){e.writeTypeRef(P1)}},w1=n=>new On,Zs=class extends Dn{constructor(e,t,r){super(e,t),this.keysChanged=r}},Nn=class n extends W{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return this.forEach((t,r)=>{e.set(r,t instanceof W?t.clone():t)}),e}_callObserver(e,t){oo(this,e,new Zs(this,e,t))}toJSON(){this.doc??se();let e={};return this._map.forEach((t,r)=>{if(!t.deleted){let i=t.content.getContent()[t.length-1];e[r]=i instanceof W?i.toJSON():i}}),e}get size(){return[...qs(this)].length}keys(){return zs(qs(this),e=>e[0])}values(){return zs(qs(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return zs(qs(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??se(),this._map.forEach((t,r)=>{t.deleted||e(t.content.getContent()[t.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?R(this.doc,t=>{Xs(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{Ic(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Rc(this,e)}has(e){return Cu(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){Xs(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(L1)}},b1=n=>new Nn,Jt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Gl(n,e),xi=class{constructor(e,t,r,i){this.left=e,this.right=t,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&j(),this.right.content.constructor){case P:this.right.deleted||xr(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}},Hf=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case P:e.right.deleted||xr(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t{let i=new Map,s=r?so(e,t):null;if(s){let o=new xi(s.p.left,s.p,s.index,i);return Hf(n,o,t-s.index)}else{let o=new xi(null,e._start,0,i);return Hf(n,o,t)}},Au=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===P&&Jt(r.get(t.right.content.key),t.right.content.value));)t.right.deleted||r.delete(t.right.content.key),t.forward();let i=n.doc,s=i.clientID;r.forEach((o,l)=>{let c=t.left,a=t.right,h=new O(M(s,B(i.store,s)),c,c&&c.lastId,a,a&&a.id,e,null,new P(l,o));h.integrate(n,0),t.right=h,t.forward()})},xr=(n,e)=>{let{key:t,value:r}=e;r===null?n.delete(t):n.set(t,r)},Eu=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===P&&Jt(e[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},Tu=(n,e,t,r)=>{let i=n.doc,s=i.clientID,o=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Jt(a,c)){o.set(l,a);let{left:h,right:d}=t;t.right=new O(M(s,B(i.store,s)),h,h&&h.lastId,d,d&&d.id,e,null,new P(l,c)),t.right.integrate(n,0),t.forward()}}return o},cc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let s=n.doc,o=s.clientID;Eu(t,i);let l=Tu(n,e,t,i),c=r.constructor===String?new Re(r):r instanceof W?new Ae(r):new Et(r),{left:a,right:h,index:d}=t;e._searchMarker&&wi(e._searchMarker,t.index,c.getLength()),h=new O(M(o,B(s.store,o)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=d,t.forward(),Au(n,e,t,l)},Jf=(n,e,t,r,i)=>{let s=n.doc,o=s.clientID;Eu(t,i);let l=Tu(n,e,t,i);e:for(;t.right!==null&&(r>0||l.size>0&&(t.right.deleted||t.right.content.constructor===P));){if(!t.right.deleted)switch(t.right.content.constructor){case P:{let{key:c,value:a}=t.right.content,h=i[c];if(h!==void 0){if(Jt(h,a))l.delete(c);else{if(r===0)break e;l.set(c,a)}t.right.delete(n)}else t.currentAttributes.set(c,a);break}default:r0){let c="";for(;r>0;r--)c+=` -`;t.right=new O(M(o,B(s.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new Re(c)),t.right.integrate(n,0),t.forward()}Au(n,e,t,l)},Du=(n,e,t,r,i)=>{let s=e,o=_();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===P){let a=s.content;o.set(a.key,a)}s=s.right}let l=0,c=!1;for(;e!==s;){if(t===e&&(c=!0),!e.deleted){let a=e.content;switch(a.constructor){case P:{let{key:h,value:d}=a,f=r.get(h)??null;(o.get(h)!==a||f===d)&&(e.delete(n),l++,!c&&(i.get(h)??null)===d&&f!==d&&(f===null?i.delete(h):i.set(h,f))),!c&&!e.deleted&&xr(i,a);break}}}e=e.right}return l},x1=(n,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;let t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===P){let r=e.content.key;t.has(r)?e.delete(n):t.add(r)}e=e.left}},Ou=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,s=_(),o=As(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case P:xr(o,i.content);break;default:e+=Du(t,r,i,s,o),s=As(o),r=i;break}i=i.right}}),e},S1=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let s=n.beforeState.get(r)||0;i!==s&&tu(n,t.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===P&&o.constructor!==ue&&e.add(o.parent)})}R(t,r=>{rt(n,n.deleteSet,i=>{if(i instanceof ue||!i.parent._hasFormatting||e.has(i.parent))return;let s=i.parent;i.content.constructor===P?e.add(s):x1(r,i)});for(let i of e)Ou(i)})},$f=(n,e,t)=>{let r=t,i=As(e.currentAttributes),s=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Ae:case Et:case Re:t{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];R(e,r=>{let i=new Map,s=new Map,o=this.target._start,l=null,c={},a="",h=0,d=0,f=()=>{if(l!==null){let u=null;switch(l){case"delete":d>0&&(u={delete:d}),d=0;break;case"insert":(typeof a=="object"||a.length>0)&&(u={insert:a},i.size>0&&(u.attributes={},i.forEach((p,m)=>{p!==null&&(u.attributes[m]=p)}))),a="";break;case"retain":h>0&&(u={retain:h},df(c)||(u.attributes=cf({},c))),h=0;break}u&&t.push(u),l=null}};for(;o!==null;){switch(o.content.constructor){case Ae:case Et:this.adds(o)?this.deletes(o)||(f(),l="insert",a=o.content.getContent()[0],f()):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=1):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case Re:this.adds(o)?this.deletes(o)||(l!=="insert"&&(f(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=o.length):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=o.length);break;case P:{let{key:u,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let m=i.get(u)??null;Jt(m,p)?p!==null&&o.delete(r):(l==="retain"&&f(),Jt(p,s.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(o)){s.set(u,p);let m=i.get(u)??null;Jt(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!o.deleted){s.set(u,p);let m=c[u];m!==void 0&&(Jt(m,p)?m!==null&&o.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}o.deleted||(l==="insert"&&f(),xr(i,o.content));break}}o=o.right}for(f();t.length>0;){let u=t[t.length-1];if(u.retain!==void 0&&u.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},ct=class n extends W{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??se(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);let r=new eo(this,e,t);oo(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??se();let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Re&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?R(this.doc,r=>{let i=new xi(null,this._start,0,new Map);for(let s=0;s0)&&cc(r,this,i,l,o.attributes||{})}else o.retain!==void 0?Jf(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&$f(r,i,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??se();let i=[],s=new Map,o=this.doc,l="",c=this._start;function a(){if(l.length>0){let d={},f=!1;s.forEach((p,m)=>{f=!0,d[m]=p});let u={insert:l};f&&(u.attributes=d),i.push(u),l=""}}let h=()=>{for(;c!==null;){if(qt(c,e)||t!==void 0&&qt(c,t))switch(c.content.constructor){case Re:{let d=s.get("ychange");e!==void 0&&!qt(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),s.set("ychange",r?r("removed",c.id):{type:"removed"})):t!==void 0&&!qt(c,t)?(d===void 0||d.user!==c.id.client||d.type!=="added")&&(a(),s.set("ychange",r?r("added",c.id):{type:"added"})):d!==void 0&&(a(),s.delete("ychange")),l+=c.content.str;break}case Ae:case Et:{a();let d={insert:c.content.getContent()[0]};if(s.size>0){let f={};d.attributes=f,s.forEach((u,p)=>{f[p]=u})}i.push(d);break}case P:qt(c,e)&&(a(),xr(s,c.content));break}c=c.right}a()};return e||t?R(o,d=>{e&&fc(d,e),t&&fc(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,s=>{let o=Hs(s,this,e,!r);r||(r={},o.currentAttributes.forEach((l,c)=>{r[c]=l})),cc(s,this,o,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,s=>{let o=Hs(s,this,e,!r);cc(s,this,o,t,r||{})}):this._pending.push(()=>this.insertEmbed(e,t,r||{}))}delete(e,t){if(t===0)return;let r=this.doc;r!==null?R(r,i=>{$f(i,Hs(i,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,r){if(t===0)return;let i=this.doc;i!==null?R(i,s=>{let o=Hs(s,this,e,!1);o.right!==null&&Jf(s,this,o,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xs(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{Ic(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Rc(this,e)}getAttributes(){return ku(this)}_write(e){e.writeTypeRef(z1)}},k1=n=>new ct,ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??se()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===Z||t.constructor===at)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},at=class n extends W{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof W?t.clone():t)),e}get length(){return this.doc??se(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new ui(this,e)}querySelector(e){e=e.toUpperCase();let r=new ui(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),$e(new ui(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){oo(this,e,new to(this,t,e))}toString(){return yu(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},r){let i=e.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),bi(this,s=>{i.insertBefore(s.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{xu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)R(this.doc,r=>{let i=e&&e instanceof W?e._item:e;Gs(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(s=>s===e)+1;if(i===0&&e!==null)throw Ze("Reference item not found");r.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Su(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return gu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return wu(this,e)}slice(e=0,t=this.length){return mu(this,e,t)}forEach(e){bi(this,e)}_write(e){e.writeTypeRef(q1)}},C1=n=>new at,Z=class n extends at{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r)}),this._prelimAttrs=null}_copy(){return new n(this.nodeName)}clone(){let e=new n(this.nodeName),t=this.getAttributes();return af(t,(r,i)=>{typeof r=="string"&&e.setAttribute(i,r)}),e.insert(0,this.toArray().map(r=>r instanceof W?r.clone():r)),e}toString(){let e=this.getAttributes(),t=[],r=[];for(let l in e)r.push(l);r.sort();let i=r.length;for(let l=0;l0?" "+t.join(" "):"";return`<${s}${o}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xs(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{Ic(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Rc(this,e)}hasAttribute(e){return Cu(this,e)}getAttributes(e){return e?Mu(this,e):ku(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),s=this.getAttributes();for(let o in s){let l=s[o];typeof l=="string"&&i.setAttribute(o,l)}return bi(this,o=>{i.appendChild(o.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(F1),e.writeKey(this.nodeName)}},M1=n=>new Z(n.readKey()),to=class extends Dn{constructor(e,t,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}},Si=class n extends Nn{constructor(e){super(),this.hookName=e}_copy(){return new n(this.hookName)}clone(){let e=new n(this.hookName);return this.forEach((t,r)=>{e.set(r,t)}),e}toDOM(e=document,t={},r){let i=t[this.hookName],s;return i!==void 0?s=i.createDom(this):s=document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(s,this),s}_write(e){e.writeTypeRef(H1),e.writeKey(this.hookName)}},A1=n=>new Si(n.readKey()),xe=class n extends ct{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,r){let i=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(i,this),i}toString(){return this.toDelta().map(e=>{let t=[];for(let i in e.attributes){let s=[];for(let o in e.attributes[i])s.push({key:o,value:e.attributes[i][o]});s.sort((o,l)=>o.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(J1)}},E1=n=>new xe,yr=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Oe()}mergeWith(e){return!1}write(e,t,r){throw Oe()}integrate(e,t){throw Oe()}},T1=0,ue=class extends yr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),eu(e.doc.store,this)}write(e,t){e.writeInfo(T1),e.writeLen(this.length-t)}getMissing(e,t){return null}},In=class n{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new n(this.content)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},D1=n=>new In(n.readBuf()),wr=class n{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.len)}splice(e){let t=new n(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){mi(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},O1=n=>new wr(n.readLen()),Nu=(n,e)=>new We({guid:n,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),Rn=class n{constructor(e){e._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=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new n(Nu(this.doc.guid,this.opts))}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},N1=n=>new Rn(Nu(n.readString(),n.readAny())),Et=class n{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new n(this.embed)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},I1=n=>new Et(n.readJSON()),P=class n{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.key,this.value)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){let r=t.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},R1=n=>new P(n.readKey(),n.readJSON()),ki=class n{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new n(this.arr)}splice(e){let t=new n(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let r=this.arr.length;e.writeLen(r-t);for(let i=t;i{let e=n.readLen(),t=[];for(let r=0;r{let e=n.readLen(),t=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"\uFFFD",t.str="\uFFFD"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},V1=n=>new Re(n.readString()),B1=[w1,b1,k1,M1,C1,A1,E1],P1=0,L1=1,z1=2,F1=3,q1=4,H1=5,J1=6,Ae=class n{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new n(this.type._copy())}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},$1=n=>new Ae(B1[n.readTypeRef()](n)),gc=(n,e)=>{let t=e,r=0,i;do r>0&&(t=M(t.client,t.clock+r)),i=Cn(n,t),r=t.clock-i.id.clock,t=i.redone;while(t!==null&&i instanceof O);return{item:i,diff:r}},vc=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},no=(n,e,t)=>{let{client:r,clock:i}=e.id,s=new O(M(r,i+t),e,M(r,i+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=M(e.redone.client,e.redone.clock+t)),e.right=s,s.right!==null&&(s.right.left=s),n._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=t,s},Wf=(n,e)=>Pd(n,t=>Tt(t.deletions,e)),Iu=(n,e,t,r,i,s)=>{let o=n.doc,l=o.store,c=o.clientID,a=e.redone;if(a!==null)return we(n,a);let h=e.parent._item,d=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!t.has(h)||Iu(n,h,t,r,i,s)===null))return null;for(;h.redone!==null;)h=we(n,h.redone)}let u=h===null?e.parent:h.content.type;if(e.parentSub===null){for(d=e.left,f=e;d!==null;){let y=d;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:we(n,y.redone);if(y!==null&&y.parent._item===h){d=y;break}d=d.left}for(;f!==null;){let y=f;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:we(n,y.redone);if(y!==null&&y.parent._item===h){f=y;break}f=f.right}}else if(f=null,e.right&&!i){for(d=e;d!==null&&d.right!==null&&(d.right.redone||Tt(r,d.right.id)||Wf(s.undoStack,d.right.id)||Wf(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=we(n,d.redone);if(d&&d.right!==null)return null}else d=u._map.get(e.parentSub)||null;let p=B(l,c),m=M(c,p),g=new O(m,d,d&&d.lastId,f,f&&f.id,u,e.parentSub,e.content.copy());return e.redone=m,vc(g,!0),g.integrate(n,0),g},O=class n extends yr{constructor(e,t,r,i,s,o,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=s,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Mt&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Bf(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=we(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ue||this.right&&this.right.constructor===ue)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===n&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===n&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Mt){let r=Cn(t,this.parent);r.constructor===ue?this.parent=null:this.parent=r.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Bf(e,e.doc.store,M(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;let s=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),s.add(i),kn(this.origin,i.origin)){if(i.id.client{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),mi(e.deleteSet,this.id.client,this.id.clock,this.length),Lf(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?Zw(e,this,new ue(this.id,this.length)):this.content=new wr(this.length)}write(e,t){let r=t>0?M(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(s===null?0:32);if(e.writeInfo(o),r!==null&&e.writeLeftID(r),i!==null&&e.writeRightID(i),r===null&&i===null){let l=this.parent;if(l._item!==void 0){let c=l._item;if(c===null){let a=_n(l);e.writeParentInfo(!0),e.writeString(a)}else e.writeParentInfo(!1),e.writeLeftID(c.id)}else l.constructor===String?(e.writeParentInfo(!0),e.writeString(l)):l.constructor===Mt?(e.writeParentInfo(!1),e.writeLeftID(l)):j();s!==null&&e.writeString(s)}this.content.write(e,t)}},Ru=(n,e)=>W1[e&31](n),W1=[()=>{j()},O1,v1,D1,V1,I1,R1,$1,U1,N1,()=>{j()}],j1=10,ie=class extends yr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){j()}write(e,t){e.writeInfo(j1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},vu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},_u="__ $YJS$ __";vu[_u]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");vu[_u]=!0;var Uu=new Map,_c=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:wf(t.newValue||"")}),rf(this._onChange)}postMessage(e){Us.setItem(this.room,yf(gf(e)))}close(){sf(this._onChange)}},K1=typeof BroadcastChannel>"u"?_c:BroadcastChannel,Uc=n=>$(Uu,n,()=>{let e=Ce(),t=new K1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Vu=(n,e)=>(Uc(n).subs.add(e),e),Bu=(n,e)=>{let t=Uc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Uu.delete(n)),r},Vn=(n,e,t=null)=>{let r=Uc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var Pu=0,co=1,Lu=2,ao=(n,e)=>{x(n,Pu);let t=Ec(e);U(n,t)},Vc=(n,e,t)=>{x(n,co),U(n,Cc(e,t))},G1=(n,e,t)=>Vc(e,t,K(n)),zu=(n,e,t)=>{try{kc(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},Fu=(n,e)=>{x(n,Lu),U(n,e)},X1=zu,qu=(n,e,t,r)=>{let i=k(n);switch(i){case Pu:G1(n,e,t);break;case co:zu(n,t,r);break;case Lu:X1(n,t,r);break;default:throw new Error("Unknown message type")}return i};var Z1=0;var Hu=(n,e,t)=>{switch(k(n)){case Z1:t(e,Le(n))}};var Bc=3e4,ho=class extends tr{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let t=Ne();this.getLocalState()!==null&&Bc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,s)=>{s!==this.clientID&&Bc<=t-i.lastUpdated&&this.states.has(s)&&r.push(s)}),r.length>0&&fo(this,r,"timeout")},fe(Bc/10)),e.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(e){let t=this.clientID,r=this.meta.get(t),i=r===void 0?0:r.clock+1,s=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Ne()});let o=[],l=[],c=[],a=[];e===null?a.push(t):s==null?e!=null&&o.push(t):(l.push(t),ur(s,e)||c.push(t)),(o.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:o,updated:c,removed:a},"local"]),this.emit("update",[{added:o,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},fo=(n,e,t)=>{let r=[];for(let i=0;i0&&(n.emit("change",[{added:[],updated:[],removed:r},t]),n.emit("update",[{added:[],updated:[],removed:r},t]))},kr=(n,e,t=n.states)=>{let r=e.length,i=F();x(i,r);for(let s=0;s{let r=q(e),i=Ne(),s=[],o=[],l=[],c=[],a=k(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:s,updated:l,removed:c},t]),(s.length>0||o.length>0||c.length>0)&&n.emit("update",[{added:s,updated:o,removed:c},t])};var $u=n=>hf(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,ju=3,Cr=1,rb=2,Ti=[];Ti[Bn]=(n,e,t,r,i)=>{x(n,Bn);let s=qu(e,n,t.doc,t);r&&s===co&&!t.synced&&(t.synced=!0)};Ti[ju]=(n,e,t,r,i)=>{x(n,Cr),U(n,kr(t.awareness,Array.from(t.awareness.getStates().keys())))};Ti[Cr]=(n,e,t,r,i)=>{Ju(t.awareness,K(e),t)};Ti[rb]=(n,e,t,r,i)=>{Hu(e,t.doc,(s,o)=>ib(t,o))};var Wu=3e4,ib=(n,e)=>console.warn(`Permission denied to access ${n.url}. -${e}`),Ku=(n,e,t)=>{let r=q(e),i=F(),s=k(r),o=n.messageHandlers[s];return o?o(i,r,n,t,s):console.error("Unable to compute message"),i},Yu=n=>{if(n.shouldConnect&&n.ws===null){let e=new n._WS(n.url,n.protocols);e.binaryType="arraybuffer",n.ws=e,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,e.onmessage=t=>{n.wsLastMessageReceived=Ne();let r=Ku(n,new Uint8Array(t.data),!0);Ns(r)>1&&e.send(I(r))},e.onerror=t=>{n.emit("connection-error",[t,n])},e.onclose=t=>{n.emit("connection-close",[t,n]),n.ws=null,n.wsconnecting=!1,n.wsconnected?(n.wsconnected=!1,n.synced=!1,fo(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Yu,De(zd(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},e.onopen=()=>{n.wsLastMessageReceived=Ne(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);let t=F();if(x(t,Bn),ao(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=F();x(r,Cr),U(r,kr(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},Pc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},Lc=class extends tr{constructor(e,t,r,{connect:i=!0,awareness:s=new ho(r),params:o={},protocols:l=[],WebSocketPolyfill:c=WebSocket,resyncInterval:a=-1,maxBackoffTime:h=2500,disableBc:d=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+"/"+t,this.maxBackoffTime=h,this.params=o,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=s,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=d,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Ti.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let f=F();x(f,Bn),ao(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=Ku(this,new Uint8Array(f),!1);Ns(p)>1&&Vn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=F();x(p,Bn),Fu(p,f),Pc(this,I(p))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:f,updated:u,removed:p},m)=>{let g=f.concat(u).concat(p),y=F();x(y,Cr),U(y,kr(s,g)),Pc(this,I(y))},this._exitHandler=()=>{fo(this.awareness,[r.clientID],"app closed")},kt&&typeof process<"u"&&process.on("exit",this._exitHandler),s.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Wu{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var sb=/[\uD800-\uDBFF]/,ob=/[\uDC00-\uDFFF]/,lb=(n,e)=>{let t=0,r=0;for(;t0&&sb.test(n[t-1])&&t--;r+t0&&ob.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Xu=lb;var v=new le("y-sync"),Dt=new le("y-undo"),Di=new le("yjs-cursor");var Ni=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!Tt(e.ds,n.id),cb=[{light:"#ecd44433",dark:"#ecd444"}],ab=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,Zd(e))}return n.get(t)},ep=(n,{colors:e=cb,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new uo(n,s),c=new H({props:{editable:a=>{let h=v.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:v,state:{init:(a,h)=>({type:n,doc:n.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:t,permanentUserData:r}),apply:(a,h)=>{let d=a.getMeta(v);if(d!==void 0){h=Object.assign({},h);for(let f in d)h[f]=d[f]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=d!==void 0&&!!d.isChangeOrigin,h.isUndoRedoOperation=d!==void 0&&!!d.isChangeOrigin&&!!d.isUndoRedoOperation,l.prosemirrorView!==null&&d!==void 0&&(d.snapshot!=null||d.prevSnapshot!=null)&&ai(0,()=>{l.prosemirrorView!=null&&(d.restore==null?l._renderSnapshot(d.snapshot,d.prevSnapshot,h):(l._renderSnapshot(d.snapshot,d.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),s==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,h.addToHistory===!1&&!h.isChangeOrigin){let d=Dt.getState(a.state),f=d&&d.undoManager;f&&f.stopCapturing()}l.mux(()=>{h.doc.transact(d=>{d.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},v)})}},destroy:()=>{l.destroy()}})});return c},hb=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null){let r=Yt(t.doc,t.type,e.anchor,t.mapping),i=Yt(t.doc,t.type,e.head,t.mapping);r!==null&&i!==null&&(n=n.setSelection(A.create(n.doc,r,i)))}},Ii=(n,e)=>({anchor:Pn(e.selection.anchor,n.type,n.mapping),head:Pn(e.selection.head,n.type,n.mapping)}),uo=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Gu(),this.mapping=t,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=Ii(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(pr&&this._domSelectionInView===null&&(ai(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.prosemirrorView._root.getSelection(),t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.getClientRects().length===0&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);let i=t.getBoundingClientRect(),s=Ct.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||s.clientWidth||0)&&i.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,t){t||(t=Mi(br(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(v,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(r=>Oi(r,this.prosemirrorView.state.schema,this.mapping)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(e),0,0));t.setMeta(v,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{let e=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(i=>Oi(i,this.prosemirrorView.state.schema,this.mapping)).filter(i=>i!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(t),0,0));e&&r.setSelection(A.create(r.doc,e.anchor,e.head)),this.prosemirrorView.dispatch(r.setMeta(v,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,r){let i=this.doc;e||(e=Ai(this.doc)),(e instanceof Uint8Array||t instanceof Uint8Array)&&((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&j(),i=new We({gc:!1}),vn(i,t),t=Ai(i),vn(i,e),e=Ai(i)),this.mapping.clear(),this.mux(()=>{i.transact(s=>{let o=r.permanentUserData;o&&o.dss.forEach(h=>{rt(s,h,d=>{})});let l=(h,d)=>{let f=h==="added"?o.getUserByClientId(d.client):o.getUserByDeletedId(d);return{user:f,type:h,color:ab(r.colorMapping,r.colors,f)}},c=lo(this.type,new jt(t.ds,e.sv)).map(h=>!h._item.deleted||Ni(h._item,e)||Ni(h._item,t)?Oi(h,this.prosemirrorView.state.schema,new Map,e,t,l):null).filter(h=>h!==null),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(c),0,0));this.prosemirrorView.dispatch(a.setMeta(v,{isChangeOrigin:!0}))},v)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let r=v.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{let i=(l,c)=>this.mapping.delete(c);rt(t,t.deleteSet,l=>{if(l.constructor===O){let c=l.content.type;c&&this.mapping.delete(c)}}),t.changed.forEach(i),t.changedParentTypes.forEach(i);let s=this.type.toArray().map(l=>tp(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(s),0,0));hb(o,this.beforeTransactionSelection,this),o=o.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Tn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{Mr(this.doc,this.type,e,this.mapping),this.beforeTransactionSelection=Ii(this,this.prosemirrorView.state)},v)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}},tp=(n,e,t,r,i,s)=>{let o=t.get(n);if(o===void 0){if(n instanceof Z)return Oi(n,e,t,r,i,s);throw Oe()}return o},Oi=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c.constructor===Z){let a=tp(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=c._item.right?.content.type;a instanceof ct&&!a._item.deleted&&a._item.id.client===a.doc.clientID&&(c.applyDelta([{retain:c.length},...a.toDelta()]),a.doc.transact(d=>{a._item.delete(d)}));let h=db(c,e,t,r,i,s);h!==null&&h.forEach(d=>{d!==null&&o.push(d)})}};r===void 0||i===void 0?n.toArray().forEach(l):lo(n,new jt(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(Ni(n._item,r)?Ni(n._item,i)||(c.ychange=s?s("added",n._item.id):{type:"added"}):c.ychange=s?s("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,o);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},db=(n,e,t,r,i,s)=>{let o=[],l=n.toDelta(r,i,s);try{for(let c=0;c{n._item.delete(a)},v),null}return o},fb=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:rp(i.marks)}));return t.applyDelta(r),e.set(t,n),t},ub=(n,e)=>{let t=new Z(n.type.name);for(let r in n.attrs){let i=n.attrs[r];i!==null&&r!=="ychange"&&t.setAttribute(r,i)}return t.insert(0,mo(n).map(r=>zc(r,e))),e.set(t,n),t},zc=(n,e)=>n instanceof Array?fb(n,e):ub(n,e),Qu=n=>typeof n=="object"&&n!==null,qc=(n,e)=>{let t=Object.keys(n).filter(i=>n[i]!==null),r=t.length===Object.keys(e).filter(i=>e[i]!==null).length;for(let i=0;i{let e=n.content.content,t=[];for(let r=0;r{let t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&Vs(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(s=>qc(r.attributes[s.type.name]||{},s.attrs)))},Ri=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Fc(n,e)){let t=mo(e);return n._length===t.length&&qc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Ri(r,t[i]))}return n instanceof xe&&e instanceof Array&&np(n,e)},po=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),Zu=(n,e,t)=>{let r=n.toArray(),i=mo(e),s=i.length,o=r.length,l=De(o,s),c=0,a=0,h=!1;for(;c{let e="",t=n._start,r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof Re?e+=t.content.str:t.content instanceof P&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},mb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=pb(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,rp(a.marks))})),{insert:o,remove:l,index:c}=Xu(i,s.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,o),n.applyDelta(s.map(a=>({retain:a.insert.length,attributes:a.attributes})))},rp=n=>{let e={};return n.forEach(t=>{t.type.name!=="ychange"&&(e[t.type.name]=t.attrs)}),e},Mr=(n,e,t,r)=>{if(e instanceof Z&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.set(e,t),e instanceof Z){let d=e.getAttributes(),f=t.attrs;for(let u in f)f[u]!==null?d[u]!==f[u]&&u!=="ychange"&&e.setAttribute(u,f[u]):e.removeAttribute(u);for(let u in d)f[u]===void 0&&e.removeAttribute(u)}let i=mo(t),s=i.length,o=e.toArray(),l=o.length,c=De(s,l),a=0,h=0;for(;a{for(;l-a-h>0&&s-a-h>0;){let f=o[a],u=i[a],p=o[l-h-1],m=i[s-h-1];if(f instanceof xe&&u instanceof Array)np(f,u)||mb(f,u,r),a+=1;else{let g=f instanceof Z&&Fc(f,u),y=p instanceof Z&&Fc(p,m);if(g&&y){let E=Zu(f,u,r),N=Zu(p,m,r);E.foundMappedChild&&!N.foundMappedChild?y=!1:!E.foundMappedChild&&N.foundMappedChild||E.equalityFactor0&&(e.slice(a,a+d).forEach(f=>r.delete(f)),e.delete(a,d)),a+h!(e instanceof Array)&&n.nodeName===e.type.name;var vi=null,gb=()=>{let n=vi;vi=null,n.forEach((e,t)=>{let r=t.state.tr,i=v.getState(t.state);i&&i.binding&&!i.binding.isDestroyed&&(e.forEach((s,o)=>{r.setMeta(o,s)}),t.dispatch(r))})},Hc=(n,e,t)=>{vi||(vi=new Map,ai(0,gb)),$(vi,n,_).set(e,t)},Pn=(n,e,t)=>{if(n===0)return Ci(e,0,-1);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof xe){if(r._length>=n)return Ci(r,n,-1);if(n-=r._length,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{do r=r._item===null?null:r._item.parent,n--;while(r!==e&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==e&&(r=r._item===null?null:r._item.next.content.type)}}else{let i=(t.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&n1)return new ot(r._item===null?null:r._item.id,r._item===null?_n(r):null,null);if(n-=i,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(n===0)return r=r._item===null?r:r._item.parent,new ot(r._item===null?null:r._item.id,r._item===null?_n(r):null,null);do r=r._item.parent,n--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw j();if(n===0&&r.constructor!==xe&&r!==e)return yb(r._item.parent,r._item)}return Ci(e,e._length,-1)},yb=(n,e)=>{let t=null,r=null;return n._item===null?r=_n(n):t=M(n._item.id.client,n._item.id.clock),new ot(t,r,e.id)},Yt=(n,e,t,r)=>{let i=Tc(t,n);if(i===null||i.type!==e&&!En(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===xe)o=i.index;else if(s._item===null||!s._item.deleted){let l=s._first,c=0;for(;ci(void 0)};return Mr(r,t,n,new Map),t}function sp(n,e="prosemirror"){return $c(n.getXmlFragment(e))}function $c(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(o=>{let l={type:"text",text:o.insert};return o.attributes&&(l.marks=Object.keys(o.attributes).map(c=>{let a=o.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let s=r.getAttributes();Object.keys(s).length&&(i.attrs=s);let o=r.toArray();o.length&&(i.content=o.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var wb=(n,e,t)=>n!==e,bb=n=>{let e=document.createElement("span");e.classList.add("ProseMirror-yjs-cursor"),e.setAttribute("style",`border-color: ${n.color}`);let t=document.createElement("div");t.setAttribute("style",`background-color: ${n.color}`),t.insertBefore(document.createTextNode(n.name),null);let r=document.createTextNode("\u2060"),i=document.createTextNode("\u2060");return e.insertBefore(r,null),e.insertBefore(t,null),e.insertBefore(i,null),e},xb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Sb=/^#[0-9a-fA-F]{6}$/,op=(n,e,t,r,i)=>{let s=v.getState(n),o=s.doc,l=[];return s.snapshot!=null||s.prevSnapshot!=null||s.binding.mapping.size===0?L.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(o.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Sb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Yt(o,s.type,Un(c.cursor.anchor),s.binding.mapping),f=Yt(o,s.type,Un(c.cursor.head),s.binding.mapping);if(d!==null&&f!==null){let u=Be(n.doc.content.size-1,0);d=De(d,u),f=De(f,u),l.push(ne.widget(f,()=>r(h),{key:a+"",side:10}));let p=De(d,f),m=Be(d,f);l.push(ne.inline(p,m,i(h),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),L.create(n.doc,l))},kb=(n,{awarenessStateFilter:e=wb,cursorBuilder:t=bb,selectionBuilder:r=xb,getSelection:i=o=>o.selection}={},s="cursor")=>new H({key:Di,state:{init(o,l){return op(l,n,e,t,r)},apply(o,l,c,a){let h=v.getState(a),d=o.getMeta(Di);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?op(a,n,e,t,r):l.map(o.mapping,o.doc)}},props:{decorations:o=>Di.getState(o)},view:o=>{let l=()=>{o.docView&&Hc(o,Di,{awarenessUpdated:!0})},c=()=>{let a=v.getState(o.state),h=n.getLocalState()||{};if(o.hasFocus()){let d=i(o.state),f=Pn(d.anchor,a.type,a.binding.mapping),u=Pn(d.head,a.type,a.binding.mapping);(h.cursor==null||!ro(Un(h.cursor.anchor),f)||!ro(Un(h.cursor.head),u))&&n.setLocalStateField(s,{anchor:f,head:u})}else h.cursor!=null&&Yt(a.doc,a.type,Un(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(s,null)};return n.on("change",l),o.dom.addEventListener("focusin",c),o.dom.addEventListener("focusout",c),{update:c,destroy:()=>{o.dom.removeEventListener("focusin",c),o.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(s,null)}}}});var Cb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.undo(),!0},Mb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.redo(),!0},Ab=new Set(["paragraph"]),Eb=(n,e)=>!(n instanceof O)||!(n.content instanceof Ae)||!(n.content.type instanceof ct||n.content.type instanceof Z&&e.has(n.content.type.nodeName))||n.content.type._length===0,Tb=({protectedNodes:n=Ab,trackedOrigins:e=[],undoManager:t=null}={})=>new H({key:Dt,state:{init:(r,i)=>{let s=v.getState(i),o=t||new Tn(s.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Eb(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(r,i,s,o)=>{let l=v.getState(o).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ii(l,s),hasUndoOps:a,hasRedoOps:h}:a!==i.hasUndoOps||h!==i.hasRedoOps?Object.assign({},i,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):i}},view:r=>{let i=v.getState(r.state),s=Dt.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,Dt.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:o})=>{let l=i.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}});var _i="http://www.w3.org/2000/svg",Db="http://www.w3.org/1999/xlink",jc="ProseMirror-icon",Wc="pm-close-dropdowns";function Ob(n){let e=0;for(let t=0;t{s.preventDefault(),r.classList.contains(je+"-disabled")||t.run(e.state,e.dispatch,e,s)});function i(s){if(t.select){let l=t.select(s);if(r.style.display=l?"":"none",!l)return!1}let o=!0;if(t.enable&&(o=t.enable(s)||!1,lp(r,je+"-disabled",!o)),t.active){let l=o&&t.active(s)||!1;lp(r,je+"-active",l)}return!0}return{dom:r,update:i}}};function go(n,e){return n._props.translate?n._props.translate(e):e}var Ui={time:0,node:null};function Rb(n){Ui.time=Date.now(),Ui.node=n.target}function vb(n){return Date.now()-100{o&&o.close()&&(o=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(Wc,c))};i.addEventListener("mousedown",d=>{d.preventDefault(),Rb(d),o?a():(r.dispatchEvent(new CustomEvent(Wc)),o=this.expand(s,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{vb(s)||a()}),r.addEventListener(Wc,c=()=>{a()}))});function h(d){let f=t.update(d);return s.style.display=f?"":"none",f}return{dom:s,update:h}}expand(e,t){let r=document.createElement("div");r.className=`${je}-dropdown-menu-col-1`;let i=document.createElement("div");i.className=`${je}-dropdown-menu-col-2`,t.forEach(c=>{c.querySelector('[column="2"]')?i.append(c):r.append(c)});let s=wt("div",{class:je+"-dropdown-menu "+(this.options.class||"")},r,i),o=!1;function l(){return o?!1:(o=!0,e.removeChild(s),!0)}return e.appendChild(s),{close:l,node:s}}};function _b(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iWr(n),icon:Vi.join}),Vk=new ht({title:"Lift out of enclosing block",run:jr,select:n=>jr(n),icon:Vi.lift}),Bk=new ht({title:"Select parent node",run:Kr,select:n=>Kr(n),icon:Vi.selectParentNode}),Pk=new ht({title:"Undo last change",run:Xr,enable:n=>Xr(n),icon:Vi.undo}),Lk=new ht({title:"Redo last undone change",run:Qn,enable:n=>Qn(n),icon:Vi.redo});function Bb(n,e){let t={run(r,i){return Xn(n,e.attrs)(r,i)},select(r){return Xn(n,e.attrs)(r)}};for(let r in e)t[r]=e[r];return new ht(t)}function Pb(n,e){let t=pn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:s,to:o,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):o<=s.end()&&s.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new ht(r)}function lp(n,e,t){t?n.classList.add(e):n.classList.remove(e)}export{zn as DOMParser,It as DOMSerializer,Kc as Dropdown,Bo as EditorState,ol as EditorView,w as Fragment,bt as InputRule,ht as MenuItem,H as Plugin,le as PluginKey,Dr as Schema,b as Slice,A as TextSelection,Lc as WebsocketProvider,Sr as Y,e0 as addColumnAfter,Zy as addColumnBefore,ay as addListNodes,s0 as addRowAfter,i0 as addRowBefore,ld as baseKeymap,Pg as baseSchema,Pb as blockTypeItem,Vy as buildKeymap,A0 as columnResizing,n0 as deleteColumn,l0 as deleteRow,m0 as deleteTable,Nd as fixTables,Ty as gapCursor,p0 as goToNextCell,ud as inputRules,He as isInTable,wy as keymap,bl as liftListItem,a0 as mergeCells,ip as prosemirrorToYDoc,Jc as prosemirrorToYXmlFragment,Ub as renderGrouped,Je as selectedRect,pn as setBlockType,xl as sinkListItem,h0 as splitCell,wl as splitListItem,V0 as tableEditing,Fy as tableNodes,mn as toggleMark,Xn as wrapIn,us as wrapInList,Bb as wrapItem,kb as yCursorPlugin,sp as yDocToProsemirrorJSON,Mb as yRedo,ep as ySyncPlugin,Cb as yUndo,Tb as yUndoPlugin,Dt as yUndoPluginKey,$c as yXmlFragmentToProsemirrorJSON}; +`))),0,0):b.empty;let d=n.someProp("clipboardTextParser",f=>f(e,i,r,n));if(d)l=d;else{let f=i.marks(),{schema:u}=n.state,p=It.fromSchema(u);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),o=$m(t),$r&&Wm(o);let a=o&&o.querySelector("[data-pm-slice]"),h=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let d=+h[3];d>0;d--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!qm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=jm(ah(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Hm(l.content,i),!0),l.openStart||l.openEnd){let d=0,f=0;for(let u=l.content.firstChild;d{l=d(l,n)}),l}var qm=/^(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 Hm(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let c=i.findWrapping(l.type),a;if(!c)return o=null;if(a=o.length&&s.length&&zh(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=Fh(o[o.length-1],s.length));let h=Lh(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return w.from(o)}return n}function Lh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function zh(n,e,t,r,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function ah(n,e,t){return et}).createHTML(n):n}function $m(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Hh().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&qh[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"").reverse().join("")),t.innerHTML=Jm(n),i)for(let s=0;s=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),s++,o++}return new b(i,s,o)}var ge={},ye={},Km={touchstart:!0,touchmove:!0},el=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Ym(n){for(let e in ge){let t=ge[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Xm(n,r)&&!hl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},Km[e]?{passive:!0}:void 0)}me&&n.dom.addEventListener("input",()=>null),tl(n)}function Vt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Gm(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function tl(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>hl(n,r))})}function hl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Xm(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Qm(n,e){!hl(n,e)&&ge[e.type]&&(n.editable||!(e.type in ye))&&ge[e.type](n,e)}ye.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!$h(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Fe&&ae&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),Kn&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,on(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Fm(n,t)?t.preventDefault():Vt(n,"key")};ye.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ye.keypress=(n,e)=>{let t=e;if($h(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||ve&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof A)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function fs(n){return{left:n.clientX,top:n.clientY}}function Zm(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function dl(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function jn(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function eg(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&C.isSelectable(r)?(jn(n,new C(t),"pointer"),!0):!1}function tg(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof C&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(C.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(jn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function ng(n,e,t,r,i){return dl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?tg(n,t):eg(n,t))}function rg(n,e,t,r){return dl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function ig(n,e,t,r){return dl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||sg(n,t,r)}function sg(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(jn(n,A.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)jn(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(C.isSelectable(o))jn(n,C.create(r,l),"pointer");else continue;return!0}}function fl(n){return ss(n)}var Jh=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=fl(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&Zm(t,n.input.lastClick)&&!t[Jh]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(fs(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new nl(n,o,t,!!r)):(s=="doubleClick"?rg:ig)(n,o.pos,o.inside,t)?t.preventDefault():Vt(n,"pointer"))};var nl=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Jh],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}let l=i?null:r.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c&&c.dom.nodeType==1?c.dom:null;let{selection:a}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||a instanceof C&&a.from<=o&&a.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&qe&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),Vt(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>mt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(fs(e))),this.updateAllowDefault(e),this.allowDefault||!t?Vt(this.view,"pointer"):ng(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||me&&this.mightDrag&&!this.mightDrag.node.isAtom||ae&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(jn(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Vt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Vt(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};ge.touchstart=n=>{n.input.lastTouch=Date.now(),fl(n),Vt(n,"pointer")};ge.touchmove=n=>{n.input.lastTouch=Date.now(),Vt(n,"pointer")};ge.contextmenu=n=>fl(n);function $h(n,e){return n.composing?!0:me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var og=Fe?5e3:-1;ye.compositionstart=ye.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof A&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),ss(n,!0),n.markCursor=null;else if(ss(n,!e.selection.empty),qe&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}Wh(n,og)};ye.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Wh(n,20))};function Wh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>ss(n),e))}function jh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=cg());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function lg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=im(e.focusNode,e.focusOffset),r=sm(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function cg(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function ss(n,e=!1){if(!(Fe&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),jh(n),e||n.docView&&n.docView.dirty){let t=cl(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function ag(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var Fr=ke&&Bt<15||Kn&&hm<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=Fr?null:t.clipboardData,o=r.content(),{dom:l,text:c}=Bh(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):ag(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function hg(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function dg(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?qr(n,r.value,null,i,e):qr(n,r.textContent,r.innerHTML,i,e)},50)}function qr(n,e,t,r,i){let s=Ph(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,s||b.empty)))return!0;if(!s)return!1;let o=hg(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Kh(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ye.paste=(n,e)=>{let t=e;if(n.composing&&!Fe)return;let r=Fr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&qr(n,Kh(r),r.getData("text/html"),i,t)?t.preventDefault():dg(n,t)};var ls=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Yh=ve?"altKey":"ctrlKey";ge.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(fs(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof C?i.to-1:i.to))){if(r&&r.mightDrag)o=C.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let d=n.docView.nearestDesc(t.target,!0);d&&d.node.type.spec.draggable&&d!=n.docView&&(o=C.create(n.state.doc,d.posBefore))}}let l=(o||n.state.selection).content(),{dom:c,text:a,slice:h}=Bh(n,l);(!t.dataTransfer.files.length||!ae||Ch>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Fr?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",Fr||t.dataTransfer.setData("text/plain",a),n.dragging=new ls(h,!t[Yh],o)};ge.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ye.dragover=ye.dragenter=(n,e)=>e.preventDefault();ye.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(fs(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",p=>{o=p(o,n)}):o=Ph(n,Kh(t.dataTransfer),Fr?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[Yh]);if(n.someProp("handleDrop",p=>p(n,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let c=o?Na(n.state.doc,s.pos,o):s.pos;c==null&&(c=s.pos);let a=n.state.tr;if(l){let{node:p}=r;p?p.replace(a):a.deleteSelection()}let h=a.mapping.map(c),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,o.content.firstChild):a.replaceRange(h,h,o),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&C.isSelectable(o.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new C(u));else{let p=a.mapping.map(c);a.mapping.maps[a.mapping.maps.length-1].forEach((m,g,y,E)=>p=E),a.setSelection(al(n,u,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))};ge.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&mt(n)},20))};ge.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};ge.beforeinput=(n,e)=>{if(ae&&Fe&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,on(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in ye)ge[n]=ye[n];function Hr(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var cs=class n{constructor(e,t){this.toDOM=e,this.spec=t||hn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new ne(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Hr(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},an=class n{constructor(e,t){this.attrs=e,this.spec=t||hn}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new ne(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==ce||e.maps.length==0?this:this.mapInner(e,t,0,0,r||hn)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let a=c+r,h;if(h=Xh(t,l,a)){for(i||(i=this.children.slice());sl&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&c.type instanceof an){let a=Math.max(s,c.from)-s,h=Math.min(o,c.to)-s;ai.map(e,t,hn));return n.from(r)}forChild(e,t){if(t.isLeaf)return z.empty;let r=[];for(let i=0;it instanceof z)?e:e.reduce((t,r)=>t.concat(r instanceof z?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-p-(u-f);for(let y=0;yE+h-d)continue;let N=l[y]+h-d;u>=N?l[y+1]=f<=N?-2:-1:f>=h&&g&&(l[y]+=g,l[y+1]+=g)}d+=g}),h=t.maps[a].map(h,-1)}let c=!1;for(let a=0;a=r.content.size){c=!0;continue}let f=t.map(n[a+1]+s,-1),u=f-i,{index:p,offset:m}=r.content.findIndex(d),g=r.maybeChild(p);if(g&&m==d&&m+g.nodeSize==u){let y=l[a+2].mapInner(t,g,h+1,n[a]+s+1,o);y!=ce?(l[a]=d,l[a+1]=u,l[a+2]=y):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=ug(l,n,e,t,i,s,o),h=hs(a,r,0,o);e=h.local;for(let d=0;dt&&o.to{let a=Xh(n,l,c+t);if(a){s=!0;let h=hs(a,l,t+c+1,r);h!=ce&&i.push(c,c+l.nodeSize,h)}});let o=Gh(s?Qh(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function zo(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=ce&&e.push(r)}),n.cursorWrapper&&e.push(z.create(n.state.doc,[n.cursorWrapper.deco])),as.from(e)}var pg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},mg=ke&&Bt<=11,il=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},sl=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new il,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),mg&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,pg)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(rh(this.view)){if(this.suppressingSelectionUpdates)return mt(this.view);if(ke&&Bt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&fn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=zr(s))t.add(s);for(let s=e.anchorNode;s;s=zr(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}selectionChanged(e){return!this.suppressingSelectionUpdates&&!this.currentSelection.eq(e)&&rh(this.view)&&!this.ignoreSelectionChange(e)}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=this.selectionChanged(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let h=0;hd.nodeName=="BR");if(h.length==2){let[d,f]=h;d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.remove()}else{let{focusNode:d}=this.currentSelection;for(let f of h){let u=f.parentNode;u&&u.nodeName=="LI"&&(!d||wg(e,d)!=u)&&f.remove()}}}let a=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),gg(e)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||mt(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let h=0;hi;g--){let y=r.childNodes[g-1],E=y.pmViewDesc;if(y.nodeName=="BR"&&!E){s=g;break}if(!E||E.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(o),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:xg,context:u});if(a&&a[0].pos!=null){let g=a[0].pos,y=a[1]&&a[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function xg(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(me&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||me&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var Sg=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function kg(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let T=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,Nt=cl(n,T);if(Nt&&!n.state.selection.eq(Nt)){if(ae&&Fe&&n.input.lastKeyCode===13&&Date.now()-100ap(n,on(13,"Enter"))))return;let Bi=n.state.tr.setSelection(Nt);T=="pointer"?Bi.setMeta("pointer",!0):T=="key"&&Bi.scrollIntoView(),s&&Bi.setMeta("composition",s),n.dispatch(Bi)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=bg(n,e,t),h=n.state.doc,d=h.slice(a.from,a.to),f,u;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||Fe)&&i.some(T=>T.nodeType==1&&!Sg.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&c instanceof A&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(a.sel&&a.sel.anchor!=a.sel.head))p={start:c.from,endA:c.to,endB:c.to};else{if(a.sel){let T=mh(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let Nt=n.state.tr.setSelection(T);s&&Nt.setMeta("composition",s),n.dispatch(Nt)}}return}n.state.selection.fromn.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=a.from?p.start=n.state.selection.from:p.endA=n.state.selection.to-2&&n.state.selection.to<=a.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),ke&&Bt<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>a.from&&a.doc.textBetween(p.start-a.from-1,p.start-a.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=a.doc.resolveNoCache(p.start-a.from),g=a.doc.resolveNoCache(p.endB-a.from),y=h.resolve(p.start),E=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,N;if((Kn&&n.input.lastIOSEnter>Date.now()-225&&(!E||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!E&&m.posT(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Mg(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,on(8,"Backspace")))){Fe&&ae&&n.domObserver.suppressSelectionUpdates();return}ae&&Fe&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),Fe&&!E&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==p.endA&&(p.endB-=2,g=a.doc.resolveNoCache(p.endB-a.from),setTimeout(()=>{n.someProp("handleKeyDown",function(T){return T(n,on(13,"Enter"))})},20));let Se=p.start,pe=p.endA,Y,dt,Ot;if(E){if(m.pos==g.pos)ke&&Bt<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>mt(n),20)),Y=n.state.tr.delete(Se,pe),dt=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(Ot=Cg(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start()))))Y=n.state.tr,Ot.type=="add"?Y.addMark(Se,pe,Ot.mark):Y.removeMark(Se,pe,Ot.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",Nt=>Nt(n,Se,pe,T)))return;Y=n.state.tr.insertText(T,Se,pe)}}if(Y||(Y=n.state.tr.replace(Se,pe,a.doc.slice(p.start-a.from,p.endB-a.from))),a.sel){let T=mh(n,Y.doc,a.sel);T&&!(ae&&Fe&&n.composing&&T.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:al(n,e.resolve(t.anchor),e.resolve(t.head))}function Cg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||Fo(o,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function Ag(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,s-Math.min(o,l));r-=o+c-s}if(o=o?s-r:0;s-=c,s&&s=l?s-r:0;s-=c,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var ol=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new el,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Sh),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=bh(this),wh(this),this.nodeViews=xh(this),this.docView=Xa(this.state.doc,yh(this),zo(this),this.dom,this),this.domObserver=new sl(this,(r,i,s,o)=>kg(this,r,i,s,o)),this.domObserver.start(),Ym(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&tl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Sh),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(jh(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let u=xh(this);Tg(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&tl(this),this.editable=bh(this),wh(this);let c=zo(this),a=yh(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=s||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(o=!0);let f=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&um(this);if(o){this.domObserver.stop();let u=d&&(ke||ae)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Eg(i.selection,e.selection);if(d){let p=ae?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=lg(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Xa(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&_m(this))?mt(this,u):(_h(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():f&&pm(f)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof C){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&$a(this,t.getBoundingClientRect(),e)}else $a(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new ls(e.slice,e.move,i<0?void 0:C.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return xm(this,e)}coordsAtPos(e,t=1){return Dh(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Am(this,t||this.state,e)}pasteHTML(e,t){return qr(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return qr(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Gm(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],zo(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,nm())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Qm(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?me&&this.root.nodeType===11&&lm(this.dom.ownerDocument)==this.dom&&yg(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function yh(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[ne.node(0,n.state.doc.content.size,e)]}function wh(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:ne.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function bh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Eg(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function xh(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Tg(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function Sh(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Dg=["p",0],Og=["blockquote",0],Ng=["hr"],Ig=["pre",["code",0]],Rg=["br"],vg={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Dg}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Og}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Ng}},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return Ig}},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return Rg}}},_g=["em",0],Ug=["strong",0],Vg=["code",0],Bg={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return _g}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return Ug}},code:{parseDOM:[{tag:"code"}],toDOM(){return Vg}}},Pg=new Dr({nodes:vg,marks:Bg});var ed=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Lg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var zg=(n,e,t)=>{let r=Lg(n,t);if(!r)return!1;let i=td(r);if(!i){let o=r.blockRange(),l=o&&nn(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(id(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Gn(s,"end")||C.isSelectable(s)))for(let o=r.depth;;o--){let l=Xi(n.doc,r.before(o),r.after(o),b.empty);if(l&&l.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function Gn(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}var Fg=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=td(r)}let o=s&&s.nodeBefore;return!o||!C.isSelectable(o)?!1:(e&&e(n.tr.setSelection(C.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function td(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function qg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=qg(n,t);if(!r)return!1;let i=nd(r);if(!i)return!1;let s=i.nodeAfter;if(id(n,i,e,1))return!0;if(r.parent.content.size==0&&(Gn(s,"start")||C.isSelectable(s))){let o=Xi(n.doc,r.before(),r.after(),b.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof C,i;if(r){if(t.node.isTextblock||!rn(n.doc,t.from))return!1;i=t.from}else if(i=Ro(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(C.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},rd=(n,e)=>{let t=n.selection,r;if(t instanceof C){if(t.node.isTextblock||!rn(n.doc,t.to))return!1;r=t.to}else if(r=Ro(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},jr=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&nn(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},$g=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` +`).scrollIntoView()),!0)};function ml(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=ml(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,o.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},Wg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Te||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=ml(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(Rt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Kg(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof C&&e.selection.node.isBlock)return!r.parentOffset||!Rt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;let s=i.parentOffset==i.parent.content.size,o=e.tr;(e.selection instanceof A||e.selection instanceof Te)&&o.deleteSelection();let l=r.depth==0?null:ml(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,s,r),a=c?[c]:s&&l?[{type:l}]:void 0,h=Rt(o.doc,o.mapping.map(r.pos),1,a);if(!a&&!h&&Rt(o.doc,o.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(o.split(o.mapping.map(r.pos),1,a),!s&&!r.parentOffset&&r.parent.type!=l){let d=o.mapping.map(r.before()),f=o.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&o.setNodeMarkup(o.mapping.map(r.before()),l)}return t&&t(o.scrollIntoView()),!0}}var Yg=Kg();var Kr=(n,e)=>{let{$from:t,to:r}=n.selection,i,s=t.sharedDepth(r);return s==0?!1:(i=t.before(s),e&&e(n.tr.setSelection(C.create(n.doc,i))),!0)},Gg=(n,e)=>(e&&e(n.tr.setSelection(new Te(n.doc))),!0);function Xg(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||rn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function id(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&Xg(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let u=e.pos+s.nodeSize,p=w.empty;for(let y=o.length-1;y>=0;y--)p=w.from(o[y].create(null,p));p=w.from(i.copy(p));let m=n.tr.step(new X(e.pos-1,u,e.pos,u,new b(p,1,0),o.length,!0)),g=m.doc.resolve(u+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&rn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||r>0&&c?null:S.findFrom(e,1),d=h&&h.$from.blockRange(h.$to),f=d&&nn(d);if(f!=null&&f>=e.depth)return t&&t(n.tr.lift(d,f).scrollIntoView()),!0;if(a&&Gn(s,"start",!0)&&Gn(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(u.canReplace(u.childCount,u.childCount,m.content)){if(t){let y=w.empty;for(let N=p.length-1;N>=0;N--)y=w.from(p[N].copy(y));let E=n.tr.step(new X(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new b(y,p.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function sd(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var Qg=sd(-1),Zg=sd(1);function Xn(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Gi(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function pn(n,e=null){return function(t,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)i=!0;else{let h=t.doc.resolve(a),d=h.index();i=h.parent.canReplaceWith(d,d+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o{if(l||!r&&c.isAtom&&c.isInline&&a>=s.pos&&a+c.nodeSize<=o.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function ty(n){let e=[];for(let t=0;t{if(s.isAtom&&s.content.size&&s.isInline&&o>=r.pos&&o+s.nodeSize<=i.pos)return o+1>r.pos&&e.push(new vt(r,r.doc.resolve(o+1))),r=r.doc.resolve(o+1+s.content.size),!1}),r.poss.doc.rangeHasMark(f.$from.pos,f.$to.pos,n)):h=!a.every(f=>{let u=!1;return d.doc.nodesBetween(f.$from.pos,f.$to.pos,(p,m,g)=>{if(u)return!1;u=!n.isInSet(p.marks)&&!!g&&g.type.allowsMarkType(n)&&!(p.isText&&/^\s*$/.test(p.textBetween(Math.max(0,f.$from.pos-m),Math.min(p.nodeSize,f.$to.pos-m))))}),!u});for(let f=0;f=2&&i.node(o.depth-1).type.compatibleContent(n)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let h=t.doc.resolve(o.start-2);c=new Zt(h,h,o.depth),o.endIndex=0;h--)s=w.from(t[h].type.create(t[h].attrs,s));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(s,0,0),t.length,!0));let o=0;for(let h=0;h=i.depth-3;y--)d=w.from(i.node(y).copy(d));let u=i.indexAfter(-1){if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=E+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let c=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,s.pos),h=c?[e?{type:n,attrs:e}:null,{type:c}]:void 0;return Rt(a.doc,i.pos,2,h)?(r&&r(a.split(i.pos,2,h).scrollIntoView()),!0):!1}}function bl(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,o=>o.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?dy(e,t,n,s):fy(e,t,s):!0:!1}}function dy(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);sm;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=s.node(-1),h=s.index(-1);if(!a.canReplace(h+(l?0:1),h+1,o.content.append(c?w.empty:w.from(i))))return!1;let d=s.pos,f=d+o.nodeSize;return r.step(new X(d-(l?1:0),f+(c?1:0),d+1,f-1,new b((l?w.empty:w.from(i.copy(w.empty))).append(c?w.empty:w.from(i.copy(w.empty))),l?0:1,c?0:1),l?0:1)),e(r.scrollIntoView()),!0}function xl(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,c=l.child(o-1);if(c.type!=n)return!1;if(t){let a=c.lastChild&&c.lastChild.type==l.type,h=w.from(a?n.create():null),d=new b(w.from(n.create(null,w.from(l.type.create(null,h)))),a?3:1,0),f=s.start,u=s.end;t(e.tr.step(new X(f-(a?3:1),u,f,u,d,1,!0)).scrollIntoView())}return!0}}var yt={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:"'"},ms={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},uy=typeof navigator<"u"&&/Mac/.test(navigator.platform),py=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(J=0;J<10;J++)yt[48+J]=yt[96+J]=String(J);var J;for(J=1;J<=24;J++)yt[J+111]="F"+J;var J;for(J=65;J<=90;J++)yt[J]=String.fromCharCode(J+32),ms[J]=String.fromCharCode(J);var J;for(ps in yt)ms.hasOwnProperty(ps)||(ms[ps]=yt[ps]);var ps;function cd(n){var e=uy&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||py&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?ms:yt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var my=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function gy(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l127)&&(s=yt[r.keyCode])&&s!=i){let l=e[Sl(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var gs=200,re=function(){};re.prototype.append=function(e){return e.length?(e=re.from(e),!this.length&&e||e.length=t?re.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};re.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};re.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};re.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i};re.from=function(e){return e instanceof re?e:e&&e.length?new ad(e):re.empty};var ad=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var c=s;c=o;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=gs)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=gs)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(re);re.empty=new ad([]);var by=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(re),kl=re;var xy=500,ys=class n{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,s;t&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,c,a=[],h=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),s=i.maps.length),s--,h.push(d);return}if(i){h.push(new Xe(d.map));let u=d.step.map(i.slice(s)),p;u&&o.maybeStep(u).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],a.push(new Xe(p,void 0,void 0,a.length+h.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(s)):d.selection,c=new n(this.items.slice(0,r).append(h.reverse().concat(a)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:l}}addTransform(e,t,r,i){let s=[],o=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hky&&(l=Sy(l,a),o-=a),new n(l.append(s),o)}remapping(e,t){let r=new Rr;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new Xe(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let c=t;this.items.forEach(f=>{let u=s.getMirror(--c);if(u==null)return;o=Math.min(o,u);let p=s.maps[u];if(f.step){let m=e.steps[u].invert(e.docs[u]),g=f.selection&&f.selection.map(s.slice(c+1,u));g&&l++,r.push(new Xe(p,m,g))}else r.push(new Xe(p))},i);let a=[];for(let f=t;fxy&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let c=o.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=o.selection&&o.selection.map(t.slice(r));h&&s++;let d=new Xe(a.invert(),c,h),f,u=i.length-1;(f=i.length&&i[u].merge(d))?i[u]=f:i.push(d)}}else o.map&&r--},this.items.length,0),new n(kl.from(i.reverse()),s)}};ys.empty=new ys(kl.empty,0);function Sy(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var Xe=class n{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new n(t.getMap().invert(),t,this.selection)}}},Ml=class{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}},ky=20;function Cy(n,e,t){let r=My(e),i=Al.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,r);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),i,r),c=new Ml(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(Al,{redo:t,historyState:c})}var Cl=!1,hd=null;function My(n){let e=n.plugins;if(hd!=e){Cl=!1,hd=e;for(let t=0;t{let i=Al.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=Cy(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}var Xr=ws(!1,!0),Qn=ws(!0,!0),yx=ws(!1,!1),wx=ws(!0,!1);var he=class n extends S{constructor(e){super(e,e)}map(e,t){let r=e.resolve(t.map(this.head));return n.valid(r)?new n(r):S.near(r)}content(){return b.empty}eq(e){return e instanceof n&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new n(e.resolve(t.pos))}getBookmark(){return new El(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Ay(e)||!Ey(e))return!1;let r=t.type.spec.allowGapCursor;if(r!=null)return r;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,r=!1){e:for(;;){if(!r&&n.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!C.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),r=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(n.valid(l))return l}return null}}};he.prototype.visible=!1;he.findFrom=he.findGapCursorFrom;S.jsonID("gapcursor",he);var El=class n{constructor(e){this.pos=e}map(e){return new n(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return he.valid(t)?new he(t):S.near(t)}};function Ay(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),r=n.node(e);if(t==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Ey(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),r=n.node(e);if(t==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||i.isAtom||i.type.spec.isolating)return!0;if(i.inlineContent)return!1}}return!0}function Ty(){return new H({props:{decorations:Iy,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:Oy,handleKeyDown:Dy,handleDOMEvents:{beforeinput:Ny}}})}var Dy=Gr({ArrowLeft:bs("horiz",-1),ArrowRight:bs("horiz",1),ArrowUp:bs("vert",-1),ArrowDown:bs("vert",1)});function bs(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,s){let o=r.selection,l=e>0?o.$to:o.$from,c=o.empty;if(o instanceof A){if(!s.endOfTextblock(t)||l.depth==0)return!1;c=!1,l=r.doc.resolve(e>0?l.after():l.before())}let a=he.findGapCursorFrom(l,e,c);return a?(i&&i(r.tr.setSelection(new he(a))),!0):!1}}function Oy(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!he.valid(r))return!1;let i=n.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&C.isSelectable(n.state.doc.nodeAt(i.inside))?!1:(n.dispatch(n.state.tr.setSelection(new he(r))),!0)}function Ny(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof he))return!1;let{$from:t}=n.state.selection,r=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!r)return!1;let i=w.empty;for(let o=r.length-1;o>=0;o--)i=w.from(r[o].createAndFill(null,i));let s=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return s.setSelection(A.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function Iy(n){if(!(n.selection instanceof he))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",z.create(n.doc,[ne.widget(n.selection.head,e,{key:"gapcursor"})])}function wt(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];typeof i=="string"?n.setAttribute(r,i):i!=null&&(n[r]=i)}e++}for(;e0&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}var vy=500;function ud({rules:n}){let e=new H({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,s){return fd(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&fd(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function fd(n,e,t,r,i,s){if(n.composing)return!1;let o=n.state,l=o.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-vy),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a{let t=n.plugins;for(let r=0;r=0;c--)o.step(l.steps[c].invert(l.docs[c]));if(s.text){let c=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,c))}else o.delete(s.from,s.to);e(o)}return!0}}return!1},_y=new bt(/--$/,"\u2014"),Uy=new bt(/\.\.\.$/,"\u2026"),Tx=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Dx=new bt(/"$/,"\u201D"),Ox=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),Nx=new bt(/'$/,"\u2019");var md=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Vy(n,e){let t={},r;function i(s,o){if(e){let l=e[s];if(l===!1)return;l&&(s=l)}t[s]=o}if(i("Mod-z",Xr),i("Shift-Mod-z",Qn),i("Backspace",pd),md||i("Mod-y",Qn),i("Alt-ArrowUp",Wr),i("Alt-ArrowDown",rd),i("Mod-BracketLeft",jr),i("Escape",Kr),(r=n.marks.strong)&&(i("Mod-b",mn(r)),i("Mod-B",mn(r))),(r=n.marks.em)&&(i("Mod-i",mn(r)),i("Mod-I",mn(r))),(r=n.marks.code)&&i("Mod-`",mn(r)),(r=n.nodes.bullet_list)&&i("Shift-Ctrl-8",us(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",us(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Xn(r)),r=n.nodes.hard_break){let s=r,o=Yr(gl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0));i("Mod-Enter",o),i("Shift-Enter",o),md&&i("Ctrl-Enter",o)}if((r=n.nodes.list_item)&&(i("Enter",wl(r)),i("Mod-[",bl(r)),i("Mod-]",xl(r))),(r=n.nodes.paragraph)&&i("Shift-Ctrl-0",pn(r)),(r=n.nodes.code_block)&&i("Shift-Ctrl-\\",pn(r)),r=n.nodes.heading)for(let s=1;s<=6;s++)i("Shift-Ctrl-"+s,pn(r,{level:s}));if(r=n.nodes.horizontal_rule){let s=r;i("Mod-_",(o,l)=>(l&&l(o.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0))}return t}var Dl,Ol;if(typeof WeakMap<"u"){let n=new WeakMap;Dl=e=>n.get(e),Ol=(e,t)=>(n.set(e,t),t)}else{let n=[],t=0;Dl=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var V=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e=t){(s||(s=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Se=i+N*e;for(let pe=0;per&&(s+=a.attrs.colspan)}}for(let o=0;o1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function Ly(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(o)):null,i=Number(n.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let o in e){let l=e[o].getFromDOM,c=l&&l(n);c!=null&&(s[o]=c)}return s}function yd(n,e){let t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(let r in e){let i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function Fy(n){let e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(let r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>gd(r,e)}],toDOM(r){return["td",yd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>gd(r,e)}],toDOM(r){return["th",yd(r,e),0]}}}}function de(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(let t in n.nodes){let r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var zt=new le("selectingCells");function Zn(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function qy(n){for(let e=n.depth;e>0;e--){let t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function He(n){let e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function vl(n){let e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;let t=Zn(e.$head)||Hy(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Hy(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function Nl(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Jy(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function _l(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function Ed(n,e,t){let r=n.node(-1),i=V.get(r),s=n.start(-1),o=i.nextCell(n.pos-s,e,t);return o==null?null:n.node(0).resolve(s+o)}function gn(n,e,t=1){let r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function Td(n,e,t=1){let r={...n,colspan:n.colspan+t};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;ih!=t.pos-s);c.unshift(t.pos-s);let a=c.map(h=>{let d=r.nodeAt(h);if(!d)throw RangeError(`No cell with offset ${h} found`);let f=s+h+1;return new vt(l.resolve(f),l.resolve(f+d.content.size))});super(a[0].$from,a[0].$to,a),this.$anchorCell=e,this.$headCell=t}map(e,t){let r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Nl(r)&&Nl(i)&&_l(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?xt.rowSelection(r,i):s&&this.isColSelection()?xt.colSelection(r,i):new xt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=V.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let c=i.top;c0||g>0){let y=p.attrs;if(m>0&&(y=gn(y,0,m)),g>0&&(y=gn(y,y.colspan-g,g)),u.lefti.bottom){let y={...p.attrs,rowspan:Math.min(u.bottom,i.bottom)-Math.max(u.top,i.top)};u.top0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){let r=e.node(-1),i=V.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.top<=l.top?(o.top>0&&(e=c.resolve(s+i.map[o.left])),l.bottom0&&(t=c.resolve(s+i.map[l.left])),o.bottom0)return!1;let o=i+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof xt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=e.node(-1),i=V.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),c=e.node(0);return o.left<=l.left?(o.left>0&&(e=c.resolve(s+i.map[o.top*i.width])),l.right0&&(t=c.resolve(s+i.map[l.top*i.width])),o.right{e.push(ne.node(r,r+t.nodeSize,{class:"selectedCell"}))}),z.create(n.doc,e)}function Ky({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Yy({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){let s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function Gy(n,e,t){let r=(e||n).selection,i=(e||n).doc,s,o;if(r instanceof C&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=B.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=B.rowSelection(l,l)}else if(!t){let l=V.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];s=B.create(i,c+1,a)}}else r instanceof A&&Ky(r)?s=A.create(i,r.from):r instanceof A&&Yy(r)&&(s=A.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}var Xy=new le("fix-tables");function Od(n,e,t,r){let i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o{i.type.spec.tableRole=="table"&&(t=Qy(n,i,s,t))};return e?e.doc!=n.doc&&Od(e.doc,n.doc,0,r):n.doc.descendants(r),t}function Qy(n,e,t,r){let i=V.get(e);if(!i.problems)return r;r||(r=n.tr);let s=[];for(let c=0;c0){let u="cell";h.firstChild&&(u=h.firstChild.type.spec.tableRole);let p=[];for(let g=0;g0?-1:0;$y(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o0&&i0&&e.map[l-1]==c||i0?-1:0;r0(e,r,i+c)&&(c=i==0||i==e.height?null:0);for(let a=0,h=e.width*i;a0&&i0&&d==e.map[h-e.width]){let f=t.nodeAt(d).attrs;n.setNodeMarkup(n.mapping.slice(l).map(d+r),null,{...f,rowspan:f.rowspan-1}),a+=f.colspan-1}else if(i0&&t[s]==t[s-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function d0(n){return(e,t)=>{var r;let i=e.selection,s,o;if(i instanceof B){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;s=i.$anchorCell.nodeAfter,o=i.$anchorCell.pos}else{if(s=qy(i.$from),!s)return!1;o=(r=Zn(i.$from))==null?void 0:r.pos}if(s==null||o==null||s.attrs.colspan==1&&s.attrs.rowspan==1)return!1;if(t){let l=s.attrs,c=[],a=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});let h=Je(e),d=e.tr;for(let u=0;ui.table.nodeAt(c));for(let c=0;c{let p=u+s.tableStart,m=o.doc.nodeAt(p);m&&o.setNodeMarkup(p,f,m.attrs)}),r(o)}return!0}}var Qx=Ul("row",{useDeprecatedLogic:!0}),Zx=Ul("column",{useDeprecatedLogic:!0}),eS=Ul("cell",{useDeprecatedLogic:!0});function u0(n,e){if(e<0){let t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){let s=n.node(-1).child(r),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(n.index()0;r--)if(t.node(r).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(r),t.after(r)).scrollIntoView()),!0;return!1}function xs(n,e){let t=n.selection;if(!(t instanceof B))return!1;if(e){let r=n.tr,i=de(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function g0(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;let i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let c=0;c=0;o--){let{rowspan:l,colspan:c}=s.child(o).attrs;for(let a=i;a=e.length&&e.push(w.empty),t[i]r&&(f=f.type.createChecked(gn(f.attrs,f.attrs.colspan,h+f.attrs.colspan-r),f.content)),a.push(f),h+=f.attrs.colspan;for(let u=1;ui&&(d=d.type.create({...d.attrs,rowspan:Math.max(1,i-d.attrs.rowspan)},d.content)),c.push(d)}s.push(w.from(c))}t=s,e=i}return{width:n,height:e,rows:t}}function b0(n,e,t,r,i,s,o){let l=n.doc.type.schema,c=de(l),a,h;if(i>e.width)for(let d=0,f=0;de.height){let d=[];for(let p=0,m=(e.height-1)*e.width;p=e.width?!1:t.nodeAt(e.map[m+p]).type==c.header_cell;d.push(g?h||(h=c.header_cell.createAndFill()):a||(a=c.cell.createAndFill()))}let f=c.row.create(null,w.from(d)),u=[];for(let p=e.height;p{if(!i)return!1;let s=t.selection;if(s instanceof B)return Cs(t,r,S.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=vd(i,n,e);if(o==null)return!1;if(n=="horiz")return Cs(t,r,S.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),c=Ed(l,n,e),a;return c?a=S.near(c,1):e<0?a=S.near(t.doc.resolve(l.before(-1)),-1):a=S.near(t.doc.resolve(l.after(-1)),1),Cs(t,r,a)}}}function ks(n,e){return(t,r,i)=>{if(!i)return!1;let s=t.selection,o;if(s instanceof B)o=s;else{let c=vd(i,n,e);if(c==null)return!1;o=new B(t.doc.resolve(c))}let l=Ed(o.$headCell,n,e);return l?Cs(t,r,new B(o.$anchorCell,l)):!1}}function S0(n,e){let t=n.state.doc,r=Zn(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new B(r))),!0):!1}function k0(n,e,t){if(!He(n.state))return!1;let r=g0(t),i=n.state.selection;if(i instanceof B){r||(r={width:1,height:1,rows:[w.from(Il(de(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=V.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=w0(r,l.right-l.left,l.bottom-l.top),kd(n.state,n.dispatch,o,l,r),!0}else if(r){let s=vl(n.state),o=s.start(-1);return kd(n.state,n.dispatch,o,V.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function C0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Cd(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof B)s(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Zn(n.state.selection.$anchor))!=null&&((t=Tl(n,e))==null?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(c,a){let h=Tl(n,a),d=zt.getState(n.state)==null;if(!h||!_l(c,h))if(d)h=c;else return;let f=new B(c,h);if(d||!n.state.selection.eq(f)){let u=n.state.tr.setSelection(f);d&&u.setMeta(zt,c.pos),n.dispatch(u)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),zt.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(zt,-1))}function l(c){let a=c,h=zt.getState(n.state),d;if(h!=null)d=n.state.doc.resolve(h);else if(Cd(n,a.target)!=r&&(d=Tl(n,e),!d))return o();d&&s(d,a)}n.root.addEventListener("mouseup",o),n.root.addEventListener("dragstart",o),n.root.addEventListener("mousemove",l)}function vd(n,e,t){if(!(n.state.selection instanceof A))return null;let{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){let l=r.before(i),c=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(c)?l:null}}return null}function Cd(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Tl(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Zn(n.state.doc.resolve(t.pos)):null}var M0=class{constructor(n,e){this.node=n,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Rl(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,Rl(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function Rl(n,e,t,r,i,s){var o;let l=0,c=!0,a=e.firstChild,h=n.firstChild;if(h){for(let d=0,f=0;dnew t(d,e,f)),new E0(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes:s=>{let o=Ve.getState(s);return o&&o.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,o)=>{T0(s,o,n,e,r)},mouseleave:s=>{D0(s)},mousedown:(s,o)=>{O0(s,o,e)}},decorations:s=>{let o=Ve.getState(s);if(o&&o.activeHandle>-1)return U0(s,o.activeHandle)},nodeViews:{}}});return i}var E0=class Ms{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(Ve);if(r&&r.setHandle!=null)return new Ms(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Ms(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Nl(e.doc.resolve(i))||(i=-1),new Ms(i,t.dragging)}return t}};function T0(n,e,t,r,i){let s=Ve.getState(n.state);if(s&&!s.dragging){let o=I0(e.target),l=-1;if(o){let{left:c,right:a}=o.getBoundingClientRect();e.clientX-c<=t?l=Md(n,e,"left",t):a-e.clientX<=t&&(l=Md(n,e,"right",t))}if(l!=s.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=V.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}_d(n,l)}}}function D0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&_d(n,-1)}function O0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,s=Ve.getState(n.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let o=n.state.doc.nodeAt(s.activeHandle),l=N0(n,s.activeHandle,o.attrs);n.dispatch(n.state.tr.setMeta(Ve,{setDragging:{startX:e.clientX,startWidth:l}}));function c(h){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",a);let d=Ve.getState(n.state);d?.dragging&&(R0(n,d.activeHandle,Ad(d.dragging,h,t)),n.dispatch(n.state.tr.setMeta(Ve,{setDragging:null})))}function a(h){if(!h.which)return c(h);let d=Ve.getState(n.state);if(d&&d.dragging){let f=Ad(d.dragging,h,t);v0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function N0(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,c=t;if(r)for(let a=0;ajs,AbstractConnector:()=>ac,AbstractStruct:()=>yr,AbstractType:()=>W,Array:()=>On,ContentAny:()=>Kt,ContentBinary:()=>In,ContentDeleted:()=>wr,ContentDoc:()=>Rn,ContentEmbed:()=>Et,ContentFormat:()=>L,ContentJSON:()=>ki,ContentString:()=>Re,ContentType:()=>Ae,Doc:()=>We,GC:()=>ue,ID:()=>Mt,Item:()=>O,Map:()=>Nn,PermanentUserData:()=>dc,RelativePosition:()=>ot,Skip:()=>ie,Snapshot:()=>jt,Text:()=>ct,Transaction:()=>Ys,UndoManager:()=>Tn,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>st,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>at,XmlHook:()=>Si,XmlText:()=>xe,YArrayEvent:()=>Qs,YEvent:()=>Dn,YMapEvent:()=>Zs,YTextEvent:()=>eo,YXmlEvent:()=>to,applyUpdate:()=>kc,applyUpdateV2:()=>vn,cleanupYTextFormatting:()=>Ou,compareIDs:()=>kn,compareRelativePositions:()=>ro,convertUpdateFormatV1ToV2:()=>h1,convertUpdateFormatV2ToV1:()=>fu,createAbsolutePositionFromRelativePosition:()=>Tc,createDeleteSet:()=>br,createDeleteSetFromStructStore:()=>bc,createDocFromSnapshot:()=>Yw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>Ci,createSnapshot:()=>Mi,decodeRelativePosition:()=>Jw,decodeSnapshot:()=>jw,decodeSnapshotV2:()=>Zf,decodeStateVector:()=>Mc,decodeUpdate:()=>r1,decodeUpdateV2:()=>ou,diffUpdate:()=>l1,diffUpdateV2:()=>Dc,emptySnapshot:()=>Kw,encodeRelativePosition:()=>qw,encodeSnapshot:()=>Ww,encodeSnapshotV2:()=>Qf,encodeStateAsUpdate:()=>Cc,encodeStateAsUpdateV2:()=>Yf,encodeStateVector:()=>Ec,encodeStateVectorFromUpdate:()=>i1,encodeStateVectorFromUpdateV2:()=>cu,equalDeleteSets:()=>jf,equalSnapshots:()=>$w,findIndexSS:()=>ze,findRootTypeKey:()=>_n,getItem:()=>Cn,getState:()=>P,getTypeChildren:()=>p1,isDeleted:()=>Tt,isParentOf:()=>En,iterateDeletedStructs:()=>rt,logType:()=>Pw,logUpdate:()=>n1,logUpdateV2:()=>su,mergeDeleteSets:()=>Mn,mergeUpdates:()=>lu,mergeUpdatesV2:()=>yi,obfuscateUpdate:()=>c1,obfuscateUpdateV2:()=>a1,parseUpdateMeta:()=>s1,parseUpdateMetaV2:()=>au,readUpdate:()=>_w,readUpdateV2:()=>Sc,relativePositionToJSON:()=>Lw,snapshot:()=>Ai,snapshotContainsUpdate:()=>Xw,transact:()=>R,tryGc:()=>e1,typeListToArraySnapshot:()=>lo,typeMapGetAllSnapshot:()=>Mu,typeMapGetSnapshot:()=>y1});var _=()=>new Map,As=n=>{let e=_();return n.forEach((t,r)=>{e.set(r,t)}),e},$=(n,e,t)=>{let r=n.get(e);return r===void 0&&n.set(e,r=t()),r},Ud=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Vd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var Es=n=>n[n.length-1];var Bd=(n,e)=>{for(let t=0;t{for(let t=0;t{let t=new Array(n);for(let r=0;r{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}},tr=class{constructor(){this._observers=_()}on(e,t){$(this._observers,e,Ce).add(t)}once(e,t){let r=(...i)=>{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}};var fe=Math.floor;var nr=Math.abs;var De=(n,e)=>nn>e?n:e,aS=Number.isNaN,zd=Math.pow;var Ds=n=>n!==0?n<0:1/n<0;var Vl=Number.MAX_SAFE_INTEGER,hS=Number.MIN_SAFE_INTEGER,dS=1<<31;var Fd=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&fe(n)===n),fS=Number.isNaN,uS=Number.parseInt;var Bl=String.fromCharCode,pS=String.fromCodePoint,mS=Bl(65535),B0=n=>n.toLowerCase(),P0=/^\s*/g,L0=n=>n.replace(P0,""),z0=/([A-Z])/g,Pl=(n,e)=>L0(n.replace(z0,t=>`${e}${B0(t)}`));var F0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;iir.encode(n),Hd=ir?q0:F0;var rr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});rr&&rr.decode(new Uint8Array).length===1&&(rr=null);var Jd=(n,e)=>Ld(e,()=>n).join("");var wn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},F=()=>new wn;var Ns=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(Ns(n)),t=0;for(let r=0;r{let t=n.cbuf.length;t-n.cpos{let t=n.cbuf.length;n.cpos===t&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(t*2),n.cpos=0),n.cbuf[n.cpos++]=e};var cr=Q;var x=(n,e)=>{for(;e>127;)Q(n,128|127&e),e=fe(e/128);Q(n,127&e)},ni=(n,e)=>{let t=Ds(e);for(t&&(e=-e),Q(n,(e>63?128:0)|(t?64:0)|63&e),e=fe(e/64);e>0;)Q(n,(e>127?128:0)|127&e),e=fe(e/128)},Ll=new Uint8Array(3e4),J0=Ll.length/3,$0=(n,e)=>{if(e.length{let t=unescape(encodeURIComponent(e)),r=t.length;x(n,r);for(let i=0;iar(n,I(e)),ar=(n,e)=>{let t=n.cbuf.length,r=n.cpos,i=De(t-r,e.length),s=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,s>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Be(t*2,s)),n.cbuf.set(e.subarray(i)),n.cpos=s)},U=(n,e)=>{x(n,e.byteLength),ar(n,e)},zl=(n,e)=>{H0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},j0=(n,e)=>zl(n,4).setFloat32(0,e,!1),K0=(n,e)=>zl(n,8).setFloat64(0,e,!1),Y0=(n,e)=>zl(n,8).setBigInt64(0,e,!1);var Wd=new DataView(new ArrayBuffer(4)),G0=n=>(Wd.setFloat32(0,n),Wd.getFloat32(0)===n),or=(n,e)=>{switch(typeof e){case"string":Q(n,119),Qe(n,e);break;case"number":Fd(e)&&nr(e)<=2147483647?(Q(n,125),ni(n,e)):G0(e)?(Q(n,124),j0(n,e)):(Q(n,123),K0(n,e));break;case"bigint":Q(n,122),Y0(n,e);break;case"object":if(e===null)Q(n,126);else if(Zr(e)){Q(n,117),x(n,e.length);for(let t=0;t0&&x(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}};var jd=n=>{n.count>0&&(ni(n.encoder,n.count===1?n.s:-n.s),n.count>1&&x(n.encoder,n.count-2))},bn=class{constructor(){this.encoder=new wn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(jd(this),this.count=1,this.s=e)}toUint8Array(){return jd(this),I(this.encoder)}};var Kd=n=>{if(n.count>0){let e=n.diff*2+(n.count===1?0:1);ni(n.encoder,e),n.count>1&&x(n.encoder,n.count-2)}},lr=class{constructor(){this.encoder=new wn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Kd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Kd(this),I(this.encoder)}},Os=class{constructor(){this.sarr=[],this.s="",this.lensE=new bn}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){let e=new wn;return this.sarr.push(this.s),this.s="",Qe(e,this.sarr.join("")),ar(e,this.lensE.toUint8Array()),I(e)}};var Ze=n=>new Error(n),Oe=()=>{throw Ze("Method unimplemented")},j=()=>{throw Ze("Unexpected case")};var Gd=Ze("Unexpected end of array"),Xd=Ze("Integer out of Range"),hr=class{constructor(e){this.arr=e,this.pos=0}},q=n=>new hr(n),Fl=n=>n.pos!==n.arr.length;var X0=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>X0(n,k(n));var xn=n=>n.arr[n.pos++];var k=n=>{let e=0,t=1,r=n.arr.length;for(;n.posVl)throw Xd}throw Gd},ii=n=>{let e=n.arr[n.pos++],t=e&63,r=64,i=(e&64)>0?-1:1;if(!(e&128))return i*t;let s=n.arr.length;for(;n.posVl)throw Xd}throw Gd};var Q0=n=>{let e=k(n);if(e===0)return"";{let t=String.fromCodePoint(xn(n));if(--e<100)for(;e--;)t+=String.fromCodePoint(xn(n));else for(;e>0;){let r=e<1e4?e:1e4,i=n.arr.subarray(n.pos,n.pos+r);n.pos+=r,t+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(t))}},Z0=n=>rr.decode(K(n)),Le=rr?Z0:Q0;var ql=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},ew=n=>ql(n,4).getFloat32(0,!1),tw=n=>ql(n,8).getFloat64(0,!1),nw=n=>ql(n,8).getBigInt64(0,!1);var rw=[n=>{},n=>null,ii,ew,tw,nw,n=>!1,n=>!0,Le,n=>{let e=k(n),t={};for(let r=0;r{let e=k(n),t=[];for(let r=0;rrw[127-xn(n)](n),ri=class extends hr{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Fl(this)?this.count=k(this)+1:this.count=-1),this.count--,this.s}};var Sn=class extends hr{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=ii(this);let e=Ds(this.s);this.count=1,e&&(this.s=-this.s,this.count=k(this)+2)}return this.count--,this.s}};var fr=class extends hr{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=ii(this),t=e&1;this.diff=fe(e/2),this.count=1,t&&(this.count=k(this)+2)}return this.s+=this.diff,this.count--,this.s}},vs=class{constructor(e){this.decoder=new Sn(e),this.str=Le(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};var wS=crypto.subtle,Qd=crypto.getRandomValues.bind(crypto);var iw=Math.random,Hl=()=>Qd(new Uint32Array(1))[0];var Zd=n=>n[fe(iw()*n.length)],sw="10000000-1000-4000-8000"+-1e11,ef=()=>sw.replace(/[018]/g,n=>(n^Hl()&15>>n/4).toString(16));var Ne=Date.now;var Jl=n=>new Promise(n);var SS=Promise.all.bind(Promise);var $l=n=>n===void 0?null:n;var Wl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},nf=new Wl,jl=!0;try{typeof localStorage<"u"&&localStorage&&(nf=localStorage,jl=!1)}catch{}var Us=nf,rf=n=>jl||addEventListener("storage",n),sf=n=>jl||removeEventListener("storage",n);var cf=Object.assign,Vs=Object.keys,af=(n,e)=>{for(let t in n)e(n[t],t)},hf=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Kl=n=>Vs(n).length,lf=n=>Vs(n).length;var df=n=>{for(let e in n)return!1;return!0},cw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Yl=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Gl=(n,e)=>n===e||lf(n)===lf(e)&&cw(n,(t,r)=>(t!==void 0||Yl(e,r))&&e[r]===t),aw=Object.freeze,Xl=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&Xl(n[e])}return aw(n)};var oi=(n,e,t=0)=>{try{for(;tn,hw=(n,e)=>n===e;var ur=(n,e)=>{if(n==null||e==null)return hw(n,e);if(n.constructor!==e.constructor)return!1;if(n===e)return!0;switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),e=new Uint8Array(e);case Uint8Array:{if(n.byteLength!==e.byteLength)return!1;for(let t=0;te.includes(n);var kt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",pr=typeof window<"u"&&typeof document<"u"&&!kt,kS=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,et,dw=[],fw=()=>{if(et===void 0)if(kt){et=_();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");et.set(`--${Pl(e,"-")}`,t),et.set(`-${Pl(e,"-")}`,t)}})):et=_();return et},ec=n=>fw().has(n);var li=n=>kt?$l(process.env[n.toUpperCase().replaceAll("-","_")]):$l(Us.getItem(n));var uf=n=>ec("--"+n)||li(n)!==null,CS=uf("production"),uw=kt&&ff(process.env.FORCE_COLOR,["true","1","2"]),pf=uw||!ec("--no-colors")&&!uf("no-color")&&(!kt||process.stdout.isTTY)&&(!kt||ec("--color")||li("COLORTERM")!==null||(li("TERM")||"").includes("color"));var mf=n=>new Uint8Array(n),pw=(n,e,t)=>new Uint8Array(n,e,t),gf=n=>new Uint8Array(n),mw=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),yw=n=>{let e=atob(n),t=mf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return pw(e.buffer,e.byteOffset,e.byteLength)},yf=pr?mw:gw,wf=pr?yw:ww;var bf=n=>{let e=mf(n.byteLength);return e.set(n),e};var tc=class{constructor(e,t){this.left=e,this.right=t}},tt=(n,e)=>new tc(n,e);var Ct=typeof document<"u"?document:{};var MS=typeof DOMParser<"u"?new DOMParser:null;var Sf=n=>Ud(n,(e,t)=>`${t}:${e};`).join("");var AS=Ct.ELEMENT_NODE,ES=Ct.TEXT_NODE,TS=Ct.CDATA_SECTION_NODE,DS=Ct.COMMENT_NODE,OS=Ct.DOCUMENT_NODE,NS=Ct.DOCUMENT_TYPE_NODE,IS=Ct.DOCUMENT_FRAGMENT_NODE;var Ps=n=>class{constructor(t){this._=t}destroy(){n(this._)}},xw=Ps(clearTimeout),ai=(n,e)=>new xw(setTimeout(e,n)),vS=Ps(clearInterval);var _S=Ps(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var US=Ps(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var nt=Symbol;var hi=nt(),di=nt(),nc=nt(),rc=nt(),ic=nt(),fi=nt(),sc=nt(),mr=nt(),oc=nt(),Mf=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=0;for(;r0&&t.push(e.join(""));r{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=_(),i=[],s=0;for(;s0||c.length>0?(e.push("%c"+o),t.push(c)):e.push(o)}else break}}for(s>0&&(i=t,i.unshift(e.join("")));s{console.log(...Af(n)),Ef.forEach(e=>e.print(n))},lc=(...n)=>{console.warn(...Af(n)),n.unshift(mr),Ef.forEach(e=>e.print(n))};var Ef=Ce();var Tf=n=>({[Symbol.iterator](){return this},next:n}),Df=(n,e)=>Tf(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),zs=(n,e)=>Tf(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var ac=class extends er{constructor(e,t){super(),this.doc=e,this.awareness=t}},pi=class{constructor(e,t){this.clock=e,this.len=t}},$t=class{constructor(){this.clients=new Map}},rt=(n,e,t)=>e.clients.forEach((r,i)=>{let s=n.doc.store.clients.get(i);for(let o=0;o{let t=0,r=n.length-1;for(;t<=r;){let i=fe((t+r)/2),s=n[i],o=s.clock;if(o<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&Ow(t,e.clock)!==null},wc=n=>{n.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let t,r;for(t=1,r=1;t=s.clock?i.len=Be(i.len,s.clock+s.len-i.clock):(r{let e=new $t;for(let t=0;t{if(!e.clients.has(i)){let s=r.slice();for(let o=t+1;o{$(n.clients,e,()=>[]).push(new pi(t,r))},br=()=>new $t,bc=n=>{let e=br();return n.clients.forEach((t,r)=>{let i=[];for(let s=0;s0&&e.clients.set(r,i)}),e},it=(n,e)=>{x(n.restEncoder,e.clients.size),$e(e.clients.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{n.resetDsCurVal(),x(n.restEncoder,t);let i=r.length;x(n.restEncoder,i);for(let s=0;s{let e=new $t,t=k(n.restDecoder);for(let r=0;r0){let o=$(e.clients,i,()=>[]);for(let l=0;l{let r=new $t,i=k(n.restDecoder);for(let s=0;s0){let s=new Ie;return x(s.restEncoder,0),it(s,r),s.toUint8Array()}return null},jf=(n,e)=>{if(n.clients.size!==e.clients.size)return!1;for(let[t,r]of n.clients.entries()){let i=e.clients.get(t);if(i===void 0||r.length!==i.length)return!1;for(let s=0;s!0,meta:s=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Kf(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ks,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Jl(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>Jl(a=>{let h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){let e=this._item;e!==null&&!this.shouldLoad&&R(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set($e(this.subdocs).map(e=>e.guid))}transact(e,t=null){return R(this,e,t)}get(e,t=W){let r=$(this.share,e,()=>{let s=new t;return s._integrate(this,null),s}),i=r.constructor;if(t!==W&&i!==t)if(i===W){let s=new t;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,On)}getText(e=""){return this.get(e,ct)}getMap(e=""){return this.get(e,Nn)}getXmlElement(e=""){return this.get(e,Z)}getXmlFragment(e=""){return this.get(e,at)}toJSON(){let e={};return this.share.forEach((t,r)=>{e[r]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,$e(this.subdocs).forEach(t=>t.destroy());let e=this._item;if(e!==null){this._item=null;let t=e.content;t.doc=new n({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,R(e.parent.doc,r=>{let i=t.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},An=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return k(this.restDecoder)}readDsLen(){return k(this.restDecoder)}},Me=class extends An{readLeftID(){return M(k(this.restDecoder),k(this.restDecoder))}readRightID(){return M(k(this.restDecoder),k(this.restDecoder))}readClient(){return k(this.restDecoder)}readInfo(){return xn(this.restDecoder)}readString(){return Le(this.restDecoder)}readParentInfo(){return k(this.restDecoder)===1}readTypeRef(){return k(this.restDecoder)}readLen(){return k(this.restDecoder)}readAny(){return dr(this.restDecoder)}readBuf(){return bf(K(this.restDecoder))}readJSON(){return JSON.parse(Le(this.restDecoder))}readKey(){return Le(this.restDecoder)}},Ws=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=k(this.restDecoder),this.dsCurrVal}readDsLen(){let e=k(this.restDecoder)+1;return this.dsCurrVal+=e,e}},be=class extends Ws{constructor(e){super(e),this.keys=[],k(e),this.keyClockDecoder=new fr(K(e)),this.clientDecoder=new Sn(K(e)),this.leftClockDecoder=new fr(K(e)),this.rightClockDecoder=new fr(K(e)),this.infoDecoder=new ri(K(e),xn),this.stringDecoder=new vs(K(e)),this.parentInfoDecoder=new ri(K(e),xn),this.typeRefDecoder=new Sn(K(e)),this.lenDecoder=new Sn(K(e))}readLeftID(){return new Mt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Mt(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 dr(this.restDecoder)}readBuf(){return K(this.restDecoder)}readJSON(){return dr(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=Be(r,e[0].id.clock);let i=ze(e,r);x(n.restEncoder,e.length-i),n.writeClient(t),x(n.restEncoder,r);let s=e[i];s.write(n,r-s.id.clock);for(let o=i+1;o{let r=new Map;t.forEach((i,s)=>{P(e,s)>i&&r.set(s,i)}),Ei(e).forEach((i,s)=>{t.has(s)||r.set(s,0)}),x(n.restEncoder,r.size),$e(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{Nw(n,e.clients.get(i),i,s)})},Iw=(n,e)=>{let t=_(),r=k(n.restDecoder);for(let i=0;i{let r=[],i=$e(t.keys()).sort((u,p)=>u-p);if(i.length===0)return null;let s=()=>{if(i.length===0)return null;let u=t.get(i[i.length-1]);for(;u.refs.length===u.i;)if(i.pop(),i.length>0)u=t.get(i[i.length-1]);else return null;return u},o=s();if(o===null)return null;let l=new Ks,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=o.refs[o.i++],d=new Map,f=()=>{for(let u of r){let p=u.id.client,m=t.get(p);m?(m.i--,l.clients.set(p,m.refs.slice(m.i)),t.delete(p),m.i=0,m.refs=[]):l.clients.set(p,[u]),i=i.filter(g=>g!==p)}r.length=0};for(;;){if(h.constructor!==ie){let p=$(d,h.id.client,()=>P(e,h.id.client))-h.id.clock;if(p<0)r.push(h),a(h.id.client,h.id.clock-1),f();else{let m=h.getMissing(n,e);if(m!==null){r.push(h);let g=t.get(m)||{refs:[],i:0};if(g.refs.length===g.i)a(m,P(e,m)),f();else{h=g.refs[g.i++];continue}}else(p===0||p0)h=r.pop();else if(o!==null&&o.i0){let u=new Ie;return xc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},vw=(n,e)=>xc(n,e.doc.store,e.beforeState),Sc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let s=!1,o=i.doc,l=o.store,c=Iw(r,o),a=Rw(i,l,c),h=l.pendingStructs;if(h){for(let[f,u]of h.missing)if(uu)&&h.missing.set(f,u)}h.update=yi([h.update,a.update])}}else l.pendingStructs=a;let d=If(r,i,l);if(l.pendingDs){let f=new be(q(l.pendingDs));k(f.restDecoder);let u=If(f,i,l);d&&u?l.pendingDs=yi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(s){let f=l.pendingStructs.update;l.pendingStructs=null,vn(i.doc,f)}},t,!1),_w=(n,e,t)=>Sc(n,e,t,new Me(n)),vn=(n,e,t,r=be)=>{let i=q(e);Sc(i,n,t,new r(i))},kc=(n,e,t)=>vn(n,e,t,Me),Uw=(n,e,t=new Map)=>{xc(n,e.store,t),it(n,bc(e.store))},Yf=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Mc(e);Uw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Dc(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===st)return lu(i.map((s,o)=>o===0?s:fu(s)));if(t.constructor===Ie)return yi(i)}return i[0]},Cc=(n,e)=>Yf(n,e,new st),Gf=n=>{let e=new Map,t=k(n.restDecoder);for(let r=0;rGf(new An(q(n))),Ac=(n,e)=>(x(n.restEncoder,e.size),$e(e.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{x(n.restEncoder,t),x(n.restEncoder,r)}),n),Vw=(n,e)=>Ac(n,Ei(e.store)),Bw=(n,e=new gr)=>(n instanceof Map?Ac(e,n):Vw(e,n),e.toUint8Array()),Ec=n=>Bw(n,new Wt),hc=class{constructor(){this.l=[]}},Rf=()=>new hc,vf=(n,e)=>n.l.push(e),_f=(n,e)=>{let t=n.l,r=t.length;n.l=t.filter(i=>e!==i),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Xf=(n,e,t)=>oi(n.l,[e,t]),Mt=class{constructor(e,t){this.client=e,this.clock=t}},kn=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,M=(n,e)=>new Mt(n,e),Uf=(n,e)=>{x(n,e.client),x(n,e.clock)},Vf=n=>M(k(n),k(n)),_n=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw j()},En=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1},Pw=n=>{let e=[],t=n._start;for(;t;)e.push(t),t=t.right;console.log("Children: ",e),console.log("Children content: ",e.filter(r=>!r.deleted).map(r=>r.content))},dc=class{constructor(e,t=e.getMap("users")){let r=new Map;this.yusers=t,this.doc=e,this.clients=new Map,this.dss=r;let i=(s,o)=>{let l=s.get("ds"),c=s.get("ids"),a=h=>this.clients.set(h,o);l.observe(h=>{h.changes.added.forEach(d=>{d.content.getContent().forEach(f=>{f instanceof Uint8Array&&this.dss.set(o,Mn([this.dss.get(o)||br(),At(new An(q(f)))]))})})}),this.dss.set(o,Mn(l.map(h=>At(new An(q(h)))))),c.observe(h=>h.changes.added.forEach(d=>d.content.getContent().forEach(a))),c.forEach(a)};t.observe(s=>{s.keysChanged.forEach(o=>i(t.get(o),o))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let s=this.yusers,o=s.get(r);o||(o=new Nn,o.set("ids",new On),o.set("ds",new On),s.set(r,o)),o.get("ids").push([t]),s.observe(l=>{setTimeout(()=>{let c=s.get(r);if(c!==o){o=c,this.clients.forEach((d,f)=>{r===d&&o.get("ids").push([f])});let a=new Wt,h=this.dss.get(r);h&&(it(a,h),o.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=o.get("ds"),a=l.deleteSet;if(l.local&&a.clients.size>0&&i(l,a)){let h=new Wt;it(h,a),c.push([h.toUint8Array()])}})})}getUserByClientId(e){return this.clients.get(e)||null}getUserByDeletedId(e){for(let[t,r]of this.dss.entries())if(Tt(r,e))return t;return null}},ot=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},Lw=n=>{let e={};return n.type&&(e.type=n.type),n.tname&&(e.tname=n.tname),n.item&&(e.item=n.item),n.assoc!=null&&(e.assoc=n.assoc),e},Un=n=>new ot(n.type==null?null:M(n.type.client,n.type.clock),n.tname??null,n.item==null?null:M(n.item.client,n.item.clock),n.assoc==null?0:n.assoc),js=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},zw=(n,e,t=0)=>new js(n,e,t),Fs=(n,e,t)=>{let r=null,i=null;return n._item===null?i=_n(n):r=M(n._item.id.client,n._item.id.clock),new ot(r,i,e,t)},Ci=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return Fs(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Fs(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Fs(n,r.lastId,t);r=r.right}return Fs(n,null,t)},Fw=(n,e)=>{let{type:t,tname:r,item:i,assoc:s}=e;if(i!==null)x(n,0),Uf(n,i);else if(r!==null)cr(n,1),Qe(n,r);else if(t!==null)cr(n,2),Uf(n,t);else throw j();return ni(n,s),n},qw=n=>{let e=F();return Fw(e,n),I(e)},Hw=n=>{let e=null,t=null,r=null;switch(k(n)){case 0:r=Vf(n);break;case 1:t=Le(n);break;case 2:e=Vf(n)}let i=Fl(n)?ii(n):0;return new ot(e,t,r,i)},Jw=n=>Hw(q(n)),Tc=(n,e,t=!0)=>{let r=e.store,i=n.item,s=n.type,o=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(P(r,i.client)<=i.clock)return null;let h=t?gc(r,i):{item:Cn(r,i),diff:0},d=h.item;if(!(d instanceof O))return null;if(c=d.parent,c._item===null||!c._item.deleted){a=d.deleted||!d.countable?0:h.diff+(l>=0?0:1);let f=d.left;for(;f!==null;)!f.deleted&&f.countable&&(a+=f.length),f=f.left}}else{if(o!==null)c=e.get(o);else if(s!==null){if(P(r,s.client)<=s.clock)return null;let{item:h}=t?gc(r,s):{item:Cn(r,s)};if(h instanceof O&&h.content instanceof Ae)c=h.content.type;else return null}else throw j();l>=0?a=c._length:a=0}return zw(c,a,n.assoc)},ro=(n,e)=>n===e||n!==null&&e!==null&&n.tname===e.tname&&kn(n.item,e.item)&&kn(n.type,e.type)&&n.assoc===e.assoc,jt=class{constructor(e,t){this.ds=e,this.sv=t}},$w=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,s=e.sv;if(i.size!==s.size||t.size!==r.size)return!1;for(let[o,l]of i.entries())if(s.get(o)!==l)return!1;for(let[o,l]of t.entries()){let c=r.get(o)||[];if(l.length!==c.length)return!1;for(let a=0;a(it(e,n.ds),Ac(e,n.sv),e.toUint8Array()),Ww=n=>Qf(n,new Wt),Zf=(n,e=new Ws(q(n)))=>new jt(At(e),Gf(e)),jw=n=>Zf(n,new An(q(n))),Mi=(n,e)=>new jt(n,e),Kw=Mi(br(),new Map),Ai=n=>Mi(bc(n.store),Ei(n.store)),qt=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!Tt(e.ds,n.id),fc=(n,e)=>{let t=$(n.meta,fc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i{}),t.add(e))},Yw=(n,e,t=new We)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,s=new Ie;return n.transact(o=>{let l=0;r.forEach(c=>{c>0&&l++}),x(s.restEncoder,l);for(let[c,a]of r){if(a===0)continue;a{let r=new t(q(e)),i=new lt(r,!1);for(let o=i.curr;o!==null;o=i.next())if((n.sv.get(o.id.client)||0)Gw(n,e,Me),Ks=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ei=n=>{let e=new Map;return n.clients.forEach((t,r)=>{let i=t[t.length-1];e.set(r,i.id.clock+i.length)}),e},P=(n,e)=>{let t=n.clients.get(e);if(t===void 0)return 0;let r=t[t.length-1];return r.id.clock+r.length},eu=(n,e)=>{let t=n.clients.get(e.id.client);if(t===void 0)t=[],n.clients.set(e.id.client,t);else{let r=t[t.length-1];if(r.id.clock+r.length!==e.id.clock)throw j()}t.push(e)},ze=(n,e)=>{let t=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===e)return r;let o=fe(e/(s+i.length-1)*r);for(;t<=r;){if(i=n[o],s=i.id.clock,s<=e){if(e{let t=n.clients.get(e.client);return t[ze(t,e.clock)]},Cn=Qw,uc=(n,e,t)=>{let r=ze(e,t),i=e[r];return i.id.clock{let t=n.doc.store.clients.get(e.client);return t[uc(n,t,e.clock)]},Bf=(n,e,t)=>{let r=e.clients.get(t.client),i=ze(r,t.clock),s=r[i];return t.clock!==s.id.clock+s.length-1&&s.constructor!==ue&&r.splice(i+1,0,no(n,s,t.clock-s.id.clock+1)),s},Zw=(n,e,t)=>{let r=n.clients.get(e.id.client);r[ze(r,e.id.clock)]=t},tu=(n,e,t,r,i)=>{if(r===0)return;let s=t+r,o=uc(n,e,t),l;do l=e[o++],se.deleteSet.clients.size===0&&!Vd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(wc(e.deleteSet),vw(n,e),it(n,e.deleteSet),!0),Lf=(n,e,t)=>{let r=e._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&$(n.changed,e,Ce).add(t)},Js=(n,e)=>{let t=n[e],r=n[e-1],i=e;for(;i>0;t=r,r=n[--i-1]){if(r.deleted===t.deleted&&r.constructor===t.constructor&&r.mergeWith(t)){t instanceof O&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,r);continue}break}let s=e-i;return s&&n.splice(e+1-s,s),s},nu=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){let l=i[o],c=l.clock+l.len;for(let a=ze(s,l.clock),h=s[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let s=t.length-1;s>=0;s--){let o=t[s],l=De(i.length-1,1+ze(i,o.clock+o.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=o.clock;a=i[c])c-=1+Js(i,c)}})},e1=(n,e,t)=>{nu(n,e,t),ru(n,e)},iu=(n,e)=>{if(el.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(t,c)})),l.push(()=>{t.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,d)=>h.path.length-d.path.length),Xf(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),oi(l,[]),t._needFormattingCleanup&&S1(t)}finally{r.gc&&nu(s,i,r.gcFilter),ru(s,i),t.afterState.forEach((h,d)=>{let f=t.beforeState.get(d)||0;if(f!==h){let u=i.clients.get(d),p=Be(ze(u,f),1);for(let m=u.length-1;m>=p;)m-=1+Js(u,m)}});for(let h=o.length-1;h>=0;h--){let{client:d,clock:f}=o[h].id,u=i.clients.get(d),p=ze(u,f);p+11||p>0&&Js(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(Ls(mr,hi,"[yjs] ",di,fi,"Changed the client-id because another client seems to be using it."),r.clientID=Kf()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new st;Pf(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;Pf(h,t)&&r.emit("updateV2",[h.toUint8Array(),t.origin,r,t])}let{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=t;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=r.clientID,h.collectionid==null&&(h.collectionid=r.collectionid),r.subdocs.add(h)}),a.forEach(h=>r.subdocs.delete(h)),r.emit("subdocs",[{loaded:c,added:l,removed:a},r,t]),a.forEach(h=>h.destroy())),n.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):iu(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new Ys(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=e(n._transaction)}finally{if(s){let l=n._transaction===i[0];n._transaction=null,l&&iu(i,0)}}return o},pc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},zf=(n,e,t)=>{rt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>En(i,r))&&vc(r,!1)})},Ff=(n,e,t)=>{let r=null,i=n.doc,s=n.scope;R(i,l=>{for(;e.length>0&&n.currStackItem===null;){let c=i.store,a=e.pop(),h=new Set,d=[],f=!1;rt(l,a.insertions,u=>{if(u instanceof O){if(u.redone!==null){let{item:p,diff:m}=gc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&s.some(p=>En(p,u))&&d.push(u)}}),rt(l,a.deletions,u=>{u instanceof O&&s.some(p=>En(p,u))&&!Tt(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=Iu(l,u,h,a.insertions,n.ignoreRemoteMapChanges,n)!==null||f});for(let u=d.length-1;u>=0;u--){let p=d[u];n.deleteFilter(p)&&(p.delete(l),f=!0)}n.currStackItem=f?a:null}l.changed.forEach((c,a)=>{c.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=l},n);let o=n.currStackItem;if(o!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:o,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return o},Tn=class extends er{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=Zr(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,s.add(this),this.trackedOrigins=s,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=t,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(g=>c.changedParentTypes.has(g))||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;let a=this.undoing,h=this.redoing,d=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);let f=new $t;c.afterState.forEach((g,y)=>{let E=c.beforeState.get(y)||0,N=g-E;N>0&&mi(f,y,E,N)});let u=Ne(),p=!1;if(this.lastChange>0&&u-this.lastChange0&&!a&&!h){let g=d[d.length-1];g.deletions=Mn([g.deletions,c.deleteSet]),g.insertions=Mn([g.insertions,f])}else d.push(new pc(c.deleteSet,f)),p=!0;!a&&!h&&(this.lastChange=u),rt(c,c.deleteSet,g=>{g instanceof O&&this.scope.some(y=>En(y,g))&&vc(g,!0)});let m=[{stackItem:d[d.length-1],origin:c.origin,type:a?"redo":"undo",changedParentTypes:c.changedParentTypes},this];p?this.emit("stack-item-added",m):this.emit("stack-item-updated",m)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){e=Zr(e)?e:[e],e.forEach(t=>{this.scope.every(r=>r!==t)&&(t.doc!==this.doc&&lc("[yjs#509] Not same Y.Doc"),this.scope.push(t))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(r=>{e&&(this.undoStack.forEach(i=>zf(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>zf(r,this,i)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Ff(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Ff(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}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*t1(n){let e=k(n.restDecoder);for(let t=0;tsu(n,Me),su=(n,e=be)=>{let t=[],r=new e(q(n)),i=new lt(r,!1);for(let o=i.curr;o!==null;o=i.next())t.push(o);Ls("Structs: ",t);let s=At(r);Ls("DeleteSet: ",s)},r1=n=>ou(n,Me),ou=(n,e=be)=>{let t=[],r=new e(q(n)),i=new lt(r,!1);for(let s=i.curr;s!==null;s=i.next())t.push(s);return{structs:t,ds:At(r)}},gi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},lu=n=>yi(n,Me,st),cu=(n,e=gr,t=be)=>{let r=new e,i=new lt(new t(q(n)),!1),s=i.curr;if(s!==null){let o=0,l=s.id.client,c=s.id.clock!==0,a=c?0:s.id.clock+s.length;for(;s!==null;s=i.next())l!==s.id.client&&(a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a)),l=s.id.client,a=0,c=s.id.clock!==0),s.constructor===ie&&(c=!0),c||(a=s.id.clock+s.length);a!==0&&(o++,x(r.restEncoder,l),x(r.restEncoder,a));let h=F();return x(h,o),Yd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},i1=n=>cu(n,Wt,Me),au=(n,e=be)=>{let t=new Map,r=new Map,i=new lt(new e(q(n)),!1),s=i.curr;if(s!==null){let o=s.id.client,l=s.id.clock;for(t.set(o,l);s!==null;s=i.next())o!==s.id.client&&(r.set(o,l),t.set(s.id.client,s.id.clock),o=s.id.client),l=s.id.clock+s.length;r.set(o,l)}return{from:t,to:r}},s1=n=>au(n,Me),o1=(n,e)=>{if(n.constructor===ue){let{client:t,clock:r}=n.id;return new ue(M(t,r+e),n.length-e)}else if(n.constructor===ie){let{client:t,clock:r}=n.id;return new ie(M(t,r+e),n.length-e)}else{let t=n,{client:r,clock:i}=t.id;return new O(M(r,i+e),null,M(r,i+e-1),null,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e))}},yi=(n,e=be,t=Ie)=>{if(n.length===1)return n[0];let r=n.map(h=>new e(q(h))),i=r.map(h=>new lt(h,!0)),s=null,o=new t,l=new gi(o);for(;i=i.filter(f=>f.curr!==null),i.sort((f,u)=>{if(f.curr.id.client===u.curr.id.client){let p=f.curr.id.clock-u.curr.id.clock;return p===0?f.curr.constructor===u.curr.constructor?0:f.curr.constructor===ie?1:-1:p}else return u.curr.id.client-f.curr.id.client}),i.length!==0;){let h=i[0],d=h.curr.id.client;if(s!==null){let f=h.curr,u=!1;for(;f!==null&&f.id.clock+f.length<=s.struct.id.clock+s.struct.length&&f.id.client>=s.struct.id.client;)f=h.next(),u=!0;if(f===null||f.id.client!==d||u&&f.id.clock>s.struct.id.clock+s.struct.length)continue;if(d!==s.struct.id.client)Ht(l,s.struct,s.offset),s={struct:f,offset:0},h.next();else if(s.struct.id.clock+s.struct.length0&&(s.struct.constructor===ie?s.struct.length-=p:f=o1(f,p)),s.struct.mergeWith(f)||(Ht(l,s.struct,s.offset),s={struct:f,offset:0},h.next())}}else s={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===s.struct.id.clock+s.struct.length&&f.constructor!==ie;f=h.next())Ht(l,s.struct,s.offset),s={struct:f,offset:0}}s!==null&&(Ht(l,s.struct,s.offset),s=null),Oc(l);let c=r.map(h=>At(h)),a=Mn(c);return it(o,a),o.toUint8Array()},Dc=(n,e,t=be,r=Ie)=>{let i=Mc(e),s=new r,o=new gi(s),l=new t(q(n)),c=new lt(l,!1);for(;c.curr;){let h=c.curr,d=h.id.client,f=i.get(d)||0;if(c.curr.constructor===ie){c.next();continue}if(h.id.clock+h.length>f)for(Ht(o,h,Be(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Ht(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=f;)c.next()}Oc(o);let a=At(l);return it(s,a),s.toUint8Array()},l1=(n,e)=>Dc(n,e,Me,st),hu=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:I(n.encoder.restEncoder)}),n.encoder.restEncoder=F(),n.written=0)},Ht=(n,e,t)=>{n.written>0&&n.currClient!==e.id.client&&hu(n),n.written===0&&(n.currClient=e.id.client,n.encoder.writeClient(e.id.client),x(n.encoder.restEncoder,e.id.clock+t)),e.write(n.encoder,t),n.written++},Oc=n=>{hu(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(q(n)),s=new lt(i,!1),o=new r,l=new gi(o);for(let a=s.curr;a!==null;a=s.next())Ht(l,e(a),0);Oc(l);let c=At(i);return it(o,c),o.toUint8Array()},du=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=_(),s=_(),o=_(),l=_();return l.set(null,null),c=>{switch(c.constructor){case ue:case ie:return c;case O:{let a=c,h=a.content;switch(h.constructor){case wr:break;case Ae:{if(t){let d=h.type;d instanceof Z&&(d.nodeName=$(s,d.nodeName,()=>"node-"+r)),d instanceof Si&&(d.hookName=$(s,d.hookName,()=>"hook-"+r))}break}case Kt:{let d=h;d.arr=d.arr.map(()=>r);break}case In:{let d=h;d.content=new Uint8Array([r]);break}case Rn:{let d=h;e&&(d.opts={},d.doc.guid=r+"");break}case Et:{let d=h;d.embed={};break}case L:{let d=h;n&&(d.key=$(o,d.key,()=>r+""),d.value=$(l,d.value,()=>({i:r})));break}case ki:{let d=h;d.arr=d.arr.map(()=>r);break}case Re:{let d=h;d.str=Jd(r%10+"",d.str.length);break}default:j()}return a.parentSub&&(a.parentSub=$(i,a.parentSub,()=>r+"")),r++,c}default:j()}}},c1=(n,e)=>io(n,du(e),Me,st),a1=(n,e)=>io(n,du(e),be,Ie),h1=n=>io(n,Ql,Me,Ie),fu=n=>io(n,Ql,be,st),qf="You must not compute changes after the event-handler fired.",Dn=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=d1(this.currentTarget,this.target))}deletes(e){return Tt(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ze(qf);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let s=t._map.get(i),o,l;if(this.adds(s)){let c=s.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(s))if(c!==null&&this.deletes(c))o="delete",l=Es(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Es(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(s))o="delete",l=Es(s.content.getContent());else return;e.set(i,{action:o,oldValue:l})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ze(qf);let t=this.target,r=Ce(),i=Ce(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&s.push(l)};for(let a=t._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,i.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),r.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=e}return e}},d1=(n,e)=>{let t=[];for(;e._item!==null&&e!==n;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)!i.deleted&&i.countable&&(r+=i.length),i=i.right;t.unshift(r)}e=e._item.parent}return t},se=()=>{lc("Invalid access: Add Yjs type to a document before reading data.")},uu=80,Nc=0,mc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Nc++}},f1=n=>{n.timestamp=Nc++},pu=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Nc++},u1=(n,e,t)=>{if(n.length>=uu){let r=n.reduce((i,s)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((s,o)=>nr(e-s.index)e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return t!==null&&nr(t.index-i){for(let r=n.length-1;r>=0;r--){let i=n[r];if(t>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){n.splice(r,1);continue}i.p=s,s.marker=!0}(e0&&e===i.index)&&(i.index=Be(e,i.index+t))}},p1=n=>{n.doc??se();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},oo=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Xf(r._eH,t,e)},W=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Rf(),this._dEH=Rf(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Oe()}clone(){throw Oe()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){vf(this._eH,e)}observeDeep(e){vf(this._dEH,e)}unobserve(e){_f(this._eH,e)}unobserveDeep(e){_f(this._dEH,e)}toJSON(){}},mu=(n,e,t)=>{n.doc??se(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],s=n._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){let o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let l=e;l0;l++)i.push(o[l]),r--;e=0}}s=s.right}return i},gu=n=>{n.doc??se();let e=[],t=n._start;for(;t!==null;){if(t.countable&&!t.deleted){let r=t.content.getContent();for(let i=0;i{let t=[],r=n._start;for(;r!==null;){if(r.countable&&qt(r,e)){let i=r.content.getContent();for(let s=0;s{let t=0,r=n._start;for(n.doc??se();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let s=0;s{let t=[];return bi(n,(r,i)=>{t.push(e(r,i,n))}),t},m1=n=>{let e=n._start,t=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),r=0,e=e.right}let i=t[r++];return t.length<=r&&(t=null),{done:!1,value:i}}}},wu=(n,e)=>{n.doc??se();let t=so(n,e),r=n._start;for(t!==null&&(r=t.p,e-=t.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e{let i=t,s=n.doc,o=s.clientID,l=s.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(o,P(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Kt(a)),i.integrate(n,0),a=[])};r.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:i=new O(M(o,P(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new In(new Uint8Array(d))),i.integrate(n,0);break;case We:i=new O(M(o,P(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Rn(d)),i.integrate(n,0);break;default:if(d instanceof W)i=new O(M(o,P(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Ae(d)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},bu=()=>Ze("Length exceeded!"),xu=(n,e,t,r)=>{if(t>e._length)throw bu();if(t===0)return e._searchMarker&&wi(e._searchMarker,t,r.length),Gs(n,e,null,r);let i=t,s=so(e,t),o=e._start;for(s!==null&&(o=s.p,t-=s.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Gs(n,e,i,t)},Su=(n,e,t,r)=>{if(r===0)return;let i=t,s=r,o=so(e,t),l=e._start;for(o!==null&&(l=o.p,t-=o.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw bu();e._searchMarker&&wi(e._searchMarker,i,-s+r)},Xs=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},Ic=(n,e,t,r)=>{let i=e._map.get(t)||null,s=n.doc,o=s.clientID,l;if(r==null)l=new Kt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:l=new Kt([r]);break;case Uint8Array:l=new In(r);break;case We:l=new Rn(r);break;default:if(r instanceof W)l=new Ae(r);else throw new Error("Unexpected content type")}new O(M(o,P(s.store,o)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},Rc=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},ku=n=>{let e={};return n.doc??se(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Cu=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted},y1=(n,e,t)=>{let r=n._map.get(e)||null;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;return r!==null&&qt(r,t)?r.content.getContent()[r.length-1]:void 0},Mu=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&qt(s,e)&&(t[i]=s.content.getContent()[s.length-1])}),t},qs=n=>(n.doc??se(),Df(n._map.entries(),e=>!e[1].deleted)),Qs=class extends Dn{},On=class n extends W{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){let t=new n;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof W?t.clone():t)),e}get length(){return this.doc??se(),this._length}_callObserver(e,t){super._callObserver(e,t),oo(this,e,new Qs(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{xu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{g1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Su(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return wu(this,e)}toArray(){return gu(this)}slice(e=0,t=this.length){return mu(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return yu(this,e)}forEach(e){bi(this,e)}[Symbol.iterator](){return m1(this)}_write(e){e.writeTypeRef(P1)}},w1=n=>new On,Zs=class extends Dn{constructor(e,t,r){super(e,t),this.keysChanged=r}},Nn=class n extends W{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return this.forEach((t,r)=>{e.set(r,t instanceof W?t.clone():t)}),e}_callObserver(e,t){oo(this,e,new Zs(this,e,t))}toJSON(){this.doc??se();let e={};return this._map.forEach((t,r)=>{if(!t.deleted){let i=t.content.getContent()[t.length-1];e[r]=i instanceof W?i.toJSON():i}}),e}get size(){return[...qs(this)].length}keys(){return zs(qs(this),e=>e[0])}values(){return zs(qs(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return zs(qs(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??se(),this._map.forEach((t,r)=>{t.deleted||e(t.content.getContent()[t.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?R(this.doc,t=>{Xs(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{Ic(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Rc(this,e)}has(e){return Cu(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){Xs(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(L1)}},b1=n=>new Nn,Jt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Gl(n,e),xi=class{constructor(e,t,r,i){this.left=e,this.right=t,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&j(),this.right.content.constructor){case L:this.right.deleted||xr(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}},Hf=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case L:e.right.deleted||xr(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t{let i=new Map,s=r?so(e,t):null;if(s){let o=new xi(s.p.left,s.p,s.index,i);return Hf(n,o,t-s.index)}else{let o=new xi(null,e._start,0,i);return Hf(n,o,t)}},Au=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===L&&Jt(r.get(t.right.content.key),t.right.content.value));)t.right.deleted||r.delete(t.right.content.key),t.forward();let i=n.doc,s=i.clientID;r.forEach((o,l)=>{let c=t.left,a=t.right,h=new O(M(s,P(i.store,s)),c,c&&c.lastId,a,a&&a.id,e,null,new L(l,o));h.integrate(n,0),t.right=h,t.forward()})},xr=(n,e)=>{let{key:t,value:r}=e;r===null?n.delete(t):n.set(t,r)},Eu=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===L&&Jt(e[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},Tu=(n,e,t,r)=>{let i=n.doc,s=i.clientID,o=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Jt(a,c)){o.set(l,a);let{left:h,right:d}=t;t.right=new O(M(s,P(i.store,s)),h,h&&h.lastId,d,d&&d.id,e,null,new L(l,c)),t.right.integrate(n,0),t.forward()}}return o},cc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let s=n.doc,o=s.clientID;Eu(t,i);let l=Tu(n,e,t,i),c=r.constructor===String?new Re(r):r instanceof W?new Ae(r):new Et(r),{left:a,right:h,index:d}=t;e._searchMarker&&wi(e._searchMarker,t.index,c.getLength()),h=new O(M(o,P(s.store,o)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=d,t.forward(),Au(n,e,t,l)},Jf=(n,e,t,r,i)=>{let s=n.doc,o=s.clientID;Eu(t,i);let l=Tu(n,e,t,i);e:for(;t.right!==null&&(r>0||l.size>0&&(t.right.deleted||t.right.content.constructor===L));){if(!t.right.deleted)switch(t.right.content.constructor){case L:{let{key:c,value:a}=t.right.content,h=i[c];if(h!==void 0){if(Jt(h,a))l.delete(c);else{if(r===0)break e;l.set(c,a)}t.right.delete(n)}else t.currentAttributes.set(c,a);break}default:r0){let c="";for(;r>0;r--)c+=` +`;t.right=new O(M(o,P(s.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new Re(c)),t.right.integrate(n,0),t.forward()}Au(n,e,t,l)},Du=(n,e,t,r,i)=>{let s=e,o=_();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===L){let a=s.content;o.set(a.key,a)}s=s.right}let l=0,c=!1;for(;e!==s;){if(t===e&&(c=!0),!e.deleted){let a=e.content;switch(a.constructor){case L:{let{key:h,value:d}=a,f=r.get(h)??null;(o.get(h)!==a||f===d)&&(e.delete(n),l++,!c&&(i.get(h)??null)===d&&f!==d&&(f===null?i.delete(h):i.set(h,f))),!c&&!e.deleted&&xr(i,a);break}}}e=e.right}return l},x1=(n,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;let t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===L){let r=e.content.key;t.has(r)?e.delete(n):t.add(r)}e=e.left}},Ou=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,s=_(),o=As(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case L:xr(o,i.content);break;default:e+=Du(t,r,i,s,o),s=As(o),r=i;break}i=i.right}}),e},S1=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let s=n.beforeState.get(r)||0;i!==s&&tu(n,t.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===L&&o.constructor!==ue&&e.add(o.parent)})}R(t,r=>{rt(n,n.deleteSet,i=>{if(i instanceof ue||!i.parent._hasFormatting||e.has(i.parent))return;let s=i.parent;i.content.constructor===L?e.add(s):x1(r,i)});for(let i of e)Ou(i)})},$f=(n,e,t)=>{let r=t,i=As(e.currentAttributes),s=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Ae:case Et:case Re:t{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];R(e,r=>{let i=new Map,s=new Map,o=this.target._start,l=null,c={},a="",h=0,d=0,f=()=>{if(l!==null){let u=null;switch(l){case"delete":d>0&&(u={delete:d}),d=0;break;case"insert":(typeof a=="object"||a.length>0)&&(u={insert:a},i.size>0&&(u.attributes={},i.forEach((p,m)=>{p!==null&&(u.attributes[m]=p)}))),a="";break;case"retain":h>0&&(u={retain:h},df(c)||(u.attributes=cf({},c))),h=0;break}u&&t.push(u),l=null}};for(;o!==null;){switch(o.content.constructor){case Ae:case Et:this.adds(o)?this.deletes(o)||(f(),l="insert",a=o.content.getContent()[0],f()):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=1):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case Re:this.adds(o)?this.deletes(o)||(l!=="insert"&&(f(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=o.length):o.deleted||(l!=="retain"&&(f(),l="retain"),h+=o.length);break;case L:{let{key:u,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let m=i.get(u)??null;Jt(m,p)?p!==null&&o.delete(r):(l==="retain"&&f(),Jt(p,s.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(o)){s.set(u,p);let m=i.get(u)??null;Jt(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!o.deleted){s.set(u,p);let m=c[u];m!==void 0&&(Jt(m,p)?m!==null&&o.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}o.deleted||(l==="insert"&&f(),xr(i,o.content));break}}o=o.right}for(f();t.length>0;){let u=t[t.length-1];if(u.retain!==void 0&&u.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},ct=class n extends W{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??se(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);let r=new eo(this,e,t);oo(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??se();let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Re&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?R(this.doc,r=>{let i=new xi(null,this._start,0,new Map);for(let s=0;s0)&&cc(r,this,i,l,o.attributes||{})}else o.retain!==void 0?Jf(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&$f(r,i,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??se();let i=[],s=new Map,o=this.doc,l="",c=this._start;function a(){if(l.length>0){let d={},f=!1;s.forEach((p,m)=>{f=!0,d[m]=p});let u={insert:l};f&&(u.attributes=d),i.push(u),l=""}}let h=()=>{for(;c!==null;){if(qt(c,e)||t!==void 0&&qt(c,t))switch(c.content.constructor){case Re:{let d=s.get("ychange");e!==void 0&&!qt(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),s.set("ychange",r?r("removed",c.id):{type:"removed"})):t!==void 0&&!qt(c,t)?(d===void 0||d.user!==c.id.client||d.type!=="added")&&(a(),s.set("ychange",r?r("added",c.id):{type:"added"})):d!==void 0&&(a(),s.delete("ychange")),l+=c.content.str;break}case Ae:case Et:{a();let d={insert:c.content.getContent()[0]};if(s.size>0){let f={};d.attributes=f,s.forEach((u,p)=>{f[p]=u})}i.push(d);break}case L:qt(c,e)&&(a(),xr(s,c.content));break}c=c.right}a()};return e||t?R(o,d=>{e&&fc(d,e),t&&fc(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,s=>{let o=Hs(s,this,e,!r);r||(r={},o.currentAttributes.forEach((l,c)=>{r[c]=l})),cc(s,this,o,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,s=>{let o=Hs(s,this,e,!r);cc(s,this,o,t,r||{})}):this._pending.push(()=>this.insertEmbed(e,t,r||{}))}delete(e,t){if(t===0)return;let r=this.doc;r!==null?R(r,i=>{$f(i,Hs(i,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,r){if(t===0)return;let i=this.doc;i!==null?R(i,s=>{let o=Hs(s,this,e,!1);o.right!==null&&Jf(s,this,o,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xs(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{Ic(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Rc(this,e)}getAttributes(){return ku(this)}_write(e){e.writeTypeRef(z1)}},k1=n=>new ct,ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??se()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===Z||t.constructor===at)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},at=class n extends W{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof W?t.clone():t)),e}get length(){return this.doc??se(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new ui(this,e)}querySelector(e){e=e.toUpperCase();let r=new ui(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),$e(new ui(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){oo(this,e,new to(this,t,e))}toString(){return yu(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},r){let i=e.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),bi(this,s=>{i.insertBefore(s.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{xu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)R(this.doc,r=>{let i=e&&e instanceof W?e._item:e;Gs(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(s=>s===e)+1;if(i===0&&e!==null)throw Ze("Reference item not found");r.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Su(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return gu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return wu(this,e)}slice(e=0,t=this.length){return mu(this,e,t)}forEach(e){bi(this,e)}_write(e){e.writeTypeRef(q1)}},C1=n=>new at,Z=class n extends at{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r)}),this._prelimAttrs=null}_copy(){return new n(this.nodeName)}clone(){let e=new n(this.nodeName),t=this.getAttributes();return af(t,(r,i)=>{typeof r=="string"&&e.setAttribute(i,r)}),e.insert(0,this.toArray().map(r=>r instanceof W?r.clone():r)),e}toString(){let e=this.getAttributes(),t=[],r=[];for(let l in e)r.push(l);r.sort();let i=r.length;for(let l=0;l0?" "+t.join(" "):"";return`<${s}${o}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xs(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{Ic(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Rc(this,e)}hasAttribute(e){return Cu(this,e)}getAttributes(e){return e?Mu(this,e):ku(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),s=this.getAttributes();for(let o in s){let l=s[o];typeof l=="string"&&i.setAttribute(o,l)}return bi(this,o=>{i.appendChild(o.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(F1),e.writeKey(this.nodeName)}},M1=n=>new Z(n.readKey()),to=class extends Dn{constructor(e,t,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}},Si=class n extends Nn{constructor(e){super(),this.hookName=e}_copy(){return new n(this.hookName)}clone(){let e=new n(this.hookName);return this.forEach((t,r)=>{e.set(r,t)}),e}toDOM(e=document,t={},r){let i=t[this.hookName],s;return i!==void 0?s=i.createDom(this):s=document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(s,this),s}_write(e){e.writeTypeRef(H1),e.writeKey(this.hookName)}},A1=n=>new Si(n.readKey()),xe=class n extends ct{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,r){let i=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(i,this),i}toString(){return this.toDelta().map(e=>{let t=[];for(let i in e.attributes){let s=[];for(let o in e.attributes[i])s.push({key:o,value:e.attributes[i][o]});s.sort((o,l)=>o.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(J1)}},E1=n=>new xe,yr=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Oe()}mergeWith(e){return!1}write(e,t,r){throw Oe()}integrate(e,t){throw Oe()}},T1=0,ue=class extends yr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),eu(e.doc.store,this)}write(e,t){e.writeInfo(T1),e.writeLen(this.length-t)}getMissing(e,t){return null}},In=class n{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new n(this.content)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},D1=n=>new In(n.readBuf()),wr=class n{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.len)}splice(e){let t=new n(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){mi(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},O1=n=>new wr(n.readLen()),Nu=(n,e)=>new We({guid:n,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),Rn=class n{constructor(e){e._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=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new n(Nu(this.doc.guid,this.opts))}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},N1=n=>new Rn(Nu(n.readString(),n.readAny())),Et=class n{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new n(this.embed)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},I1=n=>new Et(n.readJSON()),L=class n{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.key,this.value)}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){let r=t.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},R1=n=>new L(n.readKey(),n.readJSON()),ki=class n{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new n(this.arr)}splice(e){let t=new n(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let r=this.arr.length;e.writeLen(r-t);for(let i=t;i{let e=n.readLen(),t=[];for(let r=0;r{let e=n.readLen(),t=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"\uFFFD",t.str="\uFFFD"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},V1=n=>new Re(n.readString()),B1=[w1,b1,k1,M1,C1,A1,E1],P1=0,L1=1,z1=2,F1=3,q1=4,H1=5,J1=6,Ae=class n{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new n(this.type._copy())}splice(e){throw Oe()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},$1=n=>new Ae(B1[n.readTypeRef()](n)),gc=(n,e)=>{let t=e,r=0,i;do r>0&&(t=M(t.client,t.clock+r)),i=Cn(n,t),r=t.clock-i.id.clock,t=i.redone;while(t!==null&&i instanceof O);return{item:i,diff:r}},vc=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},no=(n,e,t)=>{let{client:r,clock:i}=e.id,s=new O(M(r,i+t),e,M(r,i+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=M(e.redone.client,e.redone.clock+t)),e.right=s,s.right!==null&&(s.right.left=s),n._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=t,s},Wf=(n,e)=>Pd(n,t=>Tt(t.deletions,e)),Iu=(n,e,t,r,i,s)=>{let o=n.doc,l=o.store,c=o.clientID,a=e.redone;if(a!==null)return we(n,a);let h=e.parent._item,d=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!t.has(h)||Iu(n,h,t,r,i,s)===null))return null;for(;h.redone!==null;)h=we(n,h.redone)}let u=h===null?e.parent:h.content.type;if(e.parentSub===null){for(d=e.left,f=e;d!==null;){let y=d;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:we(n,y.redone);if(y!==null&&y.parent._item===h){d=y;break}d=d.left}for(;f!==null;){let y=f;for(;y!==null&&y.parent._item!==h;)y=y.redone===null?null:we(n,y.redone);if(y!==null&&y.parent._item===h){f=y;break}f=f.right}}else if(f=null,e.right&&!i){for(d=e;d!==null&&d.right!==null&&(d.right.redone||Tt(r,d.right.id)||Wf(s.undoStack,d.right.id)||Wf(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=we(n,d.redone);if(d&&d.right!==null)return null}else d=u._map.get(e.parentSub)||null;let p=P(l,c),m=M(c,p),g=new O(m,d,d&&d.lastId,f,f&&f.id,u,e.parentSub,e.content.copy());return e.redone=m,vc(g,!0),g.integrate(n,0),g},O=class n extends yr{constructor(e,t,r,i,s,o,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=s,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=P(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=P(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Mt&&this.id.client!==this.parent.client&&this.parent.clock>=P(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Bf(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=we(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ue||this.right&&this.right.constructor===ue)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===n&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===n&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Mt){let r=Cn(t,this.parent);r.constructor===ue?this.parent=null:this.parent=r.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Bf(e,e.doc.store,M(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;let s=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),s.add(i),kn(this.origin,i.origin)){if(i.id.client{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),mi(e.deleteSet,this.id.client,this.id.clock,this.length),Lf(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?Zw(e,this,new ue(this.id,this.length)):this.content=new wr(this.length)}write(e,t){let r=t>0?M(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(s===null?0:32);if(e.writeInfo(o),r!==null&&e.writeLeftID(r),i!==null&&e.writeRightID(i),r===null&&i===null){let l=this.parent;if(l._item!==void 0){let c=l._item;if(c===null){let a=_n(l);e.writeParentInfo(!0),e.writeString(a)}else e.writeParentInfo(!1),e.writeLeftID(c.id)}else l.constructor===String?(e.writeParentInfo(!0),e.writeString(l)):l.constructor===Mt?(e.writeParentInfo(!1),e.writeLeftID(l)):j();s!==null&&e.writeString(s)}this.content.write(e,t)}},Ru=(n,e)=>W1[e&31](n),W1=[()=>{j()},O1,v1,D1,V1,I1,R1,$1,U1,N1,()=>{j()}],j1=10,ie=class extends yr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){j()}write(e,t){e.writeInfo(j1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},vu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},_u="__ $YJS$ __";vu[_u]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");vu[_u]=!0;var Uu=new Map,_c=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:wf(t.newValue||"")}),rf(this._onChange)}postMessage(e){Us.setItem(this.room,yf(gf(e)))}close(){sf(this._onChange)}},K1=typeof BroadcastChannel>"u"?_c:BroadcastChannel,Uc=n=>$(Uu,n,()=>{let e=Ce(),t=new K1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Vu=(n,e)=>(Uc(n).subs.add(e),e),Bu=(n,e)=>{let t=Uc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Uu.delete(n)),r},Vn=(n,e,t=null)=>{let r=Uc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var Pu=0,co=1,Lu=2,ao=(n,e)=>{x(n,Pu);let t=Ec(e);U(n,t)},Vc=(n,e,t)=>{x(n,co),U(n,Cc(e,t))},G1=(n,e,t)=>Vc(e,t,K(n)),zu=(n,e,t)=>{try{kc(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},Fu=(n,e)=>{x(n,Lu),U(n,e)},X1=zu,qu=(n,e,t,r)=>{let i=k(n);switch(i){case Pu:G1(n,e,t);break;case co:zu(n,t,r);break;case Lu:X1(n,t,r);break;default:throw new Error("Unknown message type")}return i};var Z1=0;var Hu=(n,e,t)=>{switch(k(n)){case Z1:t(e,Le(n))}};var Bc=3e4,ho=class extends tr{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let t=Ne();this.getLocalState()!==null&&Bc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,s)=>{s!==this.clientID&&Bc<=t-i.lastUpdated&&this.states.has(s)&&r.push(s)}),r.length>0&&fo(this,r,"timeout")},fe(Bc/10)),e.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(e){let t=this.clientID,r=this.meta.get(t),i=r===void 0?0:r.clock+1,s=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Ne()});let o=[],l=[],c=[],a=[];e===null?a.push(t):s==null?e!=null&&o.push(t):(l.push(t),ur(s,e)||c.push(t)),(o.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:o,updated:c,removed:a},"local"]),this.emit("update",[{added:o,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},fo=(n,e,t)=>{let r=[];for(let i=0;i0&&(n.emit("change",[{added:[],updated:[],removed:r},t]),n.emit("update",[{added:[],updated:[],removed:r},t]))},kr=(n,e,t=n.states)=>{let r=e.length,i=F();x(i,r);for(let s=0;s{let r=q(e),i=Ne(),s=[],o=[],l=[],c=[],a=k(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:s,updated:l,removed:c},t]),(s.length>0||o.length>0||c.length>0)&&n.emit("update",[{added:s,updated:o,removed:c},t])};var $u=n=>hf(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,ju=3,Cr=1,rb=2,Ti=[];Ti[Bn]=(n,e,t,r,i)=>{x(n,Bn);let s=qu(e,n,t.doc,t);r&&s===co&&!t.synced&&(t.synced=!0)};Ti[ju]=(n,e,t,r,i)=>{x(n,Cr),U(n,kr(t.awareness,Array.from(t.awareness.getStates().keys())))};Ti[Cr]=(n,e,t,r,i)=>{Ju(t.awareness,K(e),t)};Ti[rb]=(n,e,t,r,i)=>{Hu(e,t.doc,(s,o)=>ib(t,o))};var Wu=3e4,ib=(n,e)=>console.warn(`Permission denied to access ${n.url}. +${e}`),Ku=(n,e,t)=>{let r=q(e),i=F(),s=k(r),o=n.messageHandlers[s];return o?o(i,r,n,t,s):console.error("Unable to compute message"),i},Yu=n=>{if(n.shouldConnect&&n.ws===null){let e=new n._WS(n.url,n.protocols);e.binaryType="arraybuffer",n.ws=e,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,e.onmessage=t=>{n.wsLastMessageReceived=Ne();let r=Ku(n,new Uint8Array(t.data),!0);Ns(r)>1&&e.send(I(r))},e.onerror=t=>{n.emit("connection-error",[t,n])},e.onclose=t=>{n.emit("connection-close",[t,n]),n.ws=null,n.wsconnecting=!1,n.wsconnected?(n.wsconnected=!1,n.synced=!1,fo(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Yu,De(zd(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},e.onopen=()=>{n.wsLastMessageReceived=Ne(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);let t=F();if(x(t,Bn),ao(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=F();x(r,Cr),U(r,kr(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},Pc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},Lc=class extends tr{constructor(e,t,r,{connect:i=!0,awareness:s=new ho(r),params:o={},protocols:l=[],WebSocketPolyfill:c=WebSocket,resyncInterval:a=-1,maxBackoffTime:h=2500,disableBc:d=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+"/"+t,this.maxBackoffTime=h,this.params=o,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=s,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=d,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Ti.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let f=F();x(f,Bn),ao(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=Ku(this,new Uint8Array(f),!1);Ns(p)>1&&Vn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=F();x(p,Bn),Fu(p,f),Pc(this,I(p))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:f,updated:u,removed:p},m)=>{let g=f.concat(u).concat(p),y=F();x(y,Cr),U(y,kr(s,g)),Pc(this,I(y))},this._exitHandler=()=>{fo(this.awareness,[r.clientID],"app closed")},kt&&typeof process<"u"&&process.on("exit",this._exitHandler),s.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Wu{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var sb=/[\uD800-\uDBFF]/,ob=/[\uDC00-\uDFFF]/,lb=(n,e)=>{let t=0,r=0;for(;t0&&sb.test(n[t-1])&&t--;r+t0&&ob.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Xu=lb;var v=new le("y-sync"),Dt=new le("y-undo"),Di=new le("yjs-cursor");var Ni=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!Tt(e.ds,n.id),cb=[{light:"#ecd44433",dark:"#ecd444"}],ab=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,Zd(e))}return n.get(t)},ep=(n,{colors:e=cb,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new uo(n,s),c=new H({props:{editable:a=>{let h=v.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:v,state:{init:(a,h)=>({type:n,doc:n.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:t,permanentUserData:r}),apply:(a,h)=>{let d=a.getMeta(v);if(d!==void 0){h=Object.assign({},h);for(let f in d)h[f]=d[f]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=d!==void 0&&!!d.isChangeOrigin,h.isUndoRedoOperation=d!==void 0&&!!d.isChangeOrigin&&!!d.isUndoRedoOperation,l.prosemirrorView!==null&&d!==void 0&&(d.snapshot!=null||d.prevSnapshot!=null)&&ai(0,()=>{l.prosemirrorView!=null&&(d.restore==null?l._renderSnapshot(d.snapshot,d.prevSnapshot,h):(l._renderSnapshot(d.snapshot,d.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),s==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,h.addToHistory===!1&&!h.isChangeOrigin){let d=Dt.getState(a.state),f=d&&d.undoManager;f&&f.stopCapturing()}l.mux(()=>{h.doc.transact(d=>{d.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},v)})}},destroy:()=>{l.destroy()}})});return c},hb=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null){let r=Yt(t.doc,t.type,e.anchor,t.mapping),i=Yt(t.doc,t.type,e.head,t.mapping);r!==null&&i!==null&&(n=n.setSelection(A.create(n.doc,r,i)))}},Ii=(n,e)=>({anchor:Pn(e.selection.anchor,n.type,n.mapping),head:Pn(e.selection.head,n.type,n.mapping)}),uo=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Gu(),this.mapping=t,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=Ii(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(pr&&this._domSelectionInView===null&&(ai(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.prosemirrorView._root.getSelection(),t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.getClientRects().length===0&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);let i=t.getBoundingClientRect(),s=Ct.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||s.clientWidth||0)&&i.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,t){t||(t=Mi(br(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(v,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(r=>Oi(r,this.prosemirrorView.state.schema,this.mapping)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(e),0,0));t.setMeta(v,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{let e=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(i=>Oi(i,this.prosemirrorView.state.schema,this.mapping)).filter(i=>i!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(t),0,0));e&&r.setSelection(A.create(r.doc,e.anchor,e.head)),this.prosemirrorView.dispatch(r.setMeta(v,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,r){let i=this.doc;e||(e=Ai(this.doc)),(e instanceof Uint8Array||t instanceof Uint8Array)&&((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&j(),i=new We({gc:!1}),vn(i,t),t=Ai(i),vn(i,e),e=Ai(i)),this.mapping.clear(),this.mux(()=>{i.transact(s=>{let o=r.permanentUserData;o&&o.dss.forEach(h=>{rt(s,h,d=>{})});let l=(h,d)=>{let f=h==="added"?o.getUserByClientId(d.client):o.getUserByDeletedId(d);return{user:f,type:h,color:ab(r.colorMapping,r.colors,f)}},c=lo(this.type,new jt(t.ds,e.sv)).map(h=>!h._item.deleted||Ni(h._item,e)||Ni(h._item,t)?Oi(h,this.prosemirrorView.state.schema,new Map,e,t,l):null).filter(h=>h!==null),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(c),0,0));this.prosemirrorView.dispatch(a.setMeta(v,{isChangeOrigin:!0}))},v)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let r=v.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{let i=(l,c)=>this.mapping.delete(c);rt(t,t.deleteSet,l=>{if(l.constructor===O){let c=l.content.type;c&&this.mapping.delete(c)}}),t.changed.forEach(i),t.changedParentTypes.forEach(i);let s=this.type.toArray().map(l=>tp(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(s),0,0));hb(o,this.beforeTransactionSelection,this),o=o.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Tn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{Mr(this.doc,this.type,e,this.mapping),this.beforeTransactionSelection=Ii(this,this.prosemirrorView.state)},v)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}},tp=(n,e,t,r,i,s)=>{let o=t.get(n);if(o===void 0){if(n instanceof Z)return Oi(n,e,t,r,i,s);throw Oe()}return o},Oi=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c.constructor===Z){let a=tp(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=c._item.right?.content.type;a instanceof ct&&!a._item.deleted&&a._item.id.client===a.doc.clientID&&(c.applyDelta([{retain:c.length},...a.toDelta()]),a.doc.transact(d=>{a._item.delete(d)}));let h=db(c,e,t,r,i,s);h!==null&&h.forEach(d=>{d!==null&&o.push(d)})}};r===void 0||i===void 0?n.toArray().forEach(l):lo(n,new jt(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(Ni(n._item,r)?Ni(n._item,i)||(c.ychange=s?s("added",n._item.id):{type:"added"}):c.ychange=s?s("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,o);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},db=(n,e,t,r,i,s)=>{let o=[],l=n.toDelta(r,i,s);try{for(let c=0;c{n._item.delete(a)},v),null}return o},fb=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:rp(i.marks)}));return t.applyDelta(r),e.set(t,n),t},ub=(n,e)=>{let t=new Z(n.type.name);for(let r in n.attrs){let i=n.attrs[r];i!==null&&r!=="ychange"&&t.setAttribute(r,i)}return t.insert(0,mo(n).map(r=>zc(r,e))),e.set(t,n),t},zc=(n,e)=>n instanceof Array?fb(n,e):ub(n,e),Qu=n=>typeof n=="object"&&n!==null,qc=(n,e)=>{let t=Object.keys(n).filter(i=>n[i]!==null),r=t.length===Object.keys(e).filter(i=>e[i]!==null).length;for(let i=0;i{let e=n.content.content,t=[];for(let r=0;r{let t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&Vs(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(s=>qc(r.attributes[s.type.name]||{},s.attrs)))},Ri=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Fc(n,e)){let t=mo(e);return n._length===t.length&&qc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Ri(r,t[i]))}return n instanceof xe&&e instanceof Array&&np(n,e)},po=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),Zu=(n,e,t)=>{let r=n.toArray(),i=mo(e),s=i.length,o=r.length,l=De(o,s),c=0,a=0,h=!1;for(;c{let e="",t=n._start,r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof Re?e+=t.content.str:t.content instanceof L&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},mb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=pb(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,rp(a.marks))})),{insert:o,remove:l,index:c}=Xu(i,s.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,o),n.applyDelta(s.map(a=>({retain:a.insert.length,attributes:a.attributes})))},rp=n=>{let e={};return n.forEach(t=>{t.type.name!=="ychange"&&(e[t.type.name]=t.attrs)}),e},Mr=(n,e,t,r)=>{if(e instanceof Z&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.set(e,t),e instanceof Z){let d=e.getAttributes(),f=t.attrs;for(let u in f)f[u]!==null?d[u]!==f[u]&&u!=="ychange"&&e.setAttribute(u,f[u]):e.removeAttribute(u);for(let u in d)f[u]===void 0&&e.removeAttribute(u)}let i=mo(t),s=i.length,o=e.toArray(),l=o.length,c=De(s,l),a=0,h=0;for(;a{for(;l-a-h>0&&s-a-h>0;){let f=o[a],u=i[a],p=o[l-h-1],m=i[s-h-1];if(f instanceof xe&&u instanceof Array)np(f,u)||mb(f,u,r),a+=1;else{let g=f instanceof Z&&Fc(f,u),y=p instanceof Z&&Fc(p,m);if(g&&y){let E=Zu(f,u,r),N=Zu(p,m,r);E.foundMappedChild&&!N.foundMappedChild?y=!1:!E.foundMappedChild&&N.foundMappedChild||E.equalityFactor0&&(e.slice(a,a+d).forEach(f=>r.delete(f)),e.delete(a,d)),a+h!(e instanceof Array)&&n.nodeName===e.type.name;var vi=null,gb=()=>{let n=vi;vi=null,n.forEach((e,t)=>{let r=t.state.tr,i=v.getState(t.state);i&&i.binding&&!i.binding.isDestroyed&&(e.forEach((s,o)=>{r.setMeta(o,s)}),t.dispatch(r))})},Hc=(n,e,t)=>{vi||(vi=new Map,ai(0,gb)),$(vi,n,_).set(e,t)},Pn=(n,e,t)=>{if(n===0)return Ci(e,0,-1);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof xe){if(r._length>=n)return Ci(r,n,-1);if(n-=r._length,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{do r=r._item===null?null:r._item.parent,n--;while(r!==e&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==e&&(r=r._item===null?null:r._item.next.content.type)}}else{let i=(t.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&n1)return new ot(r._item===null?null:r._item.id,r._item===null?_n(r):null,null);if(n-=i,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(n===0)return r=r._item===null?r:r._item.parent,new ot(r._item===null?null:r._item.id,r._item===null?_n(r):null,null);do r=r._item.parent,n--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw j();if(n===0&&r.constructor!==xe&&r!==e)return yb(r._item.parent,r._item)}return Ci(e,e._length,-1)},yb=(n,e)=>{let t=null,r=null;return n._item===null?r=_n(n):t=M(n._item.id.client,n._item.id.clock),new ot(t,r,e.id)},Yt=(n,e,t,r)=>{let i=Tc(t,n);if(i===null||i.type!==e&&!En(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===xe)o=i.index;else if(s._item===null||!s._item.deleted){let l=s._first,c=0;for(;ci(void 0)};return Mr(r,t,n,new Map),t}function sp(n,e="prosemirror"){return $c(n.getXmlFragment(e))}function $c(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(o=>{let l={type:"text",text:o.insert};return o.attributes&&(l.marks=Object.keys(o.attributes).map(c=>{let a=o.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let s=r.getAttributes();Object.keys(s).length&&(i.attrs=s);let o=r.toArray();o.length&&(i.content=o.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var wb=(n,e,t)=>n!==e,bb=n=>{let e=document.createElement("span");e.classList.add("ProseMirror-yjs-cursor"),e.setAttribute("style",`border-color: ${n.color}`);let t=document.createElement("div");t.setAttribute("style",`background-color: ${n.color}`),t.insertBefore(document.createTextNode(n.name),null);let r=document.createTextNode("\u2060"),i=document.createTextNode("\u2060");return e.insertBefore(r,null),e.insertBefore(t,null),e.insertBefore(i,null),e},xb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Sb=/^#[0-9a-fA-F]{6}$/,op=(n,e,t,r,i)=>{let s=v.getState(n),o=s.doc,l=[];return s.snapshot!=null||s.prevSnapshot!=null||s.binding.mapping.size===0?z.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(o.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Sb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Yt(o,s.type,Un(c.cursor.anchor),s.binding.mapping),f=Yt(o,s.type,Un(c.cursor.head),s.binding.mapping);if(d!==null&&f!==null){let u=Be(n.doc.content.size-1,0);d=De(d,u),f=De(f,u),l.push(ne.widget(f,()=>r(h),{key:a+"",side:10}));let p=De(d,f),m=Be(d,f);l.push(ne.inline(p,m,i(h),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),z.create(n.doc,l))},kb=(n,{awarenessStateFilter:e=wb,cursorBuilder:t=bb,selectionBuilder:r=xb,getSelection:i=o=>o.selection}={},s="cursor")=>new H({key:Di,state:{init(o,l){return op(l,n,e,t,r)},apply(o,l,c,a){let h=v.getState(a),d=o.getMeta(Di);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?op(a,n,e,t,r):l.map(o.mapping,o.doc)}},props:{decorations:o=>Di.getState(o)},view:o=>{let l=()=>{o.docView&&Hc(o,Di,{awarenessUpdated:!0})},c=()=>{let a=v.getState(o.state),h=n.getLocalState()||{};if(o.hasFocus()){let d=i(o.state),f=Pn(d.anchor,a.type,a.binding.mapping),u=Pn(d.head,a.type,a.binding.mapping);(h.cursor==null||!ro(Un(h.cursor.anchor),f)||!ro(Un(h.cursor.head),u))&&n.setLocalStateField(s,{anchor:f,head:u})}else h.cursor!=null&&Yt(a.doc,a.type,Un(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(s,null)};return n.on("change",l),o.dom.addEventListener("focusin",c),o.dom.addEventListener("focusout",c),{update:c,destroy:()=>{o.dom.removeEventListener("focusin",c),o.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(s,null)}}}});var Cb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.undo(),!0},Mb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.redo(),!0},Ab=new Set(["paragraph"]),Eb=(n,e)=>!(n instanceof O)||!(n.content instanceof Ae)||!(n.content.type instanceof ct||n.content.type instanceof Z&&e.has(n.content.type.nodeName))||n.content.type._length===0,Tb=({protectedNodes:n=Ab,trackedOrigins:e=[],undoManager:t=null}={})=>new H({key:Dt,state:{init:(r,i)=>{let s=v.getState(i),o=t||new Tn(s.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Eb(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(r,i,s,o)=>{let l=v.getState(o).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ii(l,s),hasUndoOps:a,hasRedoOps:h}:a!==i.hasUndoOps||h!==i.hasRedoOps?Object.assign({},i,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):i}},view:r=>{let i=v.getState(r.state),s=Dt.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,Dt.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:o})=>{let l=i.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}});var _i="http://www.w3.org/2000/svg",Db="http://www.w3.org/1999/xlink",jc="ProseMirror-icon",Wc="pm-close-dropdowns";function Ob(n){let e=0;for(let t=0;t{s.preventDefault(),r.classList.contains(je+"-disabled")||t.run(e.state,e.dispatch,e,s)});function i(s){if(t.select){let l=t.select(s);if(r.style.display=l?"":"none",!l)return!1}let o=!0;if(t.enable&&(o=t.enable(s)||!1,lp(r,je+"-disabled",!o)),t.active){let l=o&&t.active(s)||!1;lp(r,je+"-active",l)}return!0}return{dom:r,update:i}}};function go(n,e){return n._props.translate?n._props.translate(e):e}var Ui={time:0,node:null};function Rb(n){Ui.time=Date.now(),Ui.node=n.target}function vb(n){return Date.now()-100{o&&o.close()&&(o=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(Wc,c))};i.addEventListener("mousedown",d=>{d.preventDefault(),Rb(d),o?a():(r.dispatchEvent(new CustomEvent(Wc)),o=this.expand(s,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{vb(s)||a()}),r.addEventListener(Wc,c=()=>{a()}))});function h(d){let f=t.update(d);return s.style.display=f?"":"none",f}return{dom:s,update:h}}expand(e,t){let r=document.createElement("div");r.className=`${je}-dropdown-menu-col-1`;let i=document.createElement("div");i.className=`${je}-dropdown-menu-col-2`,t.forEach(c=>{c.querySelector('[column="2"]')?i.append(c):r.append(c)});let s=wt("div",{class:je+"-dropdown-menu "+(this.options.class||"")},r,i),o=!1;function l(){return o?!1:(o=!0,e.removeChild(s),!0)}return e.appendChild(s),{close:l,node:s}}};function _b(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iWr(n),icon:Vi.join}),Vk=new ht({title:"Lift out of enclosing block",run:jr,select:n=>jr(n),icon:Vi.lift}),Bk=new ht({title:"Select parent node",run:Kr,select:n=>Kr(n),icon:Vi.selectParentNode}),Pk=new ht({title:"Undo last change",run:Xr,enable:n=>Xr(n),icon:Vi.undo}),Lk=new ht({title:"Redo last undone change",run:Qn,enable:n=>Qn(n),icon:Vi.redo});function Bb(n,e){let t={run(r,i){return Xn(n,e.attrs)(r,i)},select(r){return Xn(n,e.attrs)(r)}};for(let r in e)t[r]=e[r];return new ht(t)}function Pb(n,e){let t=pn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:s,to:o,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):o<=s.end()&&s.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new ht(r)}function lp(n,e,t){t?n.classList.add(e):n.classList.remove(e)}export{zn as DOMParser,It as DOMSerializer,Kc as Dropdown,Bo as EditorState,ol as EditorView,w as Fragment,bt as InputRule,ht as MenuItem,H as Plugin,le as PluginKey,Dr as Schema,b as Slice,V as TableMap,A as TextSelection,Lc as WebsocketProvider,Sr as Y,e0 as addColumnAfter,Zy as addColumnBefore,ay as addListNodes,s0 as addRowAfter,i0 as addRowBefore,ld as baseKeymap,Pg as baseSchema,Pb as blockTypeItem,Vy as buildKeymap,A0 as columnResizing,n0 as deleteColumn,l0 as deleteRow,m0 as deleteTable,Nd as fixTables,Ty as gapCursor,p0 as goToNextCell,ud as inputRules,He as isInTable,wy as keymap,bl as liftListItem,a0 as mergeCells,ip as prosemirrorToYDoc,Jc as prosemirrorToYXmlFragment,Ub as renderGrouped,Je as selectedRect,pn as setBlockType,xl as sinkListItem,h0 as splitCell,wl as splitListItem,V0 as tableEditing,Fy as tableNodes,mn as toggleMark,Xn as wrapIn,us as wrapInList,Bb as wrapItem,kb as yCursorPlugin,sp as yDocToProsemirrorJSON,Mb as yRedo,ep as ySyncPlugin,Cb as yUndo,Tb as yUndoPlugin,Dt as yUndoPluginKey,$c as yXmlFragmentToProsemirrorJSON}; diff --git a/deps/da-y-wrapper/src/index.js b/deps/da-y-wrapper/src/index.js index e50cf962..6bbb4292 100644 --- a/deps/da-y-wrapper/src/index.js +++ b/deps/da-y-wrapper/src/index.js @@ -26,6 +26,7 @@ import { splitCell, deleteTable, isInTable, + TableMap, } from 'prosemirror-tables'; // yjs @@ -81,6 +82,7 @@ export { mergeCells, splitCell, deleteTable, + TableMap, gapCursor, MenuItem, Dropdown, diff --git a/test/unit/blocks/edit/prose/table-modifications.test.js b/test/unit/blocks/edit/prose/table-modifications.test.js new file mode 100644 index 00000000..cb72fae4 --- /dev/null +++ b/test/unit/blocks/edit/prose/table-modifications.test.js @@ -0,0 +1,140 @@ +/* + * Copyright 2024 Adobe. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +import { expect } from '@esm-bundle/chai'; +import { + addColumnBefore, + addColumnAfter, + tableEditing, +} from 'da-y-wrapper'; +import { createTestEditor, destroyEditor } from './test-helpers.js'; +import insertTable from '../../../../../blocks/edit/prose/table.js'; +import tableHeaderFix from '../../../../../blocks/edit/prose/plugins/tableHeaderFix.js'; + +describe('Table Modifications', () => { + let editor; + + afterEach(() => { + if (editor) { + destroyEditor(editor); + editor = null; + } + }); + + describe('Column Operations - Header Row Colspan', () => { + it('should maintain header colspan when adding column before', async () => { + editor = await createTestEditor({ additionalPlugins: [tableEditing(), tableHeaderFix()] }); + const { view } = editor; + + // Insert a table (starts with 2 columns) + insertTable(view.state, view.dispatch); + + // Change the block name to a custom value by replacing the header cell content + const customBlockName = 'my-custom-block'; + const table = view.state.doc.firstChild; + const headerCell = table.child(0).child(0); + const cellStart = 3; // Position of the table cell content + const para = view.state.schema.nodes.paragraph.create( + null, + view.state.schema.text(customBlockName), + ); + const updateNameTr = view.state.tr.replaceWith( + cellStart + 1, + cellStart + 1 + headerCell.content.size, + para, + ); + view.dispatch(updateNameTr); + + // Move cursor to second row, first cell + const table2 = view.state.doc.firstChild; + const headerSize = table2.child(0).nodeSize; + const secondRowPos = view.state.doc.resolve(1 + headerSize + 1); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, secondRowPos.pos), + ); + view.dispatch(tr); + + // Add a column before + addColumnBefore(view.state, view.dispatch); + + // Check that header row still has 1 cell and colspan is now 3 + const updatedTable = view.state.doc.firstChild; + const updatedFirstRow = updatedTable.child(0); + + expect(updatedFirstRow.childCount).to.equal( + 1, + 'Header row should still have 1 cell after adding column', + ); + expect(updatedFirstRow.child(0).attrs.colspan).to.equal( + 3, + 'Header should span 3 columns after adding one', + ); + expect(updatedFirstRow.child(0).textContent).to.equal( + customBlockName, + 'Block name should be preserved', + ); + }); + + it('should maintain header colspan when adding column after', async () => { + editor = await createTestEditor({ additionalPlugins: [tableEditing(), tableHeaderFix()] }); + const { view } = editor; + + // Insert a table (starts with 2 columns) + insertTable(view.state, view.dispatch); + + // Change the block name to a custom value by replacing the header cell content + const customBlockName = 'hero-banner'; + const table = view.state.doc.firstChild; + const headerCell = table.child(0).child(0); + const cellStart = 3; // Position of the table cell content + const para = view.state.schema.nodes.paragraph.create( + null, + view.state.schema.text(customBlockName), + ); + const updateNameTr = view.state.tr.replaceWith( + cellStart + 1, + cellStart + 1 + headerCell.content.size, + para, + ); + view.dispatch(updateNameTr); + + // Move cursor to second row, last cell + const table2 = view.state.doc.firstChild; + const headerSize = table2.child(0).nodeSize; + const secondRowPos = view.state.doc.resolve(1 + headerSize + 2); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, secondRowPos.pos), + ); + view.dispatch(tr); + + // Add a column after + addColumnAfter(view.state, view.dispatch); + + // Check that header row still has 1 cell and colspan is now 3 + const updatedTable = view.state.doc.firstChild; + const updatedFirstRow = updatedTable.child(0); + + expect(updatedFirstRow.childCount).to.equal( + 1, + 'Header row should still have 1 cell after adding column', + ); + expect(updatedFirstRow.child(0).attrs.colspan).to.equal( + 3, + 'Header should span 3 columns after adding one', + ); + expect(updatedFirstRow.child(0).textContent).to.equal( + customBlockName, + 'Block name should be preserved', + ); + }); + }); +});