From 16a7c46836b09d54d62cc225461915af775b4ec4 Mon Sep 17 00:00:00 2001 From: Sean Steimer Date: Tue, 11 Nov 2025 13:54:13 -0800 Subject: [PATCH 1/7] feat: modify handing of adding and removing columns when in block header --- .../edit/prose/plugins/slashMenu/slashMenu.js | 2 +- deps/da-y-wrapper/dist/index.js | 24 +- deps/da-y-wrapper/src/index.js | 189 ++++++- .../edit/prose/table-modifications.test.js | 505 ++++++++++++++++++ 4 files changed, 701 insertions(+), 19 deletions(-) create mode 100644 test/unit/blocks/edit/prose/table-modifications.test.js diff --git a/blocks/edit/prose/plugins/slashMenu/slashMenu.js b/blocks/edit/prose/plugins/slashMenu/slashMenu.js index a84ebcec..b162aba6 100644 --- a/blocks/edit/prose/plugins/slashMenu/slashMenu.js +++ b/blocks/edit/prose/plugins/slashMenu/slashMenu.js @@ -39,8 +39,8 @@ const getTableName = ($cursor) => { const firstRow = table.child(0); const cellIndex = $cursor.index(tableCellDepth - 1); const row = $cursor.node(rowDepth); - const firstRowContent = firstRow.child(0).textContent; + // Updated regex to allow spaces in table names, which will be normalized later const tableNameMatch = firstRowContent.match(/^([a-zA-Z0-9_\s-]+)(?:\s*\([^)]*\))?$/); diff --git a/deps/da-y-wrapper/dist/index.js b/deps/da-y-wrapper/dist/index.js index 30ec4a16..95e3808f 100644 --- a/deps/da-y-wrapper/dist/index.js +++ b/deps/da-y-wrapper/dist/index.js @@ -1,13 +1,13 @@ -var hp=Object.defineProperty;var dp=(n,e)=>{for(var t in e)hp(n,t,{get:e[t],enumerable:!0})};function oe(n){this.content=n}oe.prototype={constructor:oe,find:function(n){for(var e=0;e>1}};oe.from=function(n){if(n instanceof oe)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new oe(e)};var yo=oe;function ia(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=ia(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function sa(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),c=o.nodeSize;if(o==l){t-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let a=0,h=Math.min(o.text.length,l.text.length);for(;ae&&r(c,i+l,s||null,o)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=a},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?Pi(r+1,o):Pi(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var Qt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=la(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(oa(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function oa(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(oa(s.content,e-i-1,t-i-1)))}function la(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=la(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function fp(n,e,t){if(t.openStart>n.depth)throw new Qt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Qt("Inconsistent open depths");return ca(n,e,t,0)}function ca(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Ar(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(Gt(n.nodeAfter,r),s++));for(let l=s;li&&xo(n,e,i+1),o=r.depth>i&&xo(t,r,i+1),l=[];return Ar(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(aa(s,o),Gt(Xt(s,ha(n,e,t,r,i+1)),l)):(s&&Gt(Xt(s,Fi(n,e,i+1)),l),Ar(e,t,i,l),o&&Gt(Xt(o,Fi(t,r,i+1)),l)),Ar(r,null,i,l),new w(l)}function Fi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=xo(n,e,t+1);Gt(Xt(i,Fi(n,e,t+1)),r)}return Ar(e,null,t,r),new w(r)}function up(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var qi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Zt(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:c}=o.content.findIndex(s),a=s-c;if(r.push(o,l,i+c),!a||(o=o.child(l),o.isText))break;s=a-1,i+=c+1}return new n(t,r,s)}static resolveCached(e,t){let r=Yc.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),da(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Ke.prototype.text=void 0;var ko=class n extends Ke{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):da(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function da(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var en=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Co(e,t);if(r.next==null)return n.empty;let i=fa(r);r.next&&r.err("Unexpected trailing text");let s=kp(Sp(i));return Cp(s,r),s}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(` -`)}};en.empty=new en(!0);var Co=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function fa(n){let e=[];do e.push(gp(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function gp(n){let e=[];do e.push(yp(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function yp(n){let e=xp(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=wp(n,e);else break;return e}function Gc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function wp(n,e){let t=Gc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Gc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function bp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function xp(n){if(n.eat("(")){let e=fa(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=bp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Sp(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,c){let a={term:c,to:l};return e[o].push(a),a}function i(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,a)=>c.concat(s(a,l)),[]);if(o.type=="seq")for(let c=0;;c++){let a=s(o.exprs[c],l);if(c==o.exprs.length-1)return a;i(a,l=t())}else if(o.type=="star"){let c=t();return r(l,c),i(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=t();return i(s(o.expr,l),c),i(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let a=0;a{n[o].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let s=e[r.join(",")]=new en(r.indexOf(n.length-1)>-1);for(let o=0;o-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ma(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ke(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Ke(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(w.empty,!0);return s?new Ke(this,e,t.append(s),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new n(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Mp(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}var Mo=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Mp(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Tr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=ya(e,i.attrs),this.excluded=null;let s=pa(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ma(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},Dr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=yo.from(e.nodes),t.marks=yo.from(e.marks||{}),this.nodes=Hi.compile(this.spec.nodes,this),this.marks=Tr.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=en.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?Qc(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Qc(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Hi){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new ko(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Ke.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Qc(n,e){let t=[];for(let r=0;r-1)&&t.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Ap(n){return n.tag!=null}function Ep(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Ap(i))this.tags.push(i);else if(Ep(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new Wi(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Wi(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let c=o.getAttrs(t);if(c===!1)continue;o.attrs=c||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=ea(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=ea(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},wa={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Tp={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ba={ol:!0,ul:!0},Ji=1,$i=2,Er=4;function Zc(n,e,t){return e!=null?(e?Ji:0)|(e==="full"?$i:0):n&&n.whitespace=="pre"?Ji|$i:t&~Er}var Ln=class{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=D.none,this.match=s||(o&Er?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ji)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!wa.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Wi=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=Zc(null,t.preserveWhitespace,0)|(r?Er:0);i?s=new Ln(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new Ln(null,null,D.none,!0,null,o):s=new Ln(e.schema.topNodeType,null,D.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&$i||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Ji)i.options&$i?r=r.replace(/\r\n?/g,` -`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),s;ba.hasOwnProperty(i)&&this.parser.normalizeLists&&Dp(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Tp.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,c=this.top,a=this.needsBlock;if(wa.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=o&&o.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,o,l,o.consuming===!1?s:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(o,t.attrs||null,r,t.preserveWhitespace);c&&(s=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=o,!l.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s(o.type?o.type.allowsMarkType(a.type):ta(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Ln(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(o(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=s?r.node(c-s).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Dp(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ba.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Op(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function ea(n){let e={};for(let t in n)e[t]=n[t];return e}function ta(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let c=0;c{if(s.length||o.marks.length){let l=0,c=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Li(bo(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Li(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=na(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return na(e.marks)}};function na(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function bo(n){return n.document||window.document}var ra=new WeakMap;function Np(n){let e=ra.get(n);return e===void 0&&ra.set(n,e=Ip(n)),e}function Ip(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let d in a)if(a[d]!=null){let f=d.indexOf(" ");f>0?c.setAttributeNS(d.slice(0,f),d.slice(f+1),a[d]):c.setAttribute(d,a[d])}}for(let d=h;dh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=Li(n,f,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var ka=65535,Ca=Math.pow(2,16);function vp(n,e){return n+e*Ca}function xa(n){return n&ka}function _p(n){return(n-(n&ka))/Ca}var Ma=1,Aa=2,ji=4,Ea=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Ea)>0}get deletedBefore(){return(this.delInfo&(Ma|ji))>0}get deletedAfter(){return(this.delInfo&(Aa|ji))>0}get deletedAcross(){return(this.delInfo&ji)>0}},ft=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=xa(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+s],h=this.ranges[l+o],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:vp(l/3,e-c),m=e==c?Aa:e==d?Ma:ji;return(t<0?e!=c:e!=d)&&(m|=Ea),new Ir(u,m,p)}i+=h-a}return r?e+i:new Ir(e+i,0,null)}touches(e,t){let r=0,i=xa(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+s],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&c!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,s)}invert(){return new tn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("addMark",vr);var tn=class n extends G{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(No(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,r)}invert(){return new vr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("removeMark",tn);var _r=class n extends G{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};G.jsonID("replaceAround",X);function Do(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Up(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),s.forEach(c=>n.step(c))}function Vp(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let c=null;if(r instanceof Tr){let a=o.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(o.marks)&&(c=[r]):c=o.marks;if(c&&c.length){let a=Math.min(l+o.nodeSize,t);for(let h=0;hn.step(new tn(o.from,o.to,o.style)))}function Io(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let c=0;c=0;c--)n.step(o[c])}function Bp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),d++):c--;let f=w.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=w.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new X(i,s,i,s,new b(r,0,0),t.length,!0))}function qp(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let c=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,c)&&Hp(n.doc,n.mapping.slice(s).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Da(n,o,l,s),Io(n,n.mapping.slice(s).map(l,1),r,void 0,a===null);let h=n.mapping.slice(s),d=h.map(l,1),f=h.map(l+o.nodeSize,1);return n.step(new X(d,f,d+1,f-1,new b(w.from(r.create(c,null,o.marks)),0,0),1,!0)),a===!0&&Ta(n,o,l,s),!1}})}function Ta(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Da(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(` -`))}})}function Hp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Jp(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new X(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(w.from(o),0,0),1,!0))}function Rt(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>s;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),c=r&&r[0];return i.node(s).canReplaceWith(l,l,c?c.type:i.node(s+1).type)}function $p(n,e,t=1,r){let i=n.doc.resolve(e),s=w.empty,o=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=w.from(i.node(l).copy(s));let h=r&&r[a];o=w.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Ee(e,e,new b(s.append(o),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Oa(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Wp(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&Oa(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function jp(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let h=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);h&&!d?r=!1:!h&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Da(n,h.node(),h.before(),l)}o.inlineContent&&Io(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ee(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);Ta(n,h.node(),h.before(),n.steps.length)}return n}function Kp(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,c=r.index(o)+(l>0?1:0),a=r.node(o),h=!1;if(s==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function Xi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Ia(i,s,r)?new Ee(e,t,r):new Oo(i,s,r).fit()}function Ia(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Oo=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let c=new b(s,o,l);return e>-1?new X(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ee(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=Eo(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(o?a.matchType(o.type)||(d=a.fillBefore(w.from(o),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(h=a.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&a.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Eo(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Eo(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Or(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Or(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(Ra(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Nr(this.placed,t,w.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:c,type:a}=this.frontier[l],h=To(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Nr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Nr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Nr(this.placed,this.frontier.length,t))}};function Or(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Or(n.firstChild.content,e-1,t)))}function Nr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Nr(n.lastChild.content,e-1,t)))}function Eo(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Ra(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function To(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!Yp(t,s.content,o)?l:null}function Yp(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==u&&o.splice(1,0,-f)}let c=o.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=Gp(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=o[f];u<0||(e=i.before(u),t=s.after(u))}}function va(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(w.empty,!0))}return n}function Qp(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Kp(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function Zp(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=_a(r,i);for(let o=0;o0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function _a(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var Ki=class n extends G{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return ft.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};G.jsonID("attr",Ki);var Yi=class n extends G{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ee.ok(r)}getMap(){return ft.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};G.jsonID("docAttr",Yi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Rr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Xi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Xp(this,e,t,r),this}replaceRangeWith(e,t,r){return Qp(this,e,t,r),this}deleteRange(e,t){return Zp(this,e,t),this}lift(e,t){return Pp(this,e,t),this}join(e,t=1){return jp(this,e,t),this}wrap(e,t){return Fp(this,e,t),this}setBlockType(e,t=e,r,i=null){return qp(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Jp(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Ki(e,t,r)),this}setDocAttribute(e,t){return this.step(new Yi(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Ur(e,t)),this}split(e,t=1,r){return $p(this,e,t,r),this}addMark(e,t,r){return Up(this,e,t,r),this}removeMark(e,t,r){return Vp(this,e,t,r),this}clearIncompatible(e,t,r){return Io(this,e,t,r),this}};var vo=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new vt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?Hn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Hn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Te(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Te(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=vo[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in vo)throw new RangeError("Duplicate use of selection JSON ID "+e);return vo[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var vt=class{constructor(e,t){this.$from=e,this.$to=t}},Ua=!1;function Va(n){!Ua&&!n.parent.inlineContent&&(Ua=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Va(e),Va(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&C.isSelectable(l))return C.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function Ba(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}var Pa=1,Qi=2,La=4,Vo=class extends qn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Qi,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Qi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Qi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=La,this}get scrolledIntoView(){return(this.updated&La)>0}};function za(n,e){return!e||!n?n:n.bind(e)}var sn=class{constructor(e,t,r){this.name=e,this.init=za(t.init,r),this.apply=za(t.apply,r)}},tm=[new sn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new sn("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new sn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new sn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Vr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=tm.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new sn(r.key,r.spec.state,r))})}},Bo=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Vr(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Ke.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==o.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=a.fromJSON.call(c,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function Fa(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Fa(i,e,{})),t[r]=i}return t}var H=class{constructor(e){this.spec=e,this.props={},e.props&&Fa(e.props,this,this.props),this.key=e.key?e.key.key:qa("plugin")}getState(e){return e[this.key]}},_o=Object.create(null);function qa(n){return n in _o?n+"$"+ ++_o[n]:(_o[n]=0,n+"$")}var le=class{constructor(e="key"){this.key=qa(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var te=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},zr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},qo=null,pt=function(n,e,t){let r=qo||(qo=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},nm=function(){qo=null},fn=function(n,e,t,r){return t&&(Ha(n,e,t,r,-1)||Ha(n,e,t,r,1))},rm=/^(img|br|input|textarea|hr)$/i;function Ha(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:_e(n))){let s=n.parentNode;if(!s||s.nodeType!=1||Jr(n)||rm.test(n.nodeName)||n.contentEditable=="false")return!1;e=te(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?_e(n):0}else return!1}}function _e(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function im(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=_e(n)}else if(n.parentNode&&!Jr(n))e=te(n),n=n.parentNode;else return null}}function sm(n,e){for(;;){if(n.nodeType==3&&e2),ve=Kn||(Ye?/Mac/.test(Ye.platform):!1),am=Ye?/Win/.test(Ye.platform):!1,Fe=/Android \d/.test(Lt),$r=!!Ja&&"webkitFontSmoothing"in Ja.documentElement.style,hm=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function dm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ut(n,e){return typeof n=="number"?n:n[e]}function fm(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function $a(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=zr(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?dm(s):fm(l),h=0,d=0;if(e.topa.bottom-ut(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+ut(i,"top")-a.top:e.bottom-a.bottom+ut(i,"bottom")),e.lefta.right-ut(r,"right")&&(h=e.right-a.right+ut(i,"right")),h||d)if(c)s.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function um(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:Mh(n.dom)}}function Mh(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=zr(r));return e}function pm({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Ah(t,r==0?0:r-e)}function Ah(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?gm(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:Eh(t,i)}function gm(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function ll(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function ym(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function bm(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!o&&c.left>r.left||c.top>r.top?i=l.posBefore:(!o&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Th(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;$r&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=bm(n,r,i,e))}l==null&&(l=wm(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Wa(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Br(_t(pt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Po(c.getBoundingClientRect(),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return Po(c.getBoundingClientRect(),!0)}return Po(r.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?pt(c,_e(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Br(_t(a,1),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let a=c?c.nodeType==3?pt(c,0,o?0:1):c.nodeType==1?c:null:null;if(a)return Br(_t(a,-1),!0)}return Br(_t(r.nodeType==3?pt(r):r,-t),t>=0)}function Br(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Po(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Oh(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function km(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Oh(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Dh(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=pt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}var Cm=/[\u0590-\u08ac]/;function Mm(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!Cm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Oh(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}var ja=null,Ka=null,Ya=!1;function Am(n,e,t){return ja==e&&Ka==t?Ya:(ja=e,Ka=t,Ya=t=="up"||t=="down"?km(n,e,t):Mm(n,e,t))}var Ue=0,Ga=1,ln=2,Ge=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Ue,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tte(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof ns){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof es&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?te(s.dom)+1:0}}else{let s,o=!0;for(;s=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=o;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=te(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&ot){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,` +var bp=Object.defineProperty;var xp=(n,e)=>{for(var t in e)bp(n,t,{get:e[t],enumerable:!0})};function se(n){this.content=n}se.prototype={constructor:se,find:function(n){for(var e=0;e>1}};se.from=function(n){if(n instanceof se)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new se(e)};var ws=se;function la(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=la(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function ca(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),c=s.nodeSize;if(s==l){t-=c,r-=c;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let a=0,h=Math.min(s.text.length,l.text.length);for(;ae&&r(c,i+l,o||null,s)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=a},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,o)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||t>0?Pi(r+1,s):Pi(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var Qt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=ha(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(aa(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function aa(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(aa(o.content,e-i-1,t-i-1)))}function ha(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=ha(s.content,e-o-1,t);return l&&n.replaceChild(i,s.copy(l))}function Sp(n,e,t){if(t.openStart>n.depth)throw new Qt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Qt("Inconsistent open depths");return da(n,e,t,0)}function da(n,e,t,r){let i=n.index(r),o=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Ar(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(Gt(n.nodeAfter,r),o++));for(let l=o;li&&Ss(n,e,i+1),s=r.depth>i&&Ss(t,r,i+1),l=[];return Ar(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(fa(o,s),Gt(Xt(o,ua(n,e,t,r,i+1)),l)):(o&&Gt(Xt(o,Fi(n,e,i+1)),l),Ar(e,t,i,l),s&&Gt(Xt(s,Fi(t,r,i+1)),l)),Ar(r,null,i,l),new w(l)}function Fi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=Ss(n,e,t+1);Gt(Xt(i,Fi(n,e,t+1)),r)}return Ar(e,null,t,r),new w(r)}function kp(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var qi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let o=0;o0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Zt(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,o=t;for(let s=e;;){let{index:l,offset:c}=s.content.findIndex(o),a=o-c;if(r.push(s,l,i+c),!a||(s=s.child(l),s.isText))break;o=a-1,i+=c+1}return new n(t,r,o)}static resolveCached(e,t){let r=Qc.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,t,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),pa(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,i,r);return o.type.checkAttrs(o.attrs),o}};Ke.prototype.text=void 0;var Cs=class n extends Ke{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):pa(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function pa(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var en=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Ms(e,t);if(r.next==null)return n.empty;let i=ma(r);r.next&&r.err("Unexpected trailing text");let o=Ip(Np(i));return Rp(o,r),o}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` +`)}};en.empty=new en(!0);var Ms=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function ma(n){let e=[];do e.push(Ap(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Ap(n){let e=[];do e.push(Ep(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Ep(n){let e=Op(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=Tp(n,e);else break;return e}function Zc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function Tp(n,e){let t=Zc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Zc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Dp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.isInGroup(e)&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function Op(n){if(n.eat("(")){let e=ma(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=Dp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Np(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,c){let a={term:c,to:l};return e[s].push(a),a}function i(s,l){s.forEach(c=>c.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((c,a)=>c.concat(o(a,l)),[]);if(s.type=="seq")for(let c=0;;c++){let a=o(s.exprs[c],l);if(c==s.exprs.length-1)return a;i(a,l=t())}else if(s.type=="star"){let c=t();return r(l,c),i(o(s.expr,c),c),[r(c)]}else if(s.type=="plus"){let c=t();return i(o(s.expr,l),c),i(o(s.expr,c),c),[r(c)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let c=l;for(let a=0;a{n[s].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let o=e[r.join(",")]=new en(r.indexOf(n.length-1)>-1);for(let s=0;s-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:wa(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ke(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Ke(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let s=this.contentMatch.fillBefore(t);if(!s)return null;t=s.append(t)}let i=this.contentMatch.matchFragment(t),o=i&&i.fillBefore(w.empty,!0);return o?new Ke(this,e,t.append(o),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new n(o,t,s));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function vp(n,e,t){let r=t.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}var As=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?vp(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Tr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=xa(e,i.attrs),this.excluded=null;let o=ya(this.attrs);this.instance=o?new D(this,o):null}create(e=null){return!e&&this.instance?this.instance:new D(this,wa(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new n(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}},Dr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=ws.from(e.nodes),t.marks=ws.from(e.marks||{}),this.nodes=Hi.compile(this.spec.nodes,this),this.marks=Tr.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=en.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?ta(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:ta(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Hi){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new Cs(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Ke.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function ta(n,e){let t=[];for(let r=0;r-1)&&t.push(s=c)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function _p(n){return n.tag!=null}function Up(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(_p(i))this.tags.push(i);else if(Up(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new Wi(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Wi(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(s.getAttrs){let c=s.getAttrs(t);if(c===!1)continue;s.attrs=c||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=ra(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=ra(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},Sa={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Vp={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ka={ol:!0,ul:!0},Ji=1,$i=2,Er=4;function na(n,e,t){return e!=null?(e?Ji:0)|(e==="full"?$i:0):n&&n.whitespace=="pre"?Ji|$i:t&~Er}var Ln=class{constructor(e,t,r,i,o,s){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=D.none,this.match=o||(s&Er?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ji)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Sa.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Wi=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,o,s=na(null,t.preserveWhitespace,0)|(r?Er:0);i?o=new Ln(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,s):r?o=new Ln(null,null,D.none,!0,null,s):o=new Ln(e.schema.topNodeType,null,D.none,!0,null,s),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&$i||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Ji)i.options&$i?r=r.replace(/\r\n?/g,` +`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],s=e.previousSibling;(!o||s&&s.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),o;ka.hasOwnProperty(i)&&this.parser.normalizeLists&&Bp(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,r));if(s?s.ignore:Vp.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let l,c=this.top,a=this.needsBlock;if(Sa.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=s&&s.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,s,l,s.consuming===!1?o:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` +`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let o,s;if(t.node)if(s=this.parser.schema.nodes[t.node],s.isLeaf)this.insertNode(s.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(s,t.attrs||null,r,t.preserveWhitespace);c&&(o=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}o&&this.sync(l)&&this.open--}addAll(e,t,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];s!=l;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,t);this.findAtPoint(e,o)}findPlace(e,t){let r,i;for(let o=this.open;o>=0;o--){let s=this.nodes[o],l=s.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=s,!l.length)||s.solid)break}if(!r)return null;this.sync(i);for(let o=0;o(s.type?s.type.allowsMarkType(a.type):ia(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Ln(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=o;c--)if(s(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Bp(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ka.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Pp(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function ra(n){let e={};for(let t in n)e[t]=n[t];return e}function ia(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let c=0;c{if(o.length||s.marks.length){let l=0,c=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Li(xs(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Li(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=oa(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return oa(e.marks)}};function oa(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function xs(n){return n.document||window.document}var sa=new WeakMap;function Lp(n){let e=sa.get(n);return e===void 0&&sa.set(n,e=zp(n)),e}function zp(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(t=i.slice(0,s),i=i.slice(s+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let d in a)if(a[d]!=null){let f=d.indexOf(" ");f>0?c.setAttributeNS(d.slice(0,f),d.slice(f+1),a[d]):c.setAttribute(d,a[d])}}for(let d=h;dh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=Li(n,f,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var Aa=65535,Ea=Math.pow(2,16);function qp(n,e){return n+e*Ea}function Ca(n){return n&Aa}function Hp(n){return(n-(n&Aa))/Ea}var Ta=1,Da=2,ji=4,Oa=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Oa)>0}get deletedBefore(){return(this.delInfo&(Ta|ji))>0}get deletedAfter(){return(this.delInfo&(Da|ji))>0}get deletedAcross(){return(this.delInfo&ji)>0}},ft=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=Ca(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+o],h=this.ranges[l+s],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:qp(l/3,e-c),m=e==c?Da:e==d?Ta:ji;return(t<0?e!=c:e!=d)&&(m|=Oa),new Ir(u,m,p)}i+=h-a}return r?e+i:new Ir(e+i,0,null)}touches(e,t){let r=0,i=Ca(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+o],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+s]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&c!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,o)}invert(){return new tn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("addMark",vr);var tn=class n extends G{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(Is(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,r)}invert(){return new vr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("removeMark",tn);var _r=class n extends G{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};G.jsonID("replaceAround",X);function Os(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Jp(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),o.forEach(c=>n.step(c))}function $p(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let c=null;if(r instanceof Tr){let a=s.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(s.marks)&&(c=[r]):c=s.marks;if(c&&c.length){let a=Math.min(l+s.nodeSize,t);for(let h=0;hn.step(new tn(s.from,s.to,s.style)))}function Rs(n,e,t,r=t.contentMatch,i=!0){let o=n.doc.nodeAt(e),s=[],l=e+1;for(let c=0;c=0;c--)n.step(s[c])}function Wp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),d++):c--;let f=w.empty,u=0;for(let p=o,m=!1;p>t;p--)m||i.after(p+1)=0;s--){if(r.size){let l=t[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=w.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new X(i,o,i,o,new b(r,0,0),t.length,!0))}function Xp(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{let c=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,c)&&Qp(n.doc,n.mapping.slice(o).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Ia(n,s,l,o),Rs(n,n.mapping.slice(o).map(l,1),r,void 0,a===null);let h=n.mapping.slice(o),d=h.map(l,1),f=h.map(l+s.nodeSize,1);return n.step(new X(d,f,d+1,f-1,new b(w.from(r.create(c,null,s.marks)),0,0),1,!0)),a===!0&&Na(n,s,l,o),!1}})}function Na(n,e,t,r){e.forEach((i,o)=>{if(i.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+o+s.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Ia(n,e,t,r){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let s=n.mapping.slice(r).map(t+1+o);n.replaceWith(s,s+1,e.type.schema.text(` +`))}})}function Qp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Zp(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new X(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new b(w.from(s),0,0),1,!0))}function Rt(n,e,t=1,r){let i=n.resolve(e),o=i.depth-t,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>o;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(o),c=r&&r[0];return i.node(o).canReplaceWith(l,l,c?c.type:i.node(o+1).type)}function em(n,e,t=1,r){let i=n.doc.resolve(e),o=w.empty,s=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){o=w.from(i.node(l).copy(o));let h=r&&r[a];s=w.from(h?h.type.create(h.attrs,s):i.node(l).copy(s))}n.step(new Ee(e,e,new b(o.append(s),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Ra(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function tm(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(o=r.node(i+1),l++,s=r.node(i).maybeChild(l)):(o=r.node(i).maybeChild(l-1),s=r.node(i+1)),o&&!o.isTextblock&&Ra(o,s)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function nm(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,o=n.doc.resolve(e-t),s=o.node().type;if(i&&s.inlineContent){let h=s.whitespace=="pre",d=!!s.contentMatch.matchType(i);h&&!d?r=!1:!h&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Ia(n,h.node(),h.before(),l)}s.inlineContent&&Rs(n,e+t-1,s,o.node().contentMatchAt(o.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ee(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);Na(n,h.node(),h.before(),n.steps.length)}return n}function rm(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,c=r.index(s)+(l>0?1:0),a=r.node(s),h=!1;if(o==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function Xi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return _a(i,o,r)?new Ee(e,t,r):new Ns(i,o,r).fit()}function _a(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Ns=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let c=new b(o,s,l);return e>-1?new X(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ee(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ts(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(s?a.matchType(s.type)||(d=a.fillBefore(w.from(s),!1)):o&&c.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:d};if(t==2&&s&&(h=a.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:h};if(o&&a.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ts(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ts(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new b(Or(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new b(Or(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(Ua(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Nr(this.placed,t,w.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:c,type:a}=this.frontier[l],h=Ds(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Nr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Nr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Nr(this.placed,this.frontier.length,t))}};function Or(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Or(n.firstChild.content,e-1,t)))}function Nr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Nr(n.lastChild.content,e-1,t)))}function Ts(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Ua(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function Ds(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!im(t,o.content,s)?l:null}function im(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;s.indexOf(f)>-1?l=f:i.before(f)==u&&s.splice(1,0,-f)}let c=s.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=om(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=s[f];u<0||(e=i.before(u),t=o.after(u))}}function Va(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(w.empty,!0))}return n}function lm(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=rm(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function cm(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=Ba(r,i);for(let s=0;s0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return n.delete(r.before(s),t);n.delete(e,t)}function Ba(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}var Ki=class n extends G{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return ft.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};G.jsonID("attr",Ki);var Yi=class n extends G{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ee.ok(r)}getMap(){return ft.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};G.jsonID("docAttr",Yi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Rr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Xi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return sm(this,e,t,r),this}replaceRangeWith(e,t,r){return lm(this,e,t,r),this}deleteRange(e,t){return cm(this,e,t),this}lift(e,t){return jp(this,e,t),this}join(e,t=1){return nm(this,e,t),this}wrap(e,t){return Gp(this,e,t),this}setBlockType(e,t=e,r,i=null){return Xp(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Zp(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Ki(e,t,r)),this}setDocAttribute(e,t){return this.step(new Yi(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Ur(e,t)),this}split(e,t=1,r){return em(this,e,t,r),this}addMark(e,t,r){return Jp(this,e,t,r),this}removeMark(e,t,r){return $p(this,e,t,r),this}clearIncompatible(e,t,r){return Rs(this,e,t,r),this}};var _s=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new vt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;o--){let s=t<0?Hn(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Hn(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Te(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Te(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=_s[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in _s)throw new RangeError("Duplicate use of selection JSON ID "+e);return _s[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var vt=class{constructor(e,t){this.$from=e,this.$to=t}},Pa=!1;function La(n){!Pa&&!n.parent.inlineContent&&(Pa=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){La(e),La(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let o=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(o)t=o.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&C.isSelectable(l))return C.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,o);if(c)return c}t+=l.nodeSize*i}return null}function za(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=h)}),n.setSelection(S.near(n.doc.resolve(s),t))}var Fa=1,Qi=2,qa=4,Bs=class extends qn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Qi,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Qi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Qi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=qa,this}get scrolledIntoView(){return(this.updated&qa)>0}};function Ha(n,e){return!e||!n?n:n.bind(e)}var on=class{constructor(e,t,r){this.name=e,this.init=Ha(t.init,r),this.apply=Ha(t.apply,r)}},hm=[new on("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new on("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new on("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new on("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Vr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=hm.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new on(r.key,r.spec.state,r))})}},Ps=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(t[r]=o.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Vr(e.schema,e.plugins),o=new n(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=Ke.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=S.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==s.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=a.fromJSON.call(c,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}};function Ja(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Ja(i,e,{})),t[r]=i}return t}var H=class{constructor(e){this.spec=e,this.props={},e.props&&Ja(e.props,this,this.props),this.key=e.key?e.key.key:$a("plugin")}getState(e){return e[this.key]}},Us=Object.create(null);function $a(n){return n in Us?n+"$"+ ++Us[n]:(Us[n]=0,n+"$")}var le=class{constructor(e="key"){this.key=$a(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var te=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},zr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Hs=null,pt=function(n,e,t){let r=Hs||(Hs=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},dm=function(){Hs=null},fn=function(n,e,t,r){return t&&(Wa(n,e,t,r,-1)||Wa(n,e,t,r,1))},fm=/^(img|br|input|textarea|hr)$/i;function Wa(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:_e(n))){let o=n.parentNode;if(!o||o.nodeType!=1||Jr(n)||fm.test(n.nodeName)||n.contentEditable=="false")return!1;e=te(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?_e(n):0}else return!1}}function _e(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function um(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=_e(n)}else if(n.parentNode&&!Jr(n))e=te(n),n=n.parentNode;else return null}}function pm(n,e){for(;;){if(n.nodeType==3&&e2),ve=Kn||(Ye?/Mac/.test(Ye.platform):!1),wm=Ye?/Win/.test(Ye.platform):!1,He=/Android \d/.test(Lt),$r=!!ja&&"webkitFontSmoothing"in ja.documentElement.style,bm=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function xm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ut(n,e){return typeof n=="number"?n:n[e]}function Sm(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Ka(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;s=zr(s)){if(s.nodeType!=1)continue;let l=s,c=l==o.body,a=c?xm(o):Sm(l),h=0,d=0;if(e.topa.bottom-ut(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+ut(i,"top")-a.top:e.bottom-a.bottom+ut(i,"bottom")),e.lefta.right-ut(r,"right")&&(h=e.right-a.right+ut(i,"right")),h||d)if(c)o.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function km(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:Th(n.dom)}}function Th(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=zr(r));return e}function Cm({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Dh(t,r==0?0:r-e)}function Dh(n,e){for(let t=0;t=l){s=Math.max(p.bottom,s),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(o=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?Am(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:Oh(t,i)}function Am(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function cl(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function Em(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function Dm(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!s&&c.left>r.left||c.top>r.top?i=l.posBefore:(!s&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Nh(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;$r&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=Dm(n,r,i,e))}l==null&&(l=Tm(n,s,e));let c=n.docView.nearestDesc(s,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Ya(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Br(_t(pt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Ls(c.getBoundingClientRect(),!1)}if(o==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return Ls(c.getBoundingClientRect(),!0)}return Ls(r.getBoundingClientRect(),t>=0)}if(o==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?pt(c,_e(c)-(s?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Br(_t(a,1),!1)}if(o==null&&i<_e(r)){let c=r.childNodes[i];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let a=c?c.nodeType==3?pt(c,0,s?0:1):c.nodeType==1?c:null:null;if(a)return Br(_t(a,-1),!0)}return Br(_t(r.nodeType==3?pt(r):r,-t),t>=0)}function Br(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Ls(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Rh(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Im(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Rh(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Ih(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=pt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?s.top-h.top>(h.bottom-s.top)*2:h.bottom-s.bottom>(s.bottom-h.top)*2))return!1}}return!0})}var Rm=/[\u0590-\u08ac]/;function vm(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!Rm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Rh(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}var Ga=null,Xa=null,Qa=!1;function _m(n,e,t){return Ga==e&&Xa==t?Qa:(Ga=e,Xa=t,Qa=t=="up"||t=="down"?Im(n,e,t):vm(n,e,t))}var Ue=0,Za=1,ln=2,Ge=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Ue,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tte(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof no){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof eo&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?te(o.dom)+1:0}}else{let o,s=!0;for(;o=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=s;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=te(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&st){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+o.border,c=s-o.border;if(e>=l&&t<=c){this.dirty=e==r||t==s?ln:Za,e==l&&t==c&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Ge:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?ln:Ge}r=s}this.dirty=ln}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?ln:Za;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=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}},js=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 o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=It.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,s.dom,s.contentDOM||s.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&&(o=Xs(o,0,e,r));for(let l=0;l{if(!c)return s;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=Uh(h,r,t),a?c=new Ks(e,t,r,i,h,d||null,f,a,o,s+1):t.isText?new to(e,t,r,i,h,f,o):new n(e,t,r,i,h,d||null,f,o,s+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)&&ro(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,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,c=new Gs(this,s&&s.node,e);Pm(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)&&(s&&this.protectLocalComposition(e,s),vh(this.contentDOM,this.children,e),Kn&&Lm(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 o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=zm(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new js(this,o,t,i);e.input.compositionNodes.push(s),this.children=Xs(this.children,r,r+i.length,e,s)}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(ro(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=_h(this.dom,this.nodeDOM,Ys(this.outerDeco,this.node,t),Ys(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 eh(n,e,t,r,i){Uh(r,e,n);let o=new Pt(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}var to=class n extends Pt{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,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),o=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,o,o,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}},no=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"}},Ks=class extends Pt{constructor(e,t,r,i,o,s,l,c,a,h){super(e,t,r,i,o,s,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==Ge)return!1;if(this.spec.update){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}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 vh(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,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[o],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,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,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Bm(n,e){return n.type.side-e.type.side}function Pm(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let a=0;ao;)l.push(i[s++]);let p=o+f.nodeSize;if(f.isText){let g=p;s!g.inline):l.slice();r(f,m,e.forChild(o,f),u),o=p}}function Lm(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 zm(n,e,t,r){for(let i=0,o=0;i=t){if(o>=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 Xs(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||h<=e?o.push(c):(at&&o.push(c.slice(t-a,c.size,r)))}return o}function al(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),c,a;if(ho(t)){for(c=s;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&C.isSelectable(d)&&i.parent&&!(d.isInline&&mm(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;a=new C(s==f?l:r.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=s,f=s;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 qm(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 Bh(n,e){if(e instanceof C){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(oh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else oh(n)}function oh(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function hl(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function sh(n){return n.editable&&!n.hasFocus()?!1:Ph(n)}function Ph(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 Hm(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 Qs(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&S.findFrom(o,e)}function Ut(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function lh(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return Ut(n,new A(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Qs(n.state,e);return i&&i instanceof C?Ut(n,i):!1}else if(!(ve&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?C.isSelectable(o)?Ut(n,new C(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):$r?Ut(n,new A(n.state.doc.resolve(e<0?l:l+o.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=Qs(n.state,e);return i?Ut(n,i):!1}}}function io(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?Jm(n):$m(n)}function Jm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(Je&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Lr(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Lh(t))break;{let l=t.previousSibling;for(;l&&Lr(l,-1);)i=t.parentNode,o=te(l),l=l.previousSibling;if(l)t=l,r=io(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?Zs(n,t,r):i&&Zs(n,i,o)}function $m(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=io(t),o,s;for(;;)if(r{n.state==i&&mt(n)},50)}function ch(n,e){let t=n.state.doc.resolve(e);if(!(ae||wm)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function ah(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:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Qs(n.state,e);if(s&&s instanceof C)return Ut(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Te?S.near(s,e):S.findFrom(s,e);return l?Ut(n,l):!1}return!1}function hh(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 o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function dh(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Km(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;dh(n,r,"true"),setTimeout(()=>dh(n,r,"false"),20)}return!1}function Ym(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Gm(n,e){let t=e.keyCode,r=Ym(e);if(t==8||ve&&t==72&&r=="c")return hh(n,-1)||$n(n,-1);if(t==46&&!e.shiftKey||ve&&t==68&&r=="c")return hh(n,1)||$n(n,1);if(t==13||t==27)return!0;if(t==37||ve&&t==66&&r=="c"){let i=t==37?ch(n,n.state.selection.from)=="ltr"?-1:1:-1;return lh(n,i,r)||$n(n,i)}else if(t==39||ve&&t==70&&r=="c"){let i=t==39?ch(n,n.state.selection.from)=="ltr"?1:-1:1;return lh(n,i,r)||$n(n,i)}else{if(t==38||ve&&t==80&&r=="c")return ah(n,-1,r)||$n(n,-1);if(t==40||ve&&t==78&&r=="c")return Km(n)||ah(n,1,r)||$n(n,1);if(r==(ve?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function zh(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let s=n.someProp("clipboardSerializer")||It.fromSchema(n.state.schema),l=Wh(),c=l.createElement("div");c.appendChild(s.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=$h[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} ${o}${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}; +`);return{dom:c,text:f,slice:e}}function Fh(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let c=e&&(r||o||!t);if(c){if(n.someProp("transformPastedText",f=>{e=f(e,o||r,n)}),o)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);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),s=eg(t),$r&&tg(s);let a=s&&s.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=s.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;s=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!Xm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=ng(fh(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Qm(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 Xm=/^(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 Qm(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)),o,s=[];if(n.forEach(l=>{if(!s)return;let c=i.findWrapping(l.type),a;if(!c)return s=null;if(a=s.length&&o.length&&Hh(c,o,l,s[s.length-1],0))s[s.length-1]=a;else{s.length&&(s[s.length-1]=Jh(s[s.length-1],o.length));let h=qh(l,c);s.push(h),i=i.matchType(h.type),o=c}}),s)return w.from(s)}return n}function qh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function Hh(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function fh(n,e,t){return et}).createHTML(n):n}function eg(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Wh().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&$h[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=Zm(n),i)for(let o=0;o=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),o++,s++}return new b(i,o,s)}var ge={},ye={},rg={touchstart:!0,touchmove:!0},tl=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 ig(n){for(let e in ge){let t=ge[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{sg(n,r)&&!dl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},rg[e]?{passive:!0}:void 0)}me&&n.dom.addEventListener("input",()=>null),nl(n)}function Vt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function og(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 nl(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>dl(n,r))})}function dl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function sg(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 lg(n,e){!dl(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,!Kh(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(He&&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,sn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Gm(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(Kh(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",o=>o(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function fo(n){return{left:n.clientX,top:n.clientY}}function cg(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function fl(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),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 ag(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 hg(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof C&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(C.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(jn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function dg(n,e,t,r,i){return fl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?hg(n,t):ag(n,t))}function fg(n,e,t,r){return fl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function ug(n,e,t,r){return fl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||pg(n,t,r)}function pg(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 o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)jn(n,A.create(r,l+1,l+1+s.content.size),"pointer");else if(C.isSelectable(s))jn(n,C.create(r,l),"pointer");else continue;return!0}}function ul(n){return oo(n)}var jh=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=ul(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&cg(t,n.input.lastClick)&&!t[jh]&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o};let s=n.posAtCoords(fo(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new rl(n,s,t,!!r)):(o=="doubleClick"?fg:ug)(n,s.pos,s.inside,t)?t.preventDefault():Vt(n,"pointer"))};var rl=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 o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let h=e.state.doc.resolve(t.pos);o=h.parent,s=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&&o.type.spec.draggable&&o.type.spec.selectable!==!1||a instanceof C&&a.from<=s&&a.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Je&&!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(fo(e))),this.updateAllowDefault(e),this.allowDefault||!t?Vt(this.view,"pointer"):dg(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(),ul(n),Vt(n,"pointer")};ge.touchmove=n=>{n.input.lastTouch=Date.now(),Vt(n,"pointer")};ge.contextmenu=n=>ul(n);function Kh(n,e){return n.composing?!0:me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var mg=He?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(),oo(n,!0),n.markCursor=null;else if(oo(n,!e.selection.empty),Je&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Yh(n,mg)};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++,Yh(n,20))};function Yh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>oo(n),e))}function Gh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=yg());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function gg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=um(e.focusNode,e.focusOffset),r=pm(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function yg(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function oo(n,e=!1){if(!(He&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Gh(n),e||n.docView&&n.docView.dirty){let t=al(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 wg(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&&bm<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=Fr?null:t.clipboardData,s=r.content(),{dom:l,text:c}=zh(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",c)):wg(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function bg(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function xg(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 o=Fh(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,o||b.empty)))return!0;if(!o)return!1;let s=bg(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Xh(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&&!He)return;let r=Fr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&qr(n,Xh(r),r.getData("text/html"),i,t)?t.preventDefault():xg(n,t)};var so=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Qh=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,o=i.empty?null:n.posAtCoords(fo(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof C?i.to-1:i.to))){if(r&&r.mightDrag)s=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&&(s=C.create(n.state.doc,d.posBefore))}}let l=(s||n.state.selection).content(),{dom:c,text:a,slice:h}=zh(n,l);(!t.dataTransfer.files.length||!ae||Eh>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 so(h,!t[Qh],s)};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(fo(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",p=>{s=p(s,n)}):s=Fh(n,Xh(t.dataTransfer),Fr?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!t[Qh]);if(n.someProp("handleDrop",p=>p(n,t,s||b.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let c=s?va(n.state.doc,o.pos,s):o.pos;c==null&&(c=o.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=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,s.content.firstChild):a.replaceRange(h,h,s),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&C.isSelectable(s.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(s.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(hl(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&&He&&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",o=>o(n,sn(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 lo=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:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new ne(o-r,o-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 o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new ne(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}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,o){let s;for(let l=0;l{let a=c+r,h;if(h=ed(t,l,a)){for(i||(i=this.children.slice());ol&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&c.type instanceof an){let a=Math.max(o,c.from)-o,h=Math.min(s,c.to)-o;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]+o,-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]+o+1,s);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=kg(l,n,e,t,i,o,s),h=ao(a,r,0,s);e=h.local;for(let d=0;dt&&s.to{let a=ed(n,l,c+t);if(a){o=!0;let h=ao(a,l,t+c+1,r);h!=ce&&i.push(c,c+l.nodeSize,h)}});let s=Zh(o?td(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function Fs(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])),co.from(e)}var Cg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Mg=ke&&Bt<=11,ol=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 ol,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,Cg)),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(sh(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 o=e.focusNode;o;o=zr(o))t.add(o);for(let o=e.anchorNode;o;o=zr(o))if(t.has(o)){r=o;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)&&sh(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),o=-1,s=-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||Tg(e,d)!=u)&&f.remove()}}}let a=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),Ag(e)),this.handleDOMChange(o,s,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){o=g;break}if(!E||E.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(s),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:o,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:Og,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+s,head:y+s}}return{doc:m,sel:p,from:s,to:l}}function Og(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 Ng=/^(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 Ig(n,e,t,r,i){let o=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=al(n,T);if(Nt&&!n.state.selection.eq(Nt)){if(ae&&He&&n.input.lastKeyCode===13&&Date.now()-100wp(n,sn(13,"Enter"))))return;let Bi=n.state.tr.setSelection(Nt);T=="pointer"?Bi.setMeta("pointer",!0):T=="key"&&Bi.scrollIntoView(),o&&Bi.setMeta("composition",o),n.dispatch(Bi)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=Dg(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||He)&&i.some(T=>T.nodeType==1&&!Ng.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,sn(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=wh(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let Nt=n.state.tr.setSelection(T);o&&Nt.setMeta("composition",o),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,sn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&vg(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,sn(8,"Backspace")))){He&&ae&&n.domObserver.suppressSelectionUpdates();return}ae&&He&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),He&&!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,sn(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=Rg(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=wh(n,Y.doc,a.sel);T&&!(ae&&He&&n.composing&&T.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:hl(n,e.resolve(t.anchor),e.resolve(t.head))}function Rg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||qs(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function _g(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,o-Math.min(s,l));r-=s+c-o}if(s=s?o-r:0;o-=c,o&&o=l?o-r:0;o-=c,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}var ll=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 tl,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Mh),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=kh(this),Sh(this),this.nodeViews=Ch(this),this.docView=eh(this.state.doc,xh(this),Fs(this),this.dom,this),this.domObserver=new sl(this,(r,i,o,s)=>Ig(this,r,i,o,s)),this.domObserver.start(),ig(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&&nl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Mh),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,o=!1,s=!1;e.storedMarks&&this.composing&&(Gh(this),s=!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=Ch(this);Vg(u,this.nodeViews)&&(this.nodeViews=u,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&nl(this),this.editable=kh(this),Sh(this);let c=Fs(this),a=xh(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=o||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(s=!0);let f=h=="preserve"&&s&&this.dom.style.overflowAnchor==null&&km(this);if(s){this.domObserver.stop();let u=d&&(ke||ae)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Ug(i.selection,e.selection);if(d){let p=ae?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=gg(this)),(o||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=eh(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Hm(this))?mt(this,u):(Bh(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&&Cm(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&&Ka(this,t.getBoundingClientRect(),e)}else Ka(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(o))==r.node&&(i=o)}this.dragging=new so(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 s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Om(this,e)}coordsAtPos(e,t=1){return Ih(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 _m(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&&(og(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Fs(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,dm())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return lg(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&&gm(this.dom.ownerDocument)==this.dom&&Eg(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function xh(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 Sh(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 kh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Ug(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 Ch(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 Vg(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 Mh(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 Bg=["p",0],Pg=["blockquote",0],Lg=["hr"],zg=["pre",["code",0]],Fg=["br"],qg={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Bg}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Pg}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Lg}},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 zg}},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 Fg}}},Hg=["em",0],Jg=["strong",0],$g=["code",0],Wg={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 Hg}},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 Jg}},code:{parseDOM:[{tag:"code"}],toDOM(){return $g}}},jg=new Dr({nodes:qg,marks:Wg});var rd=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Kg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Yg=(n,e,t)=>{let r=Kg(n,t);if(!r)return!1;let i=id(r);if(!i){let s=r.blockRange(),l=s&&nn(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(ld(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Gn(o,"end")||C.isSelectable(o)))for(let s=r.depth;;s--){let l=Xi(n.doc,r.before(s),r.after(s),b.empty);if(l&&l.slice.size1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-o.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 Gg=(n,e,t)=>{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=id(r)}let s=o&&o.nodeBefore;return!s||!C.isSelectable(s)?!1:(e&&e(n.tr.setSelection(C.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function id(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 Xg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Xg(n,t);if(!r)return!1;let i=od(r);if(!i)return!1;let o=i.nodeAfter;if(ld(n,i,e,1))return!0;if(r.parent.content.size==0&&(Gn(o,"start")||C.isSelectable(o))){let s=Xi(n.doc,r.before(),r.after(),b.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=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=vs(n.doc,t.from,-1),i==null)return!1;if(e){let o=n.tr.join(i);r&&o.setSelection(C.create(o.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(o.scrollIntoView())}return!0},sd=(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=vs(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),o=i&&nn(i);return o==null?!1:(e&&e(n.tr.lift(i,o).scrollIntoView()),!0)},ey=(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 gl(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),o=t.indexAfter(-1),s=gl(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,s.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},ty=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Te||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=gl(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!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 o=t.before();if(Rt(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function ry(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 o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof A||e.selection instanceof Te)&&s.deleteSelection();let l=r.depth==0?null:gl(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,o,r),a=c?[c]:o&&l?[{type:l}]:void 0,h=Rt(s.doc,s.mapping.map(r.pos),1,a);if(!a&&!h&&Rt(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(s.split(s.mapping.map(r.pos),1,a),!o&&!r.parentOffset&&r.parent.type!=l){let d=s.mapping.map(r.before()),f=s.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}return t&&t(s.scrollIntoView()),!0}}var iy=ry();var Kr=(n,e)=>{let{$from:t,to:r}=n.selection,i,o=t.sharedDepth(r);return o==0?!1:(i=t.before(o),e&&e(n.tr.setSelection(C.create(n.doc,i))),!0)},oy=(n,e)=>(e&&e(n.tr.setSelection(new Te(n.doc))),!0);function sy(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||rn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function ld(n,e,t,r){let i=e.nodeBefore,o=e.nodeAfter,s,l,c=i.type.spec.isolating||o.type.spec.isolating;if(!c&&sy(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(s=(l=i.contentMatchAt(i.childCount)).findWrapping(o.type))&&l.matchType(s[0]||o.type).validEnd){if(t){let u=e.pos+o.nodeSize,p=w.empty;for(let y=s.length-1;y>=0;y--)p=w.from(s[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),s.length,!0)),g=m.doc.resolve(u+2*s.length);g.nodeAfter&&g.nodeAfter.type==i.type&&rn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=o.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(o,"start",!0)&&Gn(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=o,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+o.nodeSize,e.pos+g,e.pos+o.nodeSize-g,new b(y,p.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function cd(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}var ly=cd(-1),cy=cd(1);function Xn(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o),l=s&&Gi(s,n,e);return l?(r&&r(t.tr.wrap(s,l).scrollIntoView()),!0):!1}}function pn(n,e=null){return function(t,r){let i=!1;for(let o=0;o{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 o=t.tr;for(let s=0;s{if(l||!r&&c.isAtom&&c.isInline&&a>=o.pos&&a+c.nodeSize<=s.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function hy(n){let e=[];for(let t=0;t{if(o.isAtom&&o.content.size&&o.isInline&&s>=r.pos&&s+o.nodeSize<=i.pos)return s+1>r.pos&&e.push(new vt(r,r.doc.resolve(s+1))),r=r.doc.resolve(s+1+o.content.size),!1}),r.poso.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(s.depth-1).type.compatibleContent(n)&&s.startIndex==0){if(i.index(s.depth-1)==0)return!1;let h=t.doc.resolve(s.start-2);c=new Zt(h,h,s.depth),s.endIndex=0;h--)o=w.from(t[h].type.create(t[h].attrs,o));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(o,0,0),t.length,!0));let s=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=o.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,o.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 xl(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?xy(e,t,n,o):Sy(e,t,o):!0:!1}}function xy(n,e,t,r){let i=n.tr,o=r.end,s=r.$to.end(r.depth);om;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let o=r.doc.resolve(t.start),s=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=o.node(-1),h=o.index(-1);if(!a.canReplace(h+(l?0:1),h+1,s.content.append(c?w.empty:w.from(i))))return!1;let d=o.pos,f=d+s.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 Sl(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let l=o.parent,c=l.child(s-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=o.start,u=o.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:"'"},mo={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ky=typeof navigator<"u"&&/Mac/.test(navigator.platform),Cy=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),mo[J]=String.fromCharCode(J);var J;for(po in yt)mo.hasOwnProperty(po)||(mo[po]=yt[po]);var po;function dd(n){var e=ky&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Cy&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?mo: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 Ay(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=yt[r.keyCode])&&o!=i){let l=e[kl(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var go=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(o,s){return i.push(e(o,s))},t,r),i};re.from=function(e){return e instanceof re?e:e&&e.length?new fd(e):re.empty};var fd=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,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,l){for(var c=o;c=s;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=go)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=go)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 fd([]);var Dy=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,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(o,l)-l,s+l)===!1||o=o?this.right.slice(r-o,i-o):this.left.slice(r,o).append(this.right.slice(0,i-o))},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),Cl=re;var Oy=500,yo=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,o;t&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,l,c,a=[],h=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),o=i.maps.length),o--,h.push(d);return}if(i){h.push(new Xe(d.map));let u=d.step.map(i.slice(o)),p;u&&s.maybeStep(u).doc&&(p=s.mapping.maps[s.mapping.maps.length-1],a.push(new Xe(p,void 0,void 0,a.length+h.length))),o--,p&&i.appendMap(p,o)}else s.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(o)):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:s,selection:l}}addTransform(e,t,r,i){let o=[],s=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hIy&&(l=Ny(l,a),s-=a),new n(l.append(o),s)}remapping(e,t){let r=new Rr;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},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),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let c=t;this.items.forEach(f=>{let u=o.getMirror(--c);if(u==null)return;s=Math.min(s,u);let p=o.maps[u];if(f.step){let m=e.steps[u].invert(e.docs[u]),g=f.selection&&f.selection.map(o.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;fOy&&(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=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let c=s.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=s.selection&&s.selection.map(t.slice(r));h&&o++;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 s.map&&r--},this.items.length,0),new n(Cl.from(i.reverse()),o)}};yo.empty=new yo(Cl.empty,0);function Ny(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)}}},Al=class{constructor(e,t,r,i,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},Iy=20;function Ry(n,e,t){let r=vy(e),i=El.get(e).spec.config,o=(t?n.undone:n.done).popEvent(e,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),l=(t?n.done:n.undone).addTransform(o.transform,e.selection.getBookmark(),i,r),c=new Al(t?l:o.remaining,t?o.remaining:l,null,0,-1);return o.transform.setSelection(s).setMeta(El,{redo:t,historyState:c})}var Ml=!1,ud=null;function vy(n){let e=n.plugins;if(ud!=e){Ml=!1,ud=e;for(let t=0;t{let i=El.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let o=Ry(i,t,n);o&&r(e?o.scrollIntoView():o)}return!0}}var Xr=wo(!1,!0),Qn=wo(!0,!0),xx=wo(!1,!1),Sx=wo(!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 Tl(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!_y(e)||!Uy(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,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!C.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),r=!1;continue e}break}o=s,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 Tl=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 _y(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 Uy(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 Vy(){return new H({props:{decorations:zy,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:Py,handleKeyDown:By,handleDOMEvents:{beforeinput:Ly}}})}var By=Gr({ArrowLeft:bo("horiz",-1),ArrowRight:bo("horiz",1),ArrowUp:bo("vert",-1),ArrowDown:bo("vert",1)});function bo(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,c=s.empty;if(s instanceof A){if(!o.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 Py(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 Ly(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 s=r.length-1;s>=0;s--)i=w.from(r[s].createAndFill(null,i));let o=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return o.setSelection(A.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function zy(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&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var qy=500;function gd({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,o){return md(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&md(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function md(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-qy),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a{let t=n.plugins;for(let r=0;r=0;c--)s.step(l.steps[c].invert(l.docs[c]));if(o.text){let c=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,n.schema.text(o.text,c))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},Hy=new bt(/--$/,"\u2014"),Jy=new bt(/\.\.\.$/,"\u2026"),Nx=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Ix=new bt(/"$/,"\u201D"),Rx=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),vx=new bt(/'$/,"\u2019");var wd=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function $y(n,e){let t={},r;function i(o,s){if(e){let l=e[o];if(l===!1)return;l&&(o=l)}t[o]=s}if(i("Mod-z",Xr),i("Shift-Mod-z",Qn),i("Backspace",yd),wd||i("Mod-y",Qn),i("Alt-ArrowUp",Wr),i("Alt-ArrowDown",sd),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",uo(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",uo(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Xn(r)),r=n.nodes.hard_break){let o=r,s=Yr(yl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(o.create()).scrollIntoView()),!0));i("Mod-Enter",s),i("Shift-Enter",s),wd&&i("Ctrl-Enter",s)}if((r=n.nodes.list_item)&&(i("Enter",bl(r)),i("Mod-[",xl(r)),i("Mod-]",Sl(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 o=1;o<=6;o++)i("Shift-Ctrl-"+o,pn(r,{level:o}));if(r=n.nodes.horizontal_rule){let o=r;i("Mod-_",(s,l)=>(l&&l(s.tr.replaceSelectionWith(o.create()).scrollIntoView()),!0))}return t}var Ol,Nl;if(typeof WeakMap<"u"){let n=new WeakMap;Ol=e=>n.get(e),Nl=(e,t)=>(n.set(e,t),t)}else{let n=[],t=0;Ol=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var _=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){(o||(o=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Se=i+N*e;for(let pe=0;per&&(o+=a.attrs.colspan)}}for(let s=0;s1&&(t=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function Ky(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(s)):null,i=Number(n.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let s in e){let l=e[s].getFromDOM,c=l&&l(n);c!=null&&(o[s]=c)}return o}function xd(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 Gy(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=>bd(r,e)}],toDOM(r){return["td",xd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>bd(r,e)}],toDOM(r){return["th",xd(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 Xy(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 Be(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 _l(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)||Qy(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Qy(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 Il(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Zy(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function Ul(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function Od(n,e,t){let r=n.node(-1),i=_.get(r),o=n.start(-1),s=i.nextCell(n.pos-o,e,t);return s==null?null:n.node(0).resolve(o+s)}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 Nd(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-o);c.unshift(t.pos-o);let a=c.map(h=>{let d=r.nodeAt(h);if(!d)throw RangeError(`No cell with offset ${h} found`);let f=o+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(Il(r)&&Il(i)&&Ul(r,i)){let o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?xt.rowSelection(r,i):o&&this.isColSelection()?xt.colSelection(r,i):new xt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=_.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];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=_.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),c=e.node(0);return s.top<=l.top?(s.top>0&&(e=c.resolve(o+i.map[s.left])),l.bottom0&&(t=c.resolve(o+i.map[l.left])),s.bottom0)return!1;let s=i+this.$anchorCell.nodeAfter.attrs.colspan,l=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,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=_.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),c=e.node(0);return s.left<=l.left?(s.left>0&&(e=c.resolve(o+i.map[s.top*i.width])),l.right0&&(t=c.resolve(o+i.map[l.top*i.width])),s.right{e.push(ne.node(r,r+t.nodeSize,{class:"selectedCell"}))}),z.create(n.doc,e)}function r0({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(o+1)>e.start(o));o--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function i0({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let o=n.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){t=o;break}}for(let i=e.depth;i>0;i--){let o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return t!==r&&e.parentOffset===0}function o0(n,e,t){let r=(e||n).selection,i=(e||n).doc,o,s;if(r instanceof C&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=B.create(i,r.from);else if(s=="row"){let l=i.resolve(r.from+1);o=B.rowSelection(l,l)}else if(!t){let l=_.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];o=B.create(i,c+1,a)}}else r instanceof A&&r0(r)?o=A.create(i,r.from):r instanceof A&&i0(r)&&(o=A.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=n.tr)).setSelection(o),e}var s0=new le("fix-tables");function Rd(n,e,t,r){let i=n.childCount,o=e.childCount;e:for(let s=0,l=0;s{i.type.spec.tableRole=="table"&&(t=l0(n,i,o,t))};return e?e.doc!=n.doc&&Rd(e.doc,n.doc,0,r):n.doc.descendants(r),t}function l0(n,e,t,r){let i=_.get(e);if(!i.problems)return r;r||(r=n.tr);let o=[];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;e0(e,r,i+o)&&(o=i==0||i==e.width?null:0);for(let s=0;s0&&i0&&e.map[l-1]==c||i0?-1:0;a0(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[o]==t[o-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function p0(n){return(e,t)=>{var r;let i=e.selection,o,s;if(i instanceof B){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;o=i.$anchorCell.nodeAfter,s=i.$anchorCell.pos}else{if(o=Xy(i.$from),!o)return!1;s=(r=Zn(i.$from))==null?void 0:r.pos}if(o==null||s==null||o.attrs.colspan==1&&o.attrs.rowspan==1)return!1;if(t){let l=o.attrs,c=[],a=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});let h=Pe(e),d=e.tr;for(let u=0;ui.table.nodeAt(c));for(let c=0;c{let p=u+o.tableStart,m=s.doc.nodeAt(p);m&&s.setNodeMarkup(p,f,m.attrs)}),r(s)}return!0}}var tS=Pl("row",{useDeprecatedLogic:!0}),nS=Pl("column",{useDeprecatedLogic:!0}),rS=Pl("cell",{useDeprecatedLogic:!0});function g0(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 o=n.node(-1).child(r),s=o.lastChild;if(s)return i-1-s.nodeSize;i-=o.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 xo(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((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function b0(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),o=i.type.spec.tableRole,s=i.type.schema,l=[];if(o=="row")for(let c=0;c=0;s--){let{rowspan:l,colspan:c}=o.child(s).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)}o.push(w.from(c))}t=o,e=i}return{width:n,height:e,rows:t}}function k0(n,e,t,r,i,o,s){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 o=t.selection;if(o instanceof B)return Co(t,r,S.near(o.$headCell,e));if(n!="horiz"&&!o.empty)return!1;let s=zd(i,n,e);if(s==null)return!1;if(n=="horiz")return Co(t,r,S.near(t.doc.resolve(o.head+e),e));{let l=t.doc.resolve(s),c=Od(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),Co(t,r,a)}}}function ko(n,e){return(t,r,i)=>{if(!i)return!1;let o=t.selection,s;if(o instanceof B)s=o;else{let c=zd(i,n,e);if(c==null)return!1;s=new B(t.doc.resolve(c))}let l=Od(s.$headCell,n,e);return l?Co(t,r,new B(s.$anchorCell,l)):!1}}function M0(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 A0(n,e,t){if(!Be(n.state))return!1;let r=b0(t),i=n.state.selection;if(i instanceof B){r||(r={width:1,height:1,rows:[w.from(Rl(de(n.state.schema).cell,t))]});let o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),l=_.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=S0(r,l.right-l.left,l.bottom-l.top),Ad(n.state,n.dispatch,s,l,r),!0}else if(r){let o=_l(n.state),s=o.start(-1);return Ad(n.state,n.dispatch,s,_.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function E0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Ed(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof B)o(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Zn(n.state.selection.$anchor))!=null&&((t=Dl(n,e))==null?void 0:t.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(c,a){let h=Dl(n,a),d=zt.getState(n.state)==null;if(!h||!Ul(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 s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),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(Ed(n,a.target)!=r&&(d=Dl(n,e),!d))return s();d&&o(d,a)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",l)}function zd(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 o=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.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 Ed(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Dl(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Zn(n.state.doc.resolve(t.pos)):null}var T0=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")),vl(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,vl(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function vl(n,e,t,r,i,o){var s;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 O0(-1,!1)},apply(o,s){return s.apply(o)}},props:{attributes:o=>{let s=Ve.getState(o);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,s)=>{N0(o,s,n,e,r)},mouseleave:o=>{I0(o)},mousedown:(o,s)=>{R0(o,s,e)}},decorations:o=>{let s=Ve.getState(o);if(s&&s.activeHandle>-1)return P0(o,s.activeHandle)},nodeViews:{}}});return i}var O0=class Mo{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 Mo(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Mo(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Il(e.doc.resolve(i))||(i=-1),new Mo(i,t.dragging)}return t}};function N0(n,e,t,r,i){let o=Ve.getState(n.state);if(o&&!o.dragging){let s=_0(e.target),l=-1;if(s){let{left:c,right:a}=s.getBoundingClientRect();e.clientX-c<=t?l=Td(n,e,"left",t):a-e.clientX<=t&&(l=Td(n,e,"right",t))}if(l!=o.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=_.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}Fd(n,l)}}}function I0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Fd(n,-1)}function R0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,o=Ve.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;let s=n.state.doc.nodeAt(o.activeHandle),l=v0(n,o.activeHandle,s.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&&(U0(n,d.activeHandle,Dd(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=Dd(d.dragging,h,t);V0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function v0(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let o=n.domAtPos(e),l=o.node.childNodes[o.offset].offsetWidth,c=t;if(r)for(let a=0;ajo,AbstractConnector:()=>fc,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:()=>pc,RelativePosition:()=>st,Skip:()=>ie,Snapshot:()=>jt,Text:()=>ct,Transaction:()=>Yo,UndoManager:()=>Tn,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>ot,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>at,XmlHook:()=>Si,XmlText:()=>xe,YArrayEvent:()=>Qo,YEvent:()=>Dn,YMapEvent:()=>Zo,YTextEvent:()=>es,YXmlEvent:()=>ts,applyUpdate:()=>Ac,applyUpdateV2:()=>vn,cleanupYTextFormatting:()=>Vu,compareIDs:()=>kn,compareRelativePositions:()=>rs,convertUpdateFormatV1ToV2:()=>u1,convertUpdateFormatV2ToV1:()=>bu,createAbsolutePositionFromRelativePosition:()=>Nc,createDeleteSet:()=>br,createDeleteSetFromStructStore:()=>kc,createDocFromSnapshot:()=>Qw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>Ci,createSnapshot:()=>Mi,decodeRelativePosition:()=>jw,decodeSnapshot:()=>Gw,decodeSnapshotV2:()=>su,decodeStateVector:()=>Tc,decodeUpdate:()=>s1,decodeUpdateV2:()=>uu,diffUpdate:()=>h1,diffUpdateV2:()=>Ic,emptySnapshot:()=>Xw,encodeRelativePosition:()=>$w,encodeSnapshot:()=>Yw,encodeSnapshotV2:()=>ou,encodeStateAsUpdate:()=>Ec,encodeStateAsUpdateV2:()=>nu,encodeStateVector:()=>Oc,encodeStateVectorFromUpdate:()=>l1,encodeStateVectorFromUpdateV2:()=>mu,equalDeleteSets:()=>eu,equalSnapshots:()=>Kw,findIndexSS:()=>qe,findRootTypeKey:()=>_n,getItem:()=>Cn,getState:()=>P,getTypeChildren:()=>y1,isDeleted:()=>Tt,isParentOf:()=>En,iterateDeletedStructs:()=>rt,logType:()=>Fw,logUpdate:()=>o1,logUpdateV2:()=>fu,mergeDeleteSets:()=>Mn,mergeUpdates:()=>pu,mergeUpdatesV2:()=>yi,obfuscateUpdate:()=>d1,obfuscateUpdateV2:()=>f1,parseUpdateMeta:()=>c1,parseUpdateMetaV2:()=>gu,readUpdate:()=>Bw,readUpdateV2:()=>Mc,relativePositionToJSON:()=>qw,snapshot:()=>Ai,snapshotContainsUpdate:()=>e1,transact:()=>R,tryGc:()=>r1,typeListToArraySnapshot:()=>cs,typeMapGetAllSnapshot:()=>Iu,typeMapGetSnapshot:()=>x1});var U=()=>new Map,Ao=n=>{let e=U();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},qd=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Hd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var Eo=n=>n[n.length-1];var Jd=(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)||U()).values()).forEach(r=>r(...t))}destroy(){this._observers=U()}},tr=class{constructor(){this._observers=U()}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)||U()).values()).forEach(r=>r(...t))}destroy(){this._observers=U()}};var fe=Math.floor;var nr=Math.abs;var De=(n,e)=>nn>e?n:e,fS=Number.isNaN,jd=Math.pow;var Do=n=>n!==0?n<0:1/n<0;var Ll=Number.MAX_SAFE_INTEGER,uS=Number.MIN_SAFE_INTEGER,pS=1<<31;var Kd=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&fe(n)===n),mS=Number.isNaN,gS=Number.parseInt;var zl=String.fromCharCode,yS=String.fromCodePoint,wS=zl(65535),z0=n=>n.toLowerCase(),F0=/^\s*/g,q0=n=>n.replace(F0,""),H0=/([A-Z])/g,Fl=(n,e)=>q0(n.replace(H0,t=>`${e}${z0(t)}`));var J0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;iir.encode(n),Gd=ir?$0:J0;var rr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});rr&&rr.decode(new Uint8Array).length===1&&(rr=null);var Xd=(n,e)=>Wd(e,()=>n).join("");var wn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},F=()=>new wn;var No=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(No(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=Do(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)},ql=new Uint8Array(3e4),j0=ql.length/3,K0=(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),o=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,o>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Le(t*2,o)),n.cbuf.set(e.subarray(i)),n.cpos=o)},V=(n,e)=>{x(n,e.byteLength),ar(n,e)},Hl=(n,e)=>{W0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},G0=(n,e)=>Hl(n,4).setFloat32(0,e,!1),X0=(n,e)=>Hl(n,8).setFloat64(0,e,!1),Q0=(n,e)=>Hl(n,8).setBigInt64(0,e,!1);var Zd=new DataView(new ArrayBuffer(4)),Z0=n=>(Zd.setFloat32(0,n),Zd.getFloat32(0)===n),sr=(n,e)=>{switch(typeof e){case"string":Q(n,119),Qe(n,e);break;case"number":Kd(e)&&nr(e)<=2147483647?(Q(n,125),ni(n,e)):Z0(e)?(Q(n,124),G0(n,e)):(Q(n,123),X0(n,e));break;case"bigint":Q(n,122),Q0(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 ef=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++:(ef(this),this.count=1,this.s=e)}toUint8Array(){return ef(this),I(this.encoder)}};var tf=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++):(tf(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return tf(this),I(this.encoder)}},Oo=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 rf=Ze("Unexpected end of array"),of=Ze("Integer out of Range"),hr=class{constructor(e){this.arr=e,this.pos=0}},q=n=>new hr(n),Jl=n=>n.pos!==n.arr.length;var ew=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>ew(n,k(n));var xn=n=>n.arr[n.pos++];var k=n=>{let e=0,t=1,r=n.arr.length;for(;n.posLl)throw of}throw rf},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 o=n.arr.length;for(;n.posLl)throw of}throw rf};var tw=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))}},nw=n=>rr.decode(K(n)),Fe=rr?nw:tw;var $l=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},rw=n=>$l(n,4).getFloat32(0,!1),iw=n=>$l(n,8).getFloat64(0,!1),ow=n=>$l(n,8).getBigInt64(0,!1);var sw=[n=>{},n=>null,ii,rw,iw,ow,n=>!1,n=>!0,Fe,n=>{let e=k(n),t={};for(let r=0;r{let e=k(n),t=[];for(let r=0;rsw[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),Jl(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=Do(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}},vo=class{constructor(e){this.decoder=new Sn(e),this.str=Fe(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 SS=crypto.subtle,sf=crypto.getRandomValues.bind(crypto);var lw=Math.random,Wl=()=>sf(new Uint32Array(1))[0];var lf=n=>n[fe(lw()*n.length)],cw="10000000-1000-4000-8000"+-1e11,cf=()=>cw.replace(/[018]/g,n=>(n^Wl()&15>>n/4).toString(16));var Ne=Date.now;var jl=n=>new Promise(n);var MS=Promise.all.bind(Promise);var Kl=n=>n===void 0?null:n;var Yl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},hf=new Yl,Gl=!0;try{typeof localStorage<"u"&&localStorage&&(hf=localStorage,Gl=!1)}catch{}var Uo=hf,df=n=>Gl||addEventListener("storage",n),ff=n=>Gl||removeEventListener("storage",n);var mf=Object.assign,Vo=Object.keys,gf=(n,e)=>{for(let t in n)e(n[t],t)},yf=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Xl=n=>Vo(n).length,pf=n=>Vo(n).length;var wf=n=>{for(let e in n)return!1;return!0},dw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Ql=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Zl=(n,e)=>n===e||pf(n)===pf(e)&&dw(n,(t,r)=>(t!==void 0||Ql(e,r))&&e[r]===t),fw=Object.freeze,ec=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&ec(n[e])}return fw(n)};var si=(n,e,t=0)=>{try{for(;tn,uw=(n,e)=>n===e;var ur=(n,e)=>{if(n==null||e==null)return uw(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,AS=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,et,pw=[],mw=()=>{if(et===void 0)if(kt){et=U();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");et.set(`--${Fl(e,"-")}`,t),et.set(`-${Fl(e,"-")}`,t)}})):et=U();return et},rc=n=>mw().has(n);var li=n=>kt?Kl(process.env[n.toUpperCase().replaceAll("-","_")]):Kl(Uo.getItem(n));var xf=n=>rc("--"+n)||li(n)!==null,ES=xf("production"),gw=kt&&bf(process.env.FORCE_COLOR,["true","1","2"]),Sf=gw||!rc("--no-colors")&&!xf("no-color")&&(!kt||process.stdout.isTTY)&&(!kt||rc("--color")||li("COLORTERM")!==null||(li("TERM")||"").includes("color"));var kf=n=>new Uint8Array(n),yw=(n,e,t)=>new Uint8Array(n,e,t),Cf=n=>new Uint8Array(n),ww=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),xw=n=>{let e=atob(n),t=kf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return yw(e.buffer,e.byteOffset,e.byteLength)},Mf=pr?ww:bw,Af=pr?xw:Sw;var Ef=n=>{let e=kf(n.byteLength);return e.set(n),e};var ic=class{constructor(e,t){this.left=e,this.right=t}},tt=(n,e)=>new ic(n,e);var Ct=typeof document<"u"?document:{};var TS=typeof DOMParser<"u"?new DOMParser:null;var Df=n=>qd(n,(e,t)=>`${t}:${e};`).join("");var DS=Ct.ELEMENT_NODE,OS=Ct.TEXT_NODE,NS=Ct.CDATA_SECTION_NODE,IS=Ct.COMMENT_NODE,RS=Ct.DOCUMENT_NODE,vS=Ct.DOCUMENT_TYPE_NODE,_S=Ct.DOCUMENT_FRAGMENT_NODE;var Po=n=>class{constructor(t){this._=t}destroy(){n(this._)}},Cw=Po(clearTimeout),ai=(n,e)=>new Cw(setTimeout(e,n)),VS=Po(clearInterval);var BS=Po(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var PS=Po(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var nt=Symbol;var hi=nt(),di=nt(),oc=nt(),sc=nt(),lc=nt(),fi=nt(),cc=nt(),mr=nt(),ac=nt(),If=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=U(),i=[],o=0;for(;o0||c.length>0?(e.push("%c"+s),t.push(c)):e.push(s)}else break}}for(o>0&&(i=t,i.unshift(e.join("")));o{console.log(...Rf(n)),vf.forEach(e=>e.print(n))},hc=(...n)=>{console.warn(...Rf(n)),n.unshift(mr),vf.forEach(e=>e.print(n))};var vf=Ce();var _f=n=>({[Symbol.iterator](){return this},next:n}),Uf=(n,e)=>_f(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),zo=(n,e)=>_f(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var fc=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 o=n.doc.store.clients.get(i);for(let s=0;s{let t=0,r=n.length-1;for(;t<=r;){let i=fe((t+r)/2),o=n[i],s=o.clock;if(s<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&Rw(t,e.clock)!==null},Sc=n=>{n.clients.forEach(e=>{e.sort((i,o)=>i.clock-o.clock);let t,r;for(t=1,r=1;t=o.clock?i.len=Le(i.len,o.clock+o.len-i.clock):(r{let e=new $t;for(let t=0;t{if(!e.clients.has(i)){let o=r.slice();for(let s=t+1;s{$(n.clients,e,()=>[]).push(new pi(t,r))},br=()=>new $t,kc=n=>{let e=br();return n.clients.forEach((t,r)=>{let i=[];for(let o=0;o0&&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 o=0;o{let e=new $t,t=k(n.restDecoder);for(let r=0;r0){let s=$(e.clients,i,()=>[]);for(let l=0;l{let r=new $t,i=k(n.restDecoder);for(let o=0;o0){let o=new Ie;return x(o.restEncoder,0),it(o,r),o.toUint8Array()}return null},eu=(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 o=0;o!0,meta:o=null,autoLoad:s=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=tu(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ko,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=s,this.meta=o,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 o=new t;return o._integrate(this,null),o}),i=r.constructor;if(t!==W&&i!==t)if(i===W){let o=new t;o._map=r._map,r._map.forEach(s=>{for(;s!==null;s=s.left)s.parent=o}),o._start=r._start;for(let s=o._start;s!==null;s=s.right)s.parent=o;return o._length=r._length,this.share.set(e,o),o._integrate(this,null),o}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 Fe(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 Ef(K(this.restDecoder))}readJSON(){return JSON.parse(Fe(this.restDecoder))}readKey(){return Fe(this.restDecoder)}},Wo=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 Wo{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 vo(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=Le(r,e[0].id.clock);let i=qe(e,r);x(n.restEncoder,e.length-i),n.writeClient(t),x(n.restEncoder,r);let o=e[i];o.write(n,r-o.id.clock);for(let s=i+1;s{let r=new Map;t.forEach((i,o)=>{P(e,o)>i&&r.set(o,i)}),Ei(e).forEach((i,o)=>{t.has(o)||r.set(o,0)}),x(n.restEncoder,r.size),$e(r.entries()).sort((i,o)=>o[0]-i[0]).forEach(([i,o])=>{vw(n,e.clients.get(i),i,o)})},_w=(n,e)=>{let t=U(),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 o=()=>{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},s=o();if(s===null)return null;let l=new Ko,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=s.refs[s.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(s!==null&&s.i0){let u=new Ie;return Cc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},Vw=(n,e)=>Cc(n,e.doc.store,e.beforeState),Mc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let o=!1,s=i.doc,l=s.store,c=_w(r,s),a=Uw(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=Pf(r,i,l);if(l.pendingDs){let f=new be(q(l.pendingDs));k(f.restDecoder);let u=Pf(f,i,l);d&&u?l.pendingDs=yi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(o){let f=l.pendingStructs.update;l.pendingStructs=null,vn(i.doc,f)}},t,!1),Bw=(n,e,t)=>Mc(n,e,t,new Me(n)),vn=(n,e,t,r=be)=>{let i=q(e);Mc(i,n,t,new r(i))},Ac=(n,e,t)=>vn(n,e,t,Me),Pw=(n,e,t=new Map)=>{Cc(n,e.store,t),it(n,kc(e.store))},nu=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Tc(e);Pw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Ic(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===ot)return pu(i.map((o,s)=>s===0?o:bu(o)));if(t.constructor===Ie)return yi(i)}return i[0]},Ec=(n,e)=>nu(n,e,new ot),ru=n=>{let e=new Map,t=k(n.restDecoder);for(let r=0;rru(new An(q(n))),Dc=(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),Lw=(n,e)=>Dc(n,Ei(e.store)),zw=(n,e=new gr)=>(n instanceof Map?Dc(e,n):Lw(e,n),e.toUint8Array()),Oc=n=>zw(n,new Wt),uc=class{constructor(){this.l=[]}},Lf=()=>new uc,zf=(n,e)=>n.l.push(e),Ff=(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.")},iu=(n,e,t)=>si(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),qf=(n,e)=>{x(n,e.client),x(n,e.clock)},Hf=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},Fw=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))},pc=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=(o,s)=>{let l=o.get("ds"),c=o.get("ids"),a=h=>this.clients.set(h,s);l.observe(h=>{h.changes.added.forEach(d=>{d.content.getContent().forEach(f=>{f instanceof Uint8Array&&this.dss.set(s,Mn([this.dss.get(s)||br(),At(new An(q(f)))]))})})}),this.dss.set(s,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(o=>{o.keysChanged.forEach(s=>i(t.get(s),s))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let o=this.yusers,s=o.get(r);s||(s=new Nn,s.set("ids",new On),s.set("ds",new On),o.set(r,s)),s.get("ids").push([t]),o.observe(l=>{setTimeout(()=>{let c=o.get(r);if(c!==s){s=c,this.clients.forEach((d,f)=>{r===d&&s.get("ids").push([f])});let a=new Wt,h=this.dss.get(r);h&&(it(a,h),s.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=s.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}},st=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},qw=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 st(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),jo=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},Hw=(n,e,t=0)=>new jo(n,e,t),Fo=(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 st(r,i,e,t)},Ci=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return Fo(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Fo(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Fo(n,r.lastId,t);r=r.right}return Fo(n,null,t)},Jw=(n,e)=>{let{type:t,tname:r,item:i,assoc:o}=e;if(i!==null)x(n,0),qf(n,i);else if(r!==null)cr(n,1),Qe(n,r);else if(t!==null)cr(n,2),qf(n,t);else throw j();return ni(n,o),n},$w=n=>{let e=F();return Jw(e,n),I(e)},Ww=n=>{let e=null,t=null,r=null;switch(k(n)){case 0:r=Hf(n);break;case 1:t=Fe(n);break;case 2:e=Hf(n)}let i=Jl(n)?ii(n):0;return new st(e,t,r,i)},jw=n=>Ww(q(n)),Nc=(n,e,t=!0)=>{let r=e.store,i=n.item,o=n.type,s=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(P(r,i.client)<=i.clock)return null;let h=t?bc(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(s!==null)c=e.get(s);else if(o!==null){if(P(r,o.client)<=o.clock)return null;let{item:h}=t?bc(r,o):{item:Cn(r,o)};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 Hw(c,a,n.assoc)},rs=(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}},Kw=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,o=e.sv;if(i.size!==o.size||t.size!==r.size)return!1;for(let[s,l]of i.entries())if(o.get(s)!==l)return!1;for(let[s,l]of t.entries()){let c=r.get(s)||[];if(l.length!==c.length)return!1;for(let a=0;a(it(e,n.ds),Dc(e,n.sv),e.toUint8Array()),Yw=n=>ou(n,new Wt),su=(n,e=new Wo(q(n)))=>new jt(At(e),ru(e)),Gw=n=>su(n,new An(q(n))),Mi=(n,e)=>new jt(n,e),Xw=Mi(br(),new Map),Ai=n=>Mi(kc(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),mc=(n,e)=>{let t=$(n.meta,mc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,o)=>{i{}),t.add(e))},Qw=(n,e,t=new We)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,o=new Ie;return n.transact(s=>{let l=0;r.forEach(c=>{c>0&&l++}),x(o.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 s=i.curr;s!==null;s=i.next())if((n.sv.get(s.id.client)||0)Zw(n,e,Me),Ko=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},lu=(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)},qe=(n,e)=>{let t=0,r=n.length-1,i=n[r],o=i.id.clock;if(o===e)return r;let s=fe(e/(o+i.length-1)*r);for(;t<=r;){if(i=n[s],o=i.id.clock,o<=e){if(e{let t=n.clients.get(e.client);return t[qe(t,e.clock)]},Cn=t1,gc=(n,e,t)=>{let r=qe(e,t),i=e[r];return i.id.clock{let t=n.doc.store.clients.get(e.client);return t[gc(n,t,e.clock)]},Jf=(n,e,t)=>{let r=e.clients.get(t.client),i=qe(r,t.clock),o=r[i];return t.clock!==o.id.clock+o.length-1&&o.constructor!==ue&&r.splice(i+1,0,ns(n,o,t.clock-o.id.clock+1)),o},n1=(n,e,t)=>{let r=n.clients.get(e.id.client);r[qe(r,e.id.clock)]=t},cu=(n,e,t,r,i)=>{if(r===0)return;let o=t+r,s=gc(n,e,t),l;do l=e[s++],oe.deleteSet.clients.size===0&&!Hd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(Sc(e.deleteSet),Vw(n,e),it(n,e.deleteSet),!0),Wf=(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)},Jo=(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 o=e-i;return o&&n.splice(e+1-o,o),o},au=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let o=e.clients.get(r);for(let s=i.length-1;s>=0;s--){let l=i[s],c=l.clock+l.len;for(let a=qe(o,l.clock),h=o[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let o=t.length-1;o>=0;o--){let s=t[o],l=De(i.length-1,1+qe(i,s.clock+s.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=s.clock;a=i[c])c-=1+Jo(i,c)}})},r1=(n,e,t)=>{au(n,e,t),hu(n,e)},du=(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),iu(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),si(l,[]),t._needFormattingCleanup&&M1(t)}finally{r.gc&&au(o,i,r.gcFilter),hu(o,i),t.afterState.forEach((h,d)=>{let f=t.beforeState.get(d)||0;if(f!==h){let u=i.clients.get(d),p=Le(qe(u,f),1);for(let m=u.length-1;m>=p;)m-=1+Jo(u,m)}});for(let h=s.length-1;h>=0;h--){let{client:d,clock:f}=s[h].id,u=i.clients.get(d),p=qe(u,f);p+11||p>0&&Jo(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(Lo(mr,hi,"[yjs] ",di,fi,"Changed the client-id because another client seems to be using it."),r.clientID=tu()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new ot;$f(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;$f(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])):du(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,o=!1,s=null;n._transaction===null&&(o=!0,n._transaction=new Yo(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{s=e(n._transaction)}finally{if(o){let l=n._transaction===i[0];n._transaction=null,l&&du(i,0)}}return s},yc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},jf=(n,e,t)=>{rt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>En(i,r))&&Vc(r,!1)})},Kf=(n,e,t)=>{let r=null,i=n.doc,o=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}=bc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&o.some(p=>En(p,u))&&d.push(u)}}),rt(l,a.deletions,u=>{u instanceof O&&o.some(p=>En(p,u))&&!Tt(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=Pu(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 s=n.currStackItem;if(s!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:s,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return s},Tn=class extends er{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:s=!1,doc:l=Zr(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,o.add(this),this.trackedOrigins=o,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=s,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 yc(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&&hc("[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=>jf(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>jf(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=Kf(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Kf(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*i1(n){let e=k(n.restDecoder);for(let t=0;tfu(n,Me),fu=(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);Lo("Structs: ",t);let o=At(r);Lo("DeleteSet: ",o)},s1=n=>uu(n,Me),uu=(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);return{structs:t,ds:At(r)}},gi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},pu=n=>yi(n,Me,ot),mu=(n,e=gr,t=be)=>{let r=new e,i=new lt(new t(q(n)),!1),o=i.curr;if(o!==null){let s=0,l=o.id.client,c=o.id.clock!==0,a=c?0:o.id.clock+o.length;for(;o!==null;o=i.next())l!==o.id.client&&(a!==0&&(s++,x(r.restEncoder,l),x(r.restEncoder,a)),l=o.id.client,a=0,c=o.id.clock!==0),o.constructor===ie&&(c=!0),c||(a=o.id.clock+o.length);a!==0&&(s++,x(r.restEncoder,l),x(r.restEncoder,a));let h=F();return x(h,s),nf(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},l1=n=>mu(n,Wt,Me),gu=(n,e=be)=>{let t=new Map,r=new Map,i=new lt(new e(q(n)),!1),o=i.curr;if(o!==null){let s=o.id.client,l=o.id.clock;for(t.set(s,l);o!==null;o=i.next())s!==o.id.client&&(r.set(s,l),t.set(o.id.client,o.id.clock),s=o.id.client),l=o.id.clock+o.length;r.set(s,l)}return{from:t,to:r}},c1=n=>gu(n,Me),a1=(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)),o=null,s=new t,l=new gi(s);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(o!==null){let f=h.curr,u=!1;for(;f!==null&&f.id.clock+f.length<=o.struct.id.clock+o.struct.length&&f.id.client>=o.struct.id.client;)f=h.next(),u=!0;if(f===null||f.id.client!==d||u&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(d!==o.struct.id.client)Ht(l,o.struct,o.offset),o={struct:f,offset:0},h.next();else if(o.struct.id.clock+o.struct.length0&&(o.struct.constructor===ie?o.struct.length-=p:f=a1(f,p)),o.struct.mergeWith(f)||(Ht(l,o.struct,o.offset),o={struct:f,offset:0},h.next())}}else o={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==ie;f=h.next())Ht(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(Ht(l,o.struct,o.offset),o=null),Rc(l);let c=r.map(h=>At(h)),a=Mn(c);return it(s,a),s.toUint8Array()},Ic=(n,e,t=be,r=Ie)=>{let i=Tc(e),o=new r,s=new gi(o),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(s,h,Le(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Ht(s,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=f;)c.next()}Rc(s);let a=At(l);return it(o,a),o.toUint8Array()},h1=(n,e)=>Ic(n,e,Me,ot),yu=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&&yu(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++},Rc=n=>{yu(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(q(n)),o=new lt(i,!1),s=new r,l=new gi(s);for(let a=o.curr;a!==null;a=o.next())Ht(l,e(a),0);Rc(l);let c=At(i);return it(s,c),s.toUint8Array()},wu=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=U(),o=U(),s=U(),l=U();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=$(o,d.nodeName,()=>"node-"+r)),d instanceof Si&&(d.hookName=$(o,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=$(s,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=Xd(r%10+"",d.str.length);break}default:j()}return a.parentSub&&(a.parentSub=$(i,a.parentSub,()=>r+"")),r++,c}default:j()}}},d1=(n,e)=>is(n,wu(e),Me,ot),f1=(n,e)=>is(n,wu(e),be,Ie),u1=n=>is(n,tc,Me,Ie),bu=n=>is(n,tc,be,ot),Yf="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=p1(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(Yf);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let o=t._map.get(i),s,l;if(this.adds(o)){let c=o.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(o))if(c!==null&&this.deletes(c))s="delete",l=Eo(c.content.getContent());else return;else c!==null&&this.deletes(c)?(s="update",l=Eo(c.content.getContent())):(s="add",l=void 0)}else if(this.deletes(o))s="delete",l=Eo(o.content.getContent());else return;e.set(i,{action:s,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(Yf);let t=this.target,r=Ce(),i=Ce(),o=[];if(e={added:r,deleted:i,delta:o,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&o.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}},p1=(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},oe=()=>{hc("Invalid access: Add Yjs type to a document before reading data.")},xu=80,vc=0,wc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=vc++}},m1=n=>{n.timestamp=vc++},Su=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=vc++},g1=(n,e,t)=>{if(n.length>=xu){let r=n.reduce((i,o)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((o,s)=>nr(e-o.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 o=i.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(i.index-=o.length);if(o===null||o.marker===!0){n.splice(r,1);continue}i.p=o,o.marker=!0}(e0&&e===i.index)&&(i.index=Le(e,i.index+t))}},y1=n=>{n.doc??oe();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},ls=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;iu(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=Lf(),this._dEH=Lf(),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){zf(this._eH,e)}observeDeep(e){zf(this._dEH,e)}unobserve(e){Ff(this._eH,e)}unobserveDeep(e){Ff(this._dEH,e)}toJSON(){}},ku=(n,e,t)=>{n.doc??oe(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],o=n._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){let s=o.content.getContent();if(s.length<=e)e-=s.length;else{for(let l=e;l0;l++)i.push(s[l]),r--;e=0}}o=o.right}return i},Cu=n=>{n.doc??oe();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 o=0;o{let t=0,r=n._start;for(n.doc??oe();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let o=0;o{let t=[];return bi(n,(r,i)=>{t.push(e(r,i,n))}),t},w1=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}}}},Au=(n,e)=>{n.doc??oe();let t=ss(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,o=n.doc,s=o.clientID,l=o.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(s,P(l,s)),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(s,P(l,s)),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(s,P(l,s)),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(s,P(l,s)),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()},Eu=()=>Ze("Length exceeded!"),Tu=(n,e,t,r)=>{if(t>e._length)throw Eu();if(t===0)return e._searchMarker&&wi(e._searchMarker,t,r.length),Go(n,e,null,r);let i=t,o=ss(e,t),s=e._start;for(o!==null&&(s=o.p,t-=o.index,t===0&&(s=s.prev,t+=s&&s.countable&&!s.deleted?s.length:0));s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<=s.length){t{let i=(e._searchMarker||[]).reduce((o,s)=>s.index>o.index?s:o,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Go(n,e,i,t)},Du=(n,e,t,r)=>{if(r===0)return;let i=t,o=r,s=ss(e,t),l=e._start;for(s!==null&&(l=s.p,t-=s.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw Eu();e._searchMarker&&wi(e._searchMarker,i,-o+r)},Xo=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},_c=(n,e,t,r)=>{let i=e._map.get(t)||null,o=n.doc,s=o.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(s,P(o.store,s)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},Uc=(n,e)=>{n.doc??oe();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Ou=n=>{let e={};return n.doc??oe(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Nu=(n,e)=>{n.doc??oe();let t=n._map.get(e);return t!==void 0&&!t.deleted},x1=(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},Iu=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let o=r;for(;o!==null&&(!e.sv.has(o.id.client)||o.id.clock>=(e.sv.get(o.id.client)||0));)o=o.left;o!==null&&qt(o,e)&&(t[i]=o.content.getContent()[o.length-1])}),t},qo=n=>(n.doc??oe(),Uf(n._map.entries(),e=>!e[1].deleted)),Qo=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??oe(),this._length}_callObserver(e,t){super._callObserver(e,t),ls(this,e,new Qo(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{Tu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{b1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Du(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return Au(this,e)}toArray(){return Cu(this)}slice(e=0,t=this.length){return ku(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return Mu(this,e)}forEach(e){bi(this,e)}[Symbol.iterator](){return w1(this)}_write(e){e.writeTypeRef(F1)}},S1=n=>new On,Zo=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){ls(this,e,new Zo(this,e,t))}toJSON(){this.doc??oe();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[...qo(this)].length}keys(){return zo(qo(this),e=>e[0])}values(){return zo(qo(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return zo(qo(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??oe(),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=>{Xo(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{_c(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Uc(this,e)}has(e){return Nu(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){Xo(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(q1)}},k1=n=>new Nn,Jt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Zl(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}},Gf=(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,o=r?ss(e,t):null;if(o){let s=new xi(o.p.left,o.p,o.index,i);return Gf(n,s,t-o.index)}else{let s=new xi(null,e._start,0,i);return Gf(n,s,t)}},Ru=(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,o=i.clientID;r.forEach((s,l)=>{let c=t.left,a=t.right,h=new O(M(o,P(i.store,o)),c,c&&c.lastId,a,a&&a.id,e,null,new L(l,s));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)},vu=(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()}},_u=(n,e,t,r)=>{let i=n.doc,o=i.clientID,s=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Jt(a,c)){s.set(l,a);let{left:h,right:d}=t;t.right=new O(M(o,P(i.store,o)),h,h&&h.lastId,d,d&&d.id,e,null,new L(l,c)),t.right.integrate(n,0),t.forward()}}return s},dc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let o=n.doc,s=o.clientID;vu(t,i);let l=_u(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(s,P(o.store,s)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=d,t.forward(),Ru(n,e,t,l)},Xf=(n,e,t,r,i)=>{let o=n.doc,s=o.clientID;vu(t,i);let l=_u(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(s,P(o.store,s)),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()}Ru(n,e,t,l)},Uu=(n,e,t,r,i)=>{let o=e,s=U();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===L){let a=o.content;s.set(a.key,a)}o=o.right}let l=0,c=!1;for(;e!==o;){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;(s.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},C1=(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}},Vu=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,o=U(),s=Ao(o);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case L:xr(s,i.content);break;default:e+=Uu(t,r,i,o,s),o=Ao(s),r=i;break}i=i.right}}),e},M1=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let o=n.beforeState.get(r)||0;i!==o&&cu(n,t.store.clients.get(r),o,i,s=>{!s.deleted&&s.content.constructor===L&&s.constructor!==ue&&e.add(s.parent)})}R(t,r=>{rt(n,n.deleteSet,i=>{if(i instanceof ue||!i.parent._hasFormatting||e.has(i.parent))return;let o=i.parent;i.content.constructor===L?e.add(o):C1(r,i)});for(let i of e)Vu(i)})},Qf=(n,e,t)=>{let r=t,i=Ao(e.currentAttributes),o=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,o=new Map,s=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},wf(c)||(u.attributes=mf({},c))),h=0;break}u&&t.push(u),l=null}};for(;s!==null;){switch(s.content.constructor){case Ae:case Et:this.adds(s)?this.deletes(s)||(f(),l="insert",a=s.content.getContent()[0],f()):this.deletes(s)?(l!=="delete"&&(f(),l="delete"),d+=1):s.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case Re:this.adds(s)?this.deletes(s)||(l!=="insert"&&(f(),l="insert"),a+=s.content.str):this.deletes(s)?(l!=="delete"&&(f(),l="delete"),d+=s.length):s.deleted||(l!=="retain"&&(f(),l="retain"),h+=s.length);break;case L:{let{key:u,value:p}=s.content;if(this.adds(s)){if(!this.deletes(s)){let m=i.get(u)??null;Jt(m,p)?p!==null&&s.delete(r):(l==="retain"&&f(),Jt(p,o.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(s)){o.set(u,p);let m=i.get(u)??null;Jt(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!s.deleted){o.set(u,p);let m=c[u];m!==void 0&&(Jt(m,p)?m!==null&&s.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}s.deleted||(l==="insert"&&f(),xr(i,s.content));break}}s=s.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??oe(),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 es(this,e,t);ls(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??oe();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 o=0;o0)&&dc(r,this,i,l,s.attributes||{})}else s.retain!==void 0?Xf(r,this,i,s.retain,s.attributes||{}):s.delete!==void 0&&Qf(r,i,s.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??oe();let i=[],o=new Map,s=this.doc,l="",c=this._start;function a(){if(l.length>0){let d={},f=!1;o.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=o.get("ychange");e!==void 0&&!qt(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),o.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(),o.set("ychange",r?r("added",c.id):{type:"added"})):d!==void 0&&(a(),o.delete("ychange")),l+=c.content.str;break}case Ae:case Et:{a();let d={insert:c.content.getContent()[0]};if(o.size>0){let f={};d.attributes=f,o.forEach((u,p)=>{f[p]=u})}i.push(d);break}case L:qt(c,e)&&(a(),xr(o,c.content));break}c=c.right}a()};return e||t?R(s,d=>{e&&mc(d,e),t&&mc(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,o=>{let s=Ho(o,this,e,!r);r||(r={},s.currentAttributes.forEach((l,c)=>{r[c]=l})),dc(o,this,s,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,o=>{let s=Ho(o,this,e,!r);dc(o,this,s,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=>{Qf(i,Ho(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,o=>{let s=Ho(o,this,e,!1);s.right!==null&&Xf(o,this,s,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xo(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{_c(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Uc(this,e)}getAttributes(){return Ou(this)}_write(e){e.writeTypeRef(H1)}},A1=n=>new ct,ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??oe()}[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??oe(),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){ls(this,e,new ts(this,t,e))}toString(){return Mu(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,o=>{i.insertBefore(o.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{Tu(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;Go(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(o=>o===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=>{Du(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return Cu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Au(this,e)}slice(e=0,t=this.length){return ku(this,e,t)}forEach(e){bi(this,e)}_write(e){e.writeTypeRef($1)}},E1=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 gf(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`<${o}${s}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xo(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{_c(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Uc(this,e)}hasAttribute(e){return Nu(this,e)}getAttributes(e){return e?Iu(this,e):Ou(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),o=this.getAttributes();for(let s in o){let l=o[s];typeof l=="string"&&i.setAttribute(s,l)}return bi(this,s=>{i.appendChild(s.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(J1),e.writeKey(this.nodeName)}},T1=n=>new Z(n.readKey()),ts=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],o;return i!==void 0?o=i.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(e){e.writeTypeRef(W1),e.writeKey(this.hookName)}},D1=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 o=[];for(let s in e.attributes[i])o.push({key:s,value:e.attributes[i][s]});o.sort((s,l)=>s.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(j1)}},O1=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()}},N1=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),lu(e.doc.store,this)}write(e,t){e.writeInfo(N1),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}},I1=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}},R1=n=>new wr(n.readLen()),Bu=(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(Bu(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}},v1=n=>new Rn(Bu(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}},_1=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}},U1=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}},L1=n=>new Re(n.readString()),z1=[S1,k1,A1,T1,E1,D1,O1],F1=0,q1=1,H1=2,J1=3,$1=4,W1=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}},K1=n=>new Ae(z1[n.readTypeRef()](n)),bc=(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},ns=(n,e,t)=>{let{client:r,clock:i}=e.id,o=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&&o.markDeleted(),e.keep&&(o.keep=!0),e.redone!==null&&(o.redone=M(e.redone.client,e.redone.clock+t)),e.right=o,o.right!==null&&(o.right.left=o),n._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),e.length=t,o},Zf=(n,e)=>$d(n,t=>Tt(t.deletions,e)),Pu=(n,e,t,r,i,o)=>{let s=n.doc,l=s.store,c=s.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)||Pu(n,h,t,r,i,o)===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)||Zf(o.undoStack,d.right.id)||Zf(o.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,o,s,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=o,this.parent=s,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=Jf(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=Jf(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 o=new Set,s=new Set;for(;i!==null&&i!==this.right;){if(s.add(i),o.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),Wf(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?n1(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,o=this.parentSub,s=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(o===null?0:32);if(e.writeInfo(s),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();o!==null&&e.writeString(o)}this.content.write(e,t)}},Lu=(n,e)=>Y1[e&31](n),Y1=[()=>{j()},R1,V1,I1,L1,_1,U1,K1,P1,v1,()=>{j()}],G1=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(G1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},zu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Fu="__ $YJS$ __";zu[Fu]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");zu[Fu]=!0;var qu=new Map,Bc=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:Af(t.newValue||"")}),df(this._onChange)}postMessage(e){Uo.setItem(this.room,Mf(Cf(e)))}close(){ff(this._onChange)}},X1=typeof BroadcastChannel>"u"?Bc:BroadcastChannel,Pc=n=>$(qu,n,()=>{let e=Ce(),t=new X1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Hu=(n,e)=>(Pc(n).subs.add(e),e),Ju=(n,e)=>{let t=Pc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),qu.delete(n)),r},Vn=(n,e,t=null)=>{let r=Pc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var $u=0,as=1,Wu=2,hs=(n,e)=>{x(n,$u);let t=Oc(e);V(n,t)},Lc=(n,e,t)=>{x(n,as),V(n,Ec(e,t))},Z1=(n,e,t)=>Lc(e,t,K(n)),ju=(n,e,t)=>{try{Ac(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},Ku=(n,e)=>{x(n,Wu),V(n,e)},eb=ju,Yu=(n,e,t,r)=>{let i=k(n);switch(i){case $u:Z1(n,e,t);break;case as:ju(n,t,r);break;case Wu:eb(n,t,r);break;default:throw new Error("Unknown message type")}return i};var nb=0;var Gu=(n,e,t)=>{switch(k(n)){case nb:t(e,Fe(n))}};var zc=3e4,ds=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&&zc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,o)=>{o!==this.clientID&&zc<=t-i.lastUpdated&&this.states.has(o)&&r.push(o)}),r.length>0&&fs(this,r,"timeout")},fe(zc/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,o=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Ne()});let s=[],l=[],c=[],a=[];e===null?a.push(t):o==null?e!=null&&s.push(t):(l.push(t),ur(o,e)||c.push(t)),(s.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:s,updated:c,removed:a},"local"]),this.emit("update",[{added:s,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},fs=(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 o=0;o{let r=q(e),i=Ne(),o=[],s=[],l=[],c=[],a=k(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:o,updated:l,removed:c},t]),(o.length>0||s.length>0||c.length>0)&&n.emit("update",[{added:o,updated:s,removed:c},t])};var Qu=n=>yf(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,ep=3,Cr=1,sb=2,Ti=[];Ti[Bn]=(n,e,t,r,i)=>{x(n,Bn);let o=Yu(e,n,t.doc,t);r&&o===as&&!t.synced&&(t.synced=!0)};Ti[ep]=(n,e,t,r,i)=>{x(n,Cr),V(n,kr(t.awareness,Array.from(t.awareness.getStates().keys())))};Ti[Cr]=(n,e,t,r,i)=>{Xu(t.awareness,K(e),t)};Ti[sb]=(n,e,t,r,i)=>{Gu(e,t.doc,(o,s)=>lb(t,s))};var Zu=3e4,lb=(n,e)=>console.warn(`Permission denied to access ${n.url}. +${e}`),tp=(n,e,t)=>{let r=q(e),i=F(),o=k(r),s=n.messageHandlers[o];return s?s(i,r,n,t,o):console.error("Unable to compute message"),i},np=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=tp(n,new Uint8Array(t.data),!0);No(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,fs(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(np,De(jd(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),hs(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=F();x(r,Cr),V(r,kr(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},Fc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},qc=class extends tr{constructor(e,t,r,{connect:i=!0,awareness:o=new ds(r),params:s={},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=s,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=o,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),hs(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=tp(this,new Uint8Array(f),!1);No(p)>1&&Vn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=F();x(p,Bn),Ku(p,f),Fc(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),V(y,kr(o,g)),Fc(this,I(y))},this._exitHandler=()=>{fs(this.awareness,[r.clientID],"app closed")},kt&&typeof process<"u"&&process.on("exit",this._exitHandler),o.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Zu{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var cb=/[\uD800-\uDBFF]/,ab=/[\uDC00-\uDFFF]/,hb=(n,e)=>{let t=0,r=0;for(;t0&&cb.test(n[t-1])&&t--;r+t0&&ab.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},ip=hb;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),db=[{light:"#ecd44433",dark:"#ecd444"}],fb=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,lf(e))}return n.get(t)},lp=(n,{colors:e=db,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:o}={})=>{let s=!1,l=new us(n,o),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),o==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(s||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(s=!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},ub=(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)}),us=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=rp(),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(),o=Ct.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||o.clientWidth||0)&&i.top<=(window.innerHeight||o.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(o=>{let s=r.permanentUserData;s&&s.dss.forEach(h=>{rt(o,h,d=>{})});let l=(h,d)=>{let f=h==="added"?s.getUserByClientId(d.client):s.getUserByDeletedId(d);return{user:f,type:h,color:fb(r.colorMapping,r.colors,f)}},c=cs(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 o=this.type.toArray().map(l=>cp(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),s=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(o),0,0));ub(s,this.beforeTransactionSelection,this),s=s.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Tn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&s.scrollIntoView(),this.prosemirrorView.dispatch(s)})}_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))}},cp=(n,e,t,r,i,o)=>{let s=t.get(n);if(s===void 0){if(n instanceof Z)return Oi(n,e,t,r,i,o);throw Oe()}return s},Oi=(n,e,t,r,i,o)=>{let s=[],l=c=>{if(c.constructor===Z){let a=cp(c,e,t,r,i,o);a!==null&&s.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=pb(c,e,t,r,i,o);h!==null&&h.forEach(d=>{d!==null&&s.push(d)})}};r===void 0||i===void 0?n.toArray().forEach(l):cs(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=o?o("added",n._item.id):{type:"added"}):c.ychange=o?o("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,s);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},pb=(n,e,t,r,i,o)=>{let s=[],l=n.toDelta(r,i,o);try{for(let c=0;c{n._item.delete(a)},v),null}return s},mb=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:hp(i.marks)}));return t.applyDelta(r),e.set(t,n),t},gb=(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,ms(n).map(r=>Hc(r,e))),e.set(t,n),t},Hc=(n,e)=>n instanceof Array?mb(n,e):gb(n,e),op=n=>typeof n=="object"&&n!==null,$c=(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&&Vo(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(o=>$c(r.attributes[o.type.name]||{},o.attrs)))},Ri=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Jc(n,e)){let t=ms(e);return n._length===t.length&&$c(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Ri(r,t[i]))}return n instanceof xe&&e instanceof Array&&ap(n,e)},ps=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),sp=(n,e,t)=>{let r=n.toArray(),i=ms(e),o=i.length,s=r.length,l=De(s,o),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}},wb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=yb(n),o=e.map(a=>({insert:a.text,attributes:Object.assign({},r,hp(a.marks))})),{insert:s,remove:l,index:c}=ip(i,o.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,s),n.applyDelta(o.map(a=>({retain:a.insert.length,attributes:a.attributes})))},hp=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=ms(t),o=i.length,s=e.toArray(),l=s.length,c=De(o,l),a=0,h=0;for(;a{for(;l-a-h>0&&o-a-h>0;){let f=s[a],u=i[a],p=s[l-h-1],m=i[o-h-1];if(f instanceof xe&&u instanceof Array)ap(f,u)||wb(f,u,r),a+=1;else{let g=f instanceof Z&&Jc(f,u),y=p instanceof Z&&Jc(p,m);if(g&&y){let E=sp(f,u,r),N=sp(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,bb=()=>{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((o,s)=>{r.setMeta(s,o)}),t.dispatch(r))})},Wc=(n,e,t)=>{vi||(vi=new Map,ai(0,bb)),$(vi,n,U).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 st(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 st(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 xb(r._item.parent,r._item)}return Ci(e,e._length,-1)},xb=(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 st(t,r,e.id)},Yt=(n,e,t,r)=>{let i=Nc(t,n);if(i===null||i.type!==e&&!En(e,i.type._item))return null;let o=i.type,s=0;if(o.constructor===xe)s=i.index;else if(o._item===null||!o._item.deleted){let l=o._first,c=0;for(;ci(void 0)};return Mr(r,t,n,new Map),t}function fp(n,e="prosemirror"){return Kc(n.getXmlFragment(e))}function Kc(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(s=>{let l={type:"text",text:s.insert};return s.attributes&&(l.marks=Object.keys(s.attributes).map(c=>{let a=s.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let o=r.getAttributes();Object.keys(o).length&&(i.attrs=o);let s=r.toArray();s.length&&(i.content=s.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var Sb=(n,e,t)=>n!==e,kb=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},Cb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Mb=/^#[0-9a-fA-F]{6}$/,up=(n,e,t,r,i)=>{let o=v.getState(n),s=o.doc,l=[];return o.snapshot!=null||o.prevSnapshot!=null||o.binding.mapping.size===0?z.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(s.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Mb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Yt(s,o.type,Un(c.cursor.anchor),o.binding.mapping),f=Yt(s,o.type,Un(c.cursor.head),o.binding.mapping);if(d!==null&&f!==null){let u=Le(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=Le(d,f);l.push(ne.inline(p,m,i(h),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),z.create(n.doc,l))},Ab=(n,{awarenessStateFilter:e=Sb,cursorBuilder:t=kb,selectionBuilder:r=Cb,getSelection:i=s=>s.selection}={},o="cursor")=>new H({key:Di,state:{init(s,l){return up(l,n,e,t,r)},apply(s,l,c,a){let h=v.getState(a),d=s.getMeta(Di);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?up(a,n,e,t,r):l.map(s.mapping,s.doc)}},props:{decorations:s=>Di.getState(s)},view:s=>{let l=()=>{s.docView&&Wc(s,Di,{awarenessUpdated:!0})},c=()=>{let a=v.getState(s.state),h=n.getLocalState()||{};if(s.hasFocus()){let d=i(s.state),f=Pn(d.anchor,a.type,a.binding.mapping),u=Pn(d.head,a.type,a.binding.mapping);(h.cursor==null||!rs(Un(h.cursor.anchor),f)||!rs(Un(h.cursor.head),u))&&n.setLocalStateField(o,{anchor:f,head:u})}else h.cursor!=null&&Yt(a.doc,a.type,Un(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(o,null)};return n.on("change",l),s.dom.addEventListener("focusin",c),s.dom.addEventListener("focusout",c),{update:c,destroy:()=>{s.dom.removeEventListener("focusin",c),s.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(o,null)}}}});var Eb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.undo(),!0},Tb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.redo(),!0},Db=new Set(["paragraph"]),Ob=(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,Nb=({protectedNodes:n=Db,trackedOrigins:e=[],undoManager:t=null}={})=>new H({key:Dt,state:{init:(r,i)=>{let o=v.getState(i),s=t||new Tn(o.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Ob(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:s,prevSel:null,hasUndoOps:s.undoStack.length>0,hasRedoOps:s.redoStack.length>0}},apply:(r,i,o,s)=>{let l=v.getState(s).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ii(l,o),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),o=Dt.getState(r.state).undoManager;return o.on("stack-item-added",({stackItem:s})=>{let l=i.binding;l&&s.meta.set(l,Dt.getState(r.state).prevSel)}),o.on("stack-item-popped",({stackItem:s})=>{let l=i.binding;l&&(l.beforeTransactionSelection=s.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{o.destroy()}}}});var _i="http://www.w3.org/2000/svg",Ib="http://www.w3.org/1999/xlink",Gc="ProseMirror-icon",Yc="pm-close-dropdowns";function Rb(n){let e=0;for(let t=0;t{o.preventDefault(),r.classList.contains(je+"-disabled")||t.run(e.state,e.dispatch,e,o)});function i(o){if(t.select){let l=t.select(o);if(r.style.display=l?"":"none",!l)return!1}let s=!0;if(t.enable&&(s=t.enable(o)||!1,pp(r,je+"-disabled",!s)),t.active){let l=s&&t.active(o)||!1;pp(r,je+"-active",l)}return!0}return{dom:r,update:i}}};function gs(n,e){return n._props.translate?n._props.translate(e):e}var Ui={time:0,node:null};function Ub(n){Ui.time=Date.now(),Ui.node=n.target}function Vb(n){return Date.now()-100{s&&s.close()&&(s=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(Yc,c))};i.addEventListener("mousedown",d=>{d.preventDefault(),Ub(d),s?a():(r.dispatchEvent(new CustomEvent(Yc)),s=this.expand(o,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{Vb(o)||a()}),r.addEventListener(Yc,c=()=>{a()}))});function h(d){let f=t.update(d);return o.style.display=f?"":"none",f}return{dom:o,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 o=wt("div",{class:je+"-dropdown-menu "+(this.options.class||"")},r,i),s=!1;function l(){return s?!1:(s=!0,e.removeChild(o),!0)}return e.appendChild(o),{close:l,node:o}}};function Bb(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iWr(n),icon:Vi.join}),Lk=new ht({title:"Lift out of enclosing block",run:jr,select:n=>jr(n),icon:Vi.lift}),zk=new ht({title:"Select parent node",run:Kr,select:n=>Kr(n),icon:Vi.selectParentNode}),Fk=new ht({title:"Undo last change",run:Xr,enable:n=>Xr(n),icon:Vi.undo}),qk=new ht({title:"Redo last undone change",run:Qn,enable:n=>Qn(n),icon:Vi.redo});function zb(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 Fb(n,e){let t=pn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:o,to:s,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):s<=o.end()&&o.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new ht(r)}function pp(n,e,t){t?n.classList.add(e):n.classList.remove(e)}function gp(n,e,t){let r=t.child(0),o=_.get(t).width;if(r.childCount===1&&r.child(0).attrs.colspan===o)return n;if(r.childCount>1){let s=[],l=null;r.forEach((m,g,y)=>{y===0&&(l=e+1),m.textContent&&s.push(m.textContent)});let c=s[0]||"columns",a=r.child(0).type,h=n.doc.type.schema.nodes.paragraph.create(null,n.doc.type.schema.text(c)),d=a.create({colspan:o,rowspan:1},h),u=n.doc.type.schema.nodes.table_row.create(null,d),p=l+r.nodeSize-1;n.replaceWith(l,p,u)}else if(r.childCount===1){let s=e+1,l=r.child(0);n.setNodeMarkup(s,null,{...l.attrs,colspan:o,rowspan:1})}return n}function yp(n){for(let e=n.depth;e>0;e-=1){let t=n.node(e);if(t.type.name==="table"){let r=n.start(e)-1;return{table:t,tableStart:r,depth:e}}}return null}function ys(n){return Be(n)?Pe(n).top===0:!1}function iC(n,e){if(!e)return Vl(n,e);let t=n.selection.$from.pos;return Vl(n,i=>{try{let o=i.doc.resolve(t),s=yp(o);if(s){let l=i.doc.nodeAt(s.tableStart);l&&gp(i,s.tableStart,l)}}catch(o){console.warn("Could not fix header row colspan:",o)}e(i)})}function oC(n,e){if(!e)return Bl(n,e);let t=n.selection.$from.pos;return Bl(n,i=>{try{let o=i.doc.resolve(t),s=yp(o);if(s){let l=i.doc.nodeAt(s.tableStart);l&&gp(i,s.tableStart,l)}}catch(o){console.warn("Could not fix header row colspan:",o)}e(i)})}function sC(n,e){return ys(n)?!1:Bd(n,e)}function lC(n,e){return ys(n)?!1:Ld(n,e)}function cC(n,e){return ys(n)?!1:Pd(n,e)}function aC(n,e){return ys(n)?!1:Ud(n,e)}export{zn as DOMParser,It as DOMSerializer,Xc as Dropdown,Ps as EditorState,ll 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,qc as WebsocketProvider,Sr as Y,oC as addColumnAfter,iC as addColumnBefore,wy as addListNodes,h0 as addRowAfter,sC as addRowBefore,hd as baseKeymap,jg as baseSchema,Fb as blockTypeItem,$y as buildKeymap,D0 as columnResizing,aC as deleteColumn,cC as deleteRow,w0 as deleteTable,vd as fixTables,Vy as gapCursor,y0 as goToNextCell,gd as inputRules,Be as isInTable,Ty as keymap,xl as liftListItem,u0 as mergeCells,dp as prosemirrorToYDoc,jc as prosemirrorToYXmlFragment,Pb as renderGrouped,Pe as selectedRect,pn as setBlockType,Sl as sinkListItem,lC as splitCell,bl as splitListItem,L0 as tableEditing,Gy as tableNodes,mn as toggleMark,Xn as wrapIn,uo as wrapInList,zb as wrapItem,Ab as yCursorPlugin,fp as yDocToProsemirrorJSON,Tb as yRedo,lp as ySyncPlugin,Eb as yUndo,Nb as yUndoPlugin,Dt as yUndoPluginKey,Kc as yXmlFragmentToProsemirrorJSON}; diff --git a/deps/da-y-wrapper/src/index.js b/deps/da-y-wrapper/src/index.js index e50cf962..c223fc75 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 @@ -48,6 +49,182 @@ import { MenuItem, Dropdown, renderGrouped, blockTypeItem, wrapItem } from '../. import { InputRule, inputRules } from 'prosemirror-inputrules'; +/** + * Fix the block header to ensure it maintains a single cell with full colspan. + */ +function fixHeaderRowColspan(tr, tableStart, table) { + const firstRow = table.child(0); + const map = TableMap.get(table); + const totalCols = map.width; + + if (firstRow.childCount === 1 && firstRow.child(0).attrs.colspan === totalCols) { + return tr; + } + + if (firstRow.childCount > 1) { + const contents = []; + let firstCellPos = null; + + firstRow.forEach((cell, offset, index) => { + if (index === 0) { + firstCellPos = tableStart + 1; + } + + if (cell.textContent) { + contents.push(cell.textContent); + } + }); + + const blockName = contents[0] || 'columns'; + + // Create a new cell with the correct colspan + const cellType = firstRow.child(0).type; + const para = tr.doc.type.schema.nodes.paragraph.create( + null, + tr.doc.type.schema.text(blockName), + ); + const newCell = cellType.create( + { colspan: totalCols, rowspan: 1 }, + para, + ); + + // Create new row with single merged cell + const rowType = tr.doc.type.schema.nodes.table_row; + const newRow = rowType.create(null, newCell); + + // Replace the entire first row + const firstRowEnd = firstCellPos + firstRow.nodeSize - 1; + tr.replaceWith(firstCellPos, firstRowEnd, newRow); + } else if (firstRow.childCount === 1) { + const cellPos = tableStart + 1; + const cell = firstRow.child(0); + tr.setNodeMarkup(cellPos, null, { + ...cell.attrs, + colspan: totalCols, + rowspan: 1, + }); + } + + return tr; +} + +/** + * Find the table node that contains a resolved position + */ +function findTableFromPos($pos) { + for (let d = $pos.depth; d > 0; d -= 1) { + const node = $pos.node(d); + if (node.type.name === 'table') { + const tableStart = $pos.start(d) - 1; // Position before the table + return { table: node, tableStart, depth: d }; + } + } + return null; +} + +/** + * Check if the current selection is in the table header row (first row). + */ +function isInTableHeader(state) { + if (!isInTable(state)) { + return false; + } + + const rect = selectedRect(state); + return rect.top === 0; +} + +// ensures header row maintains its colspan when adding columns +function addColumnBeforeWrapper(state, dispatch) { + if (!dispatch) { + return addColumnBefore(state, dispatch); + } + + const originalPos = state.selection.$from.pos; + + const result = addColumnBefore(state, (tr) => { + try { + const $pos = tr.doc.resolve(originalPos); + const tableInfo = findTableFromPos($pos); + if (tableInfo) { + const updatedTable = tr.doc.nodeAt(tableInfo.tableStart); + if (updatedTable) { + fixHeaderRowColspan(tr, tableInfo.tableStart, updatedTable); + } + } + } catch (e) { + // eslint-disable-next-line no-console + console.warn('Could not fix header row colspan:', e); + } + dispatch(tr); + }); + + return result; +} + +// ensures header row maintains its colspan when adding columns +function addColumnAfterWrapper(state, dispatch) { + if (!dispatch) { + return addColumnAfter(state, dispatch); + } + + const originalPos = state.selection.$from.pos; + const result = addColumnAfter(state, (tr) => { + try { + const $pos = tr.doc.resolve(originalPos); + const tableInfo = findTableFromPos($pos); + if (tableInfo) { + const updatedTable = tr.doc.nodeAt(tableInfo.tableStart); + if (updatedTable) { + fixHeaderRowColspan(tr, tableInfo.tableStart, updatedTable); + } + } + } catch (e) { + // eslint-disable-next-line no-console + console.warn('Could not fix header row colspan:', e); + } + dispatch(tr); + }); + + return result; +} + +// Disable addRowBefore when in the header row +function addRowBeforeWrapper(state, dispatch) { + if (isInTableHeader(state)) { + return false; + } + + return addRowBefore(state, dispatch); +} + +// Disable splitCell when in the header row +function splitCellWrapper(state, dispatch) { + if (isInTableHeader(state)) { + return false; + } + + return splitCell(state, dispatch); +} + +// Disable deleteRow when in the header row +function deleteRowWrapper(state, dispatch) { + if (isInTableHeader(state)) { + return false; + } + + return deleteRow(state, dispatch); +} + +// Disable deleteColumn when in the header row +function deleteColumnWrapper(state, dispatch) { + if (isInTableHeader(state)) { + return false; + } + + return deleteColumn(state, dispatch); +} + // All exported export { EditorView, @@ -72,14 +249,14 @@ export { selectedRect, tableNodes, fixTables, - addColumnAfter, - addColumnBefore, - deleteColumn, + addColumnAfterWrapper as addColumnAfter, + addColumnBeforeWrapper as addColumnBefore, + deleteColumnWrapper as deleteColumn, addRowAfter, - addRowBefore, - deleteRow, + addRowBeforeWrapper as addRowBefore, + deleteRowWrapper as deleteRow, mergeCells, - splitCell, + splitCellWrapper as splitCell, deleteTable, gapCursor, MenuItem, 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..74858553 --- /dev/null +++ b/test/unit/blocks/edit/prose/table-modifications.test.js @@ -0,0 +1,505 @@ +/* + * 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, + addRowBefore, + addRowAfter, + splitCell, + deleteRow, + deleteColumn, + mergeCells, +} from 'da-y-wrapper'; +import { createTestEditor, destroyEditor } from './test-helpers.js'; +import insertTable from '../../../../../blocks/edit/prose/table.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(); + const { view } = editor; + + // Insert a table (starts with 2 columns) + insertTable(view.state, view.dispatch); + + // Position cursor in a cell of the second row (content row) + // The table structure is: header row (1 cell, colspan 2) + content row (2 cells) + // We need to find and select a cell in the content row + const tableNode = view.state.doc.firstChild; + expect(tableNode.type.name).to.equal('table'); + + // Get initial state + const firstRow = tableNode.child(0); + expect(firstRow.childCount).to.equal(1, 'Header row should have 1 cell'); + expect(firstRow.child(0).attrs.colspan).to.equal(2, 'Header should span 2 columns initially'); + + // Move cursor to second row, first cell + const secondRowPos = view.state.doc.resolve(5); // Position in second row + 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', + ); + }); + + it('should maintain header colspan when adding column after', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table (starts with 2 columns) + insertTable(view.state, view.dispatch); + + // Get initial state + const tableNode = view.state.doc.firstChild; + const firstRow = tableNode.child(0); + expect(firstRow.childCount).to.equal(1, 'Header row should have 1 cell'); + expect(firstRow.child(0).attrs.colspan).to.equal(2, 'Header should span 2 columns initially'); + + // Move cursor to second row + const secondRowPos = view.state.doc.resolve(5); + 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', + ); + }); + + it('should maintain header colspan when adding multiple columns', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table (starts with 2 columns) + insertTable(view.state, view.dispatch); + + // Get initial state + const tableNode = view.state.doc.firstChild; + const firstRow = tableNode.child(0); + expect(firstRow.child(0).attrs.colspan).to.equal(2, 'Header should span 2 columns initially'); + + // Move cursor to second row + const secondRowPos = view.state.doc.resolve(5); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, secondRowPos.pos), + ); + view.dispatch(tr); + + // Add column after + addColumnAfter(view.state, view.dispatch); + + // Add another column after + addColumnAfter(view.state, view.dispatch); + + // Add column before + addColumnBefore(view.state, view.dispatch); + + // Check that header row still has 1 cell and colspan is now 5 + 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 multiple columns', + ); + expect(updatedFirstRow.child(0).attrs.colspan).to.equal( + 5, + 'Header should span 5 columns after adding three', + ); + }); + + it('should preserve header text content when adding columns', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table + insertTable(view.state, view.dispatch); + + // Get the header text + const tableNode = view.state.doc.firstChild; + const firstRow = tableNode.child(0); + const headerText = firstRow.child(0).textContent; + expect(headerText).to.equal('columns'); + + // Move cursor to second row + const secondRowPos = view.state.doc.resolve(5); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, secondRowPos.pos), + ); + view.dispatch(tr); + + // Add a column + addColumnBefore(view.state, view.dispatch); + + // Check that header text is preserved + const updatedTable = view.state.doc.firstChild; + const updatedFirstRow = updatedTable.child(0); + const updatedHeaderText = updatedFirstRow.child(0).textContent; + + expect(updatedHeaderText).to.equal( + 'columns', + 'Header text should be preserved after adding column', + ); + }); + }); + + describe('Row Operations', () => { + it('should disable add row before when cursor is in header row', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table + insertTable(view.state, view.dispatch); + + // Move cursor to header row + const headerPos = view.state.doc.resolve(3); // Position in header cell + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, headerPos.pos), + ); + view.dispatch(tr); + + // Check if addRowBefore is available (should return false when not available) + const isAvailable = addRowBefore(view.state, null); + + expect(isAvailable).to.equal(false, 'Add row before should be disabled in header row'); + }); + + it('should allow add row after when cursor is in header row', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table + insertTable(view.state, view.dispatch); + + // Move cursor to header row + const headerPos = view.state.doc.resolve(3); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, headerPos.pos), + ); + view.dispatch(tr); + + // Check if addRowAfter is available (should return true) + const isAvailable = addRowAfter(view.state, null); + + expect(isAvailable).to.equal(true, 'Add row after should be available in header row'); + }); + + it('should allow add row before when cursor is in content row', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table + insertTable(view.state, view.dispatch); + + // The table structure after insertion: + // Row 0 (header): cell with colspan=2, contains "columns" + // Row 1 (content): 2 cells + + // Find the actual position of the first cell in the second row + // We need to navigate past the table node, first row, and into second row + const table = view.state.doc.firstChild; + const firstRow = table.child(0); + + // Position: start of doc (0) + table open (1) + first row size + // + second row open (1) + first cell of second row + const secondRowFirstCellPos = 1 + firstRow.nodeSize + 1; + + const $pos = view.state.doc.resolve(secondRowFirstCellPos); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, $pos.pos), + ); + view.dispatch(tr); + + // Check if addRowBefore is available (should return true) + const isAvailable = addRowBefore(view.state, null); + + expect(isAvailable).to.equal(true, 'Add row before should be available in content rows'); + }); + + it('should disable split cell when cursor is in header row', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table + insertTable(view.state, view.dispatch); + + // Move cursor to header row + const headerPos = view.state.doc.resolve(3); // Position in header cell + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, headerPos.pos), + ); + view.dispatch(tr); + + // Check if splitCell is available (should return false) + const isAvailable = splitCell(view.state, null); + + expect(isAvailable).to.equal(false, 'Split cell should be disabled in header row'); + }); + + it('should allow split cell when cursor is in content row with merged cells', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table + insertTable(view.state, view.dispatch); + + // Move cursor to content row + const table = view.state.doc.firstChild; + const firstRow = table.child(0); + const secondRowFirstCellPos = 1 + firstRow.nodeSize + 1; + + const $pos = view.state.doc.resolve(secondRowFirstCellPos); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, $pos.pos), + ); + view.dispatch(tr); + + // Check if splitCell is available + // (will return false for normal cells, true for merged cells) + const isAvailable = splitCell(view.state, null); + + // Normal cells can't be split, so this should be false + // This test just confirms it's not disabled by our constraint + expect(typeof isAvailable).to.equal('boolean', 'Split cell returns boolean'); + }); + + it('should add row with correct number of cells when adding after header', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table (header + 1 content row with 2 cells) + insertTable(view.state, view.dispatch); + + const initialTable = view.state.doc.firstChild; + const initialContentRow = initialTable.child(1); + const initialCellCount = initialContentRow.childCount; + + expect(initialCellCount).to.equal(2, 'Initial content row should have 2 cells'); + + // Move cursor to header row + const headerPos = view.state.doc.resolve(3); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, headerPos.pos), + ); + view.dispatch(tr); + + // Add row after header + addRowAfter(view.state, view.dispatch); + + // Check the new row (should be at index 1, pushing old content row to index 2) + const updatedTable = view.state.doc.firstChild; + expect(updatedTable.childCount).to.equal(3, 'Table should now have 3 rows'); + + const headerRow = updatedTable.child(0); + const newContentRow = updatedTable.child(1); + const oldContentRow = updatedTable.child(2); + + // Header should be unchanged + expect(headerRow.childCount).to.equal(1, 'Header should still be 1 cell'); + expect(headerRow.child(0).attrs.colspan).to.equal(2, 'Header should still span 2 columns'); + + // New row should have same number of cells as the original content row + expect(newContentRow.childCount).to.equal( + initialCellCount, + 'New row should have same number of cells as original content row', + ); + expect(oldContentRow.childCount).to.equal( + initialCellCount, + 'Old content row should still have same number of cells', + ); + }); + }); + + describe('Delete Operations', () => { + it('should disable delete row when cursor is in header row', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table + insertTable(view.state, view.dispatch); + + // Move cursor to header row + const headerPos = view.state.doc.resolve(3); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, headerPos.pos), + ); + view.dispatch(tr); + + // Check if deleteRow is available (should return false) + const isAvailable = deleteRow(view.state, null); + + expect(isAvailable).to.equal(false, 'Delete row should be disabled in header row'); + }); + + it('should adjust header colspan when deleting a column', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table (starts with 2 columns) + insertTable(view.state, view.dispatch); + + // Add a column to have 3 columns total + const table = view.state.doc.firstChild; + const firstRow = table.child(0); + const secondRowFirstCellPos = 1 + firstRow.nodeSize + 1; + + const $pos = view.state.doc.resolve(secondRowFirstCellPos); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, $pos.pos), + ); + view.dispatch(tr); + + addColumnAfter(view.state, view.dispatch); + + // Verify we have 3 columns + const tableWith3Cols = view.state.doc.firstChild; + const headerWith3Cols = tableWith3Cols.child(0); + expect(headerWith3Cols.child(0).attrs.colspan).to.equal(3, 'Header should span 3 columns'); + + // Now delete a column + deleteColumn(view.state, view.dispatch); + + // Check that header colspan adjusted to 2 + const tableWith2Cols = view.state.doc.firstChild; + const headerWith2Cols = tableWith2Cols.child(0); + + expect(headerWith2Cols.childCount).to.equal( + 1, + 'Header should still have 1 cell after deleting column', + ); + expect(headerWith2Cols.child(0).attrs.colspan).to.equal( + 2, + 'Header should span 2 columns after deleting one', + ); + }); + + it('should handle deleting multiple columns and maintain header colspan', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table and add columns to have 4 total + insertTable(view.state, view.dispatch); + + const table = view.state.doc.firstChild; + const firstRow = table.child(0); + const secondRowFirstCellPos = 1 + firstRow.nodeSize + 1; + + const $pos = view.state.doc.resolve(secondRowFirstCellPos); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, $pos.pos), + ); + view.dispatch(tr); + + // Add 2 columns + addColumnAfter(view.state, view.dispatch); + addColumnAfter(view.state, view.dispatch); + + // Verify 4 columns + let currentTable = view.state.doc.firstChild; + expect(currentTable.child(0).child(0).attrs.colspan).to.equal(4); + + // Delete a column + deleteColumn(view.state, view.dispatch); + + // Check header colspan is 3 + currentTable = view.state.doc.firstChild; + expect(currentTable.child(0).child(0).attrs.colspan).to.equal(3); + + // Delete another column + deleteColumn(view.state, view.dispatch); + + // Check header colspan is 2 + currentTable = view.state.doc.firstChild; + expect(currentTable.child(0).child(0).attrs.colspan).to.equal(2); + }); + + it('should disable delete column when cursor is in header row', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table (starts with 2 columns) + insertTable(view.state, view.dispatch); + + // Move cursor to header row + const headerPos = view.state.doc.resolve(3); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, headerPos.pos), + ); + view.dispatch(tr); + + // Delete column should be disabled in header row + const isAvailable = deleteColumn(view.state, null); + expect(isAvailable).to.equal(false, 'Delete column should be disabled in header row'); + }); + }); + + describe('Merge Cells Operations', () => { + it('should disable merge cells when cursor is in header row', async () => { + editor = await createTestEditor(); + const { view } = editor; + + // Insert a table + insertTable(view.state, view.dispatch); + + // Move cursor to header row + const headerPos = view.state.doc.resolve(3); + const tr = view.state.tr.setSelection( + view.state.selection.constructor.create(view.state.doc, headerPos.pos), + ); + view.dispatch(tr); + + // Check if mergeCells is available (should return false) + const isAvailable = mergeCells(view.state, null); + + expect(isAvailable).to.equal(false, 'Merge cells should be disabled in header row'); + }); + }); +}); From a114374c5fe5052736a08380e9c604a066534519 Mon Sep 17 00:00:00 2001 From: Sean Steimer Date: Tue, 11 Nov 2025 13:55:48 -0800 Subject: [PATCH 2/7] revert formatting change --- blocks/edit/prose/plugins/slashMenu/slashMenu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/edit/prose/plugins/slashMenu/slashMenu.js b/blocks/edit/prose/plugins/slashMenu/slashMenu.js index b162aba6..a84ebcec 100644 --- a/blocks/edit/prose/plugins/slashMenu/slashMenu.js +++ b/blocks/edit/prose/plugins/slashMenu/slashMenu.js @@ -39,8 +39,8 @@ const getTableName = ($cursor) => { const firstRow = table.child(0); const cellIndex = $cursor.index(tableCellDepth - 1); const row = $cursor.node(rowDepth); - const firstRowContent = firstRow.child(0).textContent; + const firstRowContent = firstRow.child(0).textContent; // Updated regex to allow spaces in table names, which will be normalized later const tableNameMatch = firstRowContent.match(/^([a-zA-Z0-9_\s-]+)(?:\s*\([^)]*\))?$/); From a8c22d7dc726e215cf81dd0766ba1d5e540e9428 Mon Sep 17 00:00:00 2001 From: Sean Steimer Date: Tue, 11 Nov 2025 14:17:52 -0800 Subject: [PATCH 3/7] simplify changes for smaller more manageable PR. just fix the add col use cases --- deps/da-y-wrapper/dist/index.js | 24 +- deps/da-y-wrapper/src/index.js | 56 +--- .../edit/prose/table-modifications.test.js | 312 ------------------ 3 files changed, 16 insertions(+), 376 deletions(-) diff --git a/deps/da-y-wrapper/dist/index.js b/deps/da-y-wrapper/dist/index.js index 95e3808f..0b44163c 100644 --- a/deps/da-y-wrapper/dist/index.js +++ b/deps/da-y-wrapper/dist/index.js @@ -1,13 +1,13 @@ -var bp=Object.defineProperty;var xp=(n,e)=>{for(var t in e)bp(n,t,{get:e[t],enumerable:!0})};function se(n){this.content=n}se.prototype={constructor:se,find:function(n){for(var e=0;e>1}};se.from=function(n){if(n instanceof se)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new se(e)};var ws=se;function la(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=la(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function ca(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),c=s.nodeSize;if(s==l){t-=c,r-=c;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let a=0,h=Math.min(s.text.length,l.text.length);for(;ae&&r(c,i+l,o||null,s)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=a},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,o)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||t>0?Pi(r+1,s):Pi(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var Qt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=ha(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(aa(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function aa(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(aa(o.content,e-i-1,t-i-1)))}function ha(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=ha(s.content,e-o-1,t);return l&&n.replaceChild(i,s.copy(l))}function Sp(n,e,t){if(t.openStart>n.depth)throw new Qt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Qt("Inconsistent open depths");return da(n,e,t,0)}function da(n,e,t,r){let i=n.index(r),o=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Ar(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(Gt(n.nodeAfter,r),o++));for(let l=o;li&&Ss(n,e,i+1),s=r.depth>i&&Ss(t,r,i+1),l=[];return Ar(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(fa(o,s),Gt(Xt(o,ua(n,e,t,r,i+1)),l)):(o&&Gt(Xt(o,Fi(n,e,i+1)),l),Ar(e,t,i,l),s&&Gt(Xt(s,Fi(t,r,i+1)),l)),Ar(r,null,i,l),new w(l)}function Fi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=Ss(n,e,t+1);Gt(Xt(i,Fi(n,e,t+1)),r)}return Ar(e,null,t,r),new w(r)}function kp(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var qi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let o=0;o0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Zt(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,o=t;for(let s=e;;){let{index:l,offset:c}=s.content.findIndex(o),a=o-c;if(r.push(s,l,i+c),!a||(s=s.child(l),s.isText))break;o=a-1,i+=c+1}return new n(t,r,o)}static resolveCached(e,t){let r=Qc.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,t,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),pa(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,i,r);return o.type.checkAttrs(o.attrs),o}};Ke.prototype.text=void 0;var Cs=class n extends Ke{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):pa(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function pa(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var en=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Ms(e,t);if(r.next==null)return n.empty;let i=ma(r);r.next&&r.err("Unexpected trailing text");let o=Ip(Np(i));return Rp(o,r),o}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` -`)}};en.empty=new en(!0);var Ms=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function ma(n){let e=[];do e.push(Ap(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Ap(n){let e=[];do e.push(Ep(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Ep(n){let e=Op(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=Tp(n,e);else break;return e}function Zc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function Tp(n,e){let t=Zc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Zc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Dp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.isInGroup(e)&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function Op(n){if(n.eat("(")){let e=ma(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=Dp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Np(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,c){let a={term:c,to:l};return e[s].push(a),a}function i(s,l){s.forEach(c=>c.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((c,a)=>c.concat(o(a,l)),[]);if(s.type=="seq")for(let c=0;;c++){let a=o(s.exprs[c],l);if(c==s.exprs.length-1)return a;i(a,l=t())}else if(s.type=="star"){let c=t();return r(l,c),i(o(s.expr,c),c),[r(c)]}else if(s.type=="plus"){let c=t();return i(o(s.expr,l),c),i(o(s.expr,c),c),[r(c)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let c=l;for(let a=0;a{n[s].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let o=e[r.join(",")]=new en(r.indexOf(n.length-1)>-1);for(let s=0;s-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:wa(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ke(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Ke(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let s=this.contentMatch.fillBefore(t);if(!s)return null;t=s.append(t)}let i=this.contentMatch.matchFragment(t),o=i&&i.fillBefore(w.empty,!0);return o?new Ke(this,e,t.append(o),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new n(o,t,s));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function vp(n,e,t){let r=t.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}var As=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?vp(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Tr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=xa(e,i.attrs),this.excluded=null;let o=ya(this.attrs);this.instance=o?new D(this,o):null}create(e=null){return!e&&this.instance?this.instance:new D(this,wa(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new n(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}},Dr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=ws.from(e.nodes),t.marks=ws.from(e.marks||{}),this.nodes=Hi.compile(this.spec.nodes,this),this.marks=Tr.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=en.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?ta(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:ta(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Hi){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new Cs(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Ke.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function ta(n,e){let t=[];for(let r=0;r-1)&&t.push(s=c)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function _p(n){return n.tag!=null}function Up(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(_p(i))this.tags.push(i);else if(Up(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new Wi(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Wi(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(s.getAttrs){let c=s.getAttrs(t);if(c===!1)continue;s.attrs=c||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=ra(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=ra(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},Sa={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Vp={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ka={ol:!0,ul:!0},Ji=1,$i=2,Er=4;function na(n,e,t){return e!=null?(e?Ji:0)|(e==="full"?$i:0):n&&n.whitespace=="pre"?Ji|$i:t&~Er}var Ln=class{constructor(e,t,r,i,o,s){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=D.none,this.match=o||(s&Er?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ji)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Sa.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Wi=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,o,s=na(null,t.preserveWhitespace,0)|(r?Er:0);i?o=new Ln(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,s):r?o=new Ln(null,null,D.none,!0,null,s):o=new Ln(e.schema.topNodeType,null,D.none,!0,null,s),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&$i||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Ji)i.options&$i?r=r.replace(/\r\n?/g,` -`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],s=e.previousSibling;(!o||s&&s.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),o;ka.hasOwnProperty(i)&&this.parser.normalizeLists&&Bp(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,r));if(s?s.ignore:Vp.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let l,c=this.top,a=this.needsBlock;if(Sa.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=s&&s.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,s,l,s.consuming===!1?o:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let o,s;if(t.node)if(s=this.parser.schema.nodes[t.node],s.isLeaf)this.insertNode(s.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(s,t.attrs||null,r,t.preserveWhitespace);c&&(o=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}o&&this.sync(l)&&this.open--}addAll(e,t,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];s!=l;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,t);this.findAtPoint(e,o)}findPlace(e,t){let r,i;for(let o=this.open;o>=0;o--){let s=this.nodes[o],l=s.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=s,!l.length)||s.solid)break}if(!r)return null;this.sync(i);for(let o=0;o(s.type?s.type.allowsMarkType(a.type):ia(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Ln(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=o;c--)if(s(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Bp(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ka.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Pp(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function ra(n){let e={};for(let t in n)e[t]=n[t];return e}function ia(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let c=0;c{if(o.length||s.marks.length){let l=0,c=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Li(xs(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Li(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=oa(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return oa(e.marks)}};function oa(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function xs(n){return n.document||window.document}var sa=new WeakMap;function Lp(n){let e=sa.get(n);return e===void 0&&sa.set(n,e=zp(n)),e}function zp(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(t=i.slice(0,s),i=i.slice(s+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let d in a)if(a[d]!=null){let f=d.indexOf(" ");f>0?c.setAttributeNS(d.slice(0,f),d.slice(f+1),a[d]):c.setAttribute(d,a[d])}}for(let d=h;dh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=Li(n,f,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var Aa=65535,Ea=Math.pow(2,16);function qp(n,e){return n+e*Ea}function Ca(n){return n&Aa}function Hp(n){return(n-(n&Aa))/Ea}var Ta=1,Da=2,ji=4,Oa=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Oa)>0}get deletedBefore(){return(this.delInfo&(Ta|ji))>0}get deletedAfter(){return(this.delInfo&(Da|ji))>0}get deletedAcross(){return(this.delInfo&ji)>0}},ft=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=Ca(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+o],h=this.ranges[l+s],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:qp(l/3,e-c),m=e==c?Da:e==d?Ta:ji;return(t<0?e!=c:e!=d)&&(m|=Oa),new Ir(u,m,p)}i+=h-a}return r?e+i:new Ir(e+i,0,null)}touches(e,t){let r=0,i=Ca(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+o],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+s]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&c!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,o)}invert(){return new tn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("addMark",vr);var tn=class n extends G{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(Is(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,r)}invert(){return new vr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("removeMark",tn);var _r=class n extends G{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};G.jsonID("replaceAround",X);function Os(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Jp(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),o.forEach(c=>n.step(c))}function $p(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let c=null;if(r instanceof Tr){let a=s.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(s.marks)&&(c=[r]):c=s.marks;if(c&&c.length){let a=Math.min(l+s.nodeSize,t);for(let h=0;hn.step(new tn(s.from,s.to,s.style)))}function Rs(n,e,t,r=t.contentMatch,i=!0){let o=n.doc.nodeAt(e),s=[],l=e+1;for(let c=0;c=0;c--)n.step(s[c])}function Wp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),d++):c--;let f=w.empty,u=0;for(let p=o,m=!1;p>t;p--)m||i.after(p+1)=0;s--){if(r.size){let l=t[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=w.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new X(i,o,i,o,new b(r,0,0),t.length,!0))}function Xp(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{let c=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,c)&&Qp(n.doc,n.mapping.slice(o).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Ia(n,s,l,o),Rs(n,n.mapping.slice(o).map(l,1),r,void 0,a===null);let h=n.mapping.slice(o),d=h.map(l,1),f=h.map(l+s.nodeSize,1);return n.step(new X(d,f,d+1,f-1,new b(w.from(r.create(c,null,s.marks)),0,0),1,!0)),a===!0&&Na(n,s,l,o),!1}})}function Na(n,e,t,r){e.forEach((i,o)=>{if(i.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+o+s.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Ia(n,e,t,r){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let s=n.mapping.slice(r).map(t+1+o);n.replaceWith(s,s+1,e.type.schema.text(` -`))}})}function Qp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Zp(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new X(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new b(w.from(s),0,0),1,!0))}function Rt(n,e,t=1,r){let i=n.resolve(e),o=i.depth-t,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>o;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(o),c=r&&r[0];return i.node(o).canReplaceWith(l,l,c?c.type:i.node(o+1).type)}function em(n,e,t=1,r){let i=n.doc.resolve(e),o=w.empty,s=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){o=w.from(i.node(l).copy(o));let h=r&&r[a];s=w.from(h?h.type.create(h.attrs,s):i.node(l).copy(s))}n.step(new Ee(e,e,new b(o.append(s),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Ra(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function tm(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(o=r.node(i+1),l++,s=r.node(i).maybeChild(l)):(o=r.node(i).maybeChild(l-1),s=r.node(i+1)),o&&!o.isTextblock&&Ra(o,s)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function nm(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,o=n.doc.resolve(e-t),s=o.node().type;if(i&&s.inlineContent){let h=s.whitespace=="pre",d=!!s.contentMatch.matchType(i);h&&!d?r=!1:!h&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Ia(n,h.node(),h.before(),l)}s.inlineContent&&Rs(n,e+t-1,s,o.node().contentMatchAt(o.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ee(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);Na(n,h.node(),h.before(),n.steps.length)}return n}function rm(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,c=r.index(s)+(l>0?1:0),a=r.node(s),h=!1;if(o==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function Xi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return _a(i,o,r)?new Ee(e,t,r):new Ns(i,o,r).fit()}function _a(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Ns=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let c=new b(o,s,l);return e>-1?new X(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ee(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ts(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(s?a.matchType(s.type)||(d=a.fillBefore(w.from(s),!1)):o&&c.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:d};if(t==2&&s&&(h=a.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:h};if(o&&a.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ts(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ts(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new b(Or(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new b(Or(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(Ua(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Nr(this.placed,t,w.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:c,type:a}=this.frontier[l],h=Ds(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Nr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Nr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Nr(this.placed,this.frontier.length,t))}};function Or(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Or(n.firstChild.content,e-1,t)))}function Nr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Nr(n.lastChild.content,e-1,t)))}function Ts(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Ua(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function Ds(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!im(t,o.content,s)?l:null}function im(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;s.indexOf(f)>-1?l=f:i.before(f)==u&&s.splice(1,0,-f)}let c=s.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=om(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=s[f];u<0||(e=i.before(u),t=o.after(u))}}function Va(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(w.empty,!0))}return n}function lm(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=rm(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function cm(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=Ba(r,i);for(let s=0;s0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return n.delete(r.before(s),t);n.delete(e,t)}function Ba(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}var Ki=class n extends G{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return ft.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};G.jsonID("attr",Ki);var Yi=class n extends G{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ee.ok(r)}getMap(){return ft.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};G.jsonID("docAttr",Yi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Rr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Xi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return sm(this,e,t,r),this}replaceRangeWith(e,t,r){return lm(this,e,t,r),this}deleteRange(e,t){return cm(this,e,t),this}lift(e,t){return jp(this,e,t),this}join(e,t=1){return nm(this,e,t),this}wrap(e,t){return Gp(this,e,t),this}setBlockType(e,t=e,r,i=null){return Xp(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Zp(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Ki(e,t,r)),this}setDocAttribute(e,t){return this.step(new Yi(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Ur(e,t)),this}split(e,t=1,r){return em(this,e,t,r),this}addMark(e,t,r){return Jp(this,e,t,r),this}removeMark(e,t,r){return $p(this,e,t,r),this}clearIncompatible(e,t,r){return Rs(this,e,t,r),this}};var _s=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new vt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;o--){let s=t<0?Hn(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Hn(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Te(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Te(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=_s[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in _s)throw new RangeError("Duplicate use of selection JSON ID "+e);return _s[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var vt=class{constructor(e,t){this.$from=e,this.$to=t}},Pa=!1;function La(n){!Pa&&!n.parent.inlineContent&&(Pa=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){La(e),La(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let o=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(o)t=o.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&C.isSelectable(l))return C.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,o);if(c)return c}t+=l.nodeSize*i}return null}function za(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=h)}),n.setSelection(S.near(n.doc.resolve(s),t))}var Fa=1,Qi=2,qa=4,Bs=class extends qn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Qi,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Qi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Qi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=qa,this}get scrolledIntoView(){return(this.updated&qa)>0}};function Ha(n,e){return!e||!n?n:n.bind(e)}var on=class{constructor(e,t,r){this.name=e,this.init=Ha(t.init,r),this.apply=Ha(t.apply,r)}},hm=[new on("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new on("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new on("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new on("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Vr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=hm.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new on(r.key,r.spec.state,r))})}},Ps=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(t[r]=o.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Vr(e.schema,e.plugins),o=new n(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=Ke.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=S.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==s.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=a.fromJSON.call(c,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}};function Ja(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Ja(i,e,{})),t[r]=i}return t}var H=class{constructor(e){this.spec=e,this.props={},e.props&&Ja(e.props,this,this.props),this.key=e.key?e.key.key:$a("plugin")}getState(e){return e[this.key]}},Us=Object.create(null);function $a(n){return n in Us?n+"$"+ ++Us[n]:(Us[n]=0,n+"$")}var le=class{constructor(e="key"){this.key=$a(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var te=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},zr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Hs=null,pt=function(n,e,t){let r=Hs||(Hs=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},dm=function(){Hs=null},fn=function(n,e,t,r){return t&&(Wa(n,e,t,r,-1)||Wa(n,e,t,r,1))},fm=/^(img|br|input|textarea|hr)$/i;function Wa(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:_e(n))){let o=n.parentNode;if(!o||o.nodeType!=1||Jr(n)||fm.test(n.nodeName)||n.contentEditable=="false")return!1;e=te(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?_e(n):0}else return!1}}function _e(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function um(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=_e(n)}else if(n.parentNode&&!Jr(n))e=te(n),n=n.parentNode;else return null}}function pm(n,e){for(;;){if(n.nodeType==3&&e2),ve=Kn||(Ye?/Mac/.test(Ye.platform):!1),wm=Ye?/Win/.test(Ye.platform):!1,He=/Android \d/.test(Lt),$r=!!ja&&"webkitFontSmoothing"in ja.documentElement.style,bm=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function xm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ut(n,e){return typeof n=="number"?n:n[e]}function Sm(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Ka(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;s=zr(s)){if(s.nodeType!=1)continue;let l=s,c=l==o.body,a=c?xm(o):Sm(l),h=0,d=0;if(e.topa.bottom-ut(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+ut(i,"top")-a.top:e.bottom-a.bottom+ut(i,"bottom")),e.lefta.right-ut(r,"right")&&(h=e.right-a.right+ut(i,"right")),h||d)if(c)o.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function km(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:Th(n.dom)}}function Th(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=zr(r));return e}function Cm({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Dh(t,r==0?0:r-e)}function Dh(n,e){for(let t=0;t=l){s=Math.max(p.bottom,s),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(o=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?Am(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:Oh(t,i)}function Am(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function cl(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function Em(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function Dm(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!s&&c.left>r.left||c.top>r.top?i=l.posBefore:(!s&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Nh(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;$r&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=Dm(n,r,i,e))}l==null&&(l=Tm(n,s,e));let c=n.docView.nearestDesc(s,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Ya(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Br(_t(pt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Ls(c.getBoundingClientRect(),!1)}if(o==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return Ls(c.getBoundingClientRect(),!0)}return Ls(r.getBoundingClientRect(),t>=0)}if(o==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?pt(c,_e(c)-(s?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Br(_t(a,1),!1)}if(o==null&&i<_e(r)){let c=r.childNodes[i];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let a=c?c.nodeType==3?pt(c,0,s?0:1):c.nodeType==1?c:null:null;if(a)return Br(_t(a,-1),!0)}return Br(_t(r.nodeType==3?pt(r):r,-t),t>=0)}function Br(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Ls(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Rh(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Im(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Rh(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Ih(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=pt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?s.top-h.top>(h.bottom-s.top)*2:h.bottom-s.bottom>(s.bottom-h.top)*2))return!1}}return!0})}var Rm=/[\u0590-\u08ac]/;function vm(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!Rm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Rh(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}var Ga=null,Xa=null,Qa=!1;function _m(n,e,t){return Ga==e&&Xa==t?Qa:(Ga=e,Xa=t,Qa=t=="up"||t=="down"?Im(n,e,t):vm(n,e,t))}var Ue=0,Za=1,ln=2,Ge=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Ue,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tte(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof no){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof eo&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?te(o.dom)+1:0}}else{let o,s=!0;for(;o=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=s;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=te(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&st){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+o.border,c=s-o.border;if(e>=l&&t<=c){this.dirty=e==r||t==s?ln:Za,e==l&&t==c&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Ge:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?ln:Ge}r=s}this.dirty=ln}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?ln:Za;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=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}},js=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 o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=It.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,s.dom,s.contentDOM||s.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&&(o=Xs(o,0,e,r));for(let l=0;l{if(!c)return s;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=Uh(h,r,t),a?c=new Ks(e,t,r,i,h,d||null,f,a,o,s+1):t.isText?new to(e,t,r,i,h,f,o):new n(e,t,r,i,h,d||null,f,o,s+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)&&ro(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,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,c=new Gs(this,s&&s.node,e);Pm(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)&&(s&&this.protectLocalComposition(e,s),vh(this.contentDOM,this.children,e),Kn&&Lm(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 o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=zm(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new js(this,o,t,i);e.input.compositionNodes.push(s),this.children=Xs(this.children,r,r+i.length,e,s)}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(ro(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=_h(this.dom,this.nodeDOM,Ys(this.outerDeco,this.node,t),Ys(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 eh(n,e,t,r,i){Uh(r,e,n);let o=new Pt(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}var to=class n extends Pt{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,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),o=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,o,o,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}},no=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"}},Ks=class extends Pt{constructor(e,t,r,i,o,s,l,c,a,h){super(e,t,r,i,o,s,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==Ge)return!1;if(this.spec.update){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}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 vh(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,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[o],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,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,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Bm(n,e){return n.type.side-e.type.side}function Pm(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let a=0;ao;)l.push(i[s++]);let p=o+f.nodeSize;if(f.isText){let g=p;s!g.inline):l.slice();r(f,m,e.forChild(o,f),u),o=p}}function Lm(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 zm(n,e,t,r){for(let i=0,o=0;i=t){if(o>=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 Xs(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||h<=e?o.push(c):(at&&o.push(c.slice(t-a,c.size,r)))}return o}function al(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),c,a;if(ho(t)){for(c=s;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&C.isSelectable(d)&&i.parent&&!(d.isInline&&mm(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;a=new C(s==f?l:r.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=s,f=s;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 qm(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 Bh(n,e){if(e instanceof C){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(oh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else oh(n)}function oh(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function hl(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function sh(n){return n.editable&&!n.hasFocus()?!1:Ph(n)}function Ph(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 Hm(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 Qs(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&S.findFrom(o,e)}function Ut(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function lh(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return Ut(n,new A(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Qs(n.state,e);return i&&i instanceof C?Ut(n,i):!1}else if(!(ve&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?C.isSelectable(o)?Ut(n,new C(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):$r?Ut(n,new A(n.state.doc.resolve(e<0?l:l+o.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=Qs(n.state,e);return i?Ut(n,i):!1}}}function io(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?Jm(n):$m(n)}function Jm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(Je&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Lr(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Lh(t))break;{let l=t.previousSibling;for(;l&&Lr(l,-1);)i=t.parentNode,o=te(l),l=l.previousSibling;if(l)t=l,r=io(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?Zs(n,t,r):i&&Zs(n,i,o)}function $m(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=io(t),o,s;for(;;)if(r{n.state==i&&mt(n)},50)}function ch(n,e){let t=n.state.doc.resolve(e);if(!(ae||wm)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function ah(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:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Qs(n.state,e);if(s&&s instanceof C)return Ut(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Te?S.near(s,e):S.findFrom(s,e);return l?Ut(n,l):!1}return!1}function hh(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 o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function dh(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Km(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;dh(n,r,"true"),setTimeout(()=>dh(n,r,"false"),20)}return!1}function Ym(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Gm(n,e){let t=e.keyCode,r=Ym(e);if(t==8||ve&&t==72&&r=="c")return hh(n,-1)||$n(n,-1);if(t==46&&!e.shiftKey||ve&&t==68&&r=="c")return hh(n,1)||$n(n,1);if(t==13||t==27)return!0;if(t==37||ve&&t==66&&r=="c"){let i=t==37?ch(n,n.state.selection.from)=="ltr"?-1:1:-1;return lh(n,i,r)||$n(n,i)}else if(t==39||ve&&t==70&&r=="c"){let i=t==39?ch(n,n.state.selection.from)=="ltr"?1:-1:1;return lh(n,i,r)||$n(n,i)}else{if(t==38||ve&&t==80&&r=="c")return ah(n,-1,r)||$n(n,-1);if(t==40||ve&&t==78&&r=="c")return Km(n)||ah(n,1,r)||$n(n,1);if(r==(ve?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function zh(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let s=n.someProp("clipboardSerializer")||It.fromSchema(n.state.schema),l=Wh(),c=l.createElement("div");c.appendChild(s.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=$h[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} ${o}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,` +var pp=Object.defineProperty;var mp=(n,e)=>{for(var t in e)pp(n,t,{get:e[t],enumerable:!0})};function se(n){this.content=n}se.prototype={constructor:se,find:function(n){for(var e=0;e>1}};se.from=function(n){if(n instanceof se)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new se(e)};var ys=se;function sa(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=sa(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function la(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),c=s.nodeSize;if(s==l){t-=c,r-=c;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let a=0,h=Math.min(s.text.length,l.text.length);for(;ae&&r(c,i+l,o||null,s)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=a},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,o)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||t>0?Pi(r+1,s):Pi(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var Qt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=aa(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(ca(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function ca(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(ca(o.content,e-i-1,t-i-1)))}function aa(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=aa(s.content,e-o-1,t);return l&&n.replaceChild(i,s.copy(l))}function gp(n,e,t){if(t.openStart>n.depth)throw new Qt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Qt("Inconsistent open depths");return ha(n,e,t,0)}function ha(n,e,t,r){let i=n.index(r),o=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Ar(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(Gt(n.nodeAfter,r),o++));for(let l=o;li&&xs(n,e,i+1),s=r.depth>i&&xs(t,r,i+1),l=[];return Ar(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(da(o,s),Gt(Xt(o,fa(n,e,t,r,i+1)),l)):(o&&Gt(Xt(o,Fi(n,e,i+1)),l),Ar(e,t,i,l),s&&Gt(Xt(s,Fi(t,r,i+1)),l)),Ar(r,null,i,l),new w(l)}function Fi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=xs(n,e,t+1);Gt(Xt(i,Fi(n,e,t+1)),r)}return Ar(e,null,t,r),new w(r)}function yp(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var qi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let o=0;o0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Zt(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,o=t;for(let s=e;;){let{index:l,offset:c}=s.content.findIndex(o),a=o-c;if(r.push(s,l,i+c),!a||(s=s.child(l),s.isText))break;o=a-1,i+=c+1}return new n(t,r,o)}static resolveCached(e,t){let r=Xc.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,t,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),ua(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,i,r);return o.type.checkAttrs(o.attrs),o}};Ke.prototype.text=void 0;var ks=class n extends Ke{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):ua(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function ua(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var en=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Cs(e,t);if(r.next==null)return n.empty;let i=pa(r);r.next&&r.err("Unexpected trailing text");let o=Ep(Ap(i));return Tp(o,r),o}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` +`)}};en.empty=new en(!0);var Cs=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function pa(n){let e=[];do e.push(xp(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function xp(n){let e=[];do e.push(Sp(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Sp(n){let e=Mp(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=kp(n,e);else break;return e}function Qc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function kp(n,e){let t=Qc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Qc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Cp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.isInGroup(e)&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function Mp(n){if(n.eat("(")){let e=pa(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=Cp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Ap(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,c){let a={term:c,to:l};return e[s].push(a),a}function i(s,l){s.forEach(c=>c.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((c,a)=>c.concat(o(a,l)),[]);if(s.type=="seq")for(let c=0;;c++){let a=o(s.exprs[c],l);if(c==s.exprs.length-1)return a;i(a,l=t())}else if(s.type=="star"){let c=t();return r(l,c),i(o(s.expr,c),c),[r(c)]}else if(s.type=="plus"){let c=t();return i(o(s.expr,l),c),i(o(s.expr,c),c),[r(c)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let c=l;for(let a=0;a{n[s].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let o=e[r.join(",")]=new en(r.indexOf(n.length-1)>-1);for(let s=0;s-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ya(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ke(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Ke(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let s=this.contentMatch.fillBefore(t);if(!s)return null;t=s.append(t)}let i=this.contentMatch.matchFragment(t),o=i&&i.fillBefore(w.empty,!0);return o?new Ke(this,e,t.append(o),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new n(o,t,s));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Dp(n,e,t){let r=t.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}var Ms=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Dp(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Tr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=ba(e,i.attrs),this.excluded=null;let o=ga(this.attrs);this.instance=o?new D(this,o):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ya(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new n(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}},Dr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=ys.from(e.nodes),t.marks=ys.from(e.marks||{}),this.nodes=Hi.compile(this.spec.nodes,this),this.marks=Tr.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=en.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?ea(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:ea(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Hi){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new ks(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Ke.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function ea(n,e){let t=[];for(let r=0;r-1)&&t.push(s=c)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Op(n){return n.tag!=null}function Np(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Op(i))this.tags.push(i);else if(Np(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new Wi(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Wi(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(s.getAttrs){let c=s.getAttrs(t);if(c===!1)continue;s.attrs=c||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=na(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=na(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},xa={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Ip={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Sa={ol:!0,ul:!0},Ji=1,$i=2,Er=4;function ta(n,e,t){return e!=null?(e?Ji:0)|(e==="full"?$i:0):n&&n.whitespace=="pre"?Ji|$i:t&~Er}var Ln=class{constructor(e,t,r,i,o,s){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=D.none,this.match=o||(s&Er?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ji)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!xa.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Wi=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,o,s=ta(null,t.preserveWhitespace,0)|(r?Er:0);i?o=new Ln(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,s):r?o=new Ln(null,null,D.none,!0,null,s):o=new Ln(e.schema.topNodeType,null,D.none,!0,null,s),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&$i||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Ji)i.options&$i?r=r.replace(/\r\n?/g,` +`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],s=e.previousSibling;(!o||s&&s.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),o;Sa.hasOwnProperty(i)&&this.parser.normalizeLists&&Rp(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,r));if(s?s.ignore:Ip.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let l,c=this.top,a=this.needsBlock;if(xa.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=s&&s.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,s,l,s.consuming===!1?o:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` +`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let o,s;if(t.node)if(s=this.parser.schema.nodes[t.node],s.isLeaf)this.insertNode(s.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(s,t.attrs||null,r,t.preserveWhitespace);c&&(o=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}o&&this.sync(l)&&this.open--}addAll(e,t,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];s!=l;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,t);this.findAtPoint(e,o)}findPlace(e,t){let r,i;for(let o=this.open;o>=0;o--){let s=this.nodes[o],l=s.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=s,!l.length)||s.solid)break}if(!r)return null;this.sync(i);for(let o=0;o(s.type?s.type.allowsMarkType(a.type):ra(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Ln(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=o;c--)if(s(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Rp(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Sa.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function vp(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function na(n){let e={};for(let t in n)e[t]=n[t];return e}function ra(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let c=0;c{if(o.length||s.marks.length){let l=0,c=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Li(bs(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Li(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=ia(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return ia(e.marks)}};function ia(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function bs(n){return n.document||window.document}var oa=new WeakMap;function _p(n){let e=oa.get(n);return e===void 0&&oa.set(n,e=Up(n)),e}function Up(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(t=i.slice(0,s),i=i.slice(s+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let d in a)if(a[d]!=null){let f=d.indexOf(" ");f>0?c.setAttributeNS(d.slice(0,f),d.slice(f+1),a[d]):c.setAttribute(d,a[d])}}for(let d=h;dh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=Li(n,f,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var Ma=65535,Aa=Math.pow(2,16);function Bp(n,e){return n+e*Aa}function ka(n){return n&Ma}function Pp(n){return(n-(n&Ma))/Aa}var Ea=1,Ta=2,ji=4,Da=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Da)>0}get deletedBefore(){return(this.delInfo&(Ea|ji))>0}get deletedAfter(){return(this.delInfo&(Ta|ji))>0}get deletedAcross(){return(this.delInfo&ji)>0}},ft=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=ka(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+o],h=this.ranges[l+s],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:Bp(l/3,e-c),m=e==c?Ta:e==d?Ea:ji;return(t<0?e!=c:e!=d)&&(m|=Da),new Ir(u,m,p)}i+=h-a}return r?e+i:new Ir(e+i,0,null)}touches(e,t){let r=0,i=ka(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+o],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+s]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&c!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,o)}invert(){return new tn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("addMark",vr);var tn=class n extends G{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(Ns(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,r)}invert(){return new vr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("removeMark",tn);var _r=class n extends G{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};G.jsonID("replaceAround",X);function Ds(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Lp(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),o.forEach(c=>n.step(c))}function zp(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let c=null;if(r instanceof Tr){let a=s.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(s.marks)&&(c=[r]):c=s.marks;if(c&&c.length){let a=Math.min(l+s.nodeSize,t);for(let h=0;hn.step(new tn(s.from,s.to,s.style)))}function Is(n,e,t,r=t.contentMatch,i=!0){let o=n.doc.nodeAt(e),s=[],l=e+1;for(let c=0;c=0;c--)n.step(s[c])}function Fp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),d++):c--;let f=w.empty,u=0;for(let p=o,m=!1;p>t;p--)m||i.after(p+1)=0;s--){if(r.size){let l=t[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=w.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new X(i,o,i,o,new b(r,0,0),t.length,!0))}function Wp(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{let c=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,c)&&jp(n.doc,n.mapping.slice(o).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Na(n,s,l,o),Is(n,n.mapping.slice(o).map(l,1),r,void 0,a===null);let h=n.mapping.slice(o),d=h.map(l,1),f=h.map(l+s.nodeSize,1);return n.step(new X(d,f,d+1,f-1,new b(w.from(r.create(c,null,s.marks)),0,0),1,!0)),a===!0&&Oa(n,s,l,o),!1}})}function Oa(n,e,t,r){e.forEach((i,o)=>{if(i.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+o+s.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Na(n,e,t,r){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let s=n.mapping.slice(r).map(t+1+o);n.replaceWith(s,s+1,e.type.schema.text(` +`))}})}function jp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Kp(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new X(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new b(w.from(s),0,0),1,!0))}function Rt(n,e,t=1,r){let i=n.resolve(e),o=i.depth-t,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>o;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(o),c=r&&r[0];return i.node(o).canReplaceWith(l,l,c?c.type:i.node(o+1).type)}function Yp(n,e,t=1,r){let i=n.doc.resolve(e),o=w.empty,s=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){o=w.from(i.node(l).copy(o));let h=r&&r[a];s=w.from(h?h.type.create(h.attrs,s):i.node(l).copy(s))}n.step(new Ee(e,e,new b(o.append(s),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Ia(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Gp(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(o=r.node(i+1),l++,s=r.node(i).maybeChild(l)):(o=r.node(i).maybeChild(l-1),s=r.node(i+1)),o&&!o.isTextblock&&Ia(o,s)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function Xp(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,o=n.doc.resolve(e-t),s=o.node().type;if(i&&s.inlineContent){let h=s.whitespace=="pre",d=!!s.contentMatch.matchType(i);h&&!d?r=!1:!h&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Na(n,h.node(),h.before(),l)}s.inlineContent&&Is(n,e+t-1,s,o.node().contentMatchAt(o.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ee(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);Oa(n,h.node(),h.before(),n.steps.length)}return n}function Qp(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,c=r.index(s)+(l>0?1:0),a=r.node(s),h=!1;if(o==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function Xi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return va(i,o,r)?new Ee(e,t,r):new Os(i,o,r).fit()}function va(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Os=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let c=new b(o,s,l);return e>-1?new X(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ee(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Es(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(s?a.matchType(s.type)||(d=a.fillBefore(w.from(s),!1)):o&&c.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:d};if(t==2&&s&&(h=a.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:h};if(o&&a.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Es(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Es(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new b(Or(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new b(Or(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(_a(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Nr(this.placed,t,w.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:c,type:a}=this.frontier[l],h=Ts(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Nr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Nr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Nr(this.placed,this.frontier.length,t))}};function Or(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Or(n.firstChild.content,e-1,t)))}function Nr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Nr(n.lastChild.content,e-1,t)))}function Es(n,e){for(let t=0;t1&&(r=r.replaceChild(0,_a(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function Ts(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Zp(t,o.content,s)?l:null}function Zp(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;s.indexOf(f)>-1?l=f:i.before(f)==u&&s.splice(1,0,-f)}let c=s.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=em(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=s[f];u<0||(e=i.before(u),t=o.after(u))}}function Ua(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(w.empty,!0))}return n}function nm(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Qp(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function rm(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=Va(r,i);for(let s=0;s0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return n.delete(r.before(s),t);n.delete(e,t)}function Va(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}var Ki=class n extends G{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return ft.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};G.jsonID("attr",Ki);var Yi=class n extends G{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ee.ok(r)}getMap(){return ft.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};G.jsonID("docAttr",Yi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Rr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Xi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return tm(this,e,t,r),this}replaceRangeWith(e,t,r){return nm(this,e,t,r),this}deleteRange(e,t){return rm(this,e,t),this}lift(e,t){return qp(this,e,t),this}join(e,t=1){return Xp(this,e,t),this}wrap(e,t){return $p(this,e,t),this}setBlockType(e,t=e,r,i=null){return Wp(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Kp(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Ki(e,t,r)),this}setDocAttribute(e,t){return this.step(new Yi(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Ur(e,t)),this}split(e,t=1,r){return Yp(this,e,t,r),this}addMark(e,t,r){return Lp(this,e,t,r),this}removeMark(e,t,r){return zp(this,e,t,r),this}clearIncompatible(e,t,r){return Is(this,e,t,r),this}};var vs=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new vt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;o--){let s=t<0?Hn(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Hn(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Te(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Te(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=vs[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in vs)throw new RangeError("Duplicate use of selection JSON ID "+e);return vs[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var vt=class{constructor(e,t){this.$from=e,this.$to=t}},Ba=!1;function Pa(n){!Ba&&!n.parent.inlineContent&&(Ba=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Pa(e),Pa(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let o=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(o)t=o.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&C.isSelectable(l))return C.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,o);if(c)return c}t+=l.nodeSize*i}return null}function La(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=h)}),n.setSelection(S.near(n.doc.resolve(s),t))}var za=1,Qi=2,Fa=4,Vs=class extends qn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Qi,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Qi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Qi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Fa,this}get scrolledIntoView(){return(this.updated&Fa)>0}};function qa(n,e){return!e||!n?n:n.bind(e)}var on=class{constructor(e,t,r){this.name=e,this.init=qa(t.init,r),this.apply=qa(t.apply,r)}},om=[new on("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new on("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new on("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new on("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Vr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=om.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new on(r.key,r.spec.state,r))})}},Bs=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(t[r]=o.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Vr(e.schema,e.plugins),o=new n(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=Ke.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=S.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==s.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=a.fromJSON.call(c,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}};function Ha(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Ha(i,e,{})),t[r]=i}return t}var H=class{constructor(e){this.spec=e,this.props={},e.props&&Ha(e.props,this,this.props),this.key=e.key?e.key.key:Ja("plugin")}getState(e){return e[this.key]}},_s=Object.create(null);function Ja(n){return n in _s?n+"$"+ ++_s[n]:(_s[n]=0,n+"$")}var le=class{constructor(e="key"){this.key=Ja(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var te=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},zr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},qs=null,pt=function(n,e,t){let r=qs||(qs=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},sm=function(){qs=null},fn=function(n,e,t,r){return t&&($a(n,e,t,r,-1)||$a(n,e,t,r,1))},lm=/^(img|br|input|textarea|hr)$/i;function $a(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:_e(n))){let o=n.parentNode;if(!o||o.nodeType!=1||Jr(n)||lm.test(n.nodeName)||n.contentEditable=="false")return!1;e=te(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?_e(n):0}else return!1}}function _e(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function cm(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=_e(n)}else if(n.parentNode&&!Jr(n))e=te(n),n=n.parentNode;else return null}}function am(n,e){for(;;){if(n.nodeType==3&&e2),ve=Kn||(Ye?/Mac/.test(Ye.platform):!1),um=Ye?/Win/.test(Ye.platform):!1,Fe=/Android \d/.test(Lt),$r=!!Wa&&"webkitFontSmoothing"in Wa.documentElement.style,pm=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function mm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ut(n,e){return typeof n=="number"?n:n[e]}function gm(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function ja(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;s=zr(s)){if(s.nodeType!=1)continue;let l=s,c=l==o.body,a=c?mm(o):gm(l),h=0,d=0;if(e.topa.bottom-ut(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+ut(i,"top")-a.top:e.bottom-a.bottom+ut(i,"bottom")),e.lefta.right-ut(r,"right")&&(h=e.right-a.right+ut(i,"right")),h||d)if(c)o.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function ym(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:Eh(n.dom)}}function Eh(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=zr(r));return e}function wm({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Th(t,r==0?0:r-e)}function Th(n,e){for(let t=0;t=l){s=Math.max(p.bottom,s),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(o=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?xm(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:Dh(t,i)}function xm(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function ll(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function Sm(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function Cm(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!s&&c.left>r.left||c.top>r.top?i=l.posBefore:(!s&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Oh(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;$r&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=Cm(n,r,i,e))}l==null&&(l=km(n,s,e));let c=n.docView.nearestDesc(s,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Ka(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Br(_t(pt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Ps(c.getBoundingClientRect(),!1)}if(o==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return Ps(c.getBoundingClientRect(),!0)}return Ps(r.getBoundingClientRect(),t>=0)}if(o==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?pt(c,_e(c)-(s?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Br(_t(a,1),!1)}if(o==null&&i<_e(r)){let c=r.childNodes[i];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let a=c?c.nodeType==3?pt(c,0,s?0:1):c.nodeType==1?c:null:null;if(a)return Br(_t(a,-1),!0)}return Br(_t(r.nodeType==3?pt(r):r,-t),t>=0)}function Br(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Ps(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Ih(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Em(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Ih(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Nh(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=pt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?s.top-h.top>(h.bottom-s.top)*2:h.bottom-s.bottom>(s.bottom-h.top)*2))return!1}}return!0})}var Tm=/[\u0590-\u08ac]/;function Dm(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!Tm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Ih(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}var Ya=null,Ga=null,Xa=!1;function Om(n,e,t){return Ya==e&&Ga==t?Xa:(Ya=e,Ga=t,Xa=t=="up"||t=="down"?Em(n,e,t):Dm(n,e,t))}var Ue=0,Qa=1,ln=2,Ge=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Ue,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tte(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof no){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof eo&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?te(o.dom)+1:0}}else{let o,s=!0;for(;o=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=s;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=te(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&st){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+o.border,c=s-o.border;if(e>=l&&t<=c){this.dirty=e==r||t==s?ln:Qa,e==l&&t==c&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Ge:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?ln:Ge}r=s}this.dirty=ln}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?ln:Qa;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=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}},Ws=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 o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=It.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,s.dom,s.contentDOM||s.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&&(o=Gs(o,0,e,r));for(let l=0;l{if(!c)return s;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=_h(h,r,t),a?c=new js(e,t,r,i,h,d||null,f,a,o,s+1):t.isText?new to(e,t,r,i,h,f,o):new n(e,t,r,i,h,d||null,f,o,s+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)&&ro(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,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,c=new Ys(this,s&&s.node,e);vm(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)&&(s&&this.protectLocalComposition(e,s),Rh(this.contentDOM,this.children,e),Kn&&_m(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 o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=Um(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new Ws(this,o,t,i);e.input.compositionNodes.push(s),this.children=Gs(this.children,r,r+i.length,e,s)}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(ro(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=vh(this.dom,this.nodeDOM,Ks(this.outerDeco,this.node,t),Ks(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 Za(n,e,t,r,i){_h(r,e,n);let o=new Pt(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}var to=class n extends Pt{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,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),o=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,o,o,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}},no=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"}},js=class extends Pt{constructor(e,t,r,i,o,s,l,c,a,h){super(e,t,r,i,o,s,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==Ge)return!1;if(this.spec.update){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}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 Rh(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,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[o],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,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,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Rm(n,e){return n.type.side-e.type.side}function vm(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let a=0;ao;)l.push(i[s++]);let p=o+f.nodeSize;if(f.isText){let g=p;s!g.inline):l.slice();r(f,m,e.forChild(o,f),u),o=p}}function _m(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 Um(n,e,t,r){for(let i=0,o=0;i=t){if(o>=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 Gs(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||h<=e?o.push(c):(at&&o.push(c.slice(t-a,c.size,r)))}return o}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),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),c,a;if(ho(t)){for(c=s;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&C.isSelectable(d)&&i.parent&&!(d.isInline&&hm(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;a=new C(s==f?l:r.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=s,f=s;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Uh(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Bm(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 Vh(n,e){if(e instanceof C){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(ih(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else ih(n)}function ih(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 oh(n){return n.editable&&!n.hasFocus()?!1:Bh(n)}function Bh(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 Pm(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 Xs(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&S.findFrom(o,e)}function Ut(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function sh(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return Ut(n,new A(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Xs(n.state,e);return i&&i instanceof C?Ut(n,i):!1}else if(!(ve&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?C.isSelectable(o)?Ut(n,new C(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):$r?Ut(n,new A(n.state.doc.resolve(e<0?l:l+o.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=Xs(n.state,e);return i?Ut(n,i):!1}}}function io(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?Lm(n):zm(n)}function Lm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(qe&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Lr(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Ph(t))break;{let l=t.previousSibling;for(;l&&Lr(l,-1);)i=t.parentNode,o=te(l),l=l.previousSibling;if(l)t=l,r=io(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?Qs(n,t,r):i&&Qs(n,i,o)}function zm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=io(t),o,s;for(;;)if(r{n.state==i&&mt(n)},50)}function lh(n,e){let t=n.state.doc.resolve(e);if(!(ae||um)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function ch(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:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Xs(n.state,e);if(s&&s instanceof C)return Ut(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Te?S.near(s,e):S.findFrom(s,e);return l?Ut(n,l):!1}return!1}function ah(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 o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function hh(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Hm(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;hh(n,r,"true"),setTimeout(()=>hh(n,r,"false"),20)}return!1}function Jm(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function $m(n,e){let t=e.keyCode,r=Jm(e);if(t==8||ve&&t==72&&r=="c")return ah(n,-1)||$n(n,-1);if(t==46&&!e.shiftKey||ve&&t==68&&r=="c")return ah(n,1)||$n(n,1);if(t==13||t==27)return!0;if(t==37||ve&&t==66&&r=="c"){let i=t==37?lh(n,n.state.selection.from)=="ltr"?-1:1:-1;return sh(n,i,r)||$n(n,i)}else if(t==39||ve&&t==70&&r=="c"){let i=t==39?lh(n,n.state.selection.from)=="ltr"?1:-1:1;return sh(n,i,r)||$n(n,i)}else{if(t==38||ve&&t==80&&r=="c")return ch(n,-1,r)||$n(n,-1);if(t==40||ve&&t==78&&r=="c")return Hm(n)||ch(n,1,r)||$n(n,1);if(r==(ve?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Lh(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let s=n.someProp("clipboardSerializer")||It.fromSchema(n.state.schema),l=$h(),c=l.createElement("div");c.appendChild(s.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=Jh[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} ${o}${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 Fh(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let c=e&&(r||o||!t);if(c){if(n.someProp("transformPastedText",f=>{e=f(e,o||r,n)}),o)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);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),s=eg(t),$r&&tg(s);let a=s&&s.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=s.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;s=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!Xm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=ng(fh(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Qm(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 Xm=/^(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 Qm(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)),o,s=[];if(n.forEach(l=>{if(!s)return;let c=i.findWrapping(l.type),a;if(!c)return s=null;if(a=s.length&&o.length&&Hh(c,o,l,s[s.length-1],0))s[s.length-1]=a;else{s.length&&(s[s.length-1]=Jh(s[s.length-1],o.length));let h=qh(l,c);s.push(h),i=i.matchType(h.type),o=c}}),s)return w.from(s)}return n}function qh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function Hh(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function fh(n,e,t){return et}).createHTML(n):n}function eg(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Wh().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&$h[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=Zm(n),i)for(let o=0;o=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),o++,s++}return new b(i,o,s)}var ge={},ye={},rg={touchstart:!0,touchmove:!0},tl=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 ig(n){for(let e in ge){let t=ge[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{sg(n,r)&&!dl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},rg[e]?{passive:!0}:void 0)}me&&n.dom.addEventListener("input",()=>null),nl(n)}function Vt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function og(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 nl(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>dl(n,r))})}function dl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function sg(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 lg(n,e){!dl(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,!Kh(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(He&&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,sn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Gm(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(Kh(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",o=>o(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function fo(n){return{left:n.clientX,top:n.clientY}}function cg(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function fl(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),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 ag(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 hg(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof C&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(C.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(jn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function dg(n,e,t,r,i){return fl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?hg(n,t):ag(n,t))}function fg(n,e,t,r){return fl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function ug(n,e,t,r){return fl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||pg(n,t,r)}function pg(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 o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)jn(n,A.create(r,l+1,l+1+s.content.size),"pointer");else if(C.isSelectable(s))jn(n,C.create(r,l),"pointer");else continue;return!0}}function ul(n){return oo(n)}var jh=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=ul(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&cg(t,n.input.lastClick)&&!t[jh]&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o};let s=n.posAtCoords(fo(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new rl(n,s,t,!!r)):(o=="doubleClick"?fg:ug)(n,s.pos,s.inside,t)?t.preventDefault():Vt(n,"pointer"))};var rl=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 o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let h=e.state.doc.resolve(t.pos);o=h.parent,s=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&&o.type.spec.draggable&&o.type.spec.selectable!==!1||a instanceof C&&a.from<=s&&a.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Je&&!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(fo(e))),this.updateAllowDefault(e),this.allowDefault||!t?Vt(this.view,"pointer"):dg(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(),ul(n),Vt(n,"pointer")};ge.touchmove=n=>{n.input.lastTouch=Date.now(),Vt(n,"pointer")};ge.contextmenu=n=>ul(n);function Kh(n,e){return n.composing?!0:me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var mg=He?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(),oo(n,!0),n.markCursor=null;else if(oo(n,!e.selection.empty),Je&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Yh(n,mg)};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++,Yh(n,20))};function Yh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>oo(n),e))}function Gh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=yg());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function gg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=um(e.focusNode,e.focusOffset),r=pm(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function yg(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function oo(n,e=!1){if(!(He&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Gh(n),e||n.docView&&n.docView.dirty){let t=al(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 wg(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&&bm<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=Fr?null:t.clipboardData,s=r.content(),{dom:l,text:c}=zh(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",c)):wg(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function bg(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function xg(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 o=Fh(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,o||b.empty)))return!0;if(!o)return!1;let s=bg(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Xh(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&&!He)return;let r=Fr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&qr(n,Xh(r),r.getData("text/html"),i,t)?t.preventDefault():xg(n,t)};var so=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Qh=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,o=i.empty?null:n.posAtCoords(fo(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof C?i.to-1:i.to))){if(r&&r.mightDrag)s=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&&(s=C.create(n.state.doc,d.posBefore))}}let l=(s||n.state.selection).content(),{dom:c,text:a,slice:h}=zh(n,l);(!t.dataTransfer.files.length||!ae||Eh>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 so(h,!t[Qh],s)};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(fo(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",p=>{s=p(s,n)}):s=Fh(n,Xh(t.dataTransfer),Fr?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!t[Qh]);if(n.someProp("handleDrop",p=>p(n,t,s||b.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let c=s?va(n.state.doc,o.pos,s):o.pos;c==null&&(c=o.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=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,s.content.firstChild):a.replaceRange(h,h,s),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&C.isSelectable(s.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(s.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(hl(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&&He&&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",o=>o(n,sn(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 lo=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:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new ne(o-r,o-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 o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new ne(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}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,o){let s;for(let l=0;l{let a=c+r,h;if(h=ed(t,l,a)){for(i||(i=this.children.slice());ol&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&c.type instanceof an){let a=Math.max(o,c.from)-o,h=Math.min(s,c.to)-o;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]+o,-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]+o+1,s);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=kg(l,n,e,t,i,o,s),h=ao(a,r,0,s);e=h.local;for(let d=0;dt&&s.to{let a=ed(n,l,c+t);if(a){o=!0;let h=ao(a,l,t+c+1,r);h!=ce&&i.push(c,c+l.nodeSize,h)}});let s=Zh(o?td(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function Fs(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])),co.from(e)}var Cg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Mg=ke&&Bt<=11,ol=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 ol,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,Cg)),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(sh(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 o=e.focusNode;o;o=zr(o))t.add(o);for(let o=e.anchorNode;o;o=zr(o))if(t.has(o)){r=o;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)&&sh(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),o=-1,s=-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||Tg(e,d)!=u)&&f.remove()}}}let a=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),Ag(e)),this.handleDOMChange(o,s,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){o=g;break}if(!E||E.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(s),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:o,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:Og,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+s,head:y+s}}return{doc:m,sel:p,from:s,to:l}}function Og(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 Ng=/^(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 Ig(n,e,t,r,i){let o=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=al(n,T);if(Nt&&!n.state.selection.eq(Nt)){if(ae&&He&&n.input.lastKeyCode===13&&Date.now()-100wp(n,sn(13,"Enter"))))return;let Bi=n.state.tr.setSelection(Nt);T=="pointer"?Bi.setMeta("pointer",!0):T=="key"&&Bi.scrollIntoView(),o&&Bi.setMeta("composition",o),n.dispatch(Bi)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=Dg(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||He)&&i.some(T=>T.nodeType==1&&!Ng.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,sn(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=wh(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let Nt=n.state.tr.setSelection(T);o&&Nt.setMeta("composition",o),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,sn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&vg(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,sn(8,"Backspace")))){He&&ae&&n.domObserver.suppressSelectionUpdates();return}ae&&He&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),He&&!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,sn(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=Rg(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=wh(n,Y.doc,a.sel);T&&!(ae&&He&&n.composing&&T.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:hl(n,e.resolve(t.anchor),e.resolve(t.head))}function Rg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||qs(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function _g(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,o-Math.min(s,l));r-=s+c-o}if(s=s?o-r:0;o-=c,o&&o=l?o-r:0;o-=c,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}var ll=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 tl,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Mh),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=kh(this),Sh(this),this.nodeViews=Ch(this),this.docView=eh(this.state.doc,xh(this),Fs(this),this.dom,this),this.domObserver=new sl(this,(r,i,o,s)=>Ig(this,r,i,o,s)),this.domObserver.start(),ig(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&&nl(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Mh),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,o=!1,s=!1;e.storedMarks&&this.composing&&(Gh(this),s=!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=Ch(this);Vg(u,this.nodeViews)&&(this.nodeViews=u,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&nl(this),this.editable=kh(this),Sh(this);let c=Fs(this),a=xh(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=o||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(s=!0);let f=h=="preserve"&&s&&this.dom.style.overflowAnchor==null&&km(this);if(s){this.domObserver.stop();let u=d&&(ke||ae)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Ug(i.selection,e.selection);if(d){let p=ae?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=gg(this)),(o||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=eh(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Hm(this))?mt(this,u):(Bh(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&&Cm(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&&Ka(this,t.getBoundingClientRect(),e)}else Ka(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(o))==r.node&&(i=o)}this.dragging=new so(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 s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Om(this,e)}coordsAtPos(e,t=1){return Ih(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 _m(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&&(og(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Fs(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,dm())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return lg(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&&gm(this.dom.ownerDocument)==this.dom&&Eg(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function xh(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 Sh(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 kh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Ug(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 Ch(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 Vg(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 Mh(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 Bg=["p",0],Pg=["blockquote",0],Lg=["hr"],zg=["pre",["code",0]],Fg=["br"],qg={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Bg}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Pg}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Lg}},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 zg}},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 Fg}}},Hg=["em",0],Jg=["strong",0],$g=["code",0],Wg={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 Hg}},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 Jg}},code:{parseDOM:[{tag:"code"}],toDOM(){return $g}}},jg=new Dr({nodes:qg,marks:Wg});var rd=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Kg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Yg=(n,e,t)=>{let r=Kg(n,t);if(!r)return!1;let i=id(r);if(!i){let s=r.blockRange(),l=s&&nn(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(ld(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Gn(o,"end")||C.isSelectable(o)))for(let s=r.depth;;s--){let l=Xi(n.doc,r.before(s),r.after(s),b.empty);if(l&&l.slice.size1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-o.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 Gg=(n,e,t)=>{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=id(r)}let s=o&&o.nodeBefore;return!s||!C.isSelectable(s)?!1:(e&&e(n.tr.setSelection(C.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function id(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 Xg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Xg(n,t);if(!r)return!1;let i=od(r);if(!i)return!1;let o=i.nodeAfter;if(ld(n,i,e,1))return!0;if(r.parent.content.size==0&&(Gn(o,"start")||C.isSelectable(o))){let s=Xi(n.doc,r.before(),r.after(),b.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=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=vs(n.doc,t.from,-1),i==null)return!1;if(e){let o=n.tr.join(i);r&&o.setSelection(C.create(o.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(o.scrollIntoView())}return!0},sd=(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=vs(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),o=i&&nn(i);return o==null?!1:(e&&e(n.tr.lift(i,o).scrollIntoView()),!0)},ey=(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 gl(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),o=t.indexAfter(-1),s=gl(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,s.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},ty=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Te||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=gl(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!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 o=t.before();if(Rt(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function ry(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 o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof A||e.selection instanceof Te)&&s.deleteSelection();let l=r.depth==0?null:gl(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,o,r),a=c?[c]:o&&l?[{type:l}]:void 0,h=Rt(s.doc,s.mapping.map(r.pos),1,a);if(!a&&!h&&Rt(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(s.split(s.mapping.map(r.pos),1,a),!o&&!r.parentOffset&&r.parent.type!=l){let d=s.mapping.map(r.before()),f=s.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}return t&&t(s.scrollIntoView()),!0}}var iy=ry();var Kr=(n,e)=>{let{$from:t,to:r}=n.selection,i,o=t.sharedDepth(r);return o==0?!1:(i=t.before(o),e&&e(n.tr.setSelection(C.create(n.doc,i))),!0)},oy=(n,e)=>(e&&e(n.tr.setSelection(new Te(n.doc))),!0);function sy(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||rn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function ld(n,e,t,r){let i=e.nodeBefore,o=e.nodeAfter,s,l,c=i.type.spec.isolating||o.type.spec.isolating;if(!c&&sy(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(s=(l=i.contentMatchAt(i.childCount)).findWrapping(o.type))&&l.matchType(s[0]||o.type).validEnd){if(t){let u=e.pos+o.nodeSize,p=w.empty;for(let y=s.length-1;y>=0;y--)p=w.from(s[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),s.length,!0)),g=m.doc.resolve(u+2*s.length);g.nodeAfter&&g.nodeAfter.type==i.type&&rn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=o.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(o,"start",!0)&&Gn(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=o,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+o.nodeSize,e.pos+g,e.pos+o.nodeSize-g,new b(y,p.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function cd(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}var ly=cd(-1),cy=cd(1);function Xn(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o),l=s&&Gi(s,n,e);return l?(r&&r(t.tr.wrap(s,l).scrollIntoView()),!0):!1}}function pn(n,e=null){return function(t,r){let i=!1;for(let o=0;o{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 o=t.tr;for(let s=0;s{if(l||!r&&c.isAtom&&c.isInline&&a>=o.pos&&a+c.nodeSize<=s.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function hy(n){let e=[];for(let t=0;t{if(o.isAtom&&o.content.size&&o.isInline&&s>=r.pos&&s+o.nodeSize<=i.pos)return s+1>r.pos&&e.push(new vt(r,r.doc.resolve(s+1))),r=r.doc.resolve(s+1+o.content.size),!1}),r.poso.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(s.depth-1).type.compatibleContent(n)&&s.startIndex==0){if(i.index(s.depth-1)==0)return!1;let h=t.doc.resolve(s.start-2);c=new Zt(h,h,s.depth),s.endIndex=0;h--)o=w.from(t[h].type.create(t[h].attrs,o));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(o,0,0),t.length,!0));let s=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=o.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,o.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 xl(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?xy(e,t,n,o):Sy(e,t,o):!0:!1}}function xy(n,e,t,r){let i=n.tr,o=r.end,s=r.$to.end(r.depth);om;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let o=r.doc.resolve(t.start),s=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=o.node(-1),h=o.index(-1);if(!a.canReplace(h+(l?0:1),h+1,s.content.append(c?w.empty:w.from(i))))return!1;let d=o.pos,f=d+s.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 Sl(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let l=o.parent,c=l.child(s-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=o.start,u=o.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:"'"},mo={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ky=typeof navigator<"u"&&/Mac/.test(navigator.platform),Cy=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),mo[J]=String.fromCharCode(J);var J;for(po in yt)mo.hasOwnProperty(po)||(mo[po]=yt[po]);var po;function dd(n){var e=ky&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Cy&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?mo: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 Ay(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=yt[r.keyCode])&&o!=i){let l=e[kl(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var go=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(o,s){return i.push(e(o,s))},t,r),i};re.from=function(e){return e instanceof re?e:e&&e.length?new fd(e):re.empty};var fd=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,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,l){for(var c=o;c=s;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=go)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=go)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 fd([]);var Dy=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,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(o,l)-l,s+l)===!1||o=o?this.right.slice(r-o,i-o):this.left.slice(r,o).append(this.right.slice(0,i-o))},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),Cl=re;var Oy=500,yo=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,o;t&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,l,c,a=[],h=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),o=i.maps.length),o--,h.push(d);return}if(i){h.push(new Xe(d.map));let u=d.step.map(i.slice(o)),p;u&&s.maybeStep(u).doc&&(p=s.mapping.maps[s.mapping.maps.length-1],a.push(new Xe(p,void 0,void 0,a.length+h.length))),o--,p&&i.appendMap(p,o)}else s.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(o)):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:s,selection:l}}addTransform(e,t,r,i){let o=[],s=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hIy&&(l=Ny(l,a),s-=a),new n(l.append(o),s)}remapping(e,t){let r=new Rr;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},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),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let c=t;this.items.forEach(f=>{let u=o.getMirror(--c);if(u==null)return;s=Math.min(s,u);let p=o.maps[u];if(f.step){let m=e.steps[u].invert(e.docs[u]),g=f.selection&&f.selection.map(o.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;fOy&&(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=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let c=s.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=s.selection&&s.selection.map(t.slice(r));h&&o++;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 s.map&&r--},this.items.length,0),new n(Cl.from(i.reverse()),o)}};yo.empty=new yo(Cl.empty,0);function Ny(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)}}},Al=class{constructor(e,t,r,i,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},Iy=20;function Ry(n,e,t){let r=vy(e),i=El.get(e).spec.config,o=(t?n.undone:n.done).popEvent(e,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),l=(t?n.done:n.undone).addTransform(o.transform,e.selection.getBookmark(),i,r),c=new Al(t?l:o.remaining,t?o.remaining:l,null,0,-1);return o.transform.setSelection(s).setMeta(El,{redo:t,historyState:c})}var Ml=!1,ud=null;function vy(n){let e=n.plugins;if(ud!=e){Ml=!1,ud=e;for(let t=0;t{let i=El.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let o=Ry(i,t,n);o&&r(e?o.scrollIntoView():o)}return!0}}var Xr=wo(!1,!0),Qn=wo(!0,!0),xx=wo(!1,!1),Sx=wo(!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 Tl(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!_y(e)||!Uy(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,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!C.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),r=!1;continue e}break}o=s,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 Tl=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 _y(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 Uy(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 Vy(){return new H({props:{decorations:zy,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:Py,handleKeyDown:By,handleDOMEvents:{beforeinput:Ly}}})}var By=Gr({ArrowLeft:bo("horiz",-1),ArrowRight:bo("horiz",1),ArrowUp:bo("vert",-1),ArrowDown:bo("vert",1)});function bo(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,c=s.empty;if(s instanceof A){if(!o.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 Py(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 Ly(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 s=r.length-1;s>=0;s--)i=w.from(r[s].createAndFill(null,i));let o=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return o.setSelection(A.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function zy(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&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var qy=500;function gd({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,o){return md(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&md(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function md(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-qy),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a{let t=n.plugins;for(let r=0;r=0;c--)s.step(l.steps[c].invert(l.docs[c]));if(o.text){let c=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,n.schema.text(o.text,c))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},Hy=new bt(/--$/,"\u2014"),Jy=new bt(/\.\.\.$/,"\u2026"),Nx=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Ix=new bt(/"$/,"\u201D"),Rx=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),vx=new bt(/'$/,"\u2019");var wd=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function $y(n,e){let t={},r;function i(o,s){if(e){let l=e[o];if(l===!1)return;l&&(o=l)}t[o]=s}if(i("Mod-z",Xr),i("Shift-Mod-z",Qn),i("Backspace",yd),wd||i("Mod-y",Qn),i("Alt-ArrowUp",Wr),i("Alt-ArrowDown",sd),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",uo(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",uo(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Xn(r)),r=n.nodes.hard_break){let o=r,s=Yr(yl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(o.create()).scrollIntoView()),!0));i("Mod-Enter",s),i("Shift-Enter",s),wd&&i("Ctrl-Enter",s)}if((r=n.nodes.list_item)&&(i("Enter",bl(r)),i("Mod-[",xl(r)),i("Mod-]",Sl(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 o=1;o<=6;o++)i("Shift-Ctrl-"+o,pn(r,{level:o}));if(r=n.nodes.horizontal_rule){let o=r;i("Mod-_",(s,l)=>(l&&l(s.tr.replaceSelectionWith(o.create()).scrollIntoView()),!0))}return t}var Ol,Nl;if(typeof WeakMap<"u"){let n=new WeakMap;Ol=e=>n.get(e),Nl=(e,t)=>(n.set(e,t),t)}else{let n=[],t=0;Ol=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var _=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){(o||(o=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Se=i+N*e;for(let pe=0;per&&(o+=a.attrs.colspan)}}for(let s=0;s1&&(t=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function Ky(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(s)):null,i=Number(n.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let s in e){let l=e[s].getFromDOM,c=l&&l(n);c!=null&&(o[s]=c)}return o}function xd(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 Gy(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=>bd(r,e)}],toDOM(r){return["td",xd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>bd(r,e)}],toDOM(r){return["th",xd(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 Xy(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 Be(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 _l(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)||Qy(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Qy(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 Il(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Zy(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function Ul(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function Od(n,e,t){let r=n.node(-1),i=_.get(r),o=n.start(-1),s=i.nextCell(n.pos-o,e,t);return s==null?null:n.node(0).resolve(o+s)}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 Nd(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-o);c.unshift(t.pos-o);let a=c.map(h=>{let d=r.nodeAt(h);if(!d)throw RangeError(`No cell with offset ${h} found`);let f=o+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(Il(r)&&Il(i)&&Ul(r,i)){let o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?xt.rowSelection(r,i):o&&this.isColSelection()?xt.colSelection(r,i):new xt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=_.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];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=_.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),c=e.node(0);return s.top<=l.top?(s.top>0&&(e=c.resolve(o+i.map[s.left])),l.bottom0&&(t=c.resolve(o+i.map[l.left])),s.bottom0)return!1;let s=i+this.$anchorCell.nodeAfter.attrs.colspan,l=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,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=_.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),c=e.node(0);return s.left<=l.left?(s.left>0&&(e=c.resolve(o+i.map[s.top*i.width])),l.right0&&(t=c.resolve(o+i.map[l.top*i.width])),s.right{e.push(ne.node(r,r+t.nodeSize,{class:"selectedCell"}))}),z.create(n.doc,e)}function r0({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(o+1)>e.start(o));o--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function i0({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let o=n.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){t=o;break}}for(let i=e.depth;i>0;i--){let o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return t!==r&&e.parentOffset===0}function o0(n,e,t){let r=(e||n).selection,i=(e||n).doc,o,s;if(r instanceof C&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=B.create(i,r.from);else if(s=="row"){let l=i.resolve(r.from+1);o=B.rowSelection(l,l)}else if(!t){let l=_.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];o=B.create(i,c+1,a)}}else r instanceof A&&r0(r)?o=A.create(i,r.from):r instanceof A&&i0(r)&&(o=A.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=n.tr)).setSelection(o),e}var s0=new le("fix-tables");function Rd(n,e,t,r){let i=n.childCount,o=e.childCount;e:for(let s=0,l=0;s{i.type.spec.tableRole=="table"&&(t=l0(n,i,o,t))};return e?e.doc!=n.doc&&Rd(e.doc,n.doc,0,r):n.doc.descendants(r),t}function l0(n,e,t,r){let i=_.get(e);if(!i.problems)return r;r||(r=n.tr);let o=[];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;e0(e,r,i+o)&&(o=i==0||i==e.width?null:0);for(let s=0;s0&&i0&&e.map[l-1]==c||i0?-1:0;a0(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[o]==t[o-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function p0(n){return(e,t)=>{var r;let i=e.selection,o,s;if(i instanceof B){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;o=i.$anchorCell.nodeAfter,s=i.$anchorCell.pos}else{if(o=Xy(i.$from),!o)return!1;s=(r=Zn(i.$from))==null?void 0:r.pos}if(o==null||s==null||o.attrs.colspan==1&&o.attrs.rowspan==1)return!1;if(t){let l=o.attrs,c=[],a=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});let h=Pe(e),d=e.tr;for(let u=0;ui.table.nodeAt(c));for(let c=0;c{let p=u+o.tableStart,m=s.doc.nodeAt(p);m&&s.setNodeMarkup(p,f,m.attrs)}),r(s)}return!0}}var tS=Pl("row",{useDeprecatedLogic:!0}),nS=Pl("column",{useDeprecatedLogic:!0}),rS=Pl("cell",{useDeprecatedLogic:!0});function g0(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 o=n.node(-1).child(r),s=o.lastChild;if(s)return i-1-s.nodeSize;i-=o.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 xo(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((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function b0(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),o=i.type.spec.tableRole,s=i.type.schema,l=[];if(o=="row")for(let c=0;c=0;s--){let{rowspan:l,colspan:c}=o.child(s).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)}o.push(w.from(c))}t=o,e=i}return{width:n,height:e,rows:t}}function k0(n,e,t,r,i,o,s){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 o=t.selection;if(o instanceof B)return Co(t,r,S.near(o.$headCell,e));if(n!="horiz"&&!o.empty)return!1;let s=zd(i,n,e);if(s==null)return!1;if(n=="horiz")return Co(t,r,S.near(t.doc.resolve(o.head+e),e));{let l=t.doc.resolve(s),c=Od(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),Co(t,r,a)}}}function ko(n,e){return(t,r,i)=>{if(!i)return!1;let o=t.selection,s;if(o instanceof B)s=o;else{let c=zd(i,n,e);if(c==null)return!1;s=new B(t.doc.resolve(c))}let l=Od(s.$headCell,n,e);return l?Co(t,r,new B(s.$anchorCell,l)):!1}}function M0(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 A0(n,e,t){if(!Be(n.state))return!1;let r=b0(t),i=n.state.selection;if(i instanceof B){r||(r={width:1,height:1,rows:[w.from(Rl(de(n.state.schema).cell,t))]});let o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),l=_.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=S0(r,l.right-l.left,l.bottom-l.top),Ad(n.state,n.dispatch,s,l,r),!0}else if(r){let o=_l(n.state),s=o.start(-1);return Ad(n.state,n.dispatch,s,_.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function E0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Ed(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof B)o(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Zn(n.state.selection.$anchor))!=null&&((t=Dl(n,e))==null?void 0:t.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(c,a){let h=Dl(n,a),d=zt.getState(n.state)==null;if(!h||!Ul(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 s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),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(Ed(n,a.target)!=r&&(d=Dl(n,e),!d))return s();d&&o(d,a)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",l)}function zd(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 o=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.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 Ed(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Dl(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Zn(n.state.doc.resolve(t.pos)):null}var T0=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")),vl(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,vl(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function vl(n,e,t,r,i,o){var s;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 O0(-1,!1)},apply(o,s){return s.apply(o)}},props:{attributes:o=>{let s=Ve.getState(o);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,s)=>{N0(o,s,n,e,r)},mouseleave:o=>{I0(o)},mousedown:(o,s)=>{R0(o,s,e)}},decorations:o=>{let s=Ve.getState(o);if(s&&s.activeHandle>-1)return P0(o,s.activeHandle)},nodeViews:{}}});return i}var O0=class Mo{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 Mo(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Mo(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Il(e.doc.resolve(i))||(i=-1),new Mo(i,t.dragging)}return t}};function N0(n,e,t,r,i){let o=Ve.getState(n.state);if(o&&!o.dragging){let s=_0(e.target),l=-1;if(s){let{left:c,right:a}=s.getBoundingClientRect();e.clientX-c<=t?l=Td(n,e,"left",t):a-e.clientX<=t&&(l=Td(n,e,"right",t))}if(l!=o.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=_.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}Fd(n,l)}}}function I0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Fd(n,-1)}function R0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,o=Ve.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;let s=n.state.doc.nodeAt(o.activeHandle),l=v0(n,o.activeHandle,s.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&&(U0(n,d.activeHandle,Dd(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=Dd(d.dragging,h,t);V0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function v0(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let o=n.domAtPos(e),l=o.node.childNodes[o.offset].offsetWidth,c=t;if(r)for(let a=0;ajo,AbstractConnector:()=>fc,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:()=>pc,RelativePosition:()=>st,Skip:()=>ie,Snapshot:()=>jt,Text:()=>ct,Transaction:()=>Yo,UndoManager:()=>Tn,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>ot,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>at,XmlHook:()=>Si,XmlText:()=>xe,YArrayEvent:()=>Qo,YEvent:()=>Dn,YMapEvent:()=>Zo,YTextEvent:()=>es,YXmlEvent:()=>ts,applyUpdate:()=>Ac,applyUpdateV2:()=>vn,cleanupYTextFormatting:()=>Vu,compareIDs:()=>kn,compareRelativePositions:()=>rs,convertUpdateFormatV1ToV2:()=>u1,convertUpdateFormatV2ToV1:()=>bu,createAbsolutePositionFromRelativePosition:()=>Nc,createDeleteSet:()=>br,createDeleteSetFromStructStore:()=>kc,createDocFromSnapshot:()=>Qw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>Ci,createSnapshot:()=>Mi,decodeRelativePosition:()=>jw,decodeSnapshot:()=>Gw,decodeSnapshotV2:()=>su,decodeStateVector:()=>Tc,decodeUpdate:()=>s1,decodeUpdateV2:()=>uu,diffUpdate:()=>h1,diffUpdateV2:()=>Ic,emptySnapshot:()=>Xw,encodeRelativePosition:()=>$w,encodeSnapshot:()=>Yw,encodeSnapshotV2:()=>ou,encodeStateAsUpdate:()=>Ec,encodeStateAsUpdateV2:()=>nu,encodeStateVector:()=>Oc,encodeStateVectorFromUpdate:()=>l1,encodeStateVectorFromUpdateV2:()=>mu,equalDeleteSets:()=>eu,equalSnapshots:()=>Kw,findIndexSS:()=>qe,findRootTypeKey:()=>_n,getItem:()=>Cn,getState:()=>P,getTypeChildren:()=>y1,isDeleted:()=>Tt,isParentOf:()=>En,iterateDeletedStructs:()=>rt,logType:()=>Fw,logUpdate:()=>o1,logUpdateV2:()=>fu,mergeDeleteSets:()=>Mn,mergeUpdates:()=>pu,mergeUpdatesV2:()=>yi,obfuscateUpdate:()=>d1,obfuscateUpdateV2:()=>f1,parseUpdateMeta:()=>c1,parseUpdateMetaV2:()=>gu,readUpdate:()=>Bw,readUpdateV2:()=>Mc,relativePositionToJSON:()=>qw,snapshot:()=>Ai,snapshotContainsUpdate:()=>e1,transact:()=>R,tryGc:()=>r1,typeListToArraySnapshot:()=>cs,typeMapGetAllSnapshot:()=>Iu,typeMapGetSnapshot:()=>x1});var U=()=>new Map,Ao=n=>{let e=U();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},qd=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Hd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var Eo=n=>n[n.length-1];var Jd=(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)||U()).values()).forEach(r=>r(...t))}destroy(){this._observers=U()}},tr=class{constructor(){this._observers=U()}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)||U()).values()).forEach(r=>r(...t))}destroy(){this._observers=U()}};var fe=Math.floor;var nr=Math.abs;var De=(n,e)=>nn>e?n:e,fS=Number.isNaN,jd=Math.pow;var Do=n=>n!==0?n<0:1/n<0;var Ll=Number.MAX_SAFE_INTEGER,uS=Number.MIN_SAFE_INTEGER,pS=1<<31;var Kd=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&fe(n)===n),mS=Number.isNaN,gS=Number.parseInt;var zl=String.fromCharCode,yS=String.fromCodePoint,wS=zl(65535),z0=n=>n.toLowerCase(),F0=/^\s*/g,q0=n=>n.replace(F0,""),H0=/([A-Z])/g,Fl=(n,e)=>q0(n.replace(H0,t=>`${e}${z0(t)}`));var J0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;iir.encode(n),Gd=ir?$0:J0;var rr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});rr&&rr.decode(new Uint8Array).length===1&&(rr=null);var Xd=(n,e)=>Wd(e,()=>n).join("");var wn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},F=()=>new wn;var No=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(No(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=Do(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)},ql=new Uint8Array(3e4),j0=ql.length/3,K0=(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),o=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,o>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Le(t*2,o)),n.cbuf.set(e.subarray(i)),n.cpos=o)},V=(n,e)=>{x(n,e.byteLength),ar(n,e)},Hl=(n,e)=>{W0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},G0=(n,e)=>Hl(n,4).setFloat32(0,e,!1),X0=(n,e)=>Hl(n,8).setFloat64(0,e,!1),Q0=(n,e)=>Hl(n,8).setBigInt64(0,e,!1);var Zd=new DataView(new ArrayBuffer(4)),Z0=n=>(Zd.setFloat32(0,n),Zd.getFloat32(0)===n),sr=(n,e)=>{switch(typeof e){case"string":Q(n,119),Qe(n,e);break;case"number":Kd(e)&&nr(e)<=2147483647?(Q(n,125),ni(n,e)):Z0(e)?(Q(n,124),G0(n,e)):(Q(n,123),X0(n,e));break;case"bigint":Q(n,122),Q0(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 ef=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++:(ef(this),this.count=1,this.s=e)}toUint8Array(){return ef(this),I(this.encoder)}};var tf=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++):(tf(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return tf(this),I(this.encoder)}},Oo=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 rf=Ze("Unexpected end of array"),of=Ze("Integer out of Range"),hr=class{constructor(e){this.arr=e,this.pos=0}},q=n=>new hr(n),Jl=n=>n.pos!==n.arr.length;var ew=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>ew(n,k(n));var xn=n=>n.arr[n.pos++];var k=n=>{let e=0,t=1,r=n.arr.length;for(;n.posLl)throw of}throw rf},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 o=n.arr.length;for(;n.posLl)throw of}throw rf};var tw=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))}},nw=n=>rr.decode(K(n)),Fe=rr?nw:tw;var $l=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},rw=n=>$l(n,4).getFloat32(0,!1),iw=n=>$l(n,8).getFloat64(0,!1),ow=n=>$l(n,8).getBigInt64(0,!1);var sw=[n=>{},n=>null,ii,rw,iw,ow,n=>!1,n=>!0,Fe,n=>{let e=k(n),t={};for(let r=0;r{let e=k(n),t=[];for(let r=0;rsw[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),Jl(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=Do(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}},vo=class{constructor(e){this.decoder=new Sn(e),this.str=Fe(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 SS=crypto.subtle,sf=crypto.getRandomValues.bind(crypto);var lw=Math.random,Wl=()=>sf(new Uint32Array(1))[0];var lf=n=>n[fe(lw()*n.length)],cw="10000000-1000-4000-8000"+-1e11,cf=()=>cw.replace(/[018]/g,n=>(n^Wl()&15>>n/4).toString(16));var Ne=Date.now;var jl=n=>new Promise(n);var MS=Promise.all.bind(Promise);var Kl=n=>n===void 0?null:n;var Yl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},hf=new Yl,Gl=!0;try{typeof localStorage<"u"&&localStorage&&(hf=localStorage,Gl=!1)}catch{}var Uo=hf,df=n=>Gl||addEventListener("storage",n),ff=n=>Gl||removeEventListener("storage",n);var mf=Object.assign,Vo=Object.keys,gf=(n,e)=>{for(let t in n)e(n[t],t)},yf=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Xl=n=>Vo(n).length,pf=n=>Vo(n).length;var wf=n=>{for(let e in n)return!1;return!0},dw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Ql=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Zl=(n,e)=>n===e||pf(n)===pf(e)&&dw(n,(t,r)=>(t!==void 0||Ql(e,r))&&e[r]===t),fw=Object.freeze,ec=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&ec(n[e])}return fw(n)};var si=(n,e,t=0)=>{try{for(;tn,uw=(n,e)=>n===e;var ur=(n,e)=>{if(n==null||e==null)return uw(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,AS=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,et,pw=[],mw=()=>{if(et===void 0)if(kt){et=U();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");et.set(`--${Fl(e,"-")}`,t),et.set(`-${Fl(e,"-")}`,t)}})):et=U();return et},rc=n=>mw().has(n);var li=n=>kt?Kl(process.env[n.toUpperCase().replaceAll("-","_")]):Kl(Uo.getItem(n));var xf=n=>rc("--"+n)||li(n)!==null,ES=xf("production"),gw=kt&&bf(process.env.FORCE_COLOR,["true","1","2"]),Sf=gw||!rc("--no-colors")&&!xf("no-color")&&(!kt||process.stdout.isTTY)&&(!kt||rc("--color")||li("COLORTERM")!==null||(li("TERM")||"").includes("color"));var kf=n=>new Uint8Array(n),yw=(n,e,t)=>new Uint8Array(n,e,t),Cf=n=>new Uint8Array(n),ww=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),xw=n=>{let e=atob(n),t=kf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return yw(e.buffer,e.byteOffset,e.byteLength)},Mf=pr?ww:bw,Af=pr?xw:Sw;var Ef=n=>{let e=kf(n.byteLength);return e.set(n),e};var ic=class{constructor(e,t){this.left=e,this.right=t}},tt=(n,e)=>new ic(n,e);var Ct=typeof document<"u"?document:{};var TS=typeof DOMParser<"u"?new DOMParser:null;var Df=n=>qd(n,(e,t)=>`${t}:${e};`).join("");var DS=Ct.ELEMENT_NODE,OS=Ct.TEXT_NODE,NS=Ct.CDATA_SECTION_NODE,IS=Ct.COMMENT_NODE,RS=Ct.DOCUMENT_NODE,vS=Ct.DOCUMENT_TYPE_NODE,_S=Ct.DOCUMENT_FRAGMENT_NODE;var Po=n=>class{constructor(t){this._=t}destroy(){n(this._)}},Cw=Po(clearTimeout),ai=(n,e)=>new Cw(setTimeout(e,n)),VS=Po(clearInterval);var BS=Po(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var PS=Po(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var nt=Symbol;var hi=nt(),di=nt(),oc=nt(),sc=nt(),lc=nt(),fi=nt(),cc=nt(),mr=nt(),ac=nt(),If=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=U(),i=[],o=0;for(;o0||c.length>0?(e.push("%c"+s),t.push(c)):e.push(s)}else break}}for(o>0&&(i=t,i.unshift(e.join("")));o{console.log(...Rf(n)),vf.forEach(e=>e.print(n))},hc=(...n)=>{console.warn(...Rf(n)),n.unshift(mr),vf.forEach(e=>e.print(n))};var vf=Ce();var _f=n=>({[Symbol.iterator](){return this},next:n}),Uf=(n,e)=>_f(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),zo=(n,e)=>_f(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var fc=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 o=n.doc.store.clients.get(i);for(let s=0;s{let t=0,r=n.length-1;for(;t<=r;){let i=fe((t+r)/2),o=n[i],s=o.clock;if(s<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&Rw(t,e.clock)!==null},Sc=n=>{n.clients.forEach(e=>{e.sort((i,o)=>i.clock-o.clock);let t,r;for(t=1,r=1;t=o.clock?i.len=Le(i.len,o.clock+o.len-i.clock):(r{let e=new $t;for(let t=0;t{if(!e.clients.has(i)){let o=r.slice();for(let s=t+1;s{$(n.clients,e,()=>[]).push(new pi(t,r))},br=()=>new $t,kc=n=>{let e=br();return n.clients.forEach((t,r)=>{let i=[];for(let o=0;o0&&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 o=0;o{let e=new $t,t=k(n.restDecoder);for(let r=0;r0){let s=$(e.clients,i,()=>[]);for(let l=0;l{let r=new $t,i=k(n.restDecoder);for(let o=0;o0){let o=new Ie;return x(o.restEncoder,0),it(o,r),o.toUint8Array()}return null},eu=(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 o=0;o!0,meta:o=null,autoLoad:s=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=tu(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ko,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=s,this.meta=o,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 o=new t;return o._integrate(this,null),o}),i=r.constructor;if(t!==W&&i!==t)if(i===W){let o=new t;o._map=r._map,r._map.forEach(s=>{for(;s!==null;s=s.left)s.parent=o}),o._start=r._start;for(let s=o._start;s!==null;s=s.right)s.parent=o;return o._length=r._length,this.share.set(e,o),o._integrate(this,null),o}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 Fe(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 Ef(K(this.restDecoder))}readJSON(){return JSON.parse(Fe(this.restDecoder))}readKey(){return Fe(this.restDecoder)}},Wo=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 Wo{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 vo(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=Le(r,e[0].id.clock);let i=qe(e,r);x(n.restEncoder,e.length-i),n.writeClient(t),x(n.restEncoder,r);let o=e[i];o.write(n,r-o.id.clock);for(let s=i+1;s{let r=new Map;t.forEach((i,o)=>{P(e,o)>i&&r.set(o,i)}),Ei(e).forEach((i,o)=>{t.has(o)||r.set(o,0)}),x(n.restEncoder,r.size),$e(r.entries()).sort((i,o)=>o[0]-i[0]).forEach(([i,o])=>{vw(n,e.clients.get(i),i,o)})},_w=(n,e)=>{let t=U(),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 o=()=>{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},s=o();if(s===null)return null;let l=new Ko,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=s.refs[s.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(s!==null&&s.i0){let u=new Ie;return Cc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},Vw=(n,e)=>Cc(n,e.doc.store,e.beforeState),Mc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let o=!1,s=i.doc,l=s.store,c=_w(r,s),a=Uw(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=Pf(r,i,l);if(l.pendingDs){let f=new be(q(l.pendingDs));k(f.restDecoder);let u=Pf(f,i,l);d&&u?l.pendingDs=yi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(o){let f=l.pendingStructs.update;l.pendingStructs=null,vn(i.doc,f)}},t,!1),Bw=(n,e,t)=>Mc(n,e,t,new Me(n)),vn=(n,e,t,r=be)=>{let i=q(e);Mc(i,n,t,new r(i))},Ac=(n,e,t)=>vn(n,e,t,Me),Pw=(n,e,t=new Map)=>{Cc(n,e.store,t),it(n,kc(e.store))},nu=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Tc(e);Pw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Ic(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===ot)return pu(i.map((o,s)=>s===0?o:bu(o)));if(t.constructor===Ie)return yi(i)}return i[0]},Ec=(n,e)=>nu(n,e,new ot),ru=n=>{let e=new Map,t=k(n.restDecoder);for(let r=0;rru(new An(q(n))),Dc=(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),Lw=(n,e)=>Dc(n,Ei(e.store)),zw=(n,e=new gr)=>(n instanceof Map?Dc(e,n):Lw(e,n),e.toUint8Array()),Oc=n=>zw(n,new Wt),uc=class{constructor(){this.l=[]}},Lf=()=>new uc,zf=(n,e)=>n.l.push(e),Ff=(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.")},iu=(n,e,t)=>si(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),qf=(n,e)=>{x(n,e.client),x(n,e.clock)},Hf=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},Fw=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))},pc=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=(o,s)=>{let l=o.get("ds"),c=o.get("ids"),a=h=>this.clients.set(h,s);l.observe(h=>{h.changes.added.forEach(d=>{d.content.getContent().forEach(f=>{f instanceof Uint8Array&&this.dss.set(s,Mn([this.dss.get(s)||br(),At(new An(q(f)))]))})})}),this.dss.set(s,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(o=>{o.keysChanged.forEach(s=>i(t.get(s),s))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let o=this.yusers,s=o.get(r);s||(s=new Nn,s.set("ids",new On),s.set("ds",new On),o.set(r,s)),s.get("ids").push([t]),o.observe(l=>{setTimeout(()=>{let c=o.get(r);if(c!==s){s=c,this.clients.forEach((d,f)=>{r===d&&s.get("ids").push([f])});let a=new Wt,h=this.dss.get(r);h&&(it(a,h),s.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=s.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}},st=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},qw=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 st(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),jo=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},Hw=(n,e,t=0)=>new jo(n,e,t),Fo=(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 st(r,i,e,t)},Ci=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return Fo(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Fo(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Fo(n,r.lastId,t);r=r.right}return Fo(n,null,t)},Jw=(n,e)=>{let{type:t,tname:r,item:i,assoc:o}=e;if(i!==null)x(n,0),qf(n,i);else if(r!==null)cr(n,1),Qe(n,r);else if(t!==null)cr(n,2),qf(n,t);else throw j();return ni(n,o),n},$w=n=>{let e=F();return Jw(e,n),I(e)},Ww=n=>{let e=null,t=null,r=null;switch(k(n)){case 0:r=Hf(n);break;case 1:t=Fe(n);break;case 2:e=Hf(n)}let i=Jl(n)?ii(n):0;return new st(e,t,r,i)},jw=n=>Ww(q(n)),Nc=(n,e,t=!0)=>{let r=e.store,i=n.item,o=n.type,s=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(P(r,i.client)<=i.clock)return null;let h=t?bc(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(s!==null)c=e.get(s);else if(o!==null){if(P(r,o.client)<=o.clock)return null;let{item:h}=t?bc(r,o):{item:Cn(r,o)};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 Hw(c,a,n.assoc)},rs=(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}},Kw=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,o=e.sv;if(i.size!==o.size||t.size!==r.size)return!1;for(let[s,l]of i.entries())if(o.get(s)!==l)return!1;for(let[s,l]of t.entries()){let c=r.get(s)||[];if(l.length!==c.length)return!1;for(let a=0;a(it(e,n.ds),Dc(e,n.sv),e.toUint8Array()),Yw=n=>ou(n,new Wt),su=(n,e=new Wo(q(n)))=>new jt(At(e),ru(e)),Gw=n=>su(n,new An(q(n))),Mi=(n,e)=>new jt(n,e),Xw=Mi(br(),new Map),Ai=n=>Mi(kc(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),mc=(n,e)=>{let t=$(n.meta,mc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,o)=>{i{}),t.add(e))},Qw=(n,e,t=new We)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,o=new Ie;return n.transact(s=>{let l=0;r.forEach(c=>{c>0&&l++}),x(o.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 s=i.curr;s!==null;s=i.next())if((n.sv.get(s.id.client)||0)Zw(n,e,Me),Ko=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},lu=(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)},qe=(n,e)=>{let t=0,r=n.length-1,i=n[r],o=i.id.clock;if(o===e)return r;let s=fe(e/(o+i.length-1)*r);for(;t<=r;){if(i=n[s],o=i.id.clock,o<=e){if(e{let t=n.clients.get(e.client);return t[qe(t,e.clock)]},Cn=t1,gc=(n,e,t)=>{let r=qe(e,t),i=e[r];return i.id.clock{let t=n.doc.store.clients.get(e.client);return t[gc(n,t,e.clock)]},Jf=(n,e,t)=>{let r=e.clients.get(t.client),i=qe(r,t.clock),o=r[i];return t.clock!==o.id.clock+o.length-1&&o.constructor!==ue&&r.splice(i+1,0,ns(n,o,t.clock-o.id.clock+1)),o},n1=(n,e,t)=>{let r=n.clients.get(e.id.client);r[qe(r,e.id.clock)]=t},cu=(n,e,t,r,i)=>{if(r===0)return;let o=t+r,s=gc(n,e,t),l;do l=e[s++],oe.deleteSet.clients.size===0&&!Hd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(Sc(e.deleteSet),Vw(n,e),it(n,e.deleteSet),!0),Wf=(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)},Jo=(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 o=e-i;return o&&n.splice(e+1-o,o),o},au=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let o=e.clients.get(r);for(let s=i.length-1;s>=0;s--){let l=i[s],c=l.clock+l.len;for(let a=qe(o,l.clock),h=o[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let o=t.length-1;o>=0;o--){let s=t[o],l=De(i.length-1,1+qe(i,s.clock+s.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=s.clock;a=i[c])c-=1+Jo(i,c)}})},r1=(n,e,t)=>{au(n,e,t),hu(n,e)},du=(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),iu(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),si(l,[]),t._needFormattingCleanup&&M1(t)}finally{r.gc&&au(o,i,r.gcFilter),hu(o,i),t.afterState.forEach((h,d)=>{let f=t.beforeState.get(d)||0;if(f!==h){let u=i.clients.get(d),p=Le(qe(u,f),1);for(let m=u.length-1;m>=p;)m-=1+Jo(u,m)}});for(let h=s.length-1;h>=0;h--){let{client:d,clock:f}=s[h].id,u=i.clients.get(d),p=qe(u,f);p+11||p>0&&Jo(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(Lo(mr,hi,"[yjs] ",di,fi,"Changed the client-id because another client seems to be using it."),r.clientID=tu()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new ot;$f(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;$f(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])):du(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,o=!1,s=null;n._transaction===null&&(o=!0,n._transaction=new Yo(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{s=e(n._transaction)}finally{if(o){let l=n._transaction===i[0];n._transaction=null,l&&du(i,0)}}return s},yc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},jf=(n,e,t)=>{rt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>En(i,r))&&Vc(r,!1)})},Kf=(n,e,t)=>{let r=null,i=n.doc,o=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}=bc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&o.some(p=>En(p,u))&&d.push(u)}}),rt(l,a.deletions,u=>{u instanceof O&&o.some(p=>En(p,u))&&!Tt(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=Pu(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 s=n.currStackItem;if(s!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:s,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return s},Tn=class extends er{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:s=!1,doc:l=Zr(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,o.add(this),this.trackedOrigins=o,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=s,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 yc(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&&hc("[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=>jf(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>jf(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=Kf(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Kf(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*i1(n){let e=k(n.restDecoder);for(let t=0;tfu(n,Me),fu=(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);Lo("Structs: ",t);let o=At(r);Lo("DeleteSet: ",o)},s1=n=>uu(n,Me),uu=(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);return{structs:t,ds:At(r)}},gi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},pu=n=>yi(n,Me,ot),mu=(n,e=gr,t=be)=>{let r=new e,i=new lt(new t(q(n)),!1),o=i.curr;if(o!==null){let s=0,l=o.id.client,c=o.id.clock!==0,a=c?0:o.id.clock+o.length;for(;o!==null;o=i.next())l!==o.id.client&&(a!==0&&(s++,x(r.restEncoder,l),x(r.restEncoder,a)),l=o.id.client,a=0,c=o.id.clock!==0),o.constructor===ie&&(c=!0),c||(a=o.id.clock+o.length);a!==0&&(s++,x(r.restEncoder,l),x(r.restEncoder,a));let h=F();return x(h,s),nf(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},l1=n=>mu(n,Wt,Me),gu=(n,e=be)=>{let t=new Map,r=new Map,i=new lt(new e(q(n)),!1),o=i.curr;if(o!==null){let s=o.id.client,l=o.id.clock;for(t.set(s,l);o!==null;o=i.next())s!==o.id.client&&(r.set(s,l),t.set(o.id.client,o.id.clock),s=o.id.client),l=o.id.clock+o.length;r.set(s,l)}return{from:t,to:r}},c1=n=>gu(n,Me),a1=(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)),o=null,s=new t,l=new gi(s);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(o!==null){let f=h.curr,u=!1;for(;f!==null&&f.id.clock+f.length<=o.struct.id.clock+o.struct.length&&f.id.client>=o.struct.id.client;)f=h.next(),u=!0;if(f===null||f.id.client!==d||u&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(d!==o.struct.id.client)Ht(l,o.struct,o.offset),o={struct:f,offset:0},h.next();else if(o.struct.id.clock+o.struct.length0&&(o.struct.constructor===ie?o.struct.length-=p:f=a1(f,p)),o.struct.mergeWith(f)||(Ht(l,o.struct,o.offset),o={struct:f,offset:0},h.next())}}else o={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==ie;f=h.next())Ht(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(Ht(l,o.struct,o.offset),o=null),Rc(l);let c=r.map(h=>At(h)),a=Mn(c);return it(s,a),s.toUint8Array()},Ic=(n,e,t=be,r=Ie)=>{let i=Tc(e),o=new r,s=new gi(o),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(s,h,Le(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Ht(s,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=f;)c.next()}Rc(s);let a=At(l);return it(o,a),o.toUint8Array()},h1=(n,e)=>Ic(n,e,Me,ot),yu=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&&yu(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++},Rc=n=>{yu(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(q(n)),o=new lt(i,!1),s=new r,l=new gi(s);for(let a=o.curr;a!==null;a=o.next())Ht(l,e(a),0);Rc(l);let c=At(i);return it(s,c),s.toUint8Array()},wu=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=U(),o=U(),s=U(),l=U();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=$(o,d.nodeName,()=>"node-"+r)),d instanceof Si&&(d.hookName=$(o,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=$(s,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=Xd(r%10+"",d.str.length);break}default:j()}return a.parentSub&&(a.parentSub=$(i,a.parentSub,()=>r+"")),r++,c}default:j()}}},d1=(n,e)=>is(n,wu(e),Me,ot),f1=(n,e)=>is(n,wu(e),be,Ie),u1=n=>is(n,tc,Me,Ie),bu=n=>is(n,tc,be,ot),Yf="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=p1(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(Yf);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let o=t._map.get(i),s,l;if(this.adds(o)){let c=o.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(o))if(c!==null&&this.deletes(c))s="delete",l=Eo(c.content.getContent());else return;else c!==null&&this.deletes(c)?(s="update",l=Eo(c.content.getContent())):(s="add",l=void 0)}else if(this.deletes(o))s="delete",l=Eo(o.content.getContent());else return;e.set(i,{action:s,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(Yf);let t=this.target,r=Ce(),i=Ce(),o=[];if(e={added:r,deleted:i,delta:o,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&o.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}},p1=(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},oe=()=>{hc("Invalid access: Add Yjs type to a document before reading data.")},xu=80,vc=0,wc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=vc++}},m1=n=>{n.timestamp=vc++},Su=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=vc++},g1=(n,e,t)=>{if(n.length>=xu){let r=n.reduce((i,o)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((o,s)=>nr(e-o.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 o=i.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(i.index-=o.length);if(o===null||o.marker===!0){n.splice(r,1);continue}i.p=o,o.marker=!0}(e0&&e===i.index)&&(i.index=Le(e,i.index+t))}},y1=n=>{n.doc??oe();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},ls=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;iu(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=Lf(),this._dEH=Lf(),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){zf(this._eH,e)}observeDeep(e){zf(this._dEH,e)}unobserve(e){Ff(this._eH,e)}unobserveDeep(e){Ff(this._dEH,e)}toJSON(){}},ku=(n,e,t)=>{n.doc??oe(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],o=n._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){let s=o.content.getContent();if(s.length<=e)e-=s.length;else{for(let l=e;l0;l++)i.push(s[l]),r--;e=0}}o=o.right}return i},Cu=n=>{n.doc??oe();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 o=0;o{let t=0,r=n._start;for(n.doc??oe();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let o=0;o{let t=[];return bi(n,(r,i)=>{t.push(e(r,i,n))}),t},w1=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}}}},Au=(n,e)=>{n.doc??oe();let t=ss(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,o=n.doc,s=o.clientID,l=o.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(s,P(l,s)),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(s,P(l,s)),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(s,P(l,s)),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(s,P(l,s)),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()},Eu=()=>Ze("Length exceeded!"),Tu=(n,e,t,r)=>{if(t>e._length)throw Eu();if(t===0)return e._searchMarker&&wi(e._searchMarker,t,r.length),Go(n,e,null,r);let i=t,o=ss(e,t),s=e._start;for(o!==null&&(s=o.p,t-=o.index,t===0&&(s=s.prev,t+=s&&s.countable&&!s.deleted?s.length:0));s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<=s.length){t{let i=(e._searchMarker||[]).reduce((o,s)=>s.index>o.index?s:o,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Go(n,e,i,t)},Du=(n,e,t,r)=>{if(r===0)return;let i=t,o=r,s=ss(e,t),l=e._start;for(s!==null&&(l=s.p,t-=s.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw Eu();e._searchMarker&&wi(e._searchMarker,i,-o+r)},Xo=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},_c=(n,e,t,r)=>{let i=e._map.get(t)||null,o=n.doc,s=o.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(s,P(o.store,s)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},Uc=(n,e)=>{n.doc??oe();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Ou=n=>{let e={};return n.doc??oe(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Nu=(n,e)=>{n.doc??oe();let t=n._map.get(e);return t!==void 0&&!t.deleted},x1=(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},Iu=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let o=r;for(;o!==null&&(!e.sv.has(o.id.client)||o.id.clock>=(e.sv.get(o.id.client)||0));)o=o.left;o!==null&&qt(o,e)&&(t[i]=o.content.getContent()[o.length-1])}),t},qo=n=>(n.doc??oe(),Uf(n._map.entries(),e=>!e[1].deleted)),Qo=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??oe(),this._length}_callObserver(e,t){super._callObserver(e,t),ls(this,e,new Qo(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{Tu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{b1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Du(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return Au(this,e)}toArray(){return Cu(this)}slice(e=0,t=this.length){return ku(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return Mu(this,e)}forEach(e){bi(this,e)}[Symbol.iterator](){return w1(this)}_write(e){e.writeTypeRef(F1)}},S1=n=>new On,Zo=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){ls(this,e,new Zo(this,e,t))}toJSON(){this.doc??oe();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[...qo(this)].length}keys(){return zo(qo(this),e=>e[0])}values(){return zo(qo(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return zo(qo(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??oe(),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=>{Xo(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{_c(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Uc(this,e)}has(e){return Nu(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){Xo(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(q1)}},k1=n=>new Nn,Jt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Zl(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}},Gf=(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,o=r?ss(e,t):null;if(o){let s=new xi(o.p.left,o.p,o.index,i);return Gf(n,s,t-o.index)}else{let s=new xi(null,e._start,0,i);return Gf(n,s,t)}},Ru=(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,o=i.clientID;r.forEach((s,l)=>{let c=t.left,a=t.right,h=new O(M(o,P(i.store,o)),c,c&&c.lastId,a,a&&a.id,e,null,new L(l,s));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)},vu=(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()}},_u=(n,e,t,r)=>{let i=n.doc,o=i.clientID,s=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Jt(a,c)){s.set(l,a);let{left:h,right:d}=t;t.right=new O(M(o,P(i.store,o)),h,h&&h.lastId,d,d&&d.id,e,null,new L(l,c)),t.right.integrate(n,0),t.forward()}}return s},dc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let o=n.doc,s=o.clientID;vu(t,i);let l=_u(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(s,P(o.store,s)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=d,t.forward(),Ru(n,e,t,l)},Xf=(n,e,t,r,i)=>{let o=n.doc,s=o.clientID;vu(t,i);let l=_u(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(s,P(o.store,s)),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()}Ru(n,e,t,l)},Uu=(n,e,t,r,i)=>{let o=e,s=U();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===L){let a=o.content;s.set(a.key,a)}o=o.right}let l=0,c=!1;for(;e!==o;){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;(s.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},C1=(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}},Vu=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,o=U(),s=Ao(o);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case L:xr(s,i.content);break;default:e+=Uu(t,r,i,o,s),o=Ao(s),r=i;break}i=i.right}}),e},M1=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let o=n.beforeState.get(r)||0;i!==o&&cu(n,t.store.clients.get(r),o,i,s=>{!s.deleted&&s.content.constructor===L&&s.constructor!==ue&&e.add(s.parent)})}R(t,r=>{rt(n,n.deleteSet,i=>{if(i instanceof ue||!i.parent._hasFormatting||e.has(i.parent))return;let o=i.parent;i.content.constructor===L?e.add(o):C1(r,i)});for(let i of e)Vu(i)})},Qf=(n,e,t)=>{let r=t,i=Ao(e.currentAttributes),o=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,o=new Map,s=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},wf(c)||(u.attributes=mf({},c))),h=0;break}u&&t.push(u),l=null}};for(;s!==null;){switch(s.content.constructor){case Ae:case Et:this.adds(s)?this.deletes(s)||(f(),l="insert",a=s.content.getContent()[0],f()):this.deletes(s)?(l!=="delete"&&(f(),l="delete"),d+=1):s.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case Re:this.adds(s)?this.deletes(s)||(l!=="insert"&&(f(),l="insert"),a+=s.content.str):this.deletes(s)?(l!=="delete"&&(f(),l="delete"),d+=s.length):s.deleted||(l!=="retain"&&(f(),l="retain"),h+=s.length);break;case L:{let{key:u,value:p}=s.content;if(this.adds(s)){if(!this.deletes(s)){let m=i.get(u)??null;Jt(m,p)?p!==null&&s.delete(r):(l==="retain"&&f(),Jt(p,o.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(s)){o.set(u,p);let m=i.get(u)??null;Jt(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!s.deleted){o.set(u,p);let m=c[u];m!==void 0&&(Jt(m,p)?m!==null&&s.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}s.deleted||(l==="insert"&&f(),xr(i,s.content));break}}s=s.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??oe(),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 es(this,e,t);ls(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??oe();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 o=0;o0)&&dc(r,this,i,l,s.attributes||{})}else s.retain!==void 0?Xf(r,this,i,s.retain,s.attributes||{}):s.delete!==void 0&&Qf(r,i,s.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??oe();let i=[],o=new Map,s=this.doc,l="",c=this._start;function a(){if(l.length>0){let d={},f=!1;o.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=o.get("ychange");e!==void 0&&!qt(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),o.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(),o.set("ychange",r?r("added",c.id):{type:"added"})):d!==void 0&&(a(),o.delete("ychange")),l+=c.content.str;break}case Ae:case Et:{a();let d={insert:c.content.getContent()[0]};if(o.size>0){let f={};d.attributes=f,o.forEach((u,p)=>{f[p]=u})}i.push(d);break}case L:qt(c,e)&&(a(),xr(o,c.content));break}c=c.right}a()};return e||t?R(s,d=>{e&&mc(d,e),t&&mc(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,o=>{let s=Ho(o,this,e,!r);r||(r={},s.currentAttributes.forEach((l,c)=>{r[c]=l})),dc(o,this,s,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,o=>{let s=Ho(o,this,e,!r);dc(o,this,s,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=>{Qf(i,Ho(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,o=>{let s=Ho(o,this,e,!1);s.right!==null&&Xf(o,this,s,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xo(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{_c(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Uc(this,e)}getAttributes(){return Ou(this)}_write(e){e.writeTypeRef(H1)}},A1=n=>new ct,ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??oe()}[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??oe(),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){ls(this,e,new ts(this,t,e))}toString(){return Mu(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,o=>{i.insertBefore(o.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{Tu(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;Go(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(o=>o===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=>{Du(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return Cu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Au(this,e)}slice(e=0,t=this.length){return ku(this,e,t)}forEach(e){bi(this,e)}_write(e){e.writeTypeRef($1)}},E1=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 gf(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`<${o}${s}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xo(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{_c(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Uc(this,e)}hasAttribute(e){return Nu(this,e)}getAttributes(e){return e?Iu(this,e):Ou(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),o=this.getAttributes();for(let s in o){let l=o[s];typeof l=="string"&&i.setAttribute(s,l)}return bi(this,s=>{i.appendChild(s.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(J1),e.writeKey(this.nodeName)}},T1=n=>new Z(n.readKey()),ts=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],o;return i!==void 0?o=i.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(e){e.writeTypeRef(W1),e.writeKey(this.hookName)}},D1=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 o=[];for(let s in e.attributes[i])o.push({key:s,value:e.attributes[i][s]});o.sort((s,l)=>s.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(j1)}},O1=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()}},N1=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),lu(e.doc.store,this)}write(e,t){e.writeInfo(N1),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}},I1=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}},R1=n=>new wr(n.readLen()),Bu=(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(Bu(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}},v1=n=>new Rn(Bu(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}},_1=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}},U1=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}},L1=n=>new Re(n.readString()),z1=[S1,k1,A1,T1,E1,D1,O1],F1=0,q1=1,H1=2,J1=3,$1=4,W1=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}},K1=n=>new Ae(z1[n.readTypeRef()](n)),bc=(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},ns=(n,e,t)=>{let{client:r,clock:i}=e.id,o=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&&o.markDeleted(),e.keep&&(o.keep=!0),e.redone!==null&&(o.redone=M(e.redone.client,e.redone.clock+t)),e.right=o,o.right!==null&&(o.right.left=o),n._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),e.length=t,o},Zf=(n,e)=>$d(n,t=>Tt(t.deletions,e)),Pu=(n,e,t,r,i,o)=>{let s=n.doc,l=s.store,c=s.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)||Pu(n,h,t,r,i,o)===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)||Zf(o.undoStack,d.right.id)||Zf(o.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,o,s,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=o,this.parent=s,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=Jf(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=Jf(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 o=new Set,s=new Set;for(;i!==null&&i!==this.right;){if(s.add(i),o.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),Wf(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?n1(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,o=this.parentSub,s=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(o===null?0:32);if(e.writeInfo(s),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();o!==null&&e.writeString(o)}this.content.write(e,t)}},Lu=(n,e)=>Y1[e&31](n),Y1=[()=>{j()},R1,V1,I1,L1,_1,U1,K1,P1,v1,()=>{j()}],G1=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(G1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},zu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Fu="__ $YJS$ __";zu[Fu]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");zu[Fu]=!0;var qu=new Map,Bc=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:Af(t.newValue||"")}),df(this._onChange)}postMessage(e){Uo.setItem(this.room,Mf(Cf(e)))}close(){ff(this._onChange)}},X1=typeof BroadcastChannel>"u"?Bc:BroadcastChannel,Pc=n=>$(qu,n,()=>{let e=Ce(),t=new X1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Hu=(n,e)=>(Pc(n).subs.add(e),e),Ju=(n,e)=>{let t=Pc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),qu.delete(n)),r},Vn=(n,e,t=null)=>{let r=Pc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var $u=0,as=1,Wu=2,hs=(n,e)=>{x(n,$u);let t=Oc(e);V(n,t)},Lc=(n,e,t)=>{x(n,as),V(n,Ec(e,t))},Z1=(n,e,t)=>Lc(e,t,K(n)),ju=(n,e,t)=>{try{Ac(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},Ku=(n,e)=>{x(n,Wu),V(n,e)},eb=ju,Yu=(n,e,t,r)=>{let i=k(n);switch(i){case $u:Z1(n,e,t);break;case as:ju(n,t,r);break;case Wu:eb(n,t,r);break;default:throw new Error("Unknown message type")}return i};var nb=0;var Gu=(n,e,t)=>{switch(k(n)){case nb:t(e,Fe(n))}};var zc=3e4,ds=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&&zc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,o)=>{o!==this.clientID&&zc<=t-i.lastUpdated&&this.states.has(o)&&r.push(o)}),r.length>0&&fs(this,r,"timeout")},fe(zc/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,o=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Ne()});let s=[],l=[],c=[],a=[];e===null?a.push(t):o==null?e!=null&&s.push(t):(l.push(t),ur(o,e)||c.push(t)),(s.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:s,updated:c,removed:a},"local"]),this.emit("update",[{added:s,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},fs=(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 o=0;o{let r=q(e),i=Ne(),o=[],s=[],l=[],c=[],a=k(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:o,updated:l,removed:c},t]),(o.length>0||s.length>0||c.length>0)&&n.emit("update",[{added:o,updated:s,removed:c},t])};var Qu=n=>yf(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,ep=3,Cr=1,sb=2,Ti=[];Ti[Bn]=(n,e,t,r,i)=>{x(n,Bn);let o=Yu(e,n,t.doc,t);r&&o===as&&!t.synced&&(t.synced=!0)};Ti[ep]=(n,e,t,r,i)=>{x(n,Cr),V(n,kr(t.awareness,Array.from(t.awareness.getStates().keys())))};Ti[Cr]=(n,e,t,r,i)=>{Xu(t.awareness,K(e),t)};Ti[sb]=(n,e,t,r,i)=>{Gu(e,t.doc,(o,s)=>lb(t,s))};var Zu=3e4,lb=(n,e)=>console.warn(`Permission denied to access ${n.url}. -${e}`),tp=(n,e,t)=>{let r=q(e),i=F(),o=k(r),s=n.messageHandlers[o];return s?s(i,r,n,t,o):console.error("Unable to compute message"),i},np=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=tp(n,new Uint8Array(t.data),!0);No(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,fs(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(np,De(jd(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),hs(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=F();x(r,Cr),V(r,kr(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},Fc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},qc=class extends tr{constructor(e,t,r,{connect:i=!0,awareness:o=new ds(r),params:s={},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=s,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=o,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),hs(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=tp(this,new Uint8Array(f),!1);No(p)>1&&Vn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=F();x(p,Bn),Ku(p,f),Fc(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),V(y,kr(o,g)),Fc(this,I(y))},this._exitHandler=()=>{fs(this.awareness,[r.clientID],"app closed")},kt&&typeof process<"u"&&process.on("exit",this._exitHandler),o.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Zu{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var cb=/[\uD800-\uDBFF]/,ab=/[\uDC00-\uDFFF]/,hb=(n,e)=>{let t=0,r=0;for(;t0&&cb.test(n[t-1])&&t--;r+t0&&ab.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},ip=hb;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),db=[{light:"#ecd44433",dark:"#ecd444"}],fb=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,lf(e))}return n.get(t)},lp=(n,{colors:e=db,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:o}={})=>{let s=!1,l=new us(n,o),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),o==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(s||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(s=!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},ub=(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)}),us=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=rp(),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(),o=Ct.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||o.clientWidth||0)&&i.top<=(window.innerHeight||o.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(o=>{let s=r.permanentUserData;s&&s.dss.forEach(h=>{rt(o,h,d=>{})});let l=(h,d)=>{let f=h==="added"?s.getUserByClientId(d.client):s.getUserByDeletedId(d);return{user:f,type:h,color:fb(r.colorMapping,r.colors,f)}},c=cs(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 o=this.type.toArray().map(l=>cp(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),s=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(o),0,0));ub(s,this.beforeTransactionSelection,this),s=s.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Tn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&s.scrollIntoView(),this.prosemirrorView.dispatch(s)})}_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))}},cp=(n,e,t,r,i,o)=>{let s=t.get(n);if(s===void 0){if(n instanceof Z)return Oi(n,e,t,r,i,o);throw Oe()}return s},Oi=(n,e,t,r,i,o)=>{let s=[],l=c=>{if(c.constructor===Z){let a=cp(c,e,t,r,i,o);a!==null&&s.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=pb(c,e,t,r,i,o);h!==null&&h.forEach(d=>{d!==null&&s.push(d)})}};r===void 0||i===void 0?n.toArray().forEach(l):cs(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=o?o("added",n._item.id):{type:"added"}):c.ychange=o?o("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,s);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},pb=(n,e,t,r,i,o)=>{let s=[],l=n.toDelta(r,i,o);try{for(let c=0;c{n._item.delete(a)},v),null}return s},mb=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:hp(i.marks)}));return t.applyDelta(r),e.set(t,n),t},gb=(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,ms(n).map(r=>Hc(r,e))),e.set(t,n),t},Hc=(n,e)=>n instanceof Array?mb(n,e):gb(n,e),op=n=>typeof n=="object"&&n!==null,$c=(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&&Vo(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(o=>$c(r.attributes[o.type.name]||{},o.attrs)))},Ri=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Jc(n,e)){let t=ms(e);return n._length===t.length&&$c(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Ri(r,t[i]))}return n instanceof xe&&e instanceof Array&&ap(n,e)},ps=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),sp=(n,e,t)=>{let r=n.toArray(),i=ms(e),o=i.length,s=r.length,l=De(s,o),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}},wb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=yb(n),o=e.map(a=>({insert:a.text,attributes:Object.assign({},r,hp(a.marks))})),{insert:s,remove:l,index:c}=ip(i,o.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,s),n.applyDelta(o.map(a=>({retain:a.insert.length,attributes:a.attributes})))},hp=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=ms(t),o=i.length,s=e.toArray(),l=s.length,c=De(o,l),a=0,h=0;for(;a{for(;l-a-h>0&&o-a-h>0;){let f=s[a],u=i[a],p=s[l-h-1],m=i[o-h-1];if(f instanceof xe&&u instanceof Array)ap(f,u)||wb(f,u,r),a+=1;else{let g=f instanceof Z&&Jc(f,u),y=p instanceof Z&&Jc(p,m);if(g&&y){let E=sp(f,u,r),N=sp(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,bb=()=>{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((o,s)=>{r.setMeta(s,o)}),t.dispatch(r))})},Wc=(n,e,t)=>{vi||(vi=new Map,ai(0,bb)),$(vi,n,U).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 st(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 st(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 xb(r._item.parent,r._item)}return Ci(e,e._length,-1)},xb=(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 st(t,r,e.id)},Yt=(n,e,t,r)=>{let i=Nc(t,n);if(i===null||i.type!==e&&!En(e,i.type._item))return null;let o=i.type,s=0;if(o.constructor===xe)s=i.index;else if(o._item===null||!o._item.deleted){let l=o._first,c=0;for(;ci(void 0)};return Mr(r,t,n,new Map),t}function fp(n,e="prosemirror"){return Kc(n.getXmlFragment(e))}function Kc(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(s=>{let l={type:"text",text:s.insert};return s.attributes&&(l.marks=Object.keys(s.attributes).map(c=>{let a=s.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let o=r.getAttributes();Object.keys(o).length&&(i.attrs=o);let s=r.toArray();s.length&&(i.content=s.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var Sb=(n,e,t)=>n!==e,kb=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},Cb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Mb=/^#[0-9a-fA-F]{6}$/,up=(n,e,t,r,i)=>{let o=v.getState(n),s=o.doc,l=[];return o.snapshot!=null||o.prevSnapshot!=null||o.binding.mapping.size===0?z.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(s.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Mb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Yt(s,o.type,Un(c.cursor.anchor),o.binding.mapping),f=Yt(s,o.type,Un(c.cursor.head),o.binding.mapping);if(d!==null&&f!==null){let u=Le(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=Le(d,f);l.push(ne.inline(p,m,i(h),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),z.create(n.doc,l))},Ab=(n,{awarenessStateFilter:e=Sb,cursorBuilder:t=kb,selectionBuilder:r=Cb,getSelection:i=s=>s.selection}={},o="cursor")=>new H({key:Di,state:{init(s,l){return up(l,n,e,t,r)},apply(s,l,c,a){let h=v.getState(a),d=s.getMeta(Di);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?up(a,n,e,t,r):l.map(s.mapping,s.doc)}},props:{decorations:s=>Di.getState(s)},view:s=>{let l=()=>{s.docView&&Wc(s,Di,{awarenessUpdated:!0})},c=()=>{let a=v.getState(s.state),h=n.getLocalState()||{};if(s.hasFocus()){let d=i(s.state),f=Pn(d.anchor,a.type,a.binding.mapping),u=Pn(d.head,a.type,a.binding.mapping);(h.cursor==null||!rs(Un(h.cursor.anchor),f)||!rs(Un(h.cursor.head),u))&&n.setLocalStateField(o,{anchor:f,head:u})}else h.cursor!=null&&Yt(a.doc,a.type,Un(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(o,null)};return n.on("change",l),s.dom.addEventListener("focusin",c),s.dom.addEventListener("focusout",c),{update:c,destroy:()=>{s.dom.removeEventListener("focusin",c),s.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(o,null)}}}});var Eb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.undo(),!0},Tb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.redo(),!0},Db=new Set(["paragraph"]),Ob=(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,Nb=({protectedNodes:n=Db,trackedOrigins:e=[],undoManager:t=null}={})=>new H({key:Dt,state:{init:(r,i)=>{let o=v.getState(i),s=t||new Tn(o.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Ob(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:s,prevSel:null,hasUndoOps:s.undoStack.length>0,hasRedoOps:s.redoStack.length>0}},apply:(r,i,o,s)=>{let l=v.getState(s).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ii(l,o),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),o=Dt.getState(r.state).undoManager;return o.on("stack-item-added",({stackItem:s})=>{let l=i.binding;l&&s.meta.set(l,Dt.getState(r.state).prevSel)}),o.on("stack-item-popped",({stackItem:s})=>{let l=i.binding;l&&(l.beforeTransactionSelection=s.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{o.destroy()}}}});var _i="http://www.w3.org/2000/svg",Ib="http://www.w3.org/1999/xlink",Gc="ProseMirror-icon",Yc="pm-close-dropdowns";function Rb(n){let e=0;for(let t=0;t{o.preventDefault(),r.classList.contains(je+"-disabled")||t.run(e.state,e.dispatch,e,o)});function i(o){if(t.select){let l=t.select(o);if(r.style.display=l?"":"none",!l)return!1}let s=!0;if(t.enable&&(s=t.enable(o)||!1,pp(r,je+"-disabled",!s)),t.active){let l=s&&t.active(o)||!1;pp(r,je+"-active",l)}return!0}return{dom:r,update:i}}};function gs(n,e){return n._props.translate?n._props.translate(e):e}var Ui={time:0,node:null};function Ub(n){Ui.time=Date.now(),Ui.node=n.target}function Vb(n){return Date.now()-100{s&&s.close()&&(s=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(Yc,c))};i.addEventListener("mousedown",d=>{d.preventDefault(),Ub(d),s?a():(r.dispatchEvent(new CustomEvent(Yc)),s=this.expand(o,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{Vb(o)||a()}),r.addEventListener(Yc,c=()=>{a()}))});function h(d){let f=t.update(d);return o.style.display=f?"":"none",f}return{dom:o,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 o=wt("div",{class:je+"-dropdown-menu "+(this.options.class||"")},r,i),s=!1;function l(){return s?!1:(s=!0,e.removeChild(o),!0)}return e.appendChild(o),{close:l,node:o}}};function Bb(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iWr(n),icon:Vi.join}),Lk=new ht({title:"Lift out of enclosing block",run:jr,select:n=>jr(n),icon:Vi.lift}),zk=new ht({title:"Select parent node",run:Kr,select:n=>Kr(n),icon:Vi.selectParentNode}),Fk=new ht({title:"Undo last change",run:Xr,enable:n=>Xr(n),icon:Vi.undo}),qk=new ht({title:"Redo last undone change",run:Qn,enable:n=>Qn(n),icon:Vi.redo});function zb(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 Fb(n,e){let t=pn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:o,to:s,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):s<=o.end()&&o.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new ht(r)}function pp(n,e,t){t?n.classList.add(e):n.classList.remove(e)}function gp(n,e,t){let r=t.child(0),o=_.get(t).width;if(r.childCount===1&&r.child(0).attrs.colspan===o)return n;if(r.childCount>1){let s=[],l=null;r.forEach((m,g,y)=>{y===0&&(l=e+1),m.textContent&&s.push(m.textContent)});let c=s[0]||"columns",a=r.child(0).type,h=n.doc.type.schema.nodes.paragraph.create(null,n.doc.type.schema.text(c)),d=a.create({colspan:o,rowspan:1},h),u=n.doc.type.schema.nodes.table_row.create(null,d),p=l+r.nodeSize-1;n.replaceWith(l,p,u)}else if(r.childCount===1){let s=e+1,l=r.child(0);n.setNodeMarkup(s,null,{...l.attrs,colspan:o,rowspan:1})}return n}function yp(n){for(let e=n.depth;e>0;e-=1){let t=n.node(e);if(t.type.name==="table"){let r=n.start(e)-1;return{table:t,tableStart:r,depth:e}}}return null}function ys(n){return Be(n)?Pe(n).top===0:!1}function iC(n,e){if(!e)return Vl(n,e);let t=n.selection.$from.pos;return Vl(n,i=>{try{let o=i.doc.resolve(t),s=yp(o);if(s){let l=i.doc.nodeAt(s.tableStart);l&&gp(i,s.tableStart,l)}}catch(o){console.warn("Could not fix header row colspan:",o)}e(i)})}function oC(n,e){if(!e)return Bl(n,e);let t=n.selection.$from.pos;return Bl(n,i=>{try{let o=i.doc.resolve(t),s=yp(o);if(s){let l=i.doc.nodeAt(s.tableStart);l&&gp(i,s.tableStart,l)}}catch(o){console.warn("Could not fix header row colspan:",o)}e(i)})}function sC(n,e){return ys(n)?!1:Bd(n,e)}function lC(n,e){return ys(n)?!1:Ld(n,e)}function cC(n,e){return ys(n)?!1:Pd(n,e)}function aC(n,e){return ys(n)?!1:Ud(n,e)}export{zn as DOMParser,It as DOMSerializer,Xc as Dropdown,Ps as EditorState,ll 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,qc as WebsocketProvider,Sr as Y,oC as addColumnAfter,iC as addColumnBefore,wy as addListNodes,h0 as addRowAfter,sC as addRowBefore,hd as baseKeymap,jg as baseSchema,Fb as blockTypeItem,$y as buildKeymap,D0 as columnResizing,aC as deleteColumn,cC as deleteRow,w0 as deleteTable,vd as fixTables,Vy as gapCursor,y0 as goToNextCell,gd as inputRules,Be as isInTable,Ty as keymap,xl as liftListItem,u0 as mergeCells,dp as prosemirrorToYDoc,jc as prosemirrorToYXmlFragment,Pb as renderGrouped,Pe as selectedRect,pn as setBlockType,Sl as sinkListItem,lC as splitCell,bl as splitListItem,L0 as tableEditing,Gy as tableNodes,mn as toggleMark,Xn as wrapIn,uo as wrapInList,zb as wrapItem,Ab as yCursorPlugin,fp as yDocToProsemirrorJSON,Tb as yRedo,lp as ySyncPlugin,Eb as yUndo,Nb as yUndoPlugin,Dt as yUndoPluginKey,Kc as yXmlFragmentToProsemirrorJSON}; +`);return{dom:c,text:f,slice:e}}function zh(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let c=e&&(r||o||!t);if(c){if(n.someProp("transformPastedText",f=>{e=f(e,o||r,n)}),o)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);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),s=Ym(t),$r&&Gm(s);let a=s&&s.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=s.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;s=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!Wm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Xm(dh(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(jm(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 Wm=/^(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 jm(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)),o,s=[];if(n.forEach(l=>{if(!s)return;let c=i.findWrapping(l.type),a;if(!c)return s=null;if(a=s.length&&o.length&&qh(c,o,l,s[s.length-1],0))s[s.length-1]=a;else{s.length&&(s[s.length-1]=Hh(s[s.length-1],o.length));let h=Fh(l,c);s.push(h),i=i.matchType(h.type),o=c}}),s)return w.from(s)}return n}function Fh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function qh(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function dh(n,e,t){return et}).createHTML(n):n}function Ym(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=$h().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Jh[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=Km(n),i)for(let o=0;o=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),o++,s++}return new b(i,o,s)}var ge={},ye={},Qm={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 Zm(n){for(let e in ge){let t=ge[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{tg(n,r)&&!hl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},Qm[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 eg(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 tg(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 ng(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,!jh(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,sn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||$m(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(jh(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",o=>o(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function fo(n){return{left:n.clientX,top:n.clientY}}function rg(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 o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),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 ig(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 og(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof C&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(C.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(jn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function sg(n,e,t,r,i){return dl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?og(n,t):ig(n,t))}function lg(n,e,t,r){return dl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function cg(n,e,t,r){return dl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||ag(n,t,r)}function ag(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 o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)jn(n,A.create(r,l+1,l+1+s.content.size),"pointer");else if(C.isSelectable(s))jn(n,C.create(r,l),"pointer");else continue;return!0}}function fl(n){return oo(n)}var Wh=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=fl(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&rg(t,n.input.lastClick)&&!t[Wh]&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o};let s=n.posAtCoords(fo(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new nl(n,s,t,!!r)):(o=="doubleClick"?lg:cg)(n,s.pos,s.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[Wh],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let h=e.state.doc.resolve(t.pos);o=h.parent,s=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&&o.type.spec.draggable&&o.type.spec.selectable!==!1||a instanceof C&&a.from<=s&&a.to>s)&&(this.mightDrag={node:o,pos:s,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(fo(e))),this.updateAllowDefault(e),this.allowDefault||!t?Vt(this.view,"pointer"):sg(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 jh(n,e){return n.composing?!0:me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var hg=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(),oo(n,!0),n.markCursor=null;else if(oo(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,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Kh(n,hg)};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++,Kh(n,20))};function Kh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>oo(n),e))}function Yh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=fg());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function dg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=cm(e.focusNode,e.focusOffset),r=am(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function fg(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function oo(n,e=!1){if(!(Fe&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Yh(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 ug(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&&pm<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=Fr?null:t.clipboardData,s=r.content(),{dom:l,text:c}=Lh(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",c)):ug(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function pg(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function mg(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 o=zh(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,o||b.empty)))return!0;if(!o)return!1;let s=pg(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Gh(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,Gh(r),r.getData("text/html"),i,t)?t.preventDefault():mg(n,t)};var so=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Xh=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,o=i.empty?null:n.posAtCoords(fo(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof C?i.to-1:i.to))){if(r&&r.mightDrag)s=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&&(s=C.create(n.state.doc,d.posBefore))}}let l=(s||n.state.selection).content(),{dom:c,text:a,slice:h}=Lh(n,l);(!t.dataTransfer.files.length||!ae||Ah>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 so(h,!t[Xh],s)};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(fo(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",p=>{s=p(s,n)}):s=zh(n,Gh(t.dataTransfer),Fr?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!t[Xh]);if(n.someProp("handleDrop",p=>p(n,t,s||b.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let c=s?Ra(n.state.doc,o.pos,s):o.pos;c==null&&(c=o.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=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,s.content.firstChild):a.replaceRange(h,h,s),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&C.isSelectable(s.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(s.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",o=>o(n,sn(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 lo=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:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new ne(o-r,o-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 o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new ne(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}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,o){let s;for(let l=0;l{let a=c+r,h;if(h=Zh(t,l,a)){for(i||(i=this.children.slice());ol&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&c.type instanceof an){let a=Math.max(o,c.from)-o,h=Math.min(s,c.to)-o;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]+o,-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]+o+1,s);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=yg(l,n,e,t,i,o,s),h=ao(a,r,0,s);e=h.local;for(let d=0;dt&&s.to{let a=Zh(n,l,c+t);if(a){o=!0;let h=ao(a,l,t+c+1,r);h!=ce&&i.push(c,c+l.nodeSize,h)}});let s=Qh(o?ed(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function zs(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])),co.from(e)}var wg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},bg=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}},ol=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()}),bg&&(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,wg)),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(oh(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 o=e.focusNode;o;o=zr(o))t.add(o);for(let o=e.anchorNode;o;o=zr(o))if(t.has(o)){r=o;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)&&oh(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),o=-1,s=-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||kg(e,d)!=u)&&f.remove()}}}let a=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),xg(e)),this.handleDOMChange(o,s,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){o=g;break}if(!E||E.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(s),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:o,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:Mg,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+s,head:y+s}}return{doc:m,sel:p,from:s,to:l}}function Mg(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 Ag=/^(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 Eg(n,e,t,r,i){let o=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()-100up(n,sn(13,"Enter"))))return;let Bi=n.state.tr.setSelection(Nt);T=="pointer"?Bi.setMeta("pointer",!0):T=="key"&&Bi.scrollIntoView(),o&&Bi.setMeta("composition",o),n.dispatch(Bi)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=Cg(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&&!Ag.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,sn(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=yh(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let Nt=n.state.tr.setSelection(T);o&&Nt.setMeta("composition",o),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,sn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Dg(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,sn(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,sn(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=Tg(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=yh(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 Tg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||Fs(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function Og(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,o-Math.min(s,l));r-=s+c-o}if(s=s?o-r:0;o-=c,o&&o=l?o-r:0;o-=c,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}var sl=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(Ch),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=Sh(this),xh(this),this.nodeViews=kh(this),this.docView=Za(this.state.doc,bh(this),zs(this),this.dom,this),this.domObserver=new ol(this,(r,i,o,s)=>Eg(this,r,i,o,s)),this.domObserver.start(),Zm(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(Ch),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,o=!1,s=!1;e.storedMarks&&this.composing&&(Yh(this),s=!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=kh(this);Ig(u,this.nodeViews)&&(this.nodeViews=u,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&tl(this),this.editable=Sh(this),xh(this);let c=zs(this),a=bh(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=o||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(s=!0);let f=h=="preserve"&&s&&this.dom.style.overflowAnchor==null&&ym(this);if(s){this.domObserver.stop();let u=d&&(ke||ae)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Ng(i.selection,e.selection);if(d){let p=ae?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=dg(this)),(o||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Za(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Pm(this))?mt(this,u):(Vh(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&&wm(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&&ja(this,t.getBoundingClientRect(),e)}else ja(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(o))==r.node&&(i=o)}this.dragging=new so(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 s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Mm(this,e)}coordsAtPos(e,t=1){return Nh(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 Om(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&&(eg(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],zs(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,sm())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ng(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&&dm(this.dom.ownerDocument)==this.dom&&Sg(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function bh(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 xh(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 Sh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Ng(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 kh(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 Ig(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 Ch(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 Rg=["p",0],vg=["blockquote",0],_g=["hr"],Ug=["pre",["code",0]],Vg=["br"],Bg={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Rg}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return vg}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return _g}},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 Ug}},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 Vg}}},Pg=["em",0],Lg=["strong",0],zg=["code",0],Fg={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 Pg}},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 Lg}},code:{parseDOM:[{tag:"code"}],toDOM(){return zg}}},qg=new Dr({nodes:Bg,marks:Fg});var nd=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Hg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Jg=(n,e,t)=>{let r=Hg(n,t);if(!r)return!1;let i=rd(r);if(!i){let s=r.blockRange(),l=s&&nn(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(sd(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Gn(o,"end")||C.isSelectable(o)))for(let s=r.depth;;s--){let l=Xi(n.doc,r.before(s),r.after(s),b.empty);if(l&&l.slice.size1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-o.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 $g=(n,e,t)=>{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=rd(r)}let s=o&&o.nodeBefore;return!s||!C.isSelectable(s)?!1:(e&&e(n.tr.setSelection(C.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function rd(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 Wg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Wg(n,t);if(!r)return!1;let i=id(r);if(!i)return!1;let o=i.nodeAfter;if(sd(n,i,e,1))return!0;if(r.parent.content.size==0&&(Gn(o,"start")||C.isSelectable(o))){let s=Xi(n.doc,r.before(),r.after(),b.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=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=Rs(n.doc,t.from,-1),i==null)return!1;if(e){let o=n.tr.join(i);r&&o.setSelection(C.create(o.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(o.scrollIntoView())}return!0},od=(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=Rs(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),o=i&&nn(i);return o==null?!1:(e&&e(n.tr.lift(i,o).scrollIntoView()),!0)},Yg=(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),o=t.indexAfter(-1),s=ml(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,s.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},Gg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Te||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=ml(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!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 o=t.before();if(Rt(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Qg(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 o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof A||e.selection instanceof Te)&&s.deleteSelection();let l=r.depth==0?null:ml(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,o,r),a=c?[c]:o&&l?[{type:l}]:void 0,h=Rt(s.doc,s.mapping.map(r.pos),1,a);if(!a&&!h&&Rt(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(s.split(s.mapping.map(r.pos),1,a),!o&&!r.parentOffset&&r.parent.type!=l){let d=s.mapping.map(r.before()),f=s.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}return t&&t(s.scrollIntoView()),!0}}var Zg=Qg();var Kr=(n,e)=>{let{$from:t,to:r}=n.selection,i,o=t.sharedDepth(r);return o==0?!1:(i=t.before(o),e&&e(n.tr.setSelection(C.create(n.doc,i))),!0)},ey=(n,e)=>(e&&e(n.tr.setSelection(new Te(n.doc))),!0);function ty(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||rn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function sd(n,e,t,r){let i=e.nodeBefore,o=e.nodeAfter,s,l,c=i.type.spec.isolating||o.type.spec.isolating;if(!c&&ty(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(s=(l=i.contentMatchAt(i.childCount)).findWrapping(o.type))&&l.matchType(s[0]||o.type).validEnd){if(t){let u=e.pos+o.nodeSize,p=w.empty;for(let y=s.length-1;y>=0;y--)p=w.from(s[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),s.length,!0)),g=m.doc.resolve(u+2*s.length);g.nodeAfter&&g.nodeAfter.type==i.type&&rn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=o.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(o,"start",!0)&&Gn(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=o,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+o.nodeSize,e.pos+g,e.pos+o.nodeSize-g,new b(y,p.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function ld(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}var ny=ld(-1),ry=ld(1);function Xn(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o),l=s&&Gi(s,n,e);return l?(r&&r(t.tr.wrap(s,l).scrollIntoView()),!0):!1}}function pn(n,e=null){return function(t,r){let i=!1;for(let o=0;o{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 o=t.tr;for(let s=0;s{if(l||!r&&c.isAtom&&c.isInline&&a>=o.pos&&a+c.nodeSize<=s.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function oy(n){let e=[];for(let t=0;t{if(o.isAtom&&o.content.size&&o.isInline&&s>=r.pos&&s+o.nodeSize<=i.pos)return s+1>r.pos&&e.push(new vt(r,r.doc.resolve(s+1))),r=r.doc.resolve(s+1+o.content.size),!1}),r.poso.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(s.depth-1).type.compatibleContent(n)&&s.startIndex==0){if(i.index(s.depth-1)==0)return!1;let h=t.doc.resolve(s.start-2);c=new Zt(h,h,s.depth),s.endIndex=0;h--)o=w.from(t[h].type.create(t[h].attrs,o));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(o,0,0),t.length,!0));let s=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=o.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,o.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,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?my(e,t,n,o):gy(e,t,o):!0:!1}}function my(n,e,t,r){let i=n.tr,o=r.end,s=r.$to.end(r.depth);om;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let o=r.doc.resolve(t.start),s=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=o.node(-1),h=o.index(-1);if(!a.canReplace(h+(l?0:1),h+1,s.content.append(c?w.empty:w.from(i))))return!1;let d=o.pos,f=d+s.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,o=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let l=o.parent,c=l.child(s-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=o.start,u=o.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:"'"},mo={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},yy=typeof navigator<"u"&&/Mac/.test(navigator.platform),wy=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),mo[J]=String.fromCharCode(J);var J;for(po in yt)mo.hasOwnProperty(po)||(mo[po]=yt[po]);var po;function hd(n){var e=yy&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||wy&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?mo: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 by=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function xy(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=yt[r.keyCode])&&o!=i){let l=e[Sl(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var go=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(o,s){return i.push(e(o,s))},t,r),i};re.from=function(e){return e instanceof re?e:e&&e.length?new dd(e):re.empty};var dd=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,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,l){for(var c=o;c=s;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=go)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=go)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 dd([]);var Cy=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,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(o,l)-l,s+l)===!1||o=o?this.right.slice(r-o,i-o):this.left.slice(r,o).append(this.right.slice(0,i-o))},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 My=500,yo=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,o;t&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,l,c,a=[],h=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),o=i.maps.length),o--,h.push(d);return}if(i){h.push(new Xe(d.map));let u=d.step.map(i.slice(o)),p;u&&s.maybeStep(u).doc&&(p=s.mapping.maps[s.mapping.maps.length-1],a.push(new Xe(p,void 0,void 0,a.length+h.length))),o--,p&&i.appendMap(p,o)}else s.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(o)):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:s,selection:l}}addTransform(e,t,r,i){let o=[],s=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hEy&&(l=Ay(l,a),s-=a),new n(l.append(o),s)}remapping(e,t){let r=new Rr;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},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),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let c=t;this.items.forEach(f=>{let u=o.getMirror(--c);if(u==null)return;s=Math.min(s,u);let p=o.maps[u];if(f.step){let m=e.steps[u].invert(e.docs[u]),g=f.selection&&f.selection.map(o.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;fMy&&(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=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let c=s.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=s.selection&&s.selection.map(t.slice(r));h&&o++;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 s.map&&r--},this.items.length,0),new n(kl.from(i.reverse()),o)}};yo.empty=new yo(kl.empty,0);function Ay(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,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},Ey=20;function Ty(n,e,t){let r=Dy(e),i=Al.get(e).spec.config,o=(t?n.undone:n.done).popEvent(e,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),l=(t?n.done:n.undone).addTransform(o.transform,e.selection.getBookmark(),i,r),c=new Ml(t?l:o.remaining,t?o.remaining:l,null,0,-1);return o.transform.setSelection(s).setMeta(Al,{redo:t,historyState:c})}var Cl=!1,fd=null;function Dy(n){let e=n.plugins;if(fd!=e){Cl=!1,fd=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 o=Ty(i,t,n);o&&r(e?o.scrollIntoView():o)}return!0}}var Xr=wo(!1,!0),Qn=wo(!0,!0),bx=wo(!1,!1),xx=wo(!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||!Oy(e)||!Ny(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,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!C.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),r=!1;continue e}break}o=s,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 Oy(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 Ny(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 Iy(){return new H({props:{decorations:Uy,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:vy,handleKeyDown:Ry,handleDOMEvents:{beforeinput:_y}}})}var Ry=Gr({ArrowLeft:bo("horiz",-1),ArrowRight:bo("horiz",1),ArrowUp:bo("vert",-1),ArrowDown:bo("vert",1)});function bo(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,c=s.empty;if(s instanceof A){if(!o.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 vy(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 _y(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 s=r.length-1;s>=0;s--)i=w.from(r[s].createAndFill(null,i));let o=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return o.setSelection(A.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function Uy(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&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var By=500;function md({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,o){return pd(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&pd(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function pd(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-By),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a{let t=n.plugins;for(let r=0;r=0;c--)s.step(l.steps[c].invert(l.docs[c]));if(o.text){let c=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,n.schema.text(o.text,c))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},Py=new bt(/--$/,"\u2014"),Ly=new bt(/\.\.\.$/,"\u2026"),Ox=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Nx=new bt(/"$/,"\u201D"),Ix=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),Rx=new bt(/'$/,"\u2019");var yd=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function zy(n,e){let t={},r;function i(o,s){if(e){let l=e[o];if(l===!1)return;l&&(o=l)}t[o]=s}if(i("Mod-z",Xr),i("Shift-Mod-z",Qn),i("Backspace",gd),yd||i("Mod-y",Qn),i("Alt-ArrowUp",Wr),i("Alt-ArrowDown",od),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",uo(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",uo(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Xn(r)),r=n.nodes.hard_break){let o=r,s=Yr(gl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(o.create()).scrollIntoView()),!0));i("Mod-Enter",s),i("Shift-Enter",s),yd&&i("Ctrl-Enter",s)}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 o=1;o<=6;o++)i("Shift-Ctrl-"+o,pn(r,{level:o}));if(r=n.nodes.horizontal_rule){let o=r;i("Mod-_",(s,l)=>(l&&l(s.tr.replaceSelectionWith(o.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 _=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){(o||(o=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Se=i+N*e;for(let pe=0;per&&(o+=a.attrs.colspan)}}for(let s=0;s1&&(t=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function Hy(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(s)):null,i=Number(n.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let s in e){let l=e[s].getFromDOM,c=l&&l(n);c!=null&&(o[s]=c)}return o}function bd(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 $y(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=>wd(r,e)}],toDOM(r){return["td",bd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>wd(r,e)}],toDOM(r){return["th",bd(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 Wy(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)||jy(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function jy(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 Ky(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 Dd(n,e,t){let r=n.node(-1),i=_.get(r),o=n.start(-1),s=i.nextCell(n.pos-o,e,t);return s==null?null:n.node(0).resolve(o+s)}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 Od(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-o);c.unshift(t.pos-o);let a=c.map(h=>{let d=r.nodeAt(h);if(!d)throw RangeError(`No cell with offset ${h} found`);let f=o+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 o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?xt.rowSelection(r,i):o&&this.isColSelection()?xt.colSelection(r,i):new xt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=_.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];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=_.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),c=e.node(0);return s.top<=l.top?(s.top>0&&(e=c.resolve(o+i.map[s.left])),l.bottom0&&(t=c.resolve(o+i.map[l.left])),s.bottom0)return!1;let s=i+this.$anchorCell.nodeAfter.attrs.colspan,l=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,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=_.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),c=e.node(0);return s.left<=l.left?(s.left>0&&(e=c.resolve(o+i.map[s.top*i.width])),l.right0&&(t=c.resolve(o+i.map[l.top*i.width])),s.right{e.push(ne.node(r,r+t.nodeSize,{class:"selectedCell"}))}),z.create(n.doc,e)}function Qy({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(o+1)>e.start(o));o--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Zy({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let o=n.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){t=o;break}}for(let i=e.depth;i>0;i--){let o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return t!==r&&e.parentOffset===0}function e0(n,e,t){let r=(e||n).selection,i=(e||n).doc,o,s;if(r instanceof C&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=B.create(i,r.from);else if(s=="row"){let l=i.resolve(r.from+1);o=B.rowSelection(l,l)}else if(!t){let l=_.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];o=B.create(i,c+1,a)}}else r instanceof A&&Qy(r)?o=A.create(i,r.from):r instanceof A&&Zy(r)&&(o=A.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=n.tr)).setSelection(o),e}var t0=new le("fix-tables");function Id(n,e,t,r){let i=n.childCount,o=e.childCount;e:for(let s=0,l=0;s{i.type.spec.tableRole=="table"&&(t=n0(n,i,o,t))};return e?e.doc!=n.doc&&Id(e.doc,n.doc,0,r):n.doc.descendants(r),t}function n0(n,e,t,r){let i=_.get(e);if(!i.problems)return r;r||(r=n.tr);let o=[];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;Yy(e,r,i+o)&&(o=i==0||i==e.width?null:0);for(let s=0;s0&&i0&&e.map[l-1]==c||i0?-1:0;o0(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[o]==t[o-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function u0(n){return(e,t)=>{var r;let i=e.selection,o,s;if(i instanceof B){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;o=i.$anchorCell.nodeAfter,s=i.$anchorCell.pos}else{if(o=Wy(i.$from),!o)return!1;s=(r=Zn(i.$from))==null?void 0:r.pos}if(o==null||s==null||o.attrs.colspan==1&&o.attrs.rowspan==1)return!1;if(t){let l=o.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+o.tableStart,m=s.doc.nodeAt(p);m&&s.setNodeMarkup(p,f,m.attrs)}),r(s)}return!0}}var eS=Bl("row",{useDeprecatedLogic:!0}),tS=Bl("column",{useDeprecatedLogic:!0}),nS=Bl("cell",{useDeprecatedLogic:!0});function m0(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 o=n.node(-1).child(r),s=o.lastChild;if(s)return i-1-s.nodeSize;i-=o.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 xo(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((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function w0(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),o=i.type.spec.tableRole,s=i.type.schema,l=[];if(o=="row")for(let c=0;c=0;s--){let{rowspan:l,colspan:c}=o.child(s).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)}o.push(w.from(c))}t=o,e=i}return{width:n,height:e,rows:t}}function S0(n,e,t,r,i,o,s){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 o=t.selection;if(o instanceof B)return Co(t,r,S.near(o.$headCell,e));if(n!="horiz"&&!o.empty)return!1;let s=Ud(i,n,e);if(s==null)return!1;if(n=="horiz")return Co(t,r,S.near(t.doc.resolve(o.head+e),e));{let l=t.doc.resolve(s),c=Dd(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),Co(t,r,a)}}}function ko(n,e){return(t,r,i)=>{if(!i)return!1;let o=t.selection,s;if(o instanceof B)s=o;else{let c=Ud(i,n,e);if(c==null)return!1;s=new B(t.doc.resolve(c))}let l=Dd(s.$headCell,n,e);return l?Co(t,r,new B(s.$anchorCell,l)):!1}}function C0(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 M0(n,e,t){if(!He(n.state))return!1;let r=w0(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 o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),l=_.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=x0(r,l.right-l.left,l.bottom-l.top),Md(n.state,n.dispatch,s,l,r),!0}else if(r){let o=vl(n.state),s=o.start(-1);return Md(n.state,n.dispatch,s,_.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function A0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Ad(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof B)o(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)o(i,e),e.preventDefault();else if(!r)return;function o(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 s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),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(Ad(n,a.target)!=r&&(d=Tl(n,e),!d))return s();d&&o(d,a)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",l)}function Ud(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 o=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.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 Ad(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 E0=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,o){var s;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 D0(-1,!1)},apply(o,s){return s.apply(o)}},props:{attributes:o=>{let s=Ve.getState(o);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,s)=>{O0(o,s,n,e,r)},mouseleave:o=>{N0(o)},mousedown:(o,s)=>{I0(o,s,e)}},decorations:o=>{let s=Ve.getState(o);if(s&&s.activeHandle>-1)return B0(o,s.activeHandle)},nodeViews:{}}});return i}var D0=class Mo{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 Mo(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Mo(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 Mo(i,t.dragging)}return t}};function O0(n,e,t,r,i){let o=Ve.getState(n.state);if(o&&!o.dragging){let s=v0(e.target),l=-1;if(s){let{left:c,right:a}=s.getBoundingClientRect();e.clientX-c<=t?l=Ed(n,e,"left",t):a-e.clientX<=t&&(l=Ed(n,e,"right",t))}if(l!=o.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=_.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}Vd(n,l)}}}function N0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Vd(n,-1)}function I0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,o=Ve.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;let s=n.state.doc.nodeAt(o.activeHandle),l=R0(n,o.activeHandle,s.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&&(_0(n,d.activeHandle,Td(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=Td(d.dragging,h,t);U0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function R0(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let o=n.domAtPos(e),l=o.node.childNodes[o.offset].offsetWidth,c=t;if(r)for(let a=0;ajo,AbstractConnector:()=>dc,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:()=>uc,RelativePosition:()=>st,Skip:()=>ie,Snapshot:()=>jt,Text:()=>ct,Transaction:()=>Yo,UndoManager:()=>Tn,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>ot,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>at,XmlHook:()=>Si,XmlText:()=>xe,YArrayEvent:()=>Qo,YEvent:()=>Dn,YMapEvent:()=>Zo,YTextEvent:()=>es,YXmlEvent:()=>ts,applyUpdate:()=>Mc,applyUpdateV2:()=>vn,cleanupYTextFormatting:()=>Iu,compareIDs:()=>kn,compareRelativePositions:()=>rs,convertUpdateFormatV1ToV2:()=>f1,convertUpdateFormatV2ToV1:()=>pu,createAbsolutePositionFromRelativePosition:()=>Oc,createDeleteSet:()=>br,createDeleteSetFromStructStore:()=>Sc,createDocFromSnapshot:()=>Xw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>Ci,createSnapshot:()=>Mi,decodeRelativePosition:()=>Ww,decodeSnapshot:()=>Yw,decodeSnapshotV2:()=>tu,decodeStateVector:()=>Ec,decodeUpdate:()=>o1,decodeUpdateV2:()=>cu,diffUpdate:()=>a1,diffUpdateV2:()=>Nc,emptySnapshot:()=>Gw,encodeRelativePosition:()=>Jw,encodeSnapshot:()=>Kw,encodeSnapshotV2:()=>eu,encodeStateAsUpdate:()=>Ac,encodeStateAsUpdateV2:()=>Xf,encodeStateVector:()=>Dc,encodeStateVectorFromUpdate:()=>s1,encodeStateVectorFromUpdateV2:()=>hu,equalDeleteSets:()=>Yf,equalSnapshots:()=>jw,findIndexSS:()=>ze,findRootTypeKey:()=>_n,getItem:()=>Cn,getState:()=>P,getTypeChildren:()=>g1,isDeleted:()=>Tt,isParentOf:()=>En,iterateDeletedStructs:()=>rt,logType:()=>zw,logUpdate:()=>i1,logUpdateV2:()=>lu,mergeDeleteSets:()=>Mn,mergeUpdates:()=>au,mergeUpdatesV2:()=>yi,obfuscateUpdate:()=>h1,obfuscateUpdateV2:()=>d1,parseUpdateMeta:()=>l1,parseUpdateMetaV2:()=>du,readUpdate:()=>Vw,readUpdateV2:()=>Cc,relativePositionToJSON:()=>Fw,snapshot:()=>Ai,snapshotContainsUpdate:()=>Zw,transact:()=>R,tryGc:()=>n1,typeListToArraySnapshot:()=>cs,typeMapGetAllSnapshot:()=>Eu,typeMapGetSnapshot:()=>b1});var U=()=>new Map,Ao=n=>{let e=U();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},Bd=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Pd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var Eo=n=>n[n.length-1];var Ld=(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)||U()).values()).forEach(r=>r(...t))}destroy(){this._observers=U()}},tr=class{constructor(){this._observers=U()}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)||U()).values()).forEach(r=>r(...t))}destroy(){this._observers=U()}};var fe=Math.floor;var nr=Math.abs;var De=(n,e)=>nn>e?n:e,dS=Number.isNaN,qd=Math.pow;var Do=n=>n!==0?n<0:1/n<0;var Pl=Number.MAX_SAFE_INTEGER,fS=Number.MIN_SAFE_INTEGER,uS=1<<31;var Hd=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&fe(n)===n),pS=Number.isNaN,mS=Number.parseInt;var Ll=String.fromCharCode,gS=String.fromCodePoint,yS=Ll(65535),L0=n=>n.toLowerCase(),z0=/^\s*/g,F0=n=>n.replace(z0,""),q0=/([A-Z])/g,zl=(n,e)=>F0(n.replace(q0,t=>`${e}${L0(t)}`));var H0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;iir.encode(n),$d=ir?J0:H0;var rr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});rr&&rr.decode(new Uint8Array).length===1&&(rr=null);var Wd=(n,e)=>Fd(e,()=>n).join("");var wn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},F=()=>new wn;var No=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(No(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=Do(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)},Fl=new Uint8Array(3e4),W0=Fl.length/3,j0=(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),o=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,o>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Be(t*2,o)),n.cbuf.set(e.subarray(i)),n.cpos=o)},V=(n,e)=>{x(n,e.byteLength),ar(n,e)},ql=(n,e)=>{$0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},Y0=(n,e)=>ql(n,4).setFloat32(0,e,!1),G0=(n,e)=>ql(n,8).setFloat64(0,e,!1),X0=(n,e)=>ql(n,8).setBigInt64(0,e,!1);var Kd=new DataView(new ArrayBuffer(4)),Q0=n=>(Kd.setFloat32(0,n),Kd.getFloat32(0)===n),sr=(n,e)=>{switch(typeof e){case"string":Q(n,119),Qe(n,e);break;case"number":Hd(e)&&nr(e)<=2147483647?(Q(n,125),ni(n,e)):Q0(e)?(Q(n,124),Y0(n,e)):(Q(n,123),G0(n,e));break;case"bigint":Q(n,122),X0(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 Yd=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++:(Yd(this),this.count=1,this.s=e)}toUint8Array(){return Yd(this),I(this.encoder)}};var Gd=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++):(Gd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Gd(this),I(this.encoder)}},Oo=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 Qd=Ze("Unexpected end of array"),Zd=Ze("Integer out of Range"),hr=class{constructor(e){this.arr=e,this.pos=0}},q=n=>new hr(n),Hl=n=>n.pos!==n.arr.length;var Z0=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>Z0(n,k(n));var xn=n=>n.arr[n.pos++];var k=n=>{let e=0,t=1,r=n.arr.length;for(;n.posPl)throw Zd}throw Qd},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 o=n.arr.length;for(;n.posPl)throw Zd}throw Qd};var ew=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))}},tw=n=>rr.decode(K(n)),Le=rr?tw:ew;var Jl=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},nw=n=>Jl(n,4).getFloat32(0,!1),rw=n=>Jl(n,8).getFloat64(0,!1),iw=n=>Jl(n,8).getBigInt64(0,!1);var ow=[n=>{},n=>null,ii,nw,rw,iw,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;row[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),Hl(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=Do(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}},vo=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 xS=crypto.subtle,ef=crypto.getRandomValues.bind(crypto);var sw=Math.random,$l=()=>ef(new Uint32Array(1))[0];var tf=n=>n[fe(sw()*n.length)],lw="10000000-1000-4000-8000"+-1e11,nf=()=>lw.replace(/[018]/g,n=>(n^$l()&15>>n/4).toString(16));var Ne=Date.now;var Wl=n=>new Promise(n);var CS=Promise.all.bind(Promise);var jl=n=>n===void 0?null:n;var Kl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},of=new Kl,Yl=!0;try{typeof localStorage<"u"&&localStorage&&(of=localStorage,Yl=!1)}catch{}var Uo=of,sf=n=>Yl||addEventListener("storage",n),lf=n=>Yl||removeEventListener("storage",n);var hf=Object.assign,Vo=Object.keys,df=(n,e)=>{for(let t in n)e(n[t],t)},ff=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Gl=n=>Vo(n).length,af=n=>Vo(n).length;var uf=n=>{for(let e in n)return!1;return!0},hw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Xl=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Ql=(n,e)=>n===e||af(n)===af(e)&&hw(n,(t,r)=>(t!==void 0||Xl(e,r))&&e[r]===t),dw=Object.freeze,Zl=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&Zl(n[e])}return dw(n)};var si=(n,e,t=0)=>{try{for(;tn,fw=(n,e)=>n===e;var ur=(n,e)=>{if(n==null||e==null)return fw(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,MS=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,et,uw=[],pw=()=>{if(et===void 0)if(kt){et=U();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");et.set(`--${zl(e,"-")}`,t),et.set(`-${zl(e,"-")}`,t)}})):et=U();return et},nc=n=>pw().has(n);var li=n=>kt?jl(process.env[n.toUpperCase().replaceAll("-","_")]):jl(Uo.getItem(n));var mf=n=>nc("--"+n)||li(n)!==null,AS=mf("production"),mw=kt&&pf(process.env.FORCE_COLOR,["true","1","2"]),gf=mw||!nc("--no-colors")&&!mf("no-color")&&(!kt||process.stdout.isTTY)&&(!kt||nc("--color")||li("COLORTERM")!==null||(li("TERM")||"").includes("color"));var yf=n=>new Uint8Array(n),gw=(n,e,t)=>new Uint8Array(n,e,t),wf=n=>new Uint8Array(n),yw=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),bw=n=>{let e=atob(n),t=yf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return gw(e.buffer,e.byteOffset,e.byteLength)},bf=pr?yw:ww,xf=pr?bw:xw;var Sf=n=>{let e=yf(n.byteLength);return e.set(n),e};var rc=class{constructor(e,t){this.left=e,this.right=t}},tt=(n,e)=>new rc(n,e);var Ct=typeof document<"u"?document:{};var ES=typeof DOMParser<"u"?new DOMParser:null;var Cf=n=>Bd(n,(e,t)=>`${t}:${e};`).join("");var TS=Ct.ELEMENT_NODE,DS=Ct.TEXT_NODE,OS=Ct.CDATA_SECTION_NODE,NS=Ct.COMMENT_NODE,IS=Ct.DOCUMENT_NODE,RS=Ct.DOCUMENT_TYPE_NODE,vS=Ct.DOCUMENT_FRAGMENT_NODE;var Po=n=>class{constructor(t){this._=t}destroy(){n(this._)}},kw=Po(clearTimeout),ai=(n,e)=>new kw(setTimeout(e,n)),US=Po(clearInterval);var VS=Po(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var BS=Po(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var nt=Symbol;var hi=nt(),di=nt(),ic=nt(),oc=nt(),sc=nt(),fi=nt(),lc=nt(),mr=nt(),cc=nt(),Ef=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=U(),i=[],o=0;for(;o0||c.length>0?(e.push("%c"+s),t.push(c)):e.push(s)}else break}}for(o>0&&(i=t,i.unshift(e.join("")));o{console.log(...Tf(n)),Df.forEach(e=>e.print(n))},ac=(...n)=>{console.warn(...Tf(n)),n.unshift(mr),Df.forEach(e=>e.print(n))};var Df=Ce();var Of=n=>({[Symbol.iterator](){return this},next:n}),Nf=(n,e)=>Of(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),zo=(n,e)=>Of(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var dc=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 o=n.doc.store.clients.get(i);for(let s=0;s{let t=0,r=n.length-1;for(;t<=r;){let i=fe((t+r)/2),o=n[i],s=o.clock;if(s<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&Iw(t,e.clock)!==null},xc=n=>{n.clients.forEach(e=>{e.sort((i,o)=>i.clock-o.clock);let t,r;for(t=1,r=1;t=o.clock?i.len=Be(i.len,o.clock+o.len-i.clock):(r{let e=new $t;for(let t=0;t{if(!e.clients.has(i)){let o=r.slice();for(let s=t+1;s{$(n.clients,e,()=>[]).push(new pi(t,r))},br=()=>new $t,Sc=n=>{let e=br();return n.clients.forEach((t,r)=>{let i=[];for(let o=0;o0&&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 o=0;o{let e=new $t,t=k(n.restDecoder);for(let r=0;r0){let s=$(e.clients,i,()=>[]);for(let l=0;l{let r=new $t,i=k(n.restDecoder);for(let o=0;o0){let o=new Ie;return x(o.restEncoder,0),it(o,r),o.toUint8Array()}return null},Yf=(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 o=0;o!0,meta:o=null,autoLoad:s=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Gf(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ko,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=s,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Wl(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>Wl(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 o=new t;return o._integrate(this,null),o}),i=r.constructor;if(t!==W&&i!==t)if(i===W){let o=new t;o._map=r._map,r._map.forEach(s=>{for(;s!==null;s=s.left)s.parent=o}),o._start=r._start;for(let s=o._start;s!==null;s=s.right)s.parent=o;return o._length=r._length,this.share.set(e,o),o._integrate(this,null),o}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 Sf(K(this.restDecoder))}readJSON(){return JSON.parse(Le(this.restDecoder))}readKey(){return Le(this.restDecoder)}},Wo=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 Wo{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 vo(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 o=e[i];o.write(n,r-o.id.clock);for(let s=i+1;s{let r=new Map;t.forEach((i,o)=>{P(e,o)>i&&r.set(o,i)}),Ei(e).forEach((i,o)=>{t.has(o)||r.set(o,0)}),x(n.restEncoder,r.size),$e(r.entries()).sort((i,o)=>o[0]-i[0]).forEach(([i,o])=>{Rw(n,e.clients.get(i),i,o)})},vw=(n,e)=>{let t=U(),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 o=()=>{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},s=o();if(s===null)return null;let l=new Ko,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=s.refs[s.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(s!==null&&s.i0){let u=new Ie;return kc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},Uw=(n,e)=>kc(n,e.doc.store,e.beforeState),Cc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let o=!1,s=i.doc,l=s.store,c=vw(r,s),a=_w(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=vf(r,i,l);if(l.pendingDs){let f=new be(q(l.pendingDs));k(f.restDecoder);let u=vf(f,i,l);d&&u?l.pendingDs=yi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(o){let f=l.pendingStructs.update;l.pendingStructs=null,vn(i.doc,f)}},t,!1),Vw=(n,e,t)=>Cc(n,e,t,new Me(n)),vn=(n,e,t,r=be)=>{let i=q(e);Cc(i,n,t,new r(i))},Mc=(n,e,t)=>vn(n,e,t,Me),Bw=(n,e,t=new Map)=>{kc(n,e.store,t),it(n,Sc(e.store))},Xf=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Ec(e);Bw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Nc(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===ot)return au(i.map((o,s)=>s===0?o:pu(o)));if(t.constructor===Ie)return yi(i)}return i[0]},Ac=(n,e)=>Xf(n,e,new ot),Qf=n=>{let e=new Map,t=k(n.restDecoder);for(let r=0;rQf(new An(q(n))),Tc=(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),Pw=(n,e)=>Tc(n,Ei(e.store)),Lw=(n,e=new gr)=>(n instanceof Map?Tc(e,n):Pw(e,n),e.toUint8Array()),Dc=n=>Lw(n,new Wt),fc=class{constructor(){this.l=[]}},_f=()=>new fc,Uf=(n,e)=>n.l.push(e),Vf=(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.")},Zf=(n,e,t)=>si(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),Bf=(n,e)=>{x(n,e.client),x(n,e.clock)},Pf=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},zw=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))},uc=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=(o,s)=>{let l=o.get("ds"),c=o.get("ids"),a=h=>this.clients.set(h,s);l.observe(h=>{h.changes.added.forEach(d=>{d.content.getContent().forEach(f=>{f instanceof Uint8Array&&this.dss.set(s,Mn([this.dss.get(s)||br(),At(new An(q(f)))]))})})}),this.dss.set(s,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(o=>{o.keysChanged.forEach(s=>i(t.get(s),s))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let o=this.yusers,s=o.get(r);s||(s=new Nn,s.set("ids",new On),s.set("ds",new On),o.set(r,s)),s.get("ids").push([t]),o.observe(l=>{setTimeout(()=>{let c=o.get(r);if(c!==s){s=c,this.clients.forEach((d,f)=>{r===d&&s.get("ids").push([f])});let a=new Wt,h=this.dss.get(r);h&&(it(a,h),s.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=s.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}},st=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},Fw=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 st(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),jo=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},qw=(n,e,t=0)=>new jo(n,e,t),Fo=(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 st(r,i,e,t)},Ci=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return Fo(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Fo(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Fo(n,r.lastId,t);r=r.right}return Fo(n,null,t)},Hw=(n,e)=>{let{type:t,tname:r,item:i,assoc:o}=e;if(i!==null)x(n,0),Bf(n,i);else if(r!==null)cr(n,1),Qe(n,r);else if(t!==null)cr(n,2),Bf(n,t);else throw j();return ni(n,o),n},Jw=n=>{let e=F();return Hw(e,n),I(e)},$w=n=>{let e=null,t=null,r=null;switch(k(n)){case 0:r=Pf(n);break;case 1:t=Le(n);break;case 2:e=Pf(n)}let i=Hl(n)?ii(n):0;return new st(e,t,r,i)},Ww=n=>$w(q(n)),Oc=(n,e,t=!0)=>{let r=e.store,i=n.item,o=n.type,s=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(P(r,i.client)<=i.clock)return null;let h=t?wc(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(s!==null)c=e.get(s);else if(o!==null){if(P(r,o.client)<=o.clock)return null;let{item:h}=t?wc(r,o):{item:Cn(r,o)};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 qw(c,a,n.assoc)},rs=(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}},jw=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,o=e.sv;if(i.size!==o.size||t.size!==r.size)return!1;for(let[s,l]of i.entries())if(o.get(s)!==l)return!1;for(let[s,l]of t.entries()){let c=r.get(s)||[];if(l.length!==c.length)return!1;for(let a=0;a(it(e,n.ds),Tc(e,n.sv),e.toUint8Array()),Kw=n=>eu(n,new Wt),tu=(n,e=new Wo(q(n)))=>new jt(At(e),Qf(e)),Yw=n=>tu(n,new An(q(n))),Mi=(n,e)=>new jt(n,e),Gw=Mi(br(),new Map),Ai=n=>Mi(Sc(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),pc=(n,e)=>{let t=$(n.meta,pc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,o)=>{i{}),t.add(e))},Xw=(n,e,t=new We)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,o=new Ie;return n.transact(s=>{let l=0;r.forEach(c=>{c>0&&l++}),x(o.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 s=i.curr;s!==null;s=i.next())if((n.sv.get(s.id.client)||0)Qw(n,e,Me),Ko=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},nu=(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],o=i.id.clock;if(o===e)return r;let s=fe(e/(o+i.length-1)*r);for(;t<=r;){if(i=n[s],o=i.id.clock,o<=e){if(e{let t=n.clients.get(e.client);return t[ze(t,e.clock)]},Cn=e1,mc=(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[mc(n,t,e.clock)]},Lf=(n,e,t)=>{let r=e.clients.get(t.client),i=ze(r,t.clock),o=r[i];return t.clock!==o.id.clock+o.length-1&&o.constructor!==ue&&r.splice(i+1,0,ns(n,o,t.clock-o.id.clock+1)),o},t1=(n,e,t)=>{let r=n.clients.get(e.id.client);r[ze(r,e.id.clock)]=t},ru=(n,e,t,r,i)=>{if(r===0)return;let o=t+r,s=mc(n,e,t),l;do l=e[s++],oe.deleteSet.clients.size===0&&!Pd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(xc(e.deleteSet),Uw(n,e),it(n,e.deleteSet),!0),Ff=(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)},Jo=(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 o=e-i;return o&&n.splice(e+1-o,o),o},iu=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let o=e.clients.get(r);for(let s=i.length-1;s>=0;s--){let l=i[s],c=l.clock+l.len;for(let a=ze(o,l.clock),h=o[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let o=t.length-1;o>=0;o--){let s=t[o],l=De(i.length-1,1+ze(i,s.clock+s.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=s.clock;a=i[c])c-=1+Jo(i,c)}})},n1=(n,e,t)=>{iu(n,e,t),ou(n,e)},su=(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),Zf(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),si(l,[]),t._needFormattingCleanup&&C1(t)}finally{r.gc&&iu(o,i,r.gcFilter),ou(o,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+Jo(u,m)}});for(let h=s.length-1;h>=0;h--){let{client:d,clock:f}=s[h].id,u=i.clients.get(d),p=ze(u,f);p+11||p>0&&Jo(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(Lo(mr,hi,"[yjs] ",di,fi,"Changed the client-id because another client seems to be using it."),r.clientID=Gf()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new ot;zf(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;zf(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])):su(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,o=!1,s=null;n._transaction===null&&(o=!0,n._transaction=new Yo(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{s=e(n._transaction)}finally{if(o){let l=n._transaction===i[0];n._transaction=null,l&&su(i,0)}}return s},gc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},qf=(n,e,t)=>{rt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>En(i,r))&&Uc(r,!1)})},Hf=(n,e,t)=>{let r=null,i=n.doc,o=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}=wc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&o.some(p=>En(p,u))&&d.push(u)}}),rt(l,a.deletions,u=>{u instanceof O&&o.some(p=>En(p,u))&&!Tt(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=vu(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 s=n.currStackItem;if(s!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:s,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return s},Tn=class extends er{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:s=!1,doc:l=Zr(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,o.add(this),this.trackedOrigins=o,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=s,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 gc(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))&&Uc(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&&ac("[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=>qf(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>qf(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=Hf(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Hf(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*r1(n){let e=k(n.restDecoder);for(let t=0;tlu(n,Me),lu=(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);Lo("Structs: ",t);let o=At(r);Lo("DeleteSet: ",o)},o1=n=>cu(n,Me),cu=(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);return{structs:t,ds:At(r)}},gi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},au=n=>yi(n,Me,ot),hu=(n,e=gr,t=be)=>{let r=new e,i=new lt(new t(q(n)),!1),o=i.curr;if(o!==null){let s=0,l=o.id.client,c=o.id.clock!==0,a=c?0:o.id.clock+o.length;for(;o!==null;o=i.next())l!==o.id.client&&(a!==0&&(s++,x(r.restEncoder,l),x(r.restEncoder,a)),l=o.id.client,a=0,c=o.id.clock!==0),o.constructor===ie&&(c=!0),c||(a=o.id.clock+o.length);a!==0&&(s++,x(r.restEncoder,l),x(r.restEncoder,a));let h=F();return x(h,s),Xd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},s1=n=>hu(n,Wt,Me),du=(n,e=be)=>{let t=new Map,r=new Map,i=new lt(new e(q(n)),!1),o=i.curr;if(o!==null){let s=o.id.client,l=o.id.clock;for(t.set(s,l);o!==null;o=i.next())s!==o.id.client&&(r.set(s,l),t.set(o.id.client,o.id.clock),s=o.id.client),l=o.id.clock+o.length;r.set(s,l)}return{from:t,to:r}},l1=n=>du(n,Me),c1=(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)),o=null,s=new t,l=new gi(s);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(o!==null){let f=h.curr,u=!1;for(;f!==null&&f.id.clock+f.length<=o.struct.id.clock+o.struct.length&&f.id.client>=o.struct.id.client;)f=h.next(),u=!0;if(f===null||f.id.client!==d||u&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(d!==o.struct.id.client)Ht(l,o.struct,o.offset),o={struct:f,offset:0},h.next();else if(o.struct.id.clock+o.struct.length0&&(o.struct.constructor===ie?o.struct.length-=p:f=c1(f,p)),o.struct.mergeWith(f)||(Ht(l,o.struct,o.offset),o={struct:f,offset:0},h.next())}}else o={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==ie;f=h.next())Ht(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(Ht(l,o.struct,o.offset),o=null),Ic(l);let c=r.map(h=>At(h)),a=Mn(c);return it(s,a),s.toUint8Array()},Nc=(n,e,t=be,r=Ie)=>{let i=Ec(e),o=new r,s=new gi(o),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(s,h,Be(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Ht(s,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=f;)c.next()}Ic(s);let a=At(l);return it(o,a),o.toUint8Array()},a1=(n,e)=>Nc(n,e,Me,ot),fu=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&&fu(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++},Ic=n=>{fu(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(q(n)),o=new lt(i,!1),s=new r,l=new gi(s);for(let a=o.curr;a!==null;a=o.next())Ht(l,e(a),0);Ic(l);let c=At(i);return it(s,c),s.toUint8Array()},uu=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=U(),o=U(),s=U(),l=U();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=$(o,d.nodeName,()=>"node-"+r)),d instanceof Si&&(d.hookName=$(o,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=$(s,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=Wd(r%10+"",d.str.length);break}default:j()}return a.parentSub&&(a.parentSub=$(i,a.parentSub,()=>r+"")),r++,c}default:j()}}},h1=(n,e)=>is(n,uu(e),Me,ot),d1=(n,e)=>is(n,uu(e),be,Ie),f1=n=>is(n,ec,Me,Ie),pu=n=>is(n,ec,be,ot),Jf="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=u1(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(Jf);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let o=t._map.get(i),s,l;if(this.adds(o)){let c=o.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(o))if(c!==null&&this.deletes(c))s="delete",l=Eo(c.content.getContent());else return;else c!==null&&this.deletes(c)?(s="update",l=Eo(c.content.getContent())):(s="add",l=void 0)}else if(this.deletes(o))s="delete",l=Eo(o.content.getContent());else return;e.set(i,{action:s,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(Jf);let t=this.target,r=Ce(),i=Ce(),o=[];if(e={added:r,deleted:i,delta:o,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&o.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}},u1=(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},oe=()=>{ac("Invalid access: Add Yjs type to a document before reading data.")},mu=80,Rc=0,yc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Rc++}},p1=n=>{n.timestamp=Rc++},gu=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Rc++},m1=(n,e,t)=>{if(n.length>=mu){let r=n.reduce((i,o)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((o,s)=>nr(e-o.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 o=i.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(i.index-=o.length);if(o===null||o.marker===!0){n.splice(r,1);continue}i.p=o,o.marker=!0}(e0&&e===i.index)&&(i.index=Be(e,i.index+t))}},g1=n=>{n.doc??oe();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},ls=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Zf(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=_f(),this._dEH=_f(),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){Uf(this._eH,e)}observeDeep(e){Uf(this._dEH,e)}unobserve(e){Vf(this._eH,e)}unobserveDeep(e){Vf(this._dEH,e)}toJSON(){}},yu=(n,e,t)=>{n.doc??oe(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],o=n._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){let s=o.content.getContent();if(s.length<=e)e-=s.length;else{for(let l=e;l0;l++)i.push(s[l]),r--;e=0}}o=o.right}return i},wu=n=>{n.doc??oe();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 o=0;o{let t=0,r=n._start;for(n.doc??oe();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let o=0;o{let t=[];return bi(n,(r,i)=>{t.push(e(r,i,n))}),t},y1=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}}}},xu=(n,e)=>{n.doc??oe();let t=ss(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,o=n.doc,s=o.clientID,l=o.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(s,P(l,s)),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(s,P(l,s)),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(s,P(l,s)),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(s,P(l,s)),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()},Su=()=>Ze("Length exceeded!"),ku=(n,e,t,r)=>{if(t>e._length)throw Su();if(t===0)return e._searchMarker&&wi(e._searchMarker,t,r.length),Go(n,e,null,r);let i=t,o=ss(e,t),s=e._start;for(o!==null&&(s=o.p,t-=o.index,t===0&&(s=s.prev,t+=s&&s.countable&&!s.deleted?s.length:0));s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<=s.length){t{let i=(e._searchMarker||[]).reduce((o,s)=>s.index>o.index?s:o,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Go(n,e,i,t)},Cu=(n,e,t,r)=>{if(r===0)return;let i=t,o=r,s=ss(e,t),l=e._start;for(s!==null&&(l=s.p,t-=s.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw Su();e._searchMarker&&wi(e._searchMarker,i,-o+r)},Xo=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},vc=(n,e,t,r)=>{let i=e._map.get(t)||null,o=n.doc,s=o.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(s,P(o.store,s)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},_c=(n,e)=>{n.doc??oe();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Mu=n=>{let e={};return n.doc??oe(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Au=(n,e)=>{n.doc??oe();let t=n._map.get(e);return t!==void 0&&!t.deleted},b1=(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},Eu=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let o=r;for(;o!==null&&(!e.sv.has(o.id.client)||o.id.clock>=(e.sv.get(o.id.client)||0));)o=o.left;o!==null&&qt(o,e)&&(t[i]=o.content.getContent()[o.length-1])}),t},qo=n=>(n.doc??oe(),Nf(n._map.entries(),e=>!e[1].deleted)),Qo=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??oe(),this._length}_callObserver(e,t){super._callObserver(e,t),ls(this,e,new Qo(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{ku(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{w1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Cu(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return xu(this,e)}toArray(){return wu(this)}slice(e=0,t=this.length){return yu(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return bu(this,e)}forEach(e){bi(this,e)}[Symbol.iterator](){return y1(this)}_write(e){e.writeTypeRef(z1)}},x1=n=>new On,Zo=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){ls(this,e,new Zo(this,e,t))}toJSON(){this.doc??oe();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[...qo(this)].length}keys(){return zo(qo(this),e=>e[0])}values(){return zo(qo(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return zo(qo(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??oe(),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=>{Xo(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return _c(this,e)}has(e){return Au(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){Xo(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(F1)}},S1=n=>new Nn,Jt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Ql(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}},$f=(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,o=r?ss(e,t):null;if(o){let s=new xi(o.p.left,o.p,o.index,i);return $f(n,s,t-o.index)}else{let s=new xi(null,e._start,0,i);return $f(n,s,t)}},Tu=(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,o=i.clientID;r.forEach((s,l)=>{let c=t.left,a=t.right,h=new O(M(o,P(i.store,o)),c,c&&c.lastId,a,a&&a.id,e,null,new L(l,s));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)},Du=(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()}},Ou=(n,e,t,r)=>{let i=n.doc,o=i.clientID,s=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Jt(a,c)){s.set(l,a);let{left:h,right:d}=t;t.right=new O(M(o,P(i.store,o)),h,h&&h.lastId,d,d&&d.id,e,null,new L(l,c)),t.right.integrate(n,0),t.forward()}}return s},hc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let o=n.doc,s=o.clientID;Du(t,i);let l=Ou(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(s,P(o.store,s)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=d,t.forward(),Tu(n,e,t,l)},Wf=(n,e,t,r,i)=>{let o=n.doc,s=o.clientID;Du(t,i);let l=Ou(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(s,P(o.store,s)),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()}Tu(n,e,t,l)},Nu=(n,e,t,r,i)=>{let o=e,s=U();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===L){let a=o.content;s.set(a.key,a)}o=o.right}let l=0,c=!1;for(;e!==o;){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;(s.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},k1=(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}},Iu=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,o=U(),s=Ao(o);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case L:xr(s,i.content);break;default:e+=Nu(t,r,i,o,s),o=Ao(s),r=i;break}i=i.right}}),e},C1=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let o=n.beforeState.get(r)||0;i!==o&&ru(n,t.store.clients.get(r),o,i,s=>{!s.deleted&&s.content.constructor===L&&s.constructor!==ue&&e.add(s.parent)})}R(t,r=>{rt(n,n.deleteSet,i=>{if(i instanceof ue||!i.parent._hasFormatting||e.has(i.parent))return;let o=i.parent;i.content.constructor===L?e.add(o):k1(r,i)});for(let i of e)Iu(i)})},jf=(n,e,t)=>{let r=t,i=Ao(e.currentAttributes),o=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,o=new Map,s=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},uf(c)||(u.attributes=hf({},c))),h=0;break}u&&t.push(u),l=null}};for(;s!==null;){switch(s.content.constructor){case Ae:case Et:this.adds(s)?this.deletes(s)||(f(),l="insert",a=s.content.getContent()[0],f()):this.deletes(s)?(l!=="delete"&&(f(),l="delete"),d+=1):s.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case Re:this.adds(s)?this.deletes(s)||(l!=="insert"&&(f(),l="insert"),a+=s.content.str):this.deletes(s)?(l!=="delete"&&(f(),l="delete"),d+=s.length):s.deleted||(l!=="retain"&&(f(),l="retain"),h+=s.length);break;case L:{let{key:u,value:p}=s.content;if(this.adds(s)){if(!this.deletes(s)){let m=i.get(u)??null;Jt(m,p)?p!==null&&s.delete(r):(l==="retain"&&f(),Jt(p,o.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(s)){o.set(u,p);let m=i.get(u)??null;Jt(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!s.deleted){o.set(u,p);let m=c[u];m!==void 0&&(Jt(m,p)?m!==null&&s.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}s.deleted||(l==="insert"&&f(),xr(i,s.content));break}}s=s.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??oe(),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 es(this,e,t);ls(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??oe();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 o=0;o0)&&hc(r,this,i,l,s.attributes||{})}else s.retain!==void 0?Wf(r,this,i,s.retain,s.attributes||{}):s.delete!==void 0&&jf(r,i,s.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??oe();let i=[],o=new Map,s=this.doc,l="",c=this._start;function a(){if(l.length>0){let d={},f=!1;o.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=o.get("ychange");e!==void 0&&!qt(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),o.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(),o.set("ychange",r?r("added",c.id):{type:"added"})):d!==void 0&&(a(),o.delete("ychange")),l+=c.content.str;break}case Ae:case Et:{a();let d={insert:c.content.getContent()[0]};if(o.size>0){let f={};d.attributes=f,o.forEach((u,p)=>{f[p]=u})}i.push(d);break}case L:qt(c,e)&&(a(),xr(o,c.content));break}c=c.right}a()};return e||t?R(s,d=>{e&&pc(d,e),t&&pc(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,o=>{let s=Ho(o,this,e,!r);r||(r={},s.currentAttributes.forEach((l,c)=>{r[c]=l})),hc(o,this,s,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,o=>{let s=Ho(o,this,e,!r);hc(o,this,s,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=>{jf(i,Ho(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,o=>{let s=Ho(o,this,e,!1);s.right!==null&&Wf(o,this,s,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xo(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return _c(this,e)}getAttributes(){return Mu(this)}_write(e){e.writeTypeRef(q1)}},M1=n=>new ct,ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??oe()}[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??oe(),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){ls(this,e,new ts(this,t,e))}toString(){return bu(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,o=>{i.insertBefore(o.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{ku(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;Go(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(o=>o===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=>{Cu(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return wu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return xu(this,e)}slice(e=0,t=this.length){return yu(this,e,t)}forEach(e){bi(this,e)}_write(e){e.writeTypeRef(J1)}},A1=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 df(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`<${o}${s}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xo(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return _c(this,e)}hasAttribute(e){return Au(this,e)}getAttributes(e){return e?Eu(this,e):Mu(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),o=this.getAttributes();for(let s in o){let l=o[s];typeof l=="string"&&i.setAttribute(s,l)}return bi(this,s=>{i.appendChild(s.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(H1),e.writeKey(this.nodeName)}},E1=n=>new Z(n.readKey()),ts=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],o;return i!==void 0?o=i.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(e){e.writeTypeRef($1),e.writeKey(this.hookName)}},T1=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 o=[];for(let s in e.attributes[i])o.push({key:s,value:e.attributes[i][s]});o.sort((s,l)=>s.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(W1)}},D1=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()}},O1=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),nu(e.doc.store,this)}write(e,t){e.writeInfo(O1),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}},N1=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}},I1=n=>new wr(n.readLen()),Ru=(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(Ru(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}},R1=n=>new Rn(Ru(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}},v1=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}},_1=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}},P1=n=>new Re(n.readString()),L1=[x1,S1,M1,E1,A1,T1,D1],z1=0,F1=1,q1=2,H1=3,J1=4,$1=5,W1=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}},j1=n=>new Ae(L1[n.readTypeRef()](n)),wc=(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}},Uc=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},ns=(n,e,t)=>{let{client:r,clock:i}=e.id,o=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&&o.markDeleted(),e.keep&&(o.keep=!0),e.redone!==null&&(o.redone=M(e.redone.client,e.redone.clock+t)),e.right=o,o.right!==null&&(o.right.left=o),n._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),e.length=t,o},Kf=(n,e)=>zd(n,t=>Tt(t.deletions,e)),vu=(n,e,t,r,i,o)=>{let s=n.doc,l=s.store,c=s.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)||vu(n,h,t,r,i,o)===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)||Kf(o.undoStack,d.right.id)||Kf(o.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,Uc(g,!0),g.integrate(n,0),g},O=class n extends yr{constructor(e,t,r,i,o,s,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=o,this.parent=s,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=Lf(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=Lf(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 o=new Set,s=new Set;for(;i!==null&&i!==this.right;){if(s.add(i),o.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),Ff(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?t1(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,o=this.parentSub,s=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(o===null?0:32);if(e.writeInfo(s),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();o!==null&&e.writeString(o)}this.content.write(e,t)}},_u=(n,e)=>K1[e&31](n),K1=[()=>{j()},I1,U1,N1,P1,v1,_1,j1,B1,R1,()=>{j()}],Y1=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(Y1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Uu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Vu="__ $YJS$ __";Uu[Vu]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Uu[Vu]=!0;var Bu=new Map,Vc=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:xf(t.newValue||"")}),sf(this._onChange)}postMessage(e){Uo.setItem(this.room,bf(wf(e)))}close(){lf(this._onChange)}},G1=typeof BroadcastChannel>"u"?Vc:BroadcastChannel,Bc=n=>$(Bu,n,()=>{let e=Ce(),t=new G1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Pu=(n,e)=>(Bc(n).subs.add(e),e),Lu=(n,e)=>{let t=Bc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Bu.delete(n)),r},Vn=(n,e,t=null)=>{let r=Bc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var zu=0,as=1,Fu=2,hs=(n,e)=>{x(n,zu);let t=Dc(e);V(n,t)},Pc=(n,e,t)=>{x(n,as),V(n,Ac(e,t))},Q1=(n,e,t)=>Pc(e,t,K(n)),qu=(n,e,t)=>{try{Mc(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},Hu=(n,e)=>{x(n,Fu),V(n,e)},Z1=qu,Ju=(n,e,t,r)=>{let i=k(n);switch(i){case zu:Q1(n,e,t);break;case as:qu(n,t,r);break;case Fu:Z1(n,t,r);break;default:throw new Error("Unknown message type")}return i};var tb=0;var $u=(n,e,t)=>{switch(k(n)){case tb:t(e,Le(n))}};var Lc=3e4,ds=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&&Lc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,o)=>{o!==this.clientID&&Lc<=t-i.lastUpdated&&this.states.has(o)&&r.push(o)}),r.length>0&&fs(this,r,"timeout")},fe(Lc/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,o=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Ne()});let s=[],l=[],c=[],a=[];e===null?a.push(t):o==null?e!=null&&s.push(t):(l.push(t),ur(o,e)||c.push(t)),(s.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:s,updated:c,removed:a},"local"]),this.emit("update",[{added:s,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},fs=(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 o=0;o{let r=q(e),i=Ne(),o=[],s=[],l=[],c=[],a=k(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:o,updated:l,removed:c},t]),(o.length>0||s.length>0||c.length>0)&&n.emit("update",[{added:o,updated:s,removed:c},t])};var ju=n=>ff(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,Yu=3,Cr=1,ob=2,Ti=[];Ti[Bn]=(n,e,t,r,i)=>{x(n,Bn);let o=Ju(e,n,t.doc,t);r&&o===as&&!t.synced&&(t.synced=!0)};Ti[Yu]=(n,e,t,r,i)=>{x(n,Cr),V(n,kr(t.awareness,Array.from(t.awareness.getStates().keys())))};Ti[Cr]=(n,e,t,r,i)=>{Wu(t.awareness,K(e),t)};Ti[ob]=(n,e,t,r,i)=>{$u(e,t.doc,(o,s)=>sb(t,s))};var Ku=3e4,sb=(n,e)=>console.warn(`Permission denied to access ${n.url}. +${e}`),Gu=(n,e,t)=>{let r=q(e),i=F(),o=k(r),s=n.messageHandlers[o];return s?s(i,r,n,t,o):console.error("Unable to compute message"),i},Xu=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=Gu(n,new Uint8Array(t.data),!0);No(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,fs(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Xu,De(qd(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),hs(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=F();x(r,Cr),V(r,kr(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},zc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},Fc=class extends tr{constructor(e,t,r,{connect:i=!0,awareness:o=new ds(r),params:s={},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=s,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=o,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),hs(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=Gu(this,new Uint8Array(f),!1);No(p)>1&&Vn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=F();x(p,Bn),Hu(p,f),zc(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),V(y,kr(o,g)),zc(this,I(y))},this._exitHandler=()=>{fs(this.awareness,[r.clientID],"app closed")},kt&&typeof process<"u"&&process.on("exit",this._exitHandler),o.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Ku{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var lb=/[\uD800-\uDBFF]/,cb=/[\uDC00-\uDFFF]/,ab=(n,e)=>{let t=0,r=0;for(;t0&&lb.test(n[t-1])&&t--;r+t0&&cb.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Zu=ab;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),hb=[{light:"#ecd44433",dark:"#ecd444"}],db=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,tf(e))}return n.get(t)},np=(n,{colors:e=hb,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:o}={})=>{let s=!1,l=new us(n,o),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),o==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(s||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(s=!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},fb=(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)}),us=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Qu(),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(),o=Ct.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||o.clientWidth||0)&&i.top<=(window.innerHeight||o.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(o=>{let s=r.permanentUserData;s&&s.dss.forEach(h=>{rt(o,h,d=>{})});let l=(h,d)=>{let f=h==="added"?s.getUserByClientId(d.client):s.getUserByDeletedId(d);return{user:f,type:h,color:db(r.colorMapping,r.colors,f)}},c=cs(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 o=this.type.toArray().map(l=>rp(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),s=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(o),0,0));fb(s,this.beforeTransactionSelection,this),s=s.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Tn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&s.scrollIntoView(),this.prosemirrorView.dispatch(s)})}_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))}},rp=(n,e,t,r,i,o)=>{let s=t.get(n);if(s===void 0){if(n instanceof Z)return Oi(n,e,t,r,i,o);throw Oe()}return s},Oi=(n,e,t,r,i,o)=>{let s=[],l=c=>{if(c.constructor===Z){let a=rp(c,e,t,r,i,o);a!==null&&s.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=ub(c,e,t,r,i,o);h!==null&&h.forEach(d=>{d!==null&&s.push(d)})}};r===void 0||i===void 0?n.toArray().forEach(l):cs(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=o?o("added",n._item.id):{type:"added"}):c.ychange=o?o("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,s);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},ub=(n,e,t,r,i,o)=>{let s=[],l=n.toDelta(r,i,o);try{for(let c=0;c{n._item.delete(a)},v),null}return s},pb=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:op(i.marks)}));return t.applyDelta(r),e.set(t,n),t},mb=(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,ms(n).map(r=>qc(r,e))),e.set(t,n),t},qc=(n,e)=>n instanceof Array?pb(n,e):mb(n,e),ep=n=>typeof n=="object"&&n!==null,Jc=(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&&Vo(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(o=>Jc(r.attributes[o.type.name]||{},o.attrs)))},Ri=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Hc(n,e)){let t=ms(e);return n._length===t.length&&Jc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Ri(r,t[i]))}return n instanceof xe&&e instanceof Array&&ip(n,e)},ps=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),tp=(n,e,t)=>{let r=n.toArray(),i=ms(e),o=i.length,s=r.length,l=De(s,o),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}},yb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=gb(n),o=e.map(a=>({insert:a.text,attributes:Object.assign({},r,op(a.marks))})),{insert:s,remove:l,index:c}=Zu(i,o.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,s),n.applyDelta(o.map(a=>({retain:a.insert.length,attributes:a.attributes})))},op=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=ms(t),o=i.length,s=e.toArray(),l=s.length,c=De(o,l),a=0,h=0;for(;a{for(;l-a-h>0&&o-a-h>0;){let f=s[a],u=i[a],p=s[l-h-1],m=i[o-h-1];if(f instanceof xe&&u instanceof Array)ip(f,u)||yb(f,u,r),a+=1;else{let g=f instanceof Z&&Hc(f,u),y=p instanceof Z&&Hc(p,m);if(g&&y){let E=tp(f,u,r),N=tp(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,wb=()=>{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((o,s)=>{r.setMeta(s,o)}),t.dispatch(r))})},$c=(n,e,t)=>{vi||(vi=new Map,ai(0,wb)),$(vi,n,U).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 st(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 st(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 bb(r._item.parent,r._item)}return Ci(e,e._length,-1)},bb=(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 st(t,r,e.id)},Yt=(n,e,t,r)=>{let i=Oc(t,n);if(i===null||i.type!==e&&!En(e,i.type._item))return null;let o=i.type,s=0;if(o.constructor===xe)s=i.index;else if(o._item===null||!o._item.deleted){let l=o._first,c=0;for(;ci(void 0)};return Mr(r,t,n,new Map),t}function lp(n,e="prosemirror"){return jc(n.getXmlFragment(e))}function jc(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(s=>{let l={type:"text",text:s.insert};return s.attributes&&(l.marks=Object.keys(s.attributes).map(c=>{let a=s.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let o=r.getAttributes();Object.keys(o).length&&(i.attrs=o);let s=r.toArray();s.length&&(i.content=s.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var xb=(n,e,t)=>n!==e,Sb=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},kb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Cb=/^#[0-9a-fA-F]{6}$/,cp=(n,e,t,r,i)=>{let o=v.getState(n),s=o.doc,l=[];return o.snapshot!=null||o.prevSnapshot!=null||o.binding.mapping.size===0?z.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(s.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Cb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Yt(s,o.type,Un(c.cursor.anchor),o.binding.mapping),f=Yt(s,o.type,Un(c.cursor.head),o.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))},Mb=(n,{awarenessStateFilter:e=xb,cursorBuilder:t=Sb,selectionBuilder:r=kb,getSelection:i=s=>s.selection}={},o="cursor")=>new H({key:Di,state:{init(s,l){return cp(l,n,e,t,r)},apply(s,l,c,a){let h=v.getState(a),d=s.getMeta(Di);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?cp(a,n,e,t,r):l.map(s.mapping,s.doc)}},props:{decorations:s=>Di.getState(s)},view:s=>{let l=()=>{s.docView&&$c(s,Di,{awarenessUpdated:!0})},c=()=>{let a=v.getState(s.state),h=n.getLocalState()||{};if(s.hasFocus()){let d=i(s.state),f=Pn(d.anchor,a.type,a.binding.mapping),u=Pn(d.head,a.type,a.binding.mapping);(h.cursor==null||!rs(Un(h.cursor.anchor),f)||!rs(Un(h.cursor.head),u))&&n.setLocalStateField(o,{anchor:f,head:u})}else h.cursor!=null&&Yt(a.doc,a.type,Un(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(o,null)};return n.on("change",l),s.dom.addEventListener("focusin",c),s.dom.addEventListener("focusout",c),{update:c,destroy:()=>{s.dom.removeEventListener("focusin",c),s.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(o,null)}}}});var Ab=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.undo(),!0},Eb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.redo(),!0},Tb=new Set(["paragraph"]),Db=(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,Ob=({protectedNodes:n=Tb,trackedOrigins:e=[],undoManager:t=null}={})=>new H({key:Dt,state:{init:(r,i)=>{let o=v.getState(i),s=t||new Tn(o.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Db(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:s,prevSel:null,hasUndoOps:s.undoStack.length>0,hasRedoOps:s.redoStack.length>0}},apply:(r,i,o,s)=>{let l=v.getState(s).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ii(l,o),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),o=Dt.getState(r.state).undoManager;return o.on("stack-item-added",({stackItem:s})=>{let l=i.binding;l&&s.meta.set(l,Dt.getState(r.state).prevSel)}),o.on("stack-item-popped",({stackItem:s})=>{let l=i.binding;l&&(l.beforeTransactionSelection=s.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{o.destroy()}}}});var _i="http://www.w3.org/2000/svg",Nb="http://www.w3.org/1999/xlink",Yc="ProseMirror-icon",Kc="pm-close-dropdowns";function Ib(n){let e=0;for(let t=0;t{o.preventDefault(),r.classList.contains(je+"-disabled")||t.run(e.state,e.dispatch,e,o)});function i(o){if(t.select){let l=t.select(o);if(r.style.display=l?"":"none",!l)return!1}let s=!0;if(t.enable&&(s=t.enable(o)||!1,ap(r,je+"-disabled",!s)),t.active){let l=s&&t.active(o)||!1;ap(r,je+"-active",l)}return!0}return{dom:r,update:i}}};function gs(n,e){return n._props.translate?n._props.translate(e):e}var Ui={time:0,node:null};function _b(n){Ui.time=Date.now(),Ui.node=n.target}function Ub(n){return Date.now()-100{s&&s.close()&&(s=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(Kc,c))};i.addEventListener("mousedown",d=>{d.preventDefault(),_b(d),s?a():(r.dispatchEvent(new CustomEvent(Kc)),s=this.expand(o,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{Ub(o)||a()}),r.addEventListener(Kc,c=()=>{a()}))});function h(d){let f=t.update(d);return o.style.display=f?"":"none",f}return{dom:o,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 o=wt("div",{class:je+"-dropdown-menu "+(this.options.class||"")},r,i),s=!1;function l(){return s?!1:(s=!0,e.removeChild(o),!0)}return e.appendChild(o),{close:l,node:o}}};function Vb(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iWr(n),icon:Vi.join}),Pk=new ht({title:"Lift out of enclosing block",run:jr,select:n=>jr(n),icon:Vi.lift}),Lk=new ht({title:"Select parent node",run:Kr,select:n=>Kr(n),icon:Vi.selectParentNode}),zk=new ht({title:"Undo last change",run:Xr,enable:n=>Xr(n),icon:Vi.undo}),Fk=new ht({title:"Redo last undone change",run:Qn,enable:n=>Qn(n),icon:Vi.redo});function Lb(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 zb(n,e){let t=pn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:o,to:s,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):s<=o.end()&&o.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new ht(r)}function ap(n,e,t){t?n.classList.add(e):n.classList.remove(e)}function dp(n,e,t){let r=t.child(0),o=_.get(t).width;if(r.childCount===1&&r.child(0).attrs.colspan===o)return n;if(r.childCount>1){let s=[],l=null;r.forEach((m,g,y)=>{y===0&&(l=e+1),m.textContent&&s.push(m.textContent)});let c=s[0]||"columns",a=r.child(0).type,h=n.doc.type.schema.nodes.paragraph.create(null,n.doc.type.schema.text(c)),d=a.create({colspan:o,rowspan:1},h),u=n.doc.type.schema.nodes.table_row.create(null,d),p=l+r.nodeSize-1;n.replaceWith(l,p,u)}else if(r.childCount===1){let s=e+1,l=r.child(0);n.setNodeMarkup(s,null,{...l.attrs,colspan:o,rowspan:1})}return n}function fp(n){for(let e=n.depth;e>0;e-=1){let t=n.node(e);if(t.type.name==="table"){let r=n.start(e)-1;return{table:t,tableStart:r,depth:e}}}return null}function rC(n,e){if(!e)return Ul(n,e);let t=n.selection.$from.pos;return Ul(n,i=>{try{let o=i.doc.resolve(t),s=fp(o);if(s){let l=i.doc.nodeAt(s.tableStart);l&&dp(i,s.tableStart,l)}}catch(o){console.warn("Could not fix header row colspan:",o)}e(i)})}function iC(n,e){if(!e)return Vl(n,e);let t=n.selection.$from.pos;return Vl(n,i=>{try{let o=i.doc.resolve(t),s=fp(o);if(s){let l=i.doc.nodeAt(s.tableStart);l&&dp(i,s.tableStart,l)}}catch(o){console.warn("Could not fix header row colspan:",o)}e(i)})}export{zn as DOMParser,It as DOMSerializer,Gc as Dropdown,Bs as EditorState,sl 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,Fc as WebsocketProvider,Sr as Y,iC as addColumnAfter,rC as addColumnBefore,uy as addListNodes,l0 as addRowAfter,s0 as addRowBefore,ad as baseKeymap,qg as baseSchema,zb as blockTypeItem,zy as buildKeymap,T0 as columnResizing,i0 as deleteColumn,a0 as deleteRow,y0 as deleteTable,Rd as fixTables,Iy as gapCursor,g0 as goToNextCell,md as inputRules,He as isInTable,ky as keymap,bl as liftListItem,d0 as mergeCells,sp as prosemirrorToYDoc,Wc as prosemirrorToYXmlFragment,Bb as renderGrouped,Je as selectedRect,pn as setBlockType,xl as sinkListItem,f0 as splitCell,wl as splitListItem,P0 as tableEditing,$y as tableNodes,mn as toggleMark,Xn as wrapIn,uo as wrapInList,Lb as wrapItem,Mb as yCursorPlugin,lp as yDocToProsemirrorJSON,Eb as yRedo,np as ySyncPlugin,Ab as yUndo,Ob as yUndoPlugin,Dt as yUndoPluginKey,jc as yXmlFragmentToProsemirrorJSON}; diff --git a/deps/da-y-wrapper/src/index.js b/deps/da-y-wrapper/src/index.js index c223fc75..8ecd8bb8 100644 --- a/deps/da-y-wrapper/src/index.js +++ b/deps/da-y-wrapper/src/index.js @@ -122,18 +122,6 @@ function findTableFromPos($pos) { return null; } -/** - * Check if the current selection is in the table header row (first row). - */ -function isInTableHeader(state) { - if (!isInTable(state)) { - return false; - } - - const rect = selectedRect(state); - return rect.top === 0; -} - // ensures header row maintains its colspan when adding columns function addColumnBeforeWrapper(state, dispatch) { if (!dispatch) { @@ -189,42 +177,6 @@ function addColumnAfterWrapper(state, dispatch) { return result; } -// Disable addRowBefore when in the header row -function addRowBeforeWrapper(state, dispatch) { - if (isInTableHeader(state)) { - return false; - } - - return addRowBefore(state, dispatch); -} - -// Disable splitCell when in the header row -function splitCellWrapper(state, dispatch) { - if (isInTableHeader(state)) { - return false; - } - - return splitCell(state, dispatch); -} - -// Disable deleteRow when in the header row -function deleteRowWrapper(state, dispatch) { - if (isInTableHeader(state)) { - return false; - } - - return deleteRow(state, dispatch); -} - -// Disable deleteColumn when in the header row -function deleteColumnWrapper(state, dispatch) { - if (isInTableHeader(state)) { - return false; - } - - return deleteColumn(state, dispatch); -} - // All exported export { EditorView, @@ -251,12 +203,12 @@ export { fixTables, addColumnAfterWrapper as addColumnAfter, addColumnBeforeWrapper as addColumnBefore, - deleteColumnWrapper as deleteColumn, + deleteColumn, addRowAfter, - addRowBeforeWrapper as addRowBefore, - deleteRowWrapper as deleteRow, + addRowBefore, + deleteRow, mergeCells, - splitCellWrapper as splitCell, + splitCell, deleteTable, gapCursor, MenuItem, diff --git a/test/unit/blocks/edit/prose/table-modifications.test.js b/test/unit/blocks/edit/prose/table-modifications.test.js index 74858553..5d5e08fc 100644 --- a/test/unit/blocks/edit/prose/table-modifications.test.js +++ b/test/unit/blocks/edit/prose/table-modifications.test.js @@ -190,316 +190,4 @@ describe('Table Modifications', () => { ); }); }); - - describe('Row Operations', () => { - it('should disable add row before when cursor is in header row', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table - insertTable(view.state, view.dispatch); - - // Move cursor to header row - const headerPos = view.state.doc.resolve(3); // Position in header cell - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, headerPos.pos), - ); - view.dispatch(tr); - - // Check if addRowBefore is available (should return false when not available) - const isAvailable = addRowBefore(view.state, null); - - expect(isAvailable).to.equal(false, 'Add row before should be disabled in header row'); - }); - - it('should allow add row after when cursor is in header row', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table - insertTable(view.state, view.dispatch); - - // Move cursor to header row - const headerPos = view.state.doc.resolve(3); - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, headerPos.pos), - ); - view.dispatch(tr); - - // Check if addRowAfter is available (should return true) - const isAvailable = addRowAfter(view.state, null); - - expect(isAvailable).to.equal(true, 'Add row after should be available in header row'); - }); - - it('should allow add row before when cursor is in content row', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table - insertTable(view.state, view.dispatch); - - // The table structure after insertion: - // Row 0 (header): cell with colspan=2, contains "columns" - // Row 1 (content): 2 cells - - // Find the actual position of the first cell in the second row - // We need to navigate past the table node, first row, and into second row - const table = view.state.doc.firstChild; - const firstRow = table.child(0); - - // Position: start of doc (0) + table open (1) + first row size - // + second row open (1) + first cell of second row - const secondRowFirstCellPos = 1 + firstRow.nodeSize + 1; - - const $pos = view.state.doc.resolve(secondRowFirstCellPos); - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, $pos.pos), - ); - view.dispatch(tr); - - // Check if addRowBefore is available (should return true) - const isAvailable = addRowBefore(view.state, null); - - expect(isAvailable).to.equal(true, 'Add row before should be available in content rows'); - }); - - it('should disable split cell when cursor is in header row', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table - insertTable(view.state, view.dispatch); - - // Move cursor to header row - const headerPos = view.state.doc.resolve(3); // Position in header cell - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, headerPos.pos), - ); - view.dispatch(tr); - - // Check if splitCell is available (should return false) - const isAvailable = splitCell(view.state, null); - - expect(isAvailable).to.equal(false, 'Split cell should be disabled in header row'); - }); - - it('should allow split cell when cursor is in content row with merged cells', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table - insertTable(view.state, view.dispatch); - - // Move cursor to content row - const table = view.state.doc.firstChild; - const firstRow = table.child(0); - const secondRowFirstCellPos = 1 + firstRow.nodeSize + 1; - - const $pos = view.state.doc.resolve(secondRowFirstCellPos); - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, $pos.pos), - ); - view.dispatch(tr); - - // Check if splitCell is available - // (will return false for normal cells, true for merged cells) - const isAvailable = splitCell(view.state, null); - - // Normal cells can't be split, so this should be false - // This test just confirms it's not disabled by our constraint - expect(typeof isAvailable).to.equal('boolean', 'Split cell returns boolean'); - }); - - it('should add row with correct number of cells when adding after header', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table (header + 1 content row with 2 cells) - insertTable(view.state, view.dispatch); - - const initialTable = view.state.doc.firstChild; - const initialContentRow = initialTable.child(1); - const initialCellCount = initialContentRow.childCount; - - expect(initialCellCount).to.equal(2, 'Initial content row should have 2 cells'); - - // Move cursor to header row - const headerPos = view.state.doc.resolve(3); - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, headerPos.pos), - ); - view.dispatch(tr); - - // Add row after header - addRowAfter(view.state, view.dispatch); - - // Check the new row (should be at index 1, pushing old content row to index 2) - const updatedTable = view.state.doc.firstChild; - expect(updatedTable.childCount).to.equal(3, 'Table should now have 3 rows'); - - const headerRow = updatedTable.child(0); - const newContentRow = updatedTable.child(1); - const oldContentRow = updatedTable.child(2); - - // Header should be unchanged - expect(headerRow.childCount).to.equal(1, 'Header should still be 1 cell'); - expect(headerRow.child(0).attrs.colspan).to.equal(2, 'Header should still span 2 columns'); - - // New row should have same number of cells as the original content row - expect(newContentRow.childCount).to.equal( - initialCellCount, - 'New row should have same number of cells as original content row', - ); - expect(oldContentRow.childCount).to.equal( - initialCellCount, - 'Old content row should still have same number of cells', - ); - }); - }); - - describe('Delete Operations', () => { - it('should disable delete row when cursor is in header row', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table - insertTable(view.state, view.dispatch); - - // Move cursor to header row - const headerPos = view.state.doc.resolve(3); - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, headerPos.pos), - ); - view.dispatch(tr); - - // Check if deleteRow is available (should return false) - const isAvailable = deleteRow(view.state, null); - - expect(isAvailable).to.equal(false, 'Delete row should be disabled in header row'); - }); - - it('should adjust header colspan when deleting a column', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table (starts with 2 columns) - insertTable(view.state, view.dispatch); - - // Add a column to have 3 columns total - const table = view.state.doc.firstChild; - const firstRow = table.child(0); - const secondRowFirstCellPos = 1 + firstRow.nodeSize + 1; - - const $pos = view.state.doc.resolve(secondRowFirstCellPos); - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, $pos.pos), - ); - view.dispatch(tr); - - addColumnAfter(view.state, view.dispatch); - - // Verify we have 3 columns - const tableWith3Cols = view.state.doc.firstChild; - const headerWith3Cols = tableWith3Cols.child(0); - expect(headerWith3Cols.child(0).attrs.colspan).to.equal(3, 'Header should span 3 columns'); - - // Now delete a column - deleteColumn(view.state, view.dispatch); - - // Check that header colspan adjusted to 2 - const tableWith2Cols = view.state.doc.firstChild; - const headerWith2Cols = tableWith2Cols.child(0); - - expect(headerWith2Cols.childCount).to.equal( - 1, - 'Header should still have 1 cell after deleting column', - ); - expect(headerWith2Cols.child(0).attrs.colspan).to.equal( - 2, - 'Header should span 2 columns after deleting one', - ); - }); - - it('should handle deleting multiple columns and maintain header colspan', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table and add columns to have 4 total - insertTable(view.state, view.dispatch); - - const table = view.state.doc.firstChild; - const firstRow = table.child(0); - const secondRowFirstCellPos = 1 + firstRow.nodeSize + 1; - - const $pos = view.state.doc.resolve(secondRowFirstCellPos); - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, $pos.pos), - ); - view.dispatch(tr); - - // Add 2 columns - addColumnAfter(view.state, view.dispatch); - addColumnAfter(view.state, view.dispatch); - - // Verify 4 columns - let currentTable = view.state.doc.firstChild; - expect(currentTable.child(0).child(0).attrs.colspan).to.equal(4); - - // Delete a column - deleteColumn(view.state, view.dispatch); - - // Check header colspan is 3 - currentTable = view.state.doc.firstChild; - expect(currentTable.child(0).child(0).attrs.colspan).to.equal(3); - - // Delete another column - deleteColumn(view.state, view.dispatch); - - // Check header colspan is 2 - currentTable = view.state.doc.firstChild; - expect(currentTable.child(0).child(0).attrs.colspan).to.equal(2); - }); - - it('should disable delete column when cursor is in header row', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table (starts with 2 columns) - insertTable(view.state, view.dispatch); - - // Move cursor to header row - const headerPos = view.state.doc.resolve(3); - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, headerPos.pos), - ); - view.dispatch(tr); - - // Delete column should be disabled in header row - const isAvailable = deleteColumn(view.state, null); - expect(isAvailable).to.equal(false, 'Delete column should be disabled in header row'); - }); - }); - - describe('Merge Cells Operations', () => { - it('should disable merge cells when cursor is in header row', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table - insertTable(view.state, view.dispatch); - - // Move cursor to header row - const headerPos = view.state.doc.resolve(3); - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, headerPos.pos), - ); - view.dispatch(tr); - - // Check if mergeCells is available (should return false) - const isAvailable = mergeCells(view.state, null); - - expect(isAvailable).to.equal(false, 'Merge cells should be disabled in header row'); - }); - }); }); From 35d9f71569f24c33526377adab7c1873d1742e96 Mon Sep 17 00:00:00 2001 From: Sean Steimer Date: Tue, 11 Nov 2025 14:19:02 -0800 Subject: [PATCH 4/7] fix: lint --- test/unit/blocks/edit/prose/table-modifications.test.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/unit/blocks/edit/prose/table-modifications.test.js b/test/unit/blocks/edit/prose/table-modifications.test.js index 5d5e08fc..2d01c817 100644 --- a/test/unit/blocks/edit/prose/table-modifications.test.js +++ b/test/unit/blocks/edit/prose/table-modifications.test.js @@ -14,12 +14,6 @@ import { expect } from '@esm-bundle/chai'; import { addColumnBefore, addColumnAfter, - addRowBefore, - addRowAfter, - splitCell, - deleteRow, - deleteColumn, - mergeCells, } from 'da-y-wrapper'; import { createTestEditor, destroyEditor } from './test-helpers.js'; import insertTable from '../../../../../blocks/edit/prose/table.js'; From 0e90cc7cbdf0d0a6f5f60f2016b9acf97b541e93 Mon Sep 17 00:00:00 2001 From: Sean Steimer Date: Tue, 11 Nov 2025 14:21:50 -0800 Subject: [PATCH 5/7] simplify tests --- .../edit/prose/table-modifications.test.js | 97 +------------------ 1 file changed, 2 insertions(+), 95 deletions(-) diff --git a/test/unit/blocks/edit/prose/table-modifications.test.js b/test/unit/blocks/edit/prose/table-modifications.test.js index 2d01c817..3a668fa4 100644 --- a/test/unit/blocks/edit/prose/table-modifications.test.js +++ b/test/unit/blocks/edit/prose/table-modifications.test.js @@ -36,17 +36,6 @@ describe('Table Modifications', () => { // Insert a table (starts with 2 columns) insertTable(view.state, view.dispatch); - // Position cursor in a cell of the second row (content row) - // The table structure is: header row (1 cell, colspan 2) + content row (2 cells) - // We need to find and select a cell in the content row - const tableNode = view.state.doc.firstChild; - expect(tableNode.type.name).to.equal('table'); - - // Get initial state - const firstRow = tableNode.child(0); - expect(firstRow.childCount).to.equal(1, 'Header row should have 1 cell'); - expect(firstRow.child(0).attrs.colspan).to.equal(2, 'Header should span 2 columns initially'); - // Move cursor to second row, first cell const secondRowPos = view.state.doc.resolve(5); // Position in second row const tr = view.state.tr.setSelection( @@ -78,14 +67,8 @@ describe('Table Modifications', () => { // Insert a table (starts with 2 columns) insertTable(view.state, view.dispatch); - // Get initial state - const tableNode = view.state.doc.firstChild; - const firstRow = tableNode.child(0); - expect(firstRow.childCount).to.equal(1, 'Header row should have 1 cell'); - expect(firstRow.child(0).attrs.colspan).to.equal(2, 'Header should span 2 columns initially'); - - // Move cursor to second row - const secondRowPos = view.state.doc.resolve(5); + // Move cursor to second row, last cell + const secondRowPos = view.state.doc.resolve(6); const tr = view.state.tr.setSelection( view.state.selection.constructor.create(view.state.doc, secondRowPos.pos), ); @@ -107,81 +90,5 @@ describe('Table Modifications', () => { 'Header should span 3 columns after adding one', ); }); - - it('should maintain header colspan when adding multiple columns', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table (starts with 2 columns) - insertTable(view.state, view.dispatch); - - // Get initial state - const tableNode = view.state.doc.firstChild; - const firstRow = tableNode.child(0); - expect(firstRow.child(0).attrs.colspan).to.equal(2, 'Header should span 2 columns initially'); - - // Move cursor to second row - const secondRowPos = view.state.doc.resolve(5); - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, secondRowPos.pos), - ); - view.dispatch(tr); - - // Add column after - addColumnAfter(view.state, view.dispatch); - - // Add another column after - addColumnAfter(view.state, view.dispatch); - - // Add column before - addColumnBefore(view.state, view.dispatch); - - // Check that header row still has 1 cell and colspan is now 5 - 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 multiple columns', - ); - expect(updatedFirstRow.child(0).attrs.colspan).to.equal( - 5, - 'Header should span 5 columns after adding three', - ); - }); - - it('should preserve header text content when adding columns', async () => { - editor = await createTestEditor(); - const { view } = editor; - - // Insert a table - insertTable(view.state, view.dispatch); - - // Get the header text - const tableNode = view.state.doc.firstChild; - const firstRow = tableNode.child(0); - const headerText = firstRow.child(0).textContent; - expect(headerText).to.equal('columns'); - - // Move cursor to second row - const secondRowPos = view.state.doc.resolve(5); - const tr = view.state.tr.setSelection( - view.state.selection.constructor.create(view.state.doc, secondRowPos.pos), - ); - view.dispatch(tr); - - // Add a column - addColumnBefore(view.state, view.dispatch); - - // Check that header text is preserved - const updatedTable = view.state.doc.firstChild; - const updatedFirstRow = updatedTable.child(0); - const updatedHeaderText = updatedFirstRow.child(0).textContent; - - expect(updatedHeaderText).to.equal( - 'columns', - 'Header text should be preserved after adding column', - ); - }); }); }); From 497483947151e8399dddcecfd8856b5c00538734 Mon Sep 17 00:00:00 2001 From: Cursor AI Date: Thu, 13 Nov 2025 14:16:56 -0800 Subject: [PATCH 6/7] update based on PR feedback Signed-off-by: Sean Steimer --- deps/da-y-wrapper/dist/index.js | 24 ++--- deps/da-y-wrapper/src/index.js | 133 +----------------------- deps/da-y-wrapper/src/table-wrappers.js | 133 ++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 143 deletions(-) create mode 100644 deps/da-y-wrapper/src/table-wrappers.js diff --git a/deps/da-y-wrapper/dist/index.js b/deps/da-y-wrapper/dist/index.js index 0b44163c..e7157a4f 100644 --- a/deps/da-y-wrapper/dist/index.js +++ b/deps/da-y-wrapper/dist/index.js @@ -1,13 +1,13 @@ -var pp=Object.defineProperty;var mp=(n,e)=>{for(var t in e)pp(n,t,{get:e[t],enumerable:!0})};function se(n){this.content=n}se.prototype={constructor:se,find:function(n){for(var e=0;e>1}};se.from=function(n){if(n instanceof se)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new se(e)};var ys=se;function sa(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=sa(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function la(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),c=s.nodeSize;if(s==l){t-=c,r-=c;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let a=0,h=Math.min(s.text.length,l.text.length);for(;ae&&r(c,i+l,o||null,s)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=a},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,o)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||t>0?Pi(r+1,s):Pi(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var Qt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=aa(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(ca(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function ca(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(ca(o.content,e-i-1,t-i-1)))}function aa(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=aa(s.content,e-o-1,t);return l&&n.replaceChild(i,s.copy(l))}function gp(n,e,t){if(t.openStart>n.depth)throw new Qt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Qt("Inconsistent open depths");return ha(n,e,t,0)}function ha(n,e,t,r){let i=n.index(r),o=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Ar(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(Gt(n.nodeAfter,r),o++));for(let l=o;li&&xs(n,e,i+1),s=r.depth>i&&xs(t,r,i+1),l=[];return Ar(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(da(o,s),Gt(Xt(o,fa(n,e,t,r,i+1)),l)):(o&&Gt(Xt(o,Fi(n,e,i+1)),l),Ar(e,t,i,l),s&&Gt(Xt(s,Fi(t,r,i+1)),l)),Ar(r,null,i,l),new w(l)}function Fi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=xs(n,e,t+1);Gt(Xt(i,Fi(n,e,t+1)),r)}return Ar(e,null,t,r),new w(r)}function yp(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var qi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let o=0;o0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Zt(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,o=t;for(let s=e;;){let{index:l,offset:c}=s.content.findIndex(o),a=o-c;if(r.push(s,l,i+c),!a||(s=s.child(l),s.isText))break;o=a-1,i+=c+1}return new n(t,r,o)}static resolveCached(e,t){let r=Xc.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,t,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),ua(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,i,r);return o.type.checkAttrs(o.attrs),o}};Ke.prototype.text=void 0;var ks=class n extends Ke{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):ua(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function ua(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var en=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Cs(e,t);if(r.next==null)return n.empty;let i=pa(r);r.next&&r.err("Unexpected trailing text");let o=Ep(Ap(i));return Tp(o,r),o}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` -`)}};en.empty=new en(!0);var Cs=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function pa(n){let e=[];do e.push(xp(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function xp(n){let e=[];do e.push(Sp(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Sp(n){let e=Mp(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=kp(n,e);else break;return e}function Qc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function kp(n,e){let t=Qc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Qc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Cp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.isInGroup(e)&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function Mp(n){if(n.eat("(")){let e=pa(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=Cp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Ap(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,c){let a={term:c,to:l};return e[s].push(a),a}function i(s,l){s.forEach(c=>c.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((c,a)=>c.concat(o(a,l)),[]);if(s.type=="seq")for(let c=0;;c++){let a=o(s.exprs[c],l);if(c==s.exprs.length-1)return a;i(a,l=t())}else if(s.type=="star"){let c=t();return r(l,c),i(o(s.expr,c),c),[r(c)]}else if(s.type=="plus"){let c=t();return i(o(s.expr,l),c),i(o(s.expr,c),c),[r(c)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let c=l;for(let a=0;a{n[s].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let o=e[r.join(",")]=new en(r.indexOf(n.length-1)>-1);for(let s=0;s-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ya(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ke(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Ke(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let s=this.contentMatch.fillBefore(t);if(!s)return null;t=s.append(t)}let i=this.contentMatch.matchFragment(t),o=i&&i.fillBefore(w.empty,!0);return o?new Ke(this,e,t.append(o),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new n(o,t,s));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Dp(n,e,t){let r=t.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}var Ms=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Dp(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Tr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=ba(e,i.attrs),this.excluded=null;let o=ga(this.attrs);this.instance=o?new D(this,o):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ya(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new n(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}},Dr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=ys.from(e.nodes),t.marks=ys.from(e.marks||{}),this.nodes=Hi.compile(this.spec.nodes,this),this.marks=Tr.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=en.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?ea(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:ea(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Hi){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new ks(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Ke.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function ea(n,e){let t=[];for(let r=0;r-1)&&t.push(s=c)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Op(n){return n.tag!=null}function Np(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Op(i))this.tags.push(i);else if(Np(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new Wi(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Wi(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(s.getAttrs){let c=s.getAttrs(t);if(c===!1)continue;s.attrs=c||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=na(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=na(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},xa={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Ip={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Sa={ol:!0,ul:!0},Ji=1,$i=2,Er=4;function ta(n,e,t){return e!=null?(e?Ji:0)|(e==="full"?$i:0):n&&n.whitespace=="pre"?Ji|$i:t&~Er}var Ln=class{constructor(e,t,r,i,o,s){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=D.none,this.match=o||(s&Er?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ji)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!xa.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Wi=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,o,s=ta(null,t.preserveWhitespace,0)|(r?Er:0);i?o=new Ln(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,s):r?o=new Ln(null,null,D.none,!0,null,s):o=new Ln(e.schema.topNodeType,null,D.none,!0,null,s),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&$i||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Ji)i.options&$i?r=r.replace(/\r\n?/g,` -`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],s=e.previousSibling;(!o||s&&s.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),o;Sa.hasOwnProperty(i)&&this.parser.normalizeLists&&Rp(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,r));if(s?s.ignore:Ip.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let l,c=this.top,a=this.needsBlock;if(xa.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=s&&s.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,s,l,s.consuming===!1?o:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let o,s;if(t.node)if(s=this.parser.schema.nodes[t.node],s.isLeaf)this.insertNode(s.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(s,t.attrs||null,r,t.preserveWhitespace);c&&(o=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}o&&this.sync(l)&&this.open--}addAll(e,t,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];s!=l;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,t);this.findAtPoint(e,o)}findPlace(e,t){let r,i;for(let o=this.open;o>=0;o--){let s=this.nodes[o],l=s.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=s,!l.length)||s.solid)break}if(!r)return null;this.sync(i);for(let o=0;o(s.type?s.type.allowsMarkType(a.type):ra(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Ln(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=o;c--)if(s(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Rp(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Sa.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function vp(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function na(n){let e={};for(let t in n)e[t]=n[t];return e}function ra(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let c=0;c{if(o.length||s.marks.length){let l=0,c=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Li(bs(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Li(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=ia(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return ia(e.marks)}};function ia(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function bs(n){return n.document||window.document}var oa=new WeakMap;function _p(n){let e=oa.get(n);return e===void 0&&oa.set(n,e=Up(n)),e}function Up(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(t=i.slice(0,s),i=i.slice(s+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let d in a)if(a[d]!=null){let f=d.indexOf(" ");f>0?c.setAttributeNS(d.slice(0,f),d.slice(f+1),a[d]):c.setAttribute(d,a[d])}}for(let d=h;dh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=Li(n,f,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var Ma=65535,Aa=Math.pow(2,16);function Bp(n,e){return n+e*Aa}function ka(n){return n&Ma}function Pp(n){return(n-(n&Ma))/Aa}var Ea=1,Ta=2,ji=4,Da=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Da)>0}get deletedBefore(){return(this.delInfo&(Ea|ji))>0}get deletedAfter(){return(this.delInfo&(Ta|ji))>0}get deletedAcross(){return(this.delInfo&ji)>0}},ft=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=ka(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+o],h=this.ranges[l+s],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:Bp(l/3,e-c),m=e==c?Ta:e==d?Ea:ji;return(t<0?e!=c:e!=d)&&(m|=Da),new Ir(u,m,p)}i+=h-a}return r?e+i:new Ir(e+i,0,null)}touches(e,t){let r=0,i=ka(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+o],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+s]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&c!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,o)}invert(){return new tn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("addMark",vr);var tn=class n extends G{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(Ns(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,r)}invert(){return new vr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("removeMark",tn);var _r=class n extends G{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};G.jsonID("replaceAround",X);function Ds(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Lp(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),o.forEach(c=>n.step(c))}function zp(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let c=null;if(r instanceof Tr){let a=s.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(s.marks)&&(c=[r]):c=s.marks;if(c&&c.length){let a=Math.min(l+s.nodeSize,t);for(let h=0;hn.step(new tn(s.from,s.to,s.style)))}function Is(n,e,t,r=t.contentMatch,i=!0){let o=n.doc.nodeAt(e),s=[],l=e+1;for(let c=0;c=0;c--)n.step(s[c])}function Fp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),d++):c--;let f=w.empty,u=0;for(let p=o,m=!1;p>t;p--)m||i.after(p+1)=0;s--){if(r.size){let l=t[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=w.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new X(i,o,i,o,new b(r,0,0),t.length,!0))}function Wp(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{let c=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,c)&&jp(n.doc,n.mapping.slice(o).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Na(n,s,l,o),Is(n,n.mapping.slice(o).map(l,1),r,void 0,a===null);let h=n.mapping.slice(o),d=h.map(l,1),f=h.map(l+s.nodeSize,1);return n.step(new X(d,f,d+1,f-1,new b(w.from(r.create(c,null,s.marks)),0,0),1,!0)),a===!0&&Oa(n,s,l,o),!1}})}function Oa(n,e,t,r){e.forEach((i,o)=>{if(i.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+o+s.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Na(n,e,t,r){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let s=n.mapping.slice(r).map(t+1+o);n.replaceWith(s,s+1,e.type.schema.text(` -`))}})}function jp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Kp(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new X(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new b(w.from(s),0,0),1,!0))}function Rt(n,e,t=1,r){let i=n.resolve(e),o=i.depth-t,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>o;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(o),c=r&&r[0];return i.node(o).canReplaceWith(l,l,c?c.type:i.node(o+1).type)}function Yp(n,e,t=1,r){let i=n.doc.resolve(e),o=w.empty,s=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){o=w.from(i.node(l).copy(o));let h=r&&r[a];s=w.from(h?h.type.create(h.attrs,s):i.node(l).copy(s))}n.step(new Ee(e,e,new b(o.append(s),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Ia(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Gp(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(o=r.node(i+1),l++,s=r.node(i).maybeChild(l)):(o=r.node(i).maybeChild(l-1),s=r.node(i+1)),o&&!o.isTextblock&&Ia(o,s)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function Xp(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,o=n.doc.resolve(e-t),s=o.node().type;if(i&&s.inlineContent){let h=s.whitespace=="pre",d=!!s.contentMatch.matchType(i);h&&!d?r=!1:!h&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Na(n,h.node(),h.before(),l)}s.inlineContent&&Is(n,e+t-1,s,o.node().contentMatchAt(o.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ee(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);Oa(n,h.node(),h.before(),n.steps.length)}return n}function Qp(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,c=r.index(s)+(l>0?1:0),a=r.node(s),h=!1;if(o==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function Xi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return va(i,o,r)?new Ee(e,t,r):new Os(i,o,r).fit()}function va(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Os=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let c=new b(o,s,l);return e>-1?new X(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ee(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Es(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(s?a.matchType(s.type)||(d=a.fillBefore(w.from(s),!1)):o&&c.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:d};if(t==2&&s&&(h=a.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:h};if(o&&a.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Es(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Es(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new b(Or(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new b(Or(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(_a(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Nr(this.placed,t,w.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:c,type:a}=this.frontier[l],h=Ts(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Nr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Nr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Nr(this.placed,this.frontier.length,t))}};function Or(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Or(n.firstChild.content,e-1,t)))}function Nr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Nr(n.lastChild.content,e-1,t)))}function Es(n,e){for(let t=0;t1&&(r=r.replaceChild(0,_a(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function Ts(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Zp(t,o.content,s)?l:null}function Zp(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;s.indexOf(f)>-1?l=f:i.before(f)==u&&s.splice(1,0,-f)}let c=s.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=em(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=s[f];u<0||(e=i.before(u),t=o.after(u))}}function Ua(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(w.empty,!0))}return n}function nm(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Qp(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function rm(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=Va(r,i);for(let s=0;s0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return n.delete(r.before(s),t);n.delete(e,t)}function Va(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}var Ki=class n extends G{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return ft.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};G.jsonID("attr",Ki);var Yi=class n extends G{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ee.ok(r)}getMap(){return ft.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};G.jsonID("docAttr",Yi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Rr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Xi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return tm(this,e,t,r),this}replaceRangeWith(e,t,r){return nm(this,e,t,r),this}deleteRange(e,t){return rm(this,e,t),this}lift(e,t){return qp(this,e,t),this}join(e,t=1){return Xp(this,e,t),this}wrap(e,t){return $p(this,e,t),this}setBlockType(e,t=e,r,i=null){return Wp(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Kp(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Ki(e,t,r)),this}setDocAttribute(e,t){return this.step(new Yi(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Ur(e,t)),this}split(e,t=1,r){return Yp(this,e,t,r),this}addMark(e,t,r){return Lp(this,e,t,r),this}removeMark(e,t,r){return zp(this,e,t,r),this}clearIncompatible(e,t,r){return Is(this,e,t,r),this}};var vs=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new vt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;o--){let s=t<0?Hn(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Hn(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Te(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Te(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=vs[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in vs)throw new RangeError("Duplicate use of selection JSON ID "+e);return vs[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var vt=class{constructor(e,t){this.$from=e,this.$to=t}},Ba=!1;function Pa(n){!Ba&&!n.parent.inlineContent&&(Ba=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Pa(e),Pa(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let o=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(o)t=o.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&C.isSelectable(l))return C.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,o);if(c)return c}t+=l.nodeSize*i}return null}function La(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=h)}),n.setSelection(S.near(n.doc.resolve(s),t))}var za=1,Qi=2,Fa=4,Vs=class extends qn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Qi,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Qi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Qi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Fa,this}get scrolledIntoView(){return(this.updated&Fa)>0}};function qa(n,e){return!e||!n?n:n.bind(e)}var on=class{constructor(e,t,r){this.name=e,this.init=qa(t.init,r),this.apply=qa(t.apply,r)}},om=[new on("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new on("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new on("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new on("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Vr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=om.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new on(r.key,r.spec.state,r))})}},Bs=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(t[r]=o.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Vr(e.schema,e.plugins),o=new n(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=Ke.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=S.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==s.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=a.fromJSON.call(c,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}};function Ha(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Ha(i,e,{})),t[r]=i}return t}var H=class{constructor(e){this.spec=e,this.props={},e.props&&Ha(e.props,this,this.props),this.key=e.key?e.key.key:Ja("plugin")}getState(e){return e[this.key]}},_s=Object.create(null);function Ja(n){return n in _s?n+"$"+ ++_s[n]:(_s[n]=0,n+"$")}var le=class{constructor(e="key"){this.key=Ja(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var te=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},zr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},qs=null,pt=function(n,e,t){let r=qs||(qs=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},sm=function(){qs=null},fn=function(n,e,t,r){return t&&($a(n,e,t,r,-1)||$a(n,e,t,r,1))},lm=/^(img|br|input|textarea|hr)$/i;function $a(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:_e(n))){let o=n.parentNode;if(!o||o.nodeType!=1||Jr(n)||lm.test(n.nodeName)||n.contentEditable=="false")return!1;e=te(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?_e(n):0}else return!1}}function _e(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function cm(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=_e(n)}else if(n.parentNode&&!Jr(n))e=te(n),n=n.parentNode;else return null}}function am(n,e){for(;;){if(n.nodeType==3&&e2),ve=Kn||(Ye?/Mac/.test(Ye.platform):!1),um=Ye?/Win/.test(Ye.platform):!1,Fe=/Android \d/.test(Lt),$r=!!Wa&&"webkitFontSmoothing"in Wa.documentElement.style,pm=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function mm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ut(n,e){return typeof n=="number"?n:n[e]}function gm(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function ja(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;s=zr(s)){if(s.nodeType!=1)continue;let l=s,c=l==o.body,a=c?mm(o):gm(l),h=0,d=0;if(e.topa.bottom-ut(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+ut(i,"top")-a.top:e.bottom-a.bottom+ut(i,"bottom")),e.lefta.right-ut(r,"right")&&(h=e.right-a.right+ut(i,"right")),h||d)if(c)o.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function ym(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:Eh(n.dom)}}function Eh(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=zr(r));return e}function wm({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Th(t,r==0?0:r-e)}function Th(n,e){for(let t=0;t=l){s=Math.max(p.bottom,s),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(o=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?xm(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:Dh(t,i)}function xm(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function ll(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function Sm(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function Cm(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!s&&c.left>r.left||c.top>r.top?i=l.posBefore:(!s&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Oh(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;$r&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=Cm(n,r,i,e))}l==null&&(l=km(n,s,e));let c=n.docView.nearestDesc(s,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Ka(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Br(_t(pt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Ps(c.getBoundingClientRect(),!1)}if(o==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return Ps(c.getBoundingClientRect(),!0)}return Ps(r.getBoundingClientRect(),t>=0)}if(o==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?pt(c,_e(c)-(s?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Br(_t(a,1),!1)}if(o==null&&i<_e(r)){let c=r.childNodes[i];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let a=c?c.nodeType==3?pt(c,0,s?0:1):c.nodeType==1?c:null:null;if(a)return Br(_t(a,-1),!0)}return Br(_t(r.nodeType==3?pt(r):r,-t),t>=0)}function Br(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Ps(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Ih(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Em(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Ih(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Nh(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=pt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?s.top-h.top>(h.bottom-s.top)*2:h.bottom-s.bottom>(s.bottom-h.top)*2))return!1}}return!0})}var Tm=/[\u0590-\u08ac]/;function Dm(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!Tm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Ih(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}var Ya=null,Ga=null,Xa=!1;function Om(n,e,t){return Ya==e&&Ga==t?Xa:(Ya=e,Ga=t,Xa=t=="up"||t=="down"?Em(n,e,t):Dm(n,e,t))}var Ue=0,Qa=1,ln=2,Ge=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Ue,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tte(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof no){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof eo&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?te(o.dom)+1:0}}else{let o,s=!0;for(;o=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=s;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=te(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&st){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+o.border,c=s-o.border;if(e>=l&&t<=c){this.dirty=e==r||t==s?ln:Qa,e==l&&t==c&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Ge:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?ln:Ge}r=s}this.dirty=ln}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?ln:Qa;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=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}},Ws=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 o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=It.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,s.dom,s.contentDOM||s.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&&(o=Gs(o,0,e,r));for(let l=0;l{if(!c)return s;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=_h(h,r,t),a?c=new js(e,t,r,i,h,d||null,f,a,o,s+1):t.isText?new to(e,t,r,i,h,f,o):new n(e,t,r,i,h,d||null,f,o,s+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)&&ro(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,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,c=new Ys(this,s&&s.node,e);vm(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)&&(s&&this.protectLocalComposition(e,s),Rh(this.contentDOM,this.children,e),Kn&&_m(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 o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=Um(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new Ws(this,o,t,i);e.input.compositionNodes.push(s),this.children=Gs(this.children,r,r+i.length,e,s)}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(ro(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=vh(this.dom,this.nodeDOM,Ks(this.outerDeco,this.node,t),Ks(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 Za(n,e,t,r,i){_h(r,e,n);let o=new Pt(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}var to=class n extends Pt{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,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),o=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,o,o,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}},no=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"}},js=class extends Pt{constructor(e,t,r,i,o,s,l,c,a,h){super(e,t,r,i,o,s,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==Ge)return!1;if(this.spec.update){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}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 Rh(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,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[o],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,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,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Rm(n,e){return n.type.side-e.type.side}function vm(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let a=0;ao;)l.push(i[s++]);let p=o+f.nodeSize;if(f.isText){let g=p;s!g.inline):l.slice();r(f,m,e.forChild(o,f),u),o=p}}function _m(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 Um(n,e,t,r){for(let i=0,o=0;i=t){if(o>=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 Gs(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||h<=e?o.push(c):(at&&o.push(c.slice(t-a,c.size,r)))}return o}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),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),c,a;if(ho(t)){for(c=s;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&C.isSelectable(d)&&i.parent&&!(d.isInline&&hm(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;a=new C(s==f?l:r.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=s,f=s;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Uh(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Bm(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 Vh(n,e){if(e instanceof C){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(ih(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else ih(n)}function ih(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 oh(n){return n.editable&&!n.hasFocus()?!1:Bh(n)}function Bh(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 Pm(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 Xs(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&S.findFrom(o,e)}function Ut(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function sh(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return Ut(n,new A(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Xs(n.state,e);return i&&i instanceof C?Ut(n,i):!1}else if(!(ve&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?C.isSelectable(o)?Ut(n,new C(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):$r?Ut(n,new A(n.state.doc.resolve(e<0?l:l+o.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=Xs(n.state,e);return i?Ut(n,i):!1}}}function io(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?Lm(n):zm(n)}function Lm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(qe&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Lr(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Ph(t))break;{let l=t.previousSibling;for(;l&&Lr(l,-1);)i=t.parentNode,o=te(l),l=l.previousSibling;if(l)t=l,r=io(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?Qs(n,t,r):i&&Qs(n,i,o)}function zm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=io(t),o,s;for(;;)if(r{n.state==i&&mt(n)},50)}function lh(n,e){let t=n.state.doc.resolve(e);if(!(ae||um)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function ch(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:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Xs(n.state,e);if(s&&s instanceof C)return Ut(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Te?S.near(s,e):S.findFrom(s,e);return l?Ut(n,l):!1}return!1}function ah(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 o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function hh(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Hm(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;hh(n,r,"true"),setTimeout(()=>hh(n,r,"false"),20)}return!1}function Jm(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function $m(n,e){let t=e.keyCode,r=Jm(e);if(t==8||ve&&t==72&&r=="c")return ah(n,-1)||$n(n,-1);if(t==46&&!e.shiftKey||ve&&t==68&&r=="c")return ah(n,1)||$n(n,1);if(t==13||t==27)return!0;if(t==37||ve&&t==66&&r=="c"){let i=t==37?lh(n,n.state.selection.from)=="ltr"?-1:1:-1;return sh(n,i,r)||$n(n,i)}else if(t==39||ve&&t==70&&r=="c"){let i=t==39?lh(n,n.state.selection.from)=="ltr"?1:-1:1;return sh(n,i,r)||$n(n,i)}else{if(t==38||ve&&t==80&&r=="c")return ch(n,-1,r)||$n(n,-1);if(t==40||ve&&t==78&&r=="c")return Hm(n)||ch(n,1,r)||$n(n,1);if(r==(ve?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Lh(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let s=n.someProp("clipboardSerializer")||It.fromSchema(n.state.schema),l=$h(),c=l.createElement("div");c.appendChild(s.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=Jh[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} ${o}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,` +var up=Object.defineProperty;var pp=(n,e)=>{for(var t in e)up(n,t,{get:e[t],enumerable:!0})};function se(n){this.content=n}se.prototype={constructor:se,find:function(n){for(var e=0;e>1}};se.from=function(n){if(n instanceof se)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new se(e)};var ys=se;function oa(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=oa(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function sa(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),c=s.nodeSize;if(s==l){t-=c,r-=c;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let a=0,h=Math.min(s.text.length,l.text.length);for(;ae&&r(c,i+l,o||null,s)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=a},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,o)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||t>0?Pi(r+1,s):Pi(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var Qt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=ca(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(la(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function la(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(la(o.content,e-i-1,t-i-1)))}function ca(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=ca(s.content,e-o-1,t);return l&&n.replaceChild(i,s.copy(l))}function mp(n,e,t){if(t.openStart>n.depth)throw new Qt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Qt("Inconsistent open depths");return aa(n,e,t,0)}function aa(n,e,t,r){let i=n.index(r),o=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Ar(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(Gt(n.nodeAfter,r),o++));for(let l=o;li&&xs(n,e,i+1),s=r.depth>i&&xs(t,r,i+1),l=[];return Ar(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(ha(o,s),Gt(Xt(o,da(n,e,t,r,i+1)),l)):(o&&Gt(Xt(o,Fi(n,e,i+1)),l),Ar(e,t,i,l),s&&Gt(Xt(s,Fi(t,r,i+1)),l)),Ar(r,null,i,l),new w(l)}function Fi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=xs(n,e,t+1);Gt(Xt(i,Fi(n,e,t+1)),r)}return Ar(e,null,t,r),new w(r)}function gp(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var qi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let o=0;o0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Zt(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,o=t;for(let s=e;;){let{index:l,offset:c}=s.content.findIndex(o),a=o-c;if(r.push(s,l,i+c),!a||(s=s.child(l),s.isText))break;o=a-1,i+=c+1}return new n(t,r,o)}static resolveCached(e,t){let r=Gc.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,t,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),fa(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,i,r);return o.type.checkAttrs(o.attrs),o}};je.prototype.text=void 0;var ks=class n extends je{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):fa(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function fa(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var en=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Cs(e,t);if(r.next==null)return n.empty;let i=ua(r);r.next&&r.err("Unexpected trailing text");let o=Ap(Mp(i));return Tp(o,r),o}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` +`)}};en.empty=new en(!0);var Cs=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function ua(n){let e=[];do e.push(bp(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function bp(n){let e=[];do e.push(xp(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function xp(n){let e=Cp(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=Sp(n,e);else break;return e}function Xc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function Sp(n,e){let t=Xc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Xc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function kp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.isInGroup(e)&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function Cp(n){if(n.eat("(")){let e=ua(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=kp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Mp(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,c){let a={term:c,to:l};return e[s].push(a),a}function i(s,l){s.forEach(c=>c.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((c,a)=>c.concat(o(a,l)),[]);if(s.type=="seq")for(let c=0;;c++){let a=o(s.exprs[c],l);if(c==s.exprs.length-1)return a;i(a,l=t())}else if(s.type=="star"){let c=t();return r(l,c),i(o(s.expr,c),c),[r(c)]}else if(s.type=="plus"){let c=t();return i(o(s.expr,l),c),i(o(s.expr,c),c),[r(c)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let c=l;for(let a=0;a{n[s].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let o=e[r.join(",")]=new en(r.indexOf(n.length-1)>-1);for(let s=0;s-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ga(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new je(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new je(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let s=this.contentMatch.fillBefore(t);if(!s)return null;t=s.append(t)}let i=this.contentMatch.matchFragment(t),o=i&&i.fillBefore(w.empty,!0);return o?new je(this,e,t.append(o),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new n(o,t,s));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Ep(n,e,t){let r=t.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}var Ms=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Ep(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Er=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=wa(e,i.attrs),this.excluded=null;let o=ma(this.attrs);this.instance=o?new D(this,o):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ga(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new n(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}},Dr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=ys.from(e.nodes),t.marks=ys.from(e.marks||{}),this.nodes=Hi.compile(this.spec.nodes,this),this.marks=Er.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=en.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?Zc(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Zc(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Hi){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new ks(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return je.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Zc(n,e){let t=[];for(let r=0;r-1)&&t.push(s=c)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Dp(n){return n.tag!=null}function Op(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Dp(i))this.tags.push(i);else if(Op(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new Wi(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Wi(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(s.getAttrs){let c=s.getAttrs(t);if(c===!1)continue;s.attrs=c||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=ta(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=ta(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},ba={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Np={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},xa={ol:!0,ul:!0},Ji=1,$i=2,Tr=4;function ea(n,e,t){return e!=null?(e?Ji:0)|(e==="full"?$i:0):n&&n.whitespace=="pre"?Ji|$i:t&~Tr}var Ln=class{constructor(e,t,r,i,o,s){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=D.none,this.match=o||(s&Tr?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ji)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!ba.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Wi=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,o,s=ea(null,t.preserveWhitespace,0)|(r?Tr:0);i?o=new Ln(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,s):r?o=new Ln(null,null,D.none,!0,null,s):o=new Ln(e.schema.topNodeType,null,D.none,!0,null,s),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&$i||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Ji)i.options&$i?r=r.replace(/\r\n?/g,` +`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],s=e.previousSibling;(!o||s&&s.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),o;xa.hasOwnProperty(i)&&this.parser.normalizeLists&&Ip(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,r));if(s?s.ignore:Np.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let l,c=this.top,a=this.needsBlock;if(ba.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=s&&s.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,s,l,s.consuming===!1?o:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` +`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let o,s;if(t.node)if(s=this.parser.schema.nodes[t.node],s.isLeaf)this.insertNode(s.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(s,t.attrs||null,r,t.preserveWhitespace);c&&(o=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}o&&this.sync(l)&&this.open--}addAll(e,t,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];s!=l;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,t);this.findAtPoint(e,o)}findPlace(e,t){let r,i;for(let o=this.open;o>=0;o--){let s=this.nodes[o],l=s.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=s,!l.length)||s.solid)break}if(!r)return null;this.sync(i);for(let o=0;o(s.type?s.type.allowsMarkType(a.type):na(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Ln(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=o;c--)if(s(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Ip(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&xa.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Rp(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function ta(n){let e={};for(let t in n)e[t]=n[t];return e}function na(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let c=0;c{if(o.length||s.marks.length){let l=0,c=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Li(bs(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Li(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=ra(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return ra(e.marks)}};function ra(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function bs(n){return n.document||window.document}var ia=new WeakMap;function vp(n){let e=ia.get(n);return e===void 0&&ia.set(n,e=_p(n)),e}function _p(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(t=i.slice(0,s),i=i.slice(s+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let d in a)if(a[d]!=null){let f=d.indexOf(" ");f>0?c.setAttributeNS(d.slice(0,f),d.slice(f+1),a[d]):c.setAttribute(d,a[d])}}for(let d=h;dh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=Li(n,f,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var Ca=65535,Ma=Math.pow(2,16);function Vp(n,e){return n+e*Ma}function Sa(n){return n&Ca}function Bp(n){return(n-(n&Ca))/Ma}var Aa=1,Ta=2,ji=4,Ea=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Ea)>0}get deletedBefore(){return(this.delInfo&(Aa|ji))>0}get deletedAfter(){return(this.delInfo&(Ta|ji))>0}get deletedAcross(){return(this.delInfo&ji)>0}},dt=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=Sa(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+o],h=this.ranges[l+s],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:Vp(l/3,e-c),m=e==c?Ta:e==d?Aa:ji;return(t<0?e!=c:e!=d)&&(m|=Ea),new Ir(u,m,p)}i+=h-a}return r?e+i:new Ir(e+i,0,null)}touches(e,t){let r=0,i=Sa(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+o],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+s]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&c!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,o)}invert(){return new tn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("addMark",vr);var tn=class n extends G{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(Ns(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,r)}invert(){return new vr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("removeMark",tn);var _r=class n extends G{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};G.jsonID("replaceAround",X);function Ds(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Pp(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),o.forEach(c=>n.step(c))}function Lp(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let c=null;if(r instanceof Er){let a=s.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(s.marks)&&(c=[r]):c=s.marks;if(c&&c.length){let a=Math.min(l+s.nodeSize,t);for(let h=0;hn.step(new tn(s.from,s.to,s.style)))}function Is(n,e,t,r=t.contentMatch,i=!0){let o=n.doc.nodeAt(e),s=[],l=e+1;for(let c=0;c=0;c--)n.step(s[c])}function zp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),d++):c--;let f=w.empty,u=0;for(let p=o,m=!1;p>t;p--)m||i.after(p+1)=0;s--){if(r.size){let l=t[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=w.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new X(i,o,i,o,new b(r,0,0),t.length,!0))}function $p(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{let c=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,c)&&Wp(n.doc,n.mapping.slice(o).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Oa(n,s,l,o),Is(n,n.mapping.slice(o).map(l,1),r,void 0,a===null);let h=n.mapping.slice(o),d=h.map(l,1),f=h.map(l+s.nodeSize,1);return n.step(new X(d,f,d+1,f-1,new b(w.from(r.create(c,null,s.marks)),0,0),1,!0)),a===!0&&Da(n,s,l,o),!1}})}function Da(n,e,t,r){e.forEach((i,o)=>{if(i.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+o+s.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Oa(n,e,t,r){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let s=n.mapping.slice(r).map(t+1+o);n.replaceWith(s,s+1,e.type.schema.text(` +`))}})}function Wp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function jp(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new X(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new b(w.from(s),0,0),1,!0))}function Rt(n,e,t=1,r){let i=n.resolve(e),o=i.depth-t,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>o;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(o),c=r&&r[0];return i.node(o).canReplaceWith(l,l,c?c.type:i.node(o+1).type)}function Kp(n,e,t=1,r){let i=n.doc.resolve(e),o=w.empty,s=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){o=w.from(i.node(l).copy(o));let h=r&&r[a];s=w.from(h?h.type.create(h.attrs,s):i.node(l).copy(s))}n.step(new Te(e,e,new b(o.append(s),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Na(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Yp(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(o=r.node(i+1),l++,s=r.node(i).maybeChild(l)):(o=r.node(i).maybeChild(l-1),s=r.node(i+1)),o&&!o.isTextblock&&Na(o,s)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function Gp(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,o=n.doc.resolve(e-t),s=o.node().type;if(i&&s.inlineContent){let h=s.whitespace=="pre",d=!!s.contentMatch.matchType(i);h&&!d?r=!1:!h&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Oa(n,h.node(),h.before(),l)}s.inlineContent&&Is(n,e+t-1,s,o.node().contentMatchAt(o.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Te(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);Da(n,h.node(),h.before(),n.steps.length)}return n}function Xp(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,c=r.index(s)+(l>0?1:0),a=r.node(s),h=!1;if(o==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function Xi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return Ra(i,o,r)?new Te(e,t,r):new Os(i,o,r).fit()}function Ra(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Os=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let c=new b(o,s,l);return e>-1?new X(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Te(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ts(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(s?a.matchType(s.type)||(d=a.fillBefore(w.from(s),!1)):o&&c.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:d};if(t==2&&s&&(h=a.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:h};if(o&&a.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ts(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ts(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new b(Or(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new b(Or(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(va(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Nr(this.placed,t,w.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:c,type:a}=this.frontier[l],h=Es(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Nr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Nr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Nr(this.placed,this.frontier.length,t))}};function Or(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Or(n.firstChild.content,e-1,t)))}function Nr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Nr(n.lastChild.content,e-1,t)))}function Ts(n,e){for(let t=0;t1&&(r=r.replaceChild(0,va(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function Es(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Qp(t,o.content,s)?l:null}function Qp(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;s.indexOf(f)>-1?l=f:i.before(f)==u&&s.splice(1,0,-f)}let c=s.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=Zp(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=s[f];u<0||(e=i.before(u),t=o.after(u))}}function _a(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(w.empty,!0))}return n}function tm(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Xp(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function nm(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=Ua(r,i);for(let s=0;s0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return n.delete(r.before(s),t);n.delete(e,t)}function Ua(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}var Ki=class n extends G{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return dt.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};G.jsonID("attr",Ki);var Yi=class n extends G{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ee.ok(r)}getMap(){return dt.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};G.jsonID("docAttr",Yi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Rr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Xi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return em(this,e,t,r),this}replaceRangeWith(e,t,r){return tm(this,e,t,r),this}deleteRange(e,t){return nm(this,e,t),this}lift(e,t){return Fp(this,e,t),this}join(e,t=1){return Gp(this,e,t),this}wrap(e,t){return Jp(this,e,t),this}setBlockType(e,t=e,r,i=null){return $p(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return jp(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Ki(e,t,r)),this}setDocAttribute(e,t){return this.step(new Yi(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Ur(e,t)),this}split(e,t=1,r){return Kp(this,e,t,r),this}addMark(e,t,r){return Pp(this,e,t,r),this}removeMark(e,t,r){return Lp(this,e,t,r),this}clearIncompatible(e,t,r){return Is(this,e,t,r),this}};var vs=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new vt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;o--){let s=t<0?Hn(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Hn(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Ee(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Ee(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Ee(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=vs[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in vs)throw new RangeError("Duplicate use of selection JSON ID "+e);return vs[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var vt=class{constructor(e,t){this.$from=e,this.$to=t}},Va=!1;function Ba(n){!Va&&!n.parent.inlineContent&&(Va=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Ba(e),Ba(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let o=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(o)t=o.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&C.isSelectable(l))return C.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,o);if(c)return c}t+=l.nodeSize*i}return null}function Pa(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=h)}),n.setSelection(S.near(n.doc.resolve(s),t))}var La=1,Qi=2,za=4,Vs=class extends qn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Qi,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Qi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Qi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=za,this}get scrolledIntoView(){return(this.updated&za)>0}};function Fa(n,e){return!e||!n?n:n.bind(e)}var on=class{constructor(e,t,r){this.name=e,this.init=Fa(t.init,r),this.apply=Fa(t.apply,r)}},im=[new on("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new on("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new on("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new on("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Vr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=im.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new on(r.key,r.spec.state,r))})}},Bs=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(t[r]=o.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Vr(e.schema,e.plugins),o=new n(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=je.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=S.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==s.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=a.fromJSON.call(c,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}};function qa(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=qa(i,e,{})),t[r]=i}return t}var H=class{constructor(e){this.spec=e,this.props={},e.props&&qa(e.props,this,this.props),this.key=e.key?e.key.key:Ha("plugin")}getState(e){return e[this.key]}},_s=Object.create(null);function Ha(n){return n in _s?n+"$"+ ++_s[n]:(_s[n]=0,n+"$")}var le=class{constructor(e="key"){this.key=Ha(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var te=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},zr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},qs=null,ut=function(n,e,t){let r=qs||(qs=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},om=function(){qs=null},fn=function(n,e,t,r){return t&&(Ja(n,e,t,r,-1)||Ja(n,e,t,r,1))},sm=/^(img|br|input|textarea|hr)$/i;function Ja(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:_e(n))){let o=n.parentNode;if(!o||o.nodeType!=1||Jr(n)||sm.test(n.nodeName)||n.contentEditable=="false")return!1;e=te(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?_e(n):0}else return!1}}function _e(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function lm(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=_e(n)}else if(n.parentNode&&!Jr(n))e=te(n),n=n.parentNode;else return null}}function cm(n,e){for(;;){if(n.nodeType==3&&e2),ve=Kn||(Ke?/Mac/.test(Ke.platform):!1),fm=Ke?/Win/.test(Ke.platform):!1,Fe=/Android \d/.test(Lt),$r=!!$a&&"webkitFontSmoothing"in $a.documentElement.style,um=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function pm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ft(n,e){return typeof n=="number"?n:n[e]}function mm(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Wa(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;s=zr(s)){if(s.nodeType!=1)continue;let l=s,c=l==o.body,a=c?pm(o):mm(l),h=0,d=0;if(e.topa.bottom-ft(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+ft(i,"top")-a.top:e.bottom-a.bottom+ft(i,"bottom")),e.lefta.right-ft(r,"right")&&(h=e.right-a.right+ft(i,"right")),h||d)if(c)o.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function gm(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:Ah(n.dom)}}function Ah(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=zr(r));return e}function ym({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Th(t,r==0?0:r-e)}function Th(n,e){for(let t=0;t=l){s=Math.max(p.bottom,s),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(o=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?bm(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:Eh(t,i)}function bm(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function ll(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function xm(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function km(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!s&&c.left>r.left||c.top>r.top?i=l.posBefore:(!s&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Dh(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;$r&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=km(n,r,i,e))}l==null&&(l=Sm(n,s,e));let c=n.docView.nearestDesc(s,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function ja(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Br(_t(ut(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Ps(c.getBoundingClientRect(),!1)}if(o==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return Ps(c.getBoundingClientRect(),!0)}return Ps(r.getBoundingClientRect(),t>=0)}if(o==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?ut(c,_e(c)-(s?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Br(_t(a,1),!1)}if(o==null&&i<_e(r)){let c=r.childNodes[i];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let a=c?c.nodeType==3?ut(c,0,s?0:1):c.nodeType==1?c:null:null;if(a)return Br(_t(a,-1),!0)}return Br(_t(r.nodeType==3?ut(r):r,-t),t>=0)}function Br(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Ps(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Nh(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Am(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Nh(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Oh(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=ut(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?s.top-h.top>(h.bottom-s.top)*2:h.bottom-s.bottom>(s.bottom-h.top)*2))return!1}}return!0})}var Tm=/[\u0590-\u08ac]/;function Em(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!Tm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Nh(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}var Ka=null,Ya=null,Ga=!1;function Dm(n,e,t){return Ka==e&&Ya==t?Ga:(Ka=e,Ya=t,Ga=t=="up"||t=="down"?Am(n,e,t):Em(n,e,t))}var Ue=0,Xa=1,ln=2,Ye=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Ue,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tte(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof no){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof eo&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?te(o.dom)+1:0}}else{let o,s=!0;for(;o=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=s;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=te(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&st){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+o.border,c=s-o.border;if(e>=l&&t<=c){this.dirty=e==r||t==s?ln:Xa,e==l&&t==c&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Ye:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?ln:Ye}r=s}this.dirty=ln}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?ln:Xa;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=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}},Ws=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 o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=It.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,s.dom,s.contentDOM||s.dom)}parseRule(){return this.dirty&Ye||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Ye&&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&&(o=Gs(o,0,e,r));for(let l=0;l{if(!c)return s;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=vh(h,r,t),a?c=new js(e,t,r,i,h,d||null,f,a,o,s+1):t.isText?new to(e,t,r,i,h,f,o):new n(e,t,r,i,h,d||null,f,o,s+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)&&ro(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,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,c=new Ys(this,s&&s.node,e);Rm(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)&&(s&&this.protectLocalComposition(e,s),Ih(this.contentDOM,this.children,e),Kn&&vm(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 o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=_m(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new Ws(this,o,t,i);e.input.compositionNodes.push(s),this.children=Gs(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==Ye||!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(ro(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Rh(this.dom,this.nodeDOM,Ks(this.outerDeco,this.node,t),Ks(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 Qa(n,e,t,r,i){vh(r,e,n);let o=new Pt(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}var to=class n extends Pt{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,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==Ye||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),o=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Ye)}get domAtom(){return!1}isText(e){return this.node.text==e}},no=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"}},js=class extends Pt{constructor(e,t,r,i,o,s,l,c,a,h){super(e,t,r,i,o,s,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==Ye)return!1;if(this.spec.update){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}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 Ih(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,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[o],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,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,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Im(n,e){return n.type.side-e.type.side}function Rm(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let a=0;ao;)l.push(i[s++]);let p=o+f.nodeSize;if(f.isText){let g=p;s!g.inline):l.slice();r(f,m,e.forChild(o,f),u),o=p}}function vm(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 _m(n,e,t,r){for(let i=0,o=0;i=t){if(o>=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 Gs(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||h<=e?o.push(c):(at&&o.push(c.slice(t-a,c.size,r)))}return o}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),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),c,a;if(ho(t)){for(c=s;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&C.isSelectable(d)&&i.parent&&!(d.isInline&&am(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;a=new C(s==f?l:r.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=s,f=s;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!_h(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 Uh(n,e){if(e instanceof C){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(rh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else rh(n)}function rh(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 ih(n){return n.editable&&!n.hasFocus()?!1:Vh(n)}function Vh(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 Bm(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 Xs(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&S.findFrom(o,e)}function Ut(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function oh(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return Ut(n,new A(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Xs(n.state,e);return i&&i instanceof C?Ut(n,i):!1}else if(!(ve&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?C.isSelectable(o)?Ut(n,new C(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):$r?Ut(n,new A(n.state.doc.resolve(e<0?l:l+o.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=Xs(n.state,e);return i?Ut(n,i):!1}}}function io(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?Pm(n):Lm(n)}function Pm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(qe&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Lr(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Bh(t))break;{let l=t.previousSibling;for(;l&&Lr(l,-1);)i=t.parentNode,o=te(l),l=l.previousSibling;if(l)t=l,r=io(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?Qs(n,t,r):i&&Qs(n,i,o)}function Lm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=io(t),o,s;for(;;)if(r{n.state==i&&pt(n)},50)}function sh(n,e){let t=n.state.doc.resolve(e);if(!(ae||fm)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function lh(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:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Xs(n.state,e);if(s&&s instanceof C)return Ut(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Ee?S.near(s,e):S.findFrom(s,e);return l?Ut(n,l):!1}return!1}function ch(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 o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function ah(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function qm(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;ah(n,r,"true"),setTimeout(()=>ah(n,r,"false"),20)}return!1}function Hm(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Jm(n,e){let t=e.keyCode,r=Hm(e);if(t==8||ve&&t==72&&r=="c")return ch(n,-1)||$n(n,-1);if(t==46&&!e.shiftKey||ve&&t==68&&r=="c")return ch(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 oh(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 oh(n,i,r)||$n(n,i)}else{if(t==38||ve&&t==80&&r=="c")return lh(n,-1,r)||$n(n,-1);if(t==40||ve&&t==78&&r=="c")return qm(n)||lh(n,1,r)||$n(n,1);if(r==(ve?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Ph(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let s=n.someProp("clipboardSerializer")||It.fromSchema(n.state.schema),l=Jh(),c=l.createElement("div");c.appendChild(s.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=Hh[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} ${o}${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 zh(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let c=e&&(r||o||!t);if(c){if(n.someProp("transformPastedText",f=>{e=f(e,o||r,n)}),o)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);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),s=Ym(t),$r&&Gm(s);let a=s&&s.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=s.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;s=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!Wm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Xm(dh(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(jm(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 Wm=/^(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 jm(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)),o,s=[];if(n.forEach(l=>{if(!s)return;let c=i.findWrapping(l.type),a;if(!c)return s=null;if(a=s.length&&o.length&&qh(c,o,l,s[s.length-1],0))s[s.length-1]=a;else{s.length&&(s[s.length-1]=Hh(s[s.length-1],o.length));let h=Fh(l,c);s.push(h),i=i.matchType(h.type),o=c}}),s)return w.from(s)}return n}function Fh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function qh(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function dh(n,e,t){return et}).createHTML(n):n}function Ym(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=$h().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Jh[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=Km(n),i)for(let o=0;o=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),o++,s++}return new b(i,o,s)}var ge={},ye={},Qm={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 Zm(n){for(let e in ge){let t=ge[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{tg(n,r)&&!hl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},Qm[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 eg(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 tg(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 ng(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,!jh(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,sn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||$m(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(jh(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",o=>o(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function fo(n){return{left:n.clientX,top:n.clientY}}function rg(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 o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),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 ig(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 og(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof C&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(C.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(jn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function sg(n,e,t,r,i){return dl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?og(n,t):ig(n,t))}function lg(n,e,t,r){return dl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function cg(n,e,t,r){return dl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||ag(n,t,r)}function ag(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 o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)jn(n,A.create(r,l+1,l+1+s.content.size),"pointer");else if(C.isSelectable(s))jn(n,C.create(r,l),"pointer");else continue;return!0}}function fl(n){return oo(n)}var Wh=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=fl(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&rg(t,n.input.lastClick)&&!t[Wh]&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o};let s=n.posAtCoords(fo(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new nl(n,s,t,!!r)):(o=="doubleClick"?lg:cg)(n,s.pos,s.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[Wh],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let h=e.state.doc.resolve(t.pos);o=h.parent,s=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&&o.type.spec.draggable&&o.type.spec.selectable!==!1||a instanceof C&&a.from<=s&&a.to>s)&&(this.mightDrag={node:o,pos:s,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(fo(e))),this.updateAllowDefault(e),this.allowDefault||!t?Vt(this.view,"pointer"):sg(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 jh(n,e){return n.composing?!0:me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var hg=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(),oo(n,!0),n.markCursor=null;else if(oo(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,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}Kh(n,hg)};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++,Kh(n,20))};function Kh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>oo(n),e))}function Yh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=fg());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function dg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=cm(e.focusNode,e.focusOffset),r=am(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function fg(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function oo(n,e=!1){if(!(Fe&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Yh(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 ug(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&&pm<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=Fr?null:t.clipboardData,s=r.content(),{dom:l,text:c}=Lh(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",c)):ug(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function pg(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function mg(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 o=zh(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,o||b.empty)))return!0;if(!o)return!1;let s=pg(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Gh(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,Gh(r),r.getData("text/html"),i,t)?t.preventDefault():mg(n,t)};var so=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Xh=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,o=i.empty?null:n.posAtCoords(fo(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof C?i.to-1:i.to))){if(r&&r.mightDrag)s=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&&(s=C.create(n.state.doc,d.posBefore))}}let l=(s||n.state.selection).content(),{dom:c,text:a,slice:h}=Lh(n,l);(!t.dataTransfer.files.length||!ae||Ah>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 so(h,!t[Xh],s)};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(fo(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",p=>{s=p(s,n)}):s=zh(n,Gh(t.dataTransfer),Fr?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!t[Xh]);if(n.someProp("handleDrop",p=>p(n,t,s||b.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let c=s?Ra(n.state.doc,o.pos,s):o.pos;c==null&&(c=o.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=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,s.content.firstChild):a.replaceRange(h,h,s),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&C.isSelectable(s.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(s.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",o=>o(n,sn(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 lo=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:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new ne(o-r,o-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 o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new ne(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}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,o){let s;for(let l=0;l{let a=c+r,h;if(h=Zh(t,l,a)){for(i||(i=this.children.slice());ol&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&c.type instanceof an){let a=Math.max(o,c.from)-o,h=Math.min(s,c.to)-o;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]+o,-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]+o+1,s);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=yg(l,n,e,t,i,o,s),h=ao(a,r,0,s);e=h.local;for(let d=0;dt&&s.to{let a=Zh(n,l,c+t);if(a){o=!0;let h=ao(a,l,t+c+1,r);h!=ce&&i.push(c,c+l.nodeSize,h)}});let s=Qh(o?ed(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function zs(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])),co.from(e)}var wg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},bg=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}},ol=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()}),bg&&(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,wg)),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(oh(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 o=e.focusNode;o;o=zr(o))t.add(o);for(let o=e.anchorNode;o;o=zr(o))if(t.has(o)){r=o;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)&&oh(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),o=-1,s=-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||kg(e,d)!=u)&&f.remove()}}}let a=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),xg(e)),this.handleDOMChange(o,s,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){o=g;break}if(!E||E.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(s),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:o,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:Mg,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+s,head:y+s}}return{doc:m,sel:p,from:s,to:l}}function Mg(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 Ag=/^(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 Eg(n,e,t,r,i){let o=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()-100up(n,sn(13,"Enter"))))return;let Bi=n.state.tr.setSelection(Nt);T=="pointer"?Bi.setMeta("pointer",!0):T=="key"&&Bi.scrollIntoView(),o&&Bi.setMeta("composition",o),n.dispatch(Bi)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=Cg(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&&!Ag.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,sn(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=yh(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let Nt=n.state.tr.setSelection(T);o&&Nt.setMeta("composition",o),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,sn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Dg(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,sn(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,sn(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=Tg(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=yh(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 Tg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||Fs(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function Og(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,o-Math.min(s,l));r-=s+c-o}if(s=s?o-r:0;o-=c,o&&o=l?o-r:0;o-=c,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}var sl=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(Ch),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=Sh(this),xh(this),this.nodeViews=kh(this),this.docView=Za(this.state.doc,bh(this),zs(this),this.dom,this),this.domObserver=new ol(this,(r,i,o,s)=>Eg(this,r,i,o,s)),this.domObserver.start(),Zm(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(Ch),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,o=!1,s=!1;e.storedMarks&&this.composing&&(Yh(this),s=!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=kh(this);Ig(u,this.nodeViews)&&(this.nodeViews=u,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&tl(this),this.editable=Sh(this),xh(this);let c=zs(this),a=bh(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=o||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(s=!0);let f=h=="preserve"&&s&&this.dom.style.overflowAnchor==null&&ym(this);if(s){this.domObserver.stop();let u=d&&(ke||ae)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Ng(i.selection,e.selection);if(d){let p=ae?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=dg(this)),(o||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Za(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Pm(this))?mt(this,u):(Vh(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&&wm(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&&ja(this,t.getBoundingClientRect(),e)}else ja(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(o))==r.node&&(i=o)}this.dragging=new so(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 s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Mm(this,e)}coordsAtPos(e,t=1){return Nh(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 Om(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&&(eg(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],zs(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,sm())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ng(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&&dm(this.dom.ownerDocument)==this.dom&&Sg(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function bh(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 xh(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 Sh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Ng(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 kh(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 Ig(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 Ch(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 Rg=["p",0],vg=["blockquote",0],_g=["hr"],Ug=["pre",["code",0]],Vg=["br"],Bg={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Rg}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return vg}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return _g}},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 Ug}},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 Vg}}},Pg=["em",0],Lg=["strong",0],zg=["code",0],Fg={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 Pg}},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 Lg}},code:{parseDOM:[{tag:"code"}],toDOM(){return zg}}},qg=new Dr({nodes:Bg,marks:Fg});var nd=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Hg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Jg=(n,e,t)=>{let r=Hg(n,t);if(!r)return!1;let i=rd(r);if(!i){let s=r.blockRange(),l=s&&nn(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(sd(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Gn(o,"end")||C.isSelectable(o)))for(let s=r.depth;;s--){let l=Xi(n.doc,r.before(s),r.after(s),b.empty);if(l&&l.slice.size1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-o.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 $g=(n,e,t)=>{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=rd(r)}let s=o&&o.nodeBefore;return!s||!C.isSelectable(s)?!1:(e&&e(n.tr.setSelection(C.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function rd(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 Wg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=Wg(n,t);if(!r)return!1;let i=id(r);if(!i)return!1;let o=i.nodeAfter;if(sd(n,i,e,1))return!0;if(r.parent.content.size==0&&(Gn(o,"start")||C.isSelectable(o))){let s=Xi(n.doc,r.before(),r.after(),b.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=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=Rs(n.doc,t.from,-1),i==null)return!1;if(e){let o=n.tr.join(i);r&&o.setSelection(C.create(o.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(o.scrollIntoView())}return!0},od=(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=Rs(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),o=i&&nn(i);return o==null?!1:(e&&e(n.tr.lift(i,o).scrollIntoView()),!0)},Yg=(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),o=t.indexAfter(-1),s=ml(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,s.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},Gg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Te||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=ml(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!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 o=t.before();if(Rt(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Qg(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 o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof A||e.selection instanceof Te)&&s.deleteSelection();let l=r.depth==0?null:ml(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,o,r),a=c?[c]:o&&l?[{type:l}]:void 0,h=Rt(s.doc,s.mapping.map(r.pos),1,a);if(!a&&!h&&Rt(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(s.split(s.mapping.map(r.pos),1,a),!o&&!r.parentOffset&&r.parent.type!=l){let d=s.mapping.map(r.before()),f=s.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}return t&&t(s.scrollIntoView()),!0}}var Zg=Qg();var Kr=(n,e)=>{let{$from:t,to:r}=n.selection,i,o=t.sharedDepth(r);return o==0?!1:(i=t.before(o),e&&e(n.tr.setSelection(C.create(n.doc,i))),!0)},ey=(n,e)=>(e&&e(n.tr.setSelection(new Te(n.doc))),!0);function ty(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||rn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function sd(n,e,t,r){let i=e.nodeBefore,o=e.nodeAfter,s,l,c=i.type.spec.isolating||o.type.spec.isolating;if(!c&&ty(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(s=(l=i.contentMatchAt(i.childCount)).findWrapping(o.type))&&l.matchType(s[0]||o.type).validEnd){if(t){let u=e.pos+o.nodeSize,p=w.empty;for(let y=s.length-1;y>=0;y--)p=w.from(s[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),s.length,!0)),g=m.doc.resolve(u+2*s.length);g.nodeAfter&&g.nodeAfter.type==i.type&&rn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=o.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(o,"start",!0)&&Gn(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=o,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+o.nodeSize,e.pos+g,e.pos+o.nodeSize-g,new b(y,p.length,0),0,!0));t(E.scrollIntoView())}return!0}}return!1}function ld(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}var ny=ld(-1),ry=ld(1);function Xn(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o),l=s&&Gi(s,n,e);return l?(r&&r(t.tr.wrap(s,l).scrollIntoView()),!0):!1}}function pn(n,e=null){return function(t,r){let i=!1;for(let o=0;o{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 o=t.tr;for(let s=0;s{if(l||!r&&c.isAtom&&c.isInline&&a>=o.pos&&a+c.nodeSize<=s.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function oy(n){let e=[];for(let t=0;t{if(o.isAtom&&o.content.size&&o.isInline&&s>=r.pos&&s+o.nodeSize<=i.pos)return s+1>r.pos&&e.push(new vt(r,r.doc.resolve(s+1))),r=r.doc.resolve(s+1+o.content.size),!1}),r.poso.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(s.depth-1).type.compatibleContent(n)&&s.startIndex==0){if(i.index(s.depth-1)==0)return!1;let h=t.doc.resolve(s.start-2);c=new Zt(h,h,s.depth),s.endIndex=0;h--)o=w.from(t[h].type.create(t[h].attrs,o));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(o,0,0),t.length,!0));let s=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=o.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,o.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,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?my(e,t,n,o):gy(e,t,o):!0:!1}}function my(n,e,t,r){let i=n.tr,o=r.end,s=r.$to.end(r.depth);om;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let o=r.doc.resolve(t.start),s=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=o.node(-1),h=o.index(-1);if(!a.canReplace(h+(l?0:1),h+1,s.content.append(c?w.empty:w.from(i))))return!1;let d=o.pos,f=d+s.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,o=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let l=o.parent,c=l.child(s-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=o.start,u=o.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:"'"},mo={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},yy=typeof navigator<"u"&&/Mac/.test(navigator.platform),wy=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),mo[J]=String.fromCharCode(J);var J;for(po in yt)mo.hasOwnProperty(po)||(mo[po]=yt[po]);var po;function hd(n){var e=yy&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||wy&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?mo: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 by=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function xy(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=yt[r.keyCode])&&o!=i){let l=e[Sl(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var go=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(o,s){return i.push(e(o,s))},t,r),i};re.from=function(e){return e instanceof re?e:e&&e.length?new dd(e):re.empty};var dd=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,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,l){for(var c=o;c=s;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=go)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=go)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 dd([]);var Cy=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,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(o,l)-l,s+l)===!1||o=o?this.right.slice(r-o,i-o):this.left.slice(r,o).append(this.right.slice(0,i-o))},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 My=500,yo=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,o;t&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,l,c,a=[],h=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),o=i.maps.length),o--,h.push(d);return}if(i){h.push(new Xe(d.map));let u=d.step.map(i.slice(o)),p;u&&s.maybeStep(u).doc&&(p=s.mapping.maps[s.mapping.maps.length-1],a.push(new Xe(p,void 0,void 0,a.length+h.length))),o--,p&&i.appendMap(p,o)}else s.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(o)):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:s,selection:l}}addTransform(e,t,r,i){let o=[],s=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hEy&&(l=Ay(l,a),s-=a),new n(l.append(o),s)}remapping(e,t){let r=new Rr;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},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),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let c=t;this.items.forEach(f=>{let u=o.getMirror(--c);if(u==null)return;s=Math.min(s,u);let p=o.maps[u];if(f.step){let m=e.steps[u].invert(e.docs[u]),g=f.selection&&f.selection.map(o.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;fMy&&(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=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let c=s.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=s.selection&&s.selection.map(t.slice(r));h&&o++;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 s.map&&r--},this.items.length,0),new n(kl.from(i.reverse()),o)}};yo.empty=new yo(kl.empty,0);function Ay(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,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},Ey=20;function Ty(n,e,t){let r=Dy(e),i=Al.get(e).spec.config,o=(t?n.undone:n.done).popEvent(e,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),l=(t?n.done:n.undone).addTransform(o.transform,e.selection.getBookmark(),i,r),c=new Ml(t?l:o.remaining,t?o.remaining:l,null,0,-1);return o.transform.setSelection(s).setMeta(Al,{redo:t,historyState:c})}var Cl=!1,fd=null;function Dy(n){let e=n.plugins;if(fd!=e){Cl=!1,fd=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 o=Ty(i,t,n);o&&r(e?o.scrollIntoView():o)}return!0}}var Xr=wo(!1,!0),Qn=wo(!0,!0),bx=wo(!1,!1),xx=wo(!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||!Oy(e)||!Ny(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,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!C.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),r=!1;continue e}break}o=s,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 Oy(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 Ny(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 Iy(){return new H({props:{decorations:Uy,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:vy,handleKeyDown:Ry,handleDOMEvents:{beforeinput:_y}}})}var Ry=Gr({ArrowLeft:bo("horiz",-1),ArrowRight:bo("horiz",1),ArrowUp:bo("vert",-1),ArrowDown:bo("vert",1)});function bo(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,c=s.empty;if(s instanceof A){if(!o.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 vy(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 _y(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 s=r.length-1;s>=0;s--)i=w.from(r[s].createAndFill(null,i));let o=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return o.setSelection(A.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function Uy(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&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var By=500;function md({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,o){return pd(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&pd(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function pd(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-By),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a{let t=n.plugins;for(let r=0;r=0;c--)s.step(l.steps[c].invert(l.docs[c]));if(o.text){let c=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,n.schema.text(o.text,c))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},Py=new bt(/--$/,"\u2014"),Ly=new bt(/\.\.\.$/,"\u2026"),Ox=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Nx=new bt(/"$/,"\u201D"),Ix=new bt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),Rx=new bt(/'$/,"\u2019");var yd=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function zy(n,e){let t={},r;function i(o,s){if(e){let l=e[o];if(l===!1)return;l&&(o=l)}t[o]=s}if(i("Mod-z",Xr),i("Shift-Mod-z",Qn),i("Backspace",gd),yd||i("Mod-y",Qn),i("Alt-ArrowUp",Wr),i("Alt-ArrowDown",od),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",uo(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",uo(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Xn(r)),r=n.nodes.hard_break){let o=r,s=Yr(gl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(o.create()).scrollIntoView()),!0));i("Mod-Enter",s),i("Shift-Enter",s),yd&&i("Ctrl-Enter",s)}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 o=1;o<=6;o++)i("Shift-Ctrl-"+o,pn(r,{level:o}));if(r=n.nodes.horizontal_rule){let o=r;i("Mod-_",(s,l)=>(l&&l(s.tr.replaceSelectionWith(o.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 _=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){(o||(o=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Se=i+N*e;for(let pe=0;per&&(o+=a.attrs.colspan)}}for(let s=0;s1&&(t=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function Hy(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(s)):null,i=Number(n.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let s in e){let l=e[s].getFromDOM,c=l&&l(n);c!=null&&(o[s]=c)}return o}function bd(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 $y(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=>wd(r,e)}],toDOM(r){return["td",bd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>wd(r,e)}],toDOM(r){return["th",bd(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 Wy(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)||jy(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function jy(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 Ky(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 Dd(n,e,t){let r=n.node(-1),i=_.get(r),o=n.start(-1),s=i.nextCell(n.pos-o,e,t);return s==null?null:n.node(0).resolve(o+s)}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 Od(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-o);c.unshift(t.pos-o);let a=c.map(h=>{let d=r.nodeAt(h);if(!d)throw RangeError(`No cell with offset ${h} found`);let f=o+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 o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?xt.rowSelection(r,i):o&&this.isColSelection()?xt.colSelection(r,i):new xt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=_.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];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=_.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),c=e.node(0);return s.top<=l.top?(s.top>0&&(e=c.resolve(o+i.map[s.left])),l.bottom0&&(t=c.resolve(o+i.map[l.left])),s.bottom0)return!1;let s=i+this.$anchorCell.nodeAfter.attrs.colspan,l=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,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=_.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),c=e.node(0);return s.left<=l.left?(s.left>0&&(e=c.resolve(o+i.map[s.top*i.width])),l.right0&&(t=c.resolve(o+i.map[l.top*i.width])),s.right{e.push(ne.node(r,r+t.nodeSize,{class:"selectedCell"}))}),z.create(n.doc,e)}function Qy({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(o+1)>e.start(o));o--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Zy({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let o=n.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){t=o;break}}for(let i=e.depth;i>0;i--){let o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return t!==r&&e.parentOffset===0}function e0(n,e,t){let r=(e||n).selection,i=(e||n).doc,o,s;if(r instanceof C&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=B.create(i,r.from);else if(s=="row"){let l=i.resolve(r.from+1);o=B.rowSelection(l,l)}else if(!t){let l=_.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];o=B.create(i,c+1,a)}}else r instanceof A&&Qy(r)?o=A.create(i,r.from):r instanceof A&&Zy(r)&&(o=A.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=n.tr)).setSelection(o),e}var t0=new le("fix-tables");function Id(n,e,t,r){let i=n.childCount,o=e.childCount;e:for(let s=0,l=0;s{i.type.spec.tableRole=="table"&&(t=n0(n,i,o,t))};return e?e.doc!=n.doc&&Id(e.doc,n.doc,0,r):n.doc.descendants(r),t}function n0(n,e,t,r){let i=_.get(e);if(!i.problems)return r;r||(r=n.tr);let o=[];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;Yy(e,r,i+o)&&(o=i==0||i==e.width?null:0);for(let s=0;s0&&i0&&e.map[l-1]==c||i0?-1:0;o0(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[o]==t[o-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function u0(n){return(e,t)=>{var r;let i=e.selection,o,s;if(i instanceof B){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;o=i.$anchorCell.nodeAfter,s=i.$anchorCell.pos}else{if(o=Wy(i.$from),!o)return!1;s=(r=Zn(i.$from))==null?void 0:r.pos}if(o==null||s==null||o.attrs.colspan==1&&o.attrs.rowspan==1)return!1;if(t){let l=o.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+o.tableStart,m=s.doc.nodeAt(p);m&&s.setNodeMarkup(p,f,m.attrs)}),r(s)}return!0}}var eS=Bl("row",{useDeprecatedLogic:!0}),tS=Bl("column",{useDeprecatedLogic:!0}),nS=Bl("cell",{useDeprecatedLogic:!0});function m0(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 o=n.node(-1).child(r),s=o.lastChild;if(s)return i-1-s.nodeSize;i-=o.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 xo(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((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function w0(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),o=i.type.spec.tableRole,s=i.type.schema,l=[];if(o=="row")for(let c=0;c=0;s--){let{rowspan:l,colspan:c}=o.child(s).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)}o.push(w.from(c))}t=o,e=i}return{width:n,height:e,rows:t}}function S0(n,e,t,r,i,o,s){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 o=t.selection;if(o instanceof B)return Co(t,r,S.near(o.$headCell,e));if(n!="horiz"&&!o.empty)return!1;let s=Ud(i,n,e);if(s==null)return!1;if(n=="horiz")return Co(t,r,S.near(t.doc.resolve(o.head+e),e));{let l=t.doc.resolve(s),c=Dd(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),Co(t,r,a)}}}function ko(n,e){return(t,r,i)=>{if(!i)return!1;let o=t.selection,s;if(o instanceof B)s=o;else{let c=Ud(i,n,e);if(c==null)return!1;s=new B(t.doc.resolve(c))}let l=Dd(s.$headCell,n,e);return l?Co(t,r,new B(s.$anchorCell,l)):!1}}function C0(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 M0(n,e,t){if(!He(n.state))return!1;let r=w0(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 o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),l=_.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=x0(r,l.right-l.left,l.bottom-l.top),Md(n.state,n.dispatch,s,l,r),!0}else if(r){let o=vl(n.state),s=o.start(-1);return Md(n.state,n.dispatch,s,_.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function A0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Ad(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof B)o(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)o(i,e),e.preventDefault();else if(!r)return;function o(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 s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),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(Ad(n,a.target)!=r&&(d=Tl(n,e),!d))return s();d&&o(d,a)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",l)}function Ud(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 o=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.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 Ad(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 E0=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,o){var s;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 D0(-1,!1)},apply(o,s){return s.apply(o)}},props:{attributes:o=>{let s=Ve.getState(o);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,s)=>{O0(o,s,n,e,r)},mouseleave:o=>{N0(o)},mousedown:(o,s)=>{I0(o,s,e)}},decorations:o=>{let s=Ve.getState(o);if(s&&s.activeHandle>-1)return B0(o,s.activeHandle)},nodeViews:{}}});return i}var D0=class Mo{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 Mo(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Mo(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 Mo(i,t.dragging)}return t}};function O0(n,e,t,r,i){let o=Ve.getState(n.state);if(o&&!o.dragging){let s=v0(e.target),l=-1;if(s){let{left:c,right:a}=s.getBoundingClientRect();e.clientX-c<=t?l=Ed(n,e,"left",t):a-e.clientX<=t&&(l=Ed(n,e,"right",t))}if(l!=o.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=_.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}Vd(n,l)}}}function N0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Vd(n,-1)}function I0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,o=Ve.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;let s=n.state.doc.nodeAt(o.activeHandle),l=R0(n,o.activeHandle,s.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&&(_0(n,d.activeHandle,Td(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=Td(d.dragging,h,t);U0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function R0(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let o=n.domAtPos(e),l=o.node.childNodes[o.offset].offsetWidth,c=t;if(r)for(let a=0;ajo,AbstractConnector:()=>dc,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:()=>uc,RelativePosition:()=>st,Skip:()=>ie,Snapshot:()=>jt,Text:()=>ct,Transaction:()=>Yo,UndoManager:()=>Tn,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>ot,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>at,XmlHook:()=>Si,XmlText:()=>xe,YArrayEvent:()=>Qo,YEvent:()=>Dn,YMapEvent:()=>Zo,YTextEvent:()=>es,YXmlEvent:()=>ts,applyUpdate:()=>Mc,applyUpdateV2:()=>vn,cleanupYTextFormatting:()=>Iu,compareIDs:()=>kn,compareRelativePositions:()=>rs,convertUpdateFormatV1ToV2:()=>f1,convertUpdateFormatV2ToV1:()=>pu,createAbsolutePositionFromRelativePosition:()=>Oc,createDeleteSet:()=>br,createDeleteSetFromStructStore:()=>Sc,createDocFromSnapshot:()=>Xw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>Ci,createSnapshot:()=>Mi,decodeRelativePosition:()=>Ww,decodeSnapshot:()=>Yw,decodeSnapshotV2:()=>tu,decodeStateVector:()=>Ec,decodeUpdate:()=>o1,decodeUpdateV2:()=>cu,diffUpdate:()=>a1,diffUpdateV2:()=>Nc,emptySnapshot:()=>Gw,encodeRelativePosition:()=>Jw,encodeSnapshot:()=>Kw,encodeSnapshotV2:()=>eu,encodeStateAsUpdate:()=>Ac,encodeStateAsUpdateV2:()=>Xf,encodeStateVector:()=>Dc,encodeStateVectorFromUpdate:()=>s1,encodeStateVectorFromUpdateV2:()=>hu,equalDeleteSets:()=>Yf,equalSnapshots:()=>jw,findIndexSS:()=>ze,findRootTypeKey:()=>_n,getItem:()=>Cn,getState:()=>P,getTypeChildren:()=>g1,isDeleted:()=>Tt,isParentOf:()=>En,iterateDeletedStructs:()=>rt,logType:()=>zw,logUpdate:()=>i1,logUpdateV2:()=>lu,mergeDeleteSets:()=>Mn,mergeUpdates:()=>au,mergeUpdatesV2:()=>yi,obfuscateUpdate:()=>h1,obfuscateUpdateV2:()=>d1,parseUpdateMeta:()=>l1,parseUpdateMetaV2:()=>du,readUpdate:()=>Vw,readUpdateV2:()=>Cc,relativePositionToJSON:()=>Fw,snapshot:()=>Ai,snapshotContainsUpdate:()=>Zw,transact:()=>R,tryGc:()=>n1,typeListToArraySnapshot:()=>cs,typeMapGetAllSnapshot:()=>Eu,typeMapGetSnapshot:()=>b1});var U=()=>new Map,Ao=n=>{let e=U();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},Bd=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Pd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var Eo=n=>n[n.length-1];var Ld=(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)||U()).values()).forEach(r=>r(...t))}destroy(){this._observers=U()}},tr=class{constructor(){this._observers=U()}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)||U()).values()).forEach(r=>r(...t))}destroy(){this._observers=U()}};var fe=Math.floor;var nr=Math.abs;var De=(n,e)=>nn>e?n:e,dS=Number.isNaN,qd=Math.pow;var Do=n=>n!==0?n<0:1/n<0;var Pl=Number.MAX_SAFE_INTEGER,fS=Number.MIN_SAFE_INTEGER,uS=1<<31;var Hd=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&fe(n)===n),pS=Number.isNaN,mS=Number.parseInt;var Ll=String.fromCharCode,gS=String.fromCodePoint,yS=Ll(65535),L0=n=>n.toLowerCase(),z0=/^\s*/g,F0=n=>n.replace(z0,""),q0=/([A-Z])/g,zl=(n,e)=>F0(n.replace(q0,t=>`${e}${L0(t)}`));var H0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;iir.encode(n),$d=ir?J0:H0;var rr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});rr&&rr.decode(new Uint8Array).length===1&&(rr=null);var Wd=(n,e)=>Fd(e,()=>n).join("");var wn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},F=()=>new wn;var No=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(No(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=Do(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)},Fl=new Uint8Array(3e4),W0=Fl.length/3,j0=(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),o=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,o>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Be(t*2,o)),n.cbuf.set(e.subarray(i)),n.cpos=o)},V=(n,e)=>{x(n,e.byteLength),ar(n,e)},ql=(n,e)=>{$0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},Y0=(n,e)=>ql(n,4).setFloat32(0,e,!1),G0=(n,e)=>ql(n,8).setFloat64(0,e,!1),X0=(n,e)=>ql(n,8).setBigInt64(0,e,!1);var Kd=new DataView(new ArrayBuffer(4)),Q0=n=>(Kd.setFloat32(0,n),Kd.getFloat32(0)===n),sr=(n,e)=>{switch(typeof e){case"string":Q(n,119),Qe(n,e);break;case"number":Hd(e)&&nr(e)<=2147483647?(Q(n,125),ni(n,e)):Q0(e)?(Q(n,124),Y0(n,e)):(Q(n,123),G0(n,e));break;case"bigint":Q(n,122),X0(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 Yd=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++:(Yd(this),this.count=1,this.s=e)}toUint8Array(){return Yd(this),I(this.encoder)}};var Gd=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++):(Gd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Gd(this),I(this.encoder)}},Oo=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 Qd=Ze("Unexpected end of array"),Zd=Ze("Integer out of Range"),hr=class{constructor(e){this.arr=e,this.pos=0}},q=n=>new hr(n),Hl=n=>n.pos!==n.arr.length;var Z0=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>Z0(n,k(n));var xn=n=>n.arr[n.pos++];var k=n=>{let e=0,t=1,r=n.arr.length;for(;n.posPl)throw Zd}throw Qd},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 o=n.arr.length;for(;n.posPl)throw Zd}throw Qd};var ew=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))}},tw=n=>rr.decode(K(n)),Le=rr?tw:ew;var Jl=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},nw=n=>Jl(n,4).getFloat32(0,!1),rw=n=>Jl(n,8).getFloat64(0,!1),iw=n=>Jl(n,8).getBigInt64(0,!1);var ow=[n=>{},n=>null,ii,nw,rw,iw,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;row[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),Hl(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=Do(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}},vo=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 xS=crypto.subtle,ef=crypto.getRandomValues.bind(crypto);var sw=Math.random,$l=()=>ef(new Uint32Array(1))[0];var tf=n=>n[fe(sw()*n.length)],lw="10000000-1000-4000-8000"+-1e11,nf=()=>lw.replace(/[018]/g,n=>(n^$l()&15>>n/4).toString(16));var Ne=Date.now;var Wl=n=>new Promise(n);var CS=Promise.all.bind(Promise);var jl=n=>n===void 0?null:n;var Kl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},of=new Kl,Yl=!0;try{typeof localStorage<"u"&&localStorage&&(of=localStorage,Yl=!1)}catch{}var Uo=of,sf=n=>Yl||addEventListener("storage",n),lf=n=>Yl||removeEventListener("storage",n);var hf=Object.assign,Vo=Object.keys,df=(n,e)=>{for(let t in n)e(n[t],t)},ff=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Gl=n=>Vo(n).length,af=n=>Vo(n).length;var uf=n=>{for(let e in n)return!1;return!0},hw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Xl=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Ql=(n,e)=>n===e||af(n)===af(e)&&hw(n,(t,r)=>(t!==void 0||Xl(e,r))&&e[r]===t),dw=Object.freeze,Zl=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&Zl(n[e])}return dw(n)};var si=(n,e,t=0)=>{try{for(;tn,fw=(n,e)=>n===e;var ur=(n,e)=>{if(n==null||e==null)return fw(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,MS=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,et,uw=[],pw=()=>{if(et===void 0)if(kt){et=U();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");et.set(`--${zl(e,"-")}`,t),et.set(`-${zl(e,"-")}`,t)}})):et=U();return et},nc=n=>pw().has(n);var li=n=>kt?jl(process.env[n.toUpperCase().replaceAll("-","_")]):jl(Uo.getItem(n));var mf=n=>nc("--"+n)||li(n)!==null,AS=mf("production"),mw=kt&&pf(process.env.FORCE_COLOR,["true","1","2"]),gf=mw||!nc("--no-colors")&&!mf("no-color")&&(!kt||process.stdout.isTTY)&&(!kt||nc("--color")||li("COLORTERM")!==null||(li("TERM")||"").includes("color"));var yf=n=>new Uint8Array(n),gw=(n,e,t)=>new Uint8Array(n,e,t),wf=n=>new Uint8Array(n),yw=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),bw=n=>{let e=atob(n),t=yf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return gw(e.buffer,e.byteOffset,e.byteLength)},bf=pr?yw:ww,xf=pr?bw:xw;var Sf=n=>{let e=yf(n.byteLength);return e.set(n),e};var rc=class{constructor(e,t){this.left=e,this.right=t}},tt=(n,e)=>new rc(n,e);var Ct=typeof document<"u"?document:{};var ES=typeof DOMParser<"u"?new DOMParser:null;var Cf=n=>Bd(n,(e,t)=>`${t}:${e};`).join("");var TS=Ct.ELEMENT_NODE,DS=Ct.TEXT_NODE,OS=Ct.CDATA_SECTION_NODE,NS=Ct.COMMENT_NODE,IS=Ct.DOCUMENT_NODE,RS=Ct.DOCUMENT_TYPE_NODE,vS=Ct.DOCUMENT_FRAGMENT_NODE;var Po=n=>class{constructor(t){this._=t}destroy(){n(this._)}},kw=Po(clearTimeout),ai=(n,e)=>new kw(setTimeout(e,n)),US=Po(clearInterval);var VS=Po(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var BS=Po(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var nt=Symbol;var hi=nt(),di=nt(),ic=nt(),oc=nt(),sc=nt(),fi=nt(),lc=nt(),mr=nt(),cc=nt(),Ef=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=U(),i=[],o=0;for(;o0||c.length>0?(e.push("%c"+s),t.push(c)):e.push(s)}else break}}for(o>0&&(i=t,i.unshift(e.join("")));o{console.log(...Tf(n)),Df.forEach(e=>e.print(n))},ac=(...n)=>{console.warn(...Tf(n)),n.unshift(mr),Df.forEach(e=>e.print(n))};var Df=Ce();var Of=n=>({[Symbol.iterator](){return this},next:n}),Nf=(n,e)=>Of(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),zo=(n,e)=>Of(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var dc=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 o=n.doc.store.clients.get(i);for(let s=0;s{let t=0,r=n.length-1;for(;t<=r;){let i=fe((t+r)/2),o=n[i],s=o.clock;if(s<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&Iw(t,e.clock)!==null},xc=n=>{n.clients.forEach(e=>{e.sort((i,o)=>i.clock-o.clock);let t,r;for(t=1,r=1;t=o.clock?i.len=Be(i.len,o.clock+o.len-i.clock):(r{let e=new $t;for(let t=0;t{if(!e.clients.has(i)){let o=r.slice();for(let s=t+1;s{$(n.clients,e,()=>[]).push(new pi(t,r))},br=()=>new $t,Sc=n=>{let e=br();return n.clients.forEach((t,r)=>{let i=[];for(let o=0;o0&&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 o=0;o{let e=new $t,t=k(n.restDecoder);for(let r=0;r0){let s=$(e.clients,i,()=>[]);for(let l=0;l{let r=new $t,i=k(n.restDecoder);for(let o=0;o0){let o=new Ie;return x(o.restEncoder,0),it(o,r),o.toUint8Array()}return null},Yf=(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 o=0;o!0,meta:o=null,autoLoad:s=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Gf(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ko,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=s,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Wl(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>Wl(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 o=new t;return o._integrate(this,null),o}),i=r.constructor;if(t!==W&&i!==t)if(i===W){let o=new t;o._map=r._map,r._map.forEach(s=>{for(;s!==null;s=s.left)s.parent=o}),o._start=r._start;for(let s=o._start;s!==null;s=s.right)s.parent=o;return o._length=r._length,this.share.set(e,o),o._integrate(this,null),o}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 Sf(K(this.restDecoder))}readJSON(){return JSON.parse(Le(this.restDecoder))}readKey(){return Le(this.restDecoder)}},Wo=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 Wo{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 vo(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 o=e[i];o.write(n,r-o.id.clock);for(let s=i+1;s{let r=new Map;t.forEach((i,o)=>{P(e,o)>i&&r.set(o,i)}),Ei(e).forEach((i,o)=>{t.has(o)||r.set(o,0)}),x(n.restEncoder,r.size),$e(r.entries()).sort((i,o)=>o[0]-i[0]).forEach(([i,o])=>{Rw(n,e.clients.get(i),i,o)})},vw=(n,e)=>{let t=U(),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 o=()=>{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},s=o();if(s===null)return null;let l=new Ko,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=s.refs[s.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(s!==null&&s.i0){let u=new Ie;return kc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},Uw=(n,e)=>kc(n,e.doc.store,e.beforeState),Cc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let o=!1,s=i.doc,l=s.store,c=vw(r,s),a=_w(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=vf(r,i,l);if(l.pendingDs){let f=new be(q(l.pendingDs));k(f.restDecoder);let u=vf(f,i,l);d&&u?l.pendingDs=yi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(o){let f=l.pendingStructs.update;l.pendingStructs=null,vn(i.doc,f)}},t,!1),Vw=(n,e,t)=>Cc(n,e,t,new Me(n)),vn=(n,e,t,r=be)=>{let i=q(e);Cc(i,n,t,new r(i))},Mc=(n,e,t)=>vn(n,e,t,Me),Bw=(n,e,t=new Map)=>{kc(n,e.store,t),it(n,Sc(e.store))},Xf=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Ec(e);Bw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Nc(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===ot)return au(i.map((o,s)=>s===0?o:pu(o)));if(t.constructor===Ie)return yi(i)}return i[0]},Ac=(n,e)=>Xf(n,e,new ot),Qf=n=>{let e=new Map,t=k(n.restDecoder);for(let r=0;rQf(new An(q(n))),Tc=(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),Pw=(n,e)=>Tc(n,Ei(e.store)),Lw=(n,e=new gr)=>(n instanceof Map?Tc(e,n):Pw(e,n),e.toUint8Array()),Dc=n=>Lw(n,new Wt),fc=class{constructor(){this.l=[]}},_f=()=>new fc,Uf=(n,e)=>n.l.push(e),Vf=(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.")},Zf=(n,e,t)=>si(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),Bf=(n,e)=>{x(n,e.client),x(n,e.clock)},Pf=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},zw=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))},uc=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=(o,s)=>{let l=o.get("ds"),c=o.get("ids"),a=h=>this.clients.set(h,s);l.observe(h=>{h.changes.added.forEach(d=>{d.content.getContent().forEach(f=>{f instanceof Uint8Array&&this.dss.set(s,Mn([this.dss.get(s)||br(),At(new An(q(f)))]))})})}),this.dss.set(s,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(o=>{o.keysChanged.forEach(s=>i(t.get(s),s))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let o=this.yusers,s=o.get(r);s||(s=new Nn,s.set("ids",new On),s.set("ds",new On),o.set(r,s)),s.get("ids").push([t]),o.observe(l=>{setTimeout(()=>{let c=o.get(r);if(c!==s){s=c,this.clients.forEach((d,f)=>{r===d&&s.get("ids").push([f])});let a=new Wt,h=this.dss.get(r);h&&(it(a,h),s.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=s.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}},st=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},Fw=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 st(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),jo=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},qw=(n,e,t=0)=>new jo(n,e,t),Fo=(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 st(r,i,e,t)},Ci=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return Fo(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Fo(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Fo(n,r.lastId,t);r=r.right}return Fo(n,null,t)},Hw=(n,e)=>{let{type:t,tname:r,item:i,assoc:o}=e;if(i!==null)x(n,0),Bf(n,i);else if(r!==null)cr(n,1),Qe(n,r);else if(t!==null)cr(n,2),Bf(n,t);else throw j();return ni(n,o),n},Jw=n=>{let e=F();return Hw(e,n),I(e)},$w=n=>{let e=null,t=null,r=null;switch(k(n)){case 0:r=Pf(n);break;case 1:t=Le(n);break;case 2:e=Pf(n)}let i=Hl(n)?ii(n):0;return new st(e,t,r,i)},Ww=n=>$w(q(n)),Oc=(n,e,t=!0)=>{let r=e.store,i=n.item,o=n.type,s=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(P(r,i.client)<=i.clock)return null;let h=t?wc(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(s!==null)c=e.get(s);else if(o!==null){if(P(r,o.client)<=o.clock)return null;let{item:h}=t?wc(r,o):{item:Cn(r,o)};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 qw(c,a,n.assoc)},rs=(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}},jw=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,o=e.sv;if(i.size!==o.size||t.size!==r.size)return!1;for(let[s,l]of i.entries())if(o.get(s)!==l)return!1;for(let[s,l]of t.entries()){let c=r.get(s)||[];if(l.length!==c.length)return!1;for(let a=0;a(it(e,n.ds),Tc(e,n.sv),e.toUint8Array()),Kw=n=>eu(n,new Wt),tu=(n,e=new Wo(q(n)))=>new jt(At(e),Qf(e)),Yw=n=>tu(n,new An(q(n))),Mi=(n,e)=>new jt(n,e),Gw=Mi(br(),new Map),Ai=n=>Mi(Sc(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),pc=(n,e)=>{let t=$(n.meta,pc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,o)=>{i{}),t.add(e))},Xw=(n,e,t=new We)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,o=new Ie;return n.transact(s=>{let l=0;r.forEach(c=>{c>0&&l++}),x(o.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 s=i.curr;s!==null;s=i.next())if((n.sv.get(s.id.client)||0)Qw(n,e,Me),Ko=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},nu=(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],o=i.id.clock;if(o===e)return r;let s=fe(e/(o+i.length-1)*r);for(;t<=r;){if(i=n[s],o=i.id.clock,o<=e){if(e{let t=n.clients.get(e.client);return t[ze(t,e.clock)]},Cn=e1,mc=(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[mc(n,t,e.clock)]},Lf=(n,e,t)=>{let r=e.clients.get(t.client),i=ze(r,t.clock),o=r[i];return t.clock!==o.id.clock+o.length-1&&o.constructor!==ue&&r.splice(i+1,0,ns(n,o,t.clock-o.id.clock+1)),o},t1=(n,e,t)=>{let r=n.clients.get(e.id.client);r[ze(r,e.id.clock)]=t},ru=(n,e,t,r,i)=>{if(r===0)return;let o=t+r,s=mc(n,e,t),l;do l=e[s++],oe.deleteSet.clients.size===0&&!Pd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(xc(e.deleteSet),Uw(n,e),it(n,e.deleteSet),!0),Ff=(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)},Jo=(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 o=e-i;return o&&n.splice(e+1-o,o),o},iu=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let o=e.clients.get(r);for(let s=i.length-1;s>=0;s--){let l=i[s],c=l.clock+l.len;for(let a=ze(o,l.clock),h=o[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let o=t.length-1;o>=0;o--){let s=t[o],l=De(i.length-1,1+ze(i,s.clock+s.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=s.clock;a=i[c])c-=1+Jo(i,c)}})},n1=(n,e,t)=>{iu(n,e,t),ou(n,e)},su=(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),Zf(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),si(l,[]),t._needFormattingCleanup&&C1(t)}finally{r.gc&&iu(o,i,r.gcFilter),ou(o,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+Jo(u,m)}});for(let h=s.length-1;h>=0;h--){let{client:d,clock:f}=s[h].id,u=i.clients.get(d),p=ze(u,f);p+11||p>0&&Jo(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(Lo(mr,hi,"[yjs] ",di,fi,"Changed the client-id because another client seems to be using it."),r.clientID=Gf()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new ot;zf(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;zf(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])):su(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,o=!1,s=null;n._transaction===null&&(o=!0,n._transaction=new Yo(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{s=e(n._transaction)}finally{if(o){let l=n._transaction===i[0];n._transaction=null,l&&su(i,0)}}return s},gc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},qf=(n,e,t)=>{rt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>En(i,r))&&Uc(r,!1)})},Hf=(n,e,t)=>{let r=null,i=n.doc,o=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}=wc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&o.some(p=>En(p,u))&&d.push(u)}}),rt(l,a.deletions,u=>{u instanceof O&&o.some(p=>En(p,u))&&!Tt(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=vu(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 s=n.currStackItem;if(s!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:s,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return s},Tn=class extends er{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:s=!1,doc:l=Zr(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,o.add(this),this.trackedOrigins=o,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=s,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 gc(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))&&Uc(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&&ac("[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=>qf(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>qf(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=Hf(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Hf(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*r1(n){let e=k(n.restDecoder);for(let t=0;tlu(n,Me),lu=(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);Lo("Structs: ",t);let o=At(r);Lo("DeleteSet: ",o)},o1=n=>cu(n,Me),cu=(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);return{structs:t,ds:At(r)}},gi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},au=n=>yi(n,Me,ot),hu=(n,e=gr,t=be)=>{let r=new e,i=new lt(new t(q(n)),!1),o=i.curr;if(o!==null){let s=0,l=o.id.client,c=o.id.clock!==0,a=c?0:o.id.clock+o.length;for(;o!==null;o=i.next())l!==o.id.client&&(a!==0&&(s++,x(r.restEncoder,l),x(r.restEncoder,a)),l=o.id.client,a=0,c=o.id.clock!==0),o.constructor===ie&&(c=!0),c||(a=o.id.clock+o.length);a!==0&&(s++,x(r.restEncoder,l),x(r.restEncoder,a));let h=F();return x(h,s),Xd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},s1=n=>hu(n,Wt,Me),du=(n,e=be)=>{let t=new Map,r=new Map,i=new lt(new e(q(n)),!1),o=i.curr;if(o!==null){let s=o.id.client,l=o.id.clock;for(t.set(s,l);o!==null;o=i.next())s!==o.id.client&&(r.set(s,l),t.set(o.id.client,o.id.clock),s=o.id.client),l=o.id.clock+o.length;r.set(s,l)}return{from:t,to:r}},l1=n=>du(n,Me),c1=(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)),o=null,s=new t,l=new gi(s);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(o!==null){let f=h.curr,u=!1;for(;f!==null&&f.id.clock+f.length<=o.struct.id.clock+o.struct.length&&f.id.client>=o.struct.id.client;)f=h.next(),u=!0;if(f===null||f.id.client!==d||u&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(d!==o.struct.id.client)Ht(l,o.struct,o.offset),o={struct:f,offset:0},h.next();else if(o.struct.id.clock+o.struct.length0&&(o.struct.constructor===ie?o.struct.length-=p:f=c1(f,p)),o.struct.mergeWith(f)||(Ht(l,o.struct,o.offset),o={struct:f,offset:0},h.next())}}else o={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==ie;f=h.next())Ht(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(Ht(l,o.struct,o.offset),o=null),Ic(l);let c=r.map(h=>At(h)),a=Mn(c);return it(s,a),s.toUint8Array()},Nc=(n,e,t=be,r=Ie)=>{let i=Ec(e),o=new r,s=new gi(o),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(s,h,Be(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Ht(s,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=f;)c.next()}Ic(s);let a=At(l);return it(o,a),o.toUint8Array()},a1=(n,e)=>Nc(n,e,Me,ot),fu=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&&fu(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++},Ic=n=>{fu(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(q(n)),o=new lt(i,!1),s=new r,l=new gi(s);for(let a=o.curr;a!==null;a=o.next())Ht(l,e(a),0);Ic(l);let c=At(i);return it(s,c),s.toUint8Array()},uu=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=U(),o=U(),s=U(),l=U();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=$(o,d.nodeName,()=>"node-"+r)),d instanceof Si&&(d.hookName=$(o,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=$(s,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=Wd(r%10+"",d.str.length);break}default:j()}return a.parentSub&&(a.parentSub=$(i,a.parentSub,()=>r+"")),r++,c}default:j()}}},h1=(n,e)=>is(n,uu(e),Me,ot),d1=(n,e)=>is(n,uu(e),be,Ie),f1=n=>is(n,ec,Me,Ie),pu=n=>is(n,ec,be,ot),Jf="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=u1(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(Jf);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let o=t._map.get(i),s,l;if(this.adds(o)){let c=o.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(o))if(c!==null&&this.deletes(c))s="delete",l=Eo(c.content.getContent());else return;else c!==null&&this.deletes(c)?(s="update",l=Eo(c.content.getContent())):(s="add",l=void 0)}else if(this.deletes(o))s="delete",l=Eo(o.content.getContent());else return;e.set(i,{action:s,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(Jf);let t=this.target,r=Ce(),i=Ce(),o=[];if(e={added:r,deleted:i,delta:o,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&o.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}},u1=(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},oe=()=>{ac("Invalid access: Add Yjs type to a document before reading data.")},mu=80,Rc=0,yc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Rc++}},p1=n=>{n.timestamp=Rc++},gu=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Rc++},m1=(n,e,t)=>{if(n.length>=mu){let r=n.reduce((i,o)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((o,s)=>nr(e-o.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 o=i.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(i.index-=o.length);if(o===null||o.marker===!0){n.splice(r,1);continue}i.p=o,o.marker=!0}(e0&&e===i.index)&&(i.index=Be(e,i.index+t))}},g1=n=>{n.doc??oe();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},ls=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Zf(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=_f(),this._dEH=_f(),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){Uf(this._eH,e)}observeDeep(e){Uf(this._dEH,e)}unobserve(e){Vf(this._eH,e)}unobserveDeep(e){Vf(this._dEH,e)}toJSON(){}},yu=(n,e,t)=>{n.doc??oe(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],o=n._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){let s=o.content.getContent();if(s.length<=e)e-=s.length;else{for(let l=e;l0;l++)i.push(s[l]),r--;e=0}}o=o.right}return i},wu=n=>{n.doc??oe();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 o=0;o{let t=0,r=n._start;for(n.doc??oe();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let o=0;o{let t=[];return bi(n,(r,i)=>{t.push(e(r,i,n))}),t},y1=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}}}},xu=(n,e)=>{n.doc??oe();let t=ss(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,o=n.doc,s=o.clientID,l=o.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(s,P(l,s)),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(s,P(l,s)),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(s,P(l,s)),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(s,P(l,s)),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()},Su=()=>Ze("Length exceeded!"),ku=(n,e,t,r)=>{if(t>e._length)throw Su();if(t===0)return e._searchMarker&&wi(e._searchMarker,t,r.length),Go(n,e,null,r);let i=t,o=ss(e,t),s=e._start;for(o!==null&&(s=o.p,t-=o.index,t===0&&(s=s.prev,t+=s&&s.countable&&!s.deleted?s.length:0));s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<=s.length){t{let i=(e._searchMarker||[]).reduce((o,s)=>s.index>o.index?s:o,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Go(n,e,i,t)},Cu=(n,e,t,r)=>{if(r===0)return;let i=t,o=r,s=ss(e,t),l=e._start;for(s!==null&&(l=s.p,t-=s.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw Su();e._searchMarker&&wi(e._searchMarker,i,-o+r)},Xo=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},vc=(n,e,t,r)=>{let i=e._map.get(t)||null,o=n.doc,s=o.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(s,P(o.store,s)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},_c=(n,e)=>{n.doc??oe();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Mu=n=>{let e={};return n.doc??oe(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Au=(n,e)=>{n.doc??oe();let t=n._map.get(e);return t!==void 0&&!t.deleted},b1=(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},Eu=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let o=r;for(;o!==null&&(!e.sv.has(o.id.client)||o.id.clock>=(e.sv.get(o.id.client)||0));)o=o.left;o!==null&&qt(o,e)&&(t[i]=o.content.getContent()[o.length-1])}),t},qo=n=>(n.doc??oe(),Nf(n._map.entries(),e=>!e[1].deleted)),Qo=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??oe(),this._length}_callObserver(e,t){super._callObserver(e,t),ls(this,e,new Qo(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{ku(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{w1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Cu(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return xu(this,e)}toArray(){return wu(this)}slice(e=0,t=this.length){return yu(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return bu(this,e)}forEach(e){bi(this,e)}[Symbol.iterator](){return y1(this)}_write(e){e.writeTypeRef(z1)}},x1=n=>new On,Zo=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){ls(this,e,new Zo(this,e,t))}toJSON(){this.doc??oe();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[...qo(this)].length}keys(){return zo(qo(this),e=>e[0])}values(){return zo(qo(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return zo(qo(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??oe(),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=>{Xo(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return _c(this,e)}has(e){return Au(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){Xo(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(F1)}},S1=n=>new Nn,Jt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Ql(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}},$f=(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,o=r?ss(e,t):null;if(o){let s=new xi(o.p.left,o.p,o.index,i);return $f(n,s,t-o.index)}else{let s=new xi(null,e._start,0,i);return $f(n,s,t)}},Tu=(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,o=i.clientID;r.forEach((s,l)=>{let c=t.left,a=t.right,h=new O(M(o,P(i.store,o)),c,c&&c.lastId,a,a&&a.id,e,null,new L(l,s));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)},Du=(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()}},Ou=(n,e,t,r)=>{let i=n.doc,o=i.clientID,s=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Jt(a,c)){s.set(l,a);let{left:h,right:d}=t;t.right=new O(M(o,P(i.store,o)),h,h&&h.lastId,d,d&&d.id,e,null,new L(l,c)),t.right.integrate(n,0),t.forward()}}return s},hc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let o=n.doc,s=o.clientID;Du(t,i);let l=Ou(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(s,P(o.store,s)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=d,t.forward(),Tu(n,e,t,l)},Wf=(n,e,t,r,i)=>{let o=n.doc,s=o.clientID;Du(t,i);let l=Ou(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(s,P(o.store,s)),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()}Tu(n,e,t,l)},Nu=(n,e,t,r,i)=>{let o=e,s=U();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===L){let a=o.content;s.set(a.key,a)}o=o.right}let l=0,c=!1;for(;e!==o;){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;(s.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},k1=(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}},Iu=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,o=U(),s=Ao(o);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case L:xr(s,i.content);break;default:e+=Nu(t,r,i,o,s),o=Ao(s),r=i;break}i=i.right}}),e},C1=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let o=n.beforeState.get(r)||0;i!==o&&ru(n,t.store.clients.get(r),o,i,s=>{!s.deleted&&s.content.constructor===L&&s.constructor!==ue&&e.add(s.parent)})}R(t,r=>{rt(n,n.deleteSet,i=>{if(i instanceof ue||!i.parent._hasFormatting||e.has(i.parent))return;let o=i.parent;i.content.constructor===L?e.add(o):k1(r,i)});for(let i of e)Iu(i)})},jf=(n,e,t)=>{let r=t,i=Ao(e.currentAttributes),o=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,o=new Map,s=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},uf(c)||(u.attributes=hf({},c))),h=0;break}u&&t.push(u),l=null}};for(;s!==null;){switch(s.content.constructor){case Ae:case Et:this.adds(s)?this.deletes(s)||(f(),l="insert",a=s.content.getContent()[0],f()):this.deletes(s)?(l!=="delete"&&(f(),l="delete"),d+=1):s.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case Re:this.adds(s)?this.deletes(s)||(l!=="insert"&&(f(),l="insert"),a+=s.content.str):this.deletes(s)?(l!=="delete"&&(f(),l="delete"),d+=s.length):s.deleted||(l!=="retain"&&(f(),l="retain"),h+=s.length);break;case L:{let{key:u,value:p}=s.content;if(this.adds(s)){if(!this.deletes(s)){let m=i.get(u)??null;Jt(m,p)?p!==null&&s.delete(r):(l==="retain"&&f(),Jt(p,o.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(s)){o.set(u,p);let m=i.get(u)??null;Jt(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!s.deleted){o.set(u,p);let m=c[u];m!==void 0&&(Jt(m,p)?m!==null&&s.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}s.deleted||(l==="insert"&&f(),xr(i,s.content));break}}s=s.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??oe(),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 es(this,e,t);ls(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??oe();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 o=0;o0)&&hc(r,this,i,l,s.attributes||{})}else s.retain!==void 0?Wf(r,this,i,s.retain,s.attributes||{}):s.delete!==void 0&&jf(r,i,s.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??oe();let i=[],o=new Map,s=this.doc,l="",c=this._start;function a(){if(l.length>0){let d={},f=!1;o.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=o.get("ychange");e!==void 0&&!qt(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),o.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(),o.set("ychange",r?r("added",c.id):{type:"added"})):d!==void 0&&(a(),o.delete("ychange")),l+=c.content.str;break}case Ae:case Et:{a();let d={insert:c.content.getContent()[0]};if(o.size>0){let f={};d.attributes=f,o.forEach((u,p)=>{f[p]=u})}i.push(d);break}case L:qt(c,e)&&(a(),xr(o,c.content));break}c=c.right}a()};return e||t?R(s,d=>{e&&pc(d,e),t&&pc(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,o=>{let s=Ho(o,this,e,!r);r||(r={},s.currentAttributes.forEach((l,c)=>{r[c]=l})),hc(o,this,s,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,o=>{let s=Ho(o,this,e,!r);hc(o,this,s,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=>{jf(i,Ho(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,o=>{let s=Ho(o,this,e,!1);s.right!==null&&Wf(o,this,s,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xo(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return _c(this,e)}getAttributes(){return Mu(this)}_write(e){e.writeTypeRef(q1)}},M1=n=>new ct,ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??oe()}[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??oe(),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){ls(this,e,new ts(this,t,e))}toString(){return bu(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,o=>{i.insertBefore(o.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{ku(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;Go(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(o=>o===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=>{Cu(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return wu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return xu(this,e)}slice(e=0,t=this.length){return yu(this,e,t)}forEach(e){bi(this,e)}_write(e){e.writeTypeRef(J1)}},A1=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 df(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`<${o}${s}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xo(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return _c(this,e)}hasAttribute(e){return Au(this,e)}getAttributes(e){return e?Eu(this,e):Mu(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),o=this.getAttributes();for(let s in o){let l=o[s];typeof l=="string"&&i.setAttribute(s,l)}return bi(this,s=>{i.appendChild(s.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(H1),e.writeKey(this.nodeName)}},E1=n=>new Z(n.readKey()),ts=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],o;return i!==void 0?o=i.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(e){e.writeTypeRef($1),e.writeKey(this.hookName)}},T1=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 o=[];for(let s in e.attributes[i])o.push({key:s,value:e.attributes[i][s]});o.sort((s,l)=>s.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(W1)}},D1=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()}},O1=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),nu(e.doc.store,this)}write(e,t){e.writeInfo(O1),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}},N1=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}},I1=n=>new wr(n.readLen()),Ru=(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(Ru(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}},R1=n=>new Rn(Ru(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}},v1=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}},_1=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}},P1=n=>new Re(n.readString()),L1=[x1,S1,M1,E1,A1,T1,D1],z1=0,F1=1,q1=2,H1=3,J1=4,$1=5,W1=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}},j1=n=>new Ae(L1[n.readTypeRef()](n)),wc=(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}},Uc=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},ns=(n,e,t)=>{let{client:r,clock:i}=e.id,o=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&&o.markDeleted(),e.keep&&(o.keep=!0),e.redone!==null&&(o.redone=M(e.redone.client,e.redone.clock+t)),e.right=o,o.right!==null&&(o.right.left=o),n._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),e.length=t,o},Kf=(n,e)=>zd(n,t=>Tt(t.deletions,e)),vu=(n,e,t,r,i,o)=>{let s=n.doc,l=s.store,c=s.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)||vu(n,h,t,r,i,o)===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)||Kf(o.undoStack,d.right.id)||Kf(o.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,Uc(g,!0),g.integrate(n,0),g},O=class n extends yr{constructor(e,t,r,i,o,s,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=o,this.parent=s,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=Lf(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=Lf(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 o=new Set,s=new Set;for(;i!==null&&i!==this.right;){if(s.add(i),o.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),Ff(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?t1(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,o=this.parentSub,s=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(o===null?0:32);if(e.writeInfo(s),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();o!==null&&e.writeString(o)}this.content.write(e,t)}},_u=(n,e)=>K1[e&31](n),K1=[()=>{j()},I1,U1,N1,P1,v1,_1,j1,B1,R1,()=>{j()}],Y1=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(Y1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Uu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Vu="__ $YJS$ __";Uu[Vu]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Uu[Vu]=!0;var Bu=new Map,Vc=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:xf(t.newValue||"")}),sf(this._onChange)}postMessage(e){Uo.setItem(this.room,bf(wf(e)))}close(){lf(this._onChange)}},G1=typeof BroadcastChannel>"u"?Vc:BroadcastChannel,Bc=n=>$(Bu,n,()=>{let e=Ce(),t=new G1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Pu=(n,e)=>(Bc(n).subs.add(e),e),Lu=(n,e)=>{let t=Bc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Bu.delete(n)),r},Vn=(n,e,t=null)=>{let r=Bc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var zu=0,as=1,Fu=2,hs=(n,e)=>{x(n,zu);let t=Dc(e);V(n,t)},Pc=(n,e,t)=>{x(n,as),V(n,Ac(e,t))},Q1=(n,e,t)=>Pc(e,t,K(n)),qu=(n,e,t)=>{try{Mc(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},Hu=(n,e)=>{x(n,Fu),V(n,e)},Z1=qu,Ju=(n,e,t,r)=>{let i=k(n);switch(i){case zu:Q1(n,e,t);break;case as:qu(n,t,r);break;case Fu:Z1(n,t,r);break;default:throw new Error("Unknown message type")}return i};var tb=0;var $u=(n,e,t)=>{switch(k(n)){case tb:t(e,Le(n))}};var Lc=3e4,ds=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&&Lc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,o)=>{o!==this.clientID&&Lc<=t-i.lastUpdated&&this.states.has(o)&&r.push(o)}),r.length>0&&fs(this,r,"timeout")},fe(Lc/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,o=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Ne()});let s=[],l=[],c=[],a=[];e===null?a.push(t):o==null?e!=null&&s.push(t):(l.push(t),ur(o,e)||c.push(t)),(s.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:s,updated:c,removed:a},"local"]),this.emit("update",[{added:s,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},fs=(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 o=0;o{let r=q(e),i=Ne(),o=[],s=[],l=[],c=[],a=k(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:o,updated:l,removed:c},t]),(o.length>0||s.length>0||c.length>0)&&n.emit("update",[{added:o,updated:s,removed:c},t])};var ju=n=>ff(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,Yu=3,Cr=1,ob=2,Ti=[];Ti[Bn]=(n,e,t,r,i)=>{x(n,Bn);let o=Ju(e,n,t.doc,t);r&&o===as&&!t.synced&&(t.synced=!0)};Ti[Yu]=(n,e,t,r,i)=>{x(n,Cr),V(n,kr(t.awareness,Array.from(t.awareness.getStates().keys())))};Ti[Cr]=(n,e,t,r,i)=>{Wu(t.awareness,K(e),t)};Ti[ob]=(n,e,t,r,i)=>{$u(e,t.doc,(o,s)=>sb(t,s))};var Ku=3e4,sb=(n,e)=>console.warn(`Permission denied to access ${n.url}. -${e}`),Gu=(n,e,t)=>{let r=q(e),i=F(),o=k(r),s=n.messageHandlers[o];return s?s(i,r,n,t,o):console.error("Unable to compute message"),i},Xu=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=Gu(n,new Uint8Array(t.data),!0);No(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,fs(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Xu,De(qd(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),hs(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=F();x(r,Cr),V(r,kr(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},zc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},Fc=class extends tr{constructor(e,t,r,{connect:i=!0,awareness:o=new ds(r),params:s={},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=s,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=o,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),hs(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=Gu(this,new Uint8Array(f),!1);No(p)>1&&Vn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=F();x(p,Bn),Hu(p,f),zc(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),V(y,kr(o,g)),zc(this,I(y))},this._exitHandler=()=>{fs(this.awareness,[r.clientID],"app closed")},kt&&typeof process<"u"&&process.on("exit",this._exitHandler),o.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Ku{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var lb=/[\uD800-\uDBFF]/,cb=/[\uDC00-\uDFFF]/,ab=(n,e)=>{let t=0,r=0;for(;t0&&lb.test(n[t-1])&&t--;r+t0&&cb.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Zu=ab;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),hb=[{light:"#ecd44433",dark:"#ecd444"}],db=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,tf(e))}return n.get(t)},np=(n,{colors:e=hb,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:o}={})=>{let s=!1,l=new us(n,o),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),o==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(s||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(s=!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},fb=(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)}),us=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Qu(),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(),o=Ct.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||o.clientWidth||0)&&i.top<=(window.innerHeight||o.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(o=>{let s=r.permanentUserData;s&&s.dss.forEach(h=>{rt(o,h,d=>{})});let l=(h,d)=>{let f=h==="added"?s.getUserByClientId(d.client):s.getUserByDeletedId(d);return{user:f,type:h,color:db(r.colorMapping,r.colors,f)}},c=cs(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 o=this.type.toArray().map(l=>rp(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),s=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(o),0,0));fb(s,this.beforeTransactionSelection,this),s=s.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Tn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&s.scrollIntoView(),this.prosemirrorView.dispatch(s)})}_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))}},rp=(n,e,t,r,i,o)=>{let s=t.get(n);if(s===void 0){if(n instanceof Z)return Oi(n,e,t,r,i,o);throw Oe()}return s},Oi=(n,e,t,r,i,o)=>{let s=[],l=c=>{if(c.constructor===Z){let a=rp(c,e,t,r,i,o);a!==null&&s.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=ub(c,e,t,r,i,o);h!==null&&h.forEach(d=>{d!==null&&s.push(d)})}};r===void 0||i===void 0?n.toArray().forEach(l):cs(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=o?o("added",n._item.id):{type:"added"}):c.ychange=o?o("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,s);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},ub=(n,e,t,r,i,o)=>{let s=[],l=n.toDelta(r,i,o);try{for(let c=0;c{n._item.delete(a)},v),null}return s},pb=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:op(i.marks)}));return t.applyDelta(r),e.set(t,n),t},mb=(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,ms(n).map(r=>qc(r,e))),e.set(t,n),t},qc=(n,e)=>n instanceof Array?pb(n,e):mb(n,e),ep=n=>typeof n=="object"&&n!==null,Jc=(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&&Vo(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(o=>Jc(r.attributes[o.type.name]||{},o.attrs)))},Ri=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Hc(n,e)){let t=ms(e);return n._length===t.length&&Jc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Ri(r,t[i]))}return n instanceof xe&&e instanceof Array&&ip(n,e)},ps=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),tp=(n,e,t)=>{let r=n.toArray(),i=ms(e),o=i.length,s=r.length,l=De(s,o),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}},yb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=gb(n),o=e.map(a=>({insert:a.text,attributes:Object.assign({},r,op(a.marks))})),{insert:s,remove:l,index:c}=Zu(i,o.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,s),n.applyDelta(o.map(a=>({retain:a.insert.length,attributes:a.attributes})))},op=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=ms(t),o=i.length,s=e.toArray(),l=s.length,c=De(o,l),a=0,h=0;for(;a{for(;l-a-h>0&&o-a-h>0;){let f=s[a],u=i[a],p=s[l-h-1],m=i[o-h-1];if(f instanceof xe&&u instanceof Array)ip(f,u)||yb(f,u,r),a+=1;else{let g=f instanceof Z&&Hc(f,u),y=p instanceof Z&&Hc(p,m);if(g&&y){let E=tp(f,u,r),N=tp(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,wb=()=>{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((o,s)=>{r.setMeta(s,o)}),t.dispatch(r))})},$c=(n,e,t)=>{vi||(vi=new Map,ai(0,wb)),$(vi,n,U).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 st(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 st(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 bb(r._item.parent,r._item)}return Ci(e,e._length,-1)},bb=(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 st(t,r,e.id)},Yt=(n,e,t,r)=>{let i=Oc(t,n);if(i===null||i.type!==e&&!En(e,i.type._item))return null;let o=i.type,s=0;if(o.constructor===xe)s=i.index;else if(o._item===null||!o._item.deleted){let l=o._first,c=0;for(;ci(void 0)};return Mr(r,t,n,new Map),t}function lp(n,e="prosemirror"){return jc(n.getXmlFragment(e))}function jc(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(s=>{let l={type:"text",text:s.insert};return s.attributes&&(l.marks=Object.keys(s.attributes).map(c=>{let a=s.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let o=r.getAttributes();Object.keys(o).length&&(i.attrs=o);let s=r.toArray();s.length&&(i.content=s.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var xb=(n,e,t)=>n!==e,Sb=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},kb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Cb=/^#[0-9a-fA-F]{6}$/,cp=(n,e,t,r,i)=>{let o=v.getState(n),s=o.doc,l=[];return o.snapshot!=null||o.prevSnapshot!=null||o.binding.mapping.size===0?z.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(s.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Cb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Yt(s,o.type,Un(c.cursor.anchor),o.binding.mapping),f=Yt(s,o.type,Un(c.cursor.head),o.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))},Mb=(n,{awarenessStateFilter:e=xb,cursorBuilder:t=Sb,selectionBuilder:r=kb,getSelection:i=s=>s.selection}={},o="cursor")=>new H({key:Di,state:{init(s,l){return cp(l,n,e,t,r)},apply(s,l,c,a){let h=v.getState(a),d=s.getMeta(Di);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?cp(a,n,e,t,r):l.map(s.mapping,s.doc)}},props:{decorations:s=>Di.getState(s)},view:s=>{let l=()=>{s.docView&&$c(s,Di,{awarenessUpdated:!0})},c=()=>{let a=v.getState(s.state),h=n.getLocalState()||{};if(s.hasFocus()){let d=i(s.state),f=Pn(d.anchor,a.type,a.binding.mapping),u=Pn(d.head,a.type,a.binding.mapping);(h.cursor==null||!rs(Un(h.cursor.anchor),f)||!rs(Un(h.cursor.head),u))&&n.setLocalStateField(o,{anchor:f,head:u})}else h.cursor!=null&&Yt(a.doc,a.type,Un(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(o,null)};return n.on("change",l),s.dom.addEventListener("focusin",c),s.dom.addEventListener("focusout",c),{update:c,destroy:()=>{s.dom.removeEventListener("focusin",c),s.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(o,null)}}}});var Ab=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.undo(),!0},Eb=n=>{let e=Dt.getState(n).undoManager;if(e!=null)return e.redo(),!0},Tb=new Set(["paragraph"]),Db=(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,Ob=({protectedNodes:n=Tb,trackedOrigins:e=[],undoManager:t=null}={})=>new H({key:Dt,state:{init:(r,i)=>{let o=v.getState(i),s=t||new Tn(o.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Db(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:s,prevSel:null,hasUndoOps:s.undoStack.length>0,hasRedoOps:s.redoStack.length>0}},apply:(r,i,o,s)=>{let l=v.getState(s).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ii(l,o),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),o=Dt.getState(r.state).undoManager;return o.on("stack-item-added",({stackItem:s})=>{let l=i.binding;l&&s.meta.set(l,Dt.getState(r.state).prevSel)}),o.on("stack-item-popped",({stackItem:s})=>{let l=i.binding;l&&(l.beforeTransactionSelection=s.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{o.destroy()}}}});var _i="http://www.w3.org/2000/svg",Nb="http://www.w3.org/1999/xlink",Yc="ProseMirror-icon",Kc="pm-close-dropdowns";function Ib(n){let e=0;for(let t=0;t{o.preventDefault(),r.classList.contains(je+"-disabled")||t.run(e.state,e.dispatch,e,o)});function i(o){if(t.select){let l=t.select(o);if(r.style.display=l?"":"none",!l)return!1}let s=!0;if(t.enable&&(s=t.enable(o)||!1,ap(r,je+"-disabled",!s)),t.active){let l=s&&t.active(o)||!1;ap(r,je+"-active",l)}return!0}return{dom:r,update:i}}};function gs(n,e){return n._props.translate?n._props.translate(e):e}var Ui={time:0,node:null};function _b(n){Ui.time=Date.now(),Ui.node=n.target}function Ub(n){return Date.now()-100{s&&s.close()&&(s=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(Kc,c))};i.addEventListener("mousedown",d=>{d.preventDefault(),_b(d),s?a():(r.dispatchEvent(new CustomEvent(Kc)),s=this.expand(o,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{Ub(o)||a()}),r.addEventListener(Kc,c=()=>{a()}))});function h(d){let f=t.update(d);return o.style.display=f?"":"none",f}return{dom:o,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 o=wt("div",{class:je+"-dropdown-menu "+(this.options.class||"")},r,i),s=!1;function l(){return s?!1:(s=!0,e.removeChild(o),!0)}return e.appendChild(o),{close:l,node:o}}};function Vb(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iWr(n),icon:Vi.join}),Pk=new ht({title:"Lift out of enclosing block",run:jr,select:n=>jr(n),icon:Vi.lift}),Lk=new ht({title:"Select parent node",run:Kr,select:n=>Kr(n),icon:Vi.selectParentNode}),zk=new ht({title:"Undo last change",run:Xr,enable:n=>Xr(n),icon:Vi.undo}),Fk=new ht({title:"Redo last undone change",run:Qn,enable:n=>Qn(n),icon:Vi.redo});function Lb(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 zb(n,e){let t=pn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:o,to:s,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):s<=o.end()&&o.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new ht(r)}function ap(n,e,t){t?n.classList.add(e):n.classList.remove(e)}function dp(n,e,t){let r=t.child(0),o=_.get(t).width;if(r.childCount===1&&r.child(0).attrs.colspan===o)return n;if(r.childCount>1){let s=[],l=null;r.forEach((m,g,y)=>{y===0&&(l=e+1),m.textContent&&s.push(m.textContent)});let c=s[0]||"columns",a=r.child(0).type,h=n.doc.type.schema.nodes.paragraph.create(null,n.doc.type.schema.text(c)),d=a.create({colspan:o,rowspan:1},h),u=n.doc.type.schema.nodes.table_row.create(null,d),p=l+r.nodeSize-1;n.replaceWith(l,p,u)}else if(r.childCount===1){let s=e+1,l=r.child(0);n.setNodeMarkup(s,null,{...l.attrs,colspan:o,rowspan:1})}return n}function fp(n){for(let e=n.depth;e>0;e-=1){let t=n.node(e);if(t.type.name==="table"){let r=n.start(e)-1;return{table:t,tableStart:r,depth:e}}}return null}function rC(n,e){if(!e)return Ul(n,e);let t=n.selection.$from.pos;return Ul(n,i=>{try{let o=i.doc.resolve(t),s=fp(o);if(s){let l=i.doc.nodeAt(s.tableStart);l&&dp(i,s.tableStart,l)}}catch(o){console.warn("Could not fix header row colspan:",o)}e(i)})}function iC(n,e){if(!e)return Vl(n,e);let t=n.selection.$from.pos;return Vl(n,i=>{try{let o=i.doc.resolve(t),s=fp(o);if(s){let l=i.doc.nodeAt(s.tableStart);l&&dp(i,s.tableStart,l)}}catch(o){console.warn("Could not fix header row colspan:",o)}e(i)})}export{zn as DOMParser,It as DOMSerializer,Gc as Dropdown,Bs as EditorState,sl 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,Fc as WebsocketProvider,Sr as Y,iC as addColumnAfter,rC as addColumnBefore,uy as addListNodes,l0 as addRowAfter,s0 as addRowBefore,ad as baseKeymap,qg as baseSchema,zb as blockTypeItem,zy as buildKeymap,T0 as columnResizing,i0 as deleteColumn,a0 as deleteRow,y0 as deleteTable,Rd as fixTables,Iy as gapCursor,g0 as goToNextCell,md as inputRules,He as isInTable,ky as keymap,bl as liftListItem,d0 as mergeCells,sp as prosemirrorToYDoc,Wc as prosemirrorToYXmlFragment,Bb as renderGrouped,Je as selectedRect,pn as setBlockType,xl as sinkListItem,f0 as splitCell,wl as splitListItem,P0 as tableEditing,$y as tableNodes,mn as toggleMark,Xn as wrapIn,uo as wrapInList,Lb as wrapItem,Mb as yCursorPlugin,lp as yDocToProsemirrorJSON,Eb as yRedo,np as ySyncPlugin,Ab as yUndo,Ob as yUndoPlugin,Dt as yUndoPluginKey,jc as yXmlFragmentToProsemirrorJSON}; +`);return{dom:c,text:f,slice:e}}function Lh(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let c=e&&(r||o||!t);if(c){if(n.someProp("transformPastedText",f=>{e=f(e,o||r,n)}),o)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);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),s=Km(t),$r&&Ym(s);let a=s&&s.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=s.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;s=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!$m.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Gm(hh(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Wm(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 $m=/^(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 Wm(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)),o,s=[];if(n.forEach(l=>{if(!s)return;let c=i.findWrapping(l.type),a;if(!c)return s=null;if(a=s.length&&o.length&&Fh(c,o,l,s[s.length-1],0))s[s.length-1]=a;else{s.length&&(s[s.length-1]=qh(s[s.length-1],o.length));let h=zh(l,c);s.push(h),i=i.matchType(h.type),o=c}}),s)return w.from(s)}return n}function zh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function Fh(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function hh(n,e,t){return et}).createHTML(n):n}function Km(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Jh().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Hh[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=jm(n),i)for(let o=0;o=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),o++,s++}return new b(i,o,s)}var ge={},ye={},Xm={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 Qm(n){for(let e in ge){let t=ge[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{eg(n,r)&&!hl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},Xm[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 Zm(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 eg(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 tg(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,!Wh(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,sn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Jm(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(Wh(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",o=>o(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function fo(n){return{left:n.clientX,top:n.clientY}}function ng(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 o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),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 rg(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 ig(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof C&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(C.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(jn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function og(n,e,t,r,i){return dl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?ig(n,t):rg(n,t))}function sg(n,e,t,r){return dl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function lg(n,e,t,r){return dl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||cg(n,t,r)}function cg(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 o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)jn(n,A.create(r,l+1,l+1+s.content.size),"pointer");else if(C.isSelectable(s))jn(n,C.create(r,l),"pointer");else continue;return!0}}function fl(n){return oo(n)}var $h=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=fl(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&ng(t,n.input.lastClick)&&!t[$h]&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o};let s=n.posAtCoords(fo(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new nl(n,s,t,!!r)):(o=="doubleClick"?sg:lg)(n,s.pos,s.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[$h],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let h=e.state.doc.resolve(t.pos);o=h.parent,s=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&&o.type.spec.draggable&&o.type.spec.selectable!==!1||a instanceof C&&a.from<=s&&a.to>s)&&(this.mightDrag={node:o,pos:s,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(()=>pt(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(fo(e))),this.updateAllowDefault(e),this.allowDefault||!t?Vt(this.view,"pointer"):og(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 Wh(n,e){return n.composing?!0:me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var ag=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(),oo(n,!0),n.markCursor=null;else if(oo(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,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}jh(n,ag)};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++,jh(n,20))};function jh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>oo(n),e))}function Kh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=dg());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function hg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=lm(e.focusNode,e.focusOffset),r=cm(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function dg(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function oo(n,e=!1){if(!(Fe&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Kh(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 fg(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&&um<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=Fr?null:t.clipboardData,s=r.content(),{dom:l,text:c}=Ph(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",c)):fg(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function ug(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function pg(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 o=Lh(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,o||b.empty)))return!0;if(!o)return!1;let s=ug(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Yh(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,Yh(r),r.getData("text/html"),i,t)?t.preventDefault():pg(n,t)};var so=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Gh=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,o=i.empty?null:n.posAtCoords(fo(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof C?i.to-1:i.to))){if(r&&r.mightDrag)s=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&&(s=C.create(n.state.doc,d.posBefore))}}let l=(s||n.state.selection).content(),{dom:c,text:a,slice:h}=Ph(n,l);(!t.dataTransfer.files.length||!ae||Mh>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 so(h,!t[Gh],s)};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(fo(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",p=>{s=p(s,n)}):s=Lh(n,Yh(t.dataTransfer),Fr?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!t[Gh]);if(n.someProp("handleDrop",p=>p(n,t,s||b.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let c=s?Ia(n.state.doc,o.pos,s):o.pos;c==null&&(c=o.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=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,s.content.firstChild):a.replaceRange(h,h,s),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&C.isSelectable(s.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(s.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,T)=>p=T),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())&&pt(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",o=>o(n,sn(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 lo=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:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new ne(o-r,o-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 o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new ne(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}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,o){let s;for(let l=0;l{let a=c+r,h;if(h=Qh(t,l,a)){for(i||(i=this.children.slice());ol&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&c.type instanceof an){let a=Math.max(o,c.from)-o,h=Math.min(s,c.to)-o;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;yT+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]+o,-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]+o+1,s);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=gg(l,n,e,t,i,o,s),h=ao(a,r,0,s);e=h.local;for(let d=0;dt&&s.to{let a=Qh(n,l,c+t);if(a){o=!0;let h=ao(a,l,t+c+1,r);h!=ce&&i.push(c,c+l.nodeSize,h)}});let s=Xh(o?Zh(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function zs(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])),co.from(e)}var yg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},wg=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}},ol=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()}),wg&&(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,yg)),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(ih(this.view)){if(this.suppressingSelectionUpdates)return pt(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 o=e.focusNode;o;o=zr(o))t.add(o);for(let o=e.anchorNode;o;o=zr(o))if(t.has(o)){r=o;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)&&ih(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),o=-1,s=-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||Sg(e,d)!=u)&&f.remove()}}}let a=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),bg(e)),this.handleDOMChange(o,s,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||pt(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],T=y.pmViewDesc;if(y.nodeName=="BR"&&!T){o=g;break}if(!T||T.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(s),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:o,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:Cg,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+s,head:y+s}}return{doc:m,sel:p,from:s,to:l}}function Cg(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 Mg=/^(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 Ag(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let E=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,Nt=cl(n,E);if(Nt&&!n.state.selection.eq(Nt)){if(ae&&Fe&&n.input.lastKeyCode===13&&Date.now()-100fp(n,sn(13,"Enter"))))return;let Bi=n.state.tr.setSelection(Nt);E=="pointer"?Bi.setMeta("pointer",!0):E=="key"&&Bi.scrollIntoView(),o&&Bi.setMeta("composition",o),n.dispatch(Bi)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=kg(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(E=>E.nodeType==1&&!Mg.test(E.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",E=>E(n,sn(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 E=gh(n,n.state.doc,a.sel);if(E&&!E.eq(n.state.selection)){let Nt=n.state.tr.setSelection(E);o&&Nt.setMeta("composition",o),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),T=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,N;if((Kn&&n.input.lastIOSEnter>Date.now()-225&&(!T||i.some(E=>E.nodeName=="DIV"||E.nodeName=="P"))||!T&&m.posE(n,sn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Eg(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",E=>E(n,sn(8,"Backspace")))){Fe&&ae&&n.domObserver.suppressSelectionUpdates();return}ae&&Fe&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),Fe&&!T&&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(E){return E(n,sn(13,"Enter"))})},20));let Se=p.start,pe=p.endA,Y,ht,Ot;if(T){if(m.pos==g.pos)ke&&Bt<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>pt(n),20)),Y=n.state.tr.delete(Se,pe),ht=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(Ot=Tg(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 E=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",Nt=>Nt(n,Se,pe,E)))return;Y=n.state.tr.insertText(E,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 E=gh(n,Y.doc,a.sel);E&&!(ae&&Fe&&n.composing&&E.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:al(n,e.resolve(t.anchor),e.resolve(t.head))}function Tg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||Fs(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function Dg(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,o-Math.min(s,l));r-=s+c-o}if(s=s?o-r:0;o-=c,o&&o=l?o-r:0;o-=c,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}var sl=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(kh),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=xh(this),bh(this),this.nodeViews=Sh(this),this.docView=Qa(this.state.doc,wh(this),zs(this),this.dom,this),this.domObserver=new ol(this,(r,i,o,s)=>Ag(this,r,i,o,s)),this.domObserver.start(),Qm(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(kh),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,o=!1,s=!1;e.storedMarks&&this.composing&&(Kh(this),s=!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=Sh(this);Ng(u,this.nodeViews)&&(this.nodeViews=u,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&tl(this),this.editable=xh(this),bh(this);let c=zs(this),a=wh(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=o||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(s=!0);let f=h=="preserve"&&s&&this.dom.style.overflowAnchor==null&&gm(this);if(s){this.domObserver.stop();let u=d&&(ke||ae)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Og(i.selection,e.selection);if(d){let p=ae?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=hg(this)),(o||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Qa(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Bm(this))?pt(this,u):(Uh(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&&ym(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&&Wa(this,t.getBoundingClientRect(),e)}else Wa(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(o))==r.node&&(i=o)}this.dragging=new so(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 s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Cm(this,e)}coordsAtPos(e,t=1){return Oh(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 Dm(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&&(Zm(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],zs(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,om())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return tg(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&&hm(this.dom.ownerDocument)==this.dom&&xg(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function wh(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 bh(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 xh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Og(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 Sh(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 Ng(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 kh(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 Ig=["p",0],Rg=["blockquote",0],vg=["hr"],_g=["pre",["code",0]],Ug=["br"],Vg={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Ig}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Rg}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return vg}},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 _g}},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 Ug}}},Bg=["em",0],Pg=["strong",0],Lg=["code",0],zg={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 Bg}},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 Pg}},code:{parseDOM:[{tag:"code"}],toDOM(){return Lg}}},Fg=new Dr({nodes:Vg,marks:zg});var td=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function qg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Hg=(n,e,t)=>{let r=qg(n,t);if(!r)return!1;let i=nd(r);if(!i){let s=r.blockRange(),l=s&&nn(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(od(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Gn(o,"end")||C.isSelectable(o)))for(let s=r.depth;;s--){let l=Xi(n.doc,r.before(s),r.after(s),b.empty);if(l&&l.slice.size1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-o.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 Jg=(n,e,t)=>{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=nd(r)}let s=o&&o.nodeBefore;return!s||!C.isSelectable(s)?!1:(e&&e(n.tr.setSelection(C.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function nd(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 $g(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=$g(n,t);if(!r)return!1;let i=rd(r);if(!i)return!1;let o=i.nodeAfter;if(od(n,i,e,1))return!0;if(r.parent.content.size==0&&(Gn(o,"start")||C.isSelectable(o))){let s=Xi(n.doc,r.before(),r.after(),b.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=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=Rs(n.doc,t.from,-1),i==null)return!1;if(e){let o=n.tr.join(i);r&&o.setSelection(C.create(o.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(o.scrollIntoView())}return!0},id=(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=Rs(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),o=i&&nn(i);return o==null?!1:(e&&e(n.tr.lift(i,o).scrollIntoView()),!0)},Kg=(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),o=t.indexAfter(-1),s=ml(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,s.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},Yg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Ee||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=ml(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!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 o=t.before();if(Rt(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Xg(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 o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof A||e.selection instanceof Ee)&&s.deleteSelection();let l=r.depth==0?null:ml(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,o,r),a=c?[c]:o&&l?[{type:l}]:void 0,h=Rt(s.doc,s.mapping.map(r.pos),1,a);if(!a&&!h&&Rt(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(s.split(s.mapping.map(r.pos),1,a),!o&&!r.parentOffset&&r.parent.type!=l){let d=s.mapping.map(r.before()),f=s.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}return t&&t(s.scrollIntoView()),!0}}var Qg=Xg();var Kr=(n,e)=>{let{$from:t,to:r}=n.selection,i,o=t.sharedDepth(r);return o==0?!1:(i=t.before(o),e&&e(n.tr.setSelection(C.create(n.doc,i))),!0)},Zg=(n,e)=>(e&&e(n.tr.setSelection(new Ee(n.doc))),!0);function ey(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||rn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function od(n,e,t,r){let i=e.nodeBefore,o=e.nodeAfter,s,l,c=i.type.spec.isolating||o.type.spec.isolating;if(!c&&ey(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(s=(l=i.contentMatchAt(i.childCount)).findWrapping(o.type))&&l.matchType(s[0]||o.type).validEnd){if(t){let u=e.pos+o.nodeSize,p=w.empty;for(let y=s.length-1;y>=0;y--)p=w.from(s[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),s.length,!0)),g=m.doc.resolve(u+2*s.length);g.nodeAfter&&g.nodeAfter.type==i.type&&rn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=o.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(o,"start",!0)&&Gn(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=o,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 T=n.tr.step(new X(e.pos-p.length,e.pos+o.nodeSize,e.pos+g,e.pos+o.nodeSize-g,new b(y,p.length,0),0,!0));t(T.scrollIntoView())}return!0}}return!1}function sd(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}var ty=sd(-1),ny=sd(1);function Xn(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o),l=s&&Gi(s,n,e);return l?(r&&r(t.tr.wrap(s,l).scrollIntoView()),!0):!1}}function pn(n,e=null){return function(t,r){let i=!1;for(let o=0;o{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 o=t.tr;for(let s=0;s{if(l||!r&&c.isAtom&&c.isInline&&a>=o.pos&&a+c.nodeSize<=s.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function iy(n){let e=[];for(let t=0;t{if(o.isAtom&&o.content.size&&o.isInline&&s>=r.pos&&s+o.nodeSize<=i.pos)return s+1>r.pos&&e.push(new vt(r,r.doc.resolve(s+1))),r=r.doc.resolve(s+1+o.content.size),!1}),r.poso.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(s.depth-1).type.compatibleContent(n)&&s.startIndex==0){if(i.index(s.depth-1)==0)return!1;let h=t.doc.resolve(s.start-2);c=new Zt(h,h,s.depth),s.endIndex=0;h--)o=w.from(t[h].type.create(t[h].attrs,o));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(o,0,0),t.length,!0));let s=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=T+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let c=o.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,o.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,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?py(e,t,n,o):my(e,t,o):!0:!1}}function py(n,e,t,r){let i=n.tr,o=r.end,s=r.$to.end(r.depth);om;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let o=r.doc.resolve(t.start),s=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=o.node(-1),h=o.index(-1);if(!a.canReplace(h+(l?0:1),h+1,s.content.append(c?w.empty:w.from(i))))return!1;let d=o.pos,f=d+s.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,o=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let l=o.parent,c=l.child(s-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=o.start,u=o.end;t(e.tr.step(new X(f-(a?3:1),u,f,u,d,1,!0)).scrollIntoView())}return!0}}var gt={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:"'"},mo={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},gy=typeof navigator<"u"&&/Mac/.test(navigator.platform),yy=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(J=0;J<10;J++)gt[48+J]=gt[96+J]=String(J);var J;for(J=1;J<=24;J++)gt[J+111]="F"+J;var J;for(J=65;J<=90;J++)gt[J]=String.fromCharCode(J+32),mo[J]=String.fromCharCode(J);var J;for(po in gt)mo.hasOwnProperty(po)||(mo[po]=gt[po]);var po;function ad(n){var e=gy&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||yy&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?mo:gt)[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 wy=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function by(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=gt[r.keyCode])&&o!=i){let l=e[Sl(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var go=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(o,s){return i.push(e(o,s))},t,r),i};re.from=function(e){return e instanceof re?e:e&&e.length?new hd(e):re.empty};var hd=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,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,l){for(var c=o;c=s;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=go)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=go)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 hd([]);var ky=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,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(o,l)-l,s+l)===!1||o=o?this.right.slice(r-o,i-o):this.left.slice(r,o).append(this.right.slice(0,i-o))},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 Cy=500,yo=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,o;t&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,l,c,a=[],h=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),o=i.maps.length),o--,h.push(d);return}if(i){h.push(new Ge(d.map));let u=d.step.map(i.slice(o)),p;u&&s.maybeStep(u).doc&&(p=s.mapping.maps[s.mapping.maps.length-1],a.push(new Ge(p,void 0,void 0,a.length+h.length))),o--,p&&i.appendMap(p,o)}else s.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(o)):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:s,selection:l}}addTransform(e,t,r,i){let o=[],s=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hAy&&(l=My(l,a),s-=a),new n(l.append(o),s)}remapping(e,t){let r=new Rr;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new Ge(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let c=t;this.items.forEach(f=>{let u=o.getMirror(--c);if(u==null)return;s=Math.min(s,u);let p=o.maps[u];if(f.step){let m=e.steps[u].invert(e.docs[u]),g=f.selection&&f.selection.map(o.slice(c+1,u));g&&l++,r.push(new Ge(p,m,g))}else r.push(new Ge(p))},i);let a=[];for(let f=t;fCy&&(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=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let c=s.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=s.selection&&s.selection.map(t.slice(r));h&&o++;let d=new Ge(a.invert(),c,h),f,u=i.length-1;(f=i.length&&i[u].merge(d))?i[u]=f:i.push(d)}}else s.map&&r--},this.items.length,0),new n(kl.from(i.reverse()),o)}};yo.empty=new yo(kl.empty,0);function My(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var Ge=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,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},Ay=20;function Ty(n,e,t){let r=Ey(e),i=Al.get(e).spec.config,o=(t?n.undone:n.done).popEvent(e,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),l=(t?n.done:n.undone).addTransform(o.transform,e.selection.getBookmark(),i,r),c=new Ml(t?l:o.remaining,t?o.remaining:l,null,0,-1);return o.transform.setSelection(s).setMeta(Al,{redo:t,historyState:c})}var Cl=!1,dd=null;function Ey(n){let e=n.plugins;if(dd!=e){Cl=!1,dd=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 o=Ty(i,t,n);o&&r(e?o.scrollIntoView():o)}return!0}}var Xr=wo(!1,!0),Qn=wo(!0,!0),xx=wo(!1,!1),Sx=wo(!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 Tl(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Dy(e)||!Oy(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,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!C.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),r=!1;continue e}break}o=s,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 Tl=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 Dy(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 Oy(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 Ny(){return new H({props:{decorations:_y,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:Ry,handleKeyDown:Iy,handleDOMEvents:{beforeinput:vy}}})}var Iy=Gr({ArrowLeft:bo("horiz",-1),ArrowRight:bo("horiz",1),ArrowUp:bo("vert",-1),ArrowDown:bo("vert",1)});function bo(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,c=s.empty;if(s instanceof A){if(!o.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 Ry(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 vy(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 s=r.length-1;s>=0;s--)i=w.from(r[s].createAndFill(null,i));let o=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return o.setSelection(A.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function _y(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 yt(){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&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var Vy=500;function pd({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,o){return ud(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&ud(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function ud(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.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--)s.step(l.steps[c].invert(l.docs[c]));if(o.text){let c=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,n.schema.text(o.text,c))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},By=new wt(/--$/,"\u2014"),Py=new wt(/\.\.\.$/,"\u2026"),Nx=new wt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Ix=new wt(/"$/,"\u201D"),Rx=new wt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),vx=new wt(/'$/,"\u2019");var gd=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Ly(n,e){let t={},r;function i(o,s){if(e){let l=e[o];if(l===!1)return;l&&(o=l)}t[o]=s}if(i("Mod-z",Xr),i("Shift-Mod-z",Qn),i("Backspace",md),gd||i("Mod-y",Qn),i("Alt-ArrowUp",Wr),i("Alt-ArrowDown",id),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",uo(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",uo(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Xn(r)),r=n.nodes.hard_break){let o=r,s=Yr(gl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(o.create()).scrollIntoView()),!0));i("Mod-Enter",s),i("Shift-Enter",s),gd&&i("Ctrl-Enter",s)}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 o=1;o<=6;o++)i("Shift-Ctrl-"+o,pn(r,{level:o}));if(r=n.nodes.horizontal_rule){let o=r;i("Mod-_",(s,l)=>(l&&l(s.tr.replaceSelectionWith(o.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 _=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){(o||(o=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Se=i+N*e;for(let pe=0;per&&(o+=a.attrs.colspan)}}for(let s=0;s1&&(t=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function qy(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(s)):null,i=Number(n.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let s in e){let l=e[s].getFromDOM,c=l&&l(n);c!=null&&(o[s]=c)}return o}function wd(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 Jy(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=>yd(r,e)}],toDOM(r){return["td",wd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>yd(r,e)}],toDOM(r){return["th",wd(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 $y(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)||Wy(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Wy(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=_.get(r),o=n.start(-1),s=i.nextCell(n.pos-o,e,t);return s==null?null:n.node(0).resolve(o+s)}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 Dd(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-o);c.unshift(t.pos-o);let a=c.map(h=>{let d=r.nodeAt(h);if(!d)throw RangeError(`No cell with offset ${h} found`);let f=o+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 o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?bt.rowSelection(r,i):o&&this.isColSelection()?bt.colSelection(r,i):new bt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=_.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];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=_.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),c=e.node(0);return s.top<=l.top?(s.top>0&&(e=c.resolve(o+i.map[s.left])),l.bottom0&&(t=c.resolve(o+i.map[l.left])),s.bottom0)return!1;let s=i+this.$anchorCell.nodeAfter.attrs.colspan,l=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,l)==t.width}eq(e){return e instanceof bt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=e.node(-1),i=_.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),c=e.node(0);return s.left<=l.left?(s.left>0&&(e=c.resolve(o+i.map[s.top*i.width])),l.right0&&(t=c.resolve(o+i.map[l.top*i.width])),s.right{e.push(ne.node(r,r+t.nodeSize,{class:"selectedCell"}))}),z.create(n.doc,e)}function Xy({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(o+1)>e.start(o));o--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Qy({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let o=n.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){t=o;break}}for(let i=e.depth;i>0;i--){let o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return t!==r&&e.parentOffset===0}function Zy(n,e,t){let r=(e||n).selection,i=(e||n).doc,o,s;if(r instanceof C&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=B.create(i,r.from);else if(s=="row"){let l=i.resolve(r.from+1);o=B.rowSelection(l,l)}else if(!t){let l=_.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];o=B.create(i,c+1,a)}}else r instanceof A&&Xy(r)?o=A.create(i,r.from):r instanceof A&&Qy(r)&&(o=A.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=n.tr)).setSelection(o),e}var e0=new le("fix-tables");function Nd(n,e,t,r){let i=n.childCount,o=e.childCount;e:for(let s=0,l=0;s{i.type.spec.tableRole=="table"&&(t=t0(n,i,o,t))};return e?e.doc!=n.doc&&Nd(e.doc,n.doc,0,r):n.doc.descendants(r),t}function t0(n,e,t,r){let i=_.get(e);if(!i.problems)return r;r||(r=n.tr);let o=[];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;Ky(e,r,i+o)&&(o=i==0||i==e.width?null:0);for(let s=0;s0&&i0&&e.map[l-1]==c||i0?-1:0;i0(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[o]==t[o-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function f0(n){return(e,t)=>{var r;let i=e.selection,o,s;if(i instanceof B){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;o=i.$anchorCell.nodeAfter,s=i.$anchorCell.pos}else{if(o=$y(i.$from),!o)return!1;s=(r=Zn(i.$from))==null?void 0:r.pos}if(o==null||s==null||o.attrs.colspan==1&&o.attrs.rowspan==1)return!1;if(t){let l=o.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+o.tableStart,m=s.doc.nodeAt(p);m&&s.setNodeMarkup(p,f,m.attrs)}),r(s)}return!0}}var tS=Bl("row",{useDeprecatedLogic:!0}),nS=Bl("column",{useDeprecatedLogic:!0}),rS=Bl("cell",{useDeprecatedLogic:!0});function p0(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 o=n.node(-1).child(r),s=o.lastChild;if(s)return i-1-s.nodeSize;i-=o.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 xo(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((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function y0(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),o=i.type.spec.tableRole,s=i.type.schema,l=[];if(o=="row")for(let c=0;c=0;s--){let{rowspan:l,colspan:c}=o.child(s).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)}o.push(w.from(c))}t=o,e=i}return{width:n,height:e,rows:t}}function x0(n,e,t,r,i,o,s){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 o=t.selection;if(o instanceof B)return Co(t,r,S.near(o.$headCell,e));if(n!="horiz"&&!o.empty)return!1;let s=_d(i,n,e);if(s==null)return!1;if(n=="horiz")return Co(t,r,S.near(t.doc.resolve(o.head+e),e));{let l=t.doc.resolve(s),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),Co(t,r,a)}}}function ko(n,e){return(t,r,i)=>{if(!i)return!1;let o=t.selection,s;if(o instanceof B)s=o;else{let c=_d(i,n,e);if(c==null)return!1;s=new B(t.doc.resolve(c))}let l=Ed(s.$headCell,n,e);return l?Co(t,r,new B(s.$anchorCell,l)):!1}}function k0(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 C0(n,e,t){if(!He(n.state))return!1;let r=y0(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 o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),l=_.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=b0(r,l.right-l.left,l.bottom-l.top),Cd(n.state,n.dispatch,s,l,r),!0}else if(r){let o=vl(n.state),s=o.start(-1);return Cd(n.state,n.dispatch,s,_.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function M0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Md(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof B)o(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Zn(n.state.selection.$anchor))!=null&&((t=El(n,e))==null?void 0:t.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(c,a){let h=El(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 s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),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(Md(n,a.target)!=r&&(d=El(n,e),!d))return s();d&&o(d,a)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",l)}function _d(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 o=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.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 Md(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function El(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Zn(n.state.doc.resolve(t.pos)):null}var A0=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,o){var s;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(o,s){return s.apply(o)}},props:{attributes:o=>{let s=Ve.getState(o);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,s)=>{D0(o,s,n,e,r)},mouseleave:o=>{O0(o)},mousedown:(o,s)=>{N0(o,s,e)}},decorations:o=>{let s=Ve.getState(o);if(s&&s.activeHandle>-1)return V0(o,s.activeHandle)},nodeViews:{}}});return i}var E0=class Mo{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 Mo(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Mo(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 Mo(i,t.dragging)}return t}};function D0(n,e,t,r,i){let o=Ve.getState(n.state);if(o&&!o.dragging){let s=R0(e.target),l=-1;if(s){let{left:c,right:a}=s.getBoundingClientRect();e.clientX-c<=t?l=Ad(n,e,"left",t):a-e.clientX<=t&&(l=Ad(n,e,"right",t))}if(l!=o.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=_.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}Ud(n,l)}}}function O0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Ud(n,-1)}function N0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,o=Ve.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;let s=n.state.doc.nodeAt(o.activeHandle),l=I0(n,o.activeHandle,s.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&&(v0(n,d.activeHandle,Td(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=Td(d.dragging,h,t);_0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function I0(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let o=n.domAtPos(e),l=o.node.childNodes[o.offset].offsetWidth,c=t;if(r)for(let a=0;a1){let s=[],l=null;r.forEach((m,g,y)=>{y===0&&(l=e+1),m.textContent&&s.push(m.textContent)});let c=s[0]||"columns",a=r.child(0).type,h=n.doc.type.schema.nodes.paragraph.create(null,n.doc.type.schema.text(c)),d=a.create({colspan:o,rowspan:1},h),u=n.doc.type.schema.nodes.table_row.create(null,d),p=l+r.nodeSize-1;n.replaceWith(l,p,u)}else if(r.childCount===1){let s=e+1,l=r.child(0);n.setNodeMarkup(s,null,{...l.attrs,colspan:o,rowspan:1})}return n}function Bd(n){for(let e=n.depth;e>0;e-=1){let t=n.node(e);if(t.type.name==="table"){let r=n.start(e)-1;return{table:t,tableStart:r,depth:e}}}return null}function P0(n,e){if(!e)return Ul(n,e);let t=n.selection.$from.pos;return Ul(n,i=>{try{let o=i.doc.resolve(t),s=Bd(o);if(s){let l=i.doc.nodeAt(s.tableStart);l&&Vd(i,s.tableStart,l)}}catch(o){console.warn("Could not fix header row colspan:",o)}e(i)})}function L0(n,e){if(!e)return Vl(n,e);let t=n.selection.$from.pos;return Vl(n,i=>{try{let o=i.doc.resolve(t),s=Bd(o);if(s){let l=i.doc.nodeAt(s.tableStart);l&&Vd(i,s.tableStart,l)}}catch(o){console.warn("Could not fix header row colspan:",o)}e(i)})}var Sr={};pp(Sr,{AbsolutePosition:()=>jo,AbstractConnector:()=>dc,AbstractStruct:()=>yr,AbstractType:()=>W,Array:()=>On,ContentAny:()=>Kt,ContentBinary:()=>In,ContentDeleted:()=>wr,ContentDoc:()=>Rn,ContentEmbed:()=>At,ContentFormat:()=>L,ContentJSON:()=>ki,ContentString:()=>Re,ContentType:()=>Ae,Doc:()=>We,GC:()=>ue,ID:()=>Ct,Item:()=>O,Map:()=>Nn,PermanentUserData:()=>uc,RelativePosition:()=>ot,Skip:()=>ie,Snapshot:()=>jt,Text:()=>lt,Transaction:()=>Yo,UndoManager:()=>En,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>it,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>ct,XmlHook:()=>Si,XmlText:()=>xe,YArrayEvent:()=>Qo,YEvent:()=>Dn,YMapEvent:()=>Zo,YTextEvent:()=>es,YXmlEvent:()=>ts,applyUpdate:()=>Mc,applyUpdateV2:()=>vn,cleanupYTextFormatting:()=>Ru,compareIDs:()=>kn,compareRelativePositions:()=>rs,convertUpdateFormatV1ToV2:()=>u1,convertUpdateFormatV2ToV1:()=>mu,createAbsolutePositionFromRelativePosition:()=>Oc,createDeleteSet:()=>br,createDeleteSetFromStructStore:()=>Sc,createDocFromSnapshot:()=>Qw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>Ci,createSnapshot:()=>Mi,decodeRelativePosition:()=>jw,decodeSnapshot:()=>Gw,decodeSnapshotV2:()=>nu,decodeStateVector:()=>Tc,decodeUpdate:()=>s1,decodeUpdateV2:()=>au,diffUpdate:()=>h1,diffUpdateV2:()=>Nc,emptySnapshot:()=>Xw,encodeRelativePosition:()=>$w,encodeSnapshot:()=>Yw,encodeSnapshotV2:()=>tu,encodeStateAsUpdate:()=>Ac,encodeStateAsUpdateV2:()=>Qf,encodeStateVector:()=>Dc,encodeStateVectorFromUpdate:()=>l1,encodeStateVectorFromUpdateV2:()=>du,equalDeleteSets:()=>Gf,equalSnapshots:()=>Kw,findIndexSS:()=>ze,findRootTypeKey:()=>_n,getItem:()=>Cn,getState:()=>P,getTypeChildren:()=>y1,isDeleted:()=>Tt,isParentOf:()=>Tn,iterateDeletedStructs:()=>nt,logType:()=>Fw,logUpdate:()=>o1,logUpdateV2:()=>cu,mergeDeleteSets:()=>Mn,mergeUpdates:()=>hu,mergeUpdatesV2:()=>yi,obfuscateUpdate:()=>d1,obfuscateUpdateV2:()=>f1,parseUpdateMeta:()=>c1,parseUpdateMetaV2:()=>fu,readUpdate:()=>Bw,readUpdateV2:()=>Cc,relativePositionToJSON:()=>qw,snapshot:()=>Ai,snapshotContainsUpdate:()=>e1,transact:()=>R,tryGc:()=>r1,typeListToArraySnapshot:()=>cs,typeMapGetAllSnapshot:()=>Eu,typeMapGetSnapshot:()=>x1});var U=()=>new Map,Ao=n=>{let e=U();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},Pd=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Ld=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var To=n=>n[n.length-1];var zd=(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)||U()).values()).forEach(r=>r(...t))}destroy(){this._observers=U()}},tr=class{constructor(){this._observers=U()}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)||U()).values()).forEach(r=>r(...t))}destroy(){this._observers=U()}};var fe=Math.floor;var nr=Math.abs;var De=(n,e)=>nn>e?n:e,pS=Number.isNaN,Hd=Math.pow;var Do=n=>n!==0?n<0:1/n<0;var Pl=Number.MAX_SAFE_INTEGER,mS=Number.MIN_SAFE_INTEGER,gS=1<<31;var Jd=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&fe(n)===n),yS=Number.isNaN,wS=Number.parseInt;var Ll=String.fromCharCode,bS=String.fromCodePoint,xS=Ll(65535),z0=n=>n.toLowerCase(),F0=/^\s*/g,q0=n=>n.replace(F0,""),H0=/([A-Z])/g,zl=(n,e)=>q0(n.replace(H0,t=>`${e}${z0(t)}`));var J0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;iir.encode(n),Wd=ir?$0:J0;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)=>qd(e,()=>n).join("");var wn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},F=()=>new wn;var No=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(No(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=Do(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)},Fl=new Uint8Array(3e4),j0=Fl.length/3,K0=(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),o=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,o>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Be(t*2,o)),n.cbuf.set(e.subarray(i)),n.cpos=o)},V=(n,e)=>{x(n,e.byteLength),ar(n,e)},ql=(n,e)=>{W0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},G0=(n,e)=>ql(n,4).setFloat32(0,e,!1),X0=(n,e)=>ql(n,8).setFloat64(0,e,!1),Q0=(n,e)=>ql(n,8).setBigInt64(0,e,!1);var Yd=new DataView(new ArrayBuffer(4)),Z0=n=>(Yd.setFloat32(0,n),Yd.getFloat32(0)===n),sr=(n,e)=>{switch(typeof e){case"string":Q(n,119),Xe(n,e);break;case"number":Jd(e)&&nr(e)<=2147483647?(Q(n,125),ni(n,e)):Z0(e)?(Q(n,124),G0(n,e)):(Q(n,123),X0(n,e));break;case"bigint":Q(n,122),Q0(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 Gd=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++:(Gd(this),this.count=1,this.s=e)}toUint8Array(){return Gd(this),I(this.encoder)}};var Xd=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++):(Xd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Xd(this),I(this.encoder)}},Oo=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="",Xe(e,this.sarr.join("")),ar(e,this.lensE.toUint8Array()),I(e)}};var Qe=n=>new Error(n),Oe=()=>{throw Qe("Method unimplemented")},j=()=>{throw Qe("Unexpected case")};var Zd=Qe("Unexpected end of array"),ef=Qe("Integer out of Range"),hr=class{constructor(e){this.arr=e,this.pos=0}},q=n=>new hr(n),Hl=n=>n.pos!==n.arr.length;var ew=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>ew(n,k(n));var xn=n=>n.arr[n.pos++];var k=n=>{let e=0,t=1,r=n.arr.length;for(;n.posPl)throw ef}throw Zd},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 o=n.arr.length;for(;n.posPl)throw ef}throw Zd};var tw=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))}},nw=n=>rr.decode(K(n)),Le=rr?nw:tw;var Jl=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},rw=n=>Jl(n,4).getFloat32(0,!1),iw=n=>Jl(n,8).getFloat64(0,!1),ow=n=>Jl(n,8).getBigInt64(0,!1);var sw=[n=>{},n=>null,ii,rw,iw,ow,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;rsw[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),Hl(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=Do(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}},vo=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 CS=crypto.subtle,tf=crypto.getRandomValues.bind(crypto);var lw=Math.random,$l=()=>tf(new Uint32Array(1))[0];var nf=n=>n[fe(lw()*n.length)],cw="10000000-1000-4000-8000"+-1e11,rf=()=>cw.replace(/[018]/g,n=>(n^$l()&15>>n/4).toString(16));var Ne=Date.now;var Wl=n=>new Promise(n);var TS=Promise.all.bind(Promise);var jl=n=>n===void 0?null:n;var Kl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},sf=new Kl,Yl=!0;try{typeof localStorage<"u"&&localStorage&&(sf=localStorage,Yl=!1)}catch{}var Uo=sf,lf=n=>Yl||addEventListener("storage",n),cf=n=>Yl||removeEventListener("storage",n);var df=Object.assign,Vo=Object.keys,ff=(n,e)=>{for(let t in n)e(n[t],t)},uf=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Gl=n=>Vo(n).length,hf=n=>Vo(n).length;var pf=n=>{for(let e in n)return!1;return!0},dw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Xl=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Ql=(n,e)=>n===e||hf(n)===hf(e)&&dw(n,(t,r)=>(t!==void 0||Xl(e,r))&&e[r]===t),fw=Object.freeze,Zl=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&Zl(n[e])}return fw(n)};var si=(n,e,t=0)=>{try{for(;tn,uw=(n,e)=>n===e;var ur=(n,e)=>{if(n==null||e==null)return uw(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 St=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"&&!St,ES=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,Ze,pw=[],mw=()=>{if(Ze===void 0)if(St){Ze=U();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");Ze.set(`--${zl(e,"-")}`,t),Ze.set(`-${zl(e,"-")}`,t)}})):Ze=U();return Ze},nc=n=>mw().has(n);var li=n=>St?jl(process.env[n.toUpperCase().replaceAll("-","_")]):jl(Uo.getItem(n));var gf=n=>nc("--"+n)||li(n)!==null,DS=gf("production"),gw=St&&mf(process.env.FORCE_COLOR,["true","1","2"]),yf=gw||!nc("--no-colors")&&!gf("no-color")&&(!St||process.stdout.isTTY)&&(!St||nc("--color")||li("COLORTERM")!==null||(li("TERM")||"").includes("color"));var wf=n=>new Uint8Array(n),yw=(n,e,t)=>new Uint8Array(n,e,t),bf=n=>new Uint8Array(n),ww=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),xw=n=>{let e=atob(n),t=wf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return yw(e.buffer,e.byteOffset,e.byteLength)},xf=pr?ww:bw,Sf=pr?xw:Sw;var kf=n=>{let e=wf(n.byteLength);return e.set(n),e};var rc=class{constructor(e,t){this.left=e,this.right=t}},et=(n,e)=>new rc(n,e);var kt=typeof document<"u"?document:{};var OS=typeof DOMParser<"u"?new DOMParser:null;var Mf=n=>Pd(n,(e,t)=>`${t}:${e};`).join("");var NS=kt.ELEMENT_NODE,IS=kt.TEXT_NODE,RS=kt.CDATA_SECTION_NODE,vS=kt.COMMENT_NODE,_S=kt.DOCUMENT_NODE,US=kt.DOCUMENT_TYPE_NODE,VS=kt.DOCUMENT_FRAGMENT_NODE;var Po=n=>class{constructor(t){this._=t}destroy(){n(this._)}},Cw=Po(clearTimeout),ai=(n,e)=>new Cw(setTimeout(e,n)),PS=Po(clearInterval);var LS=Po(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var zS=Po(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var tt=Symbol;var hi=tt(),di=tt(),ic=tt(),oc=tt(),sc=tt(),fi=tt(),lc=tt(),mr=tt(),cc=tt(),Ef=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=U(),i=[],o=0;for(;o0||c.length>0?(e.push("%c"+s),t.push(c)):e.push(s)}else break}}for(o>0&&(i=t,i.unshift(e.join("")));o{console.log(...Df(n)),Of.forEach(e=>e.print(n))},ac=(...n)=>{console.warn(...Df(n)),n.unshift(mr),Of.forEach(e=>e.print(n))};var Of=Ce();var Nf=n=>({[Symbol.iterator](){return this},next:n}),If=(n,e)=>Nf(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),zo=(n,e)=>Nf(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var dc=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}},nt=(n,e,t)=>e.clients.forEach((r,i)=>{let o=n.doc.store.clients.get(i);for(let s=0;s{let t=0,r=n.length-1;for(;t<=r;){let i=fe((t+r)/2),o=n[i],s=o.clock;if(s<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&Rw(t,e.clock)!==null},xc=n=>{n.clients.forEach(e=>{e.sort((i,o)=>i.clock-o.clock);let t,r;for(t=1,r=1;t=o.clock?i.len=Be(i.len,o.clock+o.len-i.clock):(r{let e=new $t;for(let t=0;t{if(!e.clients.has(i)){let o=r.slice();for(let s=t+1;s{$(n.clients,e,()=>[]).push(new pi(t,r))},br=()=>new $t,Sc=n=>{let e=br();return n.clients.forEach((t,r)=>{let i=[];for(let o=0;o0&&e.clients.set(r,i)}),e},rt=(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 o=0;o{let e=new $t,t=k(n.restDecoder);for(let r=0;r0){let s=$(e.clients,i,()=>[]);for(let l=0;l{let r=new $t,i=k(n.restDecoder);for(let o=0;o0){let o=new Ie;return x(o.restEncoder,0),rt(o,r),o.toUint8Array()}return null},Gf=(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 o=0;o!0,meta:o=null,autoLoad:s=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Xf(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ko,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=s,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Wl(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>Wl(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 o=new t;return o._integrate(this,null),o}),i=r.constructor;if(t!==W&&i!==t)if(i===W){let o=new t;o._map=r._map,r._map.forEach(s=>{for(;s!==null;s=s.left)s.parent=o}),o._start=r._start;for(let s=o._start;s!==null;s=s.right)s.parent=o;return o._length=r._length,this.share.set(e,o),o._integrate(this,null),o}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,lt)}getMap(e=""){return this.get(e,Nn)}getXmlElement(e=""){return this.get(e,Z)}getXmlFragment(e=""){return this.get(e,ct)}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 kf(K(this.restDecoder))}readJSON(){return JSON.parse(Le(this.restDecoder))}readKey(){return Le(this.restDecoder)}},Wo=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 Wo{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 vo(K(e)),this.parentInfoDecoder=new ri(K(e),xn),this.typeRefDecoder=new Sn(K(e)),this.lenDecoder=new Sn(K(e))}readLeftID(){return new Ct(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Ct(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 o=e[i];o.write(n,r-o.id.clock);for(let s=i+1;s{let r=new Map;t.forEach((i,o)=>{P(e,o)>i&&r.set(o,i)}),Ti(e).forEach((i,o)=>{t.has(o)||r.set(o,0)}),x(n.restEncoder,r.size),$e(r.entries()).sort((i,o)=>o[0]-i[0]).forEach(([i,o])=>{vw(n,e.clients.get(i),i,o)})},_w=(n,e)=>{let t=U(),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 o=()=>{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},s=o();if(s===null)return null;let l=new Ko,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=s.refs[s.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(s!==null&&s.i0){let u=new Ie;return kc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},Vw=(n,e)=>kc(n,e.doc.store,e.beforeState),Cc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let o=!1,s=i.doc,l=s.store,c=_w(r,s),a=Uw(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=_f(r,i,l);if(l.pendingDs){let f=new be(q(l.pendingDs));k(f.restDecoder);let u=_f(f,i,l);d&&u?l.pendingDs=yi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(o){let f=l.pendingStructs.update;l.pendingStructs=null,vn(i.doc,f)}},t,!1),Bw=(n,e,t)=>Cc(n,e,t,new Me(n)),vn=(n,e,t,r=be)=>{let i=q(e);Cc(i,n,t,new r(i))},Mc=(n,e,t)=>vn(n,e,t,Me),Pw=(n,e,t=new Map)=>{kc(n,e.store,t),rt(n,Sc(e.store))},Qf=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Tc(e);Pw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Nc(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===it)return hu(i.map((o,s)=>s===0?o:mu(o)));if(t.constructor===Ie)return yi(i)}return i[0]},Ac=(n,e)=>Qf(n,e,new it),Zf=n=>{let e=new Map,t=k(n.restDecoder);for(let r=0;rZf(new An(q(n))),Ec=(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),Lw=(n,e)=>Ec(n,Ti(e.store)),zw=(n,e=new gr)=>(n instanceof Map?Ec(e,n):Lw(e,n),e.toUint8Array()),Dc=n=>zw(n,new Wt),fc=class{constructor(){this.l=[]}},Uf=()=>new fc,Vf=(n,e)=>n.l.push(e),Bf=(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.")},eu=(n,e,t)=>si(n.l,[e,t]),Ct=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 Ct(n,e),Pf=(n,e)=>{x(n,e.client),x(n,e.clock)},Lf=n=>M(k(n),k(n)),_n=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw j()},Tn=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1},Fw=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))},uc=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=(o,s)=>{let l=o.get("ds"),c=o.get("ids"),a=h=>this.clients.set(h,s);l.observe(h=>{h.changes.added.forEach(d=>{d.content.getContent().forEach(f=>{f instanceof Uint8Array&&this.dss.set(s,Mn([this.dss.get(s)||br(),Mt(new An(q(f)))]))})})}),this.dss.set(s,Mn(l.map(h=>Mt(new An(q(h)))))),c.observe(h=>h.changes.added.forEach(d=>d.content.getContent().forEach(a))),c.forEach(a)};t.observe(o=>{o.keysChanged.forEach(s=>i(t.get(s),s))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let o=this.yusers,s=o.get(r);s||(s=new Nn,s.set("ids",new On),s.set("ds",new On),o.set(r,s)),s.get("ids").push([t]),o.observe(l=>{setTimeout(()=>{let c=o.get(r);if(c!==s){s=c,this.clients.forEach((d,f)=>{r===d&&s.get("ids").push([f])});let a=new Wt,h=this.dss.get(r);h&&(rt(a,h),s.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=s.get("ds"),a=l.deleteSet;if(l.local&&a.clients.size>0&&i(l,a)){let h=new Wt;rt(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}},qw=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),jo=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},Hw=(n,e,t=0)=>new jo(n,e,t),Fo=(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 Fo(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Fo(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Fo(n,r.lastId,t);r=r.right}return Fo(n,null,t)},Jw=(n,e)=>{let{type:t,tname:r,item:i,assoc:o}=e;if(i!==null)x(n,0),Pf(n,i);else if(r!==null)cr(n,1),Xe(n,r);else if(t!==null)cr(n,2),Pf(n,t);else throw j();return ni(n,o),n},$w=n=>{let e=F();return Jw(e,n),I(e)},Ww=n=>{let e=null,t=null,r=null;switch(k(n)){case 0:r=Lf(n);break;case 1:t=Le(n);break;case 2:e=Lf(n)}let i=Hl(n)?ii(n):0;return new ot(e,t,r,i)},jw=n=>Ww(q(n)),Oc=(n,e,t=!0)=>{let r=e.store,i=n.item,o=n.type,s=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(P(r,i.client)<=i.clock)return null;let h=t?wc(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(s!==null)c=e.get(s);else if(o!==null){if(P(r,o.client)<=o.clock)return null;let{item:h}=t?wc(r,o):{item:Cn(r,o)};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 Hw(c,a,n.assoc)},rs=(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}},Kw=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,o=e.sv;if(i.size!==o.size||t.size!==r.size)return!1;for(let[s,l]of i.entries())if(o.get(s)!==l)return!1;for(let[s,l]of t.entries()){let c=r.get(s)||[];if(l.length!==c.length)return!1;for(let a=0;a(rt(e,n.ds),Ec(e,n.sv),e.toUint8Array()),Yw=n=>tu(n,new Wt),nu=(n,e=new Wo(q(n)))=>new jt(Mt(e),Zf(e)),Gw=n=>nu(n,new An(q(n))),Mi=(n,e)=>new jt(n,e),Xw=Mi(br(),new Map),Ai=n=>Mi(Sc(n.store),Ti(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),pc=(n,e)=>{let t=$(n.meta,pc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,o)=>{i{}),t.add(e))},Qw=(n,e,t=new We)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,o=new Ie;return n.transact(s=>{let l=0;r.forEach(c=>{c>0&&l++}),x(o.restEncoder,l);for(let[c,a]of r){if(a===0)continue;a{let r=new t(q(e)),i=new st(r,!1);for(let s=i.curr;s!==null;s=i.next())if((n.sv.get(s.id.client)||0)Zw(n,e,Me),Ko=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ti=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},ru=(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],o=i.id.clock;if(o===e)return r;let s=fe(e/(o+i.length-1)*r);for(;t<=r;){if(i=n[s],o=i.id.clock,o<=e){if(e{let t=n.clients.get(e.client);return t[ze(t,e.clock)]},Cn=t1,mc=(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[mc(n,t,e.clock)]},zf=(n,e,t)=>{let r=e.clients.get(t.client),i=ze(r,t.clock),o=r[i];return t.clock!==o.id.clock+o.length-1&&o.constructor!==ue&&r.splice(i+1,0,ns(n,o,t.clock-o.id.clock+1)),o},n1=(n,e,t)=>{let r=n.clients.get(e.id.client);r[ze(r,e.id.clock)]=t},iu=(n,e,t,r,i)=>{if(r===0)return;let o=t+r,s=mc(n,e,t),l;do l=e[s++],oe.deleteSet.clients.size===0&&!Ld(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(xc(e.deleteSet),Vw(n,e),rt(n,e.deleteSet),!0),qf=(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)},Jo=(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 o=e-i;return o&&n.splice(e+1-o,o),o},ou=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let o=e.clients.get(r);for(let s=i.length-1;s>=0;s--){let l=i[s],c=l.clock+l.len;for(let a=ze(o,l.clock),h=o[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let o=t.length-1;o>=0;o--){let s=t[o],l=De(i.length-1,1+ze(i,s.clock+s.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=s.clock;a=i[c])c-=1+Jo(i,c)}})},r1=(n,e,t)=>{ou(n,e,t),su(n,e)},lu=(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),eu(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),si(l,[]),t._needFormattingCleanup&&M1(t)}finally{r.gc&&ou(o,i,r.gcFilter),su(o,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+Jo(u,m)}});for(let h=s.length-1;h>=0;h--){let{client:d,clock:f}=s[h].id,u=i.clients.get(d),p=ze(u,f);p+11||p>0&&Jo(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(Lo(mr,hi,"[yjs] ",di,fi,"Changed the client-id because another client seems to be using it."),r.clientID=Xf()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new it;Ff(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;Ff(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])):lu(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,o=!1,s=null;n._transaction===null&&(o=!0,n._transaction=new Yo(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{s=e(n._transaction)}finally{if(o){let l=n._transaction===i[0];n._transaction=null,l&&lu(i,0)}}return s},gc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Hf=(n,e,t)=>{nt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>Tn(i,r))&&Uc(r,!1)})},Jf=(n,e,t)=>{let r=null,i=n.doc,o=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;nt(l,a.insertions,u=>{if(u instanceof O){if(u.redone!==null){let{item:p,diff:m}=wc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&o.some(p=>Tn(p,u))&&d.push(u)}}),nt(l,a.deletions,u=>{u instanceof O&&o.some(p=>Tn(p,u))&&!Tt(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=_u(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 s=n.currStackItem;if(s!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:s,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return s},En=class extends er{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:s=!1,doc:l=Zr(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,o.add(this),this.trackedOrigins=o,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=s,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 T=c.beforeState.get(y)||0,N=g-T;N>0&&mi(f,y,T,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 gc(c.deleteSet,f)),p=!0;!a&&!h&&(this.lastChange=u),nt(c,c.deleteSet,g=>{g instanceof O&&this.scope.some(y=>Tn(y,g))&&Uc(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&&ac("[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=>Hf(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>Hf(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=Jf(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Jf(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*i1(n){let e=k(n.restDecoder);for(let t=0;tcu(n,Me),cu=(n,e=be)=>{let t=[],r=new e(q(n)),i=new st(r,!1);for(let s=i.curr;s!==null;s=i.next())t.push(s);Lo("Structs: ",t);let o=Mt(r);Lo("DeleteSet: ",o)},s1=n=>au(n,Me),au=(n,e=be)=>{let t=[],r=new e(q(n)),i=new st(r,!1);for(let o=i.curr;o!==null;o=i.next())t.push(o);return{structs:t,ds:Mt(r)}},gi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},hu=n=>yi(n,Me,it),du=(n,e=gr,t=be)=>{let r=new e,i=new st(new t(q(n)),!1),o=i.curr;if(o!==null){let s=0,l=o.id.client,c=o.id.clock!==0,a=c?0:o.id.clock+o.length;for(;o!==null;o=i.next())l!==o.id.client&&(a!==0&&(s++,x(r.restEncoder,l),x(r.restEncoder,a)),l=o.id.client,a=0,c=o.id.clock!==0),o.constructor===ie&&(c=!0),c||(a=o.id.clock+o.length);a!==0&&(s++,x(r.restEncoder,l),x(r.restEncoder,a));let h=F();return x(h,s),Qd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},l1=n=>du(n,Wt,Me),fu=(n,e=be)=>{let t=new Map,r=new Map,i=new st(new e(q(n)),!1),o=i.curr;if(o!==null){let s=o.id.client,l=o.id.clock;for(t.set(s,l);o!==null;o=i.next())s!==o.id.client&&(r.set(s,l),t.set(o.id.client,o.id.clock),s=o.id.client),l=o.id.clock+o.length;r.set(s,l)}return{from:t,to:r}},c1=n=>fu(n,Me),a1=(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 st(h,!0)),o=null,s=new t,l=new gi(s);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(o!==null){let f=h.curr,u=!1;for(;f!==null&&f.id.clock+f.length<=o.struct.id.clock+o.struct.length&&f.id.client>=o.struct.id.client;)f=h.next(),u=!0;if(f===null||f.id.client!==d||u&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(d!==o.struct.id.client)Ht(l,o.struct,o.offset),o={struct:f,offset:0},h.next();else if(o.struct.id.clock+o.struct.length0&&(o.struct.constructor===ie?o.struct.length-=p:f=a1(f,p)),o.struct.mergeWith(f)||(Ht(l,o.struct,o.offset),o={struct:f,offset:0},h.next())}}else o={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==ie;f=h.next())Ht(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(Ht(l,o.struct,o.offset),o=null),Ic(l);let c=r.map(h=>Mt(h)),a=Mn(c);return rt(s,a),s.toUint8Array()},Nc=(n,e,t=be,r=Ie)=>{let i=Tc(e),o=new r,s=new gi(o),l=new t(q(n)),c=new st(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(s,h,Be(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Ht(s,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=f;)c.next()}Ic(s);let a=Mt(l);return rt(o,a),o.toUint8Array()},h1=(n,e)=>Nc(n,e,Me,it),uu=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&&uu(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++},Ic=n=>{uu(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(q(n)),o=new st(i,!1),s=new r,l=new gi(s);for(let a=o.curr;a!==null;a=o.next())Ht(l,e(a),0);Ic(l);let c=Mt(i);return rt(s,c),s.toUint8Array()},pu=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=U(),o=U(),s=U(),l=U();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=$(o,d.nodeName,()=>"node-"+r)),d instanceof Si&&(d.hookName=$(o,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 At:{let d=h;d.embed={};break}case L:{let d=h;n&&(d.key=$(s,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()}}},d1=(n,e)=>is(n,pu(e),Me,it),f1=(n,e)=>is(n,pu(e),be,Ie),u1=n=>is(n,ec,Me,Ie),mu=n=>is(n,ec,be,it),$f="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=p1(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 Qe($f);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let o=t._map.get(i),s,l;if(this.adds(o)){let c=o.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(o))if(c!==null&&this.deletes(c))s="delete",l=To(c.content.getContent());else return;else c!==null&&this.deletes(c)?(s="update",l=To(c.content.getContent())):(s="add",l=void 0)}else if(this.deletes(o))s="delete",l=To(o.content.getContent());else return;e.set(i,{action:s,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 Qe($f);let t=this.target,r=Ce(),i=Ce(),o=[];if(e={added:r,deleted:i,delta:o,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&o.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}},p1=(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},oe=()=>{ac("Invalid access: Add Yjs type to a document before reading data.")},gu=80,Rc=0,yc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Rc++}},m1=n=>{n.timestamp=Rc++},yu=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Rc++},g1=(n,e,t)=>{if(n.length>=gu){let r=n.reduce((i,o)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((o,s)=>nr(e-o.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 o=i.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(i.index-=o.length);if(o===null||o.marker===!0){n.splice(r,1);continue}i.p=o,o.marker=!0}(e0&&e===i.index)&&(i.index=Be(e,i.index+t))}},y1=n=>{n.doc??oe();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},ls=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;eu(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=Uf(),this._dEH=Uf(),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){Bf(this._eH,e)}unobserveDeep(e){Bf(this._dEH,e)}toJSON(){}},wu=(n,e,t)=>{n.doc??oe(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],o=n._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){let s=o.content.getContent();if(s.length<=e)e-=s.length;else{for(let l=e;l0;l++)i.push(s[l]),r--;e=0}}o=o.right}return i},bu=n=>{n.doc??oe();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 o=0;o{let t=0,r=n._start;for(n.doc??oe();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let o=0;o{let t=[];return bi(n,(r,i)=>{t.push(e(r,i,n))}),t},w1=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}}}},Su=(n,e)=>{n.doc??oe();let t=ss(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,o=n.doc,s=o.clientID,l=o.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(s,P(l,s)),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(s,P(l,s)),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(s,P(l,s)),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(s,P(l,s)),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()},ku=()=>Qe("Length exceeded!"),Cu=(n,e,t,r)=>{if(t>e._length)throw ku();if(t===0)return e._searchMarker&&wi(e._searchMarker,t,r.length),Go(n,e,null,r);let i=t,o=ss(e,t),s=e._start;for(o!==null&&(s=o.p,t-=o.index,t===0&&(s=s.prev,t+=s&&s.countable&&!s.deleted?s.length:0));s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<=s.length){t{let i=(e._searchMarker||[]).reduce((o,s)=>s.index>o.index?s:o,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Go(n,e,i,t)},Mu=(n,e,t,r)=>{if(r===0)return;let i=t,o=r,s=ss(e,t),l=e._start;for(s!==null&&(l=s.p,t-=s.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw ku();e._searchMarker&&wi(e._searchMarker,i,-o+r)},Xo=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},vc=(n,e,t,r)=>{let i=e._map.get(t)||null,o=n.doc,s=o.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(s,P(o.store,s)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},_c=(n,e)=>{n.doc??oe();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Au=n=>{let e={};return n.doc??oe(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Tu=(n,e)=>{n.doc??oe();let t=n._map.get(e);return t!==void 0&&!t.deleted},x1=(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},Eu=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let o=r;for(;o!==null&&(!e.sv.has(o.id.client)||o.id.clock>=(e.sv.get(o.id.client)||0));)o=o.left;o!==null&&qt(o,e)&&(t[i]=o.content.getContent()[o.length-1])}),t},qo=n=>(n.doc??oe(),If(n._map.entries(),e=>!e[1].deleted)),Qo=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??oe(),this._length}_callObserver(e,t){super._callObserver(e,t),ls(this,e,new Qo(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{Cu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{b1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Mu(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return Su(this,e)}toArray(){return bu(this)}slice(e=0,t=this.length){return wu(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return xu(this,e)}forEach(e){bi(this,e)}[Symbol.iterator](){return w1(this)}_write(e){e.writeTypeRef(F1)}},S1=n=>new On,Zo=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){ls(this,e,new Zo(this,e,t))}toJSON(){this.doc??oe();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[...qo(this)].length}keys(){return zo(qo(this),e=>e[0])}values(){return zo(qo(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return zo(qo(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??oe(),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=>{Xo(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return _c(this,e)}has(e){return Tu(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){Xo(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(q1)}},k1=n=>new Nn,Jt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Ql(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}},Wf=(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,o=r?ss(e,t):null;if(o){let s=new xi(o.p.left,o.p,o.index,i);return Wf(n,s,t-o.index)}else{let s=new xi(null,e._start,0,i);return Wf(n,s,t)}},Du=(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,o=i.clientID;r.forEach((s,l)=>{let c=t.left,a=t.right,h=new O(M(o,P(i.store,o)),c,c&&c.lastId,a,a&&a.id,e,null,new L(l,s));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)},Ou=(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()}},Nu=(n,e,t,r)=>{let i=n.doc,o=i.clientID,s=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Jt(a,c)){s.set(l,a);let{left:h,right:d}=t;t.right=new O(M(o,P(i.store,o)),h,h&&h.lastId,d,d&&d.id,e,null,new L(l,c)),t.right.integrate(n,0),t.forward()}}return s},hc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let o=n.doc,s=o.clientID;Ou(t,i);let l=Nu(n,e,t,i),c=r.constructor===String?new Re(r):r instanceof W?new Ae(r):new At(r),{left:a,right:h,index:d}=t;e._searchMarker&&wi(e._searchMarker,t.index,c.getLength()),h=new O(M(s,P(o.store,s)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=d,t.forward(),Du(n,e,t,l)},jf=(n,e,t,r,i)=>{let o=n.doc,s=o.clientID;Ou(t,i);let l=Nu(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(s,P(o.store,s)),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()}Du(n,e,t,l)},Iu=(n,e,t,r,i)=>{let o=e,s=U();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===L){let a=o.content;s.set(a.key,a)}o=o.right}let l=0,c=!1;for(;e!==o;){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;(s.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},C1=(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}},Ru=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,o=U(),s=Ao(o);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case L:xr(s,i.content);break;default:e+=Iu(t,r,i,o,s),o=Ao(s),r=i;break}i=i.right}}),e},M1=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let o=n.beforeState.get(r)||0;i!==o&&iu(n,t.store.clients.get(r),o,i,s=>{!s.deleted&&s.content.constructor===L&&s.constructor!==ue&&e.add(s.parent)})}R(t,r=>{nt(n,n.deleteSet,i=>{if(i instanceof ue||!i.parent._hasFormatting||e.has(i.parent))return;let o=i.parent;i.content.constructor===L?e.add(o):C1(r,i)});for(let i of e)Ru(i)})},Kf=(n,e,t)=>{let r=t,i=Ao(e.currentAttributes),o=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Ae:case At: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,o=new Map,s=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},pf(c)||(u.attributes=df({},c))),h=0;break}u&&t.push(u),l=null}};for(;s!==null;){switch(s.content.constructor){case Ae:case At:this.adds(s)?this.deletes(s)||(f(),l="insert",a=s.content.getContent()[0],f()):this.deletes(s)?(l!=="delete"&&(f(),l="delete"),d+=1):s.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case Re:this.adds(s)?this.deletes(s)||(l!=="insert"&&(f(),l="insert"),a+=s.content.str):this.deletes(s)?(l!=="delete"&&(f(),l="delete"),d+=s.length):s.deleted||(l!=="retain"&&(f(),l="retain"),h+=s.length);break;case L:{let{key:u,value:p}=s.content;if(this.adds(s)){if(!this.deletes(s)){let m=i.get(u)??null;Jt(m,p)?p!==null&&s.delete(r):(l==="retain"&&f(),Jt(p,o.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(s)){o.set(u,p);let m=i.get(u)??null;Jt(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!s.deleted){o.set(u,p);let m=c[u];m!==void 0&&(Jt(m,p)?m!==null&&s.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}s.deleted||(l==="insert"&&f(),xr(i,s.content));break}}s=s.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}},lt=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??oe(),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 es(this,e,t);ls(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??oe();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 o=0;o0)&&hc(r,this,i,l,s.attributes||{})}else s.retain!==void 0?jf(r,this,i,s.retain,s.attributes||{}):s.delete!==void 0&&Kf(r,i,s.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??oe();let i=[],o=new Map,s=this.doc,l="",c=this._start;function a(){if(l.length>0){let d={},f=!1;o.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=o.get("ychange");e!==void 0&&!qt(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),o.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(),o.set("ychange",r?r("added",c.id):{type:"added"})):d!==void 0&&(a(),o.delete("ychange")),l+=c.content.str;break}case Ae:case At:{a();let d={insert:c.content.getContent()[0]};if(o.size>0){let f={};d.attributes=f,o.forEach((u,p)=>{f[p]=u})}i.push(d);break}case L:qt(c,e)&&(a(),xr(o,c.content));break}c=c.right}a()};return e||t?R(s,d=>{e&&pc(d,e),t&&pc(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,o=>{let s=Ho(o,this,e,!r);r||(r={},s.currentAttributes.forEach((l,c)=>{r[c]=l})),hc(o,this,s,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,o=>{let s=Ho(o,this,e,!r);hc(o,this,s,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=>{Kf(i,Ho(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,o=>{let s=Ho(o,this,e,!1);s.right!==null&&jf(o,this,s,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xo(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return _c(this,e)}getAttributes(){return Au(this)}_write(e){e.writeTypeRef(H1)}},A1=n=>new lt,ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??oe()}[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===ct)&&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})}},ct=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??oe(),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){ls(this,e,new ts(this,t,e))}toString(){return xu(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,o=>{i.insertBefore(o.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{Cu(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;Go(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(o=>o===e)+1;if(i===0&&e!==null)throw Qe("Reference item not found");r.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Mu(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return bu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Su(this,e)}slice(e=0,t=this.length){return wu(this,e,t)}forEach(e){bi(this,e)}_write(e){e.writeTypeRef($1)}},T1=n=>new ct,Z=class n extends ct{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 ff(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`<${o}${s}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xo(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return _c(this,e)}hasAttribute(e){return Tu(this,e)}getAttributes(e){return e?Eu(this,e):Au(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),o=this.getAttributes();for(let s in o){let l=o[s];typeof l=="string"&&i.setAttribute(s,l)}return bi(this,s=>{i.appendChild(s.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(J1),e.writeKey(this.nodeName)}},E1=n=>new Z(n.readKey()),ts=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],o;return i!==void 0?o=i.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(e){e.writeTypeRef(W1),e.writeKey(this.hookName)}},D1=n=>new Si(n.readKey()),xe=class n extends lt{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 o=[];for(let s in e.attributes[i])o.push({key:s,value:e.attributes[i][s]});o.sort((s,l)=>s.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(j1)}},O1=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()}},N1=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),ru(e.doc.store,this)}write(e,t){e.writeInfo(N1),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}},I1=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}},R1=n=>new wr(n.readLen()),vu=(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(vu(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}},v1=n=>new Rn(vu(n.readString(),n.readAny())),At=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}},_1=n=>new At(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}},U1=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}},L1=n=>new Re(n.readString()),z1=[S1,k1,A1,E1,T1,D1,O1],F1=0,q1=1,H1=2,J1=3,$1=4,W1=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}},K1=n=>new Ae(z1[n.readTypeRef()](n)),wc=(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}},Uc=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},ns=(n,e,t)=>{let{client:r,clock:i}=e.id,o=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&&o.markDeleted(),e.keep&&(o.keep=!0),e.redone!==null&&(o.redone=M(e.redone.client,e.redone.clock+t)),e.right=o,o.right!==null&&(o.right.left=o),n._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),e.length=t,o},Yf=(n,e)=>Fd(n,t=>Tt(t.deletions,e)),_u=(n,e,t,r,i,o)=>{let s=n.doc,l=s.store,c=s.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)||_u(n,h,t,r,i,o)===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)||Yf(o.undoStack,d.right.id)||Yf(o.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,Uc(g,!0),g.integrate(n,0),g},O=class n extends yr{constructor(e,t,r,i,o,s,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=o,this.parent=s,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===Ct&&this.id.client!==this.parent.client&&this.parent.clock>=P(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=zf(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===Ct){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=zf(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 o=new Set,s=new Set;for(;i!==null&&i!==this.right;){if(s.add(i),o.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),qf(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?n1(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,o=this.parentSub,s=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(o===null?0:32);if(e.writeInfo(s),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===Ct?(e.writeParentInfo(!1),e.writeLeftID(l)):j();o!==null&&e.writeString(o)}this.content.write(e,t)}},Uu=(n,e)=>Y1[e&31](n),Y1=[()=>{j()},R1,V1,I1,L1,_1,U1,K1,P1,v1,()=>{j()}],G1=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(G1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Vu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Bu="__ $YJS$ __";Vu[Bu]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Vu[Bu]=!0;var Pu=new Map,Vc=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:Sf(t.newValue||"")}),lf(this._onChange)}postMessage(e){Uo.setItem(this.room,xf(bf(e)))}close(){cf(this._onChange)}},X1=typeof BroadcastChannel>"u"?Vc:BroadcastChannel,Bc=n=>$(Pu,n,()=>{let e=Ce(),t=new X1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Lu=(n,e)=>(Bc(n).subs.add(e),e),zu=(n,e)=>{let t=Bc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Pu.delete(n)),r},Vn=(n,e,t=null)=>{let r=Bc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var Fu=0,as=1,qu=2,hs=(n,e)=>{x(n,Fu);let t=Dc(e);V(n,t)},Pc=(n,e,t)=>{x(n,as),V(n,Ac(e,t))},Z1=(n,e,t)=>Pc(e,t,K(n)),Hu=(n,e,t)=>{try{Mc(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},Ju=(n,e)=>{x(n,qu),V(n,e)},eb=Hu,$u=(n,e,t,r)=>{let i=k(n);switch(i){case Fu:Z1(n,e,t);break;case as:Hu(n,t,r);break;case qu:eb(n,t,r);break;default:throw new Error("Unknown message type")}return i};var nb=0;var Wu=(n,e,t)=>{switch(k(n)){case nb:t(e,Le(n))}};var Lc=3e4,ds=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&&Lc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,o)=>{o!==this.clientID&&Lc<=t-i.lastUpdated&&this.states.has(o)&&r.push(o)}),r.length>0&&fs(this,r,"timeout")},fe(Lc/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,o=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Ne()});let s=[],l=[],c=[],a=[];e===null?a.push(t):o==null?e!=null&&s.push(t):(l.push(t),ur(o,e)||c.push(t)),(s.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:s,updated:c,removed:a},"local"]),this.emit("update",[{added:s,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},fs=(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 o=0;o{let r=q(e),i=Ne(),o=[],s=[],l=[],c=[],a=k(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:o,updated:l,removed:c},t]),(o.length>0||s.length>0||c.length>0)&&n.emit("update",[{added:o,updated:s,removed:c},t])};var Ku=n=>uf(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,Gu=3,Cr=1,sb=2,Ei=[];Ei[Bn]=(n,e,t,r,i)=>{x(n,Bn);let o=$u(e,n,t.doc,t);r&&o===as&&!t.synced&&(t.synced=!0)};Ei[Gu]=(n,e,t,r,i)=>{x(n,Cr),V(n,kr(t.awareness,Array.from(t.awareness.getStates().keys())))};Ei[Cr]=(n,e,t,r,i)=>{ju(t.awareness,K(e),t)};Ei[sb]=(n,e,t,r,i)=>{Wu(e,t.doc,(o,s)=>lb(t,s))};var Yu=3e4,lb=(n,e)=>console.warn(`Permission denied to access ${n.url}. +${e}`),Xu=(n,e,t)=>{let r=q(e),i=F(),o=k(r),s=n.messageHandlers[o];return s?s(i,r,n,t,o):console.error("Unable to compute message"),i},Qu=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=Xu(n,new Uint8Array(t.data),!0);No(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,fs(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Qu,De(Hd(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),hs(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=F();x(r,Cr),V(r,kr(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},zc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},Fc=class extends tr{constructor(e,t,r,{connect:i=!0,awareness:o=new ds(r),params:s={},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=s,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=o,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=d,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Ei.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),hs(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=Xu(this,new Uint8Array(f),!1);No(p)>1&&Vn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=F();x(p,Bn),Ju(p,f),zc(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),V(y,kr(o,g)),zc(this,I(y))},this._exitHandler=()=>{fs(this.awareness,[r.clientID],"app closed")},St&&typeof process<"u"&&process.on("exit",this._exitHandler),o.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Yu{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var cb=/[\uD800-\uDBFF]/,ab=/[\uDC00-\uDFFF]/,hb=(n,e)=>{let t=0,r=0;for(;t0&&cb.test(n[t-1])&&t--;r+t0&&ab.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},ep=hb;var v=new le("y-sync"),Et=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),db=[{light:"#ecd44433",dark:"#ecd444"}],fb=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,nf(e))}return n.get(t)},rp=(n,{colors:e=db,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:o}={})=>{let s=!1,l=new us(n,o),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),o==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(s||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(s=!0,h.addToHistory===!1&&!h.isChangeOrigin){let d=Et.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},ub=(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)}),us=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Zu(),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(),o=kt.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||o.clientWidth||0)&&i.top<=(window.innerHeight||o.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(o=>{let s=r.permanentUserData;s&&s.dss.forEach(h=>{nt(o,h,d=>{})});let l=(h,d)=>{let f=h==="added"?s.getUserByClientId(d.client):s.getUserByDeletedId(d);return{user:f,type:h,color:fb(r.colorMapping,r.colors,f)}},c=cs(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);nt(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 o=this.type.toArray().map(l=>ip(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),s=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(o),0,0));ub(s,this.beforeTransactionSelection,this),s=s.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof En}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&s.scrollIntoView(),this.prosemirrorView.dispatch(s)})}_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))}},ip=(n,e,t,r,i,o)=>{let s=t.get(n);if(s===void 0){if(n instanceof Z)return Oi(n,e,t,r,i,o);throw Oe()}return s},Oi=(n,e,t,r,i,o)=>{let s=[],l=c=>{if(c.constructor===Z){let a=ip(c,e,t,r,i,o);a!==null&&s.push(a)}else{let a=c._item.right?.content.type;a instanceof lt&&!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=pb(c,e,t,r,i,o);h!==null&&h.forEach(d=>{d!==null&&s.push(d)})}};r===void 0||i===void 0?n.toArray().forEach(l):cs(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=o?o("added",n._item.id):{type:"added"}):c.ychange=o?o("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,s);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},pb=(n,e,t,r,i,o)=>{let s=[],l=n.toDelta(r,i,o);try{for(let c=0;c{n._item.delete(a)},v),null}return s},mb=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:sp(i.marks)}));return t.applyDelta(r),e.set(t,n),t},gb=(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,ms(n).map(r=>qc(r,e))),e.set(t,n),t},qc=(n,e)=>n instanceof Array?mb(n,e):gb(n,e),tp=n=>typeof n=="object"&&n!==null,Jc=(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&&Vo(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(o=>Jc(r.attributes[o.type.name]||{},o.attrs)))},Ri=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Hc(n,e)){let t=ms(e);return n._length===t.length&&Jc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Ri(r,t[i]))}return n instanceof xe&&e instanceof Array&&op(n,e)},ps=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),np=(n,e,t)=>{let r=n.toArray(),i=ms(e),o=i.length,s=r.length,l=De(s,o),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}},wb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=yb(n),o=e.map(a=>({insert:a.text,attributes:Object.assign({},r,sp(a.marks))})),{insert:s,remove:l,index:c}=ep(i,o.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,s),n.applyDelta(o.map(a=>({retain:a.insert.length,attributes:a.attributes})))},sp=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=ms(t),o=i.length,s=e.toArray(),l=s.length,c=De(o,l),a=0,h=0;for(;a{for(;l-a-h>0&&o-a-h>0;){let f=s[a],u=i[a],p=s[l-h-1],m=i[o-h-1];if(f instanceof xe&&u instanceof Array)op(f,u)||wb(f,u,r),a+=1;else{let g=f instanceof Z&&Hc(f,u),y=p instanceof Z&&Hc(p,m);if(g&&y){let T=np(f,u,r),N=np(p,m,r);T.foundMappedChild&&!N.foundMappedChild?y=!1:!T.foundMappedChild&&N.foundMappedChild||T.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,bb=()=>{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((o,s)=>{r.setMeta(s,o)}),t.dispatch(r))})},$c=(n,e,t)=>{vi||(vi=new Map,ai(0,bb)),$(vi,n,U).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 xb(r._item.parent,r._item)}return Ci(e,e._length,-1)},xb=(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=Oc(t,n);if(i===null||i.type!==e&&!Tn(e,i.type._item))return null;let o=i.type,s=0;if(o.constructor===xe)s=i.index;else if(o._item===null||!o._item.deleted){let l=o._first,c=0;for(;ci(void 0)};return Mr(r,t,n,new Map),t}function cp(n,e="prosemirror"){return jc(n.getXmlFragment(e))}function jc(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(s=>{let l={type:"text",text:s.insert};return s.attributes&&(l.marks=Object.keys(s.attributes).map(c=>{let a=s.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let o=r.getAttributes();Object.keys(o).length&&(i.attrs=o);let s=r.toArray();s.length&&(i.content=s.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var Sb=(n,e,t)=>n!==e,kb=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},Cb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Mb=/^#[0-9a-fA-F]{6}$/,ap=(n,e,t,r,i)=>{let o=v.getState(n),s=o.doc,l=[];return o.snapshot!=null||o.prevSnapshot!=null||o.binding.mapping.size===0?z.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(s.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Mb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Yt(s,o.type,Un(c.cursor.anchor),o.binding.mapping),f=Yt(s,o.type,Un(c.cursor.head),o.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))},Ab=(n,{awarenessStateFilter:e=Sb,cursorBuilder:t=kb,selectionBuilder:r=Cb,getSelection:i=s=>s.selection}={},o="cursor")=>new H({key:Di,state:{init(s,l){return ap(l,n,e,t,r)},apply(s,l,c,a){let h=v.getState(a),d=s.getMeta(Di);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?ap(a,n,e,t,r):l.map(s.mapping,s.doc)}},props:{decorations:s=>Di.getState(s)},view:s=>{let l=()=>{s.docView&&$c(s,Di,{awarenessUpdated:!0})},c=()=>{let a=v.getState(s.state),h=n.getLocalState()||{};if(s.hasFocus()){let d=i(s.state),f=Pn(d.anchor,a.type,a.binding.mapping),u=Pn(d.head,a.type,a.binding.mapping);(h.cursor==null||!rs(Un(h.cursor.anchor),f)||!rs(Un(h.cursor.head),u))&&n.setLocalStateField(o,{anchor:f,head:u})}else h.cursor!=null&&Yt(a.doc,a.type,Un(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(o,null)};return n.on("change",l),s.dom.addEventListener("focusin",c),s.dom.addEventListener("focusout",c),{update:c,destroy:()=>{s.dom.removeEventListener("focusin",c),s.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(o,null)}}}});var Tb=n=>{let e=Et.getState(n).undoManager;if(e!=null)return e.undo(),!0},Eb=n=>{let e=Et.getState(n).undoManager;if(e!=null)return e.redo(),!0},Db=new Set(["paragraph"]),Ob=(n,e)=>!(n instanceof O)||!(n.content instanceof Ae)||!(n.content.type instanceof lt||n.content.type instanceof Z&&e.has(n.content.type.nodeName))||n.content.type._length===0,Nb=({protectedNodes:n=Db,trackedOrigins:e=[],undoManager:t=null}={})=>new H({key:Et,state:{init:(r,i)=>{let o=v.getState(i),s=t||new En(o.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Ob(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:s,prevSel:null,hasUndoOps:s.undoStack.length>0,hasRedoOps:s.redoStack.length>0}},apply:(r,i,o,s)=>{let l=v.getState(s).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ii(l,o),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),o=Et.getState(r.state).undoManager;return o.on("stack-item-added",({stackItem:s})=>{let l=i.binding;l&&s.meta.set(l,Et.getState(r.state).prevSel)}),o.on("stack-item-popped",({stackItem:s})=>{let l=i.binding;l&&(l.beforeTransactionSelection=s.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{o.destroy()}}}});var _i="http://www.w3.org/2000/svg",Ib="http://www.w3.org/1999/xlink",Kc="ProseMirror-icon";function Rb(n){let e=0;for(let t=0;t{o.preventDefault(),r.classList.contains(Dt+"-disabled")||t.run(e.state,e.dispatch,e,o)});function i(o){if(t.select){let l=t.select(o);if(r.style.display=l?"":"none",!l)return!1}let s=!0;if(t.enable&&(s=t.enable(o)||!1,hp(r,Dt+"-disabled",!s)),t.active){let l=s&&t.active(o)||!1;hp(r,Dt+"-active",l)}return!0}return{dom:r,update:i}}};function gs(n,e){return n._props.translate?n._props.translate(e):e}var Ui={time:0,node:null};function Ub(n){Ui.time=Date.now(),Ui.node=n.target}function Vb(n){return Date.now()-100{s&&s.close()&&(s=null,r.removeEventListener("mousedown",l))};i.addEventListener("mousedown",h=>{h.preventDefault(),Ub(h),s?c():(s=this.expand(o,t.dom),r.addEventListener("mousedown",l=()=>{Vb(o)||c()}))});function a(h){let d=t.update(h);return o.style.display=d?"":"none",d}return{dom:o,update:a}}expand(e,t){let r=yt("div",{class:Dt+"-dropdown-menu "+(this.options.class||"")},t),i=!1;function o(){return i?!1:(i=!0,e.removeChild(r),!0)}return e.appendChild(r),{close:o,node:r}}};function Bb(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iWr(n),icon:Vi.join}),Fk=new at({title:"Lift out of enclosing block",run:jr,select:n=>jr(n),icon:Vi.lift}),qk=new at({title:"Select parent node",run:Kr,select:n=>Kr(n),icon:Vi.selectParentNode}),Hk=new at({title:"Undo last change",run:Xr,enable:n=>Xr(n),icon:Vi.undo}),Jk=new at({title:"Redo last undone change",run:Qn,enable:n=>Qn(n),icon:Vi.redo});function zb(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 at(t)}function Fb(n,e){let t=pn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:o,to:s,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):s<=o.end()&&o.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new at(r)}function hp(n,e,t){t?n.classList.add(e):n.classList.remove(e)}export{zn as DOMParser,It as DOMSerializer,Yc as Dropdown,Bs as EditorState,sl as EditorView,w as Fragment,wt as InputRule,at as MenuItem,H as Plugin,le as PluginKey,Dr as Schema,b as Slice,A as TextSelection,Fc as WebsocketProvider,Sr as Y,L0 as addColumnAfter,P0 as addColumnBefore,fy as addListNodes,s0 as addRowAfter,o0 as addRowBefore,cd as baseKeymap,Fg as baseSchema,Fb as blockTypeItem,Ly as buildKeymap,T0 as columnResizing,r0 as deleteColumn,c0 as deleteRow,g0 as deleteTable,Id as fixTables,Ny as gapCursor,m0 as goToNextCell,pd as inputRules,He as isInTable,Sy as keymap,bl as liftListItem,h0 as mergeCells,lp as prosemirrorToYDoc,Wc as prosemirrorToYXmlFragment,Pb as renderGrouped,Je as selectedRect,pn as setBlockType,xl as sinkListItem,d0 as splitCell,wl as splitListItem,B0 as tableEditing,Jy as tableNodes,mn as toggleMark,Xn as wrapIn,uo as wrapInList,zb as wrapItem,Ab as yCursorPlugin,cp as yDocToProsemirrorJSON,Eb as yRedo,rp as ySyncPlugin,Tb as yUndo,Nb as yUndoPlugin,Et as yUndoPluginKey,jc as yXmlFragmentToProsemirrorJSON}; diff --git a/deps/da-y-wrapper/src/index.js b/deps/da-y-wrapper/src/index.js index 8ecd8bb8..7192926a 100644 --- a/deps/da-y-wrapper/src/index.js +++ b/deps/da-y-wrapper/src/index.js @@ -9,6 +9,7 @@ import { keymap } from 'prosemirror-keymap'; import { buildKeymap } from 'prosemirror-example-setup'; import { gapCursor } from 'prosemirror-gapcursor'; + import { tableEditing, columnResizing, @@ -16,8 +17,6 @@ import { selectedRect, tableNodes, fixTables, - addColumnAfter, - addColumnBefore, deleteColumn, addRowAfter, addRowBefore, @@ -26,8 +25,8 @@ import { splitCell, deleteTable, isInTable, - TableMap, } from 'prosemirror-tables'; +import { addColumnAfterWrapper, addColumnBeforeWrapper } from './table-wrappers.js'; // yjs import * as Y from 'yjs'; @@ -49,134 +48,6 @@ import { MenuItem, Dropdown, renderGrouped, blockTypeItem, wrapItem } from '../. import { InputRule, inputRules } from 'prosemirror-inputrules'; -/** - * Fix the block header to ensure it maintains a single cell with full colspan. - */ -function fixHeaderRowColspan(tr, tableStart, table) { - const firstRow = table.child(0); - const map = TableMap.get(table); - const totalCols = map.width; - - if (firstRow.childCount === 1 && firstRow.child(0).attrs.colspan === totalCols) { - return tr; - } - - if (firstRow.childCount > 1) { - const contents = []; - let firstCellPos = null; - - firstRow.forEach((cell, offset, index) => { - if (index === 0) { - firstCellPos = tableStart + 1; - } - - if (cell.textContent) { - contents.push(cell.textContent); - } - }); - - const blockName = contents[0] || 'columns'; - - // Create a new cell with the correct colspan - const cellType = firstRow.child(0).type; - const para = tr.doc.type.schema.nodes.paragraph.create( - null, - tr.doc.type.schema.text(blockName), - ); - const newCell = cellType.create( - { colspan: totalCols, rowspan: 1 }, - para, - ); - - // Create new row with single merged cell - const rowType = tr.doc.type.schema.nodes.table_row; - const newRow = rowType.create(null, newCell); - - // Replace the entire first row - const firstRowEnd = firstCellPos + firstRow.nodeSize - 1; - tr.replaceWith(firstCellPos, firstRowEnd, newRow); - } else if (firstRow.childCount === 1) { - const cellPos = tableStart + 1; - const cell = firstRow.child(0); - tr.setNodeMarkup(cellPos, null, { - ...cell.attrs, - colspan: totalCols, - rowspan: 1, - }); - } - - return tr; -} - -/** - * Find the table node that contains a resolved position - */ -function findTableFromPos($pos) { - for (let d = $pos.depth; d > 0; d -= 1) { - const node = $pos.node(d); - if (node.type.name === 'table') { - const tableStart = $pos.start(d) - 1; // Position before the table - return { table: node, tableStart, depth: d }; - } - } - return null; -} - -// ensures header row maintains its colspan when adding columns -function addColumnBeforeWrapper(state, dispatch) { - if (!dispatch) { - return addColumnBefore(state, dispatch); - } - - const originalPos = state.selection.$from.pos; - - const result = addColumnBefore(state, (tr) => { - try { - const $pos = tr.doc.resolve(originalPos); - const tableInfo = findTableFromPos($pos); - if (tableInfo) { - const updatedTable = tr.doc.nodeAt(tableInfo.tableStart); - if (updatedTable) { - fixHeaderRowColspan(tr, tableInfo.tableStart, updatedTable); - } - } - } catch (e) { - // eslint-disable-next-line no-console - console.warn('Could not fix header row colspan:', e); - } - dispatch(tr); - }); - - return result; -} - -// ensures header row maintains its colspan when adding columns -function addColumnAfterWrapper(state, dispatch) { - if (!dispatch) { - return addColumnAfter(state, dispatch); - } - - const originalPos = state.selection.$from.pos; - const result = addColumnAfter(state, (tr) => { - try { - const $pos = tr.doc.resolve(originalPos); - const tableInfo = findTableFromPos($pos); - if (tableInfo) { - const updatedTable = tr.doc.nodeAt(tableInfo.tableStart); - if (updatedTable) { - fixHeaderRowColspan(tr, tableInfo.tableStart, updatedTable); - } - } - } catch (e) { - // eslint-disable-next-line no-console - console.warn('Could not fix header row colspan:', e); - } - dispatch(tr); - }); - - return result; -} - // All exported export { EditorView, diff --git a/deps/da-y-wrapper/src/table-wrappers.js b/deps/da-y-wrapper/src/table-wrappers.js new file mode 100644 index 00000000..8f5e92d8 --- /dev/null +++ b/deps/da-y-wrapper/src/table-wrappers.js @@ -0,0 +1,133 @@ +import { + addColumnAfter, + addColumnBefore, + TableMap, +} from 'prosemirror-tables'; + +/** + * Fix the block header to ensure it maintains a single cell with full colspan. + */ +function fixHeaderRowColspan(tr, tableStart, table) { + const firstRow = table.child(0); + const map = TableMap.get(table); + const totalCols = map.width; + + if (firstRow.childCount === 1 && firstRow.child(0).attrs.colspan === totalCols) { + return tr; + } + + if (firstRow.childCount > 1) { + const contents = []; + let firstCellPos = null; + + firstRow.forEach((cell, offset, index) => { + if (index === 0) { + firstCellPos = tableStart + 1; + } + + if (cell.textContent) { + contents.push(cell.textContent); + } + }); + + const blockName = contents[0] || 'columns'; + + // Create a new cell with the correct colspan + const cellType = firstRow.child(0).type; + const para = tr.doc.type.schema.nodes.paragraph.create( + null, + tr.doc.type.schema.text(blockName), + ); + const newCell = cellType.create( + { colspan: totalCols, rowspan: 1 }, + para, + ); + + // Create new row with single merged cell + const rowType = tr.doc.type.schema.nodes.table_row; + const newRow = rowType.create(null, newCell); + + // Replace the entire first row + const firstRowEnd = firstCellPos + firstRow.nodeSize - 1; + tr.replaceWith(firstCellPos, firstRowEnd, newRow); + } else if (firstRow.childCount === 1) { + const cellPos = tableStart + 1; + const cell = firstRow.child(0); + tr.setNodeMarkup(cellPos, null, { + ...cell.attrs, + colspan: totalCols, + rowspan: 1, + }); + } + + return tr; +} + +/** + * Find the table node that contains a resolved position + */ +function findTableFromPos($pos) { + for (let d = $pos.depth; d > 0; d -= 1) { + const node = $pos.node(d); + if (node.type.name === 'table') { + const tableStart = $pos.start(d) - 1; // Position before the table + return { table: node, tableStart, depth: d }; + } + } + return null; +} + +// ensures header row maintains its colspan when adding columns +export function addColumnBeforeWrapper(state, dispatch) { + if (!dispatch) { + return addColumnBefore(state, dispatch); + } + + const originalPos = state.selection.$from.pos; + + const result = addColumnBefore(state, (tr) => { + try { + const $pos = tr.doc.resolve(originalPos); + const tableInfo = findTableFromPos($pos); + if (tableInfo) { + const updatedTable = tr.doc.nodeAt(tableInfo.tableStart); + if (updatedTable) { + fixHeaderRowColspan(tr, tableInfo.tableStart, updatedTable); + } + } + } catch (e) { + // eslint-disable-next-line no-console + console.warn('Could not fix header row colspan:', e); + } + dispatch(tr); + }); + + return result; +} + +// ensures header row maintains its colspan when adding columns +export function addColumnAfterWrapper(state, dispatch) { + if (!dispatch) { + return addColumnAfter(state, dispatch); + } + + const originalPos = state.selection.$from.pos; + const result = addColumnAfter(state, (tr) => { + try { + const $pos = tr.doc.resolve(originalPos); + const tableInfo = findTableFromPos($pos); + if (tableInfo) { + const updatedTable = tr.doc.nodeAt(tableInfo.tableStart); + if (updatedTable) { + fixHeaderRowColspan(tr, tableInfo.tableStart, updatedTable); + } + } + } catch (e) { + // eslint-disable-next-line no-console + console.warn('Could not fix header row colspan:', e); + } + dispatch(tr); + }); + + return result; +} From 891515431b932fa297b1fad26334db687d568334 Mon Sep 17 00:00:00 2001 From: Cursor AI Date: Thu, 13 Nov 2025 16:18:31 -0800 Subject: [PATCH 7/7] modify to use a plugin rather than wrapping the prose addCol functions. Should be a cleaner approach Signed-off-by: Sean Steimer --- blocks/edit/prose/index.js | 2 + blocks/edit/prose/plugins/tableHeaderFix.js | 67 +++++++++ deps/da-y-wrapper/dist/index.js | 24 ++-- deps/da-y-wrapper/src/index.js | 10 +- deps/da-y-wrapper/src/table-wrappers.js | 133 ------------------ .../edit/prose/table-modifications.test.js | 54 ++++++- 6 files changed, 137 insertions(+), 153 deletions(-) create mode 100644 blocks/edit/prose/plugins/tableHeaderFix.js delete mode 100644 deps/da-y-wrapper/src/table-wrappers.js 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 e7157a4f..3b3d4006 100644 --- a/deps/da-y-wrapper/dist/index.js +++ b/deps/da-y-wrapper/dist/index.js @@ -1,13 +1,13 @@ -var up=Object.defineProperty;var pp=(n,e)=>{for(var t in e)up(n,t,{get:e[t],enumerable:!0})};function se(n){this.content=n}se.prototype={constructor:se,find:function(n){for(var e=0;e>1}};se.from=function(n){if(n instanceof se)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new se(e)};var ys=se;function oa(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=oa(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function sa(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),c=s.nodeSize;if(s==l){t-=c,r-=c;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let a=0,h=Math.min(s.text.length,l.text.length);for(;ae&&r(c,i+l,o||null,s)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=a},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,o)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let o=this.child(r),s=i+o.nodeSize;if(s>=e)return s==e||t>0?Pi(r+1,s):Pi(r,i);i=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var Qt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=ca(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(la(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function la(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(la(o.content,e-i-1,t-i-1)))}function ca(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=ca(s.content,e-o-1,t);return l&&n.replaceChild(i,s.copy(l))}function mp(n,e,t){if(t.openStart>n.depth)throw new Qt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Qt("Inconsistent open depths");return aa(n,e,t,0)}function aa(n,e,t,r){let i=n.index(r),o=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Ar(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(Gt(n.nodeAfter,r),o++));for(let l=o;li&&xs(n,e,i+1),s=r.depth>i&&xs(t,r,i+1),l=[];return Ar(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(ha(o,s),Gt(Xt(o,da(n,e,t,r,i+1)),l)):(o&&Gt(Xt(o,Fi(n,e,i+1)),l),Ar(e,t,i,l),s&&Gt(Xt(s,Fi(t,r,i+1)),l)),Ar(r,null,i,l),new w(l)}function Fi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=xs(n,e,t+1);Gt(Xt(i,Fi(n,e,t+1)),r)}return Ar(e,null,t,r),new w(r)}function gp(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var qi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let o=0;o0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Zt(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,o=t;for(let s=e;;){let{index:l,offset:c}=s.content.findIndex(o),a=o-c;if(r.push(s,l,i+c),!a||(s=s.child(l),s.isText))break;o=a-1,i+=c+1}return new n(t,r,o)}static resolveCached(e,t){let r=Gc.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,t,o=>(r.isInSet(o.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),fa(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,i,r);return o.type.checkAttrs(o.attrs),o}};je.prototype.text=void 0;var ks=class n extends je{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):fa(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function fa(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var en=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Cs(e,t);if(r.next==null)return n.empty;let i=ua(r);r.next&&r.err("Unexpected trailing text");let o=Ap(Mp(i));return Tp(o,r),o}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` -`)}};en.empty=new en(!0);var Cs=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function ua(n){let e=[];do e.push(bp(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function bp(n){let e=[];do e.push(xp(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function xp(n){let e=Cp(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=Sp(n,e);else break;return e}function Xc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function Sp(n,e){let t=Xc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Xc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function kp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.isInGroup(e)&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function Cp(n){if(n.eat("(")){let e=ua(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=kp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Mp(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,c){let a={term:c,to:l};return e[s].push(a),a}function i(s,l){s.forEach(c=>c.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((c,a)=>c.concat(o(a,l)),[]);if(s.type=="seq")for(let c=0;;c++){let a=o(s.exprs[c],l);if(c==s.exprs.length-1)return a;i(a,l=t())}else if(s.type=="star"){let c=t();return r(l,c),i(o(s.expr,c),c),[r(c)]}else if(s.type=="plus"){let c=t();return i(o(s.expr,l),c),i(o(s.expr,c),c),[r(c)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let c=l;for(let a=0;a{n[s].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let o=e[r.join(",")]=new en(r.indexOf(n.length-1)>-1);for(let s=0;s-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ga(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new je(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new je(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let s=this.contentMatch.fillBefore(t);if(!s)return null;t=s.append(t)}let i=this.contentMatch.matchFragment(t),o=i&&i.fillBefore(w.empty,!0);return o?new je(this,e,t.append(o),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new n(o,t,s));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Ep(n,e,t){let r=t.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}var Ms=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Ep(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Er=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=wa(e,i.attrs),this.excluded=null;let o=ma(this.attrs);this.instance=o?new D(this,o):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ga(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new n(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}},Dr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=ys.from(e.nodes),t.marks=ys.from(e.marks||{}),this.nodes=Hi.compile(this.spec.nodes,this),this.marks=Er.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=en.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?Zc(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:Zc(this,s.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Hi){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new ks(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return je.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Zc(n,e){let t=[];for(let r=0;r-1)&&t.push(s=c)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Dp(n){return n.tag!=null}function Op(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Dp(i))this.tags.push(i);else if(Op(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new Wi(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Wi(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(s.getAttrs){let c=s.getAttrs(t);if(c===!1)continue;s.attrs=c||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=ta(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=ta(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},ba={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Np={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},xa={ol:!0,ul:!0},Ji=1,$i=2,Tr=4;function ea(n,e,t){return e!=null?(e?Ji:0)|(e==="full"?$i:0):n&&n.whitespace=="pre"?Ji|$i:t&~Tr}var Ln=class{constructor(e,t,r,i,o,s){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=D.none,this.match=o||(s&Tr?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ji)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!ba.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Wi=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,o,s=ea(null,t.preserveWhitespace,0)|(r?Tr:0);i?o=new Ln(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,s):r?o=new Ln(null,null,D.none,!0,null,s):o=new Ln(e.schema.topNodeType,null,D.none,!0,null,s),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&$i||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Ji)i.options&$i?r=r.replace(/\r\n?/g,` -`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],s=e.previousSibling;(!o||s&&s.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),o;xa.hasOwnProperty(i)&&this.parser.normalizeLists&&Ip(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,r));if(s?s.ignore:Np.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let l,c=this.top,a=this.needsBlock;if(ba.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=s&&s.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,s,l,s.consuming===!1?o:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let o,s;if(t.node)if(s=this.parser.schema.nodes[t.node],s.isLeaf)this.insertNode(s.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(s,t.attrs||null,r,t.preserveWhitespace);c&&(o=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}o&&this.sync(l)&&this.open--}addAll(e,t,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];s!=l;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,t);this.findAtPoint(e,o)}findPlace(e,t){let r,i;for(let o=this.open;o>=0;o--){let s=this.nodes[o],l=s.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=s,!l.length)||s.solid)break}if(!r)return null;this.sync(i);for(let o=0;o(s.type?s.type.allowsMarkType(a.type):na(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Ln(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=o;c--)if(s(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=o?r.node(c-o).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Ip(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&xa.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Rp(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function ta(n){let e={};for(let t in n)e[t]=n[t];return e}function na(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let c=0;c{if(o.length||s.marks.length){let l=0,c=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Li(bs(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Li(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=ra(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return ra(e.marks)}};function ra(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function bs(n){return n.document||window.document}var ia=new WeakMap;function vp(n){let e=ia.get(n);return e===void 0&&ia.set(n,e=_p(n)),e}function _p(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(t=i.slice(0,s),i=i.slice(s+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let d in a)if(a[d]!=null){let f=d.indexOf(" ");f>0?c.setAttributeNS(d.slice(0,f),d.slice(f+1),a[d]):c.setAttribute(d,a[d])}}for(let d=h;dh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=Li(n,f,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var Ca=65535,Ma=Math.pow(2,16);function Vp(n,e){return n+e*Ma}function Sa(n){return n&Ca}function Bp(n){return(n-(n&Ca))/Ma}var Aa=1,Ta=2,ji=4,Ea=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Ea)>0}get deletedBefore(){return(this.delInfo&(Aa|ji))>0}get deletedAfter(){return(this.delInfo&(Ta|ji))>0}get deletedAcross(){return(this.delInfo&ji)>0}},dt=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=Sa(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+o],h=this.ranges[l+s],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:Vp(l/3,e-c),m=e==c?Ta:e==d?Aa:ji;return(t<0?e!=c:e!=d)&&(m|=Ea),new Ir(u,m,p)}i+=h-a}return r?e+i:new Ir(e+i,0,null)}touches(e,t){let r=0,i=Sa(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+o],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+s]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&c!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,o)}invert(){return new tn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("addMark",vr);var tn=class n extends G{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(Ns(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,r)}invert(){return new vr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("removeMark",tn);var _r=class n extends G{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};G.jsonID("replaceAround",X);function Ds(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Pp(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),o.forEach(c=>n.step(c))}function Lp(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let c=null;if(r instanceof Er){let a=s.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(s.marks)&&(c=[r]):c=s.marks;if(c&&c.length){let a=Math.min(l+s.nodeSize,t);for(let h=0;hn.step(new tn(s.from,s.to,s.style)))}function Is(n,e,t,r=t.contentMatch,i=!0){let o=n.doc.nodeAt(e),s=[],l=e+1;for(let c=0;c=0;c--)n.step(s[c])}function zp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),d++):c--;let f=w.empty,u=0;for(let p=o,m=!1;p>t;p--)m||i.after(p+1)=0;s--){if(r.size){let l=t[s].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=w.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new X(i,o,i,o,new b(r,0,0),t.length,!0))}function $p(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{let c=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,c)&&Wp(n.doc,n.mapping.slice(o).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Oa(n,s,l,o),Is(n,n.mapping.slice(o).map(l,1),r,void 0,a===null);let h=n.mapping.slice(o),d=h.map(l,1),f=h.map(l+s.nodeSize,1);return n.step(new X(d,f,d+1,f-1,new b(w.from(r.create(c,null,s.marks)),0,0),1,!0)),a===!0&&Da(n,s,l,o),!1}})}function Da(n,e,t,r){e.forEach((i,o)=>{if(i.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+o+s.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Oa(n,e,t,r){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let s=n.mapping.slice(r).map(t+1+o);n.replaceWith(s,s+1,e.type.schema.text(` -`))}})}function Wp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function jp(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new X(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new b(w.from(s),0,0),1,!0))}function Rt(n,e,t=1,r){let i=n.resolve(e),o=i.depth-t,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>o;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(o),c=r&&r[0];return i.node(o).canReplaceWith(l,l,c?c.type:i.node(o+1).type)}function Kp(n,e,t=1,r){let i=n.doc.resolve(e),o=w.empty,s=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){o=w.from(i.node(l).copy(o));let h=r&&r[a];s=w.from(h?h.type.create(h.attrs,s):i.node(l).copy(s))}n.step(new Te(e,e,new b(o.append(s),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Na(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Yp(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(o=r.node(i+1),l++,s=r.node(i).maybeChild(l)):(o=r.node(i).maybeChild(l-1),s=r.node(i+1)),o&&!o.isTextblock&&Na(o,s)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function Gp(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,o=n.doc.resolve(e-t),s=o.node().type;if(i&&s.inlineContent){let h=s.whitespace=="pre",d=!!s.contentMatch.matchType(i);h&&!d?r=!1:!h&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Oa(n,h.node(),h.before(),l)}s.inlineContent&&Is(n,e+t-1,s,o.node().contentMatchAt(o.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Te(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);Da(n,h.node(),h.before(),n.steps.length)}return n}function Xp(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,c=r.index(s)+(l>0?1:0),a=r.node(s),h=!1;if(o==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function Xi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return Ra(i,o,r)?new Te(e,t,r):new Os(i,o,r).fit()}function Ra(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Os=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let c=new b(o,s,l);return e>-1?new X(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Te(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=Ts(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(s?a.matchType(s.type)||(d=a.fillBefore(w.from(s),!1)):o&&c.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:d};if(t==2&&s&&(h=a.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:h};if(o&&a.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ts(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Ts(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new b(Or(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new b(Or(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(va(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Nr(this.placed,t,w.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:c,type:a}=this.frontier[l],h=Es(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Nr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Nr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Nr(this.placed,this.frontier.length,t))}};function Or(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Or(n.firstChild.content,e-1,t)))}function Nr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Nr(n.lastChild.content,e-1,t)))}function Ts(n,e){for(let t=0;t1&&(r=r.replaceChild(0,va(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function Es(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!Qp(t,o.content,s)?l:null}function Qp(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;s.indexOf(f)>-1?l=f:i.before(f)==u&&s.splice(1,0,-f)}let c=s.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=Zp(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=s[f];u<0||(e=i.before(u),t=o.after(u))}}function _a(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(w.empty,!0))}return n}function tm(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Xp(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function nm(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=Ua(r,i);for(let s=0;s0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return n.delete(r.before(s),t);n.delete(e,t)}function Ua(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}var Ki=class n extends G{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return dt.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};G.jsonID("attr",Ki);var Yi=class n extends G{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ee.ok(r)}getMap(){return dt.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};G.jsonID("docAttr",Yi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Rr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Xi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return em(this,e,t,r),this}replaceRangeWith(e,t,r){return tm(this,e,t,r),this}deleteRange(e,t){return nm(this,e,t),this}lift(e,t){return Fp(this,e,t),this}join(e,t=1){return Gp(this,e,t),this}wrap(e,t){return Jp(this,e,t),this}setBlockType(e,t=e,r,i=null){return $p(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return jp(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Ki(e,t,r)),this}setDocAttribute(e,t){return this.step(new Yi(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Ur(e,t)),this}split(e,t=1,r){return Kp(this,e,t,r),this}addMark(e,t,r){return Pp(this,e,t,r),this}removeMark(e,t,r){return Lp(this,e,t,r),this}clearIncompatible(e,t,r){return Is(this,e,t,r),this}};var vs=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new vt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;o--){let s=t<0?Hn(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Hn(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Ee(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Ee(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Ee(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=vs[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in vs)throw new RangeError("Duplicate use of selection JSON ID "+e);return vs[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var vt=class{constructor(e,t){this.$from=e,this.$to=t}},Va=!1;function Ba(n){!Va&&!n.parent.inlineContent&&(Va=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Ba(e),Ba(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let o=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(o)t=o.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&C.isSelectable(l))return C.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,o);if(c)return c}t+=l.nodeSize*i}return null}function Pa(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=h)}),n.setSelection(S.near(n.doc.resolve(s),t))}var La=1,Qi=2,za=4,Vs=class extends qn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Qi,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Qi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Qi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=za,this}get scrolledIntoView(){return(this.updated&za)>0}};function Fa(n,e){return!e||!n?n:n.bind(e)}var on=class{constructor(e,t,r){this.name=e,this.init=Fa(t.init,r),this.apply=Fa(t.apply,r)}},im=[new on("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new on("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new on("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new on("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Vr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=im.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new on(r.key,r.spec.state,r))})}},Bs=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],o=i.spec.state;o&&o.toJSON&&(t[r]=o.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Vr(e.schema,e.plugins),o=new n(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=je.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=S.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==s.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=a.fromJSON.call(c,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}};function qa(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=qa(i,e,{})),t[r]=i}return t}var H=class{constructor(e){this.spec=e,this.props={},e.props&&qa(e.props,this,this.props),this.key=e.key?e.key.key:Ha("plugin")}getState(e){return e[this.key]}},_s=Object.create(null);function Ha(n){return n in _s?n+"$"+ ++_s[n]:(_s[n]=0,n+"$")}var le=class{constructor(e="key"){this.key=Ha(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var te=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},zr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},qs=null,ut=function(n,e,t){let r=qs||(qs=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},om=function(){qs=null},fn=function(n,e,t,r){return t&&(Ja(n,e,t,r,-1)||Ja(n,e,t,r,1))},sm=/^(img|br|input|textarea|hr)$/i;function Ja(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:_e(n))){let o=n.parentNode;if(!o||o.nodeType!=1||Jr(n)||sm.test(n.nodeName)||n.contentEditable=="false")return!1;e=te(n)+(i<0?0:1),n=o}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?_e(n):0}else return!1}}function _e(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function lm(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=_e(n)}else if(n.parentNode&&!Jr(n))e=te(n),n=n.parentNode;else return null}}function cm(n,e){for(;;){if(n.nodeType==3&&e2),ve=Kn||(Ke?/Mac/.test(Ke.platform):!1),fm=Ke?/Win/.test(Ke.platform):!1,Fe=/Android \d/.test(Lt),$r=!!$a&&"webkitFontSmoothing"in $a.documentElement.style,um=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function pm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ft(n,e){return typeof n=="number"?n:n[e]}function mm(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Wa(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;s=zr(s)){if(s.nodeType!=1)continue;let l=s,c=l==o.body,a=c?pm(o):mm(l),h=0,d=0;if(e.topa.bottom-ft(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+ft(i,"top")-a.top:e.bottom-a.bottom+ft(i,"bottom")),e.lefta.right-ft(r,"right")&&(h=e.right-a.right+ft(i,"right")),h||d)if(c)o.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(s).position))break}}function gm(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:Ah(n.dom)}}function Ah(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=zr(r));return e}function ym({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Th(t,r==0?0:r-e)}function Th(n,e){for(let t=0;t=l){s=Math.max(p.bottom,s),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(o=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?bm(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:Eh(t,i)}function bm(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function ll(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function xm(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function km(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!s&&c.left>r.left||c.top>r.top?i=l.posBefore:(!s&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Dh(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;$r&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=km(n,r,i,e))}l==null&&(l=Sm(n,s,e));let c=n.docView.nearestDesc(s,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function ja(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Br(_t(ut(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Ps(c.getBoundingClientRect(),!1)}if(o==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return Ps(c.getBoundingClientRect(),!0)}return Ps(r.getBoundingClientRect(),t>=0)}if(o==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?ut(c,_e(c)-(s?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Br(_t(a,1),!1)}if(o==null&&i<_e(r)){let c=r.childNodes[i];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let a=c?c.nodeType==3?ut(c,0,s?0:1):c.nodeType==1?c:null:null;if(a)return Br(_t(a,-1),!0)}return Br(_t(r.nodeType==3?ut(r):r,-t),t>=0)}function Br(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Ps(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Nh(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function Am(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Nh(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Oh(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=ut(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?s.top-h.top>(h.bottom-s.top)*2:h.bottom-s.bottom>(s.bottom-h.top)*2))return!1}}return!0})}var Tm=/[\u0590-\u08ac]/;function Em(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!Tm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Nh(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}var Ka=null,Ya=null,Ga=!1;function Dm(n,e,t){return Ka==e&&Ya==t?Ga:(Ka=e,Ya=t,Ga=t=="up"||t=="down"?Am(n,e,t):Em(n,e,t))}var Ue=0,Xa=1,ln=2,Ye=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Ue,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tte(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof no){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof eo&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?te(o.dom)+1:0}}else{let o,s=!0;for(;o=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=s;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=te(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&st){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+o.border,c=s-o.border;if(e>=l&&t<=c){this.dirty=e==r||t==s?ln:Xa,e==l&&t==c&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Ye:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?ln:Ye}r=s}this.dirty=ln}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?ln:Xa;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=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}},Ws=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 o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=It.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new n(e,t,s.dom,s.contentDOM||s.dom)}parseRule(){return this.dirty&Ye||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Ye&&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&&(o=Gs(o,0,e,r));for(let l=0;l{if(!c)return s;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=vh(h,r,t),a?c=new js(e,t,r,i,h,d||null,f,a,o,s+1):t.isText?new to(e,t,r,i,h,f,o):new n(e,t,r,i,h,d||null,f,o,s+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)&&ro(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,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,c=new Ys(this,s&&s.node,e);Rm(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)&&(s&&this.protectLocalComposition(e,s),Ih(this.contentDOM,this.children,e),Kn&&vm(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 o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=_m(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new Ws(this,o,t,i);e.input.compositionNodes.push(s),this.children=Gs(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==Ye||!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(ro(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Rh(this.dom,this.nodeDOM,Ks(this.outerDeco,this.node,t),Ks(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 Qa(n,e,t,r,i){vh(r,e,n);let o=new Pt(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}var to=class n extends Pt{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,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==Ye||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),o=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Ye)}get domAtom(){return!1}isText(e){return this.node.text==e}},no=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"}},js=class extends Pt{constructor(e,t,r,i,o,s,l,c,a,h){super(e,t,r,i,o,s,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==Ye)return!1;if(this.spec.update){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}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 Ih(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,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[o],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,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,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Im(n,e){return n.type.side-e.type.side}function Rm(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let a=0;ao;)l.push(i[s++]);let p=o+f.nodeSize;if(f.isText){let g=p;s!g.inline):l.slice();r(f,m,e.forChild(o,f),u),o=p}}function vm(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 _m(n,e,t,r){for(let i=0,o=0;i=t){if(o>=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 Gs(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||h<=e?o.push(c):(at&&o.push(c.slice(t-a,c.size,r)))}return o}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),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),c,a;if(ho(t)){for(c=s;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&C.isSelectable(d)&&i.parent&&!(d.isInline&&am(t.focusNode,t.focusOffset,i.dom))){let f=i.posBefore;a=new C(s==f?l:r.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=s,f=s;for(let u=0;u{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!_h(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 Uh(n,e){if(e instanceof C){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(rh(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else rh(n)}function rh(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 ih(n){return n.editable&&!n.hasFocus()?!1:Vh(n)}function Vh(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 Bm(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 Xs(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&S.findFrom(o,e)}function Ut(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function oh(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return Ut(n,new A(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Xs(n.state,e);return i&&i instanceof C?Ut(n,i):!1}else if(!(ve&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?C.isSelectable(o)?Ut(n,new C(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):$r?Ut(n,new A(n.state.doc.resolve(e<0?l:l+o.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=Xs(n.state,e);return i?Ut(n,i):!1}}}function io(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?Pm(n):Lm(n)}function Pm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(qe&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Lr(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Bh(t))break;{let l=t.previousSibling;for(;l&&Lr(l,-1);)i=t.parentNode,o=te(l),l=l.previousSibling;if(l)t=l,r=io(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?Qs(n,t,r):i&&Qs(n,i,o)}function Lm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=io(t),o,s;for(;;)if(r{n.state==i&&pt(n)},50)}function sh(n,e){let t=n.state.doc.resolve(e);if(!(ae||fm)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function lh(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:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Xs(n.state,e);if(s&&s instanceof C)return Ut(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof Ee?S.near(s,e):S.findFrom(s,e);return l?Ut(n,l):!1}return!1}function ch(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 o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function ah(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function qm(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;ah(n,r,"true"),setTimeout(()=>ah(n,r,"false"),20)}return!1}function Hm(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Jm(n,e){let t=e.keyCode,r=Hm(e);if(t==8||ve&&t==72&&r=="c")return ch(n,-1)||$n(n,-1);if(t==46&&!e.shiftKey||ve&&t==68&&r=="c")return ch(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 oh(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 oh(n,i,r)||$n(n,i)}else{if(t==38||ve&&t==80&&r=="c")return lh(n,-1,r)||$n(n,-1);if(t==40||ve&&t==78&&r=="c")return qm(n)||lh(n,1,r)||$n(n,1);if(r==(ve?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Ph(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let s=n.someProp("clipboardSerializer")||It.fromSchema(n.state.schema),l=Jh(),c=l.createElement("div");c.appendChild(s.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=Hh[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} ${o}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,` +var hp=Object.defineProperty;var dp=(n,e)=>{for(var t in e)hp(n,t,{get:e[t],enumerable:!0})};function oe(n){this.content=n}oe.prototype={constructor:oe,find:function(n){for(var e=0;e>1}};oe.from=function(n){if(n instanceof oe)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new oe(e)};var yo=oe;function ia(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=ia(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function sa(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),c=o.nodeSize;if(o==l){t-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let a=0,h=Math.min(o.text.length,l.text.length);for(;ae&&r(c,i+l,s||null,o)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=a},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?Pi(r+1,o):Pi(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var Qt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=la(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(oa(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(w.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};b.empty=new b(w.empty,0,0);function oa(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(oa(s.content,e-i-1,t-i-1)))}function la(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=la(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function fp(n,e,t){if(t.openStart>n.depth)throw new Qt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Qt("Inconsistent open depths");return ca(n,e,t,0)}function ca(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Ar(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(Gt(n.nodeAfter,r),s++));for(let l=s;li&&xo(n,e,i+1),o=r.depth>i&&xo(t,r,i+1),l=[];return Ar(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(aa(s,o),Gt(Xt(s,ha(n,e,t,r,i+1)),l)):(s&&Gt(Xt(s,Fi(n,e,i+1)),l),Ar(e,t,i,l),o&&Gt(Xt(o,Fi(t,r,i+1)),l)),Ar(r,null,i,l),new w(l)}function Fi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=xo(n,e,t+1);Gt(Xt(i,Fi(n,e,t+1)),r)}return Ar(e,null,t,r),new w(r)}function up(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(w.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var qi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Zt(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:c}=o.content.findIndex(s),a=s-c;if(r.push(o,l,i+c),!a||(o=o.child(l),o.isText))break;s=a-1,i+=c+1}return new n(t,r,s)}static resolveCached(e,t){let r=Yc.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),da(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=w.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=w.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Ke.prototype.text=void 0;var ko=class n extends Ke{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):da(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function da(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var en=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Co(e,t);if(r.next==null)return n.empty;let i=fa(r);r.next&&r.err("Unexpected trailing text");let s=kp(Sp(i));return Cp(s,r),s}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(` +`)}};en.empty=new en(!0);var Co=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function fa(n){let e=[];do e.push(gp(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function gp(n){let e=[];do e.push(yp(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function yp(n){let e=xp(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=wp(n,e);else break;return e}function Gc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function wp(n,e){let t=Gc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Gc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function bp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function xp(n){if(n.eat("(")){let e=fa(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=bp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Sp(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,c){let a={term:c,to:l};return e[o].push(a),a}function i(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,a)=>c.concat(s(a,l)),[]);if(o.type=="seq")for(let c=0;;c++){let a=s(o.exprs[c],l);if(c==o.exprs.length-1)return a;i(a,l=t())}else if(o.type=="star"){let c=t();return r(l,c),i(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=t();return i(s(o.expr,l),c),i(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let a=0;a{n[o].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let s=e[r.join(",")]=new en(r.indexOf(n.length-1)>-1);for(let o=0;o-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ma(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ke(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new Ke(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=w.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(w.empty,!0);return s?new Ke(this,e,t.append(s),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new n(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Mp(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}var Mo=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Mp(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},Tr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=ya(e,i.attrs),this.excluded=null;let s=pa(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ma(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},Dr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=yo.from(e.nodes),t.marks=yo.from(e.marks||{}),this.nodes=Hi.compile(this.spec.nodes,this),this.marks=Tr.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=en.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?Qc(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Qc(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Hi){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new ko(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Ke.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Qc(n,e){let t=[];for(let r=0;r-1)&&t.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Ap(n){return n.tag!=null}function Ep(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Ap(i))this.tags.push(i);else if(Ep(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new Wi(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Wi(this,t,!0);return r.addAll(e,D.none,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let c=o.getAttrs(t);if(c===!1)continue;o.attrs=c||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=ea(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=ea(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},wa={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Tp={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ba={ol:!0,ul:!0},Ji=1,$i=2,Er=4;function Zc(n,e,t){return e!=null?(e?Ji:0)|(e==="full"?$i:0):n&&n.whitespace=="pre"?Ji|$i:t&~Er}var Ln=class{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=D.none,this.match=s||(o&Er?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(w.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ji)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=w.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(w.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!wa.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Wi=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=Zc(null,t.preserveWhitespace,0)|(r?Er:0);i?s=new Ln(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new Ln(null,null,D.none,!0,null,o):s=new Ln(e.schema.topNodeType,null,D.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&$i||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Ji)i.options&$i?r=r.replace(/\r\n?/g,` +`):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),s;ba.hasOwnProperty(i)&&this.parser.normalizeLists&&Dp(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Tp.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,c=this.top,a=this.needsBlock;if(wa.hasOwnProperty(i))c.content.length&&c.content[0].isInline&&this.open&&(this.open--,c=this.top),l=!0,c.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=o&&o.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(c),this.needsBlock=a}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,o,l,o.consuming===!1?s:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` +`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!c.clearMark(a)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let c=this.enter(o,t.attrs||null,r,t.preserveWhitespace);c&&(s=!0,r=c)}else{let c=this.parser.schema.marks[t.mark];r=r.concat(c.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,r));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,r),this.findAround(e,c,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=o,!l.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s(o.type?o.type.allowsMarkType(a.type):ta(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Ln(e,t,c,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(o(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=s?r.node(c-s).type:null;if(!h||h.name!=a&&!h.isInGroup(a))return!1;c--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}};function Dp(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ba.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Op(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function ea(n){let e={};for(let t in n)e[t]=n[t];return e}function ta(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let c=0;c{if(s.length||o.marks.length){let l=0,c=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Li(bo(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Li(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=na(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return na(e.marks)}};function na(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function bo(n){return n.document||window.document}var ra=new WeakMap;function Np(n){let e=ra.get(n);return e===void 0&&ra.set(n,e=Ip(n)),e}function Ip(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,c=t?n.createElementNS(t,i):n.createElement(i),a=e[1],h=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){h=2;for(let d in a)if(a[d]!=null){let f=d.indexOf(" ");f>0?c.setAttributeNS(d.slice(0,f),d.slice(f+1),a[d]):c.setAttribute(d,a[d])}}for(let d=h;dh)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:u,contentDOM:p}=Li(n,f,t,r);if(c.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:c,contentDOM:l}}var ka=65535,Ca=Math.pow(2,16);function vp(n,e){return n+e*Ca}function xa(n){return n&ka}function _p(n){return(n-(n&ka))/Ca}var Ma=1,Aa=2,ji=4,Ea=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Ea)>0}get deletedBefore(){return(this.delInfo&(Ma|ji))>0}get deletedAfter(){return(this.delInfo&(Aa|ji))>0}get deletedAcross(){return(this.delInfo&ji)>0}},ft=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=xa(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+s],h=this.ranges[l+o],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:vp(l/3,e-c),m=e==c?Aa:e==d?Ma:ji;return(t<0?e!=c:e!=d)&&(m|=Ea),new Ir(u,m,p)}i+=h-a}return r?e+i:new Ir(e+i,0,null)}touches(e,t){let r=0,i=xa(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+s],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&c!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,s)}invert(){return new tn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("addMark",vr);var tn=class n extends G{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(No(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return ee.fromReplace(e,this.from,this.to,r)}invert(){return new vr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};G.jsonID("removeMark",tn);var _r=class n extends G{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};G.jsonID("replaceAround",X);function Do(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Up(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),s.forEach(c=>n.step(c))}function Vp(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let c=null;if(r instanceof Tr){let a=o.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(o.marks)&&(c=[r]):c=o.marks;if(c&&c.length){let a=Math.min(l+o.nodeSize,t);for(let h=0;hn.step(new tn(o.from,o.to,o.style)))}function Io(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let c=0;c=0;c--)n.step(o[c])}function Bp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=w.from(r.node(p).copy(h)),d++):c--;let f=w.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=w.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new X(i,s,i,s,new b(r,0,0),t.length,!0))}function qp(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let c=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,c)&&Hp(n.doc,n.mapping.slice(s).map(l),r)){let a=null;if(r.schema.linebreakReplacement){let u=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);u&&!p?a=!1:!u&&p&&(a=!0)}a===!1&&Da(n,o,l,s),Io(n,n.mapping.slice(s).map(l,1),r,void 0,a===null);let h=n.mapping.slice(s),d=h.map(l,1),f=h.map(l+o.nodeSize,1);return n.step(new X(d,f,d+1,f-1,new b(w.from(r.create(c,null,o.marks)),0,0),1,!0)),a===!0&&Ta(n,o,l,s),!1}})}function Ta(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let c=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Da(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(` +`))}})}function Hp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Jp(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new X(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(w.from(o),0,0),1,!0))}function Rt(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>s;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),c=r&&r[0];return i.node(s).canReplaceWith(l,l,c?c.type:i.node(s+1).type)}function $p(n,e,t=1,r){let i=n.doc.resolve(e),s=w.empty,o=w.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=w.from(i.node(l).copy(s));let h=r&&r[a];o=w.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Ee(e,e,new b(s.append(o),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Oa(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Wp(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&Oa(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function jp(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let h=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);h&&!d?r=!1:!h&&d&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);Da(n,h.node(),h.before(),l)}o.inlineContent&&Io(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let c=n.mapping.slice(l),a=c.map(e-t);if(n.step(new Ee(a,c.map(e+t,-1),b.empty,!0)),r===!0){let h=n.doc.resolve(a);Ta(n,h.node(),h.before(),n.steps.length)}return n}function Kp(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,c=r.index(o)+(l>0?1:0),a=r.node(o),h=!1;if(s==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function Xi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Ia(i,s,r)?new Ee(e,t,r):new Oo(i,s,r).fit()}function Ia(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Oo=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=w.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=w.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let c=new b(s,o,l);return e>-1?new X(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ee(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=Eo(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(o?a.matchType(o.type)||(d=a.fillBefore(w.from(o),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(h=a.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&a.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Eo(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Eo(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Or(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Or(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(Ra(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Nr(this.placed,t,w.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:c,type:a}=this.frontier[l],h=To(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Nr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Nr(this.placed,this.depth,w.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(w.empty,!0);t.childCount&&(this.placed=Nr(this.placed,this.frontier.length,t))}};function Or(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Or(n.firstChild.content,e-1,t)))}function Nr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Nr(n.lastChild.content,e-1,t)))}function Eo(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Ra(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(w.empty,!0)))),n.copy(r)}function To(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!Yp(t,s.content,o)?l:null}function Yp(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==u&&o.splice(1,0,-f)}let c=o.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=Gp(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=o[f];u<0||(e=i.before(u),t=s.after(u))}}function va(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(w.empty,!0))}return n}function Qp(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Kp(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(w.from(r),0,0))}function Zp(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=_a(r,i);for(let o=0;o0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function _a(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var Ki=class n extends G{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return ee.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return ee.fromReplace(e,this.pos,this.pos+1,new b(w.from(i),0,t.isLeaf?0:1))}getMap(){return ft.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};G.jsonID("attr",Ki);var Yi=class n extends G{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return ee.ok(r)}getMap(){return ft.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};G.jsonID("docAttr",Yi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Rr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Xi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(w.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Xp(this,e,t,r),this}replaceRangeWith(e,t,r){return Qp(this,e,t,r),this}deleteRange(e,t){return Zp(this,e,t),this}lift(e,t){return Pp(this,e,t),this}join(e,t=1){return jp(this,e,t),this}wrap(e,t){return Fp(this,e,t),this}setBlockType(e,t=e,r,i=null){return qp(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Jp(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Ki(e,t,r)),this}setDocAttribute(e,t){return this.step(new Yi(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Ur(e,t)),this}split(e,t=1,r){return $p(this,e,t,r),this}addMark(e,t,r){return Up(this,e,t,r),this}removeMark(e,t,r){return Vp(this,e,t,r),this}clearIncompatible(e,t,r){return Io(this,e,t,r),this}};var vo=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new vt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;s--){let o=t<0?Hn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Hn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Te(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Te(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=vo[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in vo)throw new RangeError("Duplicate use of selection JSON ID "+e);return vo[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var vt=class{constructor(e,t){this.$from=e,this.$to=t}},Ua=!1;function Va(n){!Ua&&!n.parent.inlineContent&&(Ua=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Va(e),Va(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Zi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&C.isSelectable(l))return C.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function Ba(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}var Pa=1,Qi=2,La=4,Vo=class extends qn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Qi,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Qi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Qi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=La,this}get scrolledIntoView(){return(this.updated&La)>0}};function za(n,e){return!e||!n?n:n.bind(e)}var sn=class{constructor(e,t,r){this.name=e,this.init=za(t.init,r),this.apply=za(t.apply,r)}},tm=[new sn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new sn("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new sn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new sn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Vr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=tm.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new sn(r.key,r.spec.state,r))})}},Bo=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Vr(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Ke.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==o.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=a.fromJSON.call(c,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function Fa(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Fa(i,e,{})),t[r]=i}return t}var H=class{constructor(e){this.spec=e,this.props={},e.props&&Fa(e.props,this,this.props),this.key=e.key?e.key.key:qa("plugin")}getState(e){return e[this.key]}},_o=Object.create(null);function qa(n){return n in _o?n+"$"+ ++_o[n]:(_o[n]=0,n+"$")}var le=class{constructor(e="key"){this.key=qa(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var te=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},zr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},qo=null,pt=function(n,e,t){let r=qo||(qo=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},nm=function(){qo=null},fn=function(n,e,t,r){return t&&(Ha(n,e,t,r,-1)||Ha(n,e,t,r,1))},rm=/^(img|br|input|textarea|hr)$/i;function Ha(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:_e(n))){let s=n.parentNode;if(!s||s.nodeType!=1||Jr(n)||rm.test(n.nodeName)||n.contentEditable=="false")return!1;e=te(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?_e(n):0}else return!1}}function _e(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function im(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=_e(n)}else if(n.parentNode&&!Jr(n))e=te(n),n=n.parentNode;else return null}}function sm(n,e){for(;;){if(n.nodeType==3&&e2),ve=Kn||(Ye?/Mac/.test(Ye.platform):!1),am=Ye?/Win/.test(Ye.platform):!1,Fe=/Android \d/.test(Lt),$r=!!Ja&&"webkitFontSmoothing"in Ja.documentElement.style,hm=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function dm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ut(n,e){return typeof n=="number"?n:n[e]}function fm(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function $a(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=zr(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?dm(s):fm(l),h=0,d=0;if(e.topa.bottom-ut(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+ut(i,"top")-a.top:e.bottom-a.bottom+ut(i,"bottom")),e.lefta.right-ut(r,"right")&&(h=e.right-a.right+ut(i,"right")),h||d)if(c)s.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function um(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:Mh(n.dom)}}function Mh(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=zr(r));return e}function pm({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Ah(t,r==0?0:r-e)}function Ah(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?gm(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:Eh(t,i)}function gm(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function ll(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function ym(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function bm(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!o&&c.left>r.left||c.top>r.top?i=l.posBefore:(!o&&c.right-1?i:n.docView.posFromDOM(e,t,-1)}function Th(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;$r&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=bm(n,r,i,e))}l==null&&(l=wm(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Wa(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Br(_t(pt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Po(c.getBoundingClientRect(),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return Po(c.getBoundingClientRect(),!0)}return Po(r.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?pt(c,_e(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Br(_t(a,1),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let a=c?c.nodeType==3?pt(c,0,o?0:1):c.nodeType==1?c:null:null;if(a)return Br(_t(a,-1),!0)}return Br(_t(r.nodeType==3?pt(r):r,-t),t>=0)}function Br(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Po(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Oh(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function km(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Oh(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Dh(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=pt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}var Cm=/[\u0590-\u08ac]/;function Mm(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!Cm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Oh(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):r.pos==r.start()||r.pos==r.end()}var ja=null,Ka=null,Ya=!1;function Am(n,e,t){return ja==e&&Ka==t?Ya:(ja=e,Ka=t,Ya=t=="up"||t=="down"?km(n,e,t):Mm(n,e,t))}var Ue=0,Ga=1,ln=2,Ge=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Ue,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tte(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof ns){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof es&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?te(s.dom)+1:0}}else{let s,o=!0;for(;s=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=o;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=te(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&ot){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 Lh(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let c=e&&(r||o||!t);if(c){if(n.someProp("transformPastedText",f=>{e=f(e,o||r,n)}),o)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);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=s.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),s=Km(t),$r&&Ym(s);let a=s&&s.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=s.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;s=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!$m.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Gm(hh(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Wm(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 $m=/^(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 Wm(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)),o,s=[];if(n.forEach(l=>{if(!s)return;let c=i.findWrapping(l.type),a;if(!c)return s=null;if(a=s.length&&o.length&&Fh(c,o,l,s[s.length-1],0))s[s.length-1]=a;else{s.length&&(s[s.length-1]=qh(s[s.length-1],o.length));let h=zh(l,c);s.push(h),i=i.matchType(h.type),o=c}}),s)return w.from(s)}return n}function zh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,w.from(n));return n}function Fh(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(w.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function hh(n,e,t){return et}).createHTML(n):n}function Km(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=Jh().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&Hh[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=jm(n),i)for(let o=0;o=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=w.from(c.create(r[l+1],i)),o++,s++}return new b(i,o,s)}var ge={},ye={},Xm={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 Qm(n){for(let e in ge){let t=ge[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{eg(n,r)&&!hl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},Xm[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 Zm(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 eg(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 tg(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,!Wh(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,sn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Jm(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(Wh(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",o=>o(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function fo(n){return{left:n.clientX,top:n.clientY}}function ng(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 o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),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 rg(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 ig(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof C&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(C.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(jn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function og(n,e,t,r,i){return dl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?ig(n,t):rg(n,t))}function sg(n,e,t,r){return dl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function lg(n,e,t,r){return dl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||cg(n,t,r)}function cg(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 o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)jn(n,A.create(r,l+1,l+1+s.content.size),"pointer");else if(C.isSelectable(s))jn(n,C.create(r,l),"pointer");else continue;return!0}}function fl(n){return oo(n)}var $h=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=fl(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&ng(t,n.input.lastClick)&&!t[$h]&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o};let s=n.posAtCoords(fo(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new nl(n,s,t,!!r)):(o=="doubleClick"?sg:lg)(n,s.pos,s.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[$h],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let h=e.state.doc.resolve(t.pos);o=h.parent,s=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&&o.type.spec.draggable&&o.type.spec.selectable!==!1||a instanceof C&&a.from<=s&&a.to>s)&&(this.mightDrag={node:o,pos:s,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(()=>pt(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(fo(e))),this.updateAllowDefault(e),this.allowDefault||!t?Vt(this.view,"pointer"):og(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 Wh(n,e){return n.composing?!0:me&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var ag=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(),oo(n,!0),n.markCursor=null;else if(oo(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,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}jh(n,ag)};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++,jh(n,20))};function jh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>oo(n),e))}function Kh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=dg());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function hg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=lm(e.focusNode,e.focusOffset),r=cm(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function dg(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function oo(n,e=!1){if(!(Fe&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Kh(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 fg(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&&um<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=Fr?null:t.clipboardData,s=r.content(),{dom:l,text:c}=Ph(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",c)):fg(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function ug(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function pg(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 o=Lh(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,o||b.empty)))return!0;if(!o)return!1;let s=ug(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Yh(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,Yh(r),r.getData("text/html"),i,t)?t.preventDefault():pg(n,t)};var so=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Gh=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,o=i.empty?null:n.posAtCoords(fo(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof C?i.to-1:i.to))){if(r&&r.mightDrag)s=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&&(s=C.create(n.state.doc,d.posBefore))}}let l=(s||n.state.selection).content(),{dom:c,text:a,slice:h}=Ph(n,l);(!t.dataTransfer.files.length||!ae||Mh>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 so(h,!t[Gh],s)};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(fo(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",p=>{s=p(s,n)}):s=Lh(n,Yh(t.dataTransfer),Fr?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&!t[Gh]);if(n.someProp("handleDrop",p=>p(n,t,s||b.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let c=s?Ia(n.state.doc,o.pos,s):o.pos;c==null&&(c=o.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=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,s.content.firstChild):a.replaceRange(h,h,s),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&C.isSelectable(s.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(s.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,T)=>p=T),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())&&pt(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",o=>o(n,sn(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 lo=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:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new ne(o-r,o-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 o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new ne(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}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,o){let s;for(let l=0;l{let a=c+r,h;if(h=Qh(t,l,a)){for(i||(i=this.children.slice());ol&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&c.type instanceof an){let a=Math.max(o,c.from)-o,h=Math.min(s,c.to)-o;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;yT+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]+o,-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]+o+1,s);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=gg(l,n,e,t,i,o,s),h=ao(a,r,0,s);e=h.local;for(let d=0;dt&&s.to{let a=Qh(n,l,c+t);if(a){o=!0;let h=ao(a,l,t+c+1,r);h!=ce&&i.push(c,c+l.nodeSize,h)}});let s=Xh(o?Zh(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function zs(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])),co.from(e)}var yg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},wg=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}},ol=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()}),wg&&(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,yg)),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(ih(this.view)){if(this.suppressingSelectionUpdates)return pt(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 o=e.focusNode;o;o=zr(o))t.add(o);for(let o=e.anchorNode;o;o=zr(o))if(t.has(o)){r=o;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)&&ih(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),o=-1,s=-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||Sg(e,d)!=u)&&f.remove()}}}let a=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),bg(e)),this.handleDOMChange(o,s,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||pt(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],T=y.pmViewDesc;if(y.nodeName=="BR"&&!T){o=g;break}if(!T||T.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(s),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:o,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:Cg,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+s,head:y+s}}return{doc:m,sel:p,from:s,to:l}}function Cg(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 Mg=/^(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 Ag(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let E=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,Nt=cl(n,E);if(Nt&&!n.state.selection.eq(Nt)){if(ae&&Fe&&n.input.lastKeyCode===13&&Date.now()-100fp(n,sn(13,"Enter"))))return;let Bi=n.state.tr.setSelection(Nt);E=="pointer"?Bi.setMeta("pointer",!0):E=="key"&&Bi.scrollIntoView(),o&&Bi.setMeta("composition",o),n.dispatch(Bi)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=kg(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(E=>E.nodeType==1&&!Mg.test(E.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",E=>E(n,sn(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 E=gh(n,n.state.doc,a.sel);if(E&&!E.eq(n.state.selection)){let Nt=n.state.tr.setSelection(E);o&&Nt.setMeta("composition",o),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),T=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA,N;if((Kn&&n.input.lastIOSEnter>Date.now()-225&&(!T||i.some(E=>E.nodeName=="DIV"||E.nodeName=="P"))||!T&&m.posE(n,sn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Eg(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",E=>E(n,sn(8,"Backspace")))){Fe&&ae&&n.domObserver.suppressSelectionUpdates();return}ae&&Fe&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),Fe&&!T&&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(E){return E(n,sn(13,"Enter"))})},20));let Se=p.start,pe=p.endA,Y,ht,Ot;if(T){if(m.pos==g.pos)ke&&Bt<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>pt(n),20)),Y=n.state.tr.delete(Se,pe),ht=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(Ot=Tg(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 E=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",Nt=>Nt(n,Se,pe,E)))return;Y=n.state.tr.insertText(E,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 E=gh(n,Y.doc,a.sel);E&&!(ae&&Fe&&n.composing&&E.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:al(n,e.resolve(t.anchor),e.resolve(t.head))}function Tg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||Fs(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function Dg(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,o-Math.min(s,l));r-=s+c-o}if(s=s?o-r:0;o-=c,o&&o=l?o-r:0;o-=c,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}var sl=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(kh),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=xh(this),bh(this),this.nodeViews=Sh(this),this.docView=Qa(this.state.doc,wh(this),zs(this),this.dom,this),this.domObserver=new ol(this,(r,i,o,s)=>Ag(this,r,i,o,s)),this.domObserver.start(),Qm(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(kh),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,o=!1,s=!1;e.storedMarks&&this.composing&&(Kh(this),s=!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=Sh(this);Ng(u,this.nodeViews)&&(this.nodeViews=u,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&tl(this),this.editable=xh(this),bh(this);let c=zs(this),a=wh(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=o||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(s=!0);let f=h=="preserve"&&s&&this.dom.style.overflowAnchor==null&&gm(this);if(s){this.domObserver.stop();let u=d&&(ke||ae)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Og(i.selection,e.selection);if(d){let p=ae?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=hg(this)),(o||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Qa(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Bm(this))?pt(this,u):(Uh(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&&ym(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&&Wa(this,t.getBoundingClientRect(),e)}else Wa(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(o))==r.node&&(i=o)}this.dragging=new so(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 s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Cm(this,e)}coordsAtPos(e,t=1){return Oh(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 Dm(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&&(Zm(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],zs(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,om())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return tg(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&&hm(this.dom.ownerDocument)==this.dom&&xg(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};function wh(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 bh(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 xh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Og(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 Sh(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 Ng(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 kh(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 Ig=["p",0],Rg=["blockquote",0],vg=["hr"],_g=["pre",["code",0]],Ug=["br"],Vg={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return Ig}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Rg}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return vg}},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 _g}},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 Ug}}},Bg=["em",0],Pg=["strong",0],Lg=["code",0],zg={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 Bg}},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 Pg}},code:{parseDOM:[{tag:"code"}],toDOM(){return Lg}}},Fg=new Dr({nodes:Vg,marks:zg});var td=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function qg(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Hg=(n,e,t)=>{let r=qg(n,t);if(!r)return!1;let i=nd(r);if(!i){let s=r.blockRange(),l=s&&nn(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(od(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Gn(o,"end")||C.isSelectable(o)))for(let s=r.depth;;s--){let l=Xi(n.doc,r.before(s),r.after(s),b.empty);if(l&&l.slice.size1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-o.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 Jg=(n,e,t)=>{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=nd(r)}let s=o&&o.nodeBefore;return!s||!C.isSelectable(s)?!1:(e&&e(n.tr.setSelection(C.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function nd(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 $g(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=$g(n,t);if(!r)return!1;let i=rd(r);if(!i)return!1;let o=i.nodeAfter;if(od(n,i,e,1))return!0;if(r.parent.content.size==0&&(Gn(o,"start")||C.isSelectable(o))){let s=Xi(n.doc,r.before(),r.after(),b.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=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=Rs(n.doc,t.from,-1),i==null)return!1;if(e){let o=n.tr.join(i);r&&o.setSelection(C.create(o.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(o.scrollIntoView())}return!0},id=(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=Rs(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),o=i&&nn(i);return o==null?!1:(e&&e(n.tr.lift(i,o).scrollIntoView()),!0)},Kg=(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),o=t.indexAfter(-1),s=ml(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,s.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},Yg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Ee||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=ml(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!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 o=t.before();if(Rt(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Xg(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 o=i.parentOffset==i.parent.content.size,s=e.tr;(e.selection instanceof A||e.selection instanceof Ee)&&s.deleteSelection();let l=r.depth==0?null:ml(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,o,r),a=c?[c]:o&&l?[{type:l}]:void 0,h=Rt(s.doc,s.mapping.map(r.pos),1,a);if(!a&&!h&&Rt(s.doc,s.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),!h)return!1;if(s.split(s.mapping.map(r.pos),1,a),!o&&!r.parentOffset&&r.parent.type!=l){let d=s.mapping.map(r.before()),f=s.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&s.setNodeMarkup(s.mapping.map(r.before()),l)}return t&&t(s.scrollIntoView()),!0}}var Qg=Xg();var Kr=(n,e)=>{let{$from:t,to:r}=n.selection,i,o=t.sharedDepth(r);return o==0?!1:(i=t.before(o),e&&e(n.tr.setSelection(C.create(n.doc,i))),!0)},Zg=(n,e)=>(e&&e(n.tr.setSelection(new Ee(n.doc))),!0);function ey(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||rn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function od(n,e,t,r){let i=e.nodeBefore,o=e.nodeAfter,s,l,c=i.type.spec.isolating||o.type.spec.isolating;if(!c&&ey(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(s=(l=i.contentMatchAt(i.childCount)).findWrapping(o.type))&&l.matchType(s[0]||o.type).validEnd){if(t){let u=e.pos+o.nodeSize,p=w.empty;for(let y=s.length-1;y>=0;y--)p=w.from(s[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),s.length,!0)),g=m.doc.resolve(u+2*s.length);g.nodeAfter&&g.nodeAfter.type==i.type&&rn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=o.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(o,"start",!0)&&Gn(i,"end")){let u=i,p=[];for(;p.push(u),!u.isTextblock;)u=u.lastChild;let m=o,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 T=n.tr.step(new X(e.pos-p.length,e.pos+o.nodeSize,e.pos+g,e.pos+o.nodeSize-g,new b(y,p.length,0),0,!0));t(T.scrollIntoView())}return!0}}return!1}function sd(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}var ty=sd(-1),ny=sd(1);function Xn(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o),l=s&&Gi(s,n,e);return l?(r&&r(t.tr.wrap(s,l).scrollIntoView()),!0):!1}}function pn(n,e=null){return function(t,r){let i=!1;for(let o=0;o{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 o=t.tr;for(let s=0;s{if(l||!r&&c.isAtom&&c.isInline&&a>=o.pos&&a+c.nodeSize<=s.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function iy(n){let e=[];for(let t=0;t{if(o.isAtom&&o.content.size&&o.isInline&&s>=r.pos&&s+o.nodeSize<=i.pos)return s+1>r.pos&&e.push(new vt(r,r.doc.resolve(s+1))),r=r.doc.resolve(s+1+o.content.size),!1}),r.poso.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(s.depth-1).type.compatibleContent(n)&&s.startIndex==0){if(i.index(s.depth-1)==0)return!1;let h=t.doc.resolve(s.start-2);c=new Zt(h,h,s.depth),s.endIndex=0;h--)o=w.from(t[h].type.create(t[h].attrs,o));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(o,0,0),t.length,!0));let s=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=T+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let c=o.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,o.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,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?py(e,t,n,o):my(e,t,o):!0:!1}}function py(n,e,t,r){let i=n.tr,o=r.end,s=r.$to.end(r.depth);om;p--)u-=i.child(p).nodeSize,r.delete(u-1,u+1);let o=r.doc.resolve(t.start),s=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=o.node(-1),h=o.index(-1);if(!a.canReplace(h+(l?0:1),h+1,s.content.append(c?w.empty:w.from(i))))return!1;let d=o.pos,f=d+s.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,o=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let l=o.parent,c=l.child(s-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=o.start,u=o.end;t(e.tr.step(new X(f-(a?3:1),u,f,u,d,1,!0)).scrollIntoView())}return!0}}var gt={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:"'"},mo={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},gy=typeof navigator<"u"&&/Mac/.test(navigator.platform),yy=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(J=0;J<10;J++)gt[48+J]=gt[96+J]=String(J);var J;for(J=1;J<=24;J++)gt[J+111]="F"+J;var J;for(J=65;J<=90;J++)gt[J]=String.fromCharCode(J+32),mo[J]=String.fromCharCode(J);var J;for(po in gt)mo.hasOwnProperty(po)||(mo[po]=gt[po]);var po;function ad(n){var e=gy&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||yy&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?mo:gt)[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 wy=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function by(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l127)&&(o=gt[r.keyCode])&&o!=i){let l=e[Sl(o,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var go=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(o,s){return i.push(e(o,s))},t,r),i};re.from=function(e){return e instanceof re?e:e&&e.length?new hd(e):re.empty};var hd=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,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,l){for(var c=o;c=s;c--)if(i(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=go)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=go)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 hd([]);var ky=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,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(o,l)-l,s+l)===!1||o=o?this.right.slice(r-o,i-o):this.left.slice(r,o).append(this.right.slice(0,i-o))},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 Cy=500,yo=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,o;t&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,l,c,a=[],h=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),o=i.maps.length),o--,h.push(d);return}if(i){h.push(new Ge(d.map));let u=d.step.map(i.slice(o)),p;u&&s.maybeStep(u).doc&&(p=s.mapping.maps[s.mapping.maps.length-1],a.push(new Ge(p,void 0,void 0,a.length+h.length))),o--,p&&i.appendMap(p,o)}else s.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(o)):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:s,selection:l}}addTransform(e,t,r,i){let o=[],s=this.eventCount,l=this.items,c=!i&&l.length?l.get(l.length-1):null;for(let h=0;hAy&&(l=My(l,a),s-=a),new n(l.append(o),s)}remapping(e,t){let r=new Rr;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},e,t),r}addMaps(e){return this.eventCount==0?this:new n(this.items.append(e.map(t=>new Ge(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let c=t;this.items.forEach(f=>{let u=o.getMirror(--c);if(u==null)return;s=Math.min(s,u);let p=o.maps[u];if(f.step){let m=e.steps[u].invert(e.docs[u]),g=f.selection&&f.selection.map(o.slice(c+1,u));g&&l++,r.push(new Ge(p,m,g))}else r.push(new Ge(p))},i);let a=[];for(let f=t;fCy&&(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=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let c=s.step.map(t.slice(r)),a=c&&c.getMap();if(r--,a&&t.appendMap(a,r),c){let h=s.selection&&s.selection.map(t.slice(r));h&&o++;let d=new Ge(a.invert(),c,h),f,u=i.length-1;(f=i.length&&i[u].merge(d))?i[u]=f:i.push(d)}}else s.map&&r--},this.items.length,0),new n(kl.from(i.reverse()),o)}};yo.empty=new yo(kl.empty,0);function My(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var Ge=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,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}},Ay=20;function Ty(n,e,t){let r=Ey(e),i=Al.get(e).spec.config,o=(t?n.undone:n.done).popEvent(e,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),l=(t?n.done:n.undone).addTransform(o.transform,e.selection.getBookmark(),i,r),c=new Ml(t?l:o.remaining,t?o.remaining:l,null,0,-1);return o.transform.setSelection(s).setMeta(Al,{redo:t,historyState:c})}var Cl=!1,dd=null;function Ey(n){let e=n.plugins;if(dd!=e){Cl=!1,dd=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 o=Ty(i,t,n);o&&r(e?o.scrollIntoView():o)}return!0}}var Xr=wo(!1,!0),Qn=wo(!0,!0),xx=wo(!1,!1),Sx=wo(!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 Tl(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Dy(e)||!Oy(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,o=null;for(let s=e.depth;;s--){let l=e.node(s);if(t>0?e.indexAfter(s)0){o=l.child(t>0?e.indexAfter(s):e.index(s)-1);break}else if(s==0)return null;i+=t;let c=e.doc.resolve(i);if(n.valid(c))return c}for(;;){let s=t>0?o.firstChild:o.lastChild;if(!s){if(o.isAtom&&!o.isText&&!C.isSelectable(o)){e=e.doc.resolve(i+o.nodeSize*t),r=!1;continue e}break}o=s,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 Tl=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 Dy(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 Oy(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 Ny(){return new H({props:{decorations:_y,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:Ry,handleKeyDown:Iy,handleDOMEvents:{beforeinput:vy}}})}var Iy=Gr({ArrowLeft:bo("horiz",-1),ArrowRight:bo("horiz",1),ArrowUp:bo("vert",-1),ArrowDown:bo("vert",1)});function bo(n,e){let t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,o){let s=r.selection,l=e>0?s.$to:s.$from,c=s.empty;if(s instanceof A){if(!o.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 Ry(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 vy(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 s=r.length-1;s>=0;s--)i=w.from(r[s].createAndFill(null,i));let o=n.state.tr.replace(t.pos,t.pos,new b(i,0,0));return o.setSelection(A.near(o.doc.resolve(t.pos+1))),n.dispatch(o),!1}function _y(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 yt(){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&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}var Vy=500;function pd({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,o){return ud(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&ud(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function ud(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.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--)s.step(l.steps[c].invert(l.docs[c]));if(o.text){let c=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,n.schema.text(o.text,c))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},By=new wt(/--$/,"\u2014"),Py=new wt(/\.\.\.$/,"\u2026"),Nx=new wt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Ix=new wt(/"$/,"\u201D"),Rx=new wt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),vx=new wt(/'$/,"\u2019");var gd=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Ly(n,e){let t={},r;function i(o,s){if(e){let l=e[o];if(l===!1)return;l&&(o=l)}t[o]=s}if(i("Mod-z",Xr),i("Shift-Mod-z",Qn),i("Backspace",md),gd||i("Mod-y",Qn),i("Alt-ArrowUp",Wr),i("Alt-ArrowDown",id),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",uo(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",uo(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Xn(r)),r=n.nodes.hard_break){let o=r,s=Yr(gl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(o.create()).scrollIntoView()),!0));i("Mod-Enter",s),i("Shift-Enter",s),gd&&i("Ctrl-Enter",s)}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 o=1;o<=6;o++)i("Shift-Ctrl-"+o,pn(r,{level:o}));if(r=n.nodes.horizontal_rule){let o=r;i("Mod-_",(s,l)=>(l&&l(s.tr.replaceSelectionWith(o.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 _=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){(o||(o=[])).push({type:"overlong_rowspan",pos:h,n:y-N});break}let Se=i+N*e;for(let pe=0;per&&(o+=a.attrs.colspan)}}for(let s=0;s1&&(t=!0)}e==-1?e=o:e!=o&&(e=Math.max(e,o))}return e}function qy(n,e,t){n.problems||(n.problems=[]);let r={};for(let i=0;iNumber(s)):null,i=Number(n.getAttribute("colspan")||1),o={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(let s in e){let l=e[s].getFromDOM,c=l&&l(n);c!=null&&(o[s]=c)}return o}function wd(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 Jy(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=>yd(r,e)}],toDOM(r){return["td",wd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>yd(r,e)}],toDOM(r){return["th",wd(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 $y(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)||Wy(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Wy(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=_.get(r),o=n.start(-1),s=i.nextCell(n.pos-o,e,t);return s==null?null:n.node(0).resolve(o+s)}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 Dd(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-o);c.unshift(t.pos-o);let a=c.map(h=>{let d=r.nodeAt(h);if(!d)throw RangeError(`No cell with offset ${h} found`);let f=o+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 o=this.$anchorCell.node(-1)!=r.node(-1);return o&&this.isRowSelection()?bt.rowSelection(r,i):o&&this.isColSelection()?bt.colSelection(r,i):new bt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=_.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),o={},s=[];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=_.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),c=e.node(0);return s.top<=l.top?(s.top>0&&(e=c.resolve(o+i.map[s.left])),l.bottom0&&(t=c.resolve(o+i.map[l.left])),s.bottom0)return!1;let s=i+this.$anchorCell.nodeAfter.attrs.colspan,l=o+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,l)==t.width}eq(e){return e instanceof bt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=e.node(-1),i=_.get(r),o=e.start(-1),s=i.findCell(e.pos-o),l=i.findCell(t.pos-o),c=e.node(0);return s.left<=l.left?(s.left>0&&(e=c.resolve(o+i.map[s.top*i.width])),l.right0&&(t=c.resolve(o+i.map[l.top*i.width])),s.right{e.push(ne.node(r,r+t.nodeSize,{class:"selectedCell"}))}),z.create(n.doc,e)}function Xy({$from:n,$to:e}){if(n.pos==e.pos||n.pos=0&&!(n.after(i+1)=0&&!(e.before(o+1)>e.start(o));o--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Qy({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let o=n.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){t=o;break}}for(let i=e.depth;i>0;i--){let o=e.node(i);if(o.type.spec.tableRole==="cell"||o.type.spec.tableRole==="header_cell"){r=o;break}}return t!==r&&e.parentOffset===0}function Zy(n,e,t){let r=(e||n).selection,i=(e||n).doc,o,s;if(r instanceof C&&(s=r.node.type.spec.tableRole)){if(s=="cell"||s=="header_cell")o=B.create(i,r.from);else if(s=="row"){let l=i.resolve(r.from+1);o=B.rowSelection(l,l)}else if(!t){let l=_.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];o=B.create(i,c+1,a)}}else r instanceof A&&Xy(r)?o=A.create(i,r.from):r instanceof A&&Qy(r)&&(o=A.create(i,r.$from.start(),r.$from.end()));return o&&(e||(e=n.tr)).setSelection(o),e}var e0=new le("fix-tables");function Nd(n,e,t,r){let i=n.childCount,o=e.childCount;e:for(let s=0,l=0;s{i.type.spec.tableRole=="table"&&(t=t0(n,i,o,t))};return e?e.doc!=n.doc&&Nd(e.doc,n.doc,0,r):n.doc.descendants(r),t}function t0(n,e,t,r){let i=_.get(e);if(!i.problems)return r;r||(r=n.tr);let o=[];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;Ky(e,r,i+o)&&(o=i==0||i==e.width?null:0);for(let s=0;s0&&i0&&e.map[l-1]==c||i0?-1:0;i0(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[o]==t[o-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function f0(n){return(e,t)=>{var r;let i=e.selection,o,s;if(i instanceof B){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;o=i.$anchorCell.nodeAfter,s=i.$anchorCell.pos}else{if(o=$y(i.$from),!o)return!1;s=(r=Zn(i.$from))==null?void 0:r.pos}if(o==null||s==null||o.attrs.colspan==1&&o.attrs.rowspan==1)return!1;if(t){let l=o.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+o.tableStart,m=s.doc.nodeAt(p);m&&s.setNodeMarkup(p,f,m.attrs)}),r(s)}return!0}}var tS=Bl("row",{useDeprecatedLogic:!0}),nS=Bl("column",{useDeprecatedLogic:!0}),rS=Bl("cell",{useDeprecatedLogic:!0});function p0(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 o=n.node(-1).child(r),s=o.lastChild;if(s)return i-1-s.nodeSize;i-=o.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 xo(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((o,s)=>{o.content.eq(i)||r.replace(r.mapping.map(s+1),r.mapping.map(s+o.nodeSize-1),new b(i,0,0))}),r.docChanged&&e(r)}return!0}function y0(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),o=i.type.spec.tableRole,s=i.type.schema,l=[];if(o=="row")for(let c=0;c=0;s--){let{rowspan:l,colspan:c}=o.child(s).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)}o.push(w.from(c))}t=o,e=i}return{width:n,height:e,rows:t}}function x0(n,e,t,r,i,o,s){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 o=t.selection;if(o instanceof B)return Co(t,r,S.near(o.$headCell,e));if(n!="horiz"&&!o.empty)return!1;let s=_d(i,n,e);if(s==null)return!1;if(n=="horiz")return Co(t,r,S.near(t.doc.resolve(o.head+e),e));{let l=t.doc.resolve(s),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),Co(t,r,a)}}}function ko(n,e){return(t,r,i)=>{if(!i)return!1;let o=t.selection,s;if(o instanceof B)s=o;else{let c=_d(i,n,e);if(c==null)return!1;s=new B(t.doc.resolve(c))}let l=Ed(s.$headCell,n,e);return l?Co(t,r,new B(s.$anchorCell,l)):!1}}function k0(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 C0(n,e,t){if(!He(n.state))return!1;let r=y0(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 o=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),l=_.get(o).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=b0(r,l.right-l.left,l.bottom-l.top),Cd(n.state,n.dispatch,s,l,r),!0}else if(r){let o=vl(n.state),s=o.start(-1);return Cd(n.state,n.dispatch,s,_.get(o.node(-1)).findCell(o.pos-s),r),!0}else return!1}function M0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Md(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof B)o(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Zn(n.state.selection.$anchor))!=null&&((t=El(n,e))==null?void 0:t.pos)!=i.pos)o(i,e),e.preventDefault();else if(!r)return;function o(c,a){let h=El(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 s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),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(Md(n,a.target)!=r&&(d=El(n,e),!d))return s();d&&o(d,a)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",l)}function _d(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 o=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:o.childCount))return null;if(o.type.spec.tableRole=="cell"||o.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 Md(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function El(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Zn(n.state.doc.resolve(t.pos)):null}var A0=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,o){var s;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(o,s){return s.apply(o)}},props:{attributes:o=>{let s=Ve.getState(o);return s&&s.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,s)=>{D0(o,s,n,e,r)},mouseleave:o=>{O0(o)},mousedown:(o,s)=>{N0(o,s,e)}},decorations:o=>{let s=Ve.getState(o);if(s&&s.activeHandle>-1)return V0(o,s.activeHandle)},nodeViews:{}}});return i}var E0=class Mo{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 Mo(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Mo(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 Mo(i,t.dragging)}return t}};function D0(n,e,t,r,i){let o=Ve.getState(n.state);if(o&&!o.dragging){let s=R0(e.target),l=-1;if(s){let{left:c,right:a}=s.getBoundingClientRect();e.clientX-c<=t?l=Ad(n,e,"left",t):a-e.clientX<=t&&(l=Ad(n,e,"right",t))}if(l!=o.activeHandle){if(!i&&l!==-1){let c=n.state.doc.resolve(l),a=c.node(-1),h=_.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}Ud(n,l)}}}function O0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Ud(n,-1)}function N0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,o=Ve.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;let s=n.state.doc.nodeAt(o.activeHandle),l=I0(n,o.activeHandle,s.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&&(v0(n,d.activeHandle,Td(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=Td(d.dragging,h,t);_0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function I0(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let o=n.domAtPos(e),l=o.node.childNodes[o.offset].offsetWidth,c=t;if(r)for(let a=0;a1){let s=[],l=null;r.forEach((m,g,y)=>{y===0&&(l=e+1),m.textContent&&s.push(m.textContent)});let c=s[0]||"columns",a=r.child(0).type,h=n.doc.type.schema.nodes.paragraph.create(null,n.doc.type.schema.text(c)),d=a.create({colspan:o,rowspan:1},h),u=n.doc.type.schema.nodes.table_row.create(null,d),p=l+r.nodeSize-1;n.replaceWith(l,p,u)}else if(r.childCount===1){let s=e+1,l=r.child(0);n.setNodeMarkup(s,null,{...l.attrs,colspan:o,rowspan:1})}return n}function Bd(n){for(let e=n.depth;e>0;e-=1){let t=n.node(e);if(t.type.name==="table"){let r=n.start(e)-1;return{table:t,tableStart:r,depth:e}}}return null}function P0(n,e){if(!e)return Ul(n,e);let t=n.selection.$from.pos;return Ul(n,i=>{try{let o=i.doc.resolve(t),s=Bd(o);if(s){let l=i.doc.nodeAt(s.tableStart);l&&Vd(i,s.tableStart,l)}}catch(o){console.warn("Could not fix header row colspan:",o)}e(i)})}function L0(n,e){if(!e)return Vl(n,e);let t=n.selection.$from.pos;return Vl(n,i=>{try{let o=i.doc.resolve(t),s=Bd(o);if(s){let l=i.doc.nodeAt(s.tableStart);l&&Vd(i,s.tableStart,l)}}catch(o){console.warn("Could not fix header row colspan:",o)}e(i)})}var Sr={};pp(Sr,{AbsolutePosition:()=>jo,AbstractConnector:()=>dc,AbstractStruct:()=>yr,AbstractType:()=>W,Array:()=>On,ContentAny:()=>Kt,ContentBinary:()=>In,ContentDeleted:()=>wr,ContentDoc:()=>Rn,ContentEmbed:()=>At,ContentFormat:()=>L,ContentJSON:()=>ki,ContentString:()=>Re,ContentType:()=>Ae,Doc:()=>We,GC:()=>ue,ID:()=>Ct,Item:()=>O,Map:()=>Nn,PermanentUserData:()=>uc,RelativePosition:()=>ot,Skip:()=>ie,Snapshot:()=>jt,Text:()=>lt,Transaction:()=>Yo,UndoManager:()=>En,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>it,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>ct,XmlHook:()=>Si,XmlText:()=>xe,YArrayEvent:()=>Qo,YEvent:()=>Dn,YMapEvent:()=>Zo,YTextEvent:()=>es,YXmlEvent:()=>ts,applyUpdate:()=>Mc,applyUpdateV2:()=>vn,cleanupYTextFormatting:()=>Ru,compareIDs:()=>kn,compareRelativePositions:()=>rs,convertUpdateFormatV1ToV2:()=>u1,convertUpdateFormatV2ToV1:()=>mu,createAbsolutePositionFromRelativePosition:()=>Oc,createDeleteSet:()=>br,createDeleteSetFromStructStore:()=>Sc,createDocFromSnapshot:()=>Qw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>Ci,createSnapshot:()=>Mi,decodeRelativePosition:()=>jw,decodeSnapshot:()=>Gw,decodeSnapshotV2:()=>nu,decodeStateVector:()=>Tc,decodeUpdate:()=>s1,decodeUpdateV2:()=>au,diffUpdate:()=>h1,diffUpdateV2:()=>Nc,emptySnapshot:()=>Xw,encodeRelativePosition:()=>$w,encodeSnapshot:()=>Yw,encodeSnapshotV2:()=>tu,encodeStateAsUpdate:()=>Ac,encodeStateAsUpdateV2:()=>Qf,encodeStateVector:()=>Dc,encodeStateVectorFromUpdate:()=>l1,encodeStateVectorFromUpdateV2:()=>du,equalDeleteSets:()=>Gf,equalSnapshots:()=>Kw,findIndexSS:()=>ze,findRootTypeKey:()=>_n,getItem:()=>Cn,getState:()=>P,getTypeChildren:()=>y1,isDeleted:()=>Tt,isParentOf:()=>Tn,iterateDeletedStructs:()=>nt,logType:()=>Fw,logUpdate:()=>o1,logUpdateV2:()=>cu,mergeDeleteSets:()=>Mn,mergeUpdates:()=>hu,mergeUpdatesV2:()=>yi,obfuscateUpdate:()=>d1,obfuscateUpdateV2:()=>f1,parseUpdateMeta:()=>c1,parseUpdateMetaV2:()=>fu,readUpdate:()=>Bw,readUpdateV2:()=>Cc,relativePositionToJSON:()=>qw,snapshot:()=>Ai,snapshotContainsUpdate:()=>e1,transact:()=>R,tryGc:()=>r1,typeListToArraySnapshot:()=>cs,typeMapGetAllSnapshot:()=>Eu,typeMapGetSnapshot:()=>x1});var U=()=>new Map,Ao=n=>{let e=U();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},Pd=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Ld=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var To=n=>n[n.length-1];var zd=(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)||U()).values()).forEach(r=>r(...t))}destroy(){this._observers=U()}},tr=class{constructor(){this._observers=U()}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)||U()).values()).forEach(r=>r(...t))}destroy(){this._observers=U()}};var fe=Math.floor;var nr=Math.abs;var De=(n,e)=>nn>e?n:e,pS=Number.isNaN,Hd=Math.pow;var Do=n=>n!==0?n<0:1/n<0;var Pl=Number.MAX_SAFE_INTEGER,mS=Number.MIN_SAFE_INTEGER,gS=1<<31;var Jd=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&fe(n)===n),yS=Number.isNaN,wS=Number.parseInt;var Ll=String.fromCharCode,bS=String.fromCodePoint,xS=Ll(65535),z0=n=>n.toLowerCase(),F0=/^\s*/g,q0=n=>n.replace(F0,""),H0=/([A-Z])/g,zl=(n,e)=>q0(n.replace(H0,t=>`${e}${z0(t)}`));var J0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;iir.encode(n),Wd=ir?$0:J0;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)=>qd(e,()=>n).join("");var wn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},F=()=>new wn;var No=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(No(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=Do(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)},Fl=new Uint8Array(3e4),j0=Fl.length/3,K0=(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),o=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,o>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Be(t*2,o)),n.cbuf.set(e.subarray(i)),n.cpos=o)},V=(n,e)=>{x(n,e.byteLength),ar(n,e)},ql=(n,e)=>{W0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},G0=(n,e)=>ql(n,4).setFloat32(0,e,!1),X0=(n,e)=>ql(n,8).setFloat64(0,e,!1),Q0=(n,e)=>ql(n,8).setBigInt64(0,e,!1);var Yd=new DataView(new ArrayBuffer(4)),Z0=n=>(Yd.setFloat32(0,n),Yd.getFloat32(0)===n),sr=(n,e)=>{switch(typeof e){case"string":Q(n,119),Xe(n,e);break;case"number":Jd(e)&&nr(e)<=2147483647?(Q(n,125),ni(n,e)):Z0(e)?(Q(n,124),G0(n,e)):(Q(n,123),X0(n,e));break;case"bigint":Q(n,122),Q0(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 Gd=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++:(Gd(this),this.count=1,this.s=e)}toUint8Array(){return Gd(this),I(this.encoder)}};var Xd=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++):(Xd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Xd(this),I(this.encoder)}},Oo=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="",Xe(e,this.sarr.join("")),ar(e,this.lensE.toUint8Array()),I(e)}};var Qe=n=>new Error(n),Oe=()=>{throw Qe("Method unimplemented")},j=()=>{throw Qe("Unexpected case")};var Zd=Qe("Unexpected end of array"),ef=Qe("Integer out of Range"),hr=class{constructor(e){this.arr=e,this.pos=0}},q=n=>new hr(n),Hl=n=>n.pos!==n.arr.length;var ew=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>ew(n,k(n));var xn=n=>n.arr[n.pos++];var k=n=>{let e=0,t=1,r=n.arr.length;for(;n.posPl)throw ef}throw Zd},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 o=n.arr.length;for(;n.posPl)throw ef}throw Zd};var tw=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))}},nw=n=>rr.decode(K(n)),Le=rr?nw:tw;var Jl=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},rw=n=>Jl(n,4).getFloat32(0,!1),iw=n=>Jl(n,8).getFloat64(0,!1),ow=n=>Jl(n,8).getBigInt64(0,!1);var sw=[n=>{},n=>null,ii,rw,iw,ow,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;rsw[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),Hl(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=Do(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}},vo=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 CS=crypto.subtle,tf=crypto.getRandomValues.bind(crypto);var lw=Math.random,$l=()=>tf(new Uint32Array(1))[0];var nf=n=>n[fe(lw()*n.length)],cw="10000000-1000-4000-8000"+-1e11,rf=()=>cw.replace(/[018]/g,n=>(n^$l()&15>>n/4).toString(16));var Ne=Date.now;var Wl=n=>new Promise(n);var TS=Promise.all.bind(Promise);var jl=n=>n===void 0?null:n;var Kl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},sf=new Kl,Yl=!0;try{typeof localStorage<"u"&&localStorage&&(sf=localStorage,Yl=!1)}catch{}var Uo=sf,lf=n=>Yl||addEventListener("storage",n),cf=n=>Yl||removeEventListener("storage",n);var df=Object.assign,Vo=Object.keys,ff=(n,e)=>{for(let t in n)e(n[t],t)},uf=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Gl=n=>Vo(n).length,hf=n=>Vo(n).length;var pf=n=>{for(let e in n)return!1;return!0},dw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Xl=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Ql=(n,e)=>n===e||hf(n)===hf(e)&&dw(n,(t,r)=>(t!==void 0||Xl(e,r))&&e[r]===t),fw=Object.freeze,Zl=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&Zl(n[e])}return fw(n)};var si=(n,e,t=0)=>{try{for(;tn,uw=(n,e)=>n===e;var ur=(n,e)=>{if(n==null||e==null)return uw(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 St=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"&&!St,ES=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,Ze,pw=[],mw=()=>{if(Ze===void 0)if(St){Ze=U();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");Ze.set(`--${zl(e,"-")}`,t),Ze.set(`-${zl(e,"-")}`,t)}})):Ze=U();return Ze},nc=n=>mw().has(n);var li=n=>St?jl(process.env[n.toUpperCase().replaceAll("-","_")]):jl(Uo.getItem(n));var gf=n=>nc("--"+n)||li(n)!==null,DS=gf("production"),gw=St&&mf(process.env.FORCE_COLOR,["true","1","2"]),yf=gw||!nc("--no-colors")&&!gf("no-color")&&(!St||process.stdout.isTTY)&&(!St||nc("--color")||li("COLORTERM")!==null||(li("TERM")||"").includes("color"));var wf=n=>new Uint8Array(n),yw=(n,e,t)=>new Uint8Array(n,e,t),bf=n=>new Uint8Array(n),ww=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),xw=n=>{let e=atob(n),t=wf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return yw(e.buffer,e.byteOffset,e.byteLength)},xf=pr?ww:bw,Sf=pr?xw:Sw;var kf=n=>{let e=wf(n.byteLength);return e.set(n),e};var rc=class{constructor(e,t){this.left=e,this.right=t}},et=(n,e)=>new rc(n,e);var kt=typeof document<"u"?document:{};var OS=typeof DOMParser<"u"?new DOMParser:null;var Mf=n=>Pd(n,(e,t)=>`${t}:${e};`).join("");var NS=kt.ELEMENT_NODE,IS=kt.TEXT_NODE,RS=kt.CDATA_SECTION_NODE,vS=kt.COMMENT_NODE,_S=kt.DOCUMENT_NODE,US=kt.DOCUMENT_TYPE_NODE,VS=kt.DOCUMENT_FRAGMENT_NODE;var Po=n=>class{constructor(t){this._=t}destroy(){n(this._)}},Cw=Po(clearTimeout),ai=(n,e)=>new Cw(setTimeout(e,n)),PS=Po(clearInterval);var LS=Po(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var zS=Po(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var tt=Symbol;var hi=tt(),di=tt(),ic=tt(),oc=tt(),sc=tt(),fi=tt(),lc=tt(),mr=tt(),cc=tt(),Ef=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=U(),i=[],o=0;for(;o0||c.length>0?(e.push("%c"+s),t.push(c)):e.push(s)}else break}}for(o>0&&(i=t,i.unshift(e.join("")));o{console.log(...Df(n)),Of.forEach(e=>e.print(n))},ac=(...n)=>{console.warn(...Df(n)),n.unshift(mr),Of.forEach(e=>e.print(n))};var Of=Ce();var Nf=n=>({[Symbol.iterator](){return this},next:n}),If=(n,e)=>Nf(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),zo=(n,e)=>Nf(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var dc=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}},nt=(n,e,t)=>e.clients.forEach((r,i)=>{let o=n.doc.store.clients.get(i);for(let s=0;s{let t=0,r=n.length-1;for(;t<=r;){let i=fe((t+r)/2),o=n[i],s=o.clock;if(s<=e){if(e{let t=n.clients.get(e.client);return t!==void 0&&Rw(t,e.clock)!==null},xc=n=>{n.clients.forEach(e=>{e.sort((i,o)=>i.clock-o.clock);let t,r;for(t=1,r=1;t=o.clock?i.len=Be(i.len,o.clock+o.len-i.clock):(r{let e=new $t;for(let t=0;t{if(!e.clients.has(i)){let o=r.slice();for(let s=t+1;s{$(n.clients,e,()=>[]).push(new pi(t,r))},br=()=>new $t,Sc=n=>{let e=br();return n.clients.forEach((t,r)=>{let i=[];for(let o=0;o0&&e.clients.set(r,i)}),e},rt=(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 o=0;o{let e=new $t,t=k(n.restDecoder);for(let r=0;r0){let s=$(e.clients,i,()=>[]);for(let l=0;l{let r=new $t,i=k(n.restDecoder);for(let o=0;o0){let o=new Ie;return x(o.restEncoder,0),rt(o,r),o.toUint8Array()}return null},Gf=(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 o=0;o!0,meta:o=null,autoLoad:s=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Xf(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ko,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=s,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Wl(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>Wl(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 o=new t;return o._integrate(this,null),o}),i=r.constructor;if(t!==W&&i!==t)if(i===W){let o=new t;o._map=r._map,r._map.forEach(s=>{for(;s!==null;s=s.left)s.parent=o}),o._start=r._start;for(let s=o._start;s!==null;s=s.right)s.parent=o;return o._length=r._length,this.share.set(e,o),o._integrate(this,null),o}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,lt)}getMap(e=""){return this.get(e,Nn)}getXmlElement(e=""){return this.get(e,Z)}getXmlFragment(e=""){return this.get(e,ct)}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 kf(K(this.restDecoder))}readJSON(){return JSON.parse(Le(this.restDecoder))}readKey(){return Le(this.restDecoder)}},Wo=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 Wo{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 vo(K(e)),this.parentInfoDecoder=new ri(K(e),xn),this.typeRefDecoder=new Sn(K(e)),this.lenDecoder=new Sn(K(e))}readLeftID(){return new Ct(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Ct(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 o=e[i];o.write(n,r-o.id.clock);for(let s=i+1;s{let r=new Map;t.forEach((i,o)=>{P(e,o)>i&&r.set(o,i)}),Ti(e).forEach((i,o)=>{t.has(o)||r.set(o,0)}),x(n.restEncoder,r.size),$e(r.entries()).sort((i,o)=>o[0]-i[0]).forEach(([i,o])=>{vw(n,e.clients.get(i),i,o)})},_w=(n,e)=>{let t=U(),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 o=()=>{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},s=o();if(s===null)return null;let l=new Ko,c=new Map,a=(u,p)=>{let m=c.get(u);(m==null||m>p)&&c.set(u,p)},h=s.refs[s.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(s!==null&&s.i0){let u=new Ie;return kc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},Vw=(n,e)=>kc(n,e.doc.store,e.beforeState),Cc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let o=!1,s=i.doc,l=s.store,c=_w(r,s),a=Uw(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=_f(r,i,l);if(l.pendingDs){let f=new be(q(l.pendingDs));k(f.restDecoder);let u=_f(f,i,l);d&&u?l.pendingDs=yi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(o){let f=l.pendingStructs.update;l.pendingStructs=null,vn(i.doc,f)}},t,!1),Bw=(n,e,t)=>Cc(n,e,t,new Me(n)),vn=(n,e,t,r=be)=>{let i=q(e);Cc(i,n,t,new r(i))},Mc=(n,e,t)=>vn(n,e,t,Me),Pw=(n,e,t=new Map)=>{kc(n,e.store,t),rt(n,Sc(e.store))},Qf=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Tc(e);Pw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Nc(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===it)return hu(i.map((o,s)=>s===0?o:mu(o)));if(t.constructor===Ie)return yi(i)}return i[0]},Ac=(n,e)=>Qf(n,e,new it),Zf=n=>{let e=new Map,t=k(n.restDecoder);for(let r=0;rZf(new An(q(n))),Ec=(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),Lw=(n,e)=>Ec(n,Ti(e.store)),zw=(n,e=new gr)=>(n instanceof Map?Ec(e,n):Lw(e,n),e.toUint8Array()),Dc=n=>zw(n,new Wt),fc=class{constructor(){this.l=[]}},Uf=()=>new fc,Vf=(n,e)=>n.l.push(e),Bf=(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.")},eu=(n,e,t)=>si(n.l,[e,t]),Ct=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 Ct(n,e),Pf=(n,e)=>{x(n,e.client),x(n,e.clock)},Lf=n=>M(k(n),k(n)),_n=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw j()},Tn=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1},Fw=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))},uc=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=(o,s)=>{let l=o.get("ds"),c=o.get("ids"),a=h=>this.clients.set(h,s);l.observe(h=>{h.changes.added.forEach(d=>{d.content.getContent().forEach(f=>{f instanceof Uint8Array&&this.dss.set(s,Mn([this.dss.get(s)||br(),Mt(new An(q(f)))]))})})}),this.dss.set(s,Mn(l.map(h=>Mt(new An(q(h)))))),c.observe(h=>h.changes.added.forEach(d=>d.content.getContent().forEach(a))),c.forEach(a)};t.observe(o=>{o.keysChanged.forEach(s=>i(t.get(s),s))}),t.forEach(i)}setUserMapping(e,t,r,{filter:i=()=>!0}={}){let o=this.yusers,s=o.get(r);s||(s=new Nn,s.set("ids",new On),s.set("ds",new On),o.set(r,s)),s.get("ids").push([t]),o.observe(l=>{setTimeout(()=>{let c=o.get(r);if(c!==s){s=c,this.clients.forEach((d,f)=>{r===d&&s.get("ids").push([f])});let a=new Wt,h=this.dss.get(r);h&&(rt(a,h),s.get("ds").push([a.toUint8Array()]))}},0)}),e.on("afterTransaction",l=>{setTimeout(()=>{let c=s.get("ds"),a=l.deleteSet;if(l.local&&a.clients.size>0&&i(l,a)){let h=new Wt;rt(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}},qw=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),jo=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},Hw=(n,e,t=0)=>new jo(n,e,t),Fo=(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 Fo(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Fo(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Fo(n,r.lastId,t);r=r.right}return Fo(n,null,t)},Jw=(n,e)=>{let{type:t,tname:r,item:i,assoc:o}=e;if(i!==null)x(n,0),Pf(n,i);else if(r!==null)cr(n,1),Xe(n,r);else if(t!==null)cr(n,2),Pf(n,t);else throw j();return ni(n,o),n},$w=n=>{let e=F();return Jw(e,n),I(e)},Ww=n=>{let e=null,t=null,r=null;switch(k(n)){case 0:r=Lf(n);break;case 1:t=Le(n);break;case 2:e=Lf(n)}let i=Hl(n)?ii(n):0;return new ot(e,t,r,i)},jw=n=>Ww(q(n)),Oc=(n,e,t=!0)=>{let r=e.store,i=n.item,o=n.type,s=n.tname,l=n.assoc,c=null,a=0;if(i!==null){if(P(r,i.client)<=i.clock)return null;let h=t?wc(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(s!==null)c=e.get(s);else if(o!==null){if(P(r,o.client)<=o.clock)return null;let{item:h}=t?wc(r,o):{item:Cn(r,o)};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 Hw(c,a,n.assoc)},rs=(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}},Kw=(n,e)=>{let t=n.ds.clients,r=e.ds.clients,i=n.sv,o=e.sv;if(i.size!==o.size||t.size!==r.size)return!1;for(let[s,l]of i.entries())if(o.get(s)!==l)return!1;for(let[s,l]of t.entries()){let c=r.get(s)||[];if(l.length!==c.length)return!1;for(let a=0;a(rt(e,n.ds),Ec(e,n.sv),e.toUint8Array()),Yw=n=>tu(n,new Wt),nu=(n,e=new Wo(q(n)))=>new jt(Mt(e),Zf(e)),Gw=n=>nu(n,new An(q(n))),Mi=(n,e)=>new jt(n,e),Xw=Mi(br(),new Map),Ai=n=>Mi(Sc(n.store),Ti(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),pc=(n,e)=>{let t=$(n.meta,pc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,o)=>{i{}),t.add(e))},Qw=(n,e,t=new We)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,o=new Ie;return n.transact(s=>{let l=0;r.forEach(c=>{c>0&&l++}),x(o.restEncoder,l);for(let[c,a]of r){if(a===0)continue;a{let r=new t(q(e)),i=new st(r,!1);for(let s=i.curr;s!==null;s=i.next())if((n.sv.get(s.id.client)||0)Zw(n,e,Me),Ko=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ti=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},ru=(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],o=i.id.clock;if(o===e)return r;let s=fe(e/(o+i.length-1)*r);for(;t<=r;){if(i=n[s],o=i.id.clock,o<=e){if(e{let t=n.clients.get(e.client);return t[ze(t,e.clock)]},Cn=t1,mc=(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[mc(n,t,e.clock)]},zf=(n,e,t)=>{let r=e.clients.get(t.client),i=ze(r,t.clock),o=r[i];return t.clock!==o.id.clock+o.length-1&&o.constructor!==ue&&r.splice(i+1,0,ns(n,o,t.clock-o.id.clock+1)),o},n1=(n,e,t)=>{let r=n.clients.get(e.id.client);r[ze(r,e.id.clock)]=t},iu=(n,e,t,r,i)=>{if(r===0)return;let o=t+r,s=mc(n,e,t),l;do l=e[s++],oe.deleteSet.clients.size===0&&!Ld(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(xc(e.deleteSet),Vw(n,e),rt(n,e.deleteSet),!0),qf=(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)},Jo=(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 o=e-i;return o&&n.splice(e+1-o,o),o},ou=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let o=e.clients.get(r);for(let s=i.length-1;s>=0;s--){let l=i[s],c=l.clock+l.len;for(let a=ze(o,l.clock),h=o[a];a{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let o=t.length-1;o>=0;o--){let s=t[o],l=De(i.length-1,1+ze(i,s.clock+s.len-1));for(let c=l,a=i[c];c>0&&a.id.clock>=s.clock;a=i[c])c-=1+Jo(i,c)}})},r1=(n,e,t)=>{ou(n,e,t),su(n,e)},lu=(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),eu(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),si(l,[]),t._needFormattingCleanup&&M1(t)}finally{r.gc&&ou(o,i,r.gcFilter),su(o,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+Jo(u,m)}});for(let h=s.length-1;h>=0;h--){let{client:d,clock:f}=s[h].id,u=i.clients.get(d),p=ze(u,f);p+11||p>0&&Jo(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(Lo(mr,hi,"[yjs] ",di,fi,"Changed the client-id because another client seems to be using it."),r.clientID=Xf()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new it;Ff(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;Ff(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])):lu(n,e+1)}}},R=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,o=!1,s=null;n._transaction===null&&(o=!0,n._transaction=new Yo(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{s=e(n._transaction)}finally{if(o){let l=n._transaction===i[0];n._transaction=null,l&&lu(i,0)}}return s},gc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Hf=(n,e,t)=>{nt(n,t.deletions,r=>{r instanceof O&&e.scope.some(i=>Tn(i,r))&&Uc(r,!1)})},Jf=(n,e,t)=>{let r=null,i=n.doc,o=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;nt(l,a.insertions,u=>{if(u instanceof O){if(u.redone!==null){let{item:p,diff:m}=wc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&o.some(p=>Tn(p,u))&&d.push(u)}}),nt(l,a.deletions,u=>{u instanceof O&&o.some(p=>Tn(p,u))&&!Tt(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=_u(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 s=n.currStackItem;if(s!=null){let l=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:s,type:t,changedParentTypes:l,origin:n},n]),n.currStackItem=null}return s},En=class extends er{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:s=!1,doc:l=Zr(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,o.add(this),this.trackedOrigins=o,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=s,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 T=c.beforeState.get(y)||0,N=g-T;N>0&&mi(f,y,T,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 gc(c.deleteSet,f)),p=!0;!a&&!h&&(this.lastChange=u),nt(c,c.deleteSet,g=>{g instanceof O&&this.scope.some(y=>Tn(y,g))&&Uc(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&&ac("[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=>Hf(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>Hf(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=Jf(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Jf(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*i1(n){let e=k(n.restDecoder);for(let t=0;tcu(n,Me),cu=(n,e=be)=>{let t=[],r=new e(q(n)),i=new st(r,!1);for(let s=i.curr;s!==null;s=i.next())t.push(s);Lo("Structs: ",t);let o=Mt(r);Lo("DeleteSet: ",o)},s1=n=>au(n,Me),au=(n,e=be)=>{let t=[],r=new e(q(n)),i=new st(r,!1);for(let o=i.curr;o!==null;o=i.next())t.push(o);return{structs:t,ds:Mt(r)}},gi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},hu=n=>yi(n,Me,it),du=(n,e=gr,t=be)=>{let r=new e,i=new st(new t(q(n)),!1),o=i.curr;if(o!==null){let s=0,l=o.id.client,c=o.id.clock!==0,a=c?0:o.id.clock+o.length;for(;o!==null;o=i.next())l!==o.id.client&&(a!==0&&(s++,x(r.restEncoder,l),x(r.restEncoder,a)),l=o.id.client,a=0,c=o.id.clock!==0),o.constructor===ie&&(c=!0),c||(a=o.id.clock+o.length);a!==0&&(s++,x(r.restEncoder,l),x(r.restEncoder,a));let h=F();return x(h,s),Qd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},l1=n=>du(n,Wt,Me),fu=(n,e=be)=>{let t=new Map,r=new Map,i=new st(new e(q(n)),!1),o=i.curr;if(o!==null){let s=o.id.client,l=o.id.clock;for(t.set(s,l);o!==null;o=i.next())s!==o.id.client&&(r.set(s,l),t.set(o.id.client,o.id.clock),s=o.id.client),l=o.id.clock+o.length;r.set(s,l)}return{from:t,to:r}},c1=n=>fu(n,Me),a1=(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 st(h,!0)),o=null,s=new t,l=new gi(s);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(o!==null){let f=h.curr,u=!1;for(;f!==null&&f.id.clock+f.length<=o.struct.id.clock+o.struct.length&&f.id.client>=o.struct.id.client;)f=h.next(),u=!0;if(f===null||f.id.client!==d||u&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(d!==o.struct.id.client)Ht(l,o.struct,o.offset),o={struct:f,offset:0},h.next();else if(o.struct.id.clock+o.struct.length0&&(o.struct.constructor===ie?o.struct.length-=p:f=a1(f,p)),o.struct.mergeWith(f)||(Ht(l,o.struct,o.offset),o={struct:f,offset:0},h.next())}}else o={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===d&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==ie;f=h.next())Ht(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(Ht(l,o.struct,o.offset),o=null),Ic(l);let c=r.map(h=>Mt(h)),a=Mn(c);return rt(s,a),s.toUint8Array()},Nc=(n,e,t=be,r=Ie)=>{let i=Tc(e),o=new r,s=new gi(o),l=new t(q(n)),c=new st(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(s,h,Be(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Ht(s,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=f;)c.next()}Ic(s);let a=Mt(l);return rt(o,a),o.toUint8Array()},h1=(n,e)=>Nc(n,e,Me,it),uu=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&&uu(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++},Ic=n=>{uu(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(q(n)),o=new st(i,!1),s=new r,l=new gi(s);for(let a=o.curr;a!==null;a=o.next())Ht(l,e(a),0);Ic(l);let c=Mt(i);return rt(s,c),s.toUint8Array()},pu=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=U(),o=U(),s=U(),l=U();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=$(o,d.nodeName,()=>"node-"+r)),d instanceof Si&&(d.hookName=$(o,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 At:{let d=h;d.embed={};break}case L:{let d=h;n&&(d.key=$(s,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()}}},d1=(n,e)=>is(n,pu(e),Me,it),f1=(n,e)=>is(n,pu(e),be,Ie),u1=n=>is(n,ec,Me,Ie),mu=n=>is(n,ec,be,it),$f="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=p1(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 Qe($f);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let o=t._map.get(i),s,l;if(this.adds(o)){let c=o.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(o))if(c!==null&&this.deletes(c))s="delete",l=To(c.content.getContent());else return;else c!==null&&this.deletes(c)?(s="update",l=To(c.content.getContent())):(s="add",l=void 0)}else if(this.deletes(o))s="delete",l=To(o.content.getContent());else return;e.set(i,{action:s,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 Qe($f);let t=this.target,r=Ce(),i=Ce(),o=[];if(e={added:r,deleted:i,delta:o,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null,c=()=>{l&&o.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}},p1=(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},oe=()=>{ac("Invalid access: Add Yjs type to a document before reading data.")},gu=80,Rc=0,yc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Rc++}},m1=n=>{n.timestamp=Rc++},yu=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Rc++},g1=(n,e,t)=>{if(n.length>=gu){let r=n.reduce((i,o)=>i.timestamp{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((o,s)=>nr(e-o.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 o=i.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(i.index-=o.length);if(o===null||o.marker===!0){n.splice(r,1);continue}i.p=o,o.marker=!0}(e0&&e===i.index)&&(i.index=Be(e,i.index+t))}},y1=n=>{n.doc??oe();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},ls=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;eu(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=Uf(),this._dEH=Uf(),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){Bf(this._eH,e)}unobserveDeep(e){Bf(this._dEH,e)}toJSON(){}},wu=(n,e,t)=>{n.doc??oe(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],o=n._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){let s=o.content.getContent();if(s.length<=e)e-=s.length;else{for(let l=e;l0;l++)i.push(s[l]),r--;e=0}}o=o.right}return i},bu=n=>{n.doc??oe();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 o=0;o{let t=0,r=n._start;for(n.doc??oe();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let o=0;o{let t=[];return bi(n,(r,i)=>{t.push(e(r,i,n))}),t},w1=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}}}},Su=(n,e)=>{n.doc??oe();let t=ss(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,o=n.doc,s=o.clientID,l=o.store,c=t===null?e._start:t.right,a=[],h=()=>{a.length>0&&(i=new O(M(s,P(l,s)),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(s,P(l,s)),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(s,P(l,s)),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(s,P(l,s)),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()},ku=()=>Qe("Length exceeded!"),Cu=(n,e,t,r)=>{if(t>e._length)throw ku();if(t===0)return e._searchMarker&&wi(e._searchMarker,t,r.length),Go(n,e,null,r);let i=t,o=ss(e,t),s=e._start;for(o!==null&&(s=o.p,t-=o.index,t===0&&(s=s.prev,t+=s&&s.countable&&!s.deleted?s.length:0));s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<=s.length){t{let i=(e._searchMarker||[]).reduce((o,s)=>s.index>o.index?s:o,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Go(n,e,i,t)},Mu=(n,e,t,r)=>{if(r===0)return;let i=t,o=r,s=ss(e,t),l=e._start;for(s!==null&&(l=s.p,t-=s.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t0&&l!==null;)l.deleted||(r0)throw ku();e._searchMarker&&wi(e._searchMarker,i,-o+r)},Xo=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},vc=(n,e,t,r)=>{let i=e._map.get(t)||null,o=n.doc,s=o.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(s,P(o.store,s)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},_c=(n,e)=>{n.doc??oe();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Au=n=>{let e={};return n.doc??oe(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Tu=(n,e)=>{n.doc??oe();let t=n._map.get(e);return t!==void 0&&!t.deleted},x1=(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},Eu=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let o=r;for(;o!==null&&(!e.sv.has(o.id.client)||o.id.clock>=(e.sv.get(o.id.client)||0));)o=o.left;o!==null&&qt(o,e)&&(t[i]=o.content.getContent()[o.length-1])}),t},qo=n=>(n.doc??oe(),If(n._map.entries(),e=>!e[1].deleted)),Qo=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??oe(),this._length}_callObserver(e,t){super._callObserver(e,t),ls(this,e,new Qo(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{Cu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{b1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Mu(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return Su(this,e)}toArray(){return bu(this)}slice(e=0,t=this.length){return wu(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return xu(this,e)}forEach(e){bi(this,e)}[Symbol.iterator](){return w1(this)}_write(e){e.writeTypeRef(F1)}},S1=n=>new On,Zo=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){ls(this,e,new Zo(this,e,t))}toJSON(){this.doc??oe();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[...qo(this)].length}keys(){return zo(qo(this),e=>e[0])}values(){return zo(qo(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return zo(qo(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??oe(),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=>{Xo(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return _c(this,e)}has(e){return Tu(this,e)}clear(){this.doc!==null?R(this.doc,e=>{this.forEach(function(t,r,i){Xo(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(q1)}},k1=n=>new Nn,Jt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Ql(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}},Wf=(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,o=r?ss(e,t):null;if(o){let s=new xi(o.p.left,o.p,o.index,i);return Wf(n,s,t-o.index)}else{let s=new xi(null,e._start,0,i);return Wf(n,s,t)}},Du=(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,o=i.clientID;r.forEach((s,l)=>{let c=t.left,a=t.right,h=new O(M(o,P(i.store,o)),c,c&&c.lastId,a,a&&a.id,e,null,new L(l,s));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)},Ou=(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()}},Nu=(n,e,t,r)=>{let i=n.doc,o=i.clientID,s=new Map;for(let l in r){let c=r[l],a=t.currentAttributes.get(l)??null;if(!Jt(a,c)){s.set(l,a);let{left:h,right:d}=t;t.right=new O(M(o,P(i.store,o)),h,h&&h.lastId,d,d&&d.id,e,null,new L(l,c)),t.right.integrate(n,0),t.forward()}}return s},hc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let o=n.doc,s=o.clientID;Ou(t,i);let l=Nu(n,e,t,i),c=r.constructor===String?new Re(r):r instanceof W?new Ae(r):new At(r),{left:a,right:h,index:d}=t;e._searchMarker&&wi(e._searchMarker,t.index,c.getLength()),h=new O(M(s,P(o.store,s)),a,a&&a.lastId,h,h&&h.id,e,null,c),h.integrate(n,0),t.right=h,t.index=d,t.forward(),Du(n,e,t,l)},jf=(n,e,t,r,i)=>{let o=n.doc,s=o.clientID;Ou(t,i);let l=Nu(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(s,P(o.store,s)),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()}Du(n,e,t,l)},Iu=(n,e,t,r,i)=>{let o=e,s=U();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===L){let a=o.content;s.set(a.key,a)}o=o.right}let l=0,c=!1;for(;e!==o;){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;(s.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},C1=(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}},Ru=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,o=U(),s=Ao(o);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case L:xr(s,i.content);break;default:e+=Iu(t,r,i,o,s),o=Ao(s),r=i;break}i=i.right}}),e},M1=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let o=n.beforeState.get(r)||0;i!==o&&iu(n,t.store.clients.get(r),o,i,s=>{!s.deleted&&s.content.constructor===L&&s.constructor!==ue&&e.add(s.parent)})}R(t,r=>{nt(n,n.deleteSet,i=>{if(i instanceof ue||!i.parent._hasFormatting||e.has(i.parent))return;let o=i.parent;i.content.constructor===L?e.add(o):C1(r,i)});for(let i of e)Ru(i)})},Kf=(n,e,t)=>{let r=t,i=Ao(e.currentAttributes),o=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Ae:case At: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,o=new Map,s=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},pf(c)||(u.attributes=df({},c))),h=0;break}u&&t.push(u),l=null}};for(;s!==null;){switch(s.content.constructor){case Ae:case At:this.adds(s)?this.deletes(s)||(f(),l="insert",a=s.content.getContent()[0],f()):this.deletes(s)?(l!=="delete"&&(f(),l="delete"),d+=1):s.deleted||(l!=="retain"&&(f(),l="retain"),h+=1);break;case Re:this.adds(s)?this.deletes(s)||(l!=="insert"&&(f(),l="insert"),a+=s.content.str):this.deletes(s)?(l!=="delete"&&(f(),l="delete"),d+=s.length):s.deleted||(l!=="retain"&&(f(),l="retain"),h+=s.length);break;case L:{let{key:u,value:p}=s.content;if(this.adds(s)){if(!this.deletes(s)){let m=i.get(u)??null;Jt(m,p)?p!==null&&s.delete(r):(l==="retain"&&f(),Jt(p,o.get(u)??null)?delete c[u]:c[u]=p)}}else if(this.deletes(s)){o.set(u,p);let m=i.get(u)??null;Jt(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!s.deleted){o.set(u,p);let m=c[u];m!==void 0&&(Jt(m,p)?m!==null&&s.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}s.deleted||(l==="insert"&&f(),xr(i,s.content));break}}s=s.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}},lt=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??oe(),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 es(this,e,t);ls(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??oe();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 o=0;o0)&&hc(r,this,i,l,s.attributes||{})}else s.retain!==void 0?jf(r,this,i,s.retain,s.attributes||{}):s.delete!==void 0&&Kf(r,i,s.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){this.doc??oe();let i=[],o=new Map,s=this.doc,l="",c=this._start;function a(){if(l.length>0){let d={},f=!1;o.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=o.get("ychange");e!==void 0&&!qt(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),o.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(),o.set("ychange",r?r("added",c.id):{type:"added"})):d!==void 0&&(a(),o.delete("ychange")),l+=c.content.str;break}case Ae:case At:{a();let d={insert:c.content.getContent()[0]};if(o.size>0){let f={};d.attributes=f,o.forEach((u,p)=>{f[p]=u})}i.push(d);break}case L:qt(c,e)&&(a(),xr(o,c.content));break}c=c.right}a()};return e||t?R(s,d=>{e&&pc(d,e),t&&pc(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?R(i,o=>{let s=Ho(o,this,e,!r);r||(r={},s.currentAttributes.forEach((l,c)=>{r[c]=l})),hc(o,this,s,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?R(i,o=>{let s=Ho(o,this,e,!r);hc(o,this,s,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=>{Kf(i,Ho(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,o=>{let s=Ho(o,this,e,!1);s.right!==null&&jf(o,this,s,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xo(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return _c(this,e)}getAttributes(){return Au(this)}_write(e){e.writeTypeRef(H1)}},A1=n=>new lt,ui=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??oe()}[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===ct)&&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})}},ct=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??oe(),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){ls(this,e,new ts(this,t,e))}toString(){return xu(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,o=>{i.insertBefore(o.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{Cu(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;Go(r,this,i,t)});else{let r=this._prelimContent,i=e===null?0:r.findIndex(o=>o===e)+1;if(i===0&&e!==null)throw Qe("Reference item not found");r.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Mu(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return bu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Su(this,e)}slice(e=0,t=this.length){return wu(this,e,t)}forEach(e){bi(this,e)}_write(e){e.writeTypeRef($1)}},T1=n=>new ct,Z=class n extends ct{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 ff(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`<${o}${s}>${super.toString()}`}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Xo(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?R(this.doc,r=>{vc(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return _c(this,e)}hasAttribute(e){return Tu(this,e)}getAttributes(e){return e?Eu(this,e):Au(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),o=this.getAttributes();for(let s in o){let l=o[s];typeof l=="string"&&i.setAttribute(s,l)}return bi(this,s=>{i.appendChild(s.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(J1),e.writeKey(this.nodeName)}},E1=n=>new Z(n.readKey()),ts=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],o;return i!==void 0?o=i.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(e){e.writeTypeRef(W1),e.writeKey(this.hookName)}},D1=n=>new Si(n.readKey()),xe=class n extends lt{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 o=[];for(let s in e.attributes[i])o.push({key:s,value:e.attributes[i][s]});o.sort((s,l)=>s.keyi.nodeName=0;i--)r+=``;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(j1)}},O1=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()}},N1=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),ru(e.doc.store,this)}write(e,t){e.writeInfo(N1),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}},I1=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}},R1=n=>new wr(n.readLen()),vu=(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(vu(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}},v1=n=>new Rn(vu(n.readString(),n.readAny())),At=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}},_1=n=>new At(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}},U1=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}},L1=n=>new Re(n.readString()),z1=[S1,k1,A1,E1,T1,D1,O1],F1=0,q1=1,H1=2,J1=3,$1=4,W1=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}},K1=n=>new Ae(z1[n.readTypeRef()](n)),wc=(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}},Uc=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},ns=(n,e,t)=>{let{client:r,clock:i}=e.id,o=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&&o.markDeleted(),e.keep&&(o.keep=!0),e.redone!==null&&(o.redone=M(e.redone.client,e.redone.clock+t)),e.right=o,o.right!==null&&(o.right.left=o),n._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),e.length=t,o},Yf=(n,e)=>Fd(n,t=>Tt(t.deletions,e)),_u=(n,e,t,r,i,o)=>{let s=n.doc,l=s.store,c=s.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)||_u(n,h,t,r,i,o)===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)||Yf(o.undoStack,d.right.id)||Yf(o.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,Uc(g,!0),g.integrate(n,0),g},O=class n extends yr{constructor(e,t,r,i,o,s,l,c){super(e,c.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=o,this.parent=s,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===Ct&&this.id.client!==this.parent.client&&this.parent.clock>=P(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=zf(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===Ct){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=zf(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 o=new Set,s=new Set;for(;i!==null&&i!==this.right;){if(s.add(i),o.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),qf(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?n1(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,o=this.parentSub,s=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(o===null?0:32);if(e.writeInfo(s),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===Ct?(e.writeParentInfo(!1),e.writeLeftID(l)):j();o!==null&&e.writeString(o)}this.content.write(e,t)}},Uu=(n,e)=>Y1[e&31](n),Y1=[()=>{j()},R1,V1,I1,L1,_1,U1,K1,P1,v1,()=>{j()}],G1=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(G1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Vu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Bu="__ $YJS$ __";Vu[Bu]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Vu[Bu]=!0;var Pu=new Map,Vc=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:Sf(t.newValue||"")}),lf(this._onChange)}postMessage(e){Uo.setItem(this.room,xf(bf(e)))}close(){cf(this._onChange)}},X1=typeof BroadcastChannel>"u"?Vc:BroadcastChannel,Bc=n=>$(Pu,n,()=>{let e=Ce(),t=new X1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Lu=(n,e)=>(Bc(n).subs.add(e),e),zu=(n,e)=>{let t=Bc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Pu.delete(n)),r},Vn=(n,e,t=null)=>{let r=Bc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var Fu=0,as=1,qu=2,hs=(n,e)=>{x(n,Fu);let t=Dc(e);V(n,t)},Pc=(n,e,t)=>{x(n,as),V(n,Ac(e,t))},Z1=(n,e,t)=>Pc(e,t,K(n)),Hu=(n,e,t)=>{try{Mc(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},Ju=(n,e)=>{x(n,qu),V(n,e)},eb=Hu,$u=(n,e,t,r)=>{let i=k(n);switch(i){case Fu:Z1(n,e,t);break;case as:Hu(n,t,r);break;case qu:eb(n,t,r);break;default:throw new Error("Unknown message type")}return i};var nb=0;var Wu=(n,e,t)=>{switch(k(n)){case nb:t(e,Le(n))}};var Lc=3e4,ds=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&&Lc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,o)=>{o!==this.clientID&&Lc<=t-i.lastUpdated&&this.states.has(o)&&r.push(o)}),r.length>0&&fs(this,r,"timeout")},fe(Lc/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,o=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Ne()});let s=[],l=[],c=[],a=[];e===null?a.push(t):o==null?e!=null&&s.push(t):(l.push(t),ur(o,e)||c.push(t)),(s.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:s,updated:c,removed:a},"local"]),this.emit("update",[{added:s,updated:l,removed:a},"local"])}setLocalStateField(e,t){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}},fs=(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 o=0;o{let r=q(e),i=Ne(),o=[],s=[],l=[],c=[],a=k(r);for(let h=0;h0||l.length>0||c.length>0)&&n.emit("change",[{added:o,updated:l,removed:c},t]),(o.length>0||s.length>0||c.length>0)&&n.emit("update",[{added:o,updated:s,removed:c},t])};var Ku=n=>uf(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,Gu=3,Cr=1,sb=2,Ei=[];Ei[Bn]=(n,e,t,r,i)=>{x(n,Bn);let o=$u(e,n,t.doc,t);r&&o===as&&!t.synced&&(t.synced=!0)};Ei[Gu]=(n,e,t,r,i)=>{x(n,Cr),V(n,kr(t.awareness,Array.from(t.awareness.getStates().keys())))};Ei[Cr]=(n,e,t,r,i)=>{ju(t.awareness,K(e),t)};Ei[sb]=(n,e,t,r,i)=>{Wu(e,t.doc,(o,s)=>lb(t,s))};var Yu=3e4,lb=(n,e)=>console.warn(`Permission denied to access ${n.url}. -${e}`),Xu=(n,e,t)=>{let r=q(e),i=F(),o=k(r),s=n.messageHandlers[o];return s?s(i,r,n,t,o):console.error("Unable to compute message"),i},Qu=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=Xu(n,new Uint8Array(t.data),!0);No(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,fs(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Qu,De(Hd(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),hs(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=F();x(r,Cr),V(r,kr(n.awareness,[n.doc.clientID])),e.send(I(r))}},n.emit("status",[{status:"connecting"}])}},zc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},Fc=class extends tr{constructor(e,t,r,{connect:i=!0,awareness:o=new ds(r),params:s={},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=s,this.protocols=l,this.roomname=t,this.doc=r,this._WS=c,this.awareness=o,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=d,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Ei.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),hs(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=Xu(this,new Uint8Array(f),!1);No(p)>1&&Vn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=F();x(p,Bn),Ju(p,f),zc(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),V(y,kr(o,g)),zc(this,I(y))},this._exitHandler=()=>{fs(this.awareness,[r.clientID],"app closed")},St&&typeof process<"u"&&process.on("exit",this._exitHandler),o.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Yu{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var cb=/[\uD800-\uDBFF]/,ab=/[\uDC00-\uDFFF]/,hb=(n,e)=>{let t=0,r=0;for(;t0&&cb.test(n[t-1])&&t--;r+t0&&ab.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},ep=hb;var v=new le("y-sync"),Et=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),db=[{light:"#ecd44433",dark:"#ecd444"}],fb=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,nf(e))}return n.get(t)},rp=(n,{colors:e=db,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:o}={})=>{let s=!1,l=new us(n,o),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),o==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(s||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(s=!0,h.addToHistory===!1&&!h.isChangeOrigin){let d=Et.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},ub=(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)}),us=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Zu(),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(),o=kt.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||o.clientWidth||0)&&i.top<=(window.innerHeight||o.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(o=>{let s=r.permanentUserData;s&&s.dss.forEach(h=>{nt(o,h,d=>{})});let l=(h,d)=>{let f=h==="added"?s.getUserByClientId(d.client):s.getUserByDeletedId(d);return{user:f,type:h,color:fb(r.colorMapping,r.colors,f)}},c=cs(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);nt(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 o=this.type.toArray().map(l=>ip(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),s=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(w.from(o),0,0));ub(s,this.beforeTransactionSelection,this),s=s.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof En}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&s.scrollIntoView(),this.prosemirrorView.dispatch(s)})}_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))}},ip=(n,e,t,r,i,o)=>{let s=t.get(n);if(s===void 0){if(n instanceof Z)return Oi(n,e,t,r,i,o);throw Oe()}return s},Oi=(n,e,t,r,i,o)=>{let s=[],l=c=>{if(c.constructor===Z){let a=ip(c,e,t,r,i,o);a!==null&&s.push(a)}else{let a=c._item.right?.content.type;a instanceof lt&&!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=pb(c,e,t,r,i,o);h!==null&&h.forEach(d=>{d!==null&&s.push(d)})}};r===void 0||i===void 0?n.toArray().forEach(l):cs(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=o?o("added",n._item.id):{type:"added"}):c.ychange=o?o("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,s);return t.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},v),t.delete(n),null}},pb=(n,e,t,r,i,o)=>{let s=[],l=n.toDelta(r,i,o);try{for(let c=0;c{n._item.delete(a)},v),null}return s},mb=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:sp(i.marks)}));return t.applyDelta(r),e.set(t,n),t},gb=(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,ms(n).map(r=>qc(r,e))),e.set(t,n),t},qc=(n,e)=>n instanceof Array?mb(n,e):gb(n,e),tp=n=>typeof n=="object"&&n!==null,Jc=(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&&Vo(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(o=>Jc(r.attributes[o.type.name]||{},o.attrs)))},Ri=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Hc(n,e)){let t=ms(e);return n._length===t.length&&Jc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Ri(r,t[i]))}return n instanceof xe&&e instanceof Array&&op(n,e)},ps=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),np=(n,e,t)=>{let r=n.toArray(),i=ms(e),o=i.length,s=r.length,l=De(s,o),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}},wb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=yb(n),o=e.map(a=>({insert:a.text,attributes:Object.assign({},r,sp(a.marks))})),{insert:s,remove:l,index:c}=ep(i,o.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,s),n.applyDelta(o.map(a=>({retain:a.insert.length,attributes:a.attributes})))},sp=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=ms(t),o=i.length,s=e.toArray(),l=s.length,c=De(o,l),a=0,h=0;for(;a{for(;l-a-h>0&&o-a-h>0;){let f=s[a],u=i[a],p=s[l-h-1],m=i[o-h-1];if(f instanceof xe&&u instanceof Array)op(f,u)||wb(f,u,r),a+=1;else{let g=f instanceof Z&&Hc(f,u),y=p instanceof Z&&Hc(p,m);if(g&&y){let T=np(f,u,r),N=np(p,m,r);T.foundMappedChild&&!N.foundMappedChild?y=!1:!T.foundMappedChild&&N.foundMappedChild||T.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,bb=()=>{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((o,s)=>{r.setMeta(s,o)}),t.dispatch(r))})},$c=(n,e,t)=>{vi||(vi=new Map,ai(0,bb)),$(vi,n,U).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 xb(r._item.parent,r._item)}return Ci(e,e._length,-1)},xb=(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=Oc(t,n);if(i===null||i.type!==e&&!Tn(e,i.type._item))return null;let o=i.type,s=0;if(o.constructor===xe)s=i.index;else if(o._item===null||!o._item.deleted){let l=o._first,c=0;for(;ci(void 0)};return Mr(r,t,n,new Map),t}function cp(n,e="prosemirror"){return jc(n.getXmlFragment(e))}function jc(n){let e=n.toArray();function t(r){let i;if(!r.nodeName)i=r.toDelta().map(s=>{let l={type:"text",text:s.insert};return s.attributes&&(l.marks=Object.keys(s.attributes).map(c=>{let a=s.attributes[c],h={type:c};return Object.keys(a)&&(h.attrs=a),h})),l});else{i={type:r.nodeName};let o=r.getAttributes();Object.keys(o).length&&(i.attrs=o);let s=r.toArray();s.length&&(i.content=s.map(t).flat())}return i}return{type:"doc",content:e.map(t)}}var Sb=(n,e,t)=>n!==e,kb=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},Cb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Mb=/^#[0-9a-fA-F]{6}$/,ap=(n,e,t,r,i)=>{let o=v.getState(n),s=o.doc,l=[];return o.snapshot!=null||o.prevSnapshot!=null||o.binding.mapping.size===0?z.create(n.doc,[]):(e.getStates().forEach((c,a)=>{if(t(s.clientID,a,c)&&c.cursor!=null){let h=c.user||{};h.color==null?h.color="#ffa500":Mb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Yt(s,o.type,Un(c.cursor.anchor),o.binding.mapping),f=Yt(s,o.type,Un(c.cursor.head),o.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))},Ab=(n,{awarenessStateFilter:e=Sb,cursorBuilder:t=kb,selectionBuilder:r=Cb,getSelection:i=s=>s.selection}={},o="cursor")=>new H({key:Di,state:{init(s,l){return ap(l,n,e,t,r)},apply(s,l,c,a){let h=v.getState(a),d=s.getMeta(Di);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?ap(a,n,e,t,r):l.map(s.mapping,s.doc)}},props:{decorations:s=>Di.getState(s)},view:s=>{let l=()=>{s.docView&&$c(s,Di,{awarenessUpdated:!0})},c=()=>{let a=v.getState(s.state),h=n.getLocalState()||{};if(s.hasFocus()){let d=i(s.state),f=Pn(d.anchor,a.type,a.binding.mapping),u=Pn(d.head,a.type,a.binding.mapping);(h.cursor==null||!rs(Un(h.cursor.anchor),f)||!rs(Un(h.cursor.head),u))&&n.setLocalStateField(o,{anchor:f,head:u})}else h.cursor!=null&&Yt(a.doc,a.type,Un(h.cursor.anchor),a.binding.mapping)!==null&&n.setLocalStateField(o,null)};return n.on("change",l),s.dom.addEventListener("focusin",c),s.dom.addEventListener("focusout",c),{update:c,destroy:()=>{s.dom.removeEventListener("focusin",c),s.dom.removeEventListener("focusout",c),n.off("change",l),n.setLocalStateField(o,null)}}}});var Tb=n=>{let e=Et.getState(n).undoManager;if(e!=null)return e.undo(),!0},Eb=n=>{let e=Et.getState(n).undoManager;if(e!=null)return e.redo(),!0},Db=new Set(["paragraph"]),Ob=(n,e)=>!(n instanceof O)||!(n.content instanceof Ae)||!(n.content.type instanceof lt||n.content.type instanceof Z&&e.has(n.content.type.nodeName))||n.content.type._length===0,Nb=({protectedNodes:n=Db,trackedOrigins:e=[],undoManager:t=null}={})=>new H({key:Et,state:{init:(r,i)=>{let o=v.getState(i),s=t||new En(o.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Ob(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:s,prevSel:null,hasUndoOps:s.undoStack.length>0,hasRedoOps:s.redoStack.length>0}},apply:(r,i,o,s)=>{let l=v.getState(s).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Ii(l,o),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),o=Et.getState(r.state).undoManager;return o.on("stack-item-added",({stackItem:s})=>{let l=i.binding;l&&s.meta.set(l,Et.getState(r.state).prevSel)}),o.on("stack-item-popped",({stackItem:s})=>{let l=i.binding;l&&(l.beforeTransactionSelection=s.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{o.destroy()}}}});var _i="http://www.w3.org/2000/svg",Ib="http://www.w3.org/1999/xlink",Kc="ProseMirror-icon";function Rb(n){let e=0;for(let t=0;t{o.preventDefault(),r.classList.contains(Dt+"-disabled")||t.run(e.state,e.dispatch,e,o)});function i(o){if(t.select){let l=t.select(o);if(r.style.display=l?"":"none",!l)return!1}let s=!0;if(t.enable&&(s=t.enable(o)||!1,hp(r,Dt+"-disabled",!s)),t.active){let l=s&&t.active(o)||!1;hp(r,Dt+"-active",l)}return!0}return{dom:r,update:i}}};function gs(n,e){return n._props.translate?n._props.translate(e):e}var Ui={time:0,node:null};function Ub(n){Ui.time=Date.now(),Ui.node=n.target}function Vb(n){return Date.now()-100{s&&s.close()&&(s=null,r.removeEventListener("mousedown",l))};i.addEventListener("mousedown",h=>{h.preventDefault(),Ub(h),s?c():(s=this.expand(o,t.dom),r.addEventListener("mousedown",l=()=>{Vb(o)||c()}))});function a(h){let d=t.update(h);return o.style.display=d?"":"none",d}return{dom:o,update:a}}expand(e,t){let r=yt("div",{class:Dt+"-dropdown-menu "+(this.options.class||"")},t),i=!1;function o(){return i?!1:(i=!0,e.removeChild(r),!0)}return e.appendChild(r),{close:o,node:r}}};function Bb(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iWr(n),icon:Vi.join}),Fk=new at({title:"Lift out of enclosing block",run:jr,select:n=>jr(n),icon:Vi.lift}),qk=new at({title:"Select parent node",run:Kr,select:n=>Kr(n),icon:Vi.selectParentNode}),Hk=new at({title:"Undo last change",run:Xr,enable:n=>Xr(n),icon:Vi.undo}),Jk=new at({title:"Redo last undone change",run:Qn,enable:n=>Qn(n),icon:Vi.redo});function zb(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 at(t)}function Fb(n,e){let t=pn(n,e.attrs),r={run:t,enable(i){return t(i)},active(i){let{$from:o,to:s,node:l}=i.selection;return l?l.hasMarkup(n,e.attrs):s<=o.end()&&o.parent.hasMarkup(n,e.attrs)}};for(let i in e)r[i]=e[i];return new at(r)}function hp(n,e,t){t?n.classList.add(e):n.classList.remove(e)}export{zn as DOMParser,It as DOMSerializer,Yc as Dropdown,Bs as EditorState,sl as EditorView,w as Fragment,wt as InputRule,at as MenuItem,H as Plugin,le as PluginKey,Dr as Schema,b as Slice,A as TextSelection,Fc as WebsocketProvider,Sr as Y,L0 as addColumnAfter,P0 as addColumnBefore,fy as addListNodes,s0 as addRowAfter,o0 as addRowBefore,cd as baseKeymap,Fg as baseSchema,Fb as blockTypeItem,Ly as buildKeymap,T0 as columnResizing,r0 as deleteColumn,c0 as deleteRow,g0 as deleteTable,Id as fixTables,Ny as gapCursor,m0 as goToNextCell,pd as inputRules,He as isInTable,Sy as keymap,bl as liftListItem,h0 as mergeCells,lp as prosemirrorToYDoc,Wc as prosemirrorToYXmlFragment,Pb as renderGrouped,Je as selectedRect,pn as setBlockType,xl as sinkListItem,d0 as splitCell,wl as splitListItem,B0 as tableEditing,Jy as tableNodes,mn as toggleMark,Xn as wrapIn,uo as wrapInList,zb as wrapItem,Ab as yCursorPlugin,cp as yDocToProsemirrorJSON,Eb as yRedo,rp as ySyncPlugin,Tb as yUndo,Nb as yUndoPlugin,Et as yUndoPluginKey,jc as yXmlFragmentToProsemirrorJSON}; +`);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 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 7192926a..6bbb4292 100644 --- a/deps/da-y-wrapper/src/index.js +++ b/deps/da-y-wrapper/src/index.js @@ -9,7 +9,6 @@ import { keymap } from 'prosemirror-keymap'; import { buildKeymap } from 'prosemirror-example-setup'; import { gapCursor } from 'prosemirror-gapcursor'; - import { tableEditing, columnResizing, @@ -17,6 +16,8 @@ import { selectedRect, tableNodes, fixTables, + addColumnAfter, + addColumnBefore, deleteColumn, addRowAfter, addRowBefore, @@ -25,8 +26,8 @@ import { splitCell, deleteTable, isInTable, + TableMap, } from 'prosemirror-tables'; -import { addColumnAfterWrapper, addColumnBeforeWrapper } from './table-wrappers.js'; // yjs import * as Y from 'yjs'; @@ -72,8 +73,8 @@ export { selectedRect, tableNodes, fixTables, - addColumnAfterWrapper as addColumnAfter, - addColumnBeforeWrapper as addColumnBefore, + addColumnAfter, + addColumnBefore, deleteColumn, addRowAfter, addRowBefore, @@ -81,6 +82,7 @@ export { mergeCells, splitCell, deleteTable, + TableMap, gapCursor, MenuItem, Dropdown, diff --git a/deps/da-y-wrapper/src/table-wrappers.js b/deps/da-y-wrapper/src/table-wrappers.js deleted file mode 100644 index 8f5e92d8..00000000 --- a/deps/da-y-wrapper/src/table-wrappers.js +++ /dev/null @@ -1,133 +0,0 @@ -import { - addColumnAfter, - addColumnBefore, - TableMap, -} from 'prosemirror-tables'; - -/** - * Fix the block header to ensure it maintains a single cell with full colspan. - */ -function fixHeaderRowColspan(tr, tableStart, table) { - const firstRow = table.child(0); - const map = TableMap.get(table); - const totalCols = map.width; - - if (firstRow.childCount === 1 && firstRow.child(0).attrs.colspan === totalCols) { - return tr; - } - - if (firstRow.childCount > 1) { - const contents = []; - let firstCellPos = null; - - firstRow.forEach((cell, offset, index) => { - if (index === 0) { - firstCellPos = tableStart + 1; - } - - if (cell.textContent) { - contents.push(cell.textContent); - } - }); - - const blockName = contents[0] || 'columns'; - - // Create a new cell with the correct colspan - const cellType = firstRow.child(0).type; - const para = tr.doc.type.schema.nodes.paragraph.create( - null, - tr.doc.type.schema.text(blockName), - ); - const newCell = cellType.create( - { colspan: totalCols, rowspan: 1 }, - para, - ); - - // Create new row with single merged cell - const rowType = tr.doc.type.schema.nodes.table_row; - const newRow = rowType.create(null, newCell); - - // Replace the entire first row - const firstRowEnd = firstCellPos + firstRow.nodeSize - 1; - tr.replaceWith(firstCellPos, firstRowEnd, newRow); - } else if (firstRow.childCount === 1) { - const cellPos = tableStart + 1; - const cell = firstRow.child(0); - tr.setNodeMarkup(cellPos, null, { - ...cell.attrs, - colspan: totalCols, - rowspan: 1, - }); - } - - return tr; -} - -/** - * Find the table node that contains a resolved position - */ -function findTableFromPos($pos) { - for (let d = $pos.depth; d > 0; d -= 1) { - const node = $pos.node(d); - if (node.type.name === 'table') { - const tableStart = $pos.start(d) - 1; // Position before the table - return { table: node, tableStart, depth: d }; - } - } - return null; -} - -// ensures header row maintains its colspan when adding columns -export function addColumnBeforeWrapper(state, dispatch) { - if (!dispatch) { - return addColumnBefore(state, dispatch); - } - - const originalPos = state.selection.$from.pos; - - const result = addColumnBefore(state, (tr) => { - try { - const $pos = tr.doc.resolve(originalPos); - const tableInfo = findTableFromPos($pos); - if (tableInfo) { - const updatedTable = tr.doc.nodeAt(tableInfo.tableStart); - if (updatedTable) { - fixHeaderRowColspan(tr, tableInfo.tableStart, updatedTable); - } - } - } catch (e) { - // eslint-disable-next-line no-console - console.warn('Could not fix header row colspan:', e); - } - dispatch(tr); - }); - - return result; -} - -// ensures header row maintains its colspan when adding columns -export function addColumnAfterWrapper(state, dispatch) { - if (!dispatch) { - return addColumnAfter(state, dispatch); - } - - const originalPos = state.selection.$from.pos; - const result = addColumnAfter(state, (tr) => { - try { - const $pos = tr.doc.resolve(originalPos); - const tableInfo = findTableFromPos($pos); - if (tableInfo) { - const updatedTable = tr.doc.nodeAt(tableInfo.tableStart); - if (updatedTable) { - fixHeaderRowColspan(tr, tableInfo.tableStart, updatedTable); - } - } - } catch (e) { - // eslint-disable-next-line no-console - console.warn('Could not fix header row colspan:', e); - } - dispatch(tr); - }); - - return result; -} diff --git a/test/unit/blocks/edit/prose/table-modifications.test.js b/test/unit/blocks/edit/prose/table-modifications.test.js index 3a668fa4..cb72fae4 100644 --- a/test/unit/blocks/edit/prose/table-modifications.test.js +++ b/test/unit/blocks/edit/prose/table-modifications.test.js @@ -14,9 +14,11 @@ 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; @@ -30,14 +32,32 @@ describe('Table Modifications', () => { describe('Column Operations - Header Row Colspan', () => { it('should maintain header colspan when adding column before', async () => { - editor = await createTestEditor(); + 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 secondRowPos = view.state.doc.resolve(5); // Position in second row + 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), ); @@ -58,17 +78,39 @@ describe('Table Modifications', () => { 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(); + 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 secondRowPos = view.state.doc.resolve(6); + 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), ); @@ -89,6 +131,10 @@ describe('Table Modifications', () => { 3, 'Header should span 3 columns after adding one', ); + expect(updatedFirstRow.child(0).textContent).to.equal( + customBlockName, + 'Block name should be preserved', + ); }); }); });