diff --git a/deps/da-y-wrapper/dist/index.js b/deps/da-y-wrapper/dist/index.js index 94a7eeab..ad8d8a93 100644 --- a/deps/da-y-wrapper/dist/index.js +++ b/deps/da-y-wrapper/dist/index.js @@ -1,12 +1,13 @@ -var rp=Object.defineProperty;var ip=(n,e)=>{for(var t in e)rp(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 po=se;function Zc(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=Zc(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function ea(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?Vi(r+1,o):Vi(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}};E.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=na(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(ta(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(y.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(y.empty,0,0);function ta(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(ta(s.content,e-i-1,t-i-1)))}function na(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=na(o.content,e-s-1,t);return l&&n.replaceChild(i,o.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 ra(n,e,t,0)}function ra(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&&bo(n,e,i+1),o=r.depth>i&&bo(t,r,i+1),l=[];return Ar(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(ia(s,o),Gt(Xt(s,sa(n,e,t,r,i+1)),l)):(s&&Gt(Xt(s,Pi(n,e,i+1)),l),Ar(e,t,i,l),o&&Gt(Xt(o,Pi(t,r,i+1)),l)),Ar(r,null,i,l),new y(l)}function Pi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=bo(n,e,t+1);Gt(Xt(i,Pi(n,e,t+1)),r)}return Ar(e,null,t,r),new y(r)}function op(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(y.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var Li=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){for(let i=0;ie&&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()+")"),oa(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=y.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=null;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=y.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,i,r)}};qe.prototype.text=void 0;var xo=class n extends qe{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):oa(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 oa(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 So(e,t);if(r.next==null)return n.empty;let i=la(r);r.next&&r.err("Unexpected trailing text");let s=mp(pp(i));return gp(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 So=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 la(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(hp(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function hp(n){let e=up(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=dp(n,e);else break;return e}function Kc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function dp(n,e){let t=Kc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Kc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function fp(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.groups.indexOf(e)>-1&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function up(n){if(n.eat("(")){let e=la(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=fp(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 pp(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}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}},ko=class{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}},Dr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=da(i.attrs),this.excluded=null;let s=aa(this.attrs);this.instance=s?new E(this,s):null}create(e=null){return!e&&this.instance?this.instance:new E(this,ha(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}},Tr=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=po.from(e.nodes),t.marks=po.from(e.marks||{}),this.nodes=zi.compile(this.spec.nodes,this),this.marks=Dr.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?Yc(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==""?[]:Yc(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 zi){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 xo(r,r.defaultAttrs,e,E.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return qe.fromJSON(this,e)}markFromJSON(e){return E.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Yc(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 yp(n){return n.tag!=null}function wp(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[],t.forEach(r=>{yp(r)?this.tags.push(r):wp(r)&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let i=e.nodes[r.node];return i.contentMatch.matchType(i)})}parse(e,t={}){let r=new Hi(this,t,!1);return r.addAll(e,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Hi(this,t,!0);return r.addAll(e,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=Xc(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=Xc(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)))}},fa={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},bp={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ua={ol:!0,ul:!0},Fi=1,qi=2,Er=4;function Gc(n,e,t){return e!=null?(e?Fi:0)|(e==="full"?qi:0):n&&n.whitespace=="pre"?Fi|qi:t&~Er}var Ln=class{constructor(e,t,r,i,s,o,l){this.type=e,this.attrs=t,this.marks=r,this.pendingMarks=i,this.solid=s,this.options=l,this.content=[],this.activeMarks=E.none,this.stashMarks=[],this.match=o||(l&Er?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(y.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&Fi)){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=y.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(y.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}popFromStashMark(e){for(let t=this.stashMarks.length-1;t>=0;t--)if(e.eq(this.stashMarks[t]))return this.stashMarks.splice(t,1)[0]}applyPending(e){for(let t=0,r=this.pendingMarks;tthis.addAll(e)),o&&this.sync(l),this.needsBlock=c}else this.withStyleRules(e,()=>{this.addElementByRule(e,s,s.consuming===!1?i:void 0)})}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` -`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let t=E.none,r=E.none;for(let i=0;i{o.clearMark(l)&&(r=l.addToSet(r))}):t=this.parser.schema.marks[o.mark].create(o.attrs).addToSet(t),o.consuming===!1)s=o;else break}return[t,r]}addElementByRule(e,t,r){let i,s,o;t.node?(s=this.parser.schema.nodes[t.node],s.isLeaf?this.insertNode(s.create(t.attrs))||this.leafFallback(e):i=this.enter(s,t.attrs||null,t.preserveWhitespace)):(o=this.parser.schema.marks[t.mark].create(t.attrs),this.addPendingMark(o));let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c));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)}i&&this.sync(l)&&this.open--,o&&this.removePendingMark(o,l)}addAll(e,t,r){let i=t||0;for(let s=t?e.childNodes[t]:e.firstChild,o=r==null?null:e.childNodes[r];s!=o;s=s.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(s);this.findAtPoint(e,i)}findPlace(e){let t,r;for(let i=this.open;i>=0;i--){let s=this.nodes[i],o=s.findWrapping(e);if(o&&(!t||t.length>o.length)&&(t=o,r=s,!o.length)||s.solid)break}if(!t)return!1;this.sync(r);for(let i=0;ithis.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.groups.indexOf(a)==-1)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}}addPendingMark(e){let t=Mp(e,this.top.pendingMarks);t&&this.top.stashMarks.push(t),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,t){for(let r=this.open;r>=0;r--){let i=this.nodes[r];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let o=i.popFromStashMark(e);o&&i.type&&i.type.allowsMarkType(o.type)&&(i.activeMarks=o.addToSet(i.activeMarks))}if(i==t)break}}};function xp(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ua.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Sp(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function kp(n){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,t,r=[];for(;t=e.exec(n);)r.push(t[1],t[2].trim());return r}function Xc(n){let e={};for(let t in n)e[t]=n[t];return e}function Cp(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&&n.renderSpec(wo(r),i(e,t))}static renderSpec(e,t,r=null){if(typeof t=="string")return{dom:e.createTextNode(t)};if(t.nodeType!=null)return{dom:t};if(t.dom&&t.dom.nodeType!=null)return t;let i=t[0],s=i.indexOf(" ");s>0&&(r=i.slice(0,s),i=i.slice(s+1));let o,l=r?e.createElementNS(r,i):e.createElement(i),c=t[1],a=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){a=2;for(let h in c)if(c[h]!=null){let d=h.indexOf(" ");d>0?l.setAttributeNS(h.slice(0,d),h.slice(d+1),c[h]):l.setAttribute(h,c[h])}}for(let h=a;ha)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:f,contentDOM:u}=n.renderSpec(e,d,r);if(l.appendChild(f),u){if(o)throw new RangeError("Multiple content holes");o=u}}}return{dom:l,contentDOM:o}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Qc(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Qc(e.marks)}};function Qc(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function wo(n){return n.document||window.document}var ga=65535,ya=Math.pow(2,16);function Ep(n,e){return n+e*ya}function pa(n){return n&ga}function Dp(n){return(n-(n&ga))/ya}var wa=1,ba=2,Ji=4,xa=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&xa)>0}get deletedBefore(){return(this.delInfo&(wa|Ji))>0}get deletedAfter(){return(this.delInfo&(ba|Ji))>0}get deletedAcross(){return(this.delInfo&Ji)>0}},ct=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=pa(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:Ep(l/3,e-c),m=e==c?ba:e==d?wa:Ji;return(t<0?e!=c:e!=d)&&(m|=xa),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=pa(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 Z.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))}};Y.jsonID("addMark",vr);var tn=class n extends Y{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(To(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Z.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))}};Y.jsonID("removeMark",tn);var _r=class n extends Y{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Z.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Z.fromReplace(e,this.pos,this.pos+1,new b(y.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)}};Y.jsonID("replaceAround",G);function Eo(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 Tp(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 Op(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 Dr){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 Np(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),s=[],o=e+1;for(let l=0;l=0;l--)n.step(s[l])}function Ip(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=y.from(r.node(p).copy(h)),d++):c--;let f=y.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=y.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new G(i,s,i,s,new b(r,0,0),t.length,!0))}function Vp(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)=>{if(o.isTextblock&&!o.hasMarkup(r,i)&&Bp(n.doc,n.mapping.slice(s).map(l),r)){n.clearIncompatible(n.mapping.slice(s).map(l,1),r);let c=n.mapping.slice(s),a=c.map(l,1),h=c.map(l+o.nodeSize,1);return n.step(new G(a,h,a+1,h-1,new b(y.from(r.create(i,null,o.marks)),0,0),1,!0)),!1}})}function Bp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Pp(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 G(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(y.from(o),0,0),1,!0))}function Nt(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 Lp(n,e,t=1,r){let i=n.doc.resolve(e),s=y.empty,o=y.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=y.from(i.node(l).copy(s));let h=r&&r[a];o=y.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Me(e,e,new b(s.append(o),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Sa(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Sa(n,e){return!!(n&&e&&!n.isLeaf&&n.canAppend(e))}function Oo(n,e,t=-1){let r=n.resolve(e);for(let i=r.depth;;i--){let s,o,l=r.index(i);if(i==r.depth?(s=r.nodeBefore,o=r.nodeAfter):t>0?(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&&Sa(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 zp(n,e,t){let r=new Me(e-t,e+t,b.empty,!0);n.step(r)}function Fp(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 ji(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Ca(i,s,r)?new Me(e,t,r):new Do(i,s,r).fit()}function Ca(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Do=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=y.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=y.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 G(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Me(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=Mo(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(y.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=Mo(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=Mo(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(Ma(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,y.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=Ao(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,y.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(y.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 Mo(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Ma(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(y.empty,!0)))),n.copy(r)}function Ao(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&&!qp(t,s.content,o)?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;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=Hp(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 Aa(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(y.empty,!0))}return n}function Wp(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Fp(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(y.from(r),0,0))}function $p(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=Ea(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)return n.delete(r.before(o),t);n.delete(e,t)}function Ea(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 Wi=class n extends Y{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 Z.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 Z.fromReplace(e,this.pos,this.pos+1,new b(y.from(i),0,t.isLeaf?0:1))}getMap(){return ct.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)}};Y.jsonID("attr",Wi);var $i=class n extends Y{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 Z.ok(r)}getMap(){return ct.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)}};Y.jsonID("docAttr",$i);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=ji(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(y.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 Jp(this,e,t,r),this}replaceRangeWith(e,t,r){return Wp(this,e,t,r),this}deleteRange(e,t){return $p(this,e,t),this}lift(e,t){return Rp(this,e,t),this}join(e,t=1){return zp(this,e,t),this}wrap(e,t){return Up(this,e,t),this}setBlockType(e,t=e,r,i=null){return Vp(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Pp(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Wi(e,t,r)),this}setDocAttribute(e,t){return this.step(new $i(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof E)){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 Lp(this,e,t,r),this}addMark(e,t,r){return Tp(this,e,t,r),this}removeMark(e,t,r){return Op(this,e,t,r),this}clearIncompatible(e,t,r){return Np(this,e,t,r),this}};var No=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Br(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 Ae(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Ae(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Ae(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=No[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 No)throw new RangeError("Duplicate use of selection JSON ID "+e);return No[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var Br=class{constructor(e,t){this.$from=e,this.$to=t}},Da=!1;function Ta(n){!Da&&!n.parent.inlineContent&&(Da=!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){Ta(e),Ta(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 Gi(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 Oa(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 Na=1,Yi=2,Ia=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|=Yi,this}ensureMarks(e){return E.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&Yi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Yi,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)||E.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|=Ia,this}get scrolledIntoView(){return(this.updated&Ia)>0}};function Ra(n,e){return!e||!n?n:n.bind(e)}var sn=class{constructor(e,t,r){this.name=e,this.init=Ra(t.init,r),this.apply=Ra(t.apply,r)}},jp=[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=jp.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))})}},_o=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=qe.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 va(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=va(i,e,{})),t[r]=i}return t}var F=class{constructor(e){this.spec=e,this.props={},e.props&&va(e.props,this,this.props),this.key=e.key?e.key.key:_a("plugin")}getState(e){return e[this.key]}},Io=Object.create(null);function _a(n){return n in Io?n+"$"+ ++Io[n]:(Io[n]=0,n+"$")}var fe=class{constructor(e="key"){this.key=_a(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var ee=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Fr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Lo=null,ht=function(n,e,t){let r=Lo||(Lo=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},Yp=function(){Lo=null},fn=function(n,e,t,r){return t&&(Ua(n,e,t,r,-1)||Ua(n,e,t,r,1))},Gp=/^(img|br|input|textarea|hr)$/i;function Ua(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:He(n))){let s=n.parentNode;if(!s||s.nodeType!=1||Wr(n)||Gp.test(n.nodeName)||n.contentEditable=="false")return!1;e=ee(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?He(n):0}else return!1}}function He(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Xp(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=He(n)}else if(n.parentNode&&!Wr(n))e=ee(n),n=n.parentNode;else return null}}function Qp(n,e){for(;;){if(n.nodeType==3&&e2),Re=jn||(Je?/Mac/.test(Je.platform):!1),rm=Je?/Win/.test(Je.platform):!1,Le=/Android \d/.test(Vt),$r=!!Va&&"webkitFontSmoothing"in Va.documentElement.style,im=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function sm(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 at(n,e){return typeof n=="number"?n:n[e]}function om(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 Ba(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=Fr(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?sm(s):om(l),h=0,d=0;if(e.topa.bottom-at(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+at(i,"top")-a.top:e.bottom-a.bottom+at(i,"bottom")),e.lefta.right-at(r,"right")&&(h=e.right-a.right+at(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 lm(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=Fr(r));return e}function cm({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;gh(t,r==0?0:r-e)}function gh(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?hm(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:yh(t,i)}function hm(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 sl(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function dm(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 um(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&&!o||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!o&&(o=!0,c.left>r.left||c.top>r.top?i=l.posBefore:(c.right-1?i:n.docView.posFromDOM(e,t,-1)}function wh(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=um(n,r,i,e))}l==null&&(l=fm(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Pa(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Pr(It(ht(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==He(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Uo(c.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==He(r))){let c=r.childNodes[i-1],a=c.nodeType==3?ht(c,He(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Pr(It(a,1),!1)}if(s==null&&i=0)}function Pr(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 Uo(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 xh(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 gm(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return xh(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=bh(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=ht(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 ym=/[\u0590-\u08ac]/;function wm(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!ym.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:xh(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})}var La=null,za=null,Fa=!1;function bm(n,e,t){return La==e&&za==t?Fa:(La=e,za=t,Fa=t=="up"||t=="down"?gm(n,e,t):wm(n,e,t))}var ve=0,qa=1,ln=2,We=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ve,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;tee(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 Zi){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 Xi&&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?ee(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=ee(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:qa,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=We:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?ln:We}r=o}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(!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==ve&&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}},Ho=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=Ot.renderSpec(document,t.type.spec.toDOM(t,r))),new n(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&We||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=We&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ve){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=jo(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}=Ot.renderSpec(document,t.type.spec.toDOM(t)));!d&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let f=h;return h=Ch(h,r,t),a?c=new Jo(e,t,r,i,h,d||null,f,a,s,o+1):t.isText?new Qi(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=()=>y.empty)}return e}matchesNode(e,t,r){return this.dirty==ve&&e.eq(this.node)&&$o(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 Ko(this,o&&o.node,e);Cm(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?E.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),Sh(this.contentDOM,this.children,e),jn&&Mm(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=Am(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 Ho(this,s,t,i);e.input.compositionNodes.push(o),this.children=jo(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==We||!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=ve}updateOuterDeco(e){if($o(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=kh(this.dom,this.nodeDOM,Wo(this.outerDeco,this.node,t),Wo(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 Ha(n,e,t,r,i){Ch(r,e,n);let s=new Ut(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var Qi=class n extends Ut{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==We||this.dirty!=ve&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ve||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=ve,!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=We)}get domAtom(){return!1}isText(e){return this.node.text==e}},Zi=class extends un{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ve&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Jo=class extends Ut{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==We)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 Sh(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 km(n,e){return n.type.side-e.type.side}function Cm(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 Mm(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 Am(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 jo(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 ol(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(ls(t)){for(c=l;i&&!i.node;)i=i.parent;let h=i.node;if(i&&h.isAtom&&C.isSelectable(h)&&i.parent&&!(h.isInline&&Zp(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;a=new C(o==d?l:r.resolve(d))}}else{let h=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(h<0)return null;c=r.resolve(h)}if(!a){let h=e=="pointer"||n.state.selection.head{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Mh(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Dm(n){let e=n.domSelection(),t=document.createRange(),r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setEnd(r.parentNode,ee(r)+1):t.setEnd(r,0),t.collapse(!1),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&xe&&_t<=11&&(r.disabled=!0,r.disabled=!1)}function Ah(n,e){if(e instanceof C){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(ja(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else ja(n)}function ja(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function ll(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function Ya(n){return n.editable&&!n.hasFocus()?!1:Eh(n)}function Eh(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 Tm(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 Yo(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 Rt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Ga(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 Rt(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Yo(n.state,e);return i&&i instanceof C?Rt(n,i):!1}else if(!(Re&&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)?Rt(n,new C(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):$r?Rt(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 Rt(n,new A(e>0?r.$to:r.$from));{let i=Yo(n.state,e);return i?Rt(n,i):!1}}}function es(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function zr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Wn(n,e){return e<0?Om(n):Nm(n)}function Om(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(ze&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(zr(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Dh(t))break;{let l=t.previousSibling;for(;l&&zr(l,-1);)i=t.parentNode,s=ee(l),l=l.previousSibling;if(l)t=l,r=es(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?Go(n,t,r):i&&Go(n,i,s)}function Nm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=es(t),s,o;for(;;)if(r{n.state==i&&dt(n)},50)}function Xa(n,e){let t=n.state.doc.resolve(e);if(!(ue||rm)&&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 Qa(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||Re&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=Yo(n.state,e);if(o&&o instanceof C)return Rt(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof Ae?S.near(o,e):S.findFrom(o,e);return l?Rt(n,l):!1}return!1}function Za(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 eh(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function vm(n){if(!pe||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;eh(n,r,"true"),setTimeout(()=>eh(n,r,"false"),20)}return!1}function _m(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Um(n,e){let t=e.keyCode,r=_m(e);if(t==8||Re&&t==72&&r=="c")return Za(n,-1)||Wn(n,-1);if(t==46&&!e.shiftKey||Re&&t==68&&r=="c")return Za(n,1)||Wn(n,1);if(t==13||t==27)return!0;if(t==37||Re&&t==66&&r=="c"){let i=t==37?Xa(n,n.state.selection.from)=="ltr"?-1:1:-1;return Ga(n,i,r)||Wn(n,i)}else if(t==39||Re&&t==70&&r=="c"){let i=t==39?Xa(n,n.state.selection.from)=="ltr"?1:-1:1;return Ga(n,i,r)||Wn(n,i)}else{if(t==38||Re&&t==80&&r=="c")return Qa(n,-1,r)||Wn(n,-1);if(t==40||Re&&t==78&&r=="c")return vm(n)||Qa(n,1,r)||Wn(n,1);if(r==(Re?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Th(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")||Ot.fromSchema(n.state.schema),l=_h(),c=l.createElement("div");c.appendChild(o.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=vh[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 pp=Object.defineProperty;var mp=(n,e)=>{for(var t in e)pp(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 bo=oe;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),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=oa(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function la(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?zi(r+1,o):zi(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 en=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 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 ca(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(ca(s.content,e-i-1,t-i-1)))}function aa(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=aa(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function gp(n,e,t){if(t.openStart>n.depth)throw new en("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new en("Inconsistent open depths");return ha(n,e,t,0)}function ha(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 Dr(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&&(Qt(n.nodeAfter,r),s++));for(let l=s;li&&ko(n,e,i+1),o=r.depth>i&&ko(t,r,i+1),l=[];return Dr(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(da(s,o),Qt(Zt(s,fa(n,e,t,r,i+1)),l)):(s&&Qt(Zt(s,Hi(n,e,i+1)),l),Dr(e,t,i,l),o&&Qt(Zt(o,Hi(t,r,i+1)),l)),Dr(r,null,i,l),new w(l)}function Hi(n,e,t){let r=[];if(Dr(null,n,t,r),n.depth>t){let i=ko(n,e,t+1);Qt(Zt(i,Hi(n,e,t+1)),r)}return Dr(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 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 Ji=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 tn(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=Xc.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()+")"),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,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}};$e.prototype.text=void 0;var Mo=class n extends $e{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 nn=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Ao(e,t);if(r.next==null)return n.empty;let i=pa(r);r.next&&r.err("Unexpected trailing text");let s=Ep(Ap(i));return Tp(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(` +`)}};nn.empty=new nn(!0);var Ao=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 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 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(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 nn(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:ya(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new $e(this,this.computeAttrs(e),w.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=w.from(t),this.checkContent(t),new $e(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 $e(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 Dp(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 Eo=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}},Nr=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 s=ga(this.attrs);this.instance=s?new D(this,s):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((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},Ir=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=bo.from(e.nodes),t.marks=bo.from(e.marks||{}),this.nodes=$i.compile(this.spec.nodes,this),this.marks=Nr.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]=nn.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?ea(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==""?[]:ea(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 $i){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 Mo(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return $e.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(o=c)}if(!o)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 Jn=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 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 Ki(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Ki(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=na(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=na(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)))}},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},Wi=1,ji=2,Or=4;function ta(n,e,t){return e!=null?(e?Wi:0)|(e==="full"?ji:0):n&&n.whitespace=="pre"?Wi|ji:t&~Or}var Hn=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&Or?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&Wi)){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&&!xa.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Ki=class{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=ta(null,t.preserveWhitespace,0)|(r?Or:0);i?s=new Hn(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new Hn(null,null,D.none,!0,null,o):s=new Hn(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&ji||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&Wi)i.options&ji?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;Sa.hasOwnProperty(i)&&this.parser.normalizeLists&&Rp(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Ip.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(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=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):ra(a.type,e))?(c=a.addToSet(c),!1):!0),this.nodes.push(new Hn(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 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 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&&Fi(So(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Fi(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 So(n){return n.document||window.document}var sa=new WeakMap;function _p(n){let e=sa.get(n);return e===void 0&&sa.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 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}=Fi(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,Yi=4,Da=8,_r=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|Yi))>0}get deletedAfter(){return(this.delInfo&(Ta|Yi))>0}get deletedAcross(){return(this.delInfo&Yi)>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=ka(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:Bp(l/3,e-c),m=e==c?Ta:e==d?Ea:Yi;return(t<0?e!=c:e!=d)&&(m|=Da),new _r(u,m,p)}i+=h-a}return r?e+i:new _r(e+i,0,null)}touches(e,t){let r=0,i=ka(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 rn(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 rn=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(Ro(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",rn);var Br=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 No(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 Lp(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 zp(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 Nr){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 rn(o.from,o.to,o.style)))}function vo(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 Fp(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function sn(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 Wp(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)&&jp(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&&Na(n,o,l,s),vo(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&&Oa(n,o,l,s),!1}})}function Oa(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 Na(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 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 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 Yp(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 on(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?(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&&Ia(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 Xp(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);Na(n,h.node(),h.before(),l)}o.inlineContent&&vo(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);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 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 Zi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return va(i,s,r)?new Ee(e,t,r):new Io(i,s,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 Io=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=Do(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=Do(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=Do(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Rr(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Rr(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(_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=vr(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=Oo(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=vr(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=vr(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=vr(this.placed,this.frontier.length,t))}};function Rr(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Rr(n.firstChild.content,e-1,t)))}function vr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(vr(n.lastChild.content,e-1,t)))}function Do(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 Oo(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&&!Zp(t,s.content,o)?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;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=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=o[f];u<0||(e=i.before(u),t=s.after(u))}}function Ua(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 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),s=Va(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 Va(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 Gi=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 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",Gi);var Xi=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",Xi);var $n=class extends Error{};$n=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};$n.prototype=Object.create(Error.prototype);$n.prototype.constructor=$n;$n.prototype.name="TransformError";var Wn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Ur}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new $n(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=Zi(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 Gi(e,t,r)),this}setDocAttribute(e,t){return this.step(new Xi(e,t)),this}addNodeMark(e,t){return this.step(new Br(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 Pr(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 vo(this,e,t,r),this}};var Uo=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?jn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):jn(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 jn(e,e,0,0,1)||new Te(e)}static atEnd(e){return jn(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=Uo[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 Uo)throw new RangeError("Duplicate use of selection JSON ID "+e);return Uo[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 ts(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=jn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function La(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 za=1,es=2,Fa=4,Po=class extends Wn{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|=es,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&es)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~es,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|=Fa,this}get scrolledIntoView(){return(this.updated&Fa)>0}};function qa(n,e){return!e||!n?n:n.bind(e)}var ln=class{constructor(e,t,r){this.name=e,this.init=qa(t.init,r),this.apply=qa(t.apply,r)}},sm=[new ln("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new ln("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new ln("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new ln("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Lr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=sm.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 ln(r.key,r.spec.state,r))})}},Lo=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 Lr(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=$e.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 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 F=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]}},Vo=Object.create(null);function Ja(n){return n in Vo?n+"$"+ ++Vo[n]:(Vo[n]=0,n+"$")}var pe=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},Hr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Jo=null,ut=function(n,e,t){let r=Jo||(Jo=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},om=function(){Jo=null},pn=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 s=n.parentNode;if(!s||s.nodeType!=1||jr(n)||lm.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 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=Qn||(We?/Mac/.test(We.platform):!1),um=We?/Win/.test(We.platform):!1,Fe=/Android \d/.test(Lt),Kr=!!Wa&&"webkitFontSmoothing"in Wa.documentElement.style,pm=Kr?+(/\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 ft(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,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=Hr(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?mm(s):gm(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)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 ym(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: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=Hr(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){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?xm(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:Dh(t,i)}function xm(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 al(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(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function Cm(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 Oh(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;Kr&&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,o,e));let c=n.docView.nearestDesc(o,!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++,zr(_t(ut(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 zo(c.getBoundingClientRect(),!1)}if(s==null&&i<_e(r)){let c=r.childNodes[i];if(c.nodeType==1)return zo(c.getBoundingClientRect(),!0)}return zo(r.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==_e(r))){let c=r.childNodes[i-1],a=c.nodeType==3?ut(c,_e(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return zr(_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?ut(c,0,o?0:1):c.nodeType==1?c:null:null;if(a)return zr(_t(a,-1),!0)}return zr(_t(r.nodeType==3?ut(r):r,-t),t>=0)}function zr(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 zo(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: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=Nh(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=ut(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 Tm=/[\u0590-\u08ac]/;function Dm(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?!Tm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o: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,an=2,je=3,mn=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 is){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 ns&&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?an:Qa,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=je:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?an:je}r=o}this.dirty=an}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?an:Qa;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}},Ko=class extends mn{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}},Zn=class n extends mn{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&je||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=je&&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=Qo(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=_h(h,r,t),a?c=new Yo(e,t,r,i,h,d||null,f,a,s,o+1):t.isText?new rs(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)&&ss(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 Xo(this,o&&o.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==an)&&(o&&this.protectLocalComposition(e,o),Rh(this.contentDOM,this.children,e),Qn&&_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 s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Um(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 Ko(this,s,t,i);e.input.compositionNodes.push(o),this.children=Qo(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==je||!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(ss(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=vh(this.dom,this.nodeDOM,Go(this.outerDeco,this.node,t),Go(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 s=new Pt(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var rs=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==je||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=je)}get domAtom(){return!1}isText(e){return this.node.text==e}},is=class extends mn{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"}},Yo=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==je)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 Rh(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=Zn.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 Zn)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 Rm(n,e){return n.type.side-e.type.side}function vm(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 _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,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 Qo(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 hl(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(us(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&&hm(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(()=>{(!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 dl(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: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 pn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Zo(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 oh(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=Zo(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)):Kr?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=Zo(n.state,e);return i?Ut(n,i):!1}}}function ls(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function qr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Yn(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,s,o=!1;for(qe&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(qr(l,-1))i=t,s=--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&&qr(l,-1);)i=t.parentNode,s=te(l),l=l.previousSibling;if(l)t=l,r=ls(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?el(n,t,r):i&&el(n,i,s)}function zm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=ls(t),s,o;for(;;)if(r{n.state==i&&pt(n)},50)}function lh(n,e){let t=n.state.doc.resolve(e);if(!(ce||um)&&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 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:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=Zo(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 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 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 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)||Yn(n,-1);if(t==46&&!e.shiftKey||ve&&t==68&&r=="c")return ah(n,1)||Yn(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 oh(n,i,r)||Yn(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 oh(n,i,r)||Yn(n,i)}else{if(t==38||ve&&t==80&&r=="c")return ch(n,-1,r)||Yn(n,-1);if(t==40||ve&&t==78&&r=="c")return Hm(n)||ch(n,1,r)||Yn(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: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=$h(),c=l.createElement("div");c.appendChild(o.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} ${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 Oh(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(y.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=Ot.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=Pm(t),$r&&Lm(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&&!Vm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=zm(th(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Bm(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 Vm=/^(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 Bm(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&&Ih(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=Rh(o[o.length-1],s.length));let h=Nh(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return y.from(o)}return n}function Nh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,y.from(n));return n}function Ih(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(y.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function th(n,e,t){return e]*>)*/.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&&vh[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"").reverse().join("")),t.innerHTML=n,i)for(let s=0;s=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=y.from(c.create(r[l+1],i)),s++,o++}return new b(i,s,o)}var me={},ge={},Fm={touchstart:!0,touchmove:!0},Qo=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 me){let t=me[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Jm(n,r)&&!cl(n,r)&&(n.editable||!(r.type in ge))&&t(n,r)},Fm[e]?{passive:!0}:void 0)}pe&&n.dom.addEventListener("input",()=>null),Zo(n)}function vt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Hm(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 Zo(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>cl(n,r))})}function cl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Jm(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 Wm(n,e){!cl(n,e)&&me[e.type]&&(n.editable||!(e.type in ge))&&me[e.type](n,e)}ge.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Vh(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Le&&ue&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),jn&&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))||Um(n,t)?t.preventDefault():vt(n,"key")};ge.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ge.keypress=(n,e)=>{let t=e;if(Vh(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Re&&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 cs(n){return{left:n.clientX,top:n.clientY}}function $m(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function al(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 Kn(n,e,t){n.focused||n.focus();let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function Km(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&C.isSelectable(r)?(Kn(n,new C(t),"pointer"),!0):!1}function jm(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?(Kn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function Ym(n,e,t,r,i){return al(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?jm(n,t):Km(n,t))}function Gm(n,e,t,r){return al(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function Xm(n,e,t,r){return al(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||Qm(n,t,r)}function Qm(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Kn(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)Kn(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(C.isSelectable(o))Kn(n,C.create(r,l),"pointer");else continue;return!0}}function hl(n){return ts(n)}var Uh=Re?"metaKey":"ctrlKey";me.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=hl(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&$m(t,n.input.lastClick)&&!t[Uh]&&(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(cs(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new el(n,o,t,!!r)):(s=="doubleClick"?Gm:Xm)(n,o.pos,o.inside,t)?t.preventDefault():vt(n,"pointer"))};var el=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[Uh],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: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&&ze&&!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(()=>dt(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(cs(e))),this.updateAllowDefault(e),this.allowDefault||!t?vt(this.view,"pointer"):Ym(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||pe&&this.mightDrag&&!this.mightDrag.node.isAtom||ue&&!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)?(Kn(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)}};me.touchstart=n=>{n.input.lastTouch=Date.now(),hl(n),vt(n,"pointer")};me.touchmove=n=>{n.input.lastTouch=Date.now(),vt(n,"pointer")};me.contextmenu=n=>hl(n);function Vh(n,e){return n.composing?!0:pe&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var Zm=Le?5e3:-1;ge.compositionstart=ge.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$from;if(e.selection.empty&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),ts(n,!0),n.markCursor=null;else if(ts(n),ze&&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){n.domSelection().collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}Bh(n,Zm)};ge.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++,Bh(n,20))};function Bh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>ts(n),e))}function Ph(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=tg());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function eg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=Xp(e.focusNode,e.focusOffset),r=Qp(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc;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 tg(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function ts(n,e=!1){if(!(Le&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Ph(n),e||n.docView&&n.docView.dirty){let t=ol(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):n.updateState(n.state),!0}return!1}}function ng(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 qr=xe&&_t<15||jn&&im<604;me.copy=ge.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=qr?null:t.clipboardData,o=r.content(),{dom:l,text:c}=Th(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):ng(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function rg(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function ig(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?Hr(n,r.value,null,i,e):Hr(n,r.textContent,r.innerHTML,i,e)},50)}function Hr(n,e,t,r,i){let s=Oh(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=rg(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 Lh(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," "):""}ge.paste=(n,e)=>{let t=e;if(n.composing&&!Le)return;let r=qr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Hr(n,Lh(r),r.getData("text/html"),i,t)?t.preventDefault():ig(n,t)};var ns=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},zh=Re?"altKey":"ctrlKey";me.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(cs(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}=Th(n,l);t.dataTransfer.clearData(),t.dataTransfer.setData(qr?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",qr||t.dataTransfer.setData("text/plain",a),n.dragging=new ns(h,!t[zh],o)};me.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ge.dragover=ge.dragenter=(n,e)=>e.preventDefault();ge.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(cs(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=Oh(n,Lh(t.dataTransfer),qr?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[zh]);if(n.someProp("handleDrop",p=>p(n,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let c=o?ka(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,w,I)=>p=I),a.setSelection(ll(n,u,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))};me.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())&&dt(n)},20))};me.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)};me.beforeinput=(n,e)=>{if(ue&&Le&&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 ge)me[n]=ge[n];function Jr(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 rs=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 te(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&&Jr(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 te(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==oe||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=qh(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 P.empty;let r=[];for(let i=0;it instanceof P)?e:e.reduce((t,r)=>t.concat(r instanceof P?r:r.members),[]))}}};function sg(n,e,t,r,i,s,o){let l=n.slice();for(let a=0,h=s;a{let g=m-p-(u-f);for(let w=0;wI+h-d)continue;let z=l[w]+h-d;u>=z?l[w+1]=f<=z?-2:-1:f>=h&&g&&(l[w]+=g,l[w+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 w=l[a+2].mapInner(t,g,h+1,n[a]+s+1,o);w!=oe?(l[a]=d,l[a+1]=u,l[a+2]=w):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=og(l,n,e,t,i,s,o),h=ss(a,r,0,o);e=h.local;for(let d=0;dt&&o.to{let a=qh(n,l,c+t);if(a){s=!0;let h=ss(a,l,t+c+1,r);h!=oe&&i.push(c,c+l.nodeSize,h)}});let o=Fh(s?Hh(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function Bo(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=oe&&e.push(r)}),n.cursorWrapper&&e.push(P.create(n.state.doc,[n.cursorWrapper.deco])),is.from(e)}var lg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},cg=xe&&_t<=11,nl=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}},rl=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new nl,this.onCharData=null,this.suppressingSelectionUpdates=!1,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()}),cg&&(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,lg)),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(Ya(this.view)){if(this.suppressingSelectionUpdates)return dt(this.view);if(xe&&_t<=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=Fr(s))t.add(s);for(let s=e.anchorNode;s;s=Fr(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}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.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&Ya(e)&&!this.ignoreSelectionChange(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let h=0;h1){let h=c.filter(d=>d.nodeName=="BR");if(h.length==2){let d=h[0],f=h[1];d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.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),ag(e)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||dt(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 w=r.childNodes[g-1],I=w.pmViewDesc;if(w.nodeName=="BR"&&!I){s=g;break}if(!I||I.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:fg,context:u});if(a&&a[0].pos!=null){let g=a[0].pos,w=a[1]&&a[1].pos;w==null&&(w=g),p={anchor:g+o,head:w+o}}return{doc:m,sel:p,from:o,to:l}}function fg(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(pe&&/^(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||pe&&/^(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 ug=/^(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 pg(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let D=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,Tt=ol(n,D);if(Tt&&!n.state.selection.eq(Tt)){if(ue&&Le&&n.input.lastKeyCode===13&&Date.now()-100np(n,on(13,"Enter"))))return;let Ui=n.state.tr.setSelection(Tt);D=="pointer"?Ui.setMeta("pointer",!0):D=="key"&&Ui.scrollIntoView(),s&&Ui.setMeta("composition",s),n.dispatch(Ui)}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=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||Le)&&i.some(D=>D.nodeType==1&&!ug.test(D.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",D=>D(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 D=lh(n,n.state.doc,a.sel);if(D&&!D.eq(n.state.selection)){let Tt=n.state.tr.setSelection(D);s&&Tt.setMeta("composition",s),n.dispatch(Tt)}}return}n.input.domChangeCount++,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)),xe&&_t<=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),w=h.resolve(p.start),I=m.sameParent(g)&&m.parent.inlineContent&&w.end()>=p.endA,z;if((jn&&n.input.lastIOSEnter>Date.now()-225&&(!I||i.some(D=>D.nodeName=="DIV"||D.nodeName=="P"))||!I&&m.posD(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&gg(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",D=>D(n,on(8,"Backspace")))){Le&&ue&&n.domObserver.suppressSelectionUpdates();return}ue&&Le&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),Le&&!I&&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(D){return D(n,on(13,"Enter"))})},20));let Ie=p.start,de=p.endA,j,lt,Dt;if(I){if(m.pos==g.pos)xe&&_t<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>dt(n),20)),j=n.state.tr.delete(Ie,de),lt=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(Dt=mg(m.parent.content.cut(m.parentOffset,g.parentOffset),w.parent.content.cut(w.parentOffset,p.endA-w.start()))))j=n.state.tr,Dt.type=="add"?j.addMark(Ie,de,Dt.mark):j.removeMark(Ie,de,Dt.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let D=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",Tt=>Tt(n,Ie,de,D)))return;j=n.state.tr.insertText(D,Ie,de)}}if(j||(j=n.state.tr.replace(Ie,de,a.doc.slice(p.start-a.from,p.endB-a.from))),a.sel){let D=lh(n,j.doc,a.sel);D&&!(ue&&Le&&n.composing&&D.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:ll(n,e.resolve(t.anchor),e.resolve(t.head))}function mg(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||Po(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 yg(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 il=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 Qo,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(uh),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=dh(this),hh(this),this.nodeViews=fh(this),this.docView=Ha(this.state.doc,ah(this),Bo(this),this.dom,this),this.domObserver=new rl(this,(r,i,s,o)=>pg(this,r,i,s,o)),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&&Zo(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(uh),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&&(Ph(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=fh(this);bg(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Zo(this),this.editable=dh(this),hh(this);let c=Bo(this),a=ah(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&&lm(this);if(o){this.domObserver.stop();let u=d&&(xe||ue)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&wg(i.selection,e.selection);if(d){let p=ue?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=eg(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Ha(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Tm(this))?dt(this,u):(Ah(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&&Ba(this,t.getBoundingClientRect(),e)}else Ba(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 ns(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 pm(this,e)}coordsAtPos(e,t=1){return bh(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 bm(this,t||this.state,e)}pasteHTML(e,t){return Hr(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Hr(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Hm(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Bo(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Yp())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Wm(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 pe&&this.root.nodeType===11&&em(this.dom.ownerDocument)==this.dom&&hg(this,e)||e}domSelection(){return this.root.getSelection()}};function ah(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"),[te.node(0,n.state.doc.content.size,e)]}function hh(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:te.widget(n.state.selection.head,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function dh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function wg(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 fh(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 bg(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 uh(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 xg=["p",0],Sg=["blockquote",0],kg=["hr"],Cg=["pre",["code",0]],Mg=["br"],Ag={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return xg}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Sg}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return kg}},heading:{attrs:{level:{default:1}},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 Cg}},text:{group:"inline"},image:{inline:!0,attrs:{src:{},alt:{default:null},title:{default: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 Mg}}},Eg=["em",0],Dg=["strong",0],Tg=["code",0],Og={link:{attrs:{href:{},title:{default: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 Eg}},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 Dg}},code:{parseDOM:[{tag:"code"}],toDOM(){return Tg}}},Ng=new Tr({nodes:Ag,marks:Og});var Wh=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Ig(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Rg=(n,e,t)=>{let r=Ig(n,t);if(!r)return!1;let i=$h(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(!s.type.spec.isolating&&Yh(n,i,e))return!0;if(r.parent.content.size==0&&(Gn(s,"end")||C.isSelectable(s))){let o=ji(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("backward",n):r.parentOffset>0)return!1;s=$h(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 $h(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=Kh(r);if(!i)return!1;let s=i.nodeAfter;if(Yh(n,i,e))return!0;if(r.parent.content.size==0&&(Gn(s,"start")||C.isSelectable(s))){let o=ji(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=Oo(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},jh=(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=Oo(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)},Bg=(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 ul(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=ul(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},Pg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Ae||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=ul(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(Nt(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 zg(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof C&&e.selection.node.isBlock)return!r.parentOffset||!Nt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;if(t){let s=i.parentOffset==i.parent.content.size,o=e.tr;(e.selection instanceof A||e.selection instanceof Ae)&&o.deleteSelection();let l=r.depth==0?null:ul(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,s),a=c?[c]:s&&l?[{type:l}]:void 0,h=Nt(o.doc,o.mapping.map(r.pos),1,a);if(!a&&!h&&Nt(o.doc,o.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),h&&(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)}t(o.scrollIntoView())}return!0}}var Fg=zg();var Yr=(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)},qg=(n,e)=>(e&&e(n.tr.setSelection(new Ae(n.doc))),!0);function Hg(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.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function Yh(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s,o;if(r.type.spec.isolating||i.type.spec.isolating)return!1;if(Hg(n,e,t))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(s=(o=r.contentMatchAt(r.childCount)).findWrapping(i.type))&&o.matchType(s[0]||i.type).validEnd){if(t){let d=e.pos+i.nodeSize,f=y.empty;for(let m=s.length-1;m>=0;m--)f=y.from(s[m].create(null,f));f=y.from(r.copy(f));let u=n.tr.step(new G(e.pos-1,d,e.pos,d,new b(f,1,0),s.length,!0)),p=d+2*s.length;rn(u.doc,p)&&u.join(p),t(u.scrollIntoView())}return!0}let c=S.findFrom(e,1),a=c&&c.$from.blockRange(c.$to),h=a&&nn(a);if(h!=null&&h>=e.depth)return t&&t(n.tr.lift(a,h).scrollIntoView()),!0;if(l&&Gn(i,"start",!0)&&Gn(r,"end")){let d=r,f=[];for(;f.push(d),!d.isTextblock;)d=d.lastChild;let u=i,p=1;for(;!u.isTextblock;u=u.firstChild)p++;if(d.canReplace(d.childCount,d.childCount,u.content)){if(t){let m=y.empty;for(let w=f.length-1;w>=0;w--)m=y.from(f[w].copy(m));let g=n.tr.step(new G(e.pos-f.length,e.pos+i.nodeSize,e.pos+p,e.pos+i.nodeSize-p,new b(m,f.length,0),0,!0));t(g.scrollIntoView())}return!0}}return!1}function Gh(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 Jg=Gh(-1),Wg=Gh(1);function ml(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Ki(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function Xn(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(o)return!1;o=l.inlineContent&&l.type.allowsMarkType(t)}),o)return!0}return!1}function pn(n,e=null){return function(t,r){let{empty:i,$cursor:s,ranges:o}=t.selection;if(i&&!s||!$g(t.doc,o,n))return!1;if(r)if(s)n.isInSet(t.storedMarks||s.marks())?r(t.tr.removeStoredMark(n)):r(t.tr.addStoredMark(n.create(e)));else{let l=!1,c=t.tr;for(let a=0;!l&&a=t?ne.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};ne.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};ne.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)};ne.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};ne.from=function(e){return e instanceof ne?e:e&&e.length?new Zh(e):ne.empty};var Zh=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<=as)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=as)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}(ne);ne.empty=new Zh([]);var jg=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}(ne),gl=ne;var Yg=500,gn=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 $e(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 $e(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;hXg&&(l=Gg(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 $e(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 $e(p,m,g))}else r.push(new $e(p))},i);let a=[];for(let f=t;fYg&&(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 $e(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(gl.from(i.reverse()),s)}};gn.empty=new gn(gl.empty,0);function Gg(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}var $e=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)}}},Ke=class{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}},Xg=20;function Qg(n,e,t,r){let i=t.getMeta(mn),s;if(i)return i.historyState;t.getMeta(ty)&&(n=new Ke(n.done,n.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(o&&o.getMeta(mn))return o.getMeta(mn).redo?new Ke(n.done.addTransform(t,void 0,r,hs(e)),n.undone,ed(t.mapping.maps[t.steps.length-1]),n.prevTime,n.prevComposition):new Ke(n.done,n.undone.addTransform(t,void 0,r,hs(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),c=n.prevTime==0||!o&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-r.newGroupDelay||!Zg(t,n.prevRanges)),a=o?yl(n.prevRanges,t.mapping):ed(t.mapping.maps[t.steps.length-1]);return new Ke(n.done.addTransform(t,c?e.selection.getBookmark():void 0,r,hs(e)),gn.empty,a,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new Ke(n.done.rebased(t,s),n.undone.rebased(t,s),yl(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new Ke(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),yl(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function Zg(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,i)=>{for(let s=0;s=e[s]&&(t=!0)}),t}function ed(n){let e=[];return n.forEach((t,r,i,s)=>e.push(i,s)),e}function yl(n,e){if(!n)return null;let t=[];for(let r=0;r{let i=mn.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=ey(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}var yn=ds(!1,!0),Bt=ds(!0,!0),Qb=ds(!1,!1),Zb=ds(!0,!1);var ny=["ol",0],ry=["ul",0],iy=["li",0],sy={attrs:{order:{default:1}},parseDOM:[{tag:"ol",getAttrs(n){return{order:n.hasAttribute("start")?+n.getAttribute("start"):1}}}],toDOM(n){return n.attrs.order==1?ny:["ol",{start:n.attrs.order},0]}},oy={parseDOM:[{tag:"ul"}],toDOM(){return ry}},ly={parseDOM:[{tag:"li"}],toDOM(){return iy},defining:!0};function bl(n,e){let t={};for(let r in n)t[r]=n[r];for(let r in e)t[r]=e[r];return t}function cy(n,e,t){return n.append({ordered_list:bl(sy,{content:"list_item+",group:t}),bullet_list:bl(oy,{content:"list_item+",group:t}),list_item:bl(ly,{content:e})})}function fs(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=!1,c=o;if(!o)return!1;if(o.depth>=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=y.from(t[h].type.create(t[h].attrs,s));n.step(new G(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;w--)d=y.from(i.node(w).copy(d));let u=i.indexAfter(-1){if(g>-1)return!1;w.isTextblock&&w.content.size==0&&(g=I+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 Nt(a.doc,i.pos,2,h)?(r&&r(a.split(i.pos,2,h).scrollIntoView()),!0):!1}}function Sl(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?hy(e,t,n,s):dy(e,t,s):!0:!1}}function hy(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?y.empty:y.from(i))))return!1;let d=s.pos,f=d+o.nodeSize;return r.step(new G(d-(l?1:0),f+(c?1:0),d+1,f-1,new b((l?y.empty:y.from(i.copy(y.empty))).append(c?y.empty:y.from(i.copy(y.empty))),l?0:1,c?0:1),l?0:1)),e(r.scrollIntoView()),!0}function kl(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=y.from(a?n.create():null),d=new b(y.from(n.create(null,y.from(l.type.create(null,h)))),a?3:1,0),f=s.start,u=s.end;t(e.tr.step(new G(f-(a?3:1),u,f,u,d,1,!0)).scrollIntoView())}return!0}}var ut={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:"'"},ps={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},fy=typeof navigator<"u"&&/Mac/.test(navigator.platform),uy=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(J=0;J<10;J++)ut[48+J]=ut[96+J]=String(J);var J;for(J=1;J<=24;J++)ut[J+111]="F"+J;var J;for(J=65;J<=90;J++)ut[J]=String.fromCharCode(J+32),ps[J]=String.fromCharCode(J);var J;for(us in ut)ps.hasOwnProperty(us)||(ps[us]=ut[us]);var us;function rd(n){var e=fy&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||uy&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?ps:ut)[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 py=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function my(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l127)&&(s=ut[r.keyCode])&&s!=i){let l=e[Cl(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var le=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 Ml(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!wy(e)||!by(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}}};le.prototype.visible=!1;le.findFrom=le.findGapCursorFrom;S.jsonID("gapcursor",le);var Ml=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 le.valid(t)?new le(t):S.near(t)}};function wy(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 by(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 xy(){return new F({props:{decorations:My,createSelectionBetween(n,e,t){return e.pos==t.pos&&le.valid(t)?new le(t):null},handleClick:ky,handleKeyDown:Sy,handleDOMEvents:{beforeinput:Cy}}})}var Sy=Xr({ArrowLeft:ms("horiz",-1),ArrowRight:ms("horiz",1),ArrowUp:ms("vert",-1),ArrowDown:ms("vert",1)});function ms(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=le.findGapCursorFrom(l,e,c);return a?(i&&i(r.tr.setSelection(new le(a))),!0):!1}}function ky(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!le.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 le(r))),!0)}function Cy(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof le))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=y.empty;for(let o=r.length-1;o>=0;o--)i=y.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 My(n){if(!(n.selection instanceof le))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",P.create(n.doc,[te.widget(n.selection.head,e,{key:"gapcursor"})])}function pt(){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 Ey=500;function od({rules:n}){let e=new F({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 sd(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&sd(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function sd(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-Ey),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},Dy=new mt(/--$/,"\u2014"),Ty=new mt(/\.\.\.$/,"\u2026"),gx=new mt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),yx=new mt(/"$/,"\u201D"),wx=new mt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),bx=new mt(/'$/,"\u2019");var cd=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Oy(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",yn),i("Shift-Mod-z",Bt),i("Backspace",ld),cd||i("Mod-y",Bt),i("Alt-ArrowUp",Kr),i("Alt-ArrowDown",jh),i("Mod-BracketLeft",jr),i("Escape",Yr),(r=n.marks.strong)&&(i("Mod-b",pn(r)),i("Mod-B",pn(r))),(r=n.marks.em)&&(i("Mod-i",pn(r)),i("Mod-I",pn(r))),(r=n.marks.code)&&i("Mod-`",pn(r)),(r=n.nodes.bullet_list)&&i("Shift-Ctrl-8",fs(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",fs(r)),(r=n.nodes.blockquote)&&i("Ctrl->",ml(r)),r=n.nodes.hard_break){let s=r,o=Gr(pl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0));i("Mod-Enter",o),i("Shift-Enter",o),cd&&i("Ctrl-Enter",o)}if((r=n.nodes.list_item)&&(i("Enter",xl(r)),i("Mod-[",Sl(r)),i("Mod-]",kl(r))),(r=n.nodes.paragraph)&&i("Shift-Ctrl-0",Xn(r)),(r=n.nodes.code_block)&&i("Shift-Ctrl-\\",Xn(r)),r=n.nodes.heading)for(let s=1;s<=6;s++)i("Shift-Ctrl-"+s,Xn(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 El,Dl;if(typeof WeakMap<"u"){let n=new WeakMap;El=e=>n.get(e),Dl=(e,t)=>(n.set(e,t),t)}else{let n=[],t=0;El=r=>{for(let i=0;i(t==10&&(t=0),n[t++]=r,n[t++]=i)}var L=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:w-z});break}let Ie=i+z*e;for(let de=0;der&&(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 Ry(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 hd(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=>ad(r,e)}],toDOM(r){return["td",hd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>ad(r,e)}],toDOM(r){return["th",hd(r,e),0]}}}}function ce(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 Pt=new fe("selectingCells");function Qn(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 Uy(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 je(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 Il(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=Qn(e.$head)||Vy(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Vy(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 Tl(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function By(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function Rl(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function bd(n,e,t){let r=n.node(-1),i=L.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 wn(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 xd(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 Br(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(Tl(r)&&Tl(i)&&Rl(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?gt.rowSelection(r,i):s&&this.isColSelection()?gt.colSelection(r,i):new gt(r,i)}return A.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=L.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 w=p.attrs;if(m>0&&(w=wn(w,0,m)),g>0&&(w=wn(w,w.colspan-g,g)),u.lefti.bottom){let w={...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=L.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 gt&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=e.node(-1),i=L.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(te.node(r,r+t.nodeSize,{class:"selectedCell"}))}),P.create(n.doc,e)}function Fy({$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 qy({$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 Hy(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=U.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=U.rowSelection(l,l)}else if(!t){let l=L.get(r.node),c=r.from+1,a=c+l.map[l.width*l.height-1];s=U.create(i,c+1,a)}}else r instanceof A&&Fy(r)?s=A.create(i,r.from):r instanceof A&&qy(r)&&(s=A.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}var Jy=new fe("fix-tables");function kd(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=Wy(n,i,s,t))};return e?e.doc!=n.doc&&kd(e.doc,n.doc,0,r):n.doc.descendants(r),t}function Wy(n,e,t,r){let i=L.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&&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(y.empty),t[i]r&&(f=f.type.createChecked(wn(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(y.from(c))}t=s,e=i}return{width:n,height:e,rows:t}}function Yy(n,e,t,r,i,s,o){let l=n.doc.type.schema,c=ce(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,y.from(d)),u=[];for(let p=e.height;p{if(!i)return!1;let s=t.selection;if(s instanceof U)return bs(t,r,S.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=Md(i,n,e);if(o==null)return!1;if(n=="horiz")return bs(t,r,S.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),c=bd(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),bs(t,r,a)}}}function ys(n,e){return(t,r,i)=>{if(!i)return!1;let s=t.selection,o;if(s instanceof U)o=s;else{let c=Md(i,n,e);if(c==null)return!1;o=new U(t.doc.resolve(c))}let l=bd(o.$headCell,n,e);return l?bs(t,r,new U(o.$anchorCell,l)):!1}}function ws(n,e){let t=n.selection;if(!(t instanceof U))return!1;if(e){let r=n.tr,i=ce(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 Xy(n,e){let t=n.state.doc,r=Qn(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new U(r))),!0):!1}function Qy(n,e,t){if(!je(n.state))return!1;let r=$y(t),i=n.state.selection;if(i instanceof U){r||(r={width:1,height:1,rows:[y.from(Ol(ce(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=L.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=jy(r,l.right-l.left,l.bottom-l.top),ud(n.state,n.dispatch,o,l,r),!0}else if(r){let s=Il(n.state),o=s.start(-1);return ud(n.state,n.dispatch,o,L.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function Zy(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=pd(n,e.target),i;if(e.shiftKey&&n.state.selection instanceof U)s(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Qn(n.state.selection.$anchor))!=null&&((t=Al(n,e))==null?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(c,a){let h=Al(n,a),d=Pt.getState(n.state)==null;if(!h||!Rl(c,h))if(d)h=c;else return;let f=new U(c,h);if(d||!n.state.selection.eq(f)){let u=n.state.tr.setSelection(f);d&&u.setMeta(Pt,c.pos),n.dispatch(u)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),Pt.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(Pt,-1))}function l(c){let a=c,h=Pt.getState(n.state),d;if(h!=null)d=n.state.doc.resolve(h);else if(pd(n,a.target)!=r&&(d=Al(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 Md(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 pd(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Al(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Qn(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")),Nl(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,Nl(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function Nl(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(l,e,c),new n0(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes:s=>{let o=_e.getState(s);return o&&o.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(s,o)=>{r0(s,o,n,e,r)},mouseleave:s=>{i0(s)},mousedown:(s,o)=>{s0(s,o,e)}},decorations:s=>{let o=_e.getState(s);if(o&&o.activeHandle>-1)return d0(s,o.activeHandle)},nodeViews:{}}});return i}var n0=class xs{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(_e);if(r&&r.setHandle!=null)return new xs(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new xs(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Tl(e.doc.resolve(i))||(i=-1),new xs(i,t.dragging)}return t}};function r0(n,e,t,r,i){let s=_e.getState(n.state);if(s&&!s.dragging){let o=l0(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=L.get(a),d=c.start(-1);if(h.colCount(c.pos-d)+c.nodeAfter.attrs.colspan-1==h.width-1)return}Ad(n,l)}}}function i0(n){let e=_e.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Ad(n,-1)}function s0(n,e,t){var r;let i=(r=n.dom.ownerDocument.defaultView)!=null?r:window,s=_e.getState(n.state);if(!s||s.activeHandle==-1||s.dragging)return!1;let o=n.state.doc.nodeAt(s.activeHandle),l=o0(n,s.activeHandle,o.attrs);n.dispatch(n.state.tr.setMeta(_e,{setDragging:{startX:e.clientX,startWidth:l}}));function c(h){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",a);let d=_e.getState(n.state);d?.dragging&&(c0(n,d.activeHandle,gd(d.dragging,h,t)),n.dispatch(n.state.tr.setMeta(_e,{setDragging:null})))}function a(h){if(!h.which)return c(h);let d=_e.getState(n.state);if(d&&d.dragging){let f=gd(d.dragging,h,t);a0(n,d.activeHandle,f,t)}}return i.addEventListener("mouseup",c),i.addEventListener("mousemove",a),e.preventDefault(),!0}function o0(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;a0?-1:0;Py(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;g0(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 M0(n){return(e,t)=>{var r;let i=e.selection,s,o;if(i instanceof U){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;s=i.$anchorCell.nodeAfter,o=i.$anchorCell.pos}else{if(s=Uy(i.$from),!s)return!1;o=(r=Qn(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=Ye(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 Jx=vl("row",{useDeprecatedLogic:!0}),Wx=vl("column",{useDeprecatedLogic:!0}),$x=vl("cell",{useDeprecatedLogic:!0});function E0(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 O0({allowTableNodeSelection:n=!1}={}){return new F({key:Pt,state:{init(){return null},apply(e,t){let r=e.getMeta(Pt);if(r!=null)return r==-1?null:r;if(t==null||!e.docChanged)return t;let{deleted:i,pos:s}=e.mapping.mapResult(t);return i?null:s}},props:{decorations:zy,handleDOMEvents:{mousedown:Zy},createSelectionBetween(e){return Pt.getState(e.state)!=null?e.state.selection:null},handleTripleClick:Xy,handleKeyDown:Gy,handlePaste:Qy},appendTransaction(e,t,r){return Hy(r,Cd(r,t),n)}})}var Sr={};ip(Sr,{AbsolutePosition:()=>Hs,AbstractConnector:()=>oc,AbstractStruct:()=>yr,AbstractType:()=>$,Array:()=>Nn,ContentAny:()=>Kt,ContentBinary:()=>Rn,ContentDeleted:()=>wr,ContentDoc:()=>vn,ContentEmbed:()=>Ct,ContentFormat:()=>B,ContentJSON:()=>Si,ContentString:()=>Ne,ContentType:()=>Ce,Doc:()=>kt,GC:()=>he,ID:()=>xt,Item:()=>T,Map:()=>In,PermanentUserData:()=>cc,RelativePosition:()=>it,Skip:()=>ie,Snapshot:()=>Wt,Text:()=>$t,Transaction:()=>Ws,UndoManager:()=>Tn,UpdateDecoderV1:()=>ke,UpdateDecoderV2:()=>we,UpdateEncoderV1:()=>rt,UpdateEncoderV2:()=>Oe,XmlElement:()=>Q,XmlFragment:()=>ot,XmlHook:()=>xi,XmlText:()=>be,YArrayEvent:()=>js,YEvent:()=>On,YMapEvent:()=>Ys,YTextEvent:()=>Gs,YXmlEvent:()=>Xs,applyUpdate:()=>bc,applyUpdateV2:()=>Zs,cleanupYTextFormatting:()=>ku,compareIDs:()=>Mn,compareRelativePositions:()=>eo,convertUpdateFormatV1ToV2:()=>n1,convertUpdateFormatV2ToV1:()=>su,createAbsolutePositionFromRelativePosition:()=>Mc,createDeleteSet:()=>br,createDeleteSetFromStructStore:()=>gc,createDocFromSnapshot:()=>Fw,createID:()=>M,createRelativePositionFromJSON:()=>Un,createRelativePositionFromTypeIndex:()=>ki,createSnapshot:()=>Ci,decodeRelativePosition:()=>Vw,decodeSnapshot:()=>Lw,decodeSnapshotV2:()=>$f,decodeStateVector:()=>Sc,decodeUpdate:()=>Yw,decodeUpdateV2:()=>Zf,diffUpdate:()=>Zw,diffUpdateV2:()=>Ec,emptySnapshot:()=>zw,encodeRelativePosition:()=>_w,encodeSnapshot:()=>Pw,encodeSnapshotV2:()=>Wf,encodeStateAsUpdate:()=>xc,encodeStateAsUpdateV2:()=>qf,encodeStateVector:()=>Cc,encodeStateVectorFromUpdate:()=>Gw,encodeStateVectorFromUpdateV2:()=>tu,equalDeleteSets:()=>zf,equalSnapshots:()=>Bw,findIndexSS:()=>Pe,findRootTypeKey:()=>_n,getItem:()=>An,getState:()=>V,getTypeChildren:()=>o1,isDeleted:()=>Mt,isParentOf:()=>Dn,iterateDeletedStructs:()=>tt,logType:()=>Nw,logUpdate:()=>jw,logUpdateV2:()=>Qf,mergeUpdates:()=>eu,mergeUpdatesV2:()=>gi,obfuscateUpdate:()=>e1,obfuscateUpdateV2:()=>t1,parseUpdateMeta:()=>Xw,parseUpdateMetaV2:()=>nu,readUpdate:()=>Ew,readUpdateV2:()=>wc,relativePositionToJSON:()=>Iw,snapshot:()=>Ac,snapshotContainsUpdate:()=>Hw,transact:()=>N,tryGc:()=>$w,typeListToArraySnapshot:()=>io,typeMapGetAllSnapshot:()=>yu,typeMapGetSnapshot:()=>a1});var v=()=>new Map,Ss=n=>{let e=v();return n.forEach((t,r)=>{e.set(r,t)}),e},W=(n,e,t)=>{let r=n.get(e);return r===void 0&&n.set(e,r=t()),r},Td=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Od=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Se=()=>new Set;var ks=n=>n[n.length-1];var Nd=(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 Fe((this._observers.get(e)||v()).values()).forEach(r=>r(...t))}destroy(){this._observers=v()}},er=class{constructor(){this._observers=v()}on(e,t){W(this._observers,e,Se).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 Fe((this._observers.get(e)||v()).values()).forEach(r=>r(...t))}destroy(){this._observers=v()}};var ae=Math.floor;var tr=Math.abs;var Ee=(n,e)=>nn>e?n:e,Xx=Number.isNaN,vd=Math.pow;var Ms=n=>n!==0?n<0:1/n<0;var _l=Number.MAX_SAFE_INTEGER,Qx=Number.MIN_SAFE_INTEGER,Zx=1<<31;var _d=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&ae(n)===n),eS=Number.isNaN,tS=Number.parseInt;var Ul=String.fromCharCode,nS=String.fromCodePoint,rS=Ul(65535),N0=n=>n.toLowerCase(),I0=/^\s*/g,R0=n=>n.replace(I0,""),v0=/([A-Z])/g,Vl=(n,e)=>R0(n.replace(v0,t=>`${e}${N0(t)}`));var _0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;irr.encode(n),Vd=rr?U0:_0;var nr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});nr&&nr.decode(new Uint8Array).length===1&&(nr=null);var Bd=(n,e)=>Rd(e,()=>n).join("");var xn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},q=()=>new xn;var Es=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(Es(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 lr=X;var x=(n,e)=>{for(;e>127;)X(n,128|127&e),e=ae(e/128);X(n,127&e)},ni=(n,e)=>{let t=Ms(e);for(t&&(e=-e),X(n,(e>63?128:0)|(t?64:0)|63&e),e=ae(e/64);e>0;)X(n,(e>127?128:0)|127&e),e=ae(e/128)},Bl=new Uint8Array(3e4),B0=Bl.length/3,P0=(n,e)=>{if(e.length{let t=unescape(encodeURIComponent(e)),r=t.length;x(n,r);for(let i=0;icr(n,O(e)),cr=(n,e)=>{let t=n.cbuf.length,r=n.cpos,i=Ee(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(Ue(t*2,s)),n.cbuf.set(e.subarray(i)),n.cpos=s)},_=(n,e)=>{x(n,e.byteLength),cr(n,e)},Pl=(n,e)=>{V0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},z0=(n,e)=>Pl(n,4).setFloat32(0,e,!1),F0=(n,e)=>Pl(n,8).setFloat64(0,e,!1),q0=(n,e)=>Pl(n,8).setBigInt64(0,e,!1);var Ld=new DataView(new ArrayBuffer(4)),H0=n=>(Ld.setFloat32(0,n),Ld.getFloat32(0)===n),sr=(n,e)=>{switch(typeof e){case"string":X(n,119),Ge(n,e);break;case"number":_d(e)&&tr(e)<=2147483647?(X(n,125),ni(n,e)):H0(e)?(X(n,124),z0(n,e)):(X(n,123),F0(n,e));break;case"bigint":X(n,122),q0(n,e);break;case"object":if(e===null)X(n,126);else if(Zr(e)){X(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 zd=n=>{n.count>0&&(ni(n.encoder,n.count===1?n.s:-n.s),n.count>1&&x(n.encoder,n.count-2))},Sn=class{constructor(){this.encoder=new xn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(zd(this),this.count=1,this.s=e)}toUint8Array(){return zd(this),O(this.encoder)}};var Fd=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)}},or=class{constructor(){this.encoder=new xn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Fd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Fd(this),O(this.encoder)}},As=class{constructor(){this.sarr=[],this.s="",this.lensE=new Sn}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 xn;return this.sarr.push(this.s),this.s="",Ge(e,this.sarr.join("")),cr(e,this.lensE.toUint8Array()),O(e)}};var Xe=n=>new Error(n),De=()=>{throw Xe("Method unimplemented")},re=()=>{throw Xe("Unexpected case")};var Hd=Xe("Unexpected end of array"),Jd=Xe("Integer out of Range"),ar=class{constructor(e){this.arr=e,this.pos=0}},H=n=>new ar(n),Ll=n=>n.pos!==n.arr.length;var J0=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>J0(n,k(n));var kn=n=>n.arr[n.pos++];var k=n=>{let e=0,t=1,r=n.arr.length;for(;n.pos_l)throw Jd}throw Hd},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.pos_l)throw Jd}throw Hd};var W0=n=>{let e=k(n);if(e===0)return"";{let t=String.fromCodePoint(kn(n));if(--e<100)for(;e--;)t+=String.fromCodePoint(kn(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))}},$0=n=>nr.decode(K(n)),Be=nr?$0:W0;var zl=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},K0=n=>zl(n,4).getFloat32(0,!1),j0=n=>zl(n,8).getFloat64(0,!1),Y0=n=>zl(n,8).getBigInt64(0,!1);var G0=[n=>{},n=>null,ii,K0,j0,Y0,n=>!1,n=>!0,Be,n=>{let e=k(n),t={};for(let r=0;r{let e=k(n),t=[];for(let r=0;rG0[127-kn(n)](n),ri=class extends ar{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Ll(this)?this.count=k(this)+1:this.count=-1),this.count--,this.s}};var Cn=class extends ar{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=ii(this);let e=Ms(this.s);this.count=1,e&&(this.s=-this.s,this.count=k(this)+2)}return this.count--,this.s}};var dr=class extends ar{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=ae(e/2),this.count=1,t&&(this.count=k(this)+2)}return this.s+=this.diff,this.count--,this.s}},Os=class{constructor(e){this.decoder=new Cn(e),this.str=Be(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 oS=crypto.subtle,Wd=crypto.getRandomValues.bind(crypto);var X0=Math.random,Fl=()=>Wd(new Uint32Array(1))[0];var $d=n=>n[ae(X0()*n.length)],Q0="10000000-1000-4000-8000"+-1e11,Kd=()=>Q0.replace(/[018]/g,n=>(n^Fl()&15>>n/4).toString(16));var Te=Date.now;var ql=n=>new Promise(n);var aS=Promise.all.bind(Promise);var Hl=n=>n===void 0?null:n;var Jl=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},Yd=new Jl,Wl=!0;try{typeof localStorage<"u"&&localStorage&&(Yd=localStorage,Wl=!1)}catch{}var Is=Yd,Gd=n=>Wl||addEventListener("storage",n),Xd=n=>Wl||removeEventListener("storage",n);var Zd=Object.assign,$l=Object.keys,ef=(n,e)=>{for(let t in n)e(n[t],t)},tf=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},oi=n=>$l(n).length;var nf=n=>{for(let e in n)return!1;return!0},tw=(n,e)=>{for(let t in n)if(!e(n[t],t))return!1;return!0},Kl=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),jl=(n,e)=>n===e||oi(n)===oi(e)&&tw(n,(t,r)=>(t!==void 0||Kl(e,r))&&e[r]===t);var li=(n,e,t=0)=>{try{for(;tn,nw=(n,e)=>n===e;var fr=(n,e)=>{if(n==null||e==null)return nw(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 wt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",ur=typeof window<"u"&&typeof document<"u"&&!wt,hS=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,Qe,rw=[],iw=()=>{if(Qe===void 0)if(wt){Qe=v();let n=process.argv,e=null;for(let t=0;t{if(n.length!==0){let[e,t]=n.split("=");Qe.set(`--${Vl(e,"-")}`,t),Qe.set(`-${Vl(e,"-")}`,t)}})):Qe=v();return Qe},Xl=n=>iw().has(n);var Ql=n=>wt?Hl(process.env[n.toUpperCase()]):Hl(Is.getItem(n));var sw=n=>Xl("--"+n)||Ql(n)!==null,dS=sw("production"),sf=wt&&rf(process.env.FORCE_COLOR,["true","1","2"]),of=!Xl("no-colors")&&(!wt||process.stdout.isTTY||sf)&&(!wt||Xl("color")||sf||Ql("COLORTERM")!==null||(Ql("TERM")||"").includes("color"));var lf=n=>new Uint8Array(n),ow=(n,e,t)=>new Uint8Array(n,e,t),cf=n=>new Uint8Array(n),lw=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),aw=n=>{let e=atob(n),t=lf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return ow(e.buffer,e.byteOffset,e.byteLength)},af=ur?lw:cw,hf=ur?aw:hw;var df=n=>{let e=lf(n.byteLength);return e.set(n),e};var Zl=class{constructor(e,t){this.left=e,this.right=t}},Ze=(n,e)=>new Zl(n,e);var bt=typeof document<"u"?document:{};var fS=typeof DOMParser<"u"?new DOMParser:null;var uf=n=>Td(n,(e,t)=>`${t}:${e};`).join("");var uS=bt.ELEMENT_NODE,pS=bt.TEXT_NODE,mS=bt.CDATA_SECTION_NODE,gS=bt.COMMENT_NODE,yS=bt.DOCUMENT_NODE,wS=bt.DOCUMENT_TYPE_NODE,bS=bt.DOCUMENT_FRAGMENT_NODE;var _s=n=>class{constructor(t){this._=t}destroy(){n(this._)}},fw=_s(clearTimeout),ci=(n,e)=>new fw(setTimeout(e,n)),SS=_s(clearInterval);var kS=_s(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var CS=_s(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var et=Symbol;var ai=et(),hi=et(),ec=et(),tc=et(),nc=et(),di=et(),rc=et(),pr=et(),ic=et(),gf=n=>{let e=[],t=[],r=0;for(;r{let e=[],t=[],r=v(),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(...yf(n)),bf.forEach(e=>e.print(n))},wf=(...n)=>{console.warn(...yf(n)),n.unshift(pr),bf.forEach(e=>e.print(n))};var bf=Se();var xf=n=>({[Symbol.iterator](){return this},next:n}),Sf=(n,e)=>xf(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),Vs=(n,e)=>xf(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var oc=class extends Zn{constructor(e,t){super(),this.doc=e,this.awareness=t}},ui=class{constructor(e,t){this.clock=e,this.len=t}},Ht=class{constructor(){this.clients=new Map}},tt=(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=ae((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&&Sw(t,e.clock)!==null},mc=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=Ue(i.len,s.clock+s.len-i.clock):(r{let e=new Ht;for(let t=0;t{if(!e.clients.has(i)){let s=r.slice();for(let o=t+1;o{W(n.clients,e,()=>[]).push(new ui(t,r))},br=()=>new Ht,gc=n=>{let e=br();return n.clients.forEach((t,r)=>{let i=[];for(let s=0;s0&&e.clients.set(r,i)}),e},nt=(n,e)=>{x(n.restEncoder,e.clients.size),Fe(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 Ht,t=k(n.restDecoder);for(let r=0;r0){let o=W(e.clients,i,()=>[]);for(let l=0;l{let r=new Ht,i=k(n.restDecoder);for(let s=0;s0){let s=new Oe;return x(s.restEncoder,0),nt(s,r),s.toUint8Array()}return null},zf=(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=Ff(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Js,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.whenLoaded=ql(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let c=()=>ql(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&&N(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Fe(this.subdocs).map(e=>e.guid))}transact(e,t=null){return N(this,e,t)}get(e,t=$){let r=W(this.share,e,()=>{let s=new t;return s._integrate(this,null),s}),i=r.constructor;if(t!==$&&i!==t)if(i===$){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,Nn)}getText(e=""){return this.get(e,$t)}getMap(e=""){return this.get(e,In)}getXmlElement(e=""){return this.get(e,Q)}getXmlFragment(e=""){return this.get(e,ot)}toJSON(){let e={};return this.share.forEach((t,r)=>{e[r]=t.toJSON()}),e}destroy(){Fe(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,N(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()}},En=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return k(this.restDecoder)}readDsLen(){return k(this.restDecoder)}},ke=class extends En{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 kn(this.restDecoder)}readString(){return Be(this.restDecoder)}readParentInfo(){return k(this.restDecoder)===1}readTypeRef(){return k(this.restDecoder)}readLen(){return k(this.restDecoder)}readAny(){return hr(this.restDecoder)}readBuf(){return df(K(this.restDecoder))}readJSON(){return JSON.parse(Be(this.restDecoder))}readKey(){return Be(this.restDecoder)}},qs=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}},we=class extends qs{constructor(e){super(e),this.keys=[],k(e),this.keyClockDecoder=new dr(K(e)),this.clientDecoder=new Cn(K(e)),this.leftClockDecoder=new dr(K(e)),this.rightClockDecoder=new dr(K(e)),this.infoDecoder=new ri(K(e),kn),this.stringDecoder=new Os(K(e)),this.parentInfoDecoder=new ri(K(e),kn),this.typeRefDecoder=new Cn(K(e)),this.lenDecoder=new Cn(K(e))}readLeftID(){return new xt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new xt(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 hr(this.restDecoder)}readBuf(){return K(this.restDecoder)}readJSON(){return hr(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=Ue(r,e[0].id.clock);let i=Pe(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)=>{V(e,s)>i&&r.set(s,i)}),Mi(e).forEach((i,s)=>{t.has(s)||r.set(s,0)}),x(n.restEncoder,r.size),Fe(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{kw(n,e.clients.get(i),i,s)})},Cw=(n,e)=>{let t=v(),r=k(n.restDecoder);for(let i=0;i{let r=[],i=Fe(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 Js,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=W(d,h.id.client,()=>V(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,V(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 Oe;return yc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},Aw=(n,e)=>yc(n,e.doc.store,e.beforeState),wc=(n,e,t,r=new we(n))=>N(e,i=>{i.local=!1;let s=!1,o=i.doc,l=o.store,c=Cw(r,o),a=Mw(i,l,c),h=l.pendingStructs;if(h){for(let[f,u]of h.missing)if(uu)&&h.missing.set(f,u)}h.update=gi([h.update,a.update])}}else l.pendingStructs=a;let d=Mf(r,i,l);if(l.pendingDs){let f=new we(H(l.pendingDs));k(f.restDecoder);let u=Mf(f,i,l);d&&u?l.pendingDs=gi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(s){let f=l.pendingStructs.update;l.pendingStructs=null,Zs(i.doc,f)}},t,!1),Ew=(n,e,t)=>wc(n,e,t,new ke(n)),Zs=(n,e,t,r=we)=>{let i=H(e);wc(i,n,t,new r(i))},bc=(n,e,t)=>Zs(n,e,t,ke),Dw=(n,e,t=new Map)=>{yc(n,e.store,t),nt(n,gc(e.store))},qf=(n,e=new Uint8Array([0]),t=new Oe)=>{let r=Sc(e);Dw(t,n,r);let i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(Ec(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===rt)return eu(i.map((s,o)=>o===0?s:su(s)));if(t.constructor===Oe)return gi(i)}return i[0]},xc=(n,e)=>qf(n,e,new rt),Hf=n=>{let e=new Map,t=k(n.restDecoder);for(let r=0;rHf(new En(H(n))),kc=(n,e)=>(x(n.restEncoder,e.size),Fe(e.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{x(n.restEncoder,t),x(n.restEncoder,r)}),n),Tw=(n,e)=>kc(n,Mi(e.store)),Ow=(n,e=new gr)=>(n instanceof Map?kc(e,n):Tw(e,n),e.toUint8Array()),Cc=n=>Ow(n,new Jt),lc=class{constructor(){this.l=[]}},Af=()=>new lc,Ef=(n,e)=>n.l.push(e),Df=(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.")},Jf=(n,e,t)=>li(n.l,[e,t]),xt=class{constructor(e,t){this.client=e,this.clock=t}},Mn=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,M=(n,e)=>new xt(n,e),Tf=(n,e)=>{x(n,e.client),x(n,e.clock)},Of=n=>M(k(n),k(n)),_n=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw re()},Dn=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1},Nw=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))},cc=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,mr([this.dss.get(o)||br(),St(new En(H(f)))]))})})}),this.dss.set(o,mr(l.map(h=>St(new En(H(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 In,o.set("ids",new Nn),o.set("ds",new Nn),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 Jt,h=this.dss.get(r);h&&(nt(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 Jt;nt(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(Mt(r,e))return t;return null}},it=class{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}},Iw=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 it(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),Hs=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},Rw=(n,e,t=0)=>new Hs(n,e,t),Bs=(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 it(r,i,e,t)},ki=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return Bs(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Bs(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Bs(n,r.lastId,t);r=r.right}return Bs(n,null,t)},vw=(n,e)=>{let{type:t,tname:r,item:i,assoc:s}=e;if(i!==null)x(n,0),Tf(n,i);else if(r!==null)lr(n,1),Ge(n,r);else if(t!==null)lr(n,2),Tf(n,t);else throw re();return ni(n,s),n},_w=n=>{let e=q();return vw(e,n),O(e)},Uw=n=>{let e=null,t=null,r=null;switch(k(n)){case 0:r=Of(n);break;case 1:t=Be(n);break;case 2:e=Of(n)}let i=Ll(n)?ii(n):0;return new it(e,t,r,i)},Vw=n=>Uw(H(n)),Mc=(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(V(r,i.client)<=i.clock)return null;let h=t?uc(r,i):{item:An(r,i),diff:0},d=h.item;if(!(d instanceof T))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(V(r,s.client)<=s.clock)return null;let{item:h}=t?uc(r,s):{item:An(r,s)};if(h instanceof T&&h.content instanceof Ce)c=h.content.type;else return null}else throw re();l>=0?a=c._length:a=0}return Rw(c,a,n.assoc)},eo=(n,e)=>n===e||n!==null&&e!==null&&n.tname===e.tname&&Mn(n.item,e.item)&&Mn(n.type,e.type)&&n.assoc===e.assoc,Wt=class{constructor(e,t){this.ds=e,this.sv=t}},Bw=(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(nt(e,n.ds),kc(e,n.sv),e.toUint8Array()),Pw=n=>Wf(n,new Jt),$f=(n,e=new qs(H(n)))=>new Wt(St(e),Hf(e)),Lw=n=>$f(n,new En(H(n))),Ci=(n,e)=>new Wt(n,e),zw=Ci(br(),new Map),Ac=n=>Ci(gc(n.store),Mi(n.store)),zt=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!Mt(e.ds,n.id),ac=(n,e)=>{let t=W(n.meta,ac,Se),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i{}),t.add(e))},Fw=(n,e,t=new kt)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:i}=e,s=new Oe;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(H(e)),i=new st(r,!1);for(let o=i.curr;o!==null;o=i.next())if((n.sv.get(o.id.client)||0)qw(n,e,ke),Js=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Mi=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},V=(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},Kf=(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 re()}t.push(e)},Pe=(n,e)=>{let t=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===e)return r;let o=ae(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[Pe(t,e.clock)]},An=Jw,hc=(n,e,t)=>{let r=Pe(e,t),i=e[r];return i.id.clock{let t=n.doc.store.clients.get(e.client);return t[hc(n,t,e.clock)]},Nf=(n,e,t)=>{let r=e.clients.get(t.client),i=Pe(r,t.clock),s=r[i];return t.clock!==s.id.clock+s.length-1&&s.constructor!==he&&r.splice(i+1,0,Qs(n,s,t.clock-s.id.clock+1)),s},Ww=(n,e,t)=>{let r=n.clients.get(e.id.client);r[Pe(r,e.id.clock)]=t},jf=(n,e,t,r,i)=>{if(r===0)return;let s=t+r,o=hc(n,e,t),l;do l=e[o++],se.deleteSet.clients.size===0&&!Od(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(mc(e.deleteSet),Aw(n,e),nt(n,e.deleteSet),!0),Rf=(n,e,t)=>{let r=e._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&W(n.changed,e,Se).add(t)},zs=(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 T&&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},Yf=(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=Pe(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=Ee(i.length-1,1+Pe(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+zs(i,c)}})},$w=(n,e,t)=>{Yf(n,e,t),Gf(n,e)},Xf=(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),Jf(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),li(l,[]),t._needFormattingCleanup&&u1(t)}finally{r.gc&&Yf(s,i,r.gcFilter),Gf(s,i),t.afterState.forEach((h,d)=>{let f=t.beforeState.get(d)||0;if(f!==h){let u=i.clients.get(d),p=Ue(Pe(u,f),1);for(let m=u.length-1;m>=p;)m-=1+zs(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=Pe(u,f);p+11||p>0&&zs(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(Us(pr,ai,"[yjs] ",hi,di,"Changed the client-id because another client seems to be using it."),r.clientID=Ff()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new rt;If(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Oe;If(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])):Xf(n,e+1)}}},N=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new Ws(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&&Xf(i,0)}}return o},dc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},vf=(n,e,t)=>{tt(n,t.deletions,r=>{r instanceof T&&e.scope.some(i=>Dn(i,r))&&Ic(r,!1)})},_f=(n,e,t)=>{let r=null,i=n.doc,s=n.scope;if(N(i,o=>{for(;e.length>0&&n.currStackItem===null;){let l=i.store,c=e.pop(),a=new Set,h=[],d=!1;tt(o,c.insertions,f=>{if(f instanceof T){if(f.redone!==null){let{item:u,diff:p}=uc(l,f.id);p>0&&(u=ye(o,M(u.id.client,u.id.clock+p))),f=u}!f.deleted&&s.some(u=>Dn(u,f))&&h.push(f)}}),tt(o,c.deletions,f=>{f instanceof T&&s.some(u=>Dn(u,f))&&!Mt(c.insertions,f.id)&&a.add(f)}),a.forEach(f=>{d=Mu(o,f,a,c.insertions,n.ignoreRemoteMapChanges,n)!==null||d});for(let f=h.length-1;f>=0;f--){let u=h[f];n.deleteFilter(u)&&(u.delete(o),d=!0)}n.currStackItem=d?c:null}o.changed.forEach((l,c)=>{l.has(null)&&c._searchMarker&&(c._searchMarker.length=0)}),r=o},n),n.currStackItem!=null){let o=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:n.currStackItem,type:t,changedParentTypes:o,origin:n},n]),n.currStackItem=null}return n.currStackItem},Tn=class extends Zn{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 Ht;c.afterState.forEach((g,w)=>{let I=c.beforeState.get(w)||0,z=g-I;z>0&&pi(f,w,I,z)});let u=Te(),p=!1;if(this.lastChange>0&&u-this.lastChange0&&!a&&!h){let g=d[d.length-1];g.deletions=mr([g.deletions,c.deleteSet]),g.insertions=mr([g.insertions,f])}else d.push(new dc(c.deleteSet,f)),p=!0;!a&&!h&&(this.lastChange=u),tt(c,c.deleteSet,g=>{g instanceof T&&this.scope.some(w=>Dn(w,g))&&Ic(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&&wf("[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=>vf(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>vf(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=_f(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=_f(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*Kw(n){let e=k(n.restDecoder);for(let t=0;tQf(n,ke),Qf=(n,e=we)=>{let t=[],r=new e(H(n)),i=new st(r,!1);for(let o=i.curr;o!==null;o=i.next())t.push(o);Us("Structs: ",t);let s=St(r);Us("DeleteSet: ",s)},Yw=n=>Zf(n,ke),Zf=(n,e=we)=>{let t=[],r=new e(H(n)),i=new st(r,!1);for(let s=i.curr;s!==null;s=i.next())t.push(s);return{structs:t,ds:St(r)}},mi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},eu=n=>gi(n,ke,rt),tu=(n,e=gr,t=we)=>{let r=new e,i=new st(new t(H(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=q();return x(h,o),qd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},Gw=n=>tu(n,Jt,ke),nu=(n,e=we)=>{let t=new Map,r=new Map,i=new st(new e(H(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}},Xw=n=>nu(n,ke),Qw=(n,e)=>{if(n.constructor===he){let{client:t,clock:r}=n.id;return new he(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 T(M(r,i+e),null,M(r,i+e-1),null,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e))}},gi=(n,e=we,t=Oe)=>{if(n.length===1)return n[0];let r=n.map(h=>new e(H(h))),i=r.map(h=>new st(h,!0)),s=null,o=new t,l=new mi(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)Ft(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=Qw(f,p)),s.struct.mergeWith(f)||(Ft(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())Ft(l,s.struct,s.offset),s={struct:f,offset:0}}s!==null&&(Ft(l,s.struct,s.offset),s=null),Dc(l);let c=r.map(h=>St(h)),a=mr(c);return nt(o,a),o.toUint8Array()},Ec=(n,e,t=we,r=Oe)=>{let i=Sc(e),s=new r,o=new mi(s),l=new t(H(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(Ft(o,h,Ue(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Ft(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()}Dc(o);let a=St(l);return nt(s,a),s.toUint8Array()},Zw=(n,e)=>Ec(n,e,ke,rt),ru=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:O(n.encoder.restEncoder)}),n.encoder.restEncoder=q(),n.written=0)},Ft=(n,e,t)=>{n.written>0&&n.currClient!==e.id.client&&ru(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++},Dc=n=>{ru(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(H(n)),s=new st(i,!1),o=new r,l=new mi(o);for(let a=s.curr;a!==null;a=s.next())Ft(l,e(a),0);Dc(l);let c=St(i);return nt(o,c),o.toUint8Array()},iu=({formatting:n=!0,subdocs:e=!0,yxml:t=!0}={})=>{let r=0,i=v(),s=v(),o=v(),l=v();return l.set(null,null),c=>{switch(c.constructor){case he:case ie:return c;case T:{let a=c,h=a.content;switch(h.constructor){case wr:break;case Ce:{if(t){let d=h.type;d instanceof Q&&(d.nodeName=W(s,d.nodeName,()=>"node-"+r)),d instanceof xi&&(d.hookName=W(s,d.hookName,()=>"hook-"+r))}break}case Kt:{let d=h;d.arr=d.arr.map(()=>r);break}case Rn:{let d=h;d.content=new Uint8Array([r]);break}case vn:{let d=h;e&&(d.opts={},d.doc.guid=r+"");break}case Ct:{let d=h;d.embed={};break}case B:{let d=h;n&&(d.key=W(o,d.key,()=>r+""),d.value=W(l,d.value,()=>({i:r})));break}case Si:{let d=h;d.arr=d.arr.map(()=>r);break}case Ne:{let d=h;d.str=Bd(r%10+"",d.str.length);break}default:re()}return a.parentSub&&(a.parentSub=W(i,a.parentSub,()=>r+"")),r++,c}default:re()}}},e1=(n,e)=>to(n,iu(e),ke,rt),t1=(n,e)=>to(n,iu(e),we,Oe),n1=n=>to(n,Yl,ke,Oe),su=n=>to(n,Yl,we,rt),Uf="You must not compute changes after the event-handler fired.",On=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=r1(this.currentTarget,this.target))}deletes(e){return Mt(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Xe(Uf);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=ks(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=ks(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(s))o="delete",l=ks(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 Xe(Uf);let t=this.target,r=Se(),i=Se(),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}},r1=(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||r++,i=i.right;t.unshift(r)}e=e._item.parent}return t},ou=80,Tc=0,fc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Tc++}},i1=n=>{n.timestamp=Tc++},lu=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Tc++},s1=(n,e,t)=>{if(n.length>=ou){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)=>tr(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&&tr(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=Ue(e,i.index+t))}},o1=n=>{let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},ro=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;W(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Jf(r._eH,t,e)},$=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Af(),this._dEH=Af(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw De()}clone(){throw De()}_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){Ef(this._eH,e)}observeDeep(e){Ef(this._dEH,e)}unobserve(e){Df(this._eH,e)}unobserveDeep(e){Df(this._dEH,e)}toJSON(){}},cu=(n,e,t)=>{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},au=n=>{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&&zt(r,e)){let i=r.content.getContent();for(let s=0;s{let t=0,r=n._start;for(;r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let s=0;s{let t=[];return wi(n,(r,i)=>{t.push(e(r,i,n))}),t},l1=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}}}},du=(n,e)=>{let t=no(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 T(M(o,V(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 T(M(o,V(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Rn(new Uint8Array(d))),i.integrate(n,0);break;case kt:i=new T(M(o,V(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new vn(d)),i.integrate(n,0);break;default:if(d instanceof $)i=new T(M(o,V(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Ce(d)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},fu=()=>Xe("Length exceeded!"),uu=(n,e,t,r)=>{if(t>e._length)throw fu();if(t===0)return e._searchMarker&&yi(e._searchMarker,t,r.length),$s(n,e,null,r);let i=t,s=no(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 $s(n,e,i,t)},pu=(n,e,t,r)=>{if(r===0)return;let i=t,s=r,o=no(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 fu();e._searchMarker&&yi(e._searchMarker,i,-s+r)},Ks=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n)},Oc=(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 Rn(r);break;case kt:l=new vn(r);break;default:if(r instanceof $)l=new Ce(r);else throw new Error("Unexpected content type")}new T(M(o,V(s.store,o)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},Nc=(n,e)=>{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._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},gu=(n,e)=>{let t=n._map.get(e);return t!==void 0&&!t.deleted},a1=(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&&zt(r,t)?r.content.getContent()[r.length-1]:void 0},yu=(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&&zt(s,e)&&(t[i]=s.content.getContent()[s.length-1])}),t},Ps=n=>Sf(n.entries(),e=>!e[1].deleted),js=class extends On{constructor(e,t){super(e,t),this._transaction=t}},Nn=class n extends ${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 $?t.clone():t)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(e,t){super._callObserver(e,t),ro(this,e,new js(this,e))}insert(e,t){this.doc!==null?N(this.doc,r=>{uu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?N(this.doc,t=>{c1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?N(this.doc,r=>{pu(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return du(this,e)}toArray(){return au(this)}slice(e=0,t=this.length){return cu(this,e,t)}toJSON(){return this.map(e=>e instanceof $?e.toJSON():e)}map(e){return hu(this,e)}forEach(e){wi(this,e)}[Symbol.iterator](){return l1(this)}_write(e){e.writeTypeRef(O1)}},h1=n=>new Nn,Ys=class extends On{constructor(e,t,r){super(e,t),this.keysChanged=r}},In=class n extends ${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 $?t.clone():t)}),e}_callObserver(e,t){ro(this,e,new Ys(this,e,t))}toJSON(){let e={};return this._map.forEach((t,r)=>{if(!t.deleted){let i=t.content.getContent()[t.length-1];e[r]=i instanceof $?i.toJSON():i}}),e}get size(){return[...Ps(this._map)].length}keys(){return Vs(Ps(this._map),e=>e[0])}values(){return Vs(Ps(this._map),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Vs(Ps(this._map),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){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?N(this.doc,t=>{Ks(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?N(this.doc,r=>{Oc(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Nc(this,e)}has(e){return gu(this,e)}clear(){this.doc!==null?N(this.doc,e=>{this.forEach(function(t,r,i){Ks(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(N1)}},d1=n=>new In,qt=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&jl(n,e),bi=class{constructor(e,t,r,i){this.left=e,this.right=t,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&re(),this.right.content.constructor){case B: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}},Vf=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case B:e.right.deleted||xr(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t{let i=new Map,s=r?no(e,t):null;if(s){let o=new bi(s.p.left,s.p,s.index,i);return Vf(n,o,t-s.index)}else{let o=new bi(null,e._start,0,i);return Vf(n,o,t)}},wu=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===B&&qt(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 T(M(s,V(i.store,s)),c,c&&c.lastId,a,a&&a.id,e,null,new B(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)},bu=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===B&&qt(e[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},xu=(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(!qt(a,c)){o.set(l,a);let{left:h,right:d}=t;t.right=new T(M(s,V(i.store,s)),h,h&&h.lastId,d,d&&d.id,e,null,new B(l,c)),t.right.integrate(n,0),t.forward()}}return o},sc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let s=n.doc,o=s.clientID;bu(t,i);let l=xu(n,e,t,i),c=r.constructor===String?new Ne(r):r instanceof $?new Ce(r):new Ct(r),{left:a,right:h,index:d}=t;e._searchMarker&&yi(e._searchMarker,t.index,c.getLength()),h=new T(M(o,V(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(),wu(n,e,t,l)},Bf=(n,e,t,r,i)=>{let s=n.doc,o=s.clientID;bu(t,i);let l=xu(n,e,t,i);e:for(;t.right!==null&&(r>0||l.size>0&&(t.right.deleted||t.right.content.constructor===B));){if(!t.right.deleted)switch(t.right.content.constructor){case B:{let{key:c,value:a}=t.right.content,h=i[c];if(h!==void 0){if(qt(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 T(M(o,V(s.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new Ne(c)),t.right.integrate(n,0),t.forward()}wu(n,e,t,l)},Su=(n,e,t,r,i)=>{let s=e,o=v();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===B){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 B:{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},f1=(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===B){let r=e.content.key;t.has(r)?e.delete(n):t.add(r)}e=e.left}},ku=n=>{let e=0;return N(n.doc,t=>{let r=n._start,i=n._start,s=v(),o=Ss(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case B:xr(o,i.content);break;default:e+=Su(t,r,i,s,o),s=Ss(o),r=i;break}i=i.right}}),e},u1=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&&jf(n,t.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===B&&o.constructor!==he&&e.add(o.parent)})}N(t,r=>{tt(n,n.deleteSet,i=>{if(i instanceof he||!i.parent._hasFormatting||e.has(i.parent))return;let s=i.parent;i.content.constructor===B?e.add(s):f1(r,i)});for(let i of e)ku(i)})},Pf=(n,e,t)=>{let r=t,i=Ss(e.currentAttributes),s=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Ce:case Ct:case Ne: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=[];N(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},nf(c)||(u.attributes=Zd({},c))),h=0;break}u&&t.push(u),l=null}};for(;o!==null;){switch(o.content.constructor){case Ce:case Ct: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 Ne: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 B:{let{key:u,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let m=i.get(u)??null;qt(m,p)?p!==null&&o.delete(r):(l==="retain"&&f(),qt(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;qt(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!o.deleted){s.set(u,p);let m=c[u];m!==void 0&&(qt(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}},$t=class n extends ${constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return 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 Gs(this,e,t);ro(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Ne&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?N(this.doc,r=>{let i=new bi(null,this._start,0,new Map);for(let s=0;s0)&&sc(r,this,i,l,o.attributes||{})}else o.retain!==void 0?Bf(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&Pf(r,i,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){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(zt(c,e)||t!==void 0&&zt(c,t))switch(c.content.constructor){case Ne:{let d=s.get("ychange");e!==void 0&&!zt(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&&!zt(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 Ce:case Ct:{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 B:zt(c,e)&&(a(),xr(s,c.content));break}c=c.right}a()};return e||t?N(o,d=>{e&&ac(d,e),t&&ac(d,t),h()},"cleanup"):h(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?N(i,s=>{let o=Ls(s,this,e,!r);r||(r={},o.currentAttributes.forEach((l,c)=>{r[c]=l})),sc(s,this,o,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){let i=this.doc;i!==null?N(i,s=>{let o=Ls(s,this,e,!r);sc(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?N(r,i=>{Pf(i,Ls(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?N(i,s=>{let o=Ls(s,this,e,!1);o.right!==null&&Bf(s,this,o,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?N(this.doc,t=>{Ks(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?N(this.doc,r=>{Oc(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Nc(this,e)}getAttributes(){return mu(this)}_write(e){e.writeTypeRef(I1)}},p1=n=>new $t,fi=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0}[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===Q||t.constructor===ot)&&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})}},ot=class n extends ${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 $?t.clone():t)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new fi(this,e)}querySelector(e){e=e.toUpperCase();let r=new fi(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),Fe(new fi(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){ro(this,e,new Xs(this,t,e))}toString(){return hu(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),wi(this,s=>{i.insertBefore(s.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?N(this.doc,r=>{uu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)N(this.doc,r=>{let i=e&&e instanceof $?e._item:e;$s(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 Xe("Reference item not found");r.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?N(this.doc,r=>{pu(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return au(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return du(this,e)}slice(e=0,t=this.length){return cu(this,e,t)}forEach(e){wi(this,e)}_write(e){e.writeTypeRef(v1)}},m1=n=>new ot,Q=class n extends ot{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 ef(t,(r,i)=>{typeof r=="string"&&e.setAttribute(i,r)}),e.insert(0,this.toArray().map(r=>r instanceof $?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?N(this.doc,t=>{Ks(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?N(this.doc,r=>{Oc(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Nc(this,e)}hasAttribute(e){return gu(this,e)}getAttributes(e){return e?yu(this,e):mu(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 wi(this,o=>{i.appendChild(o.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(R1),e.writeKey(this.nodeName)}},g1=n=>new Q(n.readKey()),Xs=class extends On{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)})}},xi=class n extends In{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(_1),e.writeKey(this.hookName)}},y1=n=>new xi(n.readKey()),be=class n extends $t{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(U1)}},w1=n=>new be,yr=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw De()}mergeWith(e){return!1}write(e,t,r){throw De()}integrate(e,t){throw De()}},b1=0,he=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),Kf(e.doc.store,this)}write(e,t){e.writeInfo(b1),e.writeLen(this.length-t)}getMissing(e,t){return null}},Rn=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 De()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},x1=n=>new Rn(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){pi(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}},S1=n=>new wr(n.readLen()),Cu=(n,e)=>new kt({guid:n,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),vn=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(Cu(this.doc.guid,this.opts))}splice(e){throw De()}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}},k1=n=>new vn(Cu(n.readString(),n.readAny())),Ct=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 De()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},C1=n=>new Ct(n.readJSON()),B=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 De()}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}},M1=n=>new B(n.readKey(),n.readJSON()),Si=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}},D1=n=>new Ne(n.readString()),T1=[h1,d1,p1,g1,m1,y1,w1],O1=0,N1=1,I1=2,R1=3,v1=4,_1=5,U1=6,Ce=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 De()}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}},V1=n=>new Ce(T1[n.readTypeRef()](n)),uc=(n,e)=>{let t=e,r=0,i;do r>0&&(t=M(t.client,t.clock+r)),i=An(n,t),r=t.clock-i.id.clock,t=i.redone;while(t!==null&&i instanceof T);return{item:i,diff:r}},Ic=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},Qs=(n,e,t)=>{let{client:r,clock:i}=e.id,s=new T(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},Lf=(n,e)=>Id(n,t=>Mt(t.deletions,e)),Mu=(n,e,t,r,i,s)=>{let o=n.doc,l=o.store,c=o.clientID,a=e.redone;if(a!==null)return ye(n,a);let h=e.parent._item,d=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!t.has(h)||Mu(n,h,t,r,i,s)===null))return null;for(;h.redone!==null;)h=ye(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 w=d;for(;w!==null&&w.parent._item!==h;)w=w.redone===null?null:ye(n,w.redone);if(w!==null&&w.parent._item===h){d=w;break}d=d.left}for(;f!==null;){let w=f;for(;w!==null&&w.parent._item!==h;)w=w.redone===null?null:ye(n,w.redone);if(w!==null&&w.parent._item===h){f=w;break}f=f.right}}else if(f=null,e.right&&!i){for(d=e;d!==null&&d.right!==null&&(d.right.redone||Mt(r,d.right.id)||Lf(s.undoStack,d.right.id)||Lf(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=ye(n,d.redone);if(d&&d.right!==null)return null}else d=u._map.get(e.parentSub)||null;let p=V(l,c),m=M(c,p),g=new T(m,d,d&&d.lastId,f,f&&f.id,u,e.parentSub,e.content.copy());return e.redone=m,Ic(g,!0),g.integrate(n,0),g},T=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>=V(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=V(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===xt&&this.id.client!==this.parent.client&&this.parent.clock>=V(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Nf(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=ye(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===he||this.right&&this.right.constructor===he)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===xt){let r=An(t,this.parent);r.constructor===he?this.parent=null:this.parent=r.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Nf(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),Mn(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(),pi(e.deleteSet,this.id.client,this.id.clock,this.length),Rf(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw re();this.content.gc(e),t?Ww(e,this,new he(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===xt?(e.writeParentInfo(!1),e.writeLeftID(l)):re();s!==null&&e.writeString(s)}this.content.write(e,t)}},Au=(n,e)=>B1[e&31](n),B1=[()=>{re()},S1,A1,x1,D1,C1,M1,V1,E1,k1,()=>{re()}],P1=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){re()}write(e,t){e.writeInfo(P1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Eu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Du="__ $YJS$ __";Eu[Du]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Eu[Du]=!0;var Tu=new Map,Rc=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:hf(t.newValue||"")}),Gd(this._onChange)}postMessage(e){Is.setItem(this.room,af(cf(e)))}close(){Xd(this._onChange)}},L1=typeof BroadcastChannel>"u"?Rc:BroadcastChannel,vc=n=>W(Tu,n,()=>{let e=Se(),t=new L1(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),Ou=(n,e)=>(vc(n).subs.add(e),e),Nu=(n,e)=>{let t=vc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Tu.delete(n)),r},Vn=(n,e,t=null)=>{let r=vc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var Iu=0,so=1,Ru=2,oo=(n,e)=>{x(n,Iu);let t=Cc(e);_(n,t)},_c=(n,e,t)=>{x(n,so),_(n,xc(e,t))},F1=(n,e,t)=>_c(e,t,K(n)),vu=(n,e,t)=>{try{bc(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},_u=(n,e)=>{x(n,Ru),_(n,e)},q1=vu,Uu=(n,e,t,r)=>{let i=k(n);switch(i){case Iu:F1(n,e,t);break;case so:vu(n,t,r);break;case Ru:q1(n,t,r);break;default:throw new Error("Unknown message type")}return i};var J1=0;var Vu=(n,e,t)=>{switch(k(n)){case J1:t(e,Be(n))}};var Uc=3e4,lo=class extends er{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let t=Te();this.getLocalState()!==null&&Uc/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((i,s)=>{s!==this.clientID&&Uc<=t-i.lastUpdated&&this.states.has(s)&&r.push(s)}),r.length>0&&co(this,r,"timeout")},ae(Uc/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:Te()});let o=[],l=[],c=[],a=[];e===null?a.push(t):s==null?e!=null&&o.push(t):(l.push(t),fr(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}},co=(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=q();x(i,r);for(let s=0;s{let r=H(e),i=Te(),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 Pu=n=>tf(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Bn=0,zu=3,Cr=1,j1=2,Ai=[];Ai[Bn]=(n,e,t,r,i)=>{x(n,Bn);let s=Uu(e,n,t.doc,t);r&&s===so&&!t.synced&&(t.synced=!0)};Ai[zu]=(n,e,t,r,i)=>{x(n,Cr),_(n,kr(t.awareness,Array.from(t.awareness.getStates().keys())))};Ai[Cr]=(n,e,t,r,i)=>{Bu(t.awareness,K(e),t)};Ai[j1]=(n,e,t,r,i)=>{Vu(e,t.doc,(s,o)=>Y1(t,o))};var Lu=3e4,Y1=(n,e)=>console.warn(`Permission denied to access ${n.url}. -${e}`),Fu=(n,e,t)=>{let r=H(e),i=q(),s=k(r),o=n.messageHandlers[s];return o?o(i,r,n,t,s):console.error("Unable to compute message"),i},qu=n=>{if(n.shouldConnect&&n.ws===null){let e=new n._WS(n.url);e.binaryType="arraybuffer",n.ws=e,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,e.onmessage=t=>{n.wsLastMessageReceived=Te();let r=Fu(n,new Uint8Array(t.data),!0);Es(r)>1&&e.send(O(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,co(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(qu,Ee(vd(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},e.onopen=()=>{n.wsLastMessageReceived=Te(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);let t=q();if(x(t,Bn),oo(t,n.doc),e.send(O(t)),n.awareness.getLocalState()!==null){let r=q();x(r,Cr),_(r,kr(n.awareness,[n.doc.clientID])),e.send(O(r))}},n.emit("status",[{status:"connecting"}])}},Vc=(n,e)=>{let t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN&&t.send(e),n.bcconnected&&Vn(n.bcChannel,e,n)},Bc=class extends er{constructor(e,t,r,{connect:i=!0,awareness:s=new lo(r),params:o={},WebSocketPolyfill:l=WebSocket,resyncInterval:c=-1,maxBackoffTime:a=2500,disableBc:h=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);let d=Pu(o);this.maxBackoffTime=a,this.bcChannel=e+"/"+t,this.url=e+"/"+t+(d.length===0?"":"?"+d),this.roomname=t,this.doc=r,this._WS=l,this.awareness=s,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=h,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Ai.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,c>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let f=q();x(f,Bn),oo(f,r),this.ws.send(O(f))}},c)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=Fu(this,new Uint8Array(f),!1);Es(p)>1&&Vn(this.bcChannel,O(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=q();x(p,Bn),_u(p,f),Vc(this,O(p))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:f,updated:u,removed:p},m)=>{let g=f.concat(u).concat(p),w=q();x(w,Cr),_(w,kr(s,g)),Vc(this,O(w))},this._exitHandler=()=>{co(this.awareness,[r.clientID],"app closed")},wt&&typeof process<"u"&&process.on("exit",this._exitHandler),s.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Lu{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var G1=/[\uD800-\uDBFF]/,X1=/[\uDC00-\uDFFF]/,Q1=(n,e)=>{let t=0,r=0;for(;t0&&G1.test(n[t-1])&&t--;r+t0&&X1.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Ju=Q1;var R=new fe("y-sync"),jt=new fe("y-undo"),Ei=new fe("yjs-cursor");var Ti=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!Mt(e.ds,n.id),Z1=[{light:"#ecd44433",dark:"#ecd444"}],eb=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,$d(e))}return n.get(t)},Ku=(n,{colors:e=Z1,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{}}={})=>{let s=!1,o=new F({props:{editable:l=>{let c=R.getState(l);return c.snapshot==null&&c.prevSnapshot==null}},key:R,state:{init:(l,c)=>({type:n,doc:n.doc,binding:null,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:t,permanentUserData:r}),apply:(l,c)=>{let a=l.getMeta(R);if(a!==void 0){c=Object.assign({},c);for(let h in a)c[h]=a[h]}return c.addToHistory=l.getMeta("addToHistory")!==!1,c.isChangeOrigin=a!==void 0&&!!a.isChangeOrigin,c.isUndoRedoOperation=a!==void 0&&!!a.isChangeOrigin&&!!a.isUndoRedoOperation,c.binding!==null&&a!==void 0&&(a.snapshot!=null||a.prevSnapshot!=null)&&ci(0,()=>{c.binding==null||c.binding.isDestroyed||(a.restore==null?c.binding._renderSnapshot(a.snapshot,a.prevSnapshot,c):(c.binding._renderSnapshot(a.snapshot,a.snapshot,c),delete c.restore,delete c.snapshot,delete c.prevSnapshot,c.binding.mux(()=>{c.binding._prosemirrorChanged(c.binding.prosemirrorView.state.doc)})))}),c}},view:l=>{let c=new ao(n,l);return c._forceRerender(),i(),{update:()=>{let a=o.getState(l.state);if(a.snapshot==null&&a.prevSnapshot==null&&(s||l.state.doc.content.findDiffStart(l.state.doc.type.createAndFill().content)!==null)){if(s=!0,a.addToHistory===!1&&!a.isChangeOrigin){let h=jt.getState(l.state),d=h&&h.undoManager;d&&d.stopCapturing()}c.mux(()=>{a.doc.transact(h=>{h.meta.set("addToHistory",a.addToHistory),c._prosemirrorChanged(l.state.doc)},R)})}},destroy:()=>{c.destroy()}}}});return o},tb=(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)))}},Oi=(n,e)=>({anchor:Pn(e.selection.anchor,n.type,n.mapping),head:Pn(e.selection.head,n.type,n.mapping)}),ao=class{constructor(e,t){this.type=e,this.prosemirrorView=t,this.mux=Hu(),this.isDestroyed=!1,this.mapping=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&(this.beforeTransactionSelection=Oi(this,t.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),e.observeDeep(this._observeFunction),this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(ur&&this._domSelectionInView===null&&(ci(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=bt.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=Ci(br(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(R,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping=new Map,this.mux(()=>{let e=this.type.toArray().map(r=>Di(r,this.prosemirrorView.state.schema,this.mapping)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(y.from(e),0,0));t.setMeta(R,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping=new Map,this.mux(()=>{let e=this.type.toArray().map(r=>Di(r,this.prosemirrorView.state.schema,this.mapping)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(y.from(e),0,0));this.prosemirrorView.dispatch(t.setMeta(R,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,r){e||(e=Ac(this.doc)),this.mapping=new Map,this.mux(()=>{this.doc.transact(i=>{let s=r.permanentUserData;s&&s.dss.forEach(a=>{tt(i,a,h=>{})});let o=(a,h)=>{let d=a==="added"?s.getUserByClientId(h.client):s.getUserByDeletedId(h);return{user:d,type:a,color:eb(r.colorMapping,r.colors,d)}},l=io(this.type,new Wt(t.ds,e.sv)).map(a=>!a._item.deleted||Ti(a._item,e)||Ti(a._item,t)?Di(a,this.prosemirrorView.state.schema,new Map,e,t,o):null).filter(a=>a!==null),c=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(y.from(l),0,0));this.prosemirrorView.dispatch(c.setMeta(R,{isChangeOrigin:!0}))},R)})}_typeChanged(e,t){let r=R.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);tt(t,t.deleteSet,l=>{if(l.constructor===T){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=>ju(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null),o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(y.from(s),0,0));tb(o,this.beforeTransactionSelection,this),o=o.setMeta(R,{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=Oi(this,this.prosemirrorView.state)},R)}destroy(){this.isDestroyed=!0,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions)}},ju=(n,e,t,r,i,s)=>{let o=t.get(n);if(o===void 0){if(n instanceof Q)return Di(n,e,t,r,i,s);throw De()}return o},Di=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c.constructor===Q){let a=ju(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=nb(c,e,t,r,i,s);a!==null&&a.forEach(h=>{h!==null&&o.push(h)})}};r===void 0||i===void 0?n.toArray().forEach(l):io(n,new Wt(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(Ti(n._item,r)?Ti(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)},R),t.delete(n),null}},nb=(n,e,t,r,i,s)=>{let o=[],l=n.toDelta(r,i,s);try{for(let c=0;c{n._item.delete(a)},R),null}return o},rb=(n,e)=>{let t=new be,r=n.map(i=>({insert:i.text,attributes:Gu(i.marks)}));return t.applyDelta(r),e.set(t,n),t},ib=(n,e)=>{let t=new Q(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,fo(n).map(r=>Pc(r,e))),e.set(t,n),t},Pc=(n,e)=>n instanceof Array?rb(n,e):ib(n,e),Wu=n=>typeof n=="object"&&n!==null,zc=(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&&$l(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(s=>zc(r.attributes[s.type.name]||{},s.attrs)))},Ni=(n,e)=>{if(n instanceof Q&&!(e instanceof Array)&&Lc(n,e)){let t=fo(e);return n._length===t.length&&zc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Ni(r,t[i]))}return n instanceof be&&e instanceof Array&&Yu(n,e)},ho=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),$u=(n,e,t)=>{let r=n.toArray(),i=fo(e),s=i.length,o=r.length,l=Ee(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 Ne?e+=t.content.str:t.content instanceof B&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},ob=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=sb(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,Gu(a.marks))})),{insert:o,remove:l,index:c}=Ju(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})))},Gu=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 Q&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.set(e,t),e instanceof Q){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=fo(t),s=i.length,o=e.toArray(),l=o.length,c=Ee(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 be&&u instanceof Array)Yu(f,u)||ob(f,u,r),a+=1;else{let g=f instanceof Q&&Lc(f,u),w=p instanceof Q&&Lc(p,m);if(g&&w){let I=$u(f,u,r),z=$u(p,m,r);I.foundMappedChild&&!z.foundMappedChild?w=!1:!I.foundMappedChild&&z.foundMappedChild||I.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 Ii=null,lb=()=>{let n=Ii;Ii=null,n.forEach((e,t)=>{let r=t.state.tr,i=R.getState(t.state);i&&i.binding&&!i.binding.isDestroyed&&(e.forEach((s,o)=>{r.setMeta(o,s)}),t.dispatch(r))})},Fc=(n,e,t)=>{Ii||(Ii=new Map,ci(0,lb)),W(Ii,n,v).set(e,t)},Pn=(n,e,t)=>{if(n===0)return ki(e,0);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof be){if(r._length>=n)return ki(r,n);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 it(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 it(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 re();if(n===0&&r.constructor!==be&&r!==e)return cb(r._item.parent,r._item)}return ki(e,e._length)},cb=(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 it(t,r,e.id)},Yt=(n,e,t,r)=>{let i=Mc(t,n);if(i===null||i.type!==e&&!Dn(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===be)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 Qu(n,e="prosemirror"){return Hc(n.getXmlFragment(e))}function Hc(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 ab=(n,e,t)=>n!==e,hb=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},db=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),fb=/^#[0-9a-fA-F]{6}$/,Zu=(n,e,t,r,i)=>{let s=R.getState(n),o=s.doc,l=[];return s.snapshot!=null||s.prevSnapshot!=null||s.binding===null?P.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":fb.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=Ue(n.doc.content.size-1,0);d=Ee(d,u),f=Ee(f,u),l.push(te.widget(f,()=>r(h),{key:a+"",side:10}));let p=Ee(d,f),m=Ue(d,f);l.push(te.inline(p,m,i(h),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),P.create(n.doc,l))},ub=(n,{awarenessStateFilter:e=ab,cursorBuilder:t=hb,selectionBuilder:r=db,getSelection:i=o=>o.selection}={},s="cursor")=>new F({key:Ei,state:{init(o,l){return Zu(l,n,e,t,r)},apply(o,l,c,a){let h=R.getState(a),d=o.getMeta(Ei);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?Zu(a,n,e,t,r):l.map(o.mapping,o.doc)}},props:{decorations:o=>Ei.getState(o)},view:o=>{let l=()=>{o.docView&&Fc(o,Ei,{awarenessUpdated:!0})},c=()=>{let a=R.getState(o.state),h=n.getLocalState()||{};if(a.binding!=null)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||!eo(Un(h.cursor.anchor),f)||!eo(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 pb=n=>{let e=jt.getState(n).undoManager;if(e!=null)return e.undo(),!0},mb=n=>{let e=jt.getState(n).undoManager;if(e!=null)return e.redo(),!0},gb=new Set(["paragraph"]),yb=(n,e)=>!(n instanceof T)||!(n.content instanceof Ce)||!(n.content.type instanceof $t||n.content.type instanceof Q&&e.has(n.content.type.nodeName))||n.content.type._length===0,wb=({protectedNodes:n=gb,trackedOrigins:e=[],undoManager:t=null}={})=>new F({key:jt,state:{init:(r,i)=>{let s=R.getState(i),o=t||new Tn(s.type,{trackedOrigins:new Set([R].concat(e)),deleteFilter:l=>yb(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=R.getState(o).binding,c=i.undoManager,a=c.undoStack.length>0,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Oi(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=R.getState(r.state),s=jt.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,jt.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 Ri="http://www.w3.org/2000/svg",bb="http://www.w3.org/1999/xlink",Wc="ProseMirror-icon",Jc="pm-close-dropdowns";function xb(n){let e=0;for(let t=0;t{s.preventDefault(),r.classList.contains(At+"-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,ep(r,At+"-disabled",!o)),t.active){let l=o&&t.active(s)||!1;ep(r,At+"-active",l)}return!0}return{dom:r,update:i}}};function uo(n,e){return n._props.translate?n._props.translate(e):e}var vi={time:0,node:null};function Cb(n){vi.time=Date.now(),vi.node=n.target}function Mb(n){return Date.now()-100{o&&o.close()&&(o=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(Jc,c))};i.addEventListener("mousedown",d=>{d.preventDefault(),Cb(d),o?a():(r.dispatchEvent(new CustomEvent(Jc)),o=this.expand(s,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{Mb(s)||a()}),r.addEventListener(Jc,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=pt("div",{class:At+"-dropdown-menu "+(this.options.class||"")},t),i=!1;function s(){return i?!1:(i=!0,e.removeChild(r),!0)}return e.appendChild(r),{close:s,node:r}}};function Ab(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iKr(n),icon:_i.join}),Ck=new Et({title:"Lift out of enclosing block",run:jr,select:n=>jr(n),icon:_i.lift}),Mk=new Et({title:"Select parent node",run:Yr,select:n=>Yr(n),icon:_i.selectParentNode}),Ak=new Et({title:"Undo last change",run:yn,enable:n=>yn(n),icon:_i.undo}),Ek=new Et({title:"Redo last undone change",run:Bt,enable:n=>Bt(n),icon:_i.redo});function Tb(n,e){let t=Xn(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 Et(r)}function ep(n,e,t){t?n.classList.add(e):n.classList.remove(e)}export{zn as DOMParser,Ot as DOMSerializer,$c as Dropdown,_o as EditorState,il as EditorView,y as Fragment,mt as InputRule,Et as MenuItem,F as Plugin,Tr as Schema,b as Slice,A as TextSelection,Bc as WebsocketProvider,Sr as Y,u0 as addColumnAfter,f0 as addColumnBefore,cy as addListNodes,w0 as addRowAfter,y0 as addRowBefore,Qh as baseKeymap,Ng as baseSchema,Tb as blockTypeItem,Oy as buildKeymap,t0 as columnResizing,m0 as deleteColumn,x0 as deleteRow,T0 as deleteTable,Cd as fixTables,xy as gapCursor,D0 as goToNextCell,nd as history,od as inputRules,yy as keymap,Sl as liftListItem,k0 as mergeCells,Xu as prosemirrorToYDoc,qc as prosemirrorToYXmlFragment,Bt as redo,Eb as renderGrouped,kl as sinkListItem,C0 as splitCell,xl as splitListItem,O0 as tableEditing,_y as tableNodes,pn as toggleMark,yn as undo,fs as wrapInList,ub as yCursorPlugin,Qu as yDocToProsemirrorJSON,mb as yRedo,Ku as ySyncPlugin,pb as yUndo,wb as yUndoPlugin,Hc as yXmlFragmentToProsemirrorJSON}; +`);return{dom:c,text:f,slice:e}}function zh(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=Ym(t),Kr&&Gm(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")||Jn.fromSchema(n.state.schema)).parseSlice(o,{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)),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&&qh(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=Hh(o[o.length-1],s.length));let h=Fh(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return w.from(o)}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&&(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 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(s=>"<"+s+">").join("")+n+i.map(s=>"").reverse().join("")),t.innerHTML=Km(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={},Qm={touchstart:!0,touchmove:!0},nl=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)&&!fl(n,r)&&(n.editable||!(r.type in ye))&&t(n,r)},Qm[e]?{passive:!0}:void 0)}me&&n.dom.addEventListener("input",()=>null),rl(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 rl(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>fl(n,r))})}function fl(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){!fl(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&&ce&&t.keyCode==13)))if(n.domObserver.selectionChanged(n.domSelectionRange())?n.domObserver.flush():t.keyCode!=229&&n.domObserver.forceFlush(),Qn&&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,cn(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",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function ps(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 ul(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 Xn(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)?(Xn(n,new C(t),"pointer"),!0):!1}function sg(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?(Xn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function og(n,e,t,r,i){return ul(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?sg(n,t):ig(n,t))}function lg(n,e,t,r){return ul(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function cg(n,e,t,r){return ul(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?(Xn(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)Xn(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(C.isSelectable(o))Xn(n,C.create(r,l),"pointer");else continue;return!0}}function pl(n){return cs(n)}var Wh=ve?"metaKey":"ctrlKey";ge.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=pl(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&rg(t,n.input.lastClick)&&!t[Wh]&&(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(ps(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new il(n,o,t,!!r)):(s=="doubleClick"?lg:cg)(n,o.pos,o.inside,t)?t.preventDefault():Vt(n,"pointer"))};var il=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 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(()=>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(ps(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||ce&&!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)?(Xn(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(),pl(n),Vt(n,"pointer")};ge.touchmove=n=>{n.input.lastTouch=Date.now(),Vt(n,"pointer")};ge.contextmenu=n=>pl(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(),cs(n,!0),n.markCursor=null;else if(cs(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}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(()=>cs(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,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 fg(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function cs(n,e=!1){if(!(Fe&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Yh(n),e||n.docView&&n.docView.dirty){let t=hl(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 Jr=ke&&Bt<15||Qn&&pm<604;ge.copy=ye.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=Jr?null:t.clipboardData,o=r.content(),{dom:l,text:c}=Lh(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.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?$r(n,r.value,null,i,e):$r(n,r.textContent,r.innerHTML,i,e)},50)}function $r(n,e,t,r,i){let s=zh(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=pg(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 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=Jr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&$r(n,Gh(r),r.getData("text/html"),i,t)?t.preventDefault():mg(n,t)};var as=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,s=i.empty?null:n.posAtCoords(ps(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}=Lh(n,l);(!t.dataTransfer.files.length||!ce||Ah>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Jr?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",Jr||t.dataTransfer.setData("text/plain",a),n.dragging=new as(h,!t[Xh],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(ps(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=zh(n,Gh(t.dataTransfer),Jr?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[Xh]);if(n.someProp("handleDrop",p=>p(n,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let c=o?Ra(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(dl(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(ce&&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,cn(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 Wr(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 hs=class n{constructor(e,t){this.toDOM=e,this.spec=t||fn,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&&Wr(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},dn=class n{constructor(e,t){this.attrs=e,this.spec=t||fn}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==le||e.maps.length==0?this:this.mapInner(e,t,0,0,r||fn)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let a=c+r,h;if(h=Zh(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 dn){let a=Math.max(s,c.from)-s,h=Math.min(o,c.to)-s;ai.map(e,t,fn));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!=le?(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,s,o),h=fs(a,r,0,o);e=h.local;for(let d=0;dt&&o.to{let a=Zh(n,l,c+t);if(a){s=!0;let h=fs(a,l,t+c+1,r);h!=le&&i.push(c,c+l.nodeSize,h)}});let o=Qh(s?ed(n):n,-t).sort(un);for(let l=0;l0;)e++;n.splice(e,0,t)}function qo(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=le&&e.push(r)}),n.cursorWrapper&&e.push(L.create(n.state.doc,[n.cursorWrapper.deco])),ds.from(e)}var wg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},bg=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}},ll=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()}),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(sh(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&&pn(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=Hr(s))t.add(s);for(let s=e.anchorNode;s;s=Hr(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)&&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),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||kg(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),xg(e)),this.handleDOMChange(s,o,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],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")||Jn.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: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+o,head:y+o}}return{doc:m,sel:p,from:o,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 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=hl(n,T);if(Nt&&!n.state.selection.eq(Nt)){if(ce&&Fe&&n.input.lastKeyCode===13&&Date.now()-100up(n,cn(13,"Enter"))))return;let Li=n.state.tr.setSelection(Nt);T=="pointer"?Li.setMeta("pointer",!0):T=="key"&&Li.scrollIntoView(),s&&Li.setMeta("composition",s),n.dispatch(Li)}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=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,cn(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);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((Qn&&n.input.lastIOSEnter>Date.now()-225&&(!E||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!E&&m.posT(n,cn(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,cn(8,"Backspace")))){Fe&&ce&&n.domObserver.suppressSelectionUpdates();return}ce&&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,cn(13,"Enter"))})},20));let Se=p.start,ue=p.endA,Y,ht,Ot;if(E){if(m.pos==g.pos)ke&&Bt<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>pt(n),20)),Y=n.state.tr.delete(Se,ue),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,ue,Ot.mark):Y.removeMark(Se,ue,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,ue,T)))return;Y=n.state.tr.insertText(T,Se,ue)}}if(Y||(Y=n.state.tr.replace(Se,ue,a.doc.slice(p.start-a.from,p.endB-a.from))),a.sel){let T=yh(n,Y.doc,a.sel);T&&!(ce&&Fe&&n.composing&&T.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:dl(n,e.resolve(t.anchor),e.resolve(t.head))}function Tg(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||Ho(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 Og(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 cl=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 nl,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),qo(this),this.dom,this),this.domObserver=new ll(this,(r,i,s,o)=>Eg(this,r,i,s,o)),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&&rl(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,s=!1,o=!1;e.storedMarks&&this.composing&&(Yh(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=kh(this);Ig(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&rl(this),this.editable=Sh(this),xh(this);let c=qo(this),a=bh(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&&ym(this);if(o){this.domObserver.stop();let u=d&&(ke||ce)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Ng(i.selection,e.selection);if(d){let p=ce?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=dg(this)),(s||!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))?pt(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(s))==r.node&&(i=s)}this.dragging=new as(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 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 $r(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return $r(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(eg(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],qo(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 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 Ir({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 o=r.blockRange(),l=o&&sn(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(od(n,i,e,-1))return!0;if(r.parent.content.size==0&&(er(s,"end")||C.isSelectable(s)))for(let o=r.depth;;o--){let l=Zi(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 er(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,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=rd(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 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 s=i.nodeAfter;if(od(n,i,e,1))return!0;if(r.parent.content.size==0&&(er(s,"start")||C.isSelectable(s))){let o=Zi(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||!on(n.doc,t.from))return!1;i=t.from}else if(i=_o(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},sd=(n,e)=>{let t=n.selection,r;if(t instanceof C){if(t.node.isTextblock||!on(n.doc,t.to))return!1;r=t.to}else if(r=_o(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},Gr=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&sn(i);return s==null?!1:(e&&e(n.tr.lift(i,s).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 yl(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=yl(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},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 s=yl(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&&sn(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 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:yl(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 Zg=Qg();var Xr=(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)},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,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||on(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function od(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&ty(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&&on(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&&sn(d);if(f!=null&&f>=e.depth)return t&&t(n.tr.lift(d,f).scrollIntoView()),!0;if(a&&er(s,"start",!0)&&er(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 ld(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 ny=ld(-1),ry=ld(1);function bl(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Qi(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function tr(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 sy(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=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 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,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<=ms)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=ms)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 ly=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),xl=re;var cy=500,wn=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 Ke(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 Ke(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;hhy&&(l=ay(l,a),o-=a),new n(l.append(s),o)}remapping(e,t){let r=new Ur;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 Ke(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 Ke(p,m,g))}else r.push(new Ke(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=[],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 Ke(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(xl.from(i.reverse()),s)}};wn.empty=new wn(xl.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 Ke=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)}}},Ye=class{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}},hy=20;function dy(n,e,t,r){let i=t.getMeta(yn),s;if(i)return i.historyState;t.getMeta(py)&&(n=new Ye(n.done,n.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(o&&o.getMeta(yn))return o.getMeta(yn).redo?new Ye(n.done.addTransform(t,void 0,r,gs(e)),n.undone,dd(t.mapping.maps),n.prevTime,n.prevComposition):new Ye(n.done,n.undone.addTransform(t,void 0,r,gs(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),c=n.prevTime==0||!o&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-r.newGroupDelay||!fy(t,n.prevRanges)),a=o?Sl(n.prevRanges,t.mapping):dd(t.mapping.maps);return new Ye(n.done.addTransform(t,c?e.selection.getBookmark():void 0,r,gs(e)),wn.empty,a,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new Ye(n.done.rebased(t,s),n.undone.rebased(t,s),Sl(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new Ye(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),Sl(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function fy(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,i)=>{for(let s=0;s=e[s]&&(t=!0)}),t}function dd(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((r,i,s,o)=>e.push(s,o));return e}function Sl(n,e){if(!n)return null;let t=[];for(let r=0;r{let i=yn.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=uy(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}var bn=ys(!1,!0),zt=ys(!0,!0),ux=ys(!1,!1),px=ys(!0,!1);var my=["ol",0],gy=["ul",0],yy=["li",0],wy={attrs:{order:{default:1,validate:"number"}},parseDOM:[{tag:"ol",getAttrs(n){return{order:n.hasAttribute("start")?+n.getAttribute("start"):1}}}],toDOM(n){return n.attrs.order==1?my:["ol",{start:n.attrs.order},0]}},by={parseDOM:[{tag:"ul"}],toDOM(){return gy}},xy={parseDOM:[{tag:"li"}],toDOM(){return yy},defining:!0};function Cl(n,e){let t={};for(let r in n)t[r]=n[r];for(let r in e)t[r]=e[r];return t}function Sy(n,e,t){return n.append({ordered_list:Cl(wy,{content:"list_item+",group:t}),bullet_list:Cl(by,{content:"list_item+",group:t}),list_item:Cl(xy,{content:e})})}function ws(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=!1,c=o;if(!o)return!1;if(o.depth>=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 tn(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 Al(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?Cy(e,t,n,s):My(e,t,s):!0:!1}}function Cy(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 El(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 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:"'"},xs={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Ay=typeof navigator<"u"&&/Mac/.test(navigator.platform),Ey=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),xs[J]=String.fromCharCode(J);var J;for(bs in gt)xs.hasOwnProperty(bs)||(xs[bs]=gt[bs]);var bs;function pd(n){var e=Ay&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Ey&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?xs: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 Ty=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Dy(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l127)&&(s=gt[r.keyCode])&&s!=i){let l=e[Tl(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var ae=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 Dl(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Iy(e)||!Ry(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}}};ae.prototype.visible=!1;ae.findFrom=ae.findGapCursorFrom;S.jsonID("gapcursor",ae);var Dl=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 ae.valid(t)?new ae(t):S.near(t)}};function Iy(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 Ry(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 F({props:{decorations:By,createSelectionBetween(n,e,t){return e.pos==t.pos&&ae.valid(t)?new ae(t):null},handleClick:Uy,handleKeyDown:_y,handleDOMEvents:{beforeinput:Vy}}})}var _y=Zr({ArrowLeft:Ss("horiz",-1),ArrowRight:Ss("horiz",1),ArrowUp:Ss("vert",-1),ArrowDown:Ss("vert",1)});function Ss(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=ae.findGapCursorFrom(l,e,c);return a?(i&&i(r.tr.setSelection(new ae(a))),!0):!1}}function Uy(n,e,t){if(!n||!n.editable)return!1;let r=n.state.doc.resolve(e);if(!ae.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 ae(r))),!0)}function Vy(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof ae))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 By(n){if(!(n.selection instanceof ae))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 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&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}var Ly=500;function yd({rules:n}){let e=new F({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 gd(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&gd(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function gd(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-Ly),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},zy=new wt(/--$/,"\u2014"),Fy=new wt(/\.\.\.$/,"\u2026"),Ix=new wt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C"),Rx=new wt(/"$/,"\u201D"),vx=new wt(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018"),_x=new wt(/'$/,"\u2019");var bd=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function qy(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",bn),i("Shift-Mod-z",zt),i("Backspace",wd),bd||i("Mod-y",zt),i("Alt-ArrowUp",Yr),i("Alt-ArrowDown",sd),i("Mod-BracketLeft",Gr),i("Escape",Xr),(r=n.marks.strong)&&(i("Mod-b",gn(r)),i("Mod-B",gn(r))),(r=n.marks.em)&&(i("Mod-i",gn(r)),i("Mod-I",gn(r))),(r=n.marks.code)&&i("Mod-`",gn(r)),(r=n.nodes.bullet_list)&&i("Shift-Ctrl-8",ws(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",ws(r)),(r=n.nodes.blockquote)&&i("Ctrl->",bl(r)),r=n.nodes.hard_break){let s=r,o=Qr(wl,(l,c)=>(c&&c(l.tr.replaceSelectionWith(s.create()).scrollIntoView()),!0));i("Mod-Enter",o),i("Shift-Enter",o),bd&&i("Ctrl-Enter",o)}if((r=n.nodes.list_item)&&(i("Enter",Ml(r)),i("Mod-[",Al(r)),i("Mod-]",El(r))),(r=n.nodes.paragraph)&&i("Shift-Ctrl-0",tr(r)),(r=n.nodes.code_block)&&i("Shift-Ctrl-\\",tr(r)),r=n.nodes.heading)for(let s=1;s<=6;s++)i("Shift-Ctrl-"+s,tr(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 Nl,Il;if(typeof WeakMap<"u"){let n=new WeakMap;Nl=e=>n.get(e),Il=(e,t)=>(n.set(e,t),t)}else{let n=[],t=0;Nl=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 ue=0;uer&&(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 $y(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 Sd(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=>xd(r,e)}],toDOM(r){return["td",Sd(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>xd(r,e)}],toDOM(r){return["th",Sd(r,e),0]}}}}function he(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 Ft=new pe("selectingCells");function nr(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 Ky(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 Ge(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 Ul(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=nr(e.$head)||Yy(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Yy(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 Rl(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Gy(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function Vl(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function Nd(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 xn(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 Id(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(Rl(r)&&Rl(i)&&Vl(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?bt.rowSelection(r,i):s&&this.isColSelection()?bt.colSelection(r,i):new bt(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=xn(y,0,m)),g>0&&(y=xn(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 bt&&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 e0({$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 t0({$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 n0(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&&e0(r)?s=A.create(i,r.from):r instanceof A&&t0(r)&&(s=A.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}var r0=new pe("fix-tables");function vd(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=i0(n,i,s,t))};return e?e.doc!=n.doc&&vd(e.doc,n.doc,0,r):n.doc.descendants(r),t}function i0(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;Xy(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;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[s]==t[s-1]||r.right0&&t[i]==t[i-n]||r.bottomt[r.type.spec.tableRole])(n,e)}function y0(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=Ky(i.$from),!s)return!1;o=(r=nr(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=Xe(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 tS=Bl("row",{useDeprecatedLogic:!0}),nS=Bl("column",{useDeprecatedLogic:!0}),rS=Bl("cell",{useDeprecatedLogic:!0});function b0(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 ks(n,e){let t=n.selection;if(!(t instanceof V))return!1;if(e){let r=n.tr,i=he(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 k0(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(xn(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 A0(n,e,t,r,i,s,o){let l=n.doc.type.schema,c=he(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 As(t,r,S.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=Bd(i,n,e);if(o==null)return!1;if(n=="horiz")return As(t,r,S.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),c=Nd(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),As(t,r,a)}}}function Ms(n,e){return(t,r,i)=>{if(!i)return!1;let s=t.selection,o;if(s instanceof V)o=s;else{let c=Bd(i,n,e);if(c==null)return!1;o=new V(t.doc.resolve(c))}let l=Nd(o.$headCell,n,e);return l?As(t,r,new V(o.$anchorCell,l)):!1}}function T0(n,e){let t=n.state.doc,r=nr(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new V(r))),!0):!1}function D0(n,e,t){if(!Ge(n.state))return!1;let r=k0(t),i=n.state.selection;if(i instanceof V){r||(r={width:1,height:1,rows:[w.from(vl(he(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=M0(r,l.right-l.left,l.bottom-l.top),Ed(n.state,n.dispatch,o,l,r),!0}else if(r){let s=Ul(n.state),o=s.start(-1);return Ed(n.state,n.dispatch,o,z.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function O0(n,e){var t;if(e.ctrlKey||e.metaKey)return;let r=Td(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=nr(n.state.selection.$anchor))!=null&&((t=Ol(n,e))==null?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(c,a){let h=Ol(n,a),d=Ft.getState(n.state)==null;if(!h||!Vl(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(Ft,c.pos),n.dispatch(u)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),Ft.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(Ft,-1))}function l(c){let a=c,h=Ft.getState(n.state),d;if(h!=null)d=n.state.doc.resolve(h);else if(Td(n,a.target)!=r&&(d=Ol(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 Bd(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 Td(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Ol(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?nr(n.state.doc.resolve(t.pos)):null}var N0=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")),_l(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,_l(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function _l(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 R0(-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)=>{v0(s,o,n,e,r)},mouseleave:s=>{_0(s)},mousedown:(s,o)=>{U0(s,o,e)}},decorations:s=>{let o=Ve.getState(s);if(o&&o.activeHandle>-1)return F0(s,o.activeHandle)},nodeViews:{}}});return i}var R0=class Es{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 Es(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new Es(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Rl(e.doc.resolve(i))||(i=-1),new Es(i,t.dragging)}return t}};function v0(n,e,t,r,i){let s=Ve.getState(n.state);if(s&&!s.dragging){let o=B0(e.target),l=-1;if(o){let{left:c,right:a}=o.getBoundingClientRect();e.clientX-c<=t?l=Dd(n,e,"left",t):a-e.clientX<=t&&(l=Dd(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}Pd(n,l)}}}function _0(n){let e=Ve.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Pd(n,-1)}function U0(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=V0(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&&(P0(n,d.activeHandle,Od(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=Od(d.dragging,h,t);L0(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 s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,c=t;if(r)for(let a=0;aYs,AbstractConnector:()=>dc,AbstractStruct:()=>xr,AbstractType:()=>W,Array:()=>vn,ContentAny:()=>Yt,ContentBinary:()=>Un,ContentDeleted:()=>Sr,ContentDoc:()=>Vn,ContentEmbed:()=>At,ContentFormat:()=>P,ContentJSON:()=>Mi,ContentString:()=>Re,ContentType:()=>Ae,Doc:()=>Je,GC:()=>fe,ID:()=>Ct,Item:()=>O,Map:()=>_n,PermanentUserData:()=>uc,RelativePosition:()=>ot,Skip:()=>ie,Snapshot:()=>Kt,Text:()=>ct,Transaction:()=>Xs,UndoManager:()=>In,UpdateDecoderV1:()=>Me,UpdateDecoderV2:()=>be,UpdateEncoderV1:()=>st,UpdateEncoderV2:()=>Ie,XmlElement:()=>Z,XmlFragment:()=>at,XmlHook:()=>Ci,XmlText:()=>xe,YArrayEvent:()=>eo,YEvent:()=>Rn,YMapEvent:()=>to,YTextEvent:()=>no,YXmlEvent:()=>ro,applyUpdate:()=>Mc,applyUpdateV2:()=>Bn,cleanupYTextFormatting:()=>vu,compareIDs:()=>En,compareRelativePositions:()=>so,convertUpdateFormatV1ToV2:()=>g1,convertUpdateFormatV2ToV1:()=>gu,createAbsolutePositionFromRelativePosition:()=>Oc,createDeleteSet:()=>kr,createDeleteSetFromStructStore:()=>Sc,createDocFromSnapshot:()=>t1,createID:()=>M,createRelativePositionFromJSON:()=>Ln,createRelativePositionFromTypeIndex:()=>Ai,createSnapshot:()=>Ei,decodeRelativePosition:()=>Gw,decodeSnapshot:()=>Zw,decodeSnapshotV2:()=>ru,decodeStateVector:()=>Ec,decodeUpdate:()=>a1,decodeUpdateV2:()=>hu,diffUpdate:()=>u1,diffUpdateV2:()=>Nc,emptySnapshot:()=>e1,encodeRelativePosition:()=>Kw,encodeSnapshot:()=>Qw,encodeSnapshotV2:()=>nu,encodeStateAsUpdate:()=>Ac,encodeStateAsUpdateV2:()=>Zf,encodeStateVector:()=>Dc,encodeStateVectorFromUpdate:()=>h1,encodeStateVectorFromUpdateV2:()=>fu,equalDeleteSets:()=>Xf,equalSnapshots:()=>Xw,findIndexSS:()=>ze,findRootTypeKey:()=>Pn,getItem:()=>Tn,getState:()=>B,getTypeChildren:()=>x1,isDeleted:()=>Et,isParentOf:()=>Nn,iterateDeletedStructs:()=>rt,logType:()=>Jw,logUpdate:()=>c1,logUpdateV2:()=>au,mergeDeleteSets:()=>Dn,mergeUpdates:()=>du,mergeUpdatesV2:()=>bi,obfuscateUpdate:()=>p1,obfuscateUpdateV2:()=>m1,parseUpdateMeta:()=>d1,parseUpdateMetaV2:()=>uu,readUpdate:()=>zw,readUpdateV2:()=>Cc,relativePositionToJSON:()=>$w,snapshot:()=>Ti,snapshotContainsUpdate:()=>r1,transact:()=>R,tryGc:()=>o1,typeListToArraySnapshot:()=>ao,typeMapGetAllSnapshot:()=>Du,typeMapGetSnapshot:()=>C1});var _=()=>new Map,Ts=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},Ld=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},zd=(n,e)=>{for(let[t,r]of n)if(e(r,t))return!0;return!1};var Ce=()=>new Set;var Ds=n=>n[n.length-1];var Fd=(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 He((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}},ir=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 He((this._observers.get(e)||_()).values()).forEach(r=>r(...t))}destroy(){this._observers=_()}};var de=Math.floor;var sr=Math.abs;var De=(n,e)=>nn>e?n:e,fS=Number.isNaN,Jd=Math.pow;var Ns=n=>n!==0?n<0:1/n<0;var Pl=Number.MAX_SAFE_INTEGER,uS=Number.MIN_SAFE_INTEGER,pS=1<<31;var $d=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&de(n)===n),mS=Number.isNaN,gS=Number.parseInt;var Ll=String.fromCharCode,yS=String.fromCodePoint,wS=Ll(65535),H0=n=>n.toLowerCase(),J0=/^\s*/g,$0=n=>n.replace(J0,""),W0=/([A-Z])/g,zl=(n,e)=>$0(n.replace(W0,t=>`${e}${H0(t)}`));var j0=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;ilr.encode(n),jd=lr?K0:j0;var or=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});or&&or.decode(new Uint8Array).length===1&&(or=null);var Kd=(n,e)=>Hd(e,()=>n).join("");var kn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},q=()=>new kn;var Rs=n=>{let e=n.cpos;for(let t=0;t{let e=new Uint8Array(Rs(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 dr=Q;var x=(n,e)=>{for(;e>127;)Q(n,128|127&e),e=de(e/128);Q(n,127&e)},ii=(n,e)=>{let t=Ns(e);for(t&&(e=-e),Q(n,(e>63?128:0)|(t?64:0)|63&e),e=de(e/64);e>0;)Q(n,(e>127?128:0)|127&e),e=de(e/128)},Fl=new Uint8Array(3e4),G0=Fl.length/3,X0=(n,e)=>{if(e.length{let t=unescape(encodeURIComponent(e)),r=t.length;x(n,r);for(let i=0;ifr(n,I(e)),fr=(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),fr(n,e)},ql=(n,e)=>{Y0(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},Z0=(n,e)=>ql(n,4).setFloat32(0,e,!1),ew=(n,e)=>ql(n,8).setFloat64(0,e,!1),tw=(n,e)=>ql(n,8).setBigInt64(0,e,!1);var Gd=new DataView(new ArrayBuffer(4)),nw=n=>(Gd.setFloat32(0,n),Gd.getFloat32(0)===n),ar=(n,e)=>{switch(typeof e){case"string":Q(n,119),Qe(n,e);break;case"number":$d(e)&&sr(e)<=2147483647?(Q(n,125),ii(n,e)):nw(e)?(Q(n,124),Z0(n,e)):(Q(n,123),ew(n,e));break;case"bigint":Q(n,122),tw(n,e);break;case"object":if(e===null)Q(n,126);else if(ti(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 Xd=n=>{n.count>0&&(ii(n.encoder,n.count===1?n.s:-n.s),n.count>1&&x(n.encoder,n.count-2))},Cn=class{constructor(){this.encoder=new kn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Xd(this),this.count=1,this.s=e)}toUint8Array(){return Xd(this),I(this.encoder)}};var Qd=n=>{if(n.count>0){let e=n.diff*2+(n.count===1?0:1);ii(n.encoder,e),n.count>1&&x(n.encoder,n.count-2)}},hr=class{constructor(){this.encoder=new kn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Qd(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Qd(this),I(this.encoder)}},Is=class{constructor(){this.sarr=[],this.s="",this.lensE=new Cn}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 kn;return this.sarr.push(this.s),this.s="",Qe(e,this.sarr.join("")),fr(e,this.lensE.toUint8Array()),I(e)}};var Ze=n=>new Error(n),Oe=()=>{throw Ze("Method unimplemented")},j=()=>{throw Ze("Unexpected case")};var ef=Ze("Unexpected end of array"),tf=Ze("Integer out of Range"),ur=class{constructor(e){this.arr=e,this.pos=0}},H=n=>new ur(n),Hl=n=>n.pos!==n.arr.length;var rw=(n,e)=>{let t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},K=n=>rw(n,k(n));var Mn=n=>n.arr[n.pos++];var k=n=>{let e=0,t=1,r=n.arr.length;for(;n.posPl)throw tf}throw ef},oi=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.posPl)throw tf}throw ef};var iw=n=>{let e=k(n);if(e===0)return"";{let t=String.fromCodePoint(Mn(n));if(--e<100)for(;e--;)t+=String.fromCodePoint(Mn(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))}},sw=n=>or.decode(K(n)),Le=or?sw:iw;var Jl=(n,e)=>{let t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},ow=n=>Jl(n,4).getFloat32(0,!1),lw=n=>Jl(n,8).getFloat64(0,!1),cw=n=>Jl(n,8).getBigInt64(0,!1);var aw=[n=>{},n=>null,oi,ow,lw,cw,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;raw[127-Mn(n)](n),si=class extends ur{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 An=class extends ur{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=oi(this);let e=Ns(this.s);this.count=1,e&&(this.s=-this.s,this.count=k(this)+2)}return this.count--,this.s}};var mr=class extends ur{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=oi(this),t=e&1;this.diff=de(e/2),this.count=1,t&&(this.count=k(this)+2)}return this.s+=this.diff,this.count--,this.s}},Us=class{constructor(e){this.decoder=new An(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 SS=crypto.subtle,nf=crypto.getRandomValues.bind(crypto);var hw=Math.random,$l=()=>nf(new Uint32Array(1))[0];var rf=n=>n[de(hw()*n.length)],dw="10000000-1000-4000-8000"+-1e11,sf=()=>dw.replace(/[018]/g,n=>(n^$l()&15>>n/4).toString(16));var Ne=Date.now;var Wl=n=>new Promise(n);var MS=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)}},lf=new Kl,Yl=!0;try{typeof localStorage<"u"&&localStorage&&(lf=localStorage,Yl=!1)}catch{}var Bs=lf,cf=n=>Yl||addEventListener("storage",n),af=n=>Yl||removeEventListener("storage",n);var ff=Object.assign,Ps=Object.keys,uf=(n,e)=>{for(let t in n)e(n[t],t)},pf=(n,e)=>{let t=[];for(let r in n)t.push(e(n[r],r));return t},Gl=n=>Ps(n).length,df=n=>Ps(n).length;var mf=n=>{for(let e in n)return!1;return!0},pw=(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||df(n)===df(e)&&pw(n,(t,r)=>(t!==void 0||Xl(e,r))&&e[r]===t),mw=Object.freeze,Zl=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&Zl(n[e])}return mw(n)};var ci=(n,e,t=0)=>{try{for(;tn,gw=(n,e)=>n===e;var gr=(n,e)=>{if(n==null||e==null)return gw(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]",yr=typeof window<"u"&&typeof document<"u"&&!St,AS=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,et,yw=[],ww=()=>{if(et===void 0)if(St){et=_();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=_();return et},nc=n=>ww().has(n);var ai=n=>St?jl(process.env[n.toUpperCase().replaceAll("-","_")]):jl(Bs.getItem(n));var yf=n=>nc("--"+n)||ai(n)!==null,ES=yf("production"),bw=St&&gf(process.env.FORCE_COLOR,["true","1","2"]),wf=bw||!nc("--no-colors")&&!yf("no-color")&&(!St||process.stdout.isTTY)&&(!St||nc("--color")||ai("COLORTERM")!==null||(ai("TERM")||"").includes("color"));var bf=n=>new Uint8Array(n),xw=(n,e,t)=>new Uint8Array(n,e,t),xf=n=>new Uint8Array(n),Sw=n=>{let e="";for(let t=0;tBuffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),Cw=n=>{let e=atob(n),t=bf(e.length);for(let r=0;r{let e=Buffer.from(n,"base64");return xw(e.buffer,e.byteOffset,e.byteLength)},Sf=yr?Sw:kw,kf=yr?Cw:Mw;var Cf=n=>{let e=bf(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 kt=typeof document<"u"?document:{};var TS=typeof DOMParser<"u"?new DOMParser:null;var Af=n=>Ld(n,(e,t)=>`${t}:${e};`).join("");var DS=kt.ELEMENT_NODE,OS=kt.TEXT_NODE,NS=kt.CDATA_SECTION_NODE,IS=kt.COMMENT_NODE,RS=kt.DOCUMENT_NODE,vS=kt.DOCUMENT_TYPE_NODE,_S=kt.DOCUMENT_FRAGMENT_NODE;var zs=n=>class{constructor(t){this._=t}destroy(){n(this._)}},Ew=zs(clearTimeout),di=(n,e)=>new Ew(setTimeout(e,n)),VS=zs(clearInterval);var BS=zs(n=>typeof requestAnimationFrame<"u"&&cancelAnimationFrame(n));var PS=zs(n=>typeof cancelIdleCallback<"u"&&cancelIdleCallback(n));var nt=Symbol;var fi=nt(),ui=nt(),ic=nt(),sc=nt(),oc=nt(),pi=nt(),lc=nt(),wr=nt(),cc=nt(),Df=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(...Of(n)),Nf.forEach(e=>e.print(n))},ac=(...n)=>{console.warn(...Of(n)),n.unshift(wr),Nf.forEach(e=>e.print(n))};var Nf=Ce();var If=n=>({[Symbol.iterator](){return this},next:n}),Rf=(n,e)=>If(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),qs=(n,e)=>If(()=>{let{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});var dc=class extends rr{constructor(e,t){super(),this.doc=e,this.awareness=t}},gi=class{constructor(e,t){this.clock=e,this.len=t}},Wt=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=de((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&&Uw(t,e.clock)!==null},xc=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 Wt;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 gi(t,r))},kr=()=>new Wt,Sc=n=>{let e=kr();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),He(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 Wt,t=k(n.restDecoder);for(let r=0;r0){let o=$(e.clients,i,()=>[]);for(let l=0;l{let r=new Wt,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},Xf=(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=Qf(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Gs,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=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(He(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,vn)}getText(e=""){return this.get(e,ct)}getMap(e=""){return this.get(e,_n)}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,He(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()}},On=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return k(this.restDecoder)}readDsLen(){return k(this.restDecoder)}},Me=class extends On{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 Mn(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 pr(this.restDecoder)}readBuf(){return Cf(K(this.restDecoder))}readJSON(){return JSON.parse(Le(this.restDecoder))}readKey(){return Le(this.restDecoder)}},Ks=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 Ks{constructor(e){super(e),this.keys=[],k(e),this.keyClockDecoder=new mr(K(e)),this.clientDecoder=new An(K(e)),this.leftClockDecoder=new mr(K(e)),this.rightClockDecoder=new mr(K(e)),this.infoDecoder=new si(K(e),Mn),this.stringDecoder=new Us(K(e)),this.parentInfoDecoder=new si(K(e),Mn),this.typeRefDecoder=new An(K(e)),this.lenDecoder=new An(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 pr(this.restDecoder)}readBuf(){return K(this.restDecoder)}readJSON(){return pr(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)}),Di(e).forEach((i,s)=>{t.has(s)||r.set(s,0)}),x(n.restEncoder,r.size),He(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{Vw(n,e.clients.get(i),i,s)})},Bw=(n,e)=>{let t=_(),r=k(n.restDecoder);for(let i=0;i{let r=[],i=He(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 Gs,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 kc(u,l,new Map),x(u.restEncoder,0),{missing:c,update:u.toUint8Array()}}return null},Lw=(n,e)=>kc(n,e.doc.store,e.beforeState),Cc=(n,e,t,r=new be(n))=>R(e,i=>{i.local=!1;let s=!1,o=i.doc,l=o.store,c=Bw(r,o),a=Pw(i,l,c),h=l.pendingStructs;if(h){for(let[f,u]of h.missing)if(uu)&&h.missing.set(f,u)}h.update=bi([h.update,a.update])}}else l.pendingStructs=a;let d=Uf(r,i,l);if(l.pendingDs){let f=new be(H(l.pendingDs));k(f.restDecoder);let u=Uf(f,i,l);d&&u?l.pendingDs=bi([d,u]):l.pendingDs=d||u}else l.pendingDs=d;if(s){let f=l.pendingStructs.update;l.pendingStructs=null,Bn(i.doc,f)}},t,!1),zw=(n,e,t)=>Cc(n,e,t,new Me(n)),Bn=(n,e,t,r=be)=>{let i=H(e);Cc(i,n,t,new r(i))},Mc=(n,e,t)=>Bn(n,e,t,Me),Fw=(n,e,t=new Map)=>{kc(n,e.store,t),it(n,Sc(e.store))},Zf=(n,e=new Uint8Array([0]),t=new Ie)=>{let r=Ec(e);Fw(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===st)return du(i.map((s,o)=>o===0?s:gu(s)));if(t.constructor===Ie)return bi(i)}return i[0]},Ac=(n,e)=>Zf(n,e,new st),eu=n=>{let e=new Map,t=k(n.restDecoder);for(let r=0;reu(new On(H(n))),Tc=(n,e)=>(x(n.restEncoder,e.size),He(e.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{x(n.restEncoder,t),x(n.restEncoder,r)}),n),qw=(n,e)=>Tc(n,Di(e.store)),Hw=(n,e=new br)=>(n instanceof Map?Tc(e,n):qw(e,n),e.toUint8Array()),Dc=n=>Hw(n,new jt),fc=class{constructor(){this.l=[]}},Vf=()=>new fc,Bf=(n,e)=>n.l.push(e),Pf=(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.")},tu=(n,e,t)=>ci(n.l,[e,t]),Ct=class{constructor(e,t){this.client=e,this.clock=t}},En=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,M=(n,e)=>new Ct(n,e),Lf=(n,e)=>{x(n,e.client),x(n,e.clock)},zf=n=>M(k(n),k(n)),Pn=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw j()},Nn=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1},Jw=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=(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,Dn([this.dss.get(o)||kr(),Mt(new On(H(f)))]))})})}),this.dss.set(o,Dn(l.map(h=>Mt(new On(H(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 _n,o.set("ids",new vn),o.set("ds",new vn),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 jt,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 jt;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(Et(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}},$w=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},Ln=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),Ys=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},Ww=(n,e,t=0)=>new Ys(n,e,t),Hs=(n,e,t)=>{let r=null,i=null;return n._item===null?i=Pn(n):r=M(n._item.id.client,n._item.id.clock),new ot(r,i,e,t)},Ai=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return Hs(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Hs(n,M(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return Hs(n,r.lastId,t);r=r.right}return Hs(n,null,t)},jw=(n,e)=>{let{type:t,tname:r,item:i,assoc:s}=e;if(i!==null)x(n,0),Lf(n,i);else if(r!==null)dr(n,1),Qe(n,r);else if(t!==null)dr(n,2),Lf(n,t);else throw j();return ii(n,s),n},Kw=n=>{let e=q();return jw(e,n),I(e)},Yw=n=>{let e=null,t=null,r=null;switch(k(n)){case 0:r=zf(n);break;case 1:t=Le(n);break;case 2:e=zf(n)}let i=Hl(n)?oi(n):0;return new ot(e,t,r,i)},Gw=n=>Yw(H(n)),Oc=(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?wc(r,i):{item:Tn(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?wc(r,s):{item:Tn(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 Ww(c,a,n.assoc)},so=(n,e)=>n===e||n!==null&&e!==null&&n.tname===e.tname&&En(n.item,e.item)&&En(n.type,e.type)&&n.assoc===e.assoc,Kt=class{constructor(e,t){this.ds=e,this.sv=t}},Xw=(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),Tc(e,n.sv),e.toUint8Array()),Qw=n=>nu(n,new jt),ru=(n,e=new Ks(H(n)))=>new Kt(Mt(e),eu(e)),Zw=n=>ru(n,new On(H(n))),Ei=(n,e)=>new Kt(n,e),e1=Ei(kr(),new Map),Ti=n=>Ei(Sc(n.store),Di(n.store)),Ht=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!Et(e.ds,n.id),pc=(n,e)=>{let t=$(n.meta,pc,Ce),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i{}),t.add(e))},t1=(n,e,t=new Je)=>{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(H(e)),i=new lt(r,!1);for(let o=i.curr;o!==null;o=i.next())if((n.sv.get(o.id.client)||0)n1(n,e,Me),Gs=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Di=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},iu=(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=de(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)]},Tn=i1,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)]},Ff=(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!==fe&&r.splice(i+1,0,io(n,s,t.clock-s.id.clock+1)),s},s1=(n,e,t)=>{let r=n.clients.get(e.id.client);r[ze(r,e.id.clock)]=t},su=(n,e,t,r,i)=>{if(r===0)return;let s=t+r,o=mc(n,e,t),l;do l=e[o++],se.deleteSet.clients.size===0&&!zd(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(xc(e.deleteSet),Lw(n,e),it(n,e.deleteSet),!0),Hf=(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)},Ws=(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},ou=(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+Ws(i,c)}})},o1=(n,e,t)=>{ou(n,e,t),lu(n,e)},cu=(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),tu(a._dEH,c,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),ci(l,[]),t._needFormattingCleanup&&T1(t)}finally{r.gc&&ou(s,i,r.gcFilter),lu(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+Ws(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&&Ws(u,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(Fs(wr,fi,"[yjs] ",ui,pi,"Changed the client-id because another client seems to be using it."),r.clientID=Qf()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let h=new st;qf(h,t)&&r.emit("update",[h.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){let h=new Ie;qf(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])):cu(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 Xs(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&&cu(i,0)}}return o},gc=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=>Nn(i,r))&&Uc(r,!1)})},$f=(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}=wc(c,u.id);m>0&&(p=we(l,M(p.id.client,p.id.clock+m))),u=p}!u.deleted&&s.some(p=>Nn(p,u))&&d.push(u)}}),rt(l,a.deletions,u=>{u instanceof O&&s.some(p=>Nn(p,u))&&!Et(a.insertions,u.id)&&h.add(u)}),h.forEach(u=>{f=Uu(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},In=class extends rr{constructor(e,{captureTimeout:t=500,captureTransaction:r=c=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=ti(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 Wt;c.afterState.forEach((g,y)=>{let E=c.beforeState.get(y)||0,N=g-E;N>0&&yi(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=Dn([g.deletions,c.deleteSet]),g.insertions=Dn([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=>Nn(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=ti(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=>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=$f(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=$f(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*l1(n){let e=k(n.restDecoder);for(let t=0;tau(n,Me),au=(n,e=be)=>{let t=[],r=new e(H(n)),i=new lt(r,!1);for(let o=i.curr;o!==null;o=i.next())t.push(o);Fs("Structs: ",t);let s=Mt(r);Fs("DeleteSet: ",s)},a1=n=>hu(n,Me),hu=(n,e=be)=>{let t=[],r=new e(H(n)),i=new lt(r,!1);for(let s=i.curr;s!==null;s=i.next())t.push(s);return{structs:t,ds:Mt(r)}},wi=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},du=n=>bi(n,Me,st),fu=(n,e=br,t=be)=>{let r=new e,i=new lt(new t(H(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=q();return x(h,o),Zd(h,r.restEncoder),r.restEncoder=h,r.toUint8Array()}else return x(r.restEncoder,0),r.toUint8Array()},h1=n=>fu(n,jt,Me),uu=(n,e=be)=>{let t=new Map,r=new Map,i=new lt(new e(H(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}},d1=n=>uu(n,Me),f1=(n,e)=>{if(n.constructor===fe){let{client:t,clock:r}=n.id;return new fe(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))}},bi=(n,e=be,t=Ie)=>{if(n.length===1)return n[0];let r=n.map(h=>new e(H(h))),i=r.map(h=>new lt(h,!0)),s=null,o=new t,l=new wi(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)Jt(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=f1(f,p)),s.struct.mergeWith(f)||(Jt(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())Jt(l,s.struct,s.offset),s={struct:f,offset:0}}s!==null&&(Jt(l,s.struct,s.offset),s=null),Ic(l);let c=r.map(h=>Mt(h)),a=Dn(c);return it(o,a),o.toUint8Array()},Nc=(n,e,t=be,r=Ie)=>{let i=Ec(e),s=new r,o=new wi(s),l=new t(H(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(Jt(o,h,Be(f-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)Jt(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()}Ic(o);let a=Mt(l);return it(s,a),s.toUint8Array()},u1=(n,e)=>Nc(n,e,Me,st),pu=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:I(n.encoder.restEncoder)}),n.encoder.restEncoder=q(),n.written=0)},Jt=(n,e,t)=>{n.written>0&&n.currClient!==e.id.client&&pu(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=>{pu(n);let e=n.encoder.restEncoder;x(e,n.clientStructs.length);for(let t=0;t{let i=new t(H(n)),s=new lt(i,!1),o=new r,l=new wi(o);for(let a=s.curr;a!==null;a=s.next())Jt(l,e(a),0);Ic(l);let c=Mt(i);return it(o,c),o.toUint8Array()},mu=({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 fe:case ie:return c;case O:{let a=c,h=a.content;switch(h.constructor){case Sr:break;case Ae:{if(t){let d=h.type;d instanceof Z&&(d.nodeName=$(s,d.nodeName,()=>"node-"+r)),d instanceof Ci&&(d.hookName=$(s,d.hookName,()=>"hook-"+r))}break}case Yt:{let d=h;d.arr=d.arr.map(()=>r);break}case Un:{let d=h;d.content=new Uint8Array([r]);break}case Vn:{let d=h;e&&(d.opts={},d.doc.guid=r+"");break}case At:{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 Mi:{let d=h;d.arr=d.arr.map(()=>r);break}case Re:{let d=h;d.str=Kd(r%10+"",d.str.length);break}default:j()}return a.parentSub&&(a.parentSub=$(i,a.parentSub,()=>r+"")),r++,c}default:j()}}},p1=(n,e)=>oo(n,mu(e),Me,st),m1=(n,e)=>oo(n,mu(e),be,Ie),g1=n=>oo(n,ec,Me,Ie),gu=n=>oo(n,ec,be,st),Wf="You must not compute changes after the event-handler fired.",Rn=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=y1(this.currentTarget,this.target))}deletes(e){return Et(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ze(Wf);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=Ds(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Ds(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(s))o="delete",l=Ds(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(Wf);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}},y1=(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=()=>{ac("Invalid access: Add Yjs type to a document before reading data.")},yu=80,Rc=0,yc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Rc++}},w1=n=>{n.timestamp=Rc++},wu=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Rc++},b1=(n,e,t)=>{if(n.length>=yu){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)=>sr(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&&sr(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))}},x1=n=>{n.doc??se();let e=n._start,t=[];for(;e;)t.push(e),e=e.right;return t},co=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;$(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;tu(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=Vf(),this._dEH=Vf(),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){Bf(this._eH,e)}observeDeep(e){Bf(this._dEH,e)}unobserve(e){Pf(this._eH,e)}unobserveDeep(e){Pf(this._dEH,e)}toJSON(){}},bu=(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},xu=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&&Ht(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 Si(n,(r,i)=>{t.push(e(r,i,n))}),t},S1=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}}}},ku=(n,e)=>{n.doc??se();let t=lo(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 Yt(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 Un(new Uint8Array(d))),i.integrate(n,0);break;case Je:i=new O(M(o,B(l,o)),i,i&&i.lastId,c,c&&c.id,e,null,new Vn(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()},Cu=()=>Ze("Length exceeded!"),Mu=(n,e,t,r)=>{if(t>e._length)throw Cu();if(t===0)return e._searchMarker&&xi(e._searchMarker,t,r.length),Qs(n,e,null,r);let i=t,s=lo(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 Qs(n,e,i,t)},Au=(n,e,t,r)=>{if(r===0)return;let i=t,s=r,o=lo(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 Cu();e._searchMarker&&xi(e._searchMarker,i,-s+r)},Zs=(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,s=n.doc,o=s.clientID,l;if(r==null)l=new Yt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:l=new Yt([r]);break;case Uint8Array:l=new Un(r);break;case Je:l=new Vn(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)},_c=(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},Eu=n=>{let e={};return n.doc??se(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},Tu=(n,e)=>{n.doc??se();let t=n._map.get(e);return t!==void 0&&!t.deleted},C1=(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&&Ht(r,t)?r.content.getContent()[r.length-1]:void 0},Du=(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&&Ht(s,e)&&(t[i]=s.content.getContent()[s.length-1])}),t},Js=n=>(n.doc??se(),Rf(n._map.entries(),e=>!e[1].deleted)),eo=class extends Rn{},vn=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),co(this,e,new eo(this,e))}insert(e,t){this.doc!==null?R(this.doc,r=>{Mu(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?R(this.doc,t=>{k1(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?R(this.doc,r=>{Au(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return ku(this,e)}toArray(){return xu(this)}slice(e=0,t=this.length){return bu(this,e,t)}toJSON(){return this.map(e=>e instanceof W?e.toJSON():e)}map(e){return Su(this,e)}forEach(e){Si(this,e)}[Symbol.iterator](){return S1(this)}_write(e){e.writeTypeRef(J1)}},M1=n=>new vn,to=class extends Rn{constructor(e,t,r){super(e,t),this.keysChanged=r}},_n=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){co(this,e,new to(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[...Js(this)].length}keys(){return qs(Js(this),e=>e[0])}values(){return qs(Js(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return qs(Js(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=>{Zs(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){Zs(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef($1)}},A1=n=>new _n,$t=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Ql(n,e),ki=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||Cr(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}},jf=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case P:e.right.deleted||Cr(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t{let i=new Map,s=r?lo(e,t):null;if(s){let o=new ki(s.p.left,s.p,s.index,i);return jf(n,o,t-s.index)}else{let o=new ki(null,e._start,0,i);return jf(n,o,t)}},Ou=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===P&&$t(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()})},Cr=(n,e)=>{let{key:t,value:r}=e;r===null?n.delete(t):n.set(t,r)},Nu=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===P&&$t(e[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},Iu=(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(!$t(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},hc=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,u)=>{i[u]===void 0&&(i[u]=null)});let s=n.doc,o=s.clientID;Nu(t,i);let l=Iu(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&&xi(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(),Ou(n,e,t,l)},Kf=(n,e,t,r,i)=>{let s=n.doc,o=s.clientID;Nu(t,i);let l=Iu(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($t(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()}Ou(n,e,t,l)},Ru=(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&&Cr(i,a);break}}}e=e.right}return l},E1=(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}},vu=n=>{let e=0;return R(n.doc,t=>{let r=n._start,i=n._start,s=_(),o=Ts(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case P:Cr(o,i.content);break;default:e+=Ru(t,r,i,s,o),s=Ts(o),r=i;break}i=i.right}}),e},T1=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&&su(n,t.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===P&&o.constructor!==fe&&e.add(o.parent)})}R(t,r=>{rt(n,n.deleteSet,i=>{if(i instanceof fe||!i.parent._hasFormatting||e.has(i.parent))return;let s=i.parent;i.content.constructor===P?e.add(s):E1(r,i)});for(let i of e)vu(i)})},Yf=(n,e,t)=>{let r=t,i=Ts(e.currentAttributes),s=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,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},mf(c)||(u.attributes=ff({},c))),h=0;break}u&&t.push(u),l=null}};for(;o!==null;){switch(o.content.constructor){case Ae:case At: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;$t(m,p)?p!==null&&o.delete(r):(l==="retain"&&f(),$t(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;$t(m,p)||(l==="retain"&&f(),c[u]=m)}else if(!o.deleted){s.set(u,p);let m=c[u];m!==void 0&&($t(m,p)?m!==null&&o.delete(r):(l==="retain"&&f(),p===null?delete c[u]:c[u]=p))}o.deleted||(l==="insert"&&f(),Cr(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 no(this,e,t);co(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 ki(null,this._start,0,new Map);for(let s=0;s0)&&hc(r,this,i,l,o.attributes||{})}else o.retain!==void 0?Kf(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&Yf(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(Ht(c,e)||t!==void 0&&Ht(c,t))switch(c.content.constructor){case Re:{let d=s.get("ychange");e!==void 0&&!Ht(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&&!Ht(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 At:{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:Ht(c,e)&&(a(),Cr(s,c.content));break}c=c.right}a()};return e||t?R(o,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,s=>{let o=$s(s,this,e,!r);r||(r={},o.currentAttributes.forEach((l,c)=>{r[c]=l})),hc(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=$s(s,this,e,!r);hc(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=>{Yf(i,$s(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=$s(s,this,e,!1);o.right!==null&&Kf(s,this,o,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?R(this.doc,t=>{Zs(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 Eu(this)}_write(e){e.writeTypeRef(W1)}},D1=n=>new ct,mi=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 mi(this,e)}querySelector(e){e=e.toUpperCase();let r=new mi(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),He(new mi(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){co(this,e,new ro(this,t,e))}toString(){return Su(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),Si(this,s=>{i.insertBefore(s.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?R(this.doc,r=>{Mu(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;Qs(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=>{Au(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return xu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return ku(this,e)}slice(e=0,t=this.length){return bu(this,e,t)}forEach(e){Si(this,e)}_write(e){e.writeTypeRef(K1)}},O1=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 uf(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=>{Zs(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?Du(this,e):Eu(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 Si(this,o=>{i.appendChild(o.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(j1),e.writeKey(this.nodeName)}},N1=n=>new Z(n.readKey()),ro=class extends Rn{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)})}},Ci=class n extends _n{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(Y1),e.writeKey(this.hookName)}},I1=n=>new Ci(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(G1)}},R1=n=>new xe,xr=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()}},v1=0,fe=class extends xr{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),iu(e.doc.store,this)}write(e,t){e.writeInfo(v1),e.writeLen(this.length-t)}getMissing(e,t){return null}},Un=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}},_1=n=>new Un(n.readBuf()),Sr=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){yi(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}},U1=n=>new Sr(n.readLen()),_u=(n,e)=>new Je({guid:n,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),Vn=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(_u(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 Vn(_u(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}},B1=n=>new At(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}},P1=n=>new P(n.readKey(),n.readJSON()),Mi=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}},q1=n=>new Re(n.readString()),H1=[M1,A1,D1,N1,O1,I1,R1],J1=0,$1=1,W1=2,j1=3,K1=4,Y1=5,G1=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}},X1=n=>new Ae(H1[n.readTypeRef()](n)),wc=(n,e)=>{let t=e,r=0,i;do r>0&&(t=M(t.client,t.clock+r)),i=Tn(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},io=(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},Gf=(n,e)=>qd(n,t=>Et(t.deletions,e)),Uu=(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)||Uu(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||Et(r,d.right.id)||Gf(s.undoStack,d.right.id)||Gf(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,Uc(g,!0),g.integrate(n,0),g},O=class n extends xr{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===Ct&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Ff(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===fe||this.right&&this.right.constructor===fe)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=Tn(t,this.parent);r.constructor===fe?this.parent=null:this.parent=r.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Ff(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),En(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(),yi(e.deleteSet,this.id.client,this.id.clock,this.length),Hf(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw j();this.content.gc(e),t?s1(e,this,new fe(this.id,this.length)):this.content=new Sr(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=Pn(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();s!==null&&e.writeString(s)}this.content.write(e,t)}},Vu=(n,e)=>Q1[e&31](n),Q1=[()=>{j()},U1,L1,_1,q1,B1,P1,X1,F1,V1,()=>{j()}],Z1=10,ie=class extends xr{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(Z1),x(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Bu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Pu="__ $YJS$ __";Bu[Pu]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Bu[Pu]=!0;var Lu=new Map,Vc=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:kf(t.newValue||"")}),cf(this._onChange)}postMessage(e){Bs.setItem(this.room,Sf(xf(e)))}close(){af(this._onChange)}},eb=typeof BroadcastChannel>"u"?Vc:BroadcastChannel,Bc=n=>$(Lu,n,()=>{let e=Ce(),t=new eb(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),zu=(n,e)=>(Bc(n).subs.add(e),e),Fu=(n,e)=>{let t=Bc(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),Lu.delete(n)),r},zn=(n,e,t=null)=>{let r=Bc(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))};var qu=0,ho=1,Hu=2,fo=(n,e)=>{x(n,qu);let t=Dc(e);U(n,t)},Pc=(n,e,t)=>{x(n,ho),U(n,Ac(e,t))},nb=(n,e,t)=>Pc(e,t,K(n)),Ju=(n,e,t)=>{try{Mc(e,K(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},$u=(n,e)=>{x(n,Hu),U(n,e)},rb=Ju,Wu=(n,e,t,r)=>{let i=k(n);switch(i){case qu:nb(n,e,t);break;case ho:Ju(n,t,r);break;case Hu:rb(n,t,r);break;default:throw new Error("Unknown message type")}return i};var sb=0;var ju=(n,e,t)=>{switch(k(n)){case sb:t(e,Le(n))}};var Lc=3e4,uo=class extends ir{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,s)=>{s!==this.clientID&&Lc<=t-i.lastUpdated&&this.states.has(s)&&r.push(s)}),r.length>0&&po(this,r,"timeout")},de(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,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),gr(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}},po=(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]))},Ar=(n,e,t=n.states)=>{let r=e.length,i=q();x(i,r);for(let s=0;s{let r=H(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 Yu=n=>pf(n,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&");var Fn=0,Xu=3,Er=1,ab=2,Oi=[];Oi[Fn]=(n,e,t,r,i)=>{x(n,Fn);let s=Wu(e,n,t.doc,t);r&&s===ho&&!t.synced&&(t.synced=!0)};Oi[Xu]=(n,e,t,r,i)=>{x(n,Er),U(n,Ar(t.awareness,Array.from(t.awareness.getStates().keys())))};Oi[Er]=(n,e,t,r,i)=>{Ku(t.awareness,K(e),t)};Oi[ab]=(n,e,t,r,i)=>{ju(e,t.doc,(s,o)=>hb(t,o))};var Gu=3e4,hb=(n,e)=>console.warn(`Permission denied to access ${n.url}. +${e}`),Qu=(n,e,t)=>{let r=H(e),i=q(),s=k(r),o=n.messageHandlers[s];return o?o(i,r,n,t,s):console.error("Unable to compute message"),i},Zu=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=Qu(n,new Uint8Array(t.data),!0);Rs(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,po(n.awareness,Array.from(n.awareness.getStates().keys()).filter(r=>r!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Zu,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=q();if(x(t,Fn),fo(t,n.doc),e.send(I(t)),n.awareness.getLocalState()!==null){let r=q();x(r,Er),U(r,Ar(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&&zn(n.bcChannel,e,n)},Fc=class extends ir{constructor(e,t,r,{connect:i=!0,awareness:s=new uo(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=Oi.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=q();x(f,Fn),fo(f,r),this.ws.send(I(f))}},a)),this._bcSubscriber=(f,u)=>{if(u!==this){let p=Qu(this,new Uint8Array(f),!1);Rs(p)>1&&zn(this.bcChannel,I(p),this)}},this._updateHandler=(f,u)=>{if(u!==this){let p=q();x(p,Fn),$u(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=q();x(y,Er),U(y,Ar(s,g)),zc(this,I(y))},this._exitHandler=()=>{po(this.awareness,[r.clientID],"app closed")},St&&typeof process<"u"&&process.on("exit",this._exitHandler),s.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Gu{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var db=/[\uD800-\uDBFF]/,fb=/[\uDC00-\uDFFF]/,ub=(n,e)=>{let t=0,r=0;for(;t0&&db.test(n[t-1])&&t--;r+t0&&fb.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},tp=ub;var v=new pe("y-sync"),Gt=new pe("y-undo"),Ni=new pe("yjs-cursor");var Ri=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!Et(e.ds,n.id),pb=[{light:"#ecd44433",dark:"#ecd444"}],mb=(n,e,t)=>{if(!n.has(t)){if(n.sizer.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,rf(e))}return n.get(t)},ip=(n,{colors:e=pb,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new mo(n,s),c=new F({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)&&di(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=Gt.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},gb=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null){let r=Xt(t.doc,t.type,e.anchor,t.mapping),i=Xt(t.doc,t.type,e.head,t.mapping);r!==null&&i!==null&&(n=n.setSelection(A.create(n.doc,r,i)))}},vi=(n,e)=>({anchor:qn(e.selection.anchor,n.type,n.mapping),head:qn(e.selection.head,n.type,n.mapping)}),mo=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=ep(),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=vi(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()?(yr&&this._domSelectionInView===null&&(di(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=kt.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=Ei(kr(),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=>Ii(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=>Ii(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=Ti(this.doc)),(e instanceof Uint8Array||t instanceof Uint8Array)&&((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&j(),i=new Je({gc:!1}),Bn(i,t),t=Ti(i),Bn(i,e),e=Ti(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:mb(r.colorMapping,r.colors,f)}},c=ao(this.type,new Kt(t.ds,e.sv)).map(h=>!h._item.deleted||Ri(h._item,e)||Ri(h._item,t)?Ii(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=>sp(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));gb(o,this.beforeTransactionSelection,this),o=o.setMeta(v,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof In}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{Tr(this.doc,this.type,e,this.mapping),this.beforeTransactionSelection=vi(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))}},sp=(n,e,t,r,i,s)=>{let o=t.get(n);if(o===void 0){if(n instanceof Z)return Ii(n,e,t,r,i,s);throw Oe()}return o},Ii=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c.constructor===Z){let a=sp(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=yb(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):ao(n,new Kt(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(Ri(n._item,r)?Ri(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}},yb=(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},wb=(n,e)=>{let t=new xe,r=n.map(i=>({insert:i.text,attributes:lp(i.marks)}));return t.applyDelta(r),e.set(t,n),t},bb=(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,yo(n).map(r=>qc(r,e))),e.set(t,n),t},qc=(n,e)=>n instanceof Array?wb(n,e):bb(n,e),np=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&&Ps(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(s=>Jc(r.attributes[s.type.name]||{},s.attrs)))},_i=(n,e)=>{if(n instanceof Z&&!(e instanceof Array)&&Hc(n,e)){let t=yo(e);return n._length===t.length&&Jc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>_i(r,t[i]))}return n instanceof xe&&e instanceof Array&&op(n,e)},go=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),rp=(n,e,t)=>{let r=n.toArray(),i=yo(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}},Sb=(n,e,t)=>{t.set(n,e);let{nAttrs:r,str:i}=xb(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,lp(a.marks))})),{insert:o,remove:l,index:c}=tp(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})))},lp=n=>{let e={};return n.forEach(t=>{t.type.name!=="ychange"&&(e[t.type.name]=t.attrs)}),e},Tr=(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=yo(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)op(f,u)||Sb(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=rp(f,u,r),N=rp(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 Ui=null,kb=()=>{let n=Ui;Ui=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))})},$c=(n,e,t)=>{Ui||(Ui=new Map,di(0,kb)),$(Ui,n,_).set(e,t)},qn=(n,e,t)=>{if(n===0)return Ai(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 Ai(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?Pn(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?Pn(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 Cb(r._item.parent,r._item)}return Ai(e,e._length,-1)},Cb=(n,e)=>{let t=null,r=null;return n._item===null?r=Pn(n):t=M(n._item.id.client,n._item.id.clock),new ot(t,r,e.id)},Xt=(n,e,t,r)=>{let i=Oc(t,n);if(i===null||i.type!==e&&!Nn(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 Tr(r,t,n,new Map),t}function ap(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(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 Mb=(n,e,t)=>n!==e,Ab=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},Eb=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),Tb=/^#[0-9a-fA-F]{6}$/,hp=(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":Tb.test(h.color)||console.warn("A user uses an unsupported color format",h),h.name==null&&(h.name=`User: ${a}`);let d=Xt(o,s.type,Ln(c.cursor.anchor),s.binding.mapping),f=Xt(o,s.type,Ln(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))},Db=(n,{awarenessStateFilter:e=Mb,cursorBuilder:t=Ab,selectionBuilder:r=Eb,getSelection:i=o=>o.selection}={},s="cursor")=>new F({key:Ni,state:{init(o,l){return hp(l,n,e,t,r)},apply(o,l,c,a){let h=v.getState(a),d=o.getMeta(Ni);return h&&h.isChangeOrigin||d&&d.awarenessUpdated?hp(a,n,e,t,r):l.map(o.mapping,o.doc)}},props:{decorations:o=>Ni.getState(o)},view:o=>{let l=()=>{o.docView&&$c(o,Ni,{awarenessUpdated:!0})},c=()=>{let a=v.getState(o.state),h=n.getLocalState()||{};if(o.hasFocus()){let d=i(o.state),f=qn(d.anchor,a.type,a.binding.mapping),u=qn(d.head,a.type,a.binding.mapping);(h.cursor==null||!so(Ln(h.cursor.anchor),f)||!so(Ln(h.cursor.head),u))&&n.setLocalStateField(s,{anchor:f,head:u})}else h.cursor!=null&&Xt(a.doc,a.type,Ln(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 Ob=n=>{let e=Gt.getState(n).undoManager;if(e!=null)return e.undo(),!0},Nb=n=>{let e=Gt.getState(n).undoManager;if(e!=null)return e.redo(),!0},Ib=new Set(["paragraph"]),Rb=(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,vb=({protectedNodes:n=Ib,trackedOrigins:e=[],undoManager:t=null}={})=>new F({key:Gt,state:{init:(r,i)=>{let s=v.getState(i),o=t||new In(s.type,{trackedOrigins:new Set([v].concat(e)),deleteFilter:l=>Rb(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:vi(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=Gt.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,Gt.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 Vi="http://www.w3.org/2000/svg",_b="http://www.w3.org/1999/xlink",Yc="ProseMirror-icon",Kc="pm-close-dropdowns";function Ub(n){let e=0;for(let t=0;t{s.preventDefault(),r.classList.contains(Tt+"-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,dp(r,Tt+"-disabled",!o)),t.active){let l=o&&t.active(s)||!1;dp(r,Tt+"-active",l)}return!0}return{dom:r,update:i}}};function wo(n,e){return n._props.translate?n._props.translate(e):e}var Bi={time:0,node:null};function Pb(n){Bi.time=Date.now(),Bi.node=n.target}function Lb(n){return Date.now()-100{o&&o.close()&&(o=null,this.options.sticky||r.removeEventListener("mousedown",l),r.removeEventListener(Kc,c))};i.addEventListener("mousedown",d=>{d.preventDefault(),Pb(d),o?a():(r.dispatchEvent(new CustomEvent(Kc)),o=this.expand(s,t.dom),this.options.sticky||r.addEventListener("mousedown",l=()=>{Lb(s)||a()}),r.addEventListener(Kc,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=yt("div",{class:Tt+"-dropdown-menu "+(this.options.class||"")},t),i=!1;function s(){return i?!1:(i=!0,e.removeChild(r),!0)}return e.appendChild(r),{close:s,node:r}}};function zb(n,e){let t=[],r=[];for(let i=0;i{let r=!1;for(let i=0;iYr(n),icon:Pi.join}),Lk=new Dt({title:"Lift out of enclosing block",run:Gr,select:n=>Gr(n),icon:Pi.lift}),zk=new Dt({title:"Select parent node",run:Xr,select:n=>Xr(n),icon:Pi.selectParentNode}),Fk=new Dt({title:"Undo last change",run:bn,enable:n=>bn(n),icon:Pi.undo}),qk=new Dt({title:"Redo last undone change",run:zt,enable:n=>zt(n),icon:Pi.redo});function Hb(n,e){let t=tr(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 Dt(r)}function dp(n,e,t){t?n.classList.add(e):n.classList.remove(e)}export{Jn as DOMParser,It as DOMSerializer,Gc as Dropdown,Lo as EditorState,cl as EditorView,w as Fragment,wt as InputRule,Dt as MenuItem,F as Plugin,Ir as Schema,b as Slice,A as TextSelection,Fc as WebsocketProvider,Mr as Y,o0 as addColumnAfter,s0 as addColumnBefore,Sy as addListNodes,d0 as addRowAfter,h0 as addRowBefore,ad as baseKeymap,qg as baseSchema,Hb as blockTypeItem,qy as buildKeymap,I0 as columnResizing,c0 as deleteColumn,u0 as deleteRow,S0 as deleteTable,_d as fixTables,vy as gapCursor,x0 as goToNextCell,ud as history,yd as inputRules,Ny as keymap,Al as liftListItem,m0 as mergeCells,cp as prosemirrorToYDoc,Wc as prosemirrorToYXmlFragment,zt as redo,Fb as renderGrouped,El as sinkListItem,g0 as splitCell,Ml as splitListItem,q0 as tableEditing,jy as tableNodes,gn as toggleMark,bn as undo,ws as wrapInList,Db as yCursorPlugin,ap as yDocToProsemirrorJSON,Nb as yRedo,ip as ySyncPlugin,Ob as yUndo,vb as yUndoPlugin,jc as yXmlFragmentToProsemirrorJSON}; diff --git a/package-lock.json b/package-lock.json index 3d24336c..ace041fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,27 +5,28 @@ "packages": { "": { "name": "@adobecom/dark-alley", + "hasInstallScript": true, "license": "Apache License 2.0", "dependencies": { "esbuild": "^0.21.0", "jspreadsheet-ce": "^4.13.4", "jsuites": "^5.0.29", "lit": "^3.2.0", - "prosemirror-commands": "^1.5.2", - "prosemirror-example-setup": "^1.2.1", + "prosemirror-commands": "^1.6.1", + "prosemirror-example-setup": "^1.2.3", "prosemirror-gapcursor": "^1.3.2", - "prosemirror-history": "^1.3.2", + "prosemirror-history": "^1.4.1", "prosemirror-keymap": "^1.2.2", "prosemirror-menu": "^1.2.4", - "prosemirror-model": "^1.19.0", - "prosemirror-schema-basic": "^1.2.1", - "prosemirror-schema-list": "^1.3.0", + "prosemirror-model": "^1.23.0", + "prosemirror-schema-basic": "^1.2.3", + "prosemirror-schema-list": "^1.4.1", "prosemirror-state": "^1.4.2", - "prosemirror-tables": "^1.3.2", - "prosemirror-view": "^1.31.1", - "y-prosemirror": "^1.2.2", - "y-websocket": "^1.5.1", - "yjs": "^13.6.10" + "prosemirror-tables": "^1.5.1", + "prosemirror-view": "^1.34.3", + "y-prosemirror": "^1.2.12", + "y-websocket": "^2.0.4", + "yjs": "^13.6.20" }, "devDependencies": { "@babel/core": "7.24.5", @@ -6213,13 +6214,15 @@ } }, "node_modules/lib0": { - "version": "0.2.88", - "resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.88.tgz", - "integrity": "sha512-KyroiEvCeZcZEMx5Ys+b4u4eEBbA1ch7XUaBhYpwa/nPMrzTjUhI4RfcytmQfYoTBPcdyx+FX6WFNIoNuJzJfQ==", + "version": "0.2.98", + "resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.98.tgz", + "integrity": "sha512-XteTiNO0qEXqqweWx+b21p/fBnNHUA1NwAtJNJek1oPrewEZs2uiT4gWivHKr9GqCjDPAhchz0UQO8NwU3bBNA==", + "license": "MIT", "dependencies": { "isomorphic.js": "^0.2.4" }, "bin": { + "0ecdsa-generate-keypair": "bin/0ecdsa-generate-keypair.js", "0gentesthtml": "bin/gentesthtml.js", "0serve": "bin/0serve.js" }, @@ -7330,13 +7333,14 @@ } }, "node_modules/prosemirror-commands": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/prosemirror-commands/-/prosemirror-commands-1.5.2.tgz", - "integrity": "sha512-hgLcPaakxH8tu6YvVAaILV2tXYsW3rAdDR8WNkeKGcgeMVQg3/TMhPdVoh7iAmfgVjZGtcOSjKiQaoeKjzd2mQ==", + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/prosemirror-commands/-/prosemirror-commands-1.6.1.tgz", + "integrity": "sha512-tNy4uaGWzvuUYXDke7B28krndIrdQJhSh0OLpubtwtEwFbjItOj/eoAfPvstBJyyV0S2+b5t4G+4XPXdxar6pg==", + "license": "MIT", "dependencies": { "prosemirror-model": "^1.0.0", "prosemirror-state": "^1.0.0", - "prosemirror-transform": "^1.0.0" + "prosemirror-transform": "^1.10.2" } }, "node_modules/prosemirror-dropcursor": { @@ -7350,9 +7354,10 @@ } }, "node_modules/prosemirror-example-setup": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/prosemirror-example-setup/-/prosemirror-example-setup-1.2.2.tgz", - "integrity": "sha512-pHJc656IgYm249RNp0eQaWNmnyWGk6OrzysWfYI4+NwE14HQ7YNYOlRBLErUS6uCAHIYJLNXf0/XCmf1OCtNbQ==", + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/prosemirror-example-setup/-/prosemirror-example-setup-1.2.3.tgz", + "integrity": "sha512-+hXZi8+xbFvYM465zZH3rdZ9w7EguVKmUYwYLZjIJIjPK+I0nPTwn8j0ByW2avchVczRwZmOJGNvehblyIerSQ==", + "license": "MIT", "dependencies": { "prosemirror-commands": "^1.0.0", "prosemirror-dropcursor": "^1.0.0", @@ -7377,9 +7382,9 @@ } }, "node_modules/prosemirror-history": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/prosemirror-history/-/prosemirror-history-1.4.0.tgz", - "integrity": "sha512-UUiGzDVcqo1lovOPdi9YxxUps3oBFWAIYkXLu3Ot+JPv1qzVogRbcizxK3LhHmtaUxclohgiOVesRw5QSlMnbQ==", + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/prosemirror-history/-/prosemirror-history-1.4.1.tgz", + "integrity": "sha512-2JZD8z2JviJrboD9cPuX/Sv/1ChFng+xh2tChQ2X4bB2HeK+rra/bmJ3xGntCcjhOqIzSDG6Id7e8RJ9QPXLEQ==", "license": "MIT", "dependencies": { "prosemirror-state": "^1.2.2", @@ -7418,26 +7423,28 @@ } }, "node_modules/prosemirror-model": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/prosemirror-model/-/prosemirror-model-1.21.0.tgz", - "integrity": "sha512-zLpS1mVCZLA7VTp82P+BfMiYVPcX1/z0Mf3gsjKZtzMWubwn2pN7CceMV0DycjlgE5JeXPR7UF4hJPbBV98oWA==", + "version": "1.23.0", + "resolved": "https://registry.npmjs.org/prosemirror-model/-/prosemirror-model-1.23.0.tgz", + "integrity": "sha512-Q/fgsgl/dlOAW9ILu4OOhYWQbc7TQd4BwKH/RwmUjyVf8682Be4zj3rOYdLnYEcGzyg8LL9Q5IWYKD8tdToreQ==", "license": "MIT", "dependencies": { "orderedmap": "^2.0.0" } }, "node_modules/prosemirror-schema-basic": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/prosemirror-schema-basic/-/prosemirror-schema-basic-1.2.2.tgz", - "integrity": "sha512-/dT4JFEGyO7QnNTe9UaKUhjDXbTNkiWTq/N4VpKaF79bBjSExVV2NXmJpcM7z/gD7mbqNjxbmWW5nf1iNSSGnw==", + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/prosemirror-schema-basic/-/prosemirror-schema-basic-1.2.3.tgz", + "integrity": "sha512-h+H0OQwZVqMon1PNn0AG9cTfx513zgIG2DY00eJ00Yvgb3UD+GQ/VlWW5rcaxacpCGT1Yx8nuhwXk4+QbXUfJA==", + "license": "MIT", "dependencies": { "prosemirror-model": "^1.19.0" } }, "node_modules/prosemirror-schema-list": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/prosemirror-schema-list/-/prosemirror-schema-list-1.3.0.tgz", - "integrity": "sha512-Hz/7gM4skaaYfRPNgr421CU4GSwotmEwBVvJh5ltGiffUJwm7C8GfN/Bc6DR1EKEp5pDKhODmdXXyi9uIsZl5A==", + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/prosemirror-schema-list/-/prosemirror-schema-list-1.4.1.tgz", + "integrity": "sha512-jbDyaP/6AFfDfu70VzySsD75Om2t3sXTOdl5+31Wlxlg62td1haUpty/ybajSfJ1pkGadlOfwQq9kgW5IMo1Rg==", + "license": "MIT", "dependencies": { "prosemirror-model": "^1.0.0", "prosemirror-state": "^1.0.0", @@ -7455,9 +7462,9 @@ } }, "node_modules/prosemirror-tables": { - "version": "1.3.7", - "resolved": "https://registry.npmjs.org/prosemirror-tables/-/prosemirror-tables-1.3.7.tgz", - "integrity": "sha512-oEwX1wrziuxMtwFvdDWSFHVUWrFJWt929kVVfHvtTi8yvw+5ppxjXZkMG/fuTdFo+3DXyIPSKfid+Be1npKXDA==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/prosemirror-tables/-/prosemirror-tables-1.5.1.tgz", + "integrity": "sha512-zL0vI0rGdhLLKXaZU1Jw1I8RuXwa5bv4aEY6G9TdynNRIU2FodtfI/YdhqVlimilhOIBGMbhvTvnQy5fvbHt2A==", "license": "MIT", "dependencies": { "prosemirror-keymap": "^1.1.2", @@ -7468,17 +7475,18 @@ } }, "node_modules/prosemirror-transform": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/prosemirror-transform/-/prosemirror-transform-1.8.0.tgz", - "integrity": "sha512-BaSBsIMv52F1BVVMvOmp1yzD3u65uC3HTzCBQV1WDPqJRQ2LuHKcyfn0jwqodo8sR9vVzMzZyI+Dal5W9E6a9A==", + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/prosemirror-transform/-/prosemirror-transform-1.10.2.tgz", + "integrity": "sha512-2iUq0wv2iRoJO/zj5mv8uDUriOHWzXRnOTVgCzSXnktS/2iQRa3UUQwVlkBlYZFtygw6Nh1+X4mGqoYBINn5KQ==", + "license": "MIT", "dependencies": { - "prosemirror-model": "^1.0.0" + "prosemirror-model": "^1.21.0" } }, "node_modules/prosemirror-view": { - "version": "1.33.6", - "resolved": "https://registry.npmjs.org/prosemirror-view/-/prosemirror-view-1.33.6.tgz", - "integrity": "sha512-zRLUNgLIQfd8IfGprsXxWTjdA8xEAFJe8cDNrOptj6Mop9sj+BMeVbJvceyAYCm5G2dOdT2prctH7K9dfnpIMw==", + "version": "1.34.3", + "resolved": "https://registry.npmjs.org/prosemirror-view/-/prosemirror-view-1.34.3.tgz", + "integrity": "sha512-mKZ54PrX19sSaQye+sef+YjBbNu2voNwLS1ivb6aD2IRmxRGW64HU9B644+7OfJStGLyxvOreKqEgfvXa91WIA==", "license": "MIT", "dependencies": { "prosemirror-model": "^1.20.0", @@ -9465,9 +9473,9 @@ } }, "node_modules/y-prosemirror": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/y-prosemirror/-/y-prosemirror-1.2.5.tgz", - "integrity": "sha512-T/JATxC8P2Dbvq/dAiaiztD1a8KEwRP8oLRlT8YlaZdNlLGE1Ea0IJ8If25UlDYmk+4+uqLbqT/S+dzUmwwgbA==", + "version": "1.2.12", + "resolved": "https://registry.npmjs.org/y-prosemirror/-/y-prosemirror-1.2.12.tgz", + "integrity": "sha512-UMnUIR5ppVn30n2kzeeBQEaesWGe4fsbnlch1HnNa3/snJMoOn7M7dieuS+o1OQwKs1dqx2eT3gFfGF2aOaQdw==", "license": "MIT", "dependencies": { "lib0": "^0.2.42" @@ -9508,9 +9516,9 @@ } }, "node_modules/y-websocket": { - "version": "1.5.4", - "resolved": "https://registry.npmjs.org/y-websocket/-/y-websocket-1.5.4.tgz", - "integrity": "sha512-Y3021uy0anOIHqAPyAZbNDoR05JuMEGjRNI8c+K9MHzVS8dWoImdJUjccljAznc8H2L7WkIXhRHZ1igWNRSgPw==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/y-websocket/-/y-websocket-2.0.4.tgz", + "integrity": "sha512-UbrkOU4GPNFFTDlJYAxAmzZhia8EPxHkngZ6qjrxgIYCN3gI2l+zzLzA9p4LQJ0IswzpioeIgmzekWe7HoBBjg==", "license": "MIT", "dependencies": { "lib0": "^0.2.52", @@ -9518,8 +9526,8 @@ "y-protocols": "^1.0.5" }, "bin": { - "y-websocket": "bin/server.js", - "y-websocket-server": "bin/server.js" + "y-websocket": "bin/server.cjs", + "y-websocket-server": "bin/server.cjs" }, "engines": { "node": ">=16.0.0", @@ -9622,12 +9630,12 @@ } }, "node_modules/yjs": { - "version": "13.6.15", - "resolved": "https://registry.npmjs.org/yjs/-/yjs-13.6.15.tgz", - "integrity": "sha512-moFv4uNYhp8BFxIk3AkpoAnnjts7gwdpiG8RtyFiKbMtxKCS0zVZ5wPaaGpwC3V2N/K8TK8MwtSI3+WO9CHWjQ==", + "version": "13.6.20", + "resolved": "https://registry.npmjs.org/yjs/-/yjs-13.6.20.tgz", + "integrity": "sha512-Z2YZI+SYqK7XdWlloI3lhMiKnCdFCVC4PchpdO+mCYwtiTwncjUbnRK9R1JmkNfdmHyDXuWN3ibJAt0wsqTbLQ==", "license": "MIT", "dependencies": { - "lib0": "^0.2.86" + "lib0": "^0.2.98" }, "engines": { "node": ">=16.0.0", diff --git a/package.json b/package.json index d6fc0288..fbdcd492 100644 --- a/package.json +++ b/package.json @@ -12,21 +12,21 @@ "jspreadsheet-ce": "^4.13.4", "jsuites": "^5.0.29", "lit": "^3.2.0", - "prosemirror-commands": "^1.5.2", - "prosemirror-example-setup": "^1.2.1", + "prosemirror-commands": "^1.6.1", + "prosemirror-example-setup": "^1.2.3", "prosemirror-gapcursor": "^1.3.2", - "prosemirror-history": "^1.3.2", + "prosemirror-history": "^1.4.1", "prosemirror-keymap": "^1.2.2", "prosemirror-menu": "^1.2.4", - "prosemirror-model": "^1.19.0", - "prosemirror-schema-basic": "^1.2.1", - "prosemirror-schema-list": "^1.3.0", + "prosemirror-model": "^1.23.0", + "prosemirror-schema-basic": "^1.2.3", + "prosemirror-schema-list": "^1.4.1", "prosemirror-state": "^1.4.2", - "prosemirror-tables": "^1.3.2", - "prosemirror-view": "^1.31.1", - "y-prosemirror": "^1.2.2", - "y-websocket": "^1.5.1", - "yjs": "^13.6.10" + "prosemirror-tables": "^1.5.1", + "prosemirror-view": "^1.34.3", + "y-prosemirror": "^1.2.12", + "y-websocket": "^2.0.4", + "yjs": "^13.6.20" }, "devDependencies": { "@babel/core": "7.24.5", @@ -52,6 +52,7 @@ "lint:css": "stylelint blocks/**/*.css styles/*.css", "lint": "npm run lint:js && npm run lint:css", "copy:deps": "node ./deps/copy.js", + "postinstall": "npm run build:da-y-wrapper && npm run build:da-lit", "test": "wtr \"./test/unit/**/*.test.js\" --node-resolve --port=2000 --coverage", "test:watch": "npm test -- --watch", "test:e2e": "cd test/e2e && npm i && npm run test:all",