import{R as Oi}from"./vendor-rope-sequence-nfUW61tr.js";import{i as ao}from"./vendor-ocavue-utils-C1mApV17.js";import{k as co,b as fo}from"./vendor-w3c-keyname-Vcq4gwWv.js";import{O as cr}from"./vendor-orderedmap-C4TimWWB.js";function Ti(r,e,t){for(let n=0;;n++){if(n==r.childCount||n==e.childCount)return r.childCount==e.childCount?null:t;let i=r.child(n),s=e.child(n);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=Ti(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function Di(r,e,t,n){for(let i=r.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:n};let o=r.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,n-=a;continue}if(!o.sameMarkup(l))return{a:t,b:n};if(o.isText&&o.text!=l.text){let c=0,f=Math.min(o.text.length,l.text.length);for(;ce&&n(a,i+l,s||null,o)!==!1&&a.content.size){let f=l+1;a.nodesBetween(Math.max(0,e-f),Math.min(a.content.size,t-f),n,i+f)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&n&&(o?o=!1:s+=n),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(n)&&(i[i.length-1]=t.withText(t.text+n.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))),n.push(l),i+=l.nodeSize),o=a}return new y(n,i)}cutByIndex(e,t){return e==t?y.empty:e==0&&t==this.content.length?this:new y(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-n.nodeSize;return i[e]=t,new y(i,s)}addToStart(e){return new y([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new y(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 t=0,n=0;;t++){let i=this.child(t),s=n+i.nodeSize;if(s>=e)return s==e?Nt(t+1,s):Nt(t,n);n=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return y.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new y(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return y.empty;let t,n=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),n=!0),t&&t.push(s)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;tn.type.rank-i.type.rank),t}}M.none=[];class Vt extends Error{}class x{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=Ei(this.content,e+this.openStart,t);return n&&new x(n,this.openStart,this.openEnd)}removeBetween(e,t){return new x(Ai(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 x.empty;let n=t.openStart||0,i=t.openEnd||0;if(typeof n!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new x(y.fromJSON(e,t.content),n,i)}static maxOpen(e,t=!0){let n=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)n++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new x(e,n,i)}}x.empty=new x(y.empty,0,0);function Ai(r,e,t){let{index:n,offset:i}=r.findIndex(e),s=r.maybeChild(n),{index:o,offset:l}=r.findIndex(t);if(i==e||s.isText){if(l!=t&&!r.child(o).isText)throw new RangeError("Removing non-flat range");return r.cut(0,e).append(r.cut(t))}if(n!=o)throw new RangeError("Removing non-flat range");return r.replaceChild(n,s.copy(Ai(s.content,e-i-1,t-i-1)))}function Ei(r,e,t,n){let{index:i,offset:s}=r.findIndex(e),o=r.maybeChild(i);if(s==e||o.isText)return n&&!n.canReplace(i,i,t)?null:r.cut(0,e).append(t).append(r.cut(e));let l=Ei(o.content,e-s-1,t,o);return l&&r.replaceChild(i,o.copy(l))}function ho(r,e,t){if(t.openStart>r.depth)throw new Vt("Inserted content deeper than insertion position");if(r.depth-t.openStart!=e.depth-t.openEnd)throw new Vt("Inconsistent open depths");return Ri(r,e,t,0)}function Ri(r,e,t,n){let i=r.index(n),s=r.node(n);if(i==e.index(n)&&n=0&&r.isText&&r.sameMarkup(e[t])?e[t]=r.withText(e[t].text+r.text):e.push(r)}function ct(r,e,t,n){let i=(e||r).node(t),s=0,o=e?e.index(t):i.childCount;r&&(s=r.index(t),r.depth>t?s++:r.textOffset&&(ze(r.nodeAfter,n),s++));for(let l=s;li&&kn(r,e,i+1),o=n.depth>i&&kn(t,n,i+1),l=[];return ct(null,r,i,l),s&&o&&e.index(i)==t.index(i)?(Ii(s,o),ze(Be(s,zi(r,e,t,n,i+1)),l)):(s&&ze(Be(s,Lt(r,e,i+1)),l),ct(e,t,i,l),o&&ze(Be(o,Lt(t,n,i+1)),l)),ct(n,null,i,l),new y(l)}function Lt(r,e,t){let n=[];if(ct(null,r,t,n),r.depth>t){let i=kn(r,e,t+1);ze(Be(i,Lt(r,e,t+1)),n)}return ct(e,null,t,n),new y(n)}function uo(r,e){let t=e.depth-r.openStart,i=e.node(t).copy(r.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(y.from(i));return{start:i.resolveNoCache(r.openStart+t),end:i.resolveNoCache(i.content.size-r.openEnd-t)}}class pt{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,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 n=this.pos-this.path[this.path.length-1],i=e.child(t);return n?e.child(t).cut(n):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 n=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;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new Bi(this,e,n);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 n=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(n.push(o,l,i+a),!c||(o=o.child(l),o.isText))break;s=c-1,i+=a+1}return new pt(t,n,s)}static resolveCached(e,t){let n=fr.get(e);if(n)for(let s=0;se&&this.nodesBetween(e,t,s=>(n.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()+")"),Pi(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,n=y.empty,i=0,s=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;at.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 n;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=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,n)}let i=y.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,n);return s.type.checkAttrs(s.attrs),s}}ie.prototype.text=void 0;class $t extends ie{constructor(e,t,n,i){if(super(e,t,null,i),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Pi(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 $t(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new $t(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 Pi(r,e){for(let t=r.length-1;t>=0;t--)e=r[t].type.name+"("+e+")";return e}class Ve{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new yo(e,t);if(n.next==null)return Ve.empty;let i=vi(n);n.next&&n.err("Unexpected trailing text");let s=Mo(wo(i));return No(s,n),s}matchType(e){for(let t=0;tc.createAndFill()));for(let c=0;c=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(n){e.push(n);for(let i=0;i{let s=i+(n.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(n.next[o].next);return s}).join(` `)}}Ve.empty=new Ve(!0);class yo{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 vi(r){let e=[];do e.push(bo(r));while(r.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function bo(r){let e=[];do e.push(xo(r));while(r.next&&r.next!=")"&&r.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function xo(r){let e=ko(r);for(;;)if(r.eat("+"))e={type:"plus",expr:e};else if(r.eat("*"))e={type:"star",expr:e};else if(r.eat("?"))e={type:"opt",expr:e};else if(r.eat("{"))e=So(r,e);else break;return e}function hr(r){/\D/.test(r.next)&&r.err("Expected number, got '"+r.next+"'");let e=Number(r.next);return r.pos++,e}function So(r,e){let t=hr(r),n=t;return r.eat(",")&&(r.next!="}"?n=hr(r):n=-1),r.eat("}")||r.err("Unclosed braced range"),{type:"range",min:t,max:n,expr:e}}function Co(r,e){let t=r.nodeTypes,n=t[e];if(n)return[n];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&r.err("No node type or group '"+e+"' found"),i}function ko(r){if(r.eat("(")){let e=vi(r);return r.eat(")")||r.err("Missing closing paren"),e}else if(/\W/.test(r.next))r.err("Unexpected token '"+r.next+"'");else{let e=Co(r,r.next).map(t=>(r.inline==null?r.inline=t.isInline:r.inline!=t.isInline&&r.err("Mixing inline and block content"),{type:"name",value:t}));return r.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function wo(r){let e=[[]];return i(s(r,0),t()),e;function t(){return e.push([])-1}function n(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;i(c,l=t())}else if(o.type=="star"){let a=t();return n(l,a),i(s(o.expr,a),a),[n(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[n(a)]}else{if(o.type=="opt")return[n(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c{r[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let f=0;f{c||i.push([l,c=[]]),c.indexOf(f)==-1&&c.push(f)})})});let s=e[n.join(",")]=new Ve(n.indexOf(r.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:Li(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new ie(this,this.computeAttrs(e),y.from(t),M.setFrom(n))}createChecked(e=null,t,n){return t=y.from(t),this.checkContent(t),new ie(this,this.computeAttrs(e),t,M.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=y.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(y.empty,!0);return s?new ie(this,e,t.append(s),M.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let n=0;n-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tn[s]=new Ji(s,t,o));let i=t.spec.topNode||"doc";if(!n[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let s in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}};function Oo(r,e,t){let n=t.split("|");return i=>{let s=i===null?"null":typeof i;if(n.indexOf(s)<0)throw new RangeError(`Expected value of type ${n} for attribute ${e} on type ${r}, got ${s}`)}}class To{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate=typeof n.validate=="string"?Oo(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class Ut{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=Wi(e,i.attrs),this.excluded=null;let s=Vi(this.attrs);this.instance=s?new M(this,s):null}create(e=null){return!e&&this.instance?this.instance:new M(this,Li(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach((s,o)=>n[s]=new Ut(s,i++,t,o)),n}removeFromSet(e){for(var t=0;t-1}}class Hf{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=cr.from(e.nodes),t.marks=cr.from(e.marks||{}),this.nodes=ur.compile(this.spec.nodes,this),this.marks=Ut.compile(this.spec.marks,this);let n=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=n[o]||(n[o]=Ve.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?pr(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==""?[]:pr(this,o.split(" "))}this.nodeFromJSON=i=>ie.fromJSON(this,i),this.markFromJSON=i=>M.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof ur){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,n,i)}text(e,t){let n=this.nodes.text;return new $t(n,n.defaultAttrs,e,M.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function pr(r,e){let t=[];for(let n=0;n-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[n]+"'")}return t}function Do(r){return r.tag!=null}function Ao(r){return r.style!=null}class mt{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(i=>{if(Do(i))this.tags.push(i);else if(Ao(i)){let s=/[^=]*/.exec(i.style)[0];n.indexOf(s)<0&&n.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 n=new gr(this,t,!1);return n.addAll(e,M.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new gr(this,t,!0);return n.addAll(e,M.none,t.from,t.to),x.maxOpen(n.finish())}matchTag(e,t,n){for(let i=n?this.tags.indexOf(n)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function n(i){let s=i.priority==null?50:i.priority,o=0;for(;o{n(o=yr(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=>{n(o=yr(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new mt(e,mt.schemaRules(e)))}}const qi={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},Eo={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ki={ol:!0,ul:!0},gt=1,wn=2,ft=4;function mr(r,e,t){return e!=null?(e?gt:0)|(e==="full"?wn:0):r&&r.whitespace=="pre"?gt|wn:t&~ft}class Ot{constructor(e,t,n,i,s,o){this.type=e,this.attrs=t,this.marks=n,this.solid=i,this.options=o,this.content=[],this.activeMarks=M.none,this.match=s||(o&ft?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 n=this.type.contentMatch,i;return(i=n.findWrapping(e.type))?(this.match=n,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options>)){let n=this.content[this.content.length-1],i;if(n&&n.isText&&(i=/[ \t\r\n\u000c]+$/.exec(n.text))){let s=n;n.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}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!qi.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class gr{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let i=t.topNode,s,o=mr(null,t.preserveWhitespace,0)|(n?ft:0);i?s=new Ot(i.type,i.attrs,M.none,!0,t.topMatch||i.type.contentMatch,o):n?s=new Ot(null,null,M.none,!0,null,o):s=new Ot(e.schema.topNodeType,null,M.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 n=e.nodeValue,i=this.top,s=i.options&wn?"full":this.localPreserveWS||(i.options>)>0,{schema:o}=this.parser;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(s)if(s==="full")n=n.replace(/\r\n?/g,` `);else if(o.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(o.linebreakReplacement.create())){let l=n.split(/\r?\n|\r/);for(let a=0;a!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,n,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),n,e.nodeName=="BR")||this.leafFallback(e,n);else{let a=this.enter(o,t.attrs||null,n,t.preserveWhitespace);a&&(s=!0,n=a)}else{let a=this.parser.schema.marks[t.mark];n=n.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,n,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,n,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,n),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,n,i){let s=n||0;for(let o=n?e.childNodes[n]: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,n){let i,s;for(let o=this.open,l=0;o>=0;o--){let a=this.nodes[o],c=a.findWrapping(e);if(c&&(!i||i.length>c.length+l)&&(i=c,s=a,!c.length))break;if(a.solid){if(n)break;l+=2}}if(!i)return null;this.sync(s);for(let o=0;o(o.type?o.type.allowsMarkType(c.type):br(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Ot(e,t,a,i,null,l)),this.open++,n}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;this.localPreserveWS&&(this.nodes[t].options|=gt)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let i=n.length-1;i>=0;i--)e+=n[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,i=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),s=-(n?n.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let f=a>0||a==0&&i?this.nodes[a].type:n&&a>=s?n.node(a-s).type:null;if(!f||f.name!=c&&!f.isInGroup(c))return!1;a--}}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 n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let n=this.parser.schema.nodes[t];if(n.isTextblock&&n.defaultAttrs)return n}}}function Ro(r){for(let e=r.firstChild,t=null;e;e=e.nextSibling){let n=e.nodeType==1?e.nodeName.toLowerCase():null;n&&Ki.hasOwnProperty(n)&&t?(t.appendChild(e),e=t):n=="li"?t=e:n&&(t=null)}}function Io(r,e){return(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,e)}function yr(r){let e={};for(let t in r)e[t]=r[t];return e}function br(r,e){let t=e.schema.nodes;for(let n in t){let i=t[n];if(!i.allowsMarkType(r))continue;let s=[],o=l=>{s.push(l);for(let a=0;a{if(s.length||o.marks.length){let l=0,a=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(n),n=s.dom)}return n}serializeMark(e,t,n={}){let i=this.marks[e.type.name];return i&&It(sn(n),i(e,t),null,e.attrs)}static renderSpec(e,t,n=null,i){return It(e,t,n,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new nt(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=xr(e.nodes);return t.text||(t.text=n=>n.text),t}static marksFromSchema(e){return xr(e.marks)}}function xr(r){let e={};for(let t in r){let n=r[t].spec.toDOM;n&&(e[t]=n)}return e}function sn(r){return r.document||window.document}const Sr=new WeakMap;function zo(r){let e=Sr.get(r);return e===void 0&&Sr.set(r,e=Bo(r)),e}function Bo(r){let e=null;function t(n){if(n&&typeof n=="object")if(Array.isArray(n))if(typeof n[0]=="string")e||(e=[]),e.push(n);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,a=t?r.createElementNS(t,i):r.createElement(i),c=e[1],f=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){f=2;for(let h in c)if(c[h]!=null){let d=h.indexOf(" ");d>0?a.setAttributeNS(h.slice(0,d),h.slice(d+1),c[h]):h=="style"&&a.style?a.style.cssText=c[h]:a.setAttribute(h,c[h])}}for(let h=f;hf)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:u,contentDOM:p}=It(r,d,t,n);if(a.appendChild(u),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}const Hi=65535,ji=Math.pow(2,16);function Po(r,e){return r+e*ji}function Cr(r){return r&Hi}function vo(r){return(r-(r&Hi))/ji}const Ui=1,Gi=2,zt=4,Xi=8;class Mn{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&Xi)>0}get deletedBefore(){return(this.delInfo&(Ui|zt))>0}get deletedAfter(){return(this.delInfo&(Gi|zt))>0}get deletedAcross(){return(this.delInfo&zt)>0}}class U{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&U.empty)return U.empty}recover(e){let t=0,n=Cr(e);if(!this.inverted)for(let i=0;ie)break;let c=this.ranges[l+s],f=this.ranges[l+o],h=a+c;if(e<=h){let d=c?e==a?-1:e==h?1:t:t,u=a+i+(d<0?0:f);if(n)return u;let p=e==(t<0?a:h)?null:Po(l/3,e-a),m=e==a?Gi:e==h?Ui:zt;return(t<0?e!=a:e!=h)&&(m|=Xi),new Mn(u,m,p)}i+=f-c}return n?e+i:new Mn(e+i,0,null)}touches(e,t){let n=0,i=Cr(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let c=this.ranges[l+s],f=a+c;if(e<=f&&l==i*3)return!0;n+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,n=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?n-i-1:void 0)}}invert(){let e=new yt;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;ns&&a!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return I.fromReplace(e,this.from,this.to,s)}invert(){return new re(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new Se(t.pos,n.pos,this.mark)}merge(e){return e instanceof Se&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Se(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 Se(t.from,t.to,e.markFromJSON(t.mark))}}$.jsonID("addMark",Se);class re extends ${constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new x(qn(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return I.fromReplace(e,this.from,this.to,n)}invert(){return new Se(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new re(t.pos,n.pos,this.mark)}merge(e){return e instanceof re&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new re(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 re(t.from,t.to,e.markFromJSON(t.mark))}}$.jsonID("removeMark",re);class Ce extends ${constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return I.fromReplace(e,this.pos,this.pos+1,new x(y.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let n=this.mark.addToSet(t.marks);if(n.length==t.marks.length){for(let i=0;in.pos?null:new L(t.pos,n.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 L(t.from,t.to,t.gapFrom,t.gapTo,x.fromJSON(e,t.slice),t.insert,!!t.structure)}}$.jsonID("replaceAround",L);function Nn(r,e,t){let n=r.resolve(e),i=t-e,s=n.depth;for(;i>0&&s>0&&n.indexAfter(s)==n.node(s).childCount;)s--,i--;if(i>0){let o=n.node(s).maybeChild(n.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Fo(r,e,t,n){let i=[],s=[],o,l;r.doc.nodesBetween(e,t,(a,c,f)=>{if(!a.isInline)return;let h=a.marks;if(!n.isInSet(h)&&f.type.allowsMarkType(n.type)){let d=Math.max(c,e),u=Math.min(c+a.nodeSize,t),p=n.addToSet(h);for(let m=0;mr.step(a)),s.forEach(a=>r.step(a))}function Vo(r,e,t,n){let i=[],s=0;r.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(n instanceof Ut){let c=o.marks,f;for(;f=n.isInSet(c);)(a||(a=[])).push(f),c=f.removeFromSet(c)}else n?n.isInSet(o.marks)&&(a=[n]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let f=0;fr.step(new re(o.from,o.to,o.style)))}function Kn(r,e,t,n=t.contentMatch,i=!0){let s=r.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a=0;a--)r.step(o[a])}function Lo(r,e,t){return(e==0||r.canReplace(e,r.childCount))&&(t==r.childCount||r.canReplace(0,t))}function Gt(r){let t=r.parent.content.cutByIndex(r.startIndex,r.endIndex);for(let n=r.depth,i=0,s=0;;--n){let o=r.$from.node(n),l=r.$from.index(n)+i,a=r.$to.indexAfter(n)-s;if(nt;p--)m||n.index(p)>0?(m=!0,f=y.from(n.node(p).copy(f)),h++):a--;let d=y.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(n.size){let l=t[o].type.contentMatch.matchFragment(n);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}n=y.from(t[o].type.create(t[o].attrs,n))}let i=e.start,s=e.end;r.step(new L(i,s,i,s,new x(n,0,0),t.length,!0))}function Ko(r,e,t,n,i){if(!n.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=r.steps.length;r.doc.nodesBetween(e,t,(o,l)=>{let a=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(n,a)&&Ho(r.doc,r.mapping.slice(s).map(l),n)){let c=null;if(n.schema.linebreakReplacement){let u=n.whitespace=="pre",p=!!n.contentMatch.matchType(n.schema.linebreakReplacement);u&&!p?c=!1:!u&&p&&(c=!0)}c===!1&&Zi(r,o,l,s),Kn(r,r.mapping.slice(s).map(l,1),n,void 0,c===null);let f=r.mapping.slice(s),h=f.map(l,1),d=f.map(l+o.nodeSize,1);return r.step(new L(h,d,h+1,d-1,new x(y.from(n.create(a,null,o.marks)),0,0),1,!0)),c===!0&&_i(r,o,l,s),!1}})}function _i(r,e,t,n){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let a=r.mapping.slice(n).map(t+1+s+o.index);r.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function Zi(r,e,t,n){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=r.mapping.slice(n).map(t+1+s);r.replaceWith(o,o+1,e.type.schema.text(` `))}})}function Ho(r,e,t){let n=r.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,t)}function jo(r,e,t,n,i){let s=r.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(n,null,i||s.marks);if(s.isLeaf)return r.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);r.step(new L(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new x(y.from(o),0,0),1,!0))}function ht(r,e,t=1,n){let i=r.resolve(e),s=i.depth-t,o=n&&n[n.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 c=i.depth-1,f=t-2;c>s;c--,f--){let h=i.node(c),d=i.index(c);if(h.type.spec.isolating)return!1;let u=h.content.cutByIndex(d,h.childCount),p=n&&n[f+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=n&&n[f]||h;if(!h.canReplace(d+1,h.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),a=n&&n[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function Uo(r,e,t=1,n){let i=r.doc.resolve(e),s=y.empty,o=y.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){s=y.from(i.node(l).copy(s));let f=n&&n[c];o=y.from(f?f.type.create(f.attrs,o):i.node(l).copy(o))}r.step(new B(e,e,new x(s.append(o),t,t),!0))}function Xt(r,e){let t=r.resolve(e),n=t.index();return Xo(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(n,n+1)}function Go(r,e){e.content.size||r.type.compatibleContent(e.type);let t=r.contentMatchAt(r.childCount),{linebreakReplacement:n}=r.type.schema;for(let i=0;i=0;i--){let s=n.index(i);if(n.node(i).canReplaceWith(s,s,t))return n.before(i+1);if(s>0)return null}if(n.parentOffset==n.parent.content.size)for(let i=n.depth-1;i>=0;i--){let s=n.indexAfter(i);if(n.node(i).canReplaceWith(s,s,t))return n.after(i+1);if(s=0;o--){let l=o==n.depth?0:n.pos<=(n.start(o+1)+n.end(o+1))/2?-1:1,a=n.index(o)+(l>0?1:0),c=n.node(o),f=!1;if(s==1)f=c.canReplace(a,a,i);else{let h=c.contentMatchAt(a).findWrapping(i.firstChild.type);f=h&&c.canReplaceWith(a,a,h[0])}if(f)return l==0?n.pos:l<0?n.before(o+1):n.after(o+1)}return null}function Yt(r,e,t=e,n=x.empty){if(e==t&&!n.size)return null;let i=r.resolve(e),s=r.resolve(t);return Qi(i,s,n)?new B(e,t,n):new Qo(i,s,n).fit()}function Qi(r,e,t){return!t.openStart&&!t.openEnd&&r.start()==e.start()&&r.parent.canReplace(r.index(),e.index(),t.content)}class Qo{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,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 c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,i=this.close(e<0?this.$to:n.doc.resolve(e));if(!i)return null;let s=this.placed,o=n.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new x(s,o,l);return e>-1?new L(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new B(n.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,i=this.unplaced.openEnd;n1&&(i=0),s.type.spec.isolating&&i<=n){e=n;break}t=s.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let i,s=null;n?(s=ln(this.unplaced.content,n-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],f,h=null;if(t==1&&(o?c.matchType(o.type)||(h=c.fillBefore(y.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:n,frontierDepth:l,parent:s,inject:h};if(t==2&&o&&(f=c.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:l,parent:s,wrap:f};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=ln(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new x(e,t+1,Math.max(n,i.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=ln(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new x(st(e,t-1,1),t-1,s?t-1:n)}else this.unplaced=new x(st(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||a==0||m.content.size)&&(h=g,f.push(es(m.mark(d.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?u:-1)))}let p=c==l.childCount;p||(u=-1),this.placed=ot(this.placed,t,y.from(f)),this.frontier[t].match=h,p&&u<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--n);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:i}=this.frontier[t],s=t=0;l--){let{match:a,type:c}=this.frontier[l],f=an(e,l,c,a,!0);if(!f||f.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=ot(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let i=e.node(n),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(n));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,n){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=ot(this.placed,this.depth,y.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(y.empty,!0);t.childCount&&(this.placed=ot(this.placed,this.frontier.length,t))}}function st(r,e,t){return e==0?r.cutByIndex(t,r.childCount):r.replaceChild(0,r.firstChild.copy(st(r.firstChild.content,e-1,t)))}function ot(r,e,t){return e==0?r.append(t):r.replaceChild(r.childCount-1,r.lastChild.copy(ot(r.lastChild.content,e-1,t)))}function ln(r,e){for(let t=0;t1&&(n=n.replaceChild(0,es(n.firstChild,e-1,n.childCount==1?t-1:0))),e>0&&(n=r.type.contentMatch.fillBefore(n).append(n),t<=0&&(n=n.append(r.type.contentMatch.matchFragment(n).fillBefore(y.empty,!0)))),r.copy(n)}function an(r,e,t,n,i){let s=r.node(e),o=i?r.indexAfter(e):r.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=n.fillBefore(s.content,!0,o);return l&&!el(t,s.content,o)?l:null}function el(r,e,t){for(let n=t;n0;d--,u--){let p=i.node(d).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(d)>-1?l=d:i.before(d)==u&&o.splice(1,0,-d)}let a=o.indexOf(l),c=[],f=n.openStart;for(let d=n.content,u=0;;u++){let p=d.firstChild;if(c.push(p),u==n.openStart)break;d=p.content}for(let d=f-1;d>=0;d--){let u=c[d],p=tl(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))f=d;else if(p||!u.type.isTextblock)break}for(let d=n.openStart;d>=0;d--){let u=(d+f+1)%(n.openStart+1),p=c[u];if(p)for(let m=0;m=0&&(r.replace(e,t,n),!(r.steps.length>h));d--){let u=o[d];u<0||(e=i.before(u),t=s.after(u))}}function ts(r,e,t,n,i){if(en){let s=i.contentMatchAt(0),o=s.fillBefore(r).append(r);r=o.append(s.matchFragment(o).fillBefore(y.empty,!0))}return r}function rl(r,e,t,n){if(!n.isInline&&e==t&&r.doc.resolve(e).parent.content.size){let i=_o(r.doc,e,n.type);i!=null&&(e=t=i)}r.replaceRange(e,t,new x(y.from(n),0,0))}function il(r,e,t){let n=r.doc.resolve(e),i=r.doc.resolve(t),s=ns(n,i);for(let o=0;o0&&(a||n.node(l-1).canReplace(n.index(l-1),i.indexAfter(l-1))))return r.delete(n.before(l),i.after(l))}for(let o=1;o<=n.depth&&o<=i.depth;o++)if(e-n.start(o)==n.depth-o&&t>n.end(o)&&i.end(o)-t!=i.depth-o&&n.start(o-1)==i.start(o-1)&&n.node(o-1).canReplace(n.index(o-1),i.index(o-1)))return r.delete(n.before(o),t);r.delete(e,t)}function ns(r,e){let t=[],n=Math.min(r.depth,e.depth);for(let i=n;i>=0;i--){let s=r.start(i);if(se.pos+(e.depth-i)||r.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==r.depth&&i==e.depth&&r.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}class Xe extends ${constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return I.fail("No node at attribute step's position");let n=Object.create(null);for(let s in t.attrs)n[s]=t.attrs[s];n[this.attr]=this.value;let i=t.type.create(n,null,t.marks);return I.fromReplace(e,this.pos,this.pos+1,new x(y.from(i),0,t.isLeaf?0:1))}getMap(){return U.empty}invert(e){return new Xe(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 Xe(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 Xe(t.pos,t.attr,t.value)}}$.jsonID("attr",Xe);class bt extends ${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 n=e.type.create(t,e.content,e.marks);return I.ok(n)}getMap(){return U.empty}invert(e){return new bt(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 bt(t.attr,t.value)}}$.jsonID("docAttr",bt);let _e=class extends Error{};_e=function r(e){let t=Error.call(this,e);return t.__proto__=r.prototype,t};_e.prototype=Object.create(Error.prototype);_e.prototype.constructor=_e;_e.prototype.name="TransformError";class rs{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new yt}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new _e(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,n=x.empty){let i=Yt(this.doc,e,t,n);return i&&this.step(i),this}replaceWith(e,t,n){return this.replace(e,t,new x(y.from(n),0,0))}delete(e,t){return this.replace(e,t,x.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return nl(this,e,t,n),this}replaceRangeWith(e,t,n){return rl(this,e,t,n),this}deleteRange(e,t){return il(this,e,t),this}lift(e,t){return $o(this,e,t),this}join(e,t=1){return Yo(this,e,t),this}wrap(e,t){return qo(this,e,t),this}setBlockType(e,t=e,n,i=null){return Ko(this,e,t,n,i),this}setNodeMarkup(e,t,n=null,i){return jo(this,e,t,n,i),this}setNodeAttribute(e,t,n){return this.step(new Xe(e,t,n)),this}setDocAttribute(e,t){return this.step(new bt(e,t)),this}addNodeMark(e,t){return this.step(new Ce(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t instanceof M)t.isInSet(n.marks)&&this.step(new Le(e,t));else{let i=n.marks,s,o=[];for(;s=t.isInSet(i);)o.push(new Le(e,s)),i=s.removeFromSet(i);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,n){return Uo(this,e,t,n),this}addMark(e,t,n){return Fo(this,e,t,n),this}removeMark(e,t,n){return Vo(this,e,t,n),this}clearIncompatible(e,t,n){return Kn(this,e,t,n),this}}const cn=Object.create(null);class C{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new is(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?He(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):He(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,n);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new X(e.node(0))}static atStart(e){return He(e,e,0,0,1)||new X(e)}static atEnd(e){return He(e,e,e.content.size,e.childCount,-1)||new X(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=cn[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in cn)throw new RangeError("Duplicate use of selection JSON ID "+e);return cn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return k.between(this.$anchor,this.$head).getBookmark()}}C.prototype.visible=!0;class is{constructor(e,t){this.$from=e,this.$to=t}}let wr=!1;function Mr(r){!wr&&!r.parent.inlineContent&&(wr=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+r.parent.type.name+")"))}class k extends C{constructor(e,t=e){Mr(e),Mr(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return C.near(n);let i=e.resolve(t.map(this.anchor));return new k(i.parent.inlineContent?i:n,n)}replace(e,t=x.empty){if(super.replace(e,t),t==x.empty){let n=this.$from.marksAcross(this.$to);n&&e.ensureMarks(n)}}eq(e){return e instanceof k&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new _t(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 k(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let i=e.resolve(t);return new this(i,n==t?i:e.resolve(n))}static between(e,t,n){let i=e.pos-t.pos;if((!n||i)&&(n=i>=0?1:-1),!t.parent.inlineContent){let s=C.findFrom(t,n,!0)||C.findFrom(t,-n,!0);if(s)t=s.$head;else return C.near(t,n)}return e.parent.inlineContent||(i==0?e=t:(e=(C.findFrom(e,-n,!0)||C.findFrom(e,n,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&S.isSelectable(l))return S.create(r,t-(i<0?l.nodeSize:0))}else{let a=He(r,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function Nr(r,e,t){let n=r.steps.length-1;if(n{o==null&&(o=f)}),r.setSelection(C.near(r.doc.resolve(o),t))}const Or=1,Tt=2,Tr=4;class ol extends rs{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|=Tt,this}ensureMarks(e){return M.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&Tt)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Tt,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||M.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(n==null&&(n=t),!e)return this.deleteRange(t,n);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=n==t?o.marks():o.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,i.text(e,s)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(C.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|=Tr,this}get scrolledIntoView(){return(this.updated&Tr)>0}}function Dr(r,e){return!e||!r?r:r.bind(e)}class lt{constructor(e,t,n){this.name=e,this.init=Dr(t.init,n),this.apply=Dr(t.apply,n)}}const ll=[new lt("doc",{init(r){return r.doc||r.schema.topNodeType.createAndFill()},apply(r){return r.doc}}),new lt("selection",{init(r,e){return r.selection||C.atStart(e.doc)},apply(r){return r.selection}}),new lt("storedMarks",{init(r){return r.storedMarks||null},apply(r,e,t,n){return n.selection.$cursor?r.storedMarks:null}}),new lt("scrollToSelection",{init(){return 0},apply(r,e){return r.scrolledIntoView?e+1:e}})];class fn{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=ll.slice(),t&&t.forEach(n=>{if(this.pluginsByKey[n.key])throw new RangeError("Adding different instances of a keyed plugin ("+n.key+")");this.plugins.push(n),this.pluginsByKey[n.key]=n,n.spec.state&&this.fields.push(new lt(n.key,n.spec.state,n))})}}class at{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 n=0;nn.toJSON())),e&&typeof e=="object")for(let n in e){if(n=="doc"||n=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[n],s=i.spec.state;s&&s.toJSON&&(t[n]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new fn(e.schema,e.plugins),s=new at(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=ie.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=C.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let l in n){let a=n[l],c=a.spec.state;if(a.key==o.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=c.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}}function ss(r,e,t){for(let n in r){let i=r[n];i instanceof Function?i=i.bind(e):n=="handleDOMEvents"&&(i=ss(i,e,{})),t[n]=i}return t}class Oe{constructor(e){this.spec=e,this.props={},e.props&&ss(e.props,this,this.props),this.key=e.key?e.key.key:ls("plugin")}getState(e){return e[this.key]}}const hn=Object.create(null);function ls(r){return r in hn?r+"$"+ ++hn[r]:(hn[r]=0,r+"$")}class Te{constructor(e="key"){this.key=ls(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const as=(r,e)=>r.selection.empty?!1:(e&&e(r.tr.deleteSelection().scrollIntoView()),!0);function cs(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("backward",r):t.parentOffset>0)?null:t}const al=(r,e,t)=>{let n=cs(r,t);if(!n)return!1;let i=jn(n);if(!i){let o=n.blockRange(),l=o&&Gt(o);return l==null?!1:(e&&e(r.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(hs(r,i,e,-1))return!0;if(n.parent.content.size==0&&(Ze(s,"end")||S.isSelectable(s)))for(let o=n.depth;;o--){let l=Yt(r.doc,n.before(o),n.after(o),x.empty);if(l&&l.slice.size1)break}return s.isAtom&&i.depth==n.depth-1?(e&&e(r.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1},jf=(r,e,t)=>{let n=cs(r,t);if(!n)return!1;let i=jn(n);return i?cl(r,i,e):!1};function cl(r,e,t){let n=e.nodeBefore,i=n,s=e.pos-1;for(;!i.isTextblock;s--){if(i.type.spec.isolating)return!1;let f=i.lastChild;if(!f)return!1;i=f}let o=e.nodeAfter,l=o,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let f=l.firstChild;if(!f)return!1;l=f}let c=Yt(r.doc,s,a,x.empty);if(!c||c.from!=s||c instanceof B&&c.slice.size>=a-s)return!1;if(t){let f=r.tr.step(c);f.setSelection(k.create(f.doc,s)),t(f.scrollIntoView())}return!0}function Ze(r,e,t=!1){for(let n=r;n;n=e=="start"?n.firstChild:n.lastChild){if(n.isTextblock)return!0;if(t&&n.childCount!=1)return!1}return!1}const fl=(r,e,t)=>{let{$head:n,empty:i}=r.selection,s=n;if(!i)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("backward",r):n.parentOffset>0)return!1;s=jn(n)}let o=s&&s.nodeBefore;return!o||!S.isSelectable(o)?!1:(e&&e(r.tr.setSelection(S.create(r.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function jn(r){if(!r.parent.type.spec.isolating)for(let e=r.depth-1;e>=0;e--){if(r.index(e)>0)return r.doc.resolve(r.before(e+1));if(r.node(e).type.spec.isolating)break}return null}function hl(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("forward",r):t.parentOffset{let n=hl(r,t);if(!n)return!1;let i=fs(n);if(!i)return!1;let s=i.nodeAfter;if(hs(r,i,e,1))return!0;if(n.parent.content.size==0&&(Ze(s,"start")||S.isSelectable(s))){let o=Yt(r.doc,n.before(),n.after(),x.empty);if(o&&o.slice.size{let{$head:n,empty:i}=r.selection,s=n;if(!i)return!1;if(n.parent.isTextblock){if(t?!t.endOfTextblock("forward",r):n.parentOffset=0;e--){let t=r.node(e);if(r.index(e)+1{let{$head:t,$anchor:n}=r.selection;return!t.parent.type.spec.code||!t.sameParent(n)?!1:(e&&e(r.tr.insertText(` `).scrollIntoView()),!0)};function Un(r){for(let e=0;e{let{$head:t,$anchor:n}=r.selection;if(!t.parent.type.spec.code||!t.sameParent(n))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=Un(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=r.tr.replaceWith(l,l,o.createAndFill());a.setSelection(C.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},gl=(r,e)=>{let t=r.selection,{$from:n,$to:i}=t;if(t instanceof X||n.parent.inlineContent||i.parent.inlineContent)return!1;let s=Un(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!n.parentOffset&&i.index(){let{$cursor:t}=r.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(ht(r.doc,s))return e&&e(r.tr.split(s).scrollIntoView()),!0}let n=t.blockRange(),i=n&&Gt(n);return i==null?!1:(e&&e(r.tr.lift(n,i).scrollIntoView()),!0)};function bl(r){return(e,t)=>{let{$from:n,$to:i}=e.selection;if(e.selection instanceof S&&e.selection.node.isBlock)return!n.parentOffset||!ht(e.doc,n.pos)?!1:(t&&t(e.tr.split(n.pos).scrollIntoView()),!0);if(!n.depth)return!1;let s=[],o,l,a=!1,c=!1;for(let u=n.depth;;u--)if(n.node(u).isBlock){a=n.end(u)==n.pos+(n.depth-u),c=n.start(u)==n.pos-(n.depth-u),l=Un(n.node(u-1).contentMatchAt(n.indexAfter(u-1))),s.unshift(a&&l?{type:l}:null),o=u;break}else{if(u==1)return!1;s.unshift(null)}let f=e.tr;(e.selection instanceof k||e.selection instanceof X)&&f.deleteSelection();let h=f.mapping.map(n.pos),d=ht(f.doc,h,s.length,s);if(d||(s[0]=l?{type:l}:null,d=ht(f.doc,h,s.length,s)),!d)return!1;if(f.split(h,s.length,s),!a&&c&&n.node(o).type!=l){let u=f.mapping.map(n.before(o)),p=f.doc.resolve(u);l&&n.node(o-1).canReplaceWith(p.index(),p.index()+1,l)&&f.setNodeMarkup(f.mapping.map(n.before(o)),l)}return t&&t(f.scrollIntoView()),!0}}const xl=bl(),Sl=(r,e)=>(e&&e(r.tr.setSelection(new X(r.doc))),!0);function Cl(r,e,t){let n=e.nodeBefore,i=e.nodeAfter,s=e.index();return!n||!i||!n.type.compatibleContent(i.type)?!1:!n.content.size&&e.parent.canReplace(s-1,s)?(t&&t(r.tr.delete(e.pos-n.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||Xt(r.doc,e.pos))?!1:(t&&t(r.tr.join(e.pos).scrollIntoView()),!0)}function hs(r,e,t,n){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&Cl(r,e,t))return!0;let c=!a&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(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=y.empty;for(let b=o.length-1;b>=0;b--)p=y.from(o[b].create(null,p));p=y.from(i.copy(p));let m=r.tr.step(new L(e.pos-1,u,e.pos,u,new x(p,1,0),o.length,!0)),g=m.doc.resolve(u+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&Xt(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let f=s.type.spec.isolating||n>0&&a?null:C.findFrom(e,1),h=f&&f.$from.blockRange(f.$to),d=h&&Gt(h);if(d!=null&&d>=e.depth)return t&&t(r.tr.lift(h,d).scrollIntoView()),!0;if(c&&Ze(s,"start",!0)&&Ze(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 b=y.empty;for(let O=p.length-1;O>=0;O--)b=y.from(p[O].copy(b));let N=r.tr.step(new L(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new x(b,p.length,0),0,!0));t(N.scrollIntoView())}return!0}}return!1}function ds(r){return function(e,t){let n=e.selection,i=r<0?n.$from:n.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(k.create(e.doc,r<0?i.start(s):i.end(s)))),!0):!1}}const kl=ds(-1),wl=ds(1);function Uf(r,e=null){return function(t,n){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Yi(o,r,e);return l?(n&&n(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function Gf(r,e=null){return function(t,n){let i=!1;for(let s=0;s{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(r,e)))if(a.type==r)i=!0;else{let f=t.doc.resolve(c),h=f.index();i=f.parent.canReplaceWith(h,h+1,r)}})}if(!i)return!1;if(n){let s=t.tr;for(let o=0;o{if(l)return!1;l=a.inlineContent&&a.type.allowsMarkType(t)}),l)return!0}return!1}function Xf(r,e=null,t){return function(n,i){let{empty:s,$cursor:o,ranges:l}=n.selection;if(s&&!o||!Ml(n.doc,l,r))return!1;if(i)if(o)r.isInSet(n.storedMarks||o.marks())?i(n.tr.removeStoredMark(r)):i(n.tr.addStoredMark(r.create(e)));else{let a,c=n.tr;a=!l.some(f=>n.doc.rangeHasMark(f.$from.pos,f.$to.pos,r));for(let f=0;f0&&(s=t[0].slice(o-l,o)+s,n=i)}return e.tr.insertText(s,n,i)}}const _f=(r,e)=>{let t=r.plugins;for(let n=0;n=0;a--)o.step(l.steps[a].invert(l.docs[a]));if(s.text){let a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,r.schema.text(s.text,a))}else o.delete(s.from,s.to);e(o)}return!0}}return!1};new De(/--$/,"—",{inCodeMark:!1});new De(/\.\.\.$/,"…",{inCodeMark:!1});new De(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“",{inCodeMark:!1});new De(/"$/,"”",{inCodeMark:!1});new De(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"‘",{inCodeMark:!1});new De(/'$/,"’",{inCodeMark:!1});function Zf(r,e,t=null,n){return new De(r,(i,s,o,l)=>{let a=t instanceof Function?t(s):t,c=i.tr.delete(o,l),f=c.doc.resolve(o),h=f.blockRange(),d=h&&Yi(h,e,a);if(!d)return null;c.wrap(h,d);let u=c.doc.resolve(o-1).nodeBefore;return u&&u.type==e&&Xt(c.doc,o-1)&&(!n||n(s,u))&&c.join(o-1),c})}function Qf(r,e,t=null){return new De(r,(n,i,s,o)=>{let l=n.doc.resolve(s),a=t instanceof Function?t(i):t;return l.node(-1).canReplaceWith(l.index(-1),l.indexAfter(-1),e)?n.tr.delete(s,o).setBlockType(s,s,e,a):null})}const Tl=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),Dl=typeof navigator<"u"&&/Win/.test(navigator.platform);function Al(r){let e=r.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let n,i,s,o;for(let l=0;l0){if(r.contentEditable=="false")return null;r=r.childNodes[e-1],e=_(r)}else if(r.parentNode&&!kt(r))e=P(r),r=r.parentNode;else return null}}function Bl(r,e){for(;;){if(r.nodeType==3&&e2),Y=et||(se?/Mac/.test(se.platform):!1),gs=se?/Win/.test(se.platform):!1,de=/Android \d/.test(Ae),wt=!!Rr&&"webkitFontSmoothing"in Rr.documentElement.style,Vl=wt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Ll(r){let e=r.defaultView&&r.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:r.documentElement.clientWidth,top:0,bottom:r.documentElement.clientHeight}}function ae(r,e){return typeof r=="number"?r:r[e]}function $l(r){let e=r.getBoundingClientRect(),t=e.width/r.offsetWidth||1,n=e.height/r.offsetHeight||1;return{left:e.left,right:e.left+r.clientWidth*t,top:e.top,bottom:e.top+r.clientHeight*n}}function Ir(r,e,t){let n=r.someProp("scrollThreshold")||0,i=r.someProp("scrollMargin")||5,s=r.dom.ownerDocument;for(let o=t||r.dom;o;){if(o.nodeType!=1){o=Qe(o);continue}let l=o,a=l==s.body,c=a?Ll(s):$l(l),f=0,h=0;if(e.topc.bottom-ae(n,"bottom")&&(h=e.bottom-e.top>c.bottom-c.top?e.top+ae(i,"top")-c.top:e.bottom-c.bottom+ae(i,"bottom")),e.leftc.right-ae(n,"right")&&(f=e.right-c.right+ae(i,"right")),f||h)if(a)s.defaultView.scrollBy(f,h);else{let u=l.scrollLeft,p=l.scrollTop;h&&(l.scrollTop+=h),f&&(l.scrollLeft+=f);let m=l.scrollLeft-u,g=l.scrollTop-p;e={left:e.left-m,top:e.top-g,right:e.right-m,bottom:e.bottom-g}}let d=a?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(d))break;o=d=="absolute"?o.offsetParent:Qe(o)}}function Wl(r){let e=r.dom.getBoundingClientRect(),t=Math.max(0,e.top),n,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){n=l,i=a.top;break}}return{refDOM:n,refTop:i,stack:ys(r.dom)}}function ys(r){let e=[],t=r.ownerDocument;for(let n=r;n&&(e.push({dom:n,top:n.scrollTop,left:n.scrollLeft}),r!=t);n=Qe(n));return e}function Jl({refDOM:r,refTop:e,stack:t}){let n=r?r.getBoundingClientRect().top:0;bs(t,n==0?0:n-e)}function bs(r,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&&!a&&p.left<=e.left&&p.right>=e.left&&(a=f,c={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=h+1)}}return!t&&a&&(t=a,i=c,n=0),t&&t.nodeType==3?Kl(t,i):!t||n&&t.nodeType==1?{node:r,offset:s}:xs(t,i)}function Kl(r,e){let t=r.nodeValue.length,n=document.createRange(),i;for(let s=0;s=(o.left+o.right)/2?1:0)};break}}return n.detach(),i||{node:r,offset:0}}function Yn(r,e){return r.left>=e.left-1&&r.left<=e.right+1&&r.top>=e.top-1&&r.top<=e.bottom+1}function Hl(r,e){let t=r.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return r.docView.posFromDOM(n,i,s)}function Ul(r,e,t,n){let i=-1;for(let s=e,o=!1;s!=r.dom;){let l=r.docView.nearestDesc(s,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!o&&a.left>n.left||a.top>n.top?i=l.posBefore:(!o&&a.right-1?i:r.docView.posFromDOM(e,t,-1)}function Ss(r,e,t){let n=r.childNodes.length;if(n&&t.tope.top&&i++}let c;wt&&i&&n.nodeType==1&&(c=n.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,n==r.dom&&i==n.childNodes.length-1&&n.lastChild.nodeType==1&&e.top>n.lastChild.getBoundingClientRect().bottom?l=r.state.doc.content.size:(i==0||n.nodeType!=1||n.childNodes[i-1].nodeName!="BR")&&(l=Ul(r,n,i,e))}l==null&&(l=jl(r,o,e));let a=r.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function zr(r){return r.top=0&&i==n.nodeValue.length?(a--,f=1):t<0?a--:c++,it(me(fe(n,a,c),f),f<0)}if(!r.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==_(n))){let a=n.childNodes[i-1];if(a.nodeType==1)return pn(a.getBoundingClientRect(),!1)}if(s==null&&i<_(n)){let a=n.childNodes[i];if(a.nodeType==1)return pn(a.getBoundingClientRect(),!0)}return pn(n.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==_(n))){let a=n.childNodes[i-1],c=a.nodeType==3?fe(a,_(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return it(me(c,1),!1)}if(s==null&&i<_(n)){let a=n.childNodes[i];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let c=a?a.nodeType==3?fe(a,0,o?0:1):a.nodeType==1?a:null:null;if(c)return it(me(c,-1),!0)}return it(me(n.nodeType==3?fe(n):n,-t),t>=0)}function it(r,e){if(r.width==0)return r;let t=e?r.left:r.right;return{top:r.top,bottom:r.bottom,left:t,right:t}}function pn(r,e){if(r.height==0)return r;let t=e?r.top:r.bottom;return{top:t,bottom:t,left:r.left,right:r.right}}function ks(r,e,t){let n=r.state,i=r.root.activeElement;n!=e&&r.updateState(e),i!=r.dom&&r.focus();try{return t()}finally{n!=e&&r.updateState(n),i!=r.dom&&i&&i.focus()}}function Yl(r,e,t){let n=e.selection,i=t=="up"?n.$from:n.$to;return ks(r,e,()=>{let{node:s}=r.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=r.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Cs(r,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=fe(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;cf.top+1&&(t=="up"?o.top-f.top>(f.bottom-o.top)*2:f.bottom-o.bottom>(o.bottom-f.top)*2))return!1}}return!0})}const _l=/[\u0590-\u08ac]/;function Zl(r,e,t){let{$head:n}=e.selection;if(!n.parent.isTextblock)return!1;let i=n.parentOffset,s=!i,o=i==n.parent.content.size,l=r.domSelection();return l?!_l.test(n.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:ks(r,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:f,anchorOffset:h}=r.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let u=n.depth?r.docView.domAfterPos(n.before()):r.dom,{focusNode:p,focusOffset:m}=r.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||a==p&&c==m;try{l.collapse(f,h),a&&(a!=f||c!=h)&&l.extend&&l.extend(a,c)}catch{}return d!=null&&(l.caretBidiLevel=d),g}):n.pos==n.start()||n.pos==n.end()}let Br=null,Pr=null,vr=!1;function Ql(r,e,t){return Br==e&&Pr==t?vr:(Br=e,Pr=t,vr=t=="up"||t=="down"?Yl(r,e,t):Zl(r,e,t))}const Q=0,Fr=1,Re=2,oe=3;class Mt{constructor(e,t,n,i){this.parent=e,this.children=t,this.dom=n,this.contentDOM=i,this.dirty=Q,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tP(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??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(n&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))n=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let n=t;n;n=n.parent)if(n==this)return t}posFromDOM(e,t,n){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;te||o instanceof Ms){i=e-s;break}s=l}if(i)return this.children[n].domFromPos(i-this.children[n].border,t);for(let s;n&&!(s=this.children[n-1]).size&&s instanceof ws&&s.side>=0;n--);if(t<=0){let s,o=!0;for(;s=n?this.children[n-1]:null,!(!s||s.dom.parentNode==this.contentDOM);n--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?P(s.dom)+1:0}}else{let s,o=!0;for(;s=n=f&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,f);e=o;for(let h=l;h>0;h--){let d=this.children[h-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=P(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let f=l+1;fp&&ot){let p=l;l=a,a=p}let u=document.createRange();u.setEnd(a.node,a.offset),u.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(u)}}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 n=0,i=0;i=n:en){let l=n+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==n||t==o?Re:Fr,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=oe:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Re:oe}n=o}this.dirty=Re}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Re:Fr;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==Q&&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 ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class ea extends Mt{constructor(e,t,n,i){super(e,[],t,null),this.textDOM=n,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}}class We extends Mt{constructor(e,t,n,i,s){super(e,[],n,i),this.mark=t,this.spec=s}static create(e,t,n,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,n);return(!o||!o.dom)&&(o=nt.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new We(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&oe||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=oe&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Q){let n=this.parent;for(;!n.node;)n=n.parent;n.dirty0&&(s=Rn(s,0,e,n));for(let l=0;l{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},n,i),f=c&&c.dom,h=c&&c.contentDOM;if(t.isText){if(!f)f=document.createTextNode(t.text);else if(f.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else f||({dom:f,contentDOM:h}=nt.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!h&&!t.isText&&f.nodeName!="BR"&&(f.hasAttribute("contenteditable")||(f.contentEditable="false"),t.type.spec.draggable&&(f.draggable=!0));let d=f;return f=Ts(f,n,t),c?a=new ta(e,t,n,i,f,h||null,d,c,s,o+1):t.isText?new Qt(e,t,n,i,f,d,s):new Me(e,t,n,i,f,h||null,d,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 n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>y.empty)}return e}matchesNode(e,t,n){return this.dirty==Q&&e.eq(this.node)&&Wt(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=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,a=new ra(this,o&&o.node,e);oa(this.node,this.innerDeco,(c,f,h)=>{c.spec.marks?a.syncToMarks(c.spec.marks,n,e,f):c.type.side>=0&&!h&&a.syncToMarks(f==this.node.childCount?M.none:this.node.child(f).marks,n,e,f),a.placeWidget(c,e,i)},(c,f,h,d)=>{a.syncToMarks(c.marks,n,e,d);let u;a.findNodeMatch(c,f,h,d)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(c,f,h,u,e)||a.updateNextNode(c,f,h,e,d,i)||a.addNode(c,f,h,e,i),i+=c.nodeSize}),a.syncToMarks([],n,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Re)&&(o&&this.protectLocalComposition(e,o),Ns(this.contentDOM,this.children,e),et&&la(this.dom))}localCompositionInfo(e,t){let{from:n,to:i}=e.state.selection;if(!(e.state.selection instanceof k)||nt+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=aa(this.node.content,o,n-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:n,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 ea(this,s,t,i);e.input.compositionNodes.push(o),this.children=Rn(this.children,n,n+i.length,e,o)}update(e,t,n,i){return this.dirty==oe||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,i),!0)}updateInner(e,t,n,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Q}updateOuterDeco(e){if(Wt(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,n=this.dom;this.dom=Os(this.dom,this.nodeDOM,En(this.outerDeco,this.node,t),En(e,this.node,t)),this.dom!=n&&(n.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.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Vr(r,e,t,n,i){Ts(n,e,r);let s=new Me(void 0,r,e,t,n,n,n,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class Qt extends Me{constructor(e,t,n,i,s,o,l){super(e,t,n,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,n,i){return this.dirty==oe||this.dirty!=Q&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Q||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=Q,!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,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,n){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new Qt(this.parent,i,this.outerDeco,this.innerDeco,s,s,n)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=oe)}get domAtom(){return!1}isText(e){return this.node.text==e}}class Ms extends Mt{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Q&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class ta extends Me{constructor(e,t,n,i,s,o,l,a,c,f){super(e,t,n,i,s,o,l,c,f),this.spec=a}update(e,t,n,i){if(this.dirty==oe)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,n);return s&&this.updateInner(e,t,n,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,i){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,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 Ns(r,e,t){let n=r.firstChild,i=!1;for(let s=0;s>1,l=Math.min(o,e.length);for(;s-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let f=We.create(this.top,e[o],t,n);this.top.children.splice(this.index,0,f),this.top=f,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,n,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,n))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(n){let c=t.children[n-1];if(c instanceof We)t=c,n=c.children.length;else{l=c,n--;break}}else{if(t==e)break e;n=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=r.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function sa(r,e){return r.type.side-e.type.side}function oa(r,e,t,n){let i=e.locals(r),s=0;if(i.length==0){for(let c=0;cs;)l.push(i[o++]);let p=s+d.nodeSize;if(d.isText){let g=p;o!g.inline):l.slice();n(d,m,e.forChild(s,d),u),s=p}}function la(r){if(r.nodeName=="UL"||r.nodeName=="OL"){let e=r.style.cssText;r.style.cssText=e+"; list-style: square !important",window.getComputedStyle(r).listStyle,r.style.cssText=e}}function aa(r,e,t,n){for(let i=0,s=0;i=t){if(s>=n&&a.slice(n-e.length-l,n-l)==e)return n-e.length;let c=l=0&&c+e.length+l>=t)return l+c;if(t==n&&a.length>=n+e.length-l&&a.slice(n-l,n-l+e.length)==e)return n}}return-1}function Rn(r,e,t,n,i){let s=[];for(let o=0,l=0;o=t||f<=e?s.push(a):(ct&&s.push(a.slice(t-c,a.size,n)))}return s}function _n(r,e=null){let t=r.domSelectionRange(),n=r.state.doc;if(!t.focusNode)return null;let i=r.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=r.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=n.resolve(o),a,c;if(Zt(t)){for(a=o;i&&!i.node;)i=i.parent;let h=i.node;if(i&&h.isAtom&&S.isSelectable(h)&&i.parent&&!(h.isInline&&Pl(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;c=new S(o==d?l:n.resolve(d))}}else{if(t instanceof r.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let h=o,d=o;for(let u=0;u{(t.anchorNode!=n||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",r.input.hideSelectionGuard),setTimeout(()=>{(!Ds(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})}function fa(r){let e=r.domSelection();if(!e)return;let t=r.cursorWrapper.dom,n=t.nodeName=="IMG";n?e.collapse(t.parentNode,P(t)+1):e.collapse(t,0),!n&&!r.state.selection.visible&&H&&we<=11&&(t.disabled=!0,t.disabled=!1)}function As(r,e){if(e instanceof S){let t=r.docView.descAt(e.from);t!=r.lastSelectedViewDesc&&(qr(r),t&&t.selectNode(),r.lastSelectedViewDesc=t)}else qr(r)}function qr(r){r.lastSelectedViewDesc&&(r.lastSelectedViewDesc.parent&&r.lastSelectedViewDesc.deselectNode(),r.lastSelectedViewDesc=void 0)}function Zn(r,e,t,n){return r.someProp("createSelectionBetween",i=>i(r,e,t))||k.between(e,t,n)}function Kr(r){return r.editable&&!r.hasFocus()?!1:Es(r)}function Es(r){let e=r.domSelectionRange();if(!e.anchorNode)return!1;try{return r.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(r.editable||r.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function ha(r){let e=r.docView.domFromPos(r.state.selection.anchor,0),t=r.domSelectionRange();return $e(e.node,e.offset,t.anchorNode,t.anchorOffset)}function In(r,e){let{$anchor:t,$head:n}=r.selection,i=e>0?t.max(n):t.min(n),s=i.parent.inlineContent?i.depth?r.doc.resolve(e>0?i.after():i.before()):null:i;return s&&C.findFrom(s,e)}function ge(r,e){return r.dispatch(r.state.tr.setSelection(e).scrollIntoView()),!0}function Hr(r,e,t){let n=r.state.selection;if(n instanceof k)if(t.indexOf("s")>-1){let{$head:i}=n,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=r.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return ge(r,new k(n.$anchor,o))}else if(n.empty){if(r.endOfTextblock(e>0?"forward":"backward")){let i=In(r.state,e);return i&&i instanceof S?ge(r,i):!1}else if(!(Y&&t.indexOf("m")>-1)){let i=n.$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=r.docView.descAt(l))&&!o.contentDOM?S.isSelectable(s)?ge(r,new S(e<0?r.state.doc.resolve(i.pos-s.nodeSize):i)):wt?ge(r,new k(r.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(n instanceof S&&n.node.isInline)return ge(r,new k(e>0?n.$to:n.$from));{let i=In(r.state,e);return i?ge(r,i):!1}}}function Jt(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function ut(r,e){let t=r.pmViewDesc;return t&&t.size==0&&(e<0||r.nextSibling||r.nodeName!="BR")}function Ke(r,e){return e<0?da(r):ua(r)}function da(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i,s,o=!1;for(Z&&t.nodeType==1&&n0){if(t.nodeType!=1)break;{let l=t.childNodes[n-1];if(ut(l,-1))i=t,s=--n;else if(l.nodeType==3)t=l,n=t.nodeValue.length;else break}}else{if(Rs(t))break;{let l=t.previousSibling;for(;l&&ut(l,-1);)i=t.parentNode,s=P(l),l=l.previousSibling;if(l)t=l,n=Jt(t);else{if(t=t.parentNode,t==r.dom)break;n=0}}}o?zn(r,t,n):i&&zn(r,i,s)}function ua(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i=Jt(t),s,o;for(;;)if(n{r.state==i&&ue(r)},50)}function jr(r,e){let t=r.state.doc.resolve(e);if(!(z||gs)&&t.parent.inlineContent){let i=r.coordsAtPos(e);if(e>t.start()){let s=r.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(r.dom).direction=="rtl"?"rtl":"ltr"}function Ur(r,e,t){let n=r.state.selection;if(n instanceof k&&!n.empty||t.indexOf("s")>-1||Y&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=n;if(!i.parent.inlineContent||r.endOfTextblock(e<0?"up":"down")){let o=In(r.state,e);if(o&&o instanceof S)return ge(r,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=n instanceof X?C.near(o,e):C.findFrom(o,e);return l?ge(r,l):!1}return!1}function Gr(r,e){if(!(r.state.selection instanceof k))return!0;let{$head:t,$anchor:n,empty:i}=r.state.selection;if(!t.sameParent(n))return!0;if(!i)return!1;if(r.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=r.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),r.dispatch(o),!0}return!1}function Xr(r,e,t){r.domObserver.stop(),e.contentEditable=t,r.domObserver.start()}function ga(r){if(!F||r.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=r.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let n=e.firstChild;Xr(r,n,"true"),setTimeout(()=>Xr(r,n,"false"),20)}return!1}function ya(r){let e="";return r.ctrlKey&&(e+="c"),r.metaKey&&(e+="m"),r.altKey&&(e+="a"),r.shiftKey&&(e+="s"),e}function ba(r,e){let t=e.keyCode,n=ya(e);if(t==8||Y&&t==72&&n=="c")return Gr(r,-1)||Ke(r,-1);if(t==46&&!e.shiftKey||Y&&t==68&&n=="c")return Gr(r,1)||Ke(r,1);if(t==13||t==27)return!0;if(t==37||Y&&t==66&&n=="c"){let i=t==37?jr(r,r.state.selection.from)=="ltr"?-1:1:-1;return Hr(r,i,n)||Ke(r,i)}else if(t==39||Y&&t==70&&n=="c"){let i=t==39?jr(r,r.state.selection.from)=="ltr"?1:-1:1;return Hr(r,i,n)||Ke(r,i)}else{if(t==38||Y&&t==80&&n=="c")return Ur(r,-1,n)||Ke(r,-1);if(t==40||Y&&t==78&&n=="c")return ga(r)||Ur(r,1,n)||Ke(r,1);if(n==(Y?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Qn(r,e){r.someProp("transformCopied",u=>{e=u(e,r)});let t=[],{content:n,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&n.childCount==1&&n.firstChild.childCount==1;){i--,s--;let u=n.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),n=u.content}let o=r.someProp("clipboardSerializer")||nt.fromSchema(r.state.schema),l=Fs(),a=l.createElement("div");a.appendChild(o.serializeFragment(n,{document:l}));let c=a.firstChild,f,h=0;for(;c&&c.nodeType==1&&(f=vs[c.nodeName.toLowerCase()]);){for(let u=f.length-1;u>=0;u--){let p=l.createElement(f[u]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),h++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${s}${h?` -${h}`:""} ${JSON.stringify(t)}`);let d=r.someProp("clipboardTextSerializer",u=>u(e,r))||e.content.textBetween(0,e.content.size,` `);return{dom:a,text:d,slice:e}}function Is(r,e,t,n,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=!!e&&(n||s||!t);if(a){if(r.someProp("transformPastedText",d=>{e=d(e,s||n,r)}),s)return l=new x(y.from(r.state.schema.text(e.replace(/\r\n?/g,` `))),0,0),r.someProp("transformPasted",d=>{l=d(l,r,!0)}),l;let h=r.someProp("clipboardTextParser",d=>d(e,i,n,r));if(h)l=h;else{let d=i.marks(),{schema:u}=r.state,p=nt.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,d)))})}}else r.someProp("transformPastedHTML",h=>{t=h(t,r)}),o=ka(t),wt&&wa(o);let c=o&&o.querySelector("[data-pm-slice]"),f=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(f&&f[3])for(let h=+f[3];h>0;h--){let d=o.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;o=d}if(l||(l=(r.someProp("clipboardParser")||r.someProp("domParser")||mt.fromSchema(r.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||f),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!xa.test(d.parentNode.nodeName)?{ignore:!0}:null}})),f)l=Ma(Yr(l,+f[1],+f[2]),f[4]);else if(l=x.maxOpen(Sa(l.content,i),!0),l.openStart||l.openEnd){let h=0,d=0;for(let u=l.content.firstChild;h{l=h(l,r,a)}),l}const xa=/^(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 Sa(r,e){if(r.childCount<2)return r;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(r.forEach(l=>{if(!o)return;let a=i.findWrapping(l.type),c;if(!a)return o=null;if(c=o.length&&s.length&&Bs(a,s,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=Ps(o[o.length-1],s.length));let f=zs(l,a);o.push(f),i=i.matchType(f.type),s=a}}),o)return y.from(o)}return r}function zs(r,e,t=0){for(let n=e.length-1;n>=t;n--)r=e[n].create(null,y.from(r));return r}function Bs(r,e,t,n,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))),r.replaceChild(e<0?0:r.childCount-1,o.copy(l))}function Yr(r,e,t){return et})),gn.createHTML(r)):r}function ka(r){let e=/^(\s*]*>)*/.exec(r);e&&(r=r.slice(e[0].length));let t=Fs().createElement("div"),n=/<([a-z][^>\s]+)/i.exec(r),i;if((i=n&&vs[n[1].toLowerCase()])&&(r=i.map(s=>"<"+s+">").join("")+r+i.map(s=>"").reverse().join("")),t.innerHTML=Ca(r),i)for(let s=0;s=0;l-=2){let a=t.nodes[n[l]];if(!a||a.hasRequiredAttrs())break;i=y.from(a.create(n[l+1],i)),s++,o++}return new x(i,s,o)}const J={},q={},Na={touchstart:!0,touchmove:!0};class Oa{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Ta(r){for(let e in J){let t=J[e];r.dom.addEventListener(e,r.input.eventHandlers[e]=n=>{Aa(r,n)&&!er(r,n)&&(r.editable||!(n.type in q))&&t(r,n)},Na[e]?{passive:!0}:void 0)}F&&r.dom.addEventListener("input",()=>null),Pn(r)}function ke(r,e){r.input.lastSelectionOrigin=e,r.input.lastSelectionTime=Date.now()}function Da(r){r.domObserver.stop();for(let e in r.input.eventHandlers)r.dom.removeEventListener(e,r.input.eventHandlers[e]);clearTimeout(r.input.composingTimeout),clearTimeout(r.input.lastIOSEnterFallbackTimeout)}function Pn(r){r.someProp("handleDOMEvents",e=>{for(let t in e)r.input.eventHandlers[t]||r.dom.addEventListener(t,r.input.eventHandlers[t]=n=>er(r,n))})}function er(r,e){return r.someProp("handleDOMEvents",t=>{let n=t[e.type];return n?n(r,e)||e.defaultPrevented:!1})}function Aa(r,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=r.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Ea(r,e){!er(r,e)&&J[e.type]&&(r.editable||!(e.type in q))&&J[e.type](r,e)}q.keydown=(r,e)=>{let t=e;if(r.input.shiftKey=t.keyCode==16||t.shiftKey,!Ls(r,t)&&(r.input.lastKeyCode=t.keyCode,r.input.lastKeyCodeTime=Date.now(),!(de&&z&&t.keyCode==13)))if(t.keyCode!=229&&r.domObserver.forceFlush(),et&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let n=Date.now();r.input.lastIOSEnter=n,r.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{r.input.lastIOSEnter==n&&(r.someProp("handleKeyDown",i=>i(r,Ee(13,"Enter"))),r.input.lastIOSEnter=0)},200)}else r.someProp("handleKeyDown",n=>n(r,t))||ba(r,t)?t.preventDefault():ke(r,"key")};q.keyup=(r,e)=>{e.keyCode==16&&(r.input.shiftKey=!1)};q.keypress=(r,e)=>{let t=e;if(Ls(r,t)||!t.charCode||t.ctrlKey&&!t.altKey||Y&&t.metaKey)return;if(r.someProp("handleKeyPress",i=>i(r,t))){t.preventDefault();return}let n=r.state.selection;if(!(n instanceof k)||!n.$from.sameParent(n.$to)){let i=String.fromCharCode(t.charCode),s=()=>r.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!r.someProp("handleTextInput",o=>o(r,n.$from.pos,n.$to.pos,i,s))&&r.dispatch(s()),t.preventDefault()}};function en(r){return{left:r.clientX,top:r.clientY}}function Ra(r,e){let t=e.x-r.clientX,n=e.y-r.clientY;return t*t+n*n<100}function tr(r,e,t,n,i){if(n==-1)return!1;let s=r.state.doc.resolve(n);for(let o=s.depth+1;o>0;o--)if(r.someProp(e,l=>o>s.depth?l(r,t,s.nodeAfter,s.before(o),i,!0):l(r,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function Ye(r,e,t){if(r.focused||r.focus(),r.state.selection.eq(e))return;let n=r.state.tr.setSelection(e);n.setMeta("pointer",!0),r.dispatch(n)}function Ia(r,e){if(e==-1)return!1;let t=r.state.doc.resolve(e),n=t.nodeAfter;return n&&n.isAtom&&S.isSelectable(n)?(Ye(r,new S(t)),!0):!1}function za(r,e){if(e==-1)return!1;let t=r.state.selection,n,i;t instanceof S&&(n=t.node);let s=r.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(S.isSelectable(l)){n&&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?(Ye(r,S.create(r.state.doc,i)),!0):!1}function Ba(r,e,t,n,i){return tr(r,"handleClickOn",e,t,n)||r.someProp("handleClick",s=>s(r,e,n))||(i?za(r,t):Ia(r,t))}function Pa(r,e,t,n){return tr(r,"handleDoubleClickOn",e,t,n)||r.someProp("handleDoubleClick",i=>i(r,e,n))}function va(r,e,t,n){return tr(r,"handleTripleClickOn",e,t,n)||r.someProp("handleTripleClick",i=>i(r,e,n))||Fa(r,t,n)}function Fa(r,e,t){if(t.button!=0)return!1;let n=r.state.doc;if(e==-1)return n.inlineContent?(Ye(r,k.create(n,0,n.content.size)),!0):!1;let i=n.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)Ye(r,k.create(n,l+1,l+1+o.content.size));else if(S.isSelectable(o))Ye(r,S.create(n,l));else continue;return!0}}function nr(r){return qt(r)}const Vs=Y?"metaKey":"ctrlKey";J.mousedown=(r,e)=>{let t=e;r.input.shiftKey=t.shiftKey;let n=nr(r),i=Date.now(),s="singleClick";i-r.input.lastClick.time<500&&Ra(t,r.input.lastClick)&&!t[Vs]&&r.input.lastClick.button==t.button&&(r.input.lastClick.type=="singleClick"?s="doubleClick":r.input.lastClick.type=="doubleClick"&&(s="tripleClick")),r.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s,button:t.button};let o=r.posAtCoords(en(t));o&&(s=="singleClick"?(r.input.mouseDown&&r.input.mouseDown.done(),r.input.mouseDown=new Va(r,o,t,!!n)):(s=="doubleClick"?Pa:va)(r,o.pos,o.inside,t)?t.preventDefault():ke(r,"pointer"))};class Va{constructor(e,t,n,i){this.view=e,this.pos=t,this.event=n,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[Vs],this.allowDefault=n.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let f=e.state.doc.resolve(t.pos);s=f.parent,o=f.depth?f.before():0}const l=i?null:n.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.nodeDOM.nodeType==1?a.nodeDOM:null;let{selection:c}=e.state;(n.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof S&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Z&&!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)),ke(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(()=>ue(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(en(e))),this.updateAllowDefault(e),this.allowDefault||!t?ke(this.view,"pointer"):Ba(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||F&&this.mightDrag&&!this.mightDrag.node.isAtom||z&&!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)?(Ye(this.view,C.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):ke(this.view,"pointer")}move(e){this.updateAllowDefault(e),ke(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)}}J.touchstart=r=>{r.input.lastTouch=Date.now(),nr(r),ke(r,"pointer")};J.touchmove=r=>{r.input.lastTouch=Date.now(),ke(r,"pointer")};J.contextmenu=r=>nr(r);function Ls(r,e){return r.composing?!0:F&&Math.abs(e.timeStamp-r.input.compositionEndedAt)<500?(r.input.compositionEndedAt=-2e8,!0):!1}const La=de?5e3:-1;q.compositionstart=q.compositionupdate=r=>{if(!r.composing){r.domObserver.flush();let{state:e}=r,t=e.selection.$to;if(e.selection instanceof k&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)||z&&gs&&$a(r)))r.markCursor=r.state.storedMarks||t.marks(),qt(r,!0),r.markCursor=null;else if(qt(r,!e.selection.empty),Z&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let n=r.domSelectionRange();for(let i=n.focusNode,s=n.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=r.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}r.input.composing=!0}$s(r,La)};function $a(r){let{focusNode:e,focusOffset:t}=r.domSelectionRange();if(!e||e.nodeType!=1||t>=e.childNodes.length)return!1;let n=e.childNodes[t];return n.nodeType==1&&n.contentEditable=="false"}q.compositionend=(r,e)=>{r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=e.timeStamp,r.input.compositionPendingChanges=r.domObserver.pendingRecords().length?r.input.compositionID:0,r.input.compositionNode=null,r.input.badSafariComposition?r.domObserver.forceFlush():r.input.compositionPendingChanges&&Promise.resolve().then(()=>r.domObserver.flush()),r.input.compositionID++,$s(r,20))};function $s(r,e){clearTimeout(r.input.composingTimeout),e>-1&&(r.input.composingTimeout=setTimeout(()=>qt(r),e))}function Ws(r){for(r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=Ja());r.input.compositionNodes.length>0;)r.input.compositionNodes.pop().markParentsDirty()}function Wa(r){let e=r.domSelectionRange();if(!e.focusNode)return null;let t=zl(e.focusNode,e.focusOffset),n=Bl(e.focusNode,e.focusOffset);if(t&&n&&t!=n){let i=n.pmViewDesc,s=r.domObserver.lastChangedTextNode;if(t==s||n==s)return s;if(!i||!i.isText(n.nodeValue))return n;if(r.input.compositionNode==n){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return n}}return t||n}function Ja(){let r=document.createEvent("Event");return r.initEvent("event",!0,!0),r.timeStamp}function qt(r,e=!1){if(!(de&&r.domObserver.flushingSoon>=0)){if(r.domObserver.forceFlush(),Ws(r),e||r.docView&&r.docView.dirty){let t=_n(r),n=r.state.selection;return t&&!t.eq(n)?r.dispatch(r.state.tr.setSelection(t)):(r.markCursor||e)&&!n.$from.node(n.$from.sharedDepth(n.to)).inlineContent?r.dispatch(r.state.tr.deleteSelection()):r.updateState(r.state),!0}return!1}}function qa(r,e){if(!r.dom.parentNode)return;let t=r.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let n=getSelection(),i=document.createRange();i.selectNodeContents(e),r.dom.blur(),n.removeAllRanges(),n.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),r.focus()},50)}const xt=H&&we<15||et&&Vl<604;J.copy=q.cut=(r,e)=>{let t=e,n=r.state.selection,i=t.type=="cut";if(n.empty)return;let s=xt?null:t.clipboardData,o=n.content(),{dom:l,text:a}=Qn(r,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):qa(r,l),i&&r.dispatch(r.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Ka(r){return r.openStart==0&&r.openEnd==0&&r.content.childCount==1?r.content.firstChild:null}function Ha(r,e){if(!r.dom.parentNode)return;let t=r.input.shiftKey||r.state.selection.$from.parent.type.spec.code,n=r.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(n.contentEditable="true"),n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus();let i=r.input.shiftKey&&r.input.lastKeyCode!=45;setTimeout(()=>{r.focus(),n.parentNode&&n.parentNode.removeChild(n),t?St(r,n.value,null,i,e):St(r,n.textContent,n.innerHTML,i,e)},50)}function St(r,e,t,n,i){let s=Is(r,e,t,n,r.state.selection.$from);if(r.someProp("handlePaste",a=>a(r,i,s||x.empty)))return!0;if(!s)return!1;let o=Ka(s),l=o?r.state.tr.replaceSelectionWith(o,n):r.state.tr.replaceSelection(s);return r.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Js(r){let e=r.getData("text/plain")||r.getData("Text");if(e)return e;let t=r.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}q.paste=(r,e)=>{let t=e;if(r.composing&&!de)return;let n=xt?null:t.clipboardData,i=r.input.shiftKey&&r.input.lastKeyCode!=45;n&&St(r,Js(n),n.getData("text/html"),i,t)?t.preventDefault():Ha(r,t)};class qs{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const ja=Y?"altKey":"ctrlKey";function Ks(r,e){let t=r.someProp("dragCopies",n=>!n(e));return t??!e[ja]}J.dragstart=(r,e)=>{let t=e,n=r.input.mouseDown;if(n&&n.done(),!t.dataTransfer)return;let i=r.state.selection,s=i.empty?null:r.posAtCoords(en(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof S?i.to-1:i.to))){if(n&&n.mightDrag)o=S.create(r.state.doc,n.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let h=r.docView.nearestDesc(t.target,!0);h&&h.node.type.spec.draggable&&h!=r.docView&&(o=S.create(r.state.doc,h.posBefore))}}let l=(o||r.state.selection).content(),{dom:a,text:c,slice:f}=Qn(r,l);(!t.dataTransfer.files.length||!z||ms>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(xt?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",xt||t.dataTransfer.setData("text/plain",c),r.dragging=new qs(f,Ks(r,t),o)};J.dragend=r=>{let e=r.dragging;window.setTimeout(()=>{r.dragging==e&&(r.dragging=null)},50)};q.dragover=q.dragenter=(r,e)=>e.preventDefault();q.drop=(r,e)=>{try{Ua(r,e,r.dragging)}finally{r.dragging=null}};function Ua(r,e,t){if(!e.dataTransfer)return;let n=r.posAtCoords(en(e));if(!n)return;let i=r.state.doc.resolve(n.pos),s=t&&t.slice;s?r.someProp("transformPasted",u=>{s=u(s,r,!1)}):s=Is(r,Js(e.dataTransfer),xt?null:e.dataTransfer.getData("text/html"),!1,i);let o=!!(t&&Ks(r,e));if(r.someProp("handleDrop",u=>u(r,e,s||x.empty,o))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?Zo(r.state.doc,i.pos,s):i.pos;l==null&&(l=i.pos);let a=r.state.tr;if(o){let{node:u}=t;u?u.replace(a):a.deleteSelection()}let c=a.mapping.map(l),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,h=a.doc;if(f?a.replaceRangeWith(c,c,s.content.firstChild):a.replaceRange(c,c,s),a.doc.eq(h))return;let d=a.doc.resolve(c);if(f&&S.isSelectable(s.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new S(d));else{let u=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((p,m,g,b)=>u=b),a.setSelection(Zn(r,d,a.doc.resolve(u)))}r.focus(),r.dispatch(a.setMeta("uiEvent","drop"))}J.focus=r=>{r.input.lastFocus=Date.now(),r.focused||(r.domObserver.stop(),r.dom.classList.add("ProseMirror-focused"),r.domObserver.start(),r.focused=!0,setTimeout(()=>{r.docView&&r.hasFocus()&&!r.domObserver.currentSelection.eq(r.domSelectionRange())&&ue(r)},20))};J.blur=(r,e)=>{let t=e;r.focused&&(r.domObserver.stop(),r.dom.classList.remove("ProseMirror-focused"),r.domObserver.start(),t.relatedTarget&&r.dom.contains(t.relatedTarget)&&r.domObserver.currentSelection.clear(),r.focused=!1)};J.beforeinput=(r,e)=>{if(z&&de&&e.inputType=="deleteContentBackward"){r.domObserver.flushSoon();let{domChangeCount:n}=r.input;setTimeout(()=>{if(r.input.domChangeCount!=n||(r.dom.blur(),r.focus(),r.someProp("handleKeyDown",s=>s(r,Ee(8,"Backspace")))))return;let{$cursor:i}=r.state.selection;i&&i.pos>0&&r.dispatch(r.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let r in q)J[r]=q[r];function Ct(r,e){if(r==e)return!0;for(let t in r)if(r[t]!==e[t])return!1;for(let t in e)if(!(t in r))return!1;return!0}class Kt{constructor(e,t){this.toDOM=e,this.spec=t||Pe,this.side=this.spec.side||0}map(e,t,n,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new v(s-n,s-n,this)}valid(){return!0}eq(e){return this==e||e instanceof Kt&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Ct(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Ne{constructor(e,t){this.attrs=e,this.spec=t||Pe}map(e,t,n,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-n,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-n;return s>=o?null:new v(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&n.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,n,i+l,s)}}map(e,t,n){return this==V||e.maps.length==0?this:this.mapInner(e,t,0,0,n||Pe)}mapInner(e,t,n,i,s){let o;for(let l=0;l{let c=a+n,f;if(f=js(t,l,c)){for(i||(i=this.children.slice());sl&&h.to=e){this.children[l]==e&&(n=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&a.type instanceof Ne){let c=Math.max(s,a.from)-s,f=Math.min(o,a.to)-s;ci.map(e,t,Pe));return be.from(n)}forChild(e,t){if(t.isLeaf)return D.empty;let n=[];for(let i=0;it instanceof D)?e:e.reduce((t,n)=>t.concat(n instanceof D?n:n.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-p-(u-d);for(let b=0;bN+f-h)continue;let O=l[b]+f-h;u>=O?l[b+1]=d<=O?-2:-1:d>=f&&g&&(l[b]+=g,l[b+1]+=g)}h+=g}),f=t.maps[c].map(f,-1)}let a=!1;for(let c=0;c=n.content.size){a=!0;continue}let d=t.map(r[c+1]+s,-1),u=d-i,{index:p,offset:m}=n.content.findIndex(h),g=n.maybeChild(p);if(g&&m==h&&m+g.nodeSize==u){let b=l[c+2].mapInner(t,g,f+1,r[c]+s+1,o);b!=V?(l[c]=h,l[c+1]=u,l[c+2]=b):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=Xa(l,r,e,t,i,s,o),f=Ht(c,n,0,o);e=f.local;for(let h=0;ht&&o.to{let c=js(r,l,a+t);if(c){s=!0;let f=Ht(c,l,t+a+1,n);f!=V&&i.push(a,a+l.nodeSize,f)}});let o=Hs(s?Us(r):r,-t).sort(ve);for(let l=0;l0;)e++;r.splice(e,0,t)}function yn(r){let e=[];return r.someProp("decorations",t=>{let n=t(r.state);n&&n!=V&&e.push(n)}),r.cursorWrapper&&e.push(D.create(r.state.doc,[r.cursorWrapper.deco])),be.from(e)}const Ya={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},_a=H&&we<=11;class Za{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}}class Qa{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Za,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(n=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():F&&e.composing&&n.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),_a&&(this.onCharData=n=>{this.queue.push({target:n.target,type:"characterData",oldValue:n.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,Ya)),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(Kr(this.view)){if(this.suppressingSelectionUpdates)return ue(this.view);if(H&&we<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&$e(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,n;for(let s=e.focusNode;s;s=Qe(s))t.add(s);for(let s=e.anchorNode;s;s=Qe(s))if(t.has(s)){n=s;break}let i=n&&this.view.docView.nearestDesc(n);if(i&&i.ignoreMutation({type:"selection",target:n.nodeType==3?n.parentNode:n}))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 n=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Kr(e)&&!this.ignoreSelectionChange(n),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let f=0;fh.nodeName=="BR");if(f.length==2){let[h,d]=f;h.parentNode&&h.parentNode.parentNode==d.parentNode?d.remove():h.remove()}else{let{focusNode:h}=this.currentSelection;for(let d of f){let u=d.parentNode;u&&u.nodeName=="LI"&&(!h||nc(e,h)!=u)&&d.remove()}}}else if((z||F)&&a.some(f=>f.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let f of a)if(f.nodeName=="BR"&&f.parentNode){let h=f.nextSibling;h&&h.nodeType==1&&h.contentEditable=="false"&&f.parentNode.removeChild(f)}}let c=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),ec(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,rc(e,a)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||ue(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(n==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!n||n.ignoreMutation(e))return null;if(e.type=="childList"){for(let f=0;fi;g--){let b=n.childNodes[g-1],N=b.pmViewDesc;if(b.nodeName=="BR"&&!N){s=g;break}if(!N||N.size)break}let h=r.state.doc,d=r.someProp("domParser")||mt.fromSchema(r.state.schema),u=h.resolve(o),p=null,m=d.parse(n,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:sc,context:u});if(c&&c[0].pos!=null){let g=c[0].pos,b=c[1]&&c[1].pos;b==null&&(b=g),p={anchor:g+o,head:b+o}}return{doc:m,sel:p,from:o,to:l}}function sc(r){let e=r.pmViewDesc;if(e)return e.parseRule();if(r.nodeName=="BR"&&r.parentNode){if(F&&/^(ul|ol)$/i.test(r.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(r.parentNode.lastChild==r||F&&/^(tr|table)$/i.test(r.parentNode.nodeName))return{ignore:!0}}else if(r.nodeName=="IMG"&&r.getAttribute("mark-placeholder"))return{ignore:!0};return null}const oc=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function lc(r,e,t,n,i){let s=r.input.compositionPendingChanges||(r.composing?r.input.compositionID:0);if(r.input.compositionPendingChanges=0,e<0){let w=r.input.lastSelectionTime>Date.now()-50?r.input.lastSelectionOrigin:null,A=_n(r,w);if(A&&!r.state.selection.eq(A)){if(z&&de&&r.input.lastKeyCode===13&&Date.now()-100lo(r,Ee(13,"Enter"))))return;let K=r.state.tr.setSelection(A);w=="pointer"?K.setMeta("pointer",!0):w=="key"&&K.scrollIntoView(),s&&K.setMeta("composition",s),r.dispatch(K)}return}let o=r.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=r.state.doc.resolve(t).after(l+1);let a=r.state.selection,c=ic(r,e,t),f=r.state.doc,h=f.slice(c.from,c.to),d,u;r.input.lastKeyCode===8&&Date.now()-100Date.now()-225||de)&&i.some(w=>w.nodeType==1&&!oc.test(w.nodeName))&&(!p||p.endA>=p.endB)&&r.someProp("handleKeyDown",w=>w(r,Ee(13,"Enter")))){r.input.lastIOSEnter=0;return}if(!p)if(n&&a instanceof k&&!a.empty&&a.$head.sameParent(a.$anchor)&&!r.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))p={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let w=ni(r,r.state.doc,c.sel);if(w&&!w.eq(r.state.selection)){let A=r.state.tr.setSelection(w);s&&A.setMeta("composition",s),r.dispatch(A)}}return}r.state.selection.fromr.state.selection.from&&p.start<=r.state.selection.from+2&&r.state.selection.from>=c.from?p.start=r.state.selection.from:p.endA=r.state.selection.to-2&&r.state.selection.to<=c.to&&(p.endB+=r.state.selection.to-p.endA,p.endA=r.state.selection.to)),H&&we<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>c.from&&c.doc.textBetween(p.start-c.from-1,p.start-c.from+1)=="  "&&(p.start--,p.endA--,p.endB--);let m=c.doc.resolveNoCache(p.start-c.from),g=c.doc.resolveNoCache(p.endB-c.from),b=f.resolve(p.start),N=m.sameParent(g)&&m.parent.inlineContent&&b.end()>=p.endA;if((et&&r.input.lastIOSEnter>Date.now()-225&&(!N||i.some(w=>w.nodeName=="DIV"||w.nodeName=="P"))||!N&&m.posw(r,Ee(13,"Enter")))){r.input.lastIOSEnter=0;return}if(r.state.selection.anchor>p.start&&cc(f,p.start,p.endA,m,g)&&r.someProp("handleKeyDown",w=>w(r,Ee(8,"Backspace")))){de&&z&&r.domObserver.suppressSelectionUpdates();return}z&&p.endB==p.start&&(r.input.lastChromeDelete=Date.now()),de&&!N&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==p.endA&&(p.endB-=2,g=c.doc.resolveNoCache(p.endB-c.from),setTimeout(()=>{r.someProp("handleKeyDown",function(w){return w(r,Ee(13,"Enter"))})},20));let O=p.start,W=p.endA,j=w=>{let A=w||r.state.tr.replace(O,W,c.doc.slice(p.start-c.from,p.endB-c.from));if(c.sel){let K=ni(r,A.doc,c.sel);K&&!(z&&r.composing&&K.empty&&(p.start!=p.endB||r.input.lastChromeDeleteue(r),20));let w=j(r.state.tr.delete(O,W)),A=f.resolve(p.start).marksAcross(f.resolve(p.endA));A&&w.ensureMarks(A),r.dispatch(w)}else if(p.endA==p.endB&&(le=ac(m.parent.content.cut(m.parentOffset,g.parentOffset),b.parent.content.cut(b.parentOffset,p.endA-b.start())))){let w=j(r.state.tr);le.type=="add"?w.addMark(O,W,le.mark):w.removeMark(O,W,le.mark),r.dispatch(w)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let w=m.parent.textBetween(m.parentOffset,g.parentOffset),A=()=>j(r.state.tr.insertText(w,O,W));r.someProp("handleTextInput",K=>K(r,O,W,w,A))||r.dispatch(A())}else r.dispatch(j());else r.dispatch(j())}function ni(r,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Zn(r,e.resolve(t.anchor),e.resolve(t.head))}function ac(r,e){let t=r.firstChild.marks,n=e.firstChild.marks,i=t,s=n,o,l,a;for(let f=0;ff.mark(l.addToSet(f.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=f=>f.mark(l.removeFromSet(f.marks));else return null;let c=[];for(let f=0;ft||bn(o,!0,!1)0&&(e||r.indexAfter(n)==r.node(n).childCount);)n--,i++,e=!1;if(t){let s=r.node(n).maybeChild(r.indexAfter(n));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function fc(r,e,t,n,i){let s=r.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=r.findDiffEnd(e,t+r.size,t+e.size);if(i=="end"){let a=Math.max(0,s-Math.min(o,l));n-=o+a-s}if(o=o?s-n:0;s-=a,s&&s=l?s-n:0;s-=a,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}class hc{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 Oa,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(ai),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=oi(this),si(this),this.nodeViews=li(this),this.docView=Vr(this.state.doc,ii(this),yn(this),this.dom,this),this.domObserver=new Qa(this,(n,i,s,o)=>lc(this,n,i,s,o)),this.domObserver.start(),Ta(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&&Pn(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(ai),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let n in this._props)t[n]=this._props[n];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(Ws(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=li(this);uc(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Pn(this),this.editable=oi(this),si(this);let a=yn(this),c=ii(this),f=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",h=s||!this.docView.matchesNode(e.doc,c,a);(h||!e.selection.eq(i.selection))&&(o=!0);let d=f=="preserve"&&o&&this.dom.style.overflowAnchor==null&&Wl(this);if(o){this.domObserver.stop();let u=h&&(H||z)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&dc(i.selection,e.selection);if(h){let p=z?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Wa(this)),(s||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Vr(e.doc,c,a,this.dom,this)),p&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&ha(this))?ue(this,u):(As(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((n=this.dragging)===null||n===void 0)&&n.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),f=="reset"?this.dom.scrollTop=0:f=="to selection"?this.scrollToSelection():d&&Jl(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof S){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Ir(this,t.getBoundingClientRect(),e)}else Ir(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))==n.node&&(i=s)}this.dragging=new qs(e.slice,e.move,i<0?void 0:S.create(this.state.doc,i))}someProp(e,t){let n=this._props&&this._props[e],i;if(n!=null&&(i=t?t(n):n))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Gl(this,e)}coordsAtPos(e,t=1){return Cs(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,n=-1){let i=this.docView.posFromDOM(e,t,n);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Ql(this,t||this.state,e)}pasteHTML(e,t){return St(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return St(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return Qn(this,e)}destroy(){this.docView&&(Da(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],yn(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Rl())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Ea(this,e)}domSelectionRange(){let e=this.domSelection();return e?F&&this.root.nodeType===11&&vl(this.dom.ownerDocument)==this.dom&&tc(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}hc.prototype.dispatch=function(r){let e=this._props.dispatchTransaction;e?e.call(this,r):this.updateState(this.state.apply(r))};function ii(r){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(r.editable),r.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(r.state)),t)for(let n in t)n=="class"?e.class+=" "+t[n]:n=="style"?e.style=(e.style?e.style+";":"")+t[n]:!e[n]&&n!="contenteditable"&&n!="nodeName"&&(e[n]=String(t[n]))}),e.translate||(e.translate="no"),[v.node(0,r.state.doc.content.size,e)]}function si(r){if(r.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),r.cursorWrapper={dom:e,deco:v.widget(r.state.selection.from,e,{raw:!0,marks:r.markCursor})}}else r.cursorWrapper=null}function oi(r){return!r.someProp("editable",e=>e(r.state)===!1)}function dc(r,e){let t=Math.min(r.$anchor.sharedDepth(r.head),e.$anchor.sharedDepth(e.head));return r.$anchor.start(t)!=e.$anchor.start(t)}function li(r){let e=Object.create(null);function t(n){for(let i in n)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=n[i])}return r.someProp("nodeViews",t),r.someProp("markViews",t),e}function uc(r,e){let t=0,n=0;for(let i in r){if(r[i]!=e[i])return!0;t++}for(let i in e)n++;return t!=n}function ai(r){if(r.spec.state||r.spec.filterTransaction||r.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}function th(r,e){return function(t,n){let{$from:i,$to:s,node:o}=t.selection;if(o&&o.isBlock||i.depth<2||!i.sameParent(s))return!1;let l=i.node(-1);if(l.type!=r)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=r||i.index(-2)!=i.node(-2).childCount-1)return!1;if(n){let h=y.empty,d=i.index(-1)?1:i.index(-2)?2:3;for(let b=i.depth-d;b>=i.depth-3;b--)h=y.from(i.node(b).copy(h));let u=i.indexAfter(-1){if(g>-1)return!1;b.isTextblock&&b.content.size==0&&(g=N+1)}),g>-1&&m.setSelection(C.near(m.doc.resolve(g))),n(m.scrollIntoView())}return!0}let a=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,c=t.tr.delete(i.pos,s.pos),f=a?[null,{type:a}]:void 0;return ht(c.doc,i.pos,2,f)?(n&&n(c.split(i.pos,2,f).scrollIntoView()),!0):!1}}function nh(r){return function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,o=>o.childCount>0&&o.firstChild.type==r);return s?t?n.node(s.depth-1).type==r?pc(e,t,r,s):mc(e,t,s):!0:!1}}function pc(r,e,t,n){let i=r.tr,s=n.end,o=n.$to.end(n.depth);sm;p--)u-=i.child(p).nodeSize,n.delete(u-1,u+1);let s=n.doc.resolve(t.start),o=s.nodeAfter;if(n.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=s.node(-1),f=s.index(-1);if(!c.canReplace(f+(l?0:1),f+1,o.content.append(a?y.empty:y.from(i))))return!1;let h=s.pos,d=h+o.nodeSize;return n.step(new L(h-(l?1:0),d+(a?1:0),h+1,d-1,new x((l?y.empty:y.from(i.copy(y.empty))).append(a?y.empty:y.from(i.copy(y.empty))),l?0:1,a?0:1),l?0:1)),e(n.scrollIntoView()),!0}function rh(r){return function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,c=>c.childCount>0&&c.firstChild.type==r);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(a.type!=r)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,f=y.from(c?r.create():null),h=new x(y.from(r.create(null,y.from(l.type.create(null,f)))),c?3:1,0),d=s.start,u=s.end;t(e.tr.step(new L(d-(c?3:1),u,d,u,h,1,!0)).scrollIntoView())}return!0}}let vn,Fn;if(typeof WeakMap<"u"){let r=new WeakMap;vn=e=>r.get(e),Fn=(e,t)=>(r.set(e,t),t)}else{const r=[];let t=0;vn=n=>{for(let i=0;i(t==10&&(t=0),r[t++]=n,r[t++]=i)}var T=class{constructor(r,e,t,n){this.width=r,this.height=e,this.map=t,this.problems=n}findCell(r){for(let e=0;e=t){(s||(s=[])).push({type:"overlong_rowspan",pos:f,n:b-O});break}const W=i+O*e;for(let j=0;jn&&(s+=c.attrs.colspan)}}for(let o=0;o1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function bc(r,e,t){r.problems||(r.problems=[]);const n={};for(let i=0;iNumber(o)):null,i=Number(r.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(r.getAttribute("rowspan")||1),colwidth:n&&n.length==i?n:null};for(const o in e){const l=e[o].getFromDOM,a=l&&l(r);a!=null&&(s[o]=a)}return s}function fi(r,e){const t={};r.attrs.colspan!=1&&(t.colspan=r.attrs.colspan),r.attrs.rowspan!=1&&(t.rowspan=r.attrs.rowspan),r.attrs.colwidth&&(t["data-colwidth"]=r.attrs.colwidth.join(","));for(const n in e){const i=e[n].setDOMAttr;i&&i(r.attrs[n],t)}return t}function Sc(r){if(r!==null){if(!Array.isArray(r))throw new TypeError("colwidth must be null or an array");for(const e of r)if(typeof e!="number")throw new TypeError("colwidth must be null or an array of numbers")}}function ih(r){const e=r.cellAttributes||{},t={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:Sc}};for(const n in e)t[n]={default:e[n].default,validate:e[n].validate};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:r.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:r.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:n=>ci(n,e)}],toDOM(n){return["td",fi(n,e),0]}},table_header:{content:r.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:n=>ci(n,e)}],toDOM(n){return["th",fi(n,e),0]}}}}function ee(r){let e=r.cached.tableNodeTypes;if(!e){e=r.cached.tableNodeTypes={};for(const t in r.nodes){const n=r.nodes[t],i=n.spec.tableRole;i&&(e[i]=n)}}return e}const xe=new Te("selectingCells");function tt(r){for(let e=r.depth-1;e>0;e--)if(r.node(e).type.spec.tableRole=="row")return r.node(0).resolve(r.before(e+1));return null}function pe(r){const e=r.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function tn(r){const e=r.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;const t=tt(e.$head)||Cc(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Cc(r){for(let e=r.nodeAfter,t=r.pos;e;e=e.firstChild,t++){const n=e.type.spec.tableRole;if(n=="cell"||n=="header_cell")return r.doc.resolve(t)}for(let e=r.nodeBefore,t=r.pos;e;e=e.lastChild,t--){const n=e.type.spec.tableRole;if(n=="cell"||n=="header_cell")return r.doc.resolve(t-e.nodeSize)}}function Vn(r){return r.parent.type.spec.tableRole=="row"&&!!r.nodeAfter}function kc(r){return r.node(0).resolve(r.pos+r.nodeAfter.nodeSize)}function sr(r,e){return r.depth==e.depth&&r.pos>=e.start(-1)&&r.pos<=e.end(-1)}function Gs(r,e,t){const n=r.node(-1),i=T.get(n),s=r.start(-1),o=i.nextCell(r.pos-s,e,t);return o==null?null:r.node(0).resolve(s+o)}function Je(r,e,t=1){const n={...r,colspan:r.colspan-t};return n.colwidth&&(n.colwidth=n.colwidth.slice(),n.colwidth.splice(e,t),n.colwidth.some(i=>i>0)||(n.colwidth=null)),n}function wc(r,e,t=1){const n={...r,colspan:r.colspan+t};if(n.colwidth){n.colwidth=n.colwidth.slice();for(let i=0;if!=t.pos-s);a.unshift(t.pos-s);const c=a.map(f=>{const h=n.nodeAt(f);if(!h)throw new RangeError(`No cell with offset ${f} found`);const d=s+f+1;return new is(l.resolve(d),l.resolve(d+h.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(e,t){const n=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Vn(n)&&Vn(i)&&sr(n,i)){const s=this.$anchorCell.node(-1)!=n.node(-1);return s&&this.isRowSelection()?ce.rowSelection(n,i):s&&this.isColSelection()?ce.colSelection(n,i):new ce(n,i)}return k.between(n,i)}content(){const e=this.$anchorCell.node(-1),t=T.get(e),n=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),s={},o=[];for(let a=i.top;a0||g>0){let b=p.attrs;if(m>0&&(b=Je(b,0,m)),g>0&&(b=Je(b,b.colspan-g,g)),u.lefti.bottom){const b={...p.attrs,rowspan:Math.min(u.bottom,i.bottom)-Math.max(u.top,i.top)};u.top0)return!1;const n=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){const n=e.node(-1),i=T.get(n),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),a=e.node(0);return o.top<=l.top?(o.top>0&&(e=a.resolve(s+i.map[o.left])),l.bottom0&&(t=a.resolve(s+i.map[l.left])),o.bottom0)return!1;const 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 ce&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){const n=e.node(-1),i=T.get(n),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),a=e.node(0);return o.left<=l.left?(o.left>0&&(e=a.resolve(s+i.map[o.top*i.width])),l.right0&&(t=a.resolve(s+i.map[l.top*i.width])),o.right{e.push(v.node(n,n+t.nodeSize,{class:"selectedCell"}))}),D.create(r.doc,e)}function Tc({$from:r,$to:e}){if(r.pos==e.pos||r.pos=0&&!(r.after(i+1)=0&&!(e.before(s+1)>e.start(s));s--,n--);return t==n&&/row|table/.test(r.node(i).type.spec.tableRole)}function Dc({$from:r,$to:e}){let t,n;for(let i=r.depth;i>0;i--){const s=r.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--){const s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){n=s;break}}return t!==n&&e.parentOffset===0}function Ac(r,e,t){const n=(e||r).selection,i=(e||r).doc;let s,o;if(n instanceof S&&(o=n.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=R.create(i,n.from);else if(o=="row"){const l=i.resolve(n.from+1);s=R.rowSelection(l,l)}else if(!t){const l=T.get(n.node),a=n.from+1,c=a+l.map[l.width*l.height-1];s=R.create(i,a+1,c)}}else n instanceof k&&Tc(n)?s=k.create(i,n.from):n instanceof k&&Dc(n)&&(s=k.create(i,n.$from.start(),n.$from.end()));return s&&(e||(e=r.tr)).setSelection(s),e}const Ec=new Te("fix-tables");function Ys(r,e,t,n){const i=r.childCount,s=e.childCount;e:for(let o=0,l=0;o{i.type.spec.tableRole=="table"&&(t=Ic(r,i,s,t))};return e?e.doc!=r.doc&&Ys(e.doc,r.doc,0,n):r.doc.descendants(n),t}function Ic(r,e,t,n){const i=T.get(e);if(!i.problems)return n;n||(n=r.tr);const s=[];for(let a=0;a0){let u="cell";f.firstChild&&(u=f.firstChild.type.spec.tableRole);const p=[];for(let g=0;g0){const f=a-i;if(c===e.map[f]){o.push(null);continue}}if(l>0){const f=a-1;if(c===e.map[f]){o.push(null);continue}}o.push(r.nodeAt(c))}t.push(o)}return t}function Zs(r,e){const t=[],n=T.get(r),i=n.height,s=n.width;for(let o=0;ot[0]?-1:1,s=r.splice(e[0],e.length),o=s.length%2===0?1:0;let l;return l=i===-1?t[0]:t[t.length-1]-o,r.splice(l,0,...s),r}function nn(r){return zc(e=>e.type.spec.tableRole==="table",r)}function zc(r,e){for(let t=e.depth;t>=0;t-=1){const n=e.node(t);if(r(n))return{node:n,pos:t===0?0:e.before(t),start:e.start(t),depth:t}}return null}function Ue(r,e){const t=nn(e.$from);if(!t)return;const n=T.get(t.node);if(!(r<0||r>n.width-1))return n.cellsInRect({left:r,right:r+1,top:0,bottom:n.height}).map(i=>{const s=t.node.nodeAt(i),o=i+t.start;return{pos:o,start:o+1,node:s,depth:t.depth+2}})}function Ge(r,e){const t=nn(e.$from);if(!t)return;const n=T.get(t.node);if(!(r<0||r>n.height-1))return n.cellsInRect({left:0,right:n.width,top:r,bottom:r+1}).map(i=>{const s=t.node.nodeAt(i),o=i+t.start;return{pos:o,start:o+1,node:s,depth:t.depth+2}})}function hi(r,e,t=e){let n=e,i=t;for(let f=e;f>=0;f--){const h=Ue(f,r.selection);h&&h.forEach(d=>{const u=d.node.attrs.colspan+f-1;u>=n&&(n=f),u>i&&(i=u)})}for(let f=e;f<=i;f++){const h=Ue(f,r.selection);h&&h.forEach(d=>{const u=d.node.attrs.colspan+f-1;d.node.attrs.colspan>1&&u>i&&(i=u)})}const s=[];for(let f=n;f<=i;f++){const h=Ue(f,r.selection);h&&h.length>0&&s.push(f)}n=s[0],i=s[s.length-1];const o=Ue(n,r.selection),l=Ge(0,r.selection);if(!o||!l)return;const a=r.doc.resolve(o[o.length-1].pos);let c;for(let f=i;f>=n;f--){const h=Ue(f,r.selection);if(h&&h.length>0){for(let d=l.length-1;d>=0;d--)if(l[d].pos===h[0].pos){c=h[0];break}if(c)break}}if(c)return{$anchor:a,$head:r.doc.resolve(c.pos),indexes:s}}function di(r,e,t=e){let n=e,i=t;for(let f=e;f>=0;f--){const h=Ge(f,r.selection);h&&h.forEach(d=>{const u=d.node.attrs.rowspan+f-1;u>=n&&(n=f),u>i&&(i=u)})}for(let f=e;f<=i;f++){const h=Ge(f,r.selection);h&&h.forEach(d=>{const u=d.node.attrs.rowspan+f-1;d.node.attrs.rowspan>1&&u>i&&(i=u)})}const s=[];for(let f=n;f<=i;f++){const h=Ge(f,r.selection);h&&h.length>0&&s.push(f)}n=s[0],i=s[s.length-1];const o=Ge(n,r.selection),l=Ue(0,r.selection);if(!o||!l)return;const a=r.doc.resolve(o[o.length-1].pos);let c;for(let f=i;f>=n;f--){const h=Ge(f,r.selection);if(h&&h.length>0){for(let d=l.length-1;d>=0;d--)if(l[d].pos===h[0].pos){c=h[0];break}if(c)break}}if(c)return{$anchor:a,$head:r.doc.resolve(c.pos),indexes:s}}function ui(r){return r[0].map((e,t)=>r.map(n=>n[t]))}function Bc(r){var e,t;const{tr:n,originIndex:i,targetIndex:s,select:o,pos:l}=r,a=nn(n.doc.resolve(l));if(!a)return!1;const c=(e=hi(n,i))===null||e===void 0?void 0:e.indexes,f=(t=hi(n,s))===null||t===void 0?void 0:t.indexes;if(!c||!f||c.includes(s))return!1;const h=Pc(a.node,c,f);if(n.replaceWith(a.pos,a.pos+a.node.nodeSize,h),!o)return!0;const d=T.get(h),u=a.start,p=s,m=d.positionAt(d.height-1,p,h),g=n.doc.resolve(u+m),b=d.positionAt(0,p,h),N=n.doc.resolve(u+b);return n.setSelection(R.colSelection(g,N)),!0}function Pc(r,e,t,n){let i=ui(_s(r));return i=Qs(i,e,t),i=ui(i),Zs(r,i)}function vc(r){var e,t;const{tr:n,originIndex:i,targetIndex:s,select:o,pos:l}=r,a=nn(n.doc.resolve(l));if(!a)return!1;const c=(e=di(n,i))===null||e===void 0?void 0:e.indexes,f=(t=di(n,s))===null||t===void 0?void 0:t.indexes;if(!c||!f||c.includes(s))return!1;const h=Fc(a.node,c,f);if(n.replaceWith(a.pos,a.pos+a.node.nodeSize,h),!o)return!0;const d=T.get(h),u=a.start,p=s,m=d.positionAt(p,d.width-1,h),g=n.doc.resolve(u+m),b=d.positionAt(p,0,h),N=n.doc.resolve(u+b);return n.setSelection(R.rowSelection(g,N)),!0}function Fc(r,e,t,n){let i=_s(r);return i=Qs(i,e,t),Zs(r,i)}function rt(r){const e=r.selection,t=tn(r),n=t.node(-1),i=t.start(-1),s=T.get(n);return{...e instanceof R?s.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):s.findCell(t.pos-i),tableStart:i,map:s,table:n}}function eo(r,{map:e,tableStart:t,table:n},i){let s=i>0?-1:0;Mc(e,n,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o0&&i0&&e.map[l-1]==a||i0&&h==e.map[f-e.width]){const d=t.nodeAt(h).attrs;r.setNodeMarkup(r.mapping.slice(l).map(h+n),null,{...d,rowspan:d.rowspan-1}),c+=d.colspan-1}else if(i{o.attrs[r]!==e&&s.setNodeMarkup(l,null,{...o.attrs,[r]:e})}):s.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[r]:e}),n(s)}return!0}}function $c(r){return function(e,t){if(!pe(e))return!1;if(t){const n=ee(e.schema),i=rt(e),s=e.tr,o=i.map.cellsInRect(r=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:r=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),l=o.map(a=>i.table.nodeAt(a));for(let a=0;a{const u=d+s.tableStart,p=o.doc.nodeAt(u);p&&o.setNodeMarkup(u,h,p.attrs)}),n(o)}return!0}}or("row",{useDeprecatedLogic:!0});or("column",{useDeprecatedLogic:!0});or("cell",{useDeprecatedLogic:!0});function Wc(r,e){if(e<0){const t=r.nodeBefore;if(t)return r.pos-t.nodeSize;for(let n=r.index(-1)-1,i=r.before();n>=0;n--){const s=r.node(-1).child(n),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(r.index()0;n--)if(t.node(n).type.spec.tableRole=="table")return e&&e(r.tr.delete(t.before(n),t.after(n)).scrollIntoView()),!0;return!1}function Dt(r,e){const t=r.selection;if(!(t instanceof R))return!1;if(e){const n=r.tr,i=ee(r.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||n.replace(n.mapping.map(o+1),n.mapping.map(o+s.nodeSize-1),new x(i,0,0))}),n.docChanged&&e(n)}return!0}function dh(r){return(e,t)=>{const{from:n,to:i,select:s=!0,pos:o=e.selection.from}=r,l=e.tr;return vc({tr:l,originIndex:n,targetIndex:i,select:s,pos:o})?(t?.(l),!0):!1}}function uh(r){return(e,t)=>{const{from:n,to:i,select:s=!0,pos:o=e.selection.from}=r,l=e.tr;return Bc({tr:l,originIndex:n,targetIndex:i,select:s,pos:o})?(t?.(l),!0):!1}}function Jc(r){if(r.size===0)return null;let{content:e,openStart:t,openEnd:n}=r;for(;e.childCount==1&&(t>0&&n>0||e.child(0).type.spec.tableRole=="table");)t--,n--,e=e.child(0).content;const i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let a=0;a=0;o--){const{rowspan:l,colspan:a}=s.child(o).attrs;for(let c=i;c=e.length&&e.push(y.empty),t[i]n&&(d=d.type.createChecked(Je(d.attrs,d.attrs.colspan,f+d.attrs.colspan-n),d.content)),c.push(d),f+=d.attrs.colspan;for(let u=1;ui&&(h=h.type.create({...h.attrs,rowspan:Math.max(1,i-h.attrs.rowspan)},h.content)),a.push(h)}s.push(y.from(a))}t=s,e=i}return{width:r,height:e,rows:t}}function Hc(r,e,t,n,i,s,o){const l=r.doc.type.schema,a=ee(l);let c,f;if(i>e.width)for(let h=0,d=0;he.height){const h=[];for(let p=0,m=(e.height-1)*e.width;p=e.width?!1:t.nodeAt(e.map[m+p]).type==a.header_cell;h.push(g?f||(f=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}const d=a.row.create(null,y.from(h)),u=[];for(let p=e.height;p{if(!i)return!1;const s=t.selection;if(s instanceof R)return Bt(t,n,C.near(s.$headCell,e));if(r!="horiz"&&!s.empty)return!1;const o=to(i,r,e);if(o==null)return!1;if(r=="horiz")return Bt(t,n,C.near(t.doc.resolve(s.head+e),e));{const l=t.doc.resolve(o),a=Gs(l,r,e);let c;return a?c=C.near(a,1):e<0?c=C.near(t.doc.resolve(l.before(-1)),-1):c=C.near(t.doc.resolve(l.after(-1)),1),Bt(t,n,c)}}}function Et(r,e){return(t,n,i)=>{if(!i)return!1;const s=t.selection;let o;if(s instanceof R)o=s;else{const a=to(i,r,e);if(a==null)return!1;o=new R(t.doc.resolve(a))}const l=Gs(o.$headCell,r,e);return l?Bt(t,n,new R(o.$anchorCell,l)):!1}}function Uc(r,e){const t=r.state.doc,n=tt(t.resolve(e));return n?(r.dispatch(r.state.tr.setSelection(new R(n))),!0):!1}function Gc(r,e,t){if(!pe(r.state))return!1;let n=Jc(t);const i=r.state.selection;if(i instanceof R){n||(n={width:1,height:1,rows:[y.from(Ln(ee(r.state.schema).cell,t))]});const s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=T.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return n=Kc(n,l.right-l.left,l.bottom-l.top),yi(r.state,r.dispatch,o,l,n),!0}else if(n){const s=tn(r.state),o=s.start(-1);return yi(r.state,r.dispatch,o,T.get(s.node(-1)).findCell(s.pos-o),n),!0}else return!1}function Xc(r,e){var t;if(e.button!=0||e.ctrlKey||e.metaKey)return;const n=bi(r,e.target);let i;if(e.shiftKey&&r.state.selection instanceof R)s(r.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&n&&(i=tt(r.state.selection.$anchor))!=null&&((t=xn(r,e))===null||t===void 0?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!n)return;function s(a,c){let f=xn(r,c);const h=xe.getState(r.state)==null;if(!f||!sr(a,f))if(h)f=a;else return;const d=new R(a,f);if(h||!r.state.selection.eq(d)){const u=r.state.tr.setSelection(d);h&&u.setMeta(xe,a.pos),r.dispatch(u)}}function o(){r.root.removeEventListener("mouseup",o),r.root.removeEventListener("dragstart",o),r.root.removeEventListener("mousemove",l),xe.getState(r.state)!=null&&r.dispatch(r.state.tr.setMeta(xe,-1))}function l(a){const c=a,f=xe.getState(r.state);let h;if(f!=null)h=r.state.doc.resolve(f);else if(bi(r,c.target)!=n&&(h=xn(r,e),!h))return o();h&&s(h,c)}r.root.addEventListener("mouseup",o),r.root.addEventListener("dragstart",o),r.root.addEventListener("mousemove",l)}function to(r,e,t){if(!(r.state.selection instanceof k))return null;const{$head:n}=r.state.selection;for(let i=n.depth-1;i>=0;i--){const s=n.node(i);if((t<0?n.index(i):n.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){const o=n.before(i),l=e=="vert"?t>0?"down":"up":t>0?"right":"left";return r.endOfTextblock(l)?o:null}}return null}function bi(r,e){for(;e&&e!=r.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function xn(r,e){const t=r.posAtCoords({left:e.clientX,top:e.clientY});if(!t)return null;let{inside:n,pos:i}=t;return n>=0&&tt(r.state.doc.resolve(n))||tt(r.state.doc.resolve(i))}var Yc=class{constructor(r,e){this.node=r,this.defaultCellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${e}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),$n(r,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(r){return r.type!=this.node.type?!1:(this.node=r,$n(r,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(r){return r.type=="attributes"&&(r.target==this.table||this.colgroup.contains(r.target))}};function $n(r,e,t,n,i,s){let o=0,l=!0,a=e.firstChild;const c=r.firstChild;if(c){for(let h=0,d=0;hnew n(h,t,d)),new _c(-1,!1)},apply(o,l){return l.apply(o)}},props:{attributes:o=>{const l=G.getState(o);return l&&l.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,l)=>{Zc(o,l,r,i)},mouseleave:o=>{Qc(o)},mousedown:(o,l)=>{ef(o,l,e,t)}},decorations:o=>{const l=G.getState(o);if(l&&l.activeHandle>-1)return of(o,l.activeHandle)},nodeViews:{}}});return s}var _c=class Pt{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){const t=this,n=e.getMeta(G);if(n&&n.setHandle!=null)return new Pt(n.setHandle,!1);if(n&&n.setDragging!==void 0)return new Pt(t.activeHandle,n.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Vn(e.doc.resolve(i))||(i=-1),new Pt(i,t.dragging)}return t}};function Zc(r,e,t,n){if(!r.editable)return;const i=G.getState(r.state);if(i&&!i.dragging){const s=nf(e.target);let o=-1;if(s){const{left:l,right:a}=s.getBoundingClientRect();e.clientX-l<=t?o=xi(r,e,"left",t):a-e.clientX<=t&&(o=xi(r,e,"right",t))}if(o!=i.activeHandle){if(!n&&o!==-1){const l=r.state.doc.resolve(o),a=l.node(-1),c=T.get(a),f=l.start(-1);if(c.colCount(l.pos-f)+l.nodeAfter.attrs.colspan-1==c.width-1)return}no(r,o)}}}function Qc(r){if(!r.editable)return;const e=G.getState(r.state);e&&e.activeHandle>-1&&!e.dragging&&no(r,-1)}function ef(r,e,t,n){var i;if(!r.editable)return!1;const s=(i=r.dom.ownerDocument.defaultView)!==null&&i!==void 0?i:window,o=G.getState(r.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const l=r.state.doc.nodeAt(o.activeHandle),a=tf(r,o.activeHandle,l.attrs);r.dispatch(r.state.tr.setMeta(G,{setDragging:{startX:e.clientX,startWidth:a}}));function c(h){s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",f);const d=G.getState(r.state);d?.dragging&&(rf(r,d.activeHandle,Si(d.dragging,h,t)),r.dispatch(r.state.tr.setMeta(G,{setDragging:null})))}function f(h){if(!h.which)return c(h);const d=G.getState(r.state);if(d&&d.dragging){const u=Si(d.dragging,h,t);Ci(r,d.activeHandle,u,n)}}return Ci(r,o.activeHandle,a,n),s.addEventListener("mouseup",c),s.addEventListener("mousemove",f),e.preventDefault(),!0}function tf(r,e,{colspan:t,colwidth:n}){const i=n&&n[n.length-1];if(i)return i;const s=r.domAtPos(e);let o=s.node.childNodes[s.offset].offsetWidth,l=t;if(n)for(let a=0;a{Wn=!0},compositionend:()=>{Wn=!1}}}};function uf(r){const{$from:e,$to:t,to:n}=r.selection;if(Wn&&e.sameParent(t)){const i=v.widget(n,pf,{ignoreSelection:!0,key:"safari-ime-span"});return D.create(r.doc,[i])}}function pf(r){const e=r.dom.ownerDocument.createElement("span");return e.className="ProseMirror-safari-ime-span",e}var gh=new Oe(hf?df:{key:ro});const mf=500;class te{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let n=this.items.length;for(;;n--)if(this.items.get(n-1).selection){--n;break}let i,s;t&&(i=this.remapping(n,this.items.length),s=i.maps.length);let o=e.tr,l,a,c=[],f=[];return this.items.forEach((h,d)=>{if(!h.step){i||(i=this.remapping(n,d+1),s=i.maps.length),s--,f.push(h);return}if(i){f.push(new ne(h.map));let u=h.step.map(i.slice(s)),p;u&&o.maybeStep(u).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],c.push(new ne(p,void 0,void 0,c.length+f.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(h.step);if(h.selection)return l=i?h.selection.map(i.slice(s)):h.selection,a=new te(this.items.slice(0,n).append(f.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,t,n,i){let s=[],o=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let f=0;fyf&&(l=gf(l,c),o-=c),new te(l.append(s),o)}remapping(e,t){let n=new yt;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?n.maps.length-i.mirrorOffset:void 0;n.appendMap(i.map,o)},e,t),n}addMaps(e){return this.eventCount==0?this:new te(this.items.append(e.map(t=>new ne(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let a=t;this.items.forEach(d=>{let u=s.getMirror(--a);if(u==null)return;o=Math.min(o,u);let p=s.maps[u];if(d.step){let m=e.steps[u].invert(e.docs[u]),g=d.selection&&d.selection.map(s.slice(a+1,u));g&&l++,n.push(new ne(p,m,g))}else n.push(new ne(p))},i);let c=[];for(let d=t;dmf&&(h=h.compress(this.items.length-n.length)),h}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),n=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 a=o.step.map(t.slice(n)),c=a&&a.getMap();if(n--,c&&t.appendMap(c,n),a){let f=o.selection&&o.selection.map(t.slice(n));f&&s++;let h=new ne(c.invert(),a,f),d,u=i.length-1;(d=i.length&&i[u].merge(h))?i[u]=d:i.push(h)}}else o.map&&n--},this.items.length,0),new te(Oi.from(i.reverse()),s)}}te.empty=new te(Oi.empty,0);function gf(r,e){let t;return r.forEach((n,i)=>{if(n.selection&&e--==0)return t=i,!1}),r.slice(t)}class ne{constructor(e,t,n,i){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new ne(t.getMap().invert(),t,this.selection)}}}class ye{constructor(e,t,n,i,s){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=i,this.prevComposition=s}}const yf=20;function bf(r,e,t,n){let i=t.getMeta(Fe),s;if(i)return i.historyState;t.getMeta(Cf)&&(r=new ye(r.done,r.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return r;if(o&&o.getMeta(Fe))return o.getMeta(Fe).redo?new ye(r.done.addTransform(t,void 0,n,vt(e)),r.undone,ki(t.mapping.maps),r.prevTime,r.prevComposition):new ye(r.done,r.undone.addTransform(t,void 0,n,vt(e)),null,r.prevTime,r.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=r.prevTime==0||!o&&r.prevComposition!=l&&(r.prevTime<(t.time||0)-n.newGroupDelay||!xf(t,r.prevRanges)),c=o?Sn(r.prevRanges,t.mapping):ki(t.mapping.maps);return new ye(r.done.addTransform(t,a?e.selection.getBookmark():void 0,n,vt(e)),te.empty,c,t.time,l??r.prevComposition)}else return(s=t.getMeta("rebased"))?new ye(r.done.rebased(t,s),r.undone.rebased(t,s),Sn(r.prevRanges,t.mapping),r.prevTime,r.prevComposition):new ye(r.done.addMaps(t.mapping.maps),r.undone.addMaps(t.mapping.maps),Sn(r.prevRanges,t.mapping),r.prevTime,r.prevComposition)}function xf(r,e){if(!e)return!1;if(!r.docChanged)return!0;let t=!1;return r.mapping.maps[0].forEach((n,i)=>{for(let s=0;s=e[s]&&(t=!0)}),t}function ki(r){let e=[];for(let t=r.length-1;t>=0&&e.length==0;t--)r[t].forEach((n,i,s,o)=>e.push(s,o));return e}function Sn(r,e){if(!r)return null;let t=[];for(let n=0;n{let i=Fe.getState(t);if(!i||(r?i.undone:i.done).eventCount==0)return!1;if(n){let s=Sf(i,t,r);s&&n(e?s.scrollIntoView():s)}return!0}}const kf=io(!1,!0),wf=io(!0,!0);function Mf(r){let e=[[-1,r.state.doc]],t=[];for(;e.length>0;){const[n,i]=e.pop();if(n>=0){let s=r.nodeDOM(n);if(s&&ao(s)){let{top:o,bottom:l,left:a,right:c}=s.getBoundingClientRect();t.push([n,[a,o,c,o]],[n+i.nodeSize,[a,l,c,l]])}}if(i.isBlock&&!i.isTextblock){let s=n+1;for(let o of i.children)e.push([s,o]),s+=o.nodeSize}}return t}function Nf(r,e){let t=[],n,i;const s=()=>{const f=r.dom.getBoundingClientRect(),h=r.state.doc;return t&&n&&i&&f.width===i.width&&f.height===i.height&&f.x===i.x&&f.y===i.y&&n.eq(h)||(i=f,n=h,t=Mf(r)),t},o=(f,h)=>{if(!r.editable||r.isDestroyed)return;const d=(m,g)=>{const[b,N]=m,[O,W]=g;return Ni(f,N)-Ni(f,W)||b-O};let u=s();u.sort(d),u=u.slice(0,8);const p=u.find(m=>e?.({view:r,pos:m[0],event:h})!==!1);if(!(p&&Tf(r,p[0])))return p};let l,a;return(f,h)=>(l&&Of(l,f)||(l=f,a=o(f,h)),a)}function Of(r,e){return r[0]===e[0]&&r[1]===e[1]}function Mi(r,e){return Math.abs(r[0]-e[0])+Math.abs(r[1]-e[1])}function Ni(r,e){return Math.min(Mi(r,[e[0],e[1]]),Mi(r,[e[2],e[3]]))}function Tf(r,e){const t=r.dragging;if(!t)return;const{move:n}=t;if(!n)return;const i=r.state.selection;if(!(i instanceof S))return;const{from:s,to:o}=i;return s<=e&&e<=o}function bh(r){let e;return new Oe({key:new Te("prosekit-drop-indicator"),view:t=>(e=Nf(t,r.onDrag),Af(t,e,r)),props:{handleDrop(t,n,i,s){if(!e)return!1;const o=e([n.clientX,n.clientY],n);if(!o)return!1;n.preventDefault();let l=o[0],a=t.state.tr;if(s){let{node:u}=t.dragging||{};u?u.replace(a):a.deleteSelection()}let c=a.mapping.map(l),f=i.openStart==0&&i.openEnd==0&&i.content.childCount==1,h=a.doc;if(f?a.replaceRangeWith(c,c,i.content.firstChild):a.replaceRange(c,c,i),a.doc.eq(h))return!0;let d=a.doc.resolve(c);if(f&&S.isSelectable(i.content.firstChild)&&d.nodeAfter&&d.nodeAfter.sameMarkup(i.content.firstChild))a.setSelection(new S(d));else{let u=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((p,m,g,b)=>u=b),a.setSelection(Df(t,d,a.doc.resolve(u)))}return t.focus(),t.dispatch(a.setMeta("uiEvent","drop")),!0}}})}function Df(r,e,t,n){return r.someProp("createSelectionBetween",i=>i(r,e,t))||k.between(e,t,n)}function Af(r,e,t){let n=r.dom,i,s,o,l=!1;const a=()=>{i&&clearTimeout(i),l=!1,i=setTimeout(()=>{l||t.onHide?.()},30)},c=h=>{l=!0;const{clientX:d,clientY:u}=h;if(s===d&&o===u)return;s=d,o=u;let p=e([d,u],h);if(p){const[m,[g,b,N,O]]=p,W={p1:{x:g,y:b},p2:{x:N,y:O}};t.onShow?.({view:r,pos:m,line:W})}else{a();return}};return n.addEventListener("dragover",c),n.addEventListener("dragend",a),n.addEventListener("drop",a),n.addEventListener("dragleave",a),{destroy:()=>{n.removeEventListener("dragover",c),n.removeEventListener("dragend",a),n.removeEventListener("drop",a),n.removeEventListener("dragleave",a)}}}class E extends C{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return E.valid(n)?new E(n):C.near(n)}content(){return x.empty}eq(e){return e instanceof E&&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 E(e.resolve(t.pos))}getBookmark(){return new ar(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Ef(e)||!Rf(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let i=t.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&E.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 a=e.doc.resolve(i);if(E.valid(a))return a}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!S.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*t),n=!1;continue e}break}s=o,i+=t;let l=e.doc.resolve(i);if(E.valid(l))return l}return null}}}E.prototype.visible=!1;E.findFrom=E.findGapCursorFrom;C.jsonID("gapcursor",E);class ar{constructor(e){this.pos=e}map(e){return new ar(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return E.valid(t)?new E(t):C.near(t)}}function so(r){return r.isAtom||r.spec.isolating||r.spec.createGapCursor}function Ef(r){for(let e=r.depth;e>=0;e--){let t=r.index(e),n=r.node(e);if(t==0){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||so(i.type))return!0;if(i.inlineContent)return!1}}return!0}function Rf(r){for(let e=r.depth;e>=0;e--){let t=r.indexAfter(e),n=r.node(e);if(t==n.childCount){if(n.type.spec.isolating)return!0;continue}for(let i=n.child(t);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||so(i.type))return!0;if(i.inlineContent)return!1}}return!0}function xh(){return new Oe({props:{decorations:Pf,createSelectionBetween(r,e,t){return e.pos==t.pos&&E.valid(t)?new E(t):null},handleClick:zf,handleKeyDown:If,handleDOMEvents:{beforeinput:Bf}}})}const If=Xn({ArrowLeft:Rt("horiz",-1),ArrowRight:Rt("horiz",1),ArrowUp:Rt("vert",-1),ArrowDown:Rt("vert",1)});function Rt(r,e){const t=r=="vert"?e>0?"down":"up":e>0?"right":"left";return function(n,i,s){let o=n.selection,l=e>0?o.$to:o.$from,a=o.empty;if(o instanceof k){if(!s.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=n.doc.resolve(e>0?l.after():l.before())}let c=E.findGapCursorFrom(l,e,a);return c?(i&&i(n.tr.setSelection(new E(c))),!0):!1}}function zf(r,e,t){if(!r||!r.editable)return!1;let n=r.state.doc.resolve(e);if(!E.valid(n))return!1;let i=r.posAtCoords({left:t.clientX,top:t.clientY});return i&&i.inside>-1&&S.isSelectable(r.state.doc.nodeAt(i.inside))?!1:(r.dispatch(r.state.tr.setSelection(new E(n))),!0)}function Bf(r,e){if(e.inputType!="insertCompositionText"||!(r.state.selection instanceof E))return!1;let{$from:t}=r.state.selection,n=t.parent.contentMatchAt(t.index()).findWrapping(r.state.schema.nodes.text);if(!n)return!1;let i=y.empty;for(let o=n.length-1;o>=0;o--)i=y.from(n[o].createAndFill(null,i));let s=r.state.tr.replace(t.pos,t.pos,new x(i,0,0));return s.setSelection(k.near(s.doc.resolve(t.pos+1))),r.dispatch(s),!1}function Pf(r){if(!(r.selection instanceof E))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",D.create(r.doc,[v.widget(r.selection.head,e,{key:"gapcursor"})])}function Sh(r){var e;const t=(e=void 0)!=null?e:!1;let n=typeof document>"u"?null:document.createElement("div");return new Oe({key:vf,view:i=>{t!==!0&&$f(i.state.schema,t||[]);const s=i.dom.ownerDocument;n=n||document.createElement("div");const o=n,l=()=>{Vf(i,o)};let a;return window.ResizeObserver&&(a=new window.ResizeObserver(()=>l()),a.observe(i.dom)),s.addEventListener("selectionchange",l),{update:()=>{l()},destroy:()=>{s.removeEventListener("selectionchange",l),a&&a.unobserve(i.dom)}}},props:{handleKeyDown:(i,s)=>{var o;const{selection:l}=i.state;if(s.altKey||s.ctrlKey||s.metaKey||s.shiftKey||s.isComposing||!["ArrowLeft","ArrowRight"].includes(s.key)||!Jn(l)||!l.empty)return!1;const a=l.$head,[c,f]=oo(a),h=i.state.storedMarks||a.marks();if(c&&f&&!M.sameSet(c,f)){if(s.key==="ArrowLeft"&&!M.sameSet(c,h))return i.dispatch(i.state.tr.setStoredMarks(c)),!0;if(s.key==="ArrowRight"&&!M.sameSet(f,h))return i.dispatch(i.state.tr.setStoredMarks(f)),!0}return s.key==="ArrowLeft"&&a.textOffset===1?(i.dispatch(i.state.tr.setSelection(k.create(i.state.doc,a.pos-1)).setStoredMarks(a.marks())),!0):s.key==="ArrowRight"&&a.textOffset+1===((o=a.parent.maybeChild(a.index()))==null?void 0:o.nodeSize)?(i.dispatch(i.state.tr.setSelection(k.create(i.state.doc,a.pos+1)).setStoredMarks(a.marks())),!0):!1},decorations:i=>{if(!(!n||!Jn(i.selection)||!i.selection.empty))return D.create(i.doc,[v.widget(0,n,{key:"prosemirror-virtual-cursor"})])},attributes:{class:"virtual-cursor-enabled"}}})}var vf=new Te("prosemirror-virtual-cursor");function Ff(r,e){var t;const n=window.getSelection();if(!n||!n.rangeCount)return null;const i=(t=n?.getRangeAt(0))==null?void 0:t.cloneRange();if(!i)return null;i.collapse(e);const s=i.getClientRects(),o=s?.length?s[s.length-1]:null;return o?.height?o:r.coordsAtPos(r.state.selection.head)}function oo(r){const e=r.index(),t=r.parent.maybeChild(e);let n=r.textOffset?t:null;return!n&&e>0&&(n=r.parent.maybeChild(e-1)),[n?.marks,t?.marks]}function Jn(r){return r&&typeof r=="object"&&"$cursor"in r}function Vf(r,e){if(!r||!r.dom||r.isDestroyed||!e)return;const{state:t,dom:n}=r,{selection:i}=t;if(!Jn(i))return;const s=Ff(r,i.$head===i.$from);if(!s)return e;const o=n.getBoundingClientRect();let l="prosemirror-virtual-cursor";const a=t.selection.$head,[c,f]=oo(a),h=t.storedMarks||a.marks();i.$cursor&&c&&f&&h&&!M.sameSet(c,f)&&(M.sameSet(c,h)?l+=" prosemirror-virtual-cursor-left":M.sameSet(f,h)&&(l+=" prosemirror-virtual-cursor-right")),e.className=l,Lf(e,"prosemirror-virtual-cursor-animation"),e.style.height=`${s.bottom-s.top}px`,e.style.left=`${s.left-o.left}px`,e.style.top=`${s.top-o.top}px`}function Lf(r,e){r.classList.remove(e),r.offsetWidth,r.classList.add(e)}function $f(r,e){for(const[t,n]of Object.entries(r.marks))n.spec.inclusive===!1&&!e.includes(t)&&console.warn(`[prosemirror-virtual-cursor] Virtual cursor does not work well with marks that have inclusive set to false. Please consider removing the inclusive option from the "${t}" mark or adding it to the "skipWarning" option.`)}export{nn as $,Se as A,gh as B,mh as C,mt as D,at as E,y as F,fh as G,pe as H,De as I,dh as J,uh as K,R as L,M,S as N,hh as O,Oe as P,lh as Q,B as R,Hf as S,k as T,ah as U,sh as V,oh as W,rt as X,ch as Y,ph as Z,T as _,Te as a,kf as a0,wf as a1,ml as a2,xh as a3,bh as a4,nt as a5,yh as a6,X as a7,Sh as a8,hc as b,ie as c,Gn as d,Yf as e,as as f,x as g,ur as h,v as i,jf as j,eh as k,D as l,Gf as m,Qf as n,Uf as o,C as p,rh as q,nh as r,fl as s,Xf as t,_f as u,th as v,Zf as w,Yi as x,al as y,ih as z};