function B(r){this.content=r}B.prototype={constructor:B,find:function(r){for(var e=0;e>1}};B.from=function(r){if(r instanceof B)return r;var e=[];if(r)for(var t in r)e.push(t,r[t]);return new B(e)};function mi(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=mi(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function gi(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 n=0,i=0;;n++){let s=this.child(n),o=i+s.nodeSize;if(o>=e)return o==e||t>0?wt(n+1,o):wt(n,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return 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}};N.none=[];class Rt extends Error{}class k{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=bi(this.content,e+this.openStart,t);return n&&new k(n,this.openStart,this.openEnd)}removeBetween(e,t){return new k(yi(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 k.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 k(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 k(e,n,i)}}k.empty=new k(y.empty,0,0);function yi(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(yi(s.content,e-i-1,t-i-1)))}function bi(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=bi(o.content,e-s-1,t);return l&&r.replaceChild(i,o.copy(l))}function Ks(r,e,t){if(t.openStart>r.depth)throw new Rt("Inserted content deeper than insertion position");if(r.depth-t.openStart!=e.depth-t.openEnd)throw new Rt("Inconsistent open depths");return ki(r,e,t,0)}function ki(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 ot(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&&(Ie(r.nodeAfter,n),s++));for(let l=s;li&&xn(r,e,i+1),o=n.depth>i&&xn(t,n,i+1),l=[];return ot(null,r,i,l),s&&o&&e.index(i)==t.index(i)?(Si(s,o),Ie(Pe(s,xi(r,e,t,n,i+1)),l)):(s&&Ie(Pe(s,It(r,e,i+1)),l),ot(e,t,i,l),o&&Ie(Pe(o,It(t,n,i+1)),l)),ot(n,null,i,l),new y(l)}function It(r,e,t){let n=[];if(ot(null,r,t,n),r.depth>t){let i=xn(r,e,t+1);Ie(Pe(i,It(r,e,t+1)),n)}return ot(e,null,t,n),new y(n)}function js(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 dt{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 Pt(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 dt(t,n,s)}static resolveCached(e,t){let n=sr.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()+")"),Mi(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}};Be.prototype.text=void 0;class Bt extends Be{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):Mi(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 Bt(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Bt(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 Mi(r,e){for(let t=r.length-1;t>=0;t--)e=r[t].type.name+"("+e+")";return e}class Fe{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new _s(e,t);if(n.next==null)return Fe.empty;let i=Ci(n);n.next&&n.err("Unexpected trailing text");let s=ro(no(i));return io(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(` `)}}Fe.empty=new Fe(!0);class _s{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 Ci(r){let e=[];do e.push(Xs(r));while(r.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Xs(r){let e=[];do e.push(Zs(r));while(r.next&&r.next!=")"&&r.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Zs(r){let e=to(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=Qs(r,e);else break;return e}function or(r){/\D/.test(r.next)&&r.err("Expected number, got '"+r.next+"'");let e=Number(r.next);return r.pos++,e}function Qs(r,e){let t=or(r),n=t;return r.eat(",")&&(r.next!="}"?n=or(r):n=-1),r.eat("}")||r.err("Unclosed braced range"),{type:"range",min:t,max:n,expr:e}}function eo(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 to(r){if(r.eat("(")){let e=Ci(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=eo(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 no(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 Fe(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:Ti(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Be(this,this.computeAttrs(e),y.from(t),N.setFrom(n))}createChecked(e=null,t,n){return t=y.from(t),this.checkContent(t),new Be(this,this.computeAttrs(e),t,N.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 Be(this,e,t.append(s),N.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 Ai(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 so(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 oo{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate=typeof n.validate=="string"?so(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class Kt{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=Ei(e,i.attrs),this.excluded=null;let s=Oi(this.attrs);this.instance=s?new N(this,s):null}create(e=null){return!e&&this.instance?this.instance:new N(this,Ti(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach((s,o)=>n[s]=new Kt(s,i++,t,o)),n}removeFromSet(e){for(var t=0;t-1}}class lo{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=B.from(e.nodes),t.marks=B.from(e.marks||{}),this.nodes=ar.compile(this.spec.nodes,this),this.marks=Kt.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]=Fe.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?cr(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==""?[]:cr(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof ar){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 Bt(n,n.defaultAttrs,e,N.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Be.fromJSON(this,e)}markFromJSON(e){return N.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function cr(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 ao(r){return r.tag!=null}function co(r){return r.style!=null}class _e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(i=>{if(ao(i))this.tags.push(i);else if(co(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 dr(this,t,!1);return n.addAll(e,N.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new dr(this,t,!0);return n.addAll(e,N.none,t.from,t.to),k.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=ur(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=ur(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new _e(e,_e.schemaRules(e)))}}const Di={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},fo={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ri={ol:!0,ul:!0},ut=1,Cn=2,lt=4;function fr(r,e,t){return e!=null?(e?ut:0)|(e==="full"?Cn:0):r&&r.whitespace=="pre"?ut|Cn:t&~lt}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=N.none,this.match=s||(o<?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&ut)){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&&!Di.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class dr{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=fr(null,t.preserveWhitespace,0)|(n?lt:0);i?s=new Ot(i.type,i.attrs,N.none,!0,t.topMatch||i.type.contentMatch,o):n?s=new Ot(null,null,N.none,!0,null,o):s=new Ot(e.schema.topNodeType,null,N.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&Cn?"full":this.localPreserveWS||(i.options&ut)>0;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(s)s!=="full"?n=n.replace(/\r?\n|\r/g," "):n=n.replace(/\r\n?/g,` `);else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],l=e.previousSibling;(!o||l&&l.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let i=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),l;Ri.hasOwnProperty(o)&&this.parser.normalizeLists&&uo(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,n));e:if(a?a.ignore:fo.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let c,f=this.needsBlock;if(Di.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),c=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let d=a&&a.skip?t:this.readStyles(e,t);d&&this.addAll(e,d),c&&this.sync(s),this.needsBlock=f}else{let c=this.readStyles(e,t);c&&this.addElementByRule(e,a,c,a.consuming===!1?l:void 0)}this.localPreserveWS=i}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` `),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let i=0;i!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)||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));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){let n,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!n||n.length>l.length)&&(n=l,i=o,!l.length)||o.solid)break}if(!n)return null;this.sync(i);for(let s=0;s(o.type?o.type.allowsMarkType(c.type):hr(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|=ut)}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 uo(r){for(let e=r.firstChild,t=null;e;e=e.nextSibling){let n=e.nodeType==1?e.nodeName.toLowerCase():null;n&&Ri.hasOwnProperty(n)&&t?(t.appendChild(e),e=t):n=="li"?t=e:n&&(t=null)}}function ho(r,e){return(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,e)}function ur(r){let e={};for(let t in r)e[t]=r[t];return e}function hr(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&&Nt(nn(n),i(e,t),null,e.attrs)}static renderSpec(e,t,n=null,i){return Nt(e,t,n,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new $e(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=pr(e.nodes);return t.text||(t.text=n=>n.text),t}static marksFromSchema(e){return pr(e.marks)}}function pr(r){let e={};for(let t in r){let n=r[t].spec.toDOM;n&&(e[t]=n)}return e}function nn(r){return r.document||window.document}const mr=new WeakMap;function po(r){let e=mr.get(r);return e===void 0&&mr.set(r,e=mo(r)),e}function mo(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 d in c)if(c[d]!=null){let u=d.indexOf(" ");u>0?a.setAttributeNS(d.slice(0,u),d.slice(u+1),c[d]):a.setAttribute(d,c[d])}}for(let d=f;df)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:p,contentDOM:h}=Nt(r,u,t,n);if(a.appendChild(p),h){if(l)throw new RangeError("Multiple content holes");l=h}}}return{dom:a,contentDOM:l}}const Ii=65535,Pi=Math.pow(2,16);function go(r,e){return r+e*Pi}function gr(r){return r&Ii}function yo(r){return(r-(r&Ii))/Pi}const Bi=1,zi=2,Et=4,vi=8;class wn{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&vi)>0}get deletedBefore(){return(this.delInfo&(Bi|Et))>0}get deletedAfter(){return(this.delInfo&(zi|Et))>0}get deletedAcross(){return(this.delInfo&Et)>0}}class j{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&j.empty)return j.empty}recover(e){let t=0,n=gr(e);if(!this.inverted)for(let i=0;ie)break;let c=this.ranges[l+s],f=this.ranges[l+o],d=a+c;if(e<=d){let u=c?e==a?-1:e==d?1:t:t,p=a+i+(u<0?0:f);if(n)return p;let h=e==(t<0?a:d)?null:go(l/3,e-a),m=e==a?zi:e==d?Bi:Et;return(t<0?e!=a:e!=d)&&(m|=vi),new wn(p,m,h)}i+=f-c}return n?e+i:new wn(e+i,0,null)}touches(e,t){let n=0,i=gr(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 at;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 A.fromReplace(e,this.from,this.to,s)}invert(){return new ne(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 ge(t.pos,n.pos,this.mark)}merge(e){return e instanceof ge&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ge(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 ge(t.from,t.to,e.markFromJSON(t.mark))}}$.jsonID("addMark",ge);class ne 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 k($n(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return A.fromReplace(e,this.from,this.to,n)}invert(){return new ge(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 ne(t.pos,n.pos,this.mark)}merge(e){return e instanceof ne&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ne(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 ne(t.from,t.to,e.markFromJSON(t.mark))}}$.jsonID("removeMark",ne);class ye extends ${constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return A.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return A.fromReplace(e,this.pos,this.pos+1,new k(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 I(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 I(t.from,t.to,t.gapFrom,t.gapTo,k.fromJSON(e,t.slice),t.insert,!!t.structure)}}$.jsonID("replaceAround",I);function On(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 bo(r,e,t,n){let i=[],s=[],o,l;r.doc.nodesBetween(e,t,(a,c,f)=>{if(!a.isInline)return;let d=a.marks;if(!n.isInSet(d)&&f.type.allowsMarkType(n.type)){let u=Math.max(c,e),p=Math.min(c+a.nodeSize,t),h=n.addToSet(d);for(let m=0;mr.step(a)),s.forEach(a=>r.step(a))}function ko(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 Kt){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 ne(o.from,o.to,o.style)))}function Wn(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 So(r,e,t){return(e==0||r.canReplace(e,r.childCount))&&(t==r.childCount||r.canReplace(0,t))}function tt(r){let t=r.parent.content.cutByIndex(r.startIndex,r.endIndex);for(let n=r.depth;;--n){let i=r.$from.node(n),s=r.$from.index(n),o=r.$to.indexAfter(n);if(nt;h--)m||n.index(h)>0?(m=!0,f=y.from(n.node(h).copy(f)),d++):a--;let u=y.empty,p=0;for(let h=s,m=!1;h>t;h--)m||i.after(h+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 I(i,s,i,s,new k(n,0,0),t.length,!0))}function Oo(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)&&To(r.doc,r.mapping.slice(s).map(l),n)){let c=null;if(n.schema.linebreakReplacement){let p=n.whitespace=="pre",h=!!n.contentMatch.matchType(n.schema.linebreakReplacement);p&&!h?c=!1:!p&&h&&(c=!0)}c===!1&&Li(r,o,l,s),Wn(r,r.mapping.slice(s).map(l,1),n,void 0,c===null);let f=r.mapping.slice(s),d=f.map(l,1),u=f.map(l+o.nodeSize,1);return r.step(new I(d,u,d+1,u-1,new k(y.from(n.create(a,null,o.marks)),0,0),1,!0)),c===!0&&Fi(r,o,l,s),!1}})}function Fi(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 Li(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 To(r,e,t){let n=r.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,t)}function No(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 I(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new k(y.from(o),0,0),1,!0))}function Ue(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 d=i.node(c),u=i.index(c);if(d.type.spec.isolating)return!1;let p=d.content.cutByIndex(u,d.childCount),h=n&&n[f+1];h&&(p=p.replaceChild(0,h.type.create(h.attrs)));let m=n&&n[f]||d;if(!d.canReplace(u+1,d.childCount)||!m.type.validContent(p))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 Eo(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 z(e,e,new k(s.append(o),t,t),!0))}function we(r,e){let t=r.resolve(e),n=t.index();return Vi(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(n,n+1)}function Ao(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;i0?(s=n.node(i+1),l++,o=n.node(i).maybeChild(l)):(s=n.node(i).maybeChild(l-1),o=n.node(i+1)),s&&!s.isTextblock&&Vi(s,o)&&n.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?n.before(i):n.after(i)}}function Do(r,e,t){let n=null,{linebreakReplacement:i}=r.doc.type.schema,s=r.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let f=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);f&&!d?n=!1:!f&&d&&(n=!0)}let l=r.steps.length;if(n===!1){let f=r.doc.resolve(e+t);Li(r,f.node(),f.before(),l)}o.inlineContent&&Wn(r,e+t-1,o,s.node().contentMatchAt(s.index()),n==null);let a=r.mapping.slice(l),c=a.map(e-t);if(r.step(new z(c,a.map(e+t,-1),k.empty,!0)),n===!0){let f=r.doc.resolve(c);Fi(r,f.node(),f.before(),r.steps.length)}return r}function Ro(r,e,t){let n=r.resolve(e);if(n.parent.canReplaceWith(n.index(),n.index(),t))return e;if(n.parentOffset==0)for(let i=n.depth-1;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 d=c.contentMatchAt(a).findWrapping(i.firstChild.type);f=d&&c.canReplaceWith(a,a,d[0])}if(f)return l==0?n.pos:l<0?n.before(o+1):n.after(o+1)}return null}function Hn(r,e,t=e,n=k.empty){if(e==t&&!n.size)return null;let i=r.resolve(e),s=r.resolve(t);return Wi(i,s,n)?new z(e,t,n):new Po(i,s,n).fit()}function Wi(r,e,t){return!t.openStart&&!t.openEnd&&r.start()==e.start()&&r.parent.canReplace(r.index(),e.index(),t.content)}class Po{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 k(s,o,l);return e>-1?new I(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new z(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=sn(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,d=null;if(t==1&&(o?c.matchType(o.type)||(d=c.fillBefore(y.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:n,frontierDepth:l,parent:s,inject:d};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=sn(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new k(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=sn(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new k(rt(e,t-1,1),t-1,s?t-1:n)}else this.unplaced=new k(rt(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)&&(d=g,f.push(Ji(m.mark(u.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?p:-1)))}let h=c==l.childCount;h||(p=-1),this.placed=it(this.placed,t,y.from(f)),this.frontier[t].match=d,h&&p<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=on(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=it(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=it(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=it(this.placed,this.frontier.length,t))}}function rt(r,e,t){return e==0?r.cutByIndex(t,r.childCount):r.replaceChild(0,r.firstChild.copy(rt(r.firstChild.content,e-1,t)))}function it(r,e,t){return e==0?r.append(t):r.replaceChild(r.childCount-1,r.lastChild.copy(it(r.lastChild.content,e-1,t)))}function sn(r,e){for(let t=0;t1&&(n=n.replaceChild(0,Ji(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 on(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&&!Bo(t,s.content,o)?l:null}function Bo(r,e,t){for(let n=t;n0;u--,p--){let h=i.node(u).type.spec;if(h.defining||h.definingAsContext||h.isolating)break;o.indexOf(u)>-1?l=u:i.before(u)==p&&o.splice(1,0,-u)}let a=o.indexOf(l),c=[],f=n.openStart;for(let u=n.content,p=0;;p++){let h=u.firstChild;if(c.push(h),p==n.openStart)break;u=h.content}for(let u=f-1;u>=0;u--){let p=c[u],h=zo(p.type);if(h&&!p.sameMarkup(i.node(Math.abs(l)-1)))f=u;else if(h||!p.type.isTextblock)break}for(let u=n.openStart;u>=0;u--){let p=(u+f+1)%(n.openStart+1),h=c[p];if(h)for(let m=0;m=0&&(r.replace(e,t,n),!(r.steps.length>d));u--){let p=o[u];p<0||(e=i.before(p),t=s.after(p))}}function Hi(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 Fo(r,e,t,n){if(!n.isInline&&e==t&&r.doc.resolve(e).parent.content.size){let i=Ro(r.doc,e,n.type);i!=null&&(e=t=i)}r.replaceRange(e,t,new k(y.from(n),0,0))}function Lo(r,e,t){let n=r.doc.resolve(e),i=r.doc.resolve(t),s=qi(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 qi(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 Ge 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 A.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 A.fromReplace(e,this.pos,this.pos+1,new k(y.from(i),0,t.isLeaf?0:1))}getMap(){return j.empty}invert(e){return new Ge(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 Ge(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 Ge(t.pos,t.attr,t.value)}}$.jsonID("attr",Ge);class ht 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 A.ok(n)}getMap(){return j.empty}invert(e){return new ht(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 ht(t.attr,t.value)}}$.jsonID("docAttr",ht);let Ze=class extends Error{};Ze=function r(e){let t=Error.call(this,e);return t.__proto__=r.prototype,t};Ze.prototype=Object.create(Error.prototype);Ze.prototype.constructor=Ze;Ze.prototype.name="TransformError";class Ki{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new at}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Ze(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=k.empty){let i=Hn(this.doc,e,t,n);return i&&this.step(i),this}replaceWith(e,t,n){return this.replace(e,t,new k(y.from(n),0,0))}delete(e,t){return this.replace(e,t,k.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return vo(this,e,t,n),this}replaceRangeWith(e,t,n){return Fo(this,e,t,n),this}deleteRange(e,t){return Lo(this,e,t),this}lift(e,t){return xo(this,e,t),this}join(e,t=1){return Do(this,e,t),this}wrap(e,t){return wo(this,e,t),this}setBlockType(e,t=e,n,i=null){return Oo(this,e,t,n,i),this}setNodeMarkup(e,t,n=null,i){return No(this,e,t,n,i),this}setNodeAttribute(e,t,n){return this.step(new Ge(e,t,n)),this}setDocAttribute(e,t){return this.step(new ht(e,t)),this}addNodeMark(e,t){return this.step(new ye(e,t)),this}removeNodeMark(e,t){if(!(t instanceof N)){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t=t.isInSet(n.marks),!t)return this}return this.step(new Xe(e,t)),this}split(e,t=1,n){return Eo(this,e,t,n),this}addMark(e,t,n){return bo(this,e,t,n),this}removeMark(e,t,n){return ko(this,e,t,n),this}clearIncompatible(e,t,n){return Wn(this,e,t,n),this}}const ln=Object.create(null);class C{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Vo(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?qe(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):qe(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 Z(e.node(0))}static atStart(e){return qe(e,e,0,0,1)||new Z(e)}static atEnd(e){return qe(e,e,e.content.size,e.childCount,-1)||new Z(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=ln[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 ln)throw new RangeError("Duplicate use of selection JSON ID "+e);return ln[e]=t,t.prototype.jsonID=e,t}getBookmark(){return w.between(this.$anchor,this.$head).getBookmark()}}C.prototype.visible=!0;class Vo{constructor(e,t){this.$from=e,this.$to=t}}let br=!1;function kr(r){!br&&!r.parent.inlineContent&&(br=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+r.parent.type.name+")"))}class w extends C{constructor(e,t=e){kr(e),kr(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 w(i.parent.inlineContent?i:n,n)}replace(e,t=k.empty){if(super.replace(e,t),t==k.empty){let n=this.$from.marksAcross(this.$to);n&&e.ensureMarks(n)}}eq(e){return e instanceof w&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new jt(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 w(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&&x.isSelectable(l))return x.create(r,t-(i<0?l.nodeSize:0))}else{let a=qe(r,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function Sr(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 xr=1,Tt=2,Mr=4;class Wo extends Ki{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 N.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)||N.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),n=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.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|=Mr,this}get scrolledIntoView(){return(this.updated&Mr)>0}}function Cr(r,e){return!e||!r?r:r.bind(e)}class st{constructor(e,t,n){this.name=e,this.init=Cr(t.init,n),this.apply=Cr(t.apply,n)}}const Jo=[new st("doc",{init(r){return r.doc||r.schema.topNodeType.createAndFill()},apply(r){return r.doc}}),new st("selection",{init(r,e){return r.selection||C.atStart(e.doc)},apply(r){return r.selection}}),new st("storedMarks",{init(r){return r.storedMarks||null},apply(r,e,t,n){return n.selection.$cursor?r.storedMarks:null}}),new st("scrollToSelection",{init(){return 0},apply(r,e){return r.scrolledIntoView?e+1:e}})];class an{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Jo.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 st(n.key,n.spec.state,n))})}}class je{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 an(e.schema,e.plugins),s=new je(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Be.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 ji(r,e,t){for(let n in r){let i=r[n];i instanceof Function?i=i.bind(e):n=="handleDOMEvents"&&(i=ji(i,e,{})),t[n]=i}return t}class Oe{constructor(e){this.spec=e,this.props={},e.props&&ji(e.props,this,this.props),this.key=e.key?e.key.key:Ui("plugin")}getState(e){return e[this.key]}}const cn=Object.create(null);function Ui(r){return r in cn?r+"$"+ ++cn[r]:(cn[r]=0,r+"$")}class kt{constructor(e="key"){this.key=Ui(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const v=function(r){for(var e=0;;e++)if(r=r.previousSibling,!r)return e},pt=function(r){let e=r.assignedSlot||r.parentNode;return e&&e.nodeType==11?e.host:e};let Tn=null;const le=function(r,e,t){let n=Tn||(Tn=document.createRange());return n.setEnd(r,t??r.nodeValue.length),n.setStart(r,e||0),n},Ho=function(){Tn=null},Le=function(r,e,t,n){return t&&(wr(r,e,t,n,-1)||wr(r,e,t,n,1))},qo=/^(img|br|input|textarea|hr)$/i;function wr(r,e,t,n,i){for(;;){if(r==t&&e==n)return!0;if(e==(i<0?0:Y(r))){let s=r.parentNode;if(!s||s.nodeType!=1||St(r)||qo.test(r.nodeName)||r.contentEditable=="false")return!1;e=v(r)+(i<0?0:1),r=s}else if(r.nodeType==1){if(r=r.childNodes[e+(i<0?-1:0)],r.contentEditable=="false")return!1;e=i<0?Y(r):0}else return!1}}function Y(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function Ko(r,e){for(;;){if(r.nodeType==3&&e)return r;if(r.nodeType==1&&e>0){if(r.contentEditable=="false")return null;r=r.childNodes[e-1],e=Y(r)}else if(r.parentNode&&!St(r))e=v(r),r=r.parentNode;else return null}}function jo(r,e){for(;;){if(r.nodeType==3&&e2),G=Qe||(re?/Mac/.test(re.platform):!1),_o=re?/Win/.test(re.platform):!1,ae=/Android \d/.test(Te),xt=!!Or&&"webkitFontSmoothing"in Or.documentElement.style,Xo=xt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Zo(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 oe(r,e){return typeof r=="number"?r:r[e]}function Qo(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 Tr(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;o=pt(o)){if(o.nodeType!=1)continue;let l=o,a=l==s.body,c=a?Zo(s):Qo(l),f=0,d=0;if(e.topc.bottom-oe(n,"bottom")&&(d=e.bottom-e.top>c.bottom-c.top?e.top+oe(i,"top")-c.top:e.bottom-c.bottom+oe(i,"bottom")),e.leftc.right-oe(n,"right")&&(f=e.right-c.right+oe(i,"right")),f||d)if(a)s.defaultView.scrollBy(f,d);else{let u=l.scrollLeft,p=l.scrollTop;d&&(l.scrollTop+=d),f&&(l.scrollLeft+=f);let h=l.scrollLeft-u,m=l.scrollTop-p;e={left:e.left-h,top:e.top-m,right:e.right-h,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function el(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:_i(r.dom)}}function _i(r){let e=[],t=r.ownerDocument;for(let n=r;n&&(e.push({dom:n,top:n.scrollTop,left:n.scrollLeft}),r!=t);n=pt(n));return e}function tl({refDOM:r,refTop:e,stack:t}){let n=r?r.getBoundingClientRect().top:0;Xi(t,n==0?0:n-e)}function Xi(r,e){for(let t=0;t=l){o=Math.max(h.bottom,o),l=Math.min(h.top,l);let m=h.left>e.left?h.left-e.left:h.right=(h.left+h.right)/2?1:0));continue}}else h.top>e.top&&!a&&h.left<=e.left&&h.right>=e.left&&(a=f,c={left:Math.max(h.left,Math.min(h.right,e.left)),top:h.top});!t&&(e.left>=h.right&&e.top>=h.top||e.left>=h.left&&e.top>=h.bottom)&&(s=d+1)}}return!t&&a&&(t=a,i=c,n=0),t&&t.nodeType==3?rl(t,i):!t||n&&t.nodeType==1?{node:r,offset:s}:Zi(t,i)}function rl(r,e){let t=r.nodeValue.length,n=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:r,offset:0}}function Kn(r,e){return r.left>=e.left-1&&r.left<=e.right+1&&r.top>=e.top-1&&r.top<=e.bottom+1}function il(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 ol(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&&(!o&&a.left>n.left||a.top>n.top?i=l.posBefore:(!o&&a.right-1?i:r.docView.posFromDOM(e,t,-1)}function Qi(r,e,t){let n=r.childNodes.length;if(n&&t.tope.top&&i++}let c;xt&&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=ol(r,n,i,e))}l==null&&(l=sl(r,o,e));let a=r.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Nr(r){return r.top=0&&i==n.nodeValue.length?(a--,f=1):t<0?a--:c++,nt(he(le(n,a,c),f),f<0)}if(!r.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==Y(n))){let a=n.childNodes[i-1];if(a.nodeType==1)return fn(a.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==Y(n))){let a=n.childNodes[i-1],c=a.nodeType==3?le(a,Y(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return nt(he(c,1),!1)}if(s==null&&i=0)}function nt(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 fn(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 ts(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 cl(r,e,t){let n=e.selection,i=t=="up"?n.$from:n.$to;return ts(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=es(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=le(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 fl=/[\u0590-\u08ac]/;function dl(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?!fl.test(n.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:ts(r,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:f,anchorOffset:d}=r.domSelectionRange(),u=l.caretBidiLevel;l.modify("move",t,"character");let p=n.depth?r.docView.domAfterPos(n.before()):r.dom,{focusNode:h,focusOffset:m}=r.domSelectionRange(),g=h&&!p.contains(h.nodeType==1?h:h.parentNode)||a==h&&c==m;try{l.collapse(f,d),a&&(a!=f||c!=d)&&l.extend&&l.extend(a,c)}catch{}return u!=null&&(l.caretBidiLevel=u),g}):n.pos==n.start()||n.pos==n.end()}let Er=null,Ar=null,Dr=!1;function ul(r,e,t){return Er==e&&Ar==t?Dr:(Er=e,Ar=t,Dr=t=="up"||t=="down"?cl(r,e,t):dl(r,e,t))}const _=0,Rr=1,Ae=2,ie=3;class Mt{constructor(e,t,n,i){this.parent=e,this.children=t,this.dom=n,this.contentDOM=i,this.dirty=_,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;tv(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 rs){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 ns&&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?v(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 d=l;d>0;d--){let u=this.children[d-1];if(u.size&&u.dom.parentNode==this.contentDOM&&!u.emptyChildAt(1)){i=v(u.dom)+1;break}e-=u.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let f=l+1;fh&&ot){let h=l;l=a,a=h}let p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(p)}}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?Ae:Rr,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=ie:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Ae:ie}n=o}this.dirty=Ae}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Ae:Rr;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==_&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class hl 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 Ve 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=$e.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new Ve(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&ie||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ie&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=_){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,d=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:d}=$e.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!d&&!t.isText&&f.nodeName!="BR"&&(f.hasAttribute("contenteditable")||(f.contentEditable="false"),t.type.spec.draggable&&(f.draggable=!0));let u=f;return f=ls(f,n,t),c?a=new pl(e,t,n,i,f,d||null,u,c,s,o+1):t.isText?new Gt(e,t,n,i,f,u,s):new Se(e,t,n,i,f,d||null,u,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==_&&e.eq(this.node)&&zt(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 gl(this,o&&o.node,e);kl(this.node,this.innerDeco,(c,f,d)=>{c.spec.marks?a.syncToMarks(c.spec.marks,n,e):c.type.side>=0&&!d&&a.syncToMarks(f==this.node.childCount?N.none:this.node.child(f).marks,n,e),a.placeWidget(c,e,i)},(c,f,d,u)=>{a.syncToMarks(c.marks,n,e);let p;a.findNodeMatch(c,f,d,u)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(c,f,d,p,e)||a.updateNextNode(c,f,d,e,u,i)||a.addNode(c,f,d,e,i),i+=c.nodeSize}),a.syncToMarks([],n,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Ae)&&(o&&this.protectLocalComposition(e,o),is(this.contentDOM,this.children,e),Qe&&Sl(this.dom))}localCompositionInfo(e,t){let{from:n,to:i}=e.state.selection;if(!(e.state.selection instanceof w)||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=xl(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 hl(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==ie||!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=_}updateOuterDeco(e){if(zt(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,n=this.dom;this.dom=ss(this.dom,this.nodeDOM,Dn(this.outerDeco,this.node,t),Dn(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.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Ir(r,e,t,n,i){ls(n,e,r);let s=new Se(void 0,r,e,t,n,n,n,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class Gt extends Se{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==ie||this.dirty!=_&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=_||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=_,!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 Gt(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=ie)}get domAtom(){return!1}isText(e){return this.node.text==e}}class rs extends Mt{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==_&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class pl extends Se{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==ie)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 is(r,e,t){let n=r.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=Ve.create(this.top,e[s],t,n);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,s++}}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 Ve)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 bl(r,e){return r.type.side-e.type.side}function kl(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 h=s+u.nodeSize;if(u.isText){let g=h;o!g.inline):l.slice();n(u,m,e.forChild(s,u),p),s=h}}function Sl(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 xl(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 jn(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(Ut(t)){for(a=o;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&x.isSelectable(d)&&i.parent&&!(d.isInline&&Uo(t.focusNode,t.focusOffset,i.dom))){let u=i.posBefore;c=new x(o==u?l:n.resolve(u))}}else{if(t instanceof r.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let d=o,u=o;for(let p=0;p{(t.anchorNode!=n||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",r.input.hideSelectionGuard),setTimeout(()=>{(!as(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})}function Cl(r){let e=r.domSelection(),t=document.createRange();if(!e)return;let n=r.cursorWrapper.dom,i=n.nodeName=="IMG";i?t.setStart(n.parentNode,v(n)+1):t.setStart(n,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!r.state.selection.visible&&K&&ke<=11&&(n.disabled=!0,n.disabled=!1)}function cs(r,e){if(e instanceof x){let t=r.docView.descAt(e.from);t!=r.lastSelectedViewDesc&&(Fr(r),t&&t.selectNode(),r.lastSelectedViewDesc=t)}else Fr(r)}function Fr(r){r.lastSelectedViewDesc&&(r.lastSelectedViewDesc.parent&&r.lastSelectedViewDesc.deselectNode(),r.lastSelectedViewDesc=void 0)}function Un(r,e,t,n){return r.someProp("createSelectionBetween",i=>i(r,e,t))||w.between(e,t,n)}function Lr(r){return r.editable&&!r.hasFocus()?!1:fs(r)}function fs(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 wl(r){let e=r.docView.domFromPos(r.state.selection.anchor,0),t=r.domSelectionRange();return Le(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 pe(r,e){return r.dispatch(r.state.tr.setSelection(e).scrollIntoView()),!0}function Vr(r,e,t){let n=r.state.selection;if(n instanceof w)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 pe(r,new w(n.$anchor,o))}else if(n.empty){if(r.endOfTextblock(e>0?"forward":"backward")){let i=In(r.state,e);return i&&i instanceof x?pe(r,i):!1}else if(!(G&&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?x.isSelectable(s)?pe(r,new x(e<0?r.state.doc.resolve(i.pos-s.nodeSize):i)):xt?pe(r,new w(r.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(n instanceof x&&n.node.isInline)return pe(r,new w(e>0?n.$to:n.$from));{let i=In(r.state,e);return i?pe(r,i):!1}}}function vt(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}function ft(r,e){let t=r.pmViewDesc;return t&&t.size==0&&(e<0||r.nextSibling||r.nodeName!="BR")}function He(r,e){return e<0?Ol(r):Tl(r)}function Ol(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i,s,o=!1;for(Q&&t.nodeType==1&&n0){if(t.nodeType!=1)break;{let l=t.childNodes[n-1];if(ft(l,-1))i=t,s=--n;else if(l.nodeType==3)t=l,n=t.nodeValue.length;else break}}else{if(ds(t))break;{let l=t.previousSibling;for(;l&&ft(l,-1);)i=t.parentNode,s=v(l),l=l.previousSibling;if(l)t=l,n=vt(t);else{if(t=t.parentNode,t==r.dom)break;n=0}}}o?Pn(r,t,n):i&&Pn(r,i,s)}function Tl(r){let e=r.domSelectionRange(),t=e.focusNode,n=e.focusOffset;if(!t)return;let i=vt(t),s,o;for(;;)if(n{r.state==i&&fe(r)},50)}function $r(r,e){let t=r.state.doc.resolve(e);if(!(V||_o)&&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 Wr(r,e,t){let n=r.state.selection;if(n instanceof w&&!n.empty||t.indexOf("s")>-1||G&&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 x)return pe(r,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=n instanceof Z?C.near(o,e):C.findFrom(o,e);return l?pe(r,l):!1}return!1}function Jr(r,e){if(!(r.state.selection instanceof w))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 Hr(r,e,t){r.domObserver.stop(),e.contentEditable=t,r.domObserver.start()}function Al(r){if(!J||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;Hr(r,n,"true"),setTimeout(()=>Hr(r,n,"false"),20)}return!1}function Dl(r){let e="";return r.ctrlKey&&(e+="c"),r.metaKey&&(e+="m"),r.altKey&&(e+="a"),r.shiftKey&&(e+="s"),e}function Rl(r,e){let t=e.keyCode,n=Dl(e);if(t==8||G&&t==72&&n=="c")return Jr(r,-1)||He(r,-1);if(t==46&&!e.shiftKey||G&&t==68&&n=="c")return Jr(r,1)||He(r,1);if(t==13||t==27)return!0;if(t==37||G&&t==66&&n=="c"){let i=t==37?$r(r,r.state.selection.from)=="ltr"?-1:1:-1;return Vr(r,i,n)||He(r,i)}else if(t==39||G&&t==70&&n=="c"){let i=t==39?$r(r,r.state.selection.from)=="ltr"?1:-1:1;return Vr(r,i,n)||He(r,i)}else{if(t==38||G&&t==80&&n=="c")return Wr(r,-1,n)||He(r,-1);if(t==40||G&&t==78&&n=="c")return Al(r)||Wr(r,1,n)||He(r,1);if(n==(G?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function us(r,e){r.someProp("transformCopied",p=>{e=p(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 p=n.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),n=p.content}let o=r.someProp("clipboardSerializer")||$e.fromSchema(r.state.schema),l=bs(),a=l.createElement("div");a.appendChild(o.serializeFragment(n,{document:l}));let c=a.firstChild,f,d=0;for(;c&&c.nodeType==1&&(f=ys[c.nodeName.toLowerCase()]);){for(let p=f.length-1;p>=0;p--){let h=l.createElement(f[p]);for(;a.firstChild;)h.appendChild(a.firstChild);a.appendChild(h),d++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let u=r.someProp("clipboardTextSerializer",p=>p(e,r))||e.content.textBetween(0,e.content.size,` `);return{dom:a,text:u,slice:e}}function hs(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",u=>{e=u(e,s||n,r)}),s)return e?new k(y.from(r.state.schema.text(e.replace(/\r\n?/g,` `))),0,0):k.empty;let d=r.someProp("clipboardTextParser",u=>u(e,i,n,r));if(d)l=d;else{let u=i.marks(),{schema:p}=r.state,h=$e.fromSchema(p);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(h.serializeNode(p.text(m,u)))})}}else r.someProp("transformPastedHTML",d=>{t=d(t,r)}),o=zl(t),xt&&vl(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 d=+f[3];d>0;d--){let u=o.firstChild;for(;u&&u.nodeType!=1;)u=u.nextSibling;if(!u)break;o=u}if(l||(l=(r.someProp("clipboardParser")||r.someProp("domParser")||_e.fromSchema(r.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||f),context:i,ruleFromNode(u){return u.nodeName=="BR"&&!u.nextSibling&&u.parentNode&&!Il.test(u.parentNode.nodeName)?{ignore:!0}:null}})),f)l=Fl(qr(l,+f[1],+f[2]),f[4]);else if(l=k.maxOpen(Pl(l.content,i),!0),l.openStart||l.openEnd){let d=0,u=0;for(let p=l.content.firstChild;d{l=d(l,r)}),l}const Il=/^(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 Pl(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&&ms(a,s,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=gs(o[o.length-1],s.length));let f=ps(l,a);o.push(f),i=i.matchType(f.type),s=a}}),o)return y.from(o)}return r}function ps(r,e,t=0){for(let n=e.length-1;n>=t;n--)r=e[n].create(null,y.from(r));return r}function ms(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 qr(r,e,t){return et})),un.createHTML(r)):r}function zl(r){let e=/^(\s*]*>)*/.exec(r);e&&(r=r.slice(e[0].length));let t=bs().createElement("div"),n=/<([a-z][^>\s]+)/i.exec(r),i;if((i=n&&ys[n[1].toLowerCase()])&&(r=i.map(s=>"<"+s+">").join("")+r+i.map(s=>"").reverse().join("")),t.innerHTML=Bl(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 k(i,s,o)}const H={},q={},Ll={touchstart:!0,touchmove:!0};class Vl{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function $l(r){for(let e in H){let t=H[e];r.dom.addEventListener(e,r.input.eventHandlers[e]=n=>{Jl(r,n)&&!Gn(r,n)&&(r.editable||!(n.type in q))&&t(r,n)},Ll[e]?{passive:!0}:void 0)}J&&r.dom.addEventListener("input",()=>null),zn(r)}function be(r,e){r.input.lastSelectionOrigin=e,r.input.lastSelectionTime=Date.now()}function Wl(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 zn(r){r.someProp("handleDOMEvents",e=>{for(let t in e)r.input.eventHandlers[t]||r.dom.addEventListener(t,r.input.eventHandlers[t]=n=>Gn(r,n))})}function Gn(r,e){return r.someProp("handleDOMEvents",t=>{let n=t[e.type];return n?n(r,e)||e.defaultPrevented:!1})}function Jl(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 Hl(r,e){!Gn(r,e)&&H[e.type]&&(r.editable||!(e.type in q))&&H[e.type](r,e)}q.keydown=(r,e)=>{let t=e;if(r.input.shiftKey=t.keyCode==16||t.shiftKey,!Ss(r,t)&&(r.input.lastKeyCode=t.keyCode,r.input.lastKeyCodeTime=Date.now(),!(ae&&V&&t.keyCode==13)))if(t.keyCode!=229&&r.domObserver.forceFlush(),Qe&&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))||Rl(r,t)?t.preventDefault():be(r,"key")};q.keyup=(r,e)=>{e.keyCode==16&&(r.input.shiftKey=!1)};q.keypress=(r,e)=>{let t=e;if(Ss(r,t)||!t.charCode||t.ctrlKey&&!t.altKey||G&&t.metaKey)return;if(r.someProp("handleKeyPress",i=>i(r,t))){t.preventDefault();return}let n=r.state.selection;if(!(n instanceof w)||!n.$from.sameParent(n.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!r.someProp("handleTextInput",s=>s(r,n.$from.pos,n.$to.pos,i))&&r.dispatch(r.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function Yt(r){return{left:r.clientX,top:r.clientY}}function ql(r,e){let t=e.x-r.clientX,n=e.y-r.clientY;return t*t+n*n<100}function Yn(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);t=="pointer"&&n.setMeta("pointer",!0),r.dispatch(n)}function Kl(r,e){if(e==-1)return!1;let t=r.state.doc.resolve(e),n=t.nodeAfter;return n&&n.isAtom&&x.isSelectable(n)?(Ye(r,new x(t),"pointer"),!0):!1}function jl(r,e){if(e==-1)return!1;let t=r.state.selection,n,i;t instanceof x&&(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(x.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,x.create(r.state.doc,i),"pointer"),!0):!1}function Ul(r,e,t,n,i){return Yn(r,"handleClickOn",e,t,n)||r.someProp("handleClick",s=>s(r,e,n))||(i?jl(r,t):Kl(r,t))}function Gl(r,e,t,n){return Yn(r,"handleDoubleClickOn",e,t,n)||r.someProp("handleDoubleClick",i=>i(r,e,n))}function Yl(r,e,t,n){return Yn(r,"handleTripleClickOn",e,t,n)||r.someProp("handleTripleClick",i=>i(r,e,n))||_l(r,t,n)}function _l(r,e,t){if(t.button!=0)return!1;let n=r.state.doc;if(e==-1)return n.inlineContent?(Ye(r,w.create(n,0,n.content.size),"pointer"),!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,w.create(n,l+1,l+1+o.content.size),"pointer");else if(x.isSelectable(o))Ye(r,x.create(n,l),"pointer");else continue;return!0}}function _n(r){return Ft(r)}const ks=G?"metaKey":"ctrlKey";H.mousedown=(r,e)=>{let t=e;r.input.shiftKey=t.shiftKey;let n=_n(r),i=Date.now(),s="singleClick";i-r.input.lastClick.time<500&&ql(t,r.input.lastClick)&&!t[ks]&&(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};let o=r.posAtCoords(Yt(t));o&&(s=="singleClick"?(r.input.mouseDown&&r.input.mouseDown.done(),r.input.mouseDown=new Xl(r,o,t,!!n)):(s=="doubleClick"?Gl:Yl)(r,o.pos,o.inside,t)?t.preventDefault():be(r,"pointer"))};class Xl{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[ks],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.dom.nodeType==1?a.dom:null;let{selection:c}=e.state;(n.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof x&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Q&&!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)),be(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(()=>fe(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(Yt(e))),this.updateAllowDefault(e),this.allowDefault||!t?be(this.view,"pointer"):Ul(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||J&&this.mightDrag&&!this.mightDrag.node.isAtom||V&&!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)),"pointer"),e.preventDefault()):be(this.view,"pointer")}move(e){this.updateAllowDefault(e),be(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)}}H.touchstart=r=>{r.input.lastTouch=Date.now(),_n(r),be(r,"pointer")};H.touchmove=r=>{r.input.lastTouch=Date.now(),be(r,"pointer")};H.contextmenu=r=>_n(r);function Ss(r,e){return r.composing?!0:J&&Math.abs(e.timeStamp-r.input.compositionEndedAt)<500?(r.input.compositionEndedAt=-2e8,!0):!1}const Zl=ae?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 w&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(n=>n.type.spec.inclusive===!1)))r.markCursor=r.state.storedMarks||t.marks(),Ft(r,!0),r.markCursor=null;else if(Ft(r,!e.selection.empty),Q&&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}xs(r,Zl)};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.compositionPendingChanges&&Promise.resolve().then(()=>r.domObserver.flush()),r.input.compositionID++,xs(r,20))};function xs(r,e){clearTimeout(r.input.composingTimeout),e>-1&&(r.input.composingTimeout=setTimeout(()=>Ft(r),e))}function Ms(r){for(r.composing&&(r.input.composing=!1,r.input.compositionEndedAt=ea());r.input.compositionNodes.length>0;)r.input.compositionNodes.pop().markParentsDirty()}function Ql(r){let e=r.domSelectionRange();if(!e.focusNode)return null;let t=Ko(e.focusNode,e.focusOffset),n=jo(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 ea(){let r=document.createEvent("Event");return r.initEvent("event",!0,!0),r.timeStamp}function Ft(r,e=!1){if(!(ae&&r.domObserver.flushingSoon>=0)){if(r.domObserver.forceFlush(),Ms(r),e||r.docView&&r.docView.dirty){let t=jn(r);return t&&!t.eq(r.state.selection)?r.dispatch(r.state.tr.setSelection(t)):(r.markCursor||e)&&!r.state.selection.empty?r.dispatch(r.state.tr.deleteSelection()):r.updateState(r.state),!0}return!1}}function ta(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 mt=K&&ke<15||Qe&&Xo<604;H.copy=q.cut=(r,e)=>{let t=e,n=r.state.selection,i=t.type=="cut";if(n.empty)return;let s=mt?null:t.clipboardData,o=n.content(),{dom:l,text:a}=us(r,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):ta(r,l),i&&r.dispatch(r.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function na(r){return r.openStart==0&&r.openEnd==0&&r.content.childCount==1?r.content.firstChild:null}function ra(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?gt(r,n.value,null,i,e):gt(r,n.textContent,n.innerHTML,i,e)},50)}function gt(r,e,t,n,i){let s=hs(r,e,t,n,r.state.selection.$from);if(r.someProp("handlePaste",a=>a(r,i,s||k.empty)))return!0;if(!s)return!1;let o=na(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 Cs(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&&!ae)return;let n=mt?null:t.clipboardData,i=r.input.shiftKey&&r.input.lastKeyCode!=45;n&>(r,Cs(n),n.getData("text/html"),i,t)?t.preventDefault():ra(r,t)};class ws{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const Os=G?"altKey":"ctrlKey";H.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(Yt(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof x?i.to-1:i.to))){if(n&&n.mightDrag)o=x.create(r.state.doc,n.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let d=r.docView.nearestDesc(t.target,!0);d&&d.node.type.spec.draggable&&d!=r.docView&&(o=x.create(r.state.doc,d.posBefore))}}let l=(o||r.state.selection).content(),{dom:a,text:c,slice:f}=us(r,l);(!t.dataTransfer.files.length||!V||Yi>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(mt?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",mt||t.dataTransfer.setData("text/plain",c),r.dragging=new ws(f,!t[Os],o)};H.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)=>{let t=e,n=r.dragging;if(r.dragging=null,!t.dataTransfer)return;let i=r.posAtCoords(Yt(t));if(!i)return;let s=r.state.doc.resolve(i.pos),o=n&&n.slice;o?r.someProp("transformPasted",h=>{o=h(o,r)}):o=hs(r,Cs(t.dataTransfer),mt?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(n&&!t[Os]);if(r.someProp("handleDrop",h=>h(r,t,o||k.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let a=o?Io(r.state.doc,s.pos,o):s.pos;a==null&&(a=s.pos);let c=r.state.tr;if(l){let{node:h}=n;h?h.replace(c):c.deleteSelection()}let f=c.mapping.map(a),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,u=c.doc;if(d?c.replaceRangeWith(f,f,o.content.firstChild):c.replaceRange(f,f,o),c.doc.eq(u))return;let p=c.doc.resolve(f);if(d&&x.isSelectable(o.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(o.content.firstChild))c.setSelection(new x(p));else{let h=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((m,g,b,T)=>h=T),c.setSelection(Un(r,p,c.doc.resolve(h)))}r.focus(),r.dispatch(c.setMeta("uiEvent","drop"))};H.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())&&fe(r)},20))};H.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)};H.beforeinput=(r,e)=>{if(V&&ae&&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)H[r]=q[r];function yt(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 Lt{constructor(e,t){this.toDOM=e,this.spec=t||ze,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 X(s-n,s-n,this)}valid(){return!0}eq(e){return this==e||e instanceof Lt&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&yt(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class xe{constructor(e,t){this.attrs=e,this.spec=t||ze}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 X(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==L||e.maps.length==0?this:this.mapInner(e,t,0,0,n||ze)}mapInner(e,t,n,i,s){let o;for(let l=0;l{let c=a+n,f;if(f=Ns(t,l,c)){for(i||(i=this.children.slice());sl&&d.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 xe){let c=Math.max(s,a.from)-s,f=Math.min(o,a.to)-s;ci.map(e,t,ze));return me.from(n)}forChild(e,t){if(t.isLeaf)return R.empty;let n=[];for(let i=0;it instanceof R)?e:e.reduce((t,n)=>t.concat(n instanceof R?n:n.members),[]))}}forEachSet(e){for(let t=0;t{let g=m-h-(p-u);for(let b=0;bT+f-d)continue;let E=l[b]+f-d;p>=E?l[b+1]=u<=E?-2:-1:u>=f&&g&&(l[b]+=g,l[b+1]+=g)}d+=g}),f=t.maps[c].map(f,-1)}let a=!1;for(let c=0;c=n.content.size){a=!0;continue}let u=t.map(r[c+1]+s,-1),p=u-i,{index:h,offset:m}=n.content.findIndex(d),g=n.maybeChild(h);if(g&&m==d&&m+g.nodeSize==p){let b=l[c+2].mapInner(t,g,f+1,r[c]+s+1,o);b!=L?(l[c]=d,l[c+1]=p,l[c+2]=b):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=sa(l,r,e,t,i,s,o),f=Vt(c,n,0,o);e=f.local;for(let d=0;dt&&o.to{let c=Ns(r,l,a+t);if(c){s=!0;let f=Vt(c,l,t+a+1,n);f!=L&&i.push(a,a+l.nodeSize,f)}});let o=Ts(s?Es(r):r,-t).sort(ve);for(let l=0;l0;)e++;r.splice(e,0,t)}function hn(r){let e=[];return r.someProp("decorations",t=>{let n=t(r.state);n&&n!=L&&e.push(n)}),r.cursorWrapper&&e.push(R.create(r.state.doc,[r.cursorWrapper.deco])),me.from(e)}const oa={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},la=K&&ke<=11;class aa{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 ca{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new aa,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():this.flush()}),la&&(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,oa)),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(Lr(this.view)){if(this.suppressingSelectionUpdates)return fe(this.view);if(K&&ke<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Le(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=pt(s))t.add(s);for(let s=e.anchorNode;s;s=pt(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)&&Lr(e)&&!this.ignoreSelectionChange(n),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let f=0;fd.nodeName=="BR");if(f.length==2){let[d,u]=f;d.parentNode&&d.parentNode.parentNode==u.parentNode?u.remove():d.remove()}else{let{focusNode:d}=this.currentSelection;for(let u of f){let p=u.parentNode;p&&p.nodeName=="LI"&&(!d||ua(e,d)!=p)&&u.remove()}}}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),fa(e)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||fe(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],T=b.pmViewDesc;if(b.nodeName=="BR"&&!T){s=g;break}if(!T||T.size)break}let d=r.state.doc,u=r.someProp("domParser")||_e.fromSchema(r.state.schema),p=d.resolve(o),h=null,m=u.parse(n,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:s,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:pa,context:p});if(c&&c[0].pos!=null){let g=c[0].pos,b=c[1]&&c[1].pos;b==null&&(b=g),h={anchor:g+o,head:b+o}}return{doc:m,sel:h,from:o,to:l}}function pa(r){let e=r.pmViewDesc;if(e)return e.parseRule();if(r.nodeName=="BR"&&r.parentNode){if(J&&/^(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||J&&/^(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 ma=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function ga(r,e,t,n,i){let s=r.input.compositionPendingChanges||(r.composing?r.input.compositionID:0);if(r.input.compositionPendingChanges=0,e<0){let O=r.input.lastSelectionTime>Date.now()-50?r.input.lastSelectionOrigin:null,ue=jn(r,O);if(ue&&!r.state.selection.eq(ue)){if(V&&ae&&r.input.lastKeyCode===13&&Date.now()-100qs(r,Ee(13,"Enter"))))return;let Ct=r.state.tr.setSelection(ue);O=="pointer"?Ct.setMeta("pointer",!0):O=="key"&&Ct.scrollIntoView(),s&&Ct.setMeta("composition",s),r.dispatch(Ct)}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=ha(r,e,t),f=r.state.doc,d=f.slice(c.from,c.to),u,p;r.input.lastKeyCode===8&&Date.now()-100Date.now()-225||ae)&&i.some(O=>O.nodeType==1&&!ma.test(O.nodeName))&&(!h||h.endA>=h.endB)&&r.someProp("handleKeyDown",O=>O(r,Ee(13,"Enter")))){r.input.lastIOSEnter=0;return}if(!h)if(n&&a instanceof w&&!a.empty&&a.$head.sameParent(a.$anchor)&&!r.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))h={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let O=_r(r,r.state.doc,c.sel);if(O&&!O.eq(r.state.selection)){let ue=r.state.tr.setSelection(O);s&&ue.setMeta("composition",s),r.dispatch(ue)}}return}r.state.selection.fromr.state.selection.from&&h.start<=r.state.selection.from+2&&r.state.selection.from>=c.from?h.start=r.state.selection.from:h.endA=r.state.selection.to-2&&r.state.selection.to<=c.to&&(h.endB+=r.state.selection.to-h.endA,h.endA=r.state.selection.to)),K&&ke<=11&&h.endB==h.start+1&&h.endA==h.start&&h.start>c.from&&c.doc.textBetween(h.start-c.from-1,h.start-c.from+1)=="  "&&(h.start--,h.endA--,h.endB--);let m=c.doc.resolveNoCache(h.start-c.from),g=c.doc.resolveNoCache(h.endB-c.from),b=f.resolve(h.start),T=m.sameParent(g)&&m.parent.inlineContent&&b.end()>=h.endA,E;if((Qe&&r.input.lastIOSEnter>Date.now()-225&&(!T||i.some(O=>O.nodeName=="DIV"||O.nodeName=="P"))||!T&&m.posO(r,Ee(13,"Enter")))){r.input.lastIOSEnter=0;return}if(r.state.selection.anchor>h.start&&ba(f,h.start,h.endA,m,g)&&r.someProp("handleKeyDown",O=>O(r,Ee(8,"Backspace")))){ae&&V&&r.domObserver.suppressSelectionUpdates();return}V&&h.endB==h.start&&(r.input.lastChromeDelete=Date.now()),ae&&!T&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==h.endA&&(h.endB-=2,g=c.doc.resolveNoCache(h.endB-c.from),setTimeout(()=>{r.someProp("handleKeyDown",function(O){return O(r,Ee(13,"Enter"))})},20));let W=h.start,U=h.endA,D,te,We;if(T){if(m.pos==g.pos)K&&ke<=11&&m.parentOffset==0&&(r.domObserver.suppressSelectionUpdates(),setTimeout(()=>fe(r),20)),D=r.state.tr.delete(W,U),te=f.resolve(h.start).marksAcross(f.resolve(h.endA));else if(h.endA==h.endB&&(We=ya(m.parent.content.cut(m.parentOffset,g.parentOffset),b.parent.content.cut(b.parentOffset,h.endA-b.start()))))D=r.state.tr,We.type=="add"?D.addMark(W,U,We.mark):D.removeMark(W,U,We.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let O=m.parent.textBetween(m.parentOffset,g.parentOffset);if(r.someProp("handleTextInput",ue=>ue(r,W,U,O)))return;D=r.state.tr.insertText(O,W,U)}}if(D||(D=r.state.tr.replace(W,U,c.doc.slice(h.start-c.from,h.endB-c.from))),c.sel){let O=_r(r,D.doc,c.sel);O&&!(V&&r.composing&&O.empty&&(h.start!=h.endB||r.input.lastChromeDeletee.content.size?null:Un(r,e.resolve(t.anchor),e.resolve(t.head))}function ya(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||pn(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 ka(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 Sa{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 Vl,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(ni),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=ei(this),Qr(this),this.nodeViews=ti(this),this.docView=Ir(this.state.doc,Zr(this),hn(this),this.dom,this),this.domObserver=new ca(this,(n,i,s,o)=>ga(this,n,i,s,o)),this.domObserver.start(),$l(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&&zn(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(ni),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&&(Ms(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 p=ti(this);Ma(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&zn(this),this.editable=ei(this),Qr(this);let a=hn(this),c=Zr(this),f=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=s||!this.docView.matchesNode(e.doc,c,a);(d||!e.selection.eq(i.selection))&&(o=!0);let u=f=="preserve"&&o&&this.dom.style.overflowAnchor==null&&el(this);if(o){this.domObserver.stop();let p=d&&(K||V)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&xa(i.selection,e.selection);if(d){let h=V?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Ql(this)),(s||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Ir(e.doc,c,a,this.dom,this)),h&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&wl(this))?fe(this,p):(cs(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():u&&tl(u)}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 x){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Tr(this,t.getBoundingClientRect(),e)}else Tr(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 ws(e.slice,e.move,i<0?void 0:x.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 ll(this,e)}coordsAtPos(e,t=1){return es(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 ul(this,t||this.state,e)}pasteHTML(e,t){return gt(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return gt(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Wl(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],hn(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Ho())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Hl(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?J&&this.root.nodeType===11&&Go(this.dom.ownerDocument)==this.dom&&da(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function Zr(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"),[X.node(0,r.state.doc.content.size,e)]}function Qr(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:X.widget(r.state.selection.from,e,{raw:!0,marks:r.markCursor})}}else r.cursorWrapper=null}function ei(r){return!r.someProp("editable",e=>e(r.state)===!1)}function xa(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 ti(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 Ma(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 ni(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")}var Me={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},$t={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Ca=typeof navigator<"u"&&/Mac/.test(navigator.platform),wa=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var F=0;F<10;F++)Me[48+F]=Me[96+F]=String(F);for(var F=1;F<=24;F++)Me[F+111]="F"+F;for(var F=65;F<=90;F++)Me[F]=String.fromCharCode(F+32),$t[F]=String.fromCharCode(F);for(var mn in Me)$t.hasOwnProperty(mn)||($t[mn]=Me[mn]);function Oa(r){var e=Ca&&r.metaKey&&r.shiftKey&&!r.ctrlKey&&!r.altKey||wa&&r.shiftKey&&r.key&&r.key.length==1||r.key=="Unidentified",t=!e&&r.key||(r.shiftKey?$t:Me)[r.keyCode]||r.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const Ta=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Na(r){let e=r.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let n,i,s,o;for(let l=0;l127)&&(s=Me[n.keyCode])&&s!=i){let l=e[gn(s,n)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}const Ra=(r,e)=>r.selection.empty?!1:(e&&e(r.tr.deleteSelection().scrollIntoView()),!0);function Ia(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("backward",r):t.parentOffset>0)?null:t}const Pa=(r,e,t)=>{let n=Ia(r,t);if(!n)return!1;let i=As(n);if(!i){let o=n.blockRange(),l=o&&tt(o);return l==null?!1:(e&&e(r.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Is(r,i,e,-1))return!0;if(n.parent.content.size==0&&(et(s,"end")||x.isSelectable(s)))for(let o=n.depth;;o--){let l=Hn(r.doc,n.before(o),n.after(o),k.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};function et(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 Ba=(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=As(n)}let o=s&&s.nodeBefore;return!o||!x.isSelectable(o)?!1:(e&&e(r.tr.setSelection(x.create(r.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function As(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 za(r,e){let{$cursor:t}=r.selection;return!t||(e?!e.endOfTextblock("forward",r):t.parentOffset{let n=za(r,t);if(!n)return!1;let i=Ds(n);if(!i)return!1;let s=i.nodeAfter;if(Is(r,i,e,1))return!0;if(n.parent.content.size==0&&(et(s,"start")||x.isSelectable(s))){let o=Hn(r.doc,n.before(),n.after(),k.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 t=r.selection,n=t instanceof x,i;if(n){if(t.node.isTextblock||!we(r.doc,t.from))return!1;i=t.from}else if(i=$i(r.doc,t.from,-1),i==null)return!1;if(e){let s=r.tr.join(i);n&&s.setSelection(x.create(s.doc,i-r.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},Va=(r,e)=>{let t=r.selection,n;if(t instanceof x){if(t.node.isTextblock||!we(r.doc,t.to))return!1;n=t.to}else if(n=$i(r.doc,t.to,1),n==null)return!1;return e&&e(r.tr.join(n).scrollIntoView()),!0},$a=(r,e)=>{let{$from:t,$to:n}=r.selection,i=t.blockRange(n),s=i&&tt(i);return s==null?!1:(e&&e(r.tr.lift(i,s).scrollIntoView()),!0)},Wa=(r,e)=>{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 Rs(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=Rs(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},Ha=(r,e)=>{let t=r.selection,{$from:n,$to:i}=t;if(t instanceof Z||n.parent.inlineContent||i.parent.inlineContent)return!1;let s=Rs(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(Ue(r.doc,s))return e&&e(r.tr.split(s).scrollIntoView()),!0}let n=t.blockRange(),i=n&&tt(n);return i==null?!1:(e&&e(r.tr.lift(n,i).scrollIntoView()),!0)},Ka=(r,e)=>{let{$from:t,to:n}=r.selection,i,s=t.sharedDepth(n);return s==0?!1:(i=t.before(s),e&&e(r.tr.setSelection(x.create(r.doc,i))),!0)};function ja(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||we(r.doc,e.pos))?!1:(t&&t(r.tr.join(e.pos).scrollIntoView()),!0)}function Is(r,e,t,n){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&ja(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 p=e.pos+s.nodeSize,h=y.empty;for(let b=o.length-1;b>=0;b--)h=y.from(o[b].create(null,h));h=y.from(i.copy(h));let m=r.tr.step(new I(e.pos-1,p,e.pos,p,new k(h,1,0),o.length,!0)),g=m.doc.resolve(p+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&we(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),d=f&&f.$from.blockRange(f.$to),u=d&&tt(d);if(u!=null&&u>=e.depth)return t&&t(r.tr.lift(d,u).scrollIntoView()),!0;if(c&&et(s,"start",!0)&&et(i,"end")){let p=i,h=[];for(;h.push(p),!p.isTextblock;)p=p.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(p.canReplace(p.childCount,p.childCount,m.content)){if(t){let b=y.empty;for(let E=h.length-1;E>=0;E--)b=y.from(h[E].copy(b));let T=r.tr.step(new I(e.pos-h.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new k(b,h.length,0),0,!0));t(T.scrollIntoView())}return!0}}return!1}function Ps(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(w.create(e.doc,r<0?i.start(s):i.end(s)))),!0):!1}}const Ua=Ps(-1),Ga=Ps(1);function Ya(r,e=null){return function(t,n){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Jn(o,r,e);return l?(n&&n(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function ri(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),d=f.index();i=f.parent.canReplaceWith(d,d+1,r)}})}if(!i)return!1;if(n){let s=t.tr;for(let o=0;o=2&&e.$from.node(e.depth-1).type.compatibleContent(t)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let a=o.resolve(e.start-2);s=new Pt(a,a,e.depth),e.endIndex=0;f--)s=y.from(t[f].type.create(t[f].attrs,s));r.step(new I(e.start-(n?2:0),e.end,e.start,e.end,new k(s,0,0),t.length,!0));let o=0;for(let f=0;fo.childCount>0&&o.firstChild.type==r);return s?t?n.node(s.depth-1).type==r?ec(e,t,r,s):tc(e,t,s):!0:!1}}function ec(r,e,t,n){let i=r.tr,s=n.end,o=n.$to.end(n.depth);sm;h--)p-=i.child(h).nodeSize,n.delete(p-1,p+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 d=s.pos,u=d+o.nodeSize;return n.step(new I(d-(l?1:0),u+(a?1:0),d+1,u-1,new k((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 nc(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),d=new k(y.from(r.create(null,y.from(l.type.create(null,f)))),c?3:1,0),u=s.start,p=s.end;t(e.tr.step(new I(u-(c?3:1),p,u,p,d,1,!0)).scrollIntoView())}return!0}}function _t(r){const{state:e,transaction:t}=r;let{selection:n}=t,{doc:i}=t,{storedMarks:s}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),filterTransaction:e.filterTransaction,plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return n},get doc(){return i},get tr(){return n=t.selection,i=t.doc,s=t.storedMarks,t}}}class Xt{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:t,state:n}=this,{view:i}=t,{tr:s}=n,o=this.buildProps(s);return Object.fromEntries(Object.entries(e).map(([l,a])=>[l,(...f)=>{const d=a(...f)(o);return!s.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(s),d}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){const{rawCommands:n,editor:i,state:s}=this,{view:o}=i,l=[],a=!!e,c=e||s.tr,f=()=>(!a&&t&&!c.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(c),l.every(u=>u===!0)),d={...Object.fromEntries(Object.entries(n).map(([u,p])=>[u,(...m)=>{const g=this.buildProps(c,t),b=p(...m)(g);return l.push(b),d}])),run:f};return d}createCan(e){const{rawCommands:t,state:n}=this,i=!1,s=e||n.tr,o=this.buildProps(s,i);return{...Object.fromEntries(Object.entries(t).map(([a,c])=>[a,(...f)=>c(...f)({...o,dispatch:void 0})])),chain:()=>this.createChain(s,i)}}buildProps(e,t=!0){const{rawCommands:n,editor:i,state:s}=this,{view:o}=i;s.storedMarks&&e.setStoredMarks(s.storedMarks);const l={tr:e,editor:i,view:o,state:_t({state:s,transaction:e}),dispatch:t?()=>{}:void 0,chain:()=>this.createChain(e),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([a,c])=>[a,(...f)=>c(...f)(l)]))}};return l}}class rc{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){const n=this.callbacks[e];return n&&n.forEach(i=>i.apply(this,t)),this}off(e,t){const n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(i=>i!==t):delete this.callbacks[e]),this}removeAllListeners(){this.callbacks={}}}function S(r,e,t){return r.config[e]===void 0&&r.parent?S(r.parent,e,t):typeof r.config[e]=="function"?r.config[e].bind({...t,parent:r.parent?S(r.parent,e,t):null}):r.config[e]}function Zt(r){const e=r.filter(i=>i.type==="extension"),t=r.filter(i=>i.type==="node"),n=r.filter(i=>i.type==="mark");return{baseExtensions:e,nodeExtensions:t,markExtensions:n}}function Bs(r){const e=[],{nodeExtensions:t,markExtensions:n}=Zt(r),i=[...t,...n],s={default:null,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return r.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage},a=S(o,"addGlobalAttributes",l);if(!a)return;a().forEach(f=>{f.types.forEach(d=>{Object.entries(f.attributes).forEach(([u,p])=>{e.push({type:d,name:u,attribute:{...s,...p}})})})})}),i.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage},a=S(o,"addAttributes",l);if(!a)return;const c=a();Object.entries(c).forEach(([f,d])=>{const u={...s,...d};d!=null&&d.isRequired&&(d==null?void 0:d.default)===void 0&&delete u.default,e.push({type:o.name,name:f,attribute:u})})}),e}function P(r,e){if(typeof r=="string"){if(!e.nodes[r])throw Error(`There is no node type named '${r}'. Maybe you forgot to add the extension?`);return e.nodes[r]}return r}function ee(...r){return r.filter(e=>!!e).reduce((e,t)=>{const n={...e};return Object.entries(t).forEach(([i,s])=>{if(!n[i]){n[i]=s;return}i==="class"?n[i]=[n[i],s].join(" "):i==="style"?n[i]=[n[i],s].join("; "):n[i]=s}),n},{})}function vn(r,e){return e.filter(t=>t.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(r.attrs)||{}:{[t.name]:r.attrs[t.name]}).reduce((t,n)=>ee(t,n),{})}function zs(r){return typeof r=="function"}function M(r,e=void 0,...t){return zs(r)?e?r.bind(e)(...t):r(...t):r}function ic(r={}){return Object.keys(r).length===0&&r.constructor===Object}function sc(r){return typeof r!="string"?r:r.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(r):r==="true"?!0:r==="false"?!1:r}function ii(r,e){return r.style?r:{...r,getAttrs:t=>{const n=r.getAttrs?r.getAttrs(t):r.attrs;if(n===!1)return!1;const i=e.reduce((s,o)=>{const l=o.attribute.parseHTML?o.attribute.parseHTML(t):sc(t.getAttribute(o.name));return l==null?s:{...s,[o.name]:l}},{});return{...n,...i}}}}function si(r){return Object.fromEntries(Object.entries(r).filter(([e,t])=>e==="attrs"&&ic(t)?!1:t!=null))}function vs(r){var e;const t=Bs(r),{nodeExtensions:n,markExtensions:i}=Zt(r),s=(e=n.find(a=>S(a,"topNode")))===null||e===void 0?void 0:e.name,o=Object.fromEntries(n.map(a=>{const c=t.filter(g=>g.type===a.name),f={name:a.name,options:a.options,storage:a.storage},d=r.reduce((g,b)=>{const T=S(b,"extendNodeSchema",f);return{...g,...T?T(a):{}}},{}),u=si({...d,content:M(S(a,"content",f)),marks:M(S(a,"marks",f)),group:M(S(a,"group",f)),inline:M(S(a,"inline",f)),atom:M(S(a,"atom",f)),selectable:M(S(a,"selectable",f)),draggable:M(S(a,"draggable",f)),code:M(S(a,"code",f)),defining:M(S(a,"defining",f)),isolating:M(S(a,"isolating",f)),attrs:Object.fromEntries(c.map(g=>{var b;return[g.name,{default:(b=g==null?void 0:g.attribute)===null||b===void 0?void 0:b.default}]}))}),p=M(S(a,"parseHTML",f));p&&(u.parseDOM=p.map(g=>ii(g,c)));const h=S(a,"renderHTML",f);h&&(u.toDOM=g=>h({node:g,HTMLAttributes:vn(g,c)}));const m=S(a,"renderText",f);return m&&(u.toText=m),[a.name,u]})),l=Object.fromEntries(i.map(a=>{const c=t.filter(m=>m.type===a.name),f={name:a.name,options:a.options,storage:a.storage},d=r.reduce((m,g)=>{const b=S(g,"extendMarkSchema",f);return{...m,...b?b(a):{}}},{}),u=si({...d,inclusive:M(S(a,"inclusive",f)),excludes:M(S(a,"excludes",f)),group:M(S(a,"group",f)),spanning:M(S(a,"spanning",f)),code:M(S(a,"code",f)),attrs:Object.fromEntries(c.map(m=>{var g;return[m.name,{default:(g=m==null?void 0:m.attribute)===null||g===void 0?void 0:g.default}]}))}),p=M(S(a,"parseHTML",f));p&&(u.parseDOM=p.map(m=>ii(m,c)));const h=S(a,"renderHTML",f);return h&&(u.toDOM=m=>h({mark:m,HTMLAttributes:vn(m,c)})),[a.name,u]}));return new lo({topNode:s,nodes:o,marks:l})}function yn(r,e){return e.nodes[r]||e.marks[r]||null}function oi(r,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===r.name):e}const oc=(r,e=500)=>{let t="";const n=r.parentOffset;return r.parent.nodesBetween(Math.max(0,n-e),n,(i,s,o,l)=>{var a,c;const f=((c=(a=i.type.spec).toText)===null||c===void 0?void 0:c.call(a,{node:i,pos:s,parent:o,index:l}))||i.textContent||"%leaf%";t+=f.slice(0,Math.max(0,n-s))}),t};function Qn(r){return Object.prototype.toString.call(r)==="[object RegExp]"}class er{constructor(e){this.find=e.find,this.handler=e.handler}}const lc=(r,e)=>{if(Qn(e))return e.exec(r);const t=e(r);if(!t)return null;const n=[];return n.push(t.text),n.index=t.index,n.input=r,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),n.push(t.replaceWith)),n};function bn(r){var e;const{editor:t,from:n,to:i,text:s,rules:o,plugin:l}=r,{view:a}=t;if(a.composing)return!1;const c=a.state.doc.resolve(n);if(c.parent.type.spec.code||!((e=c.nodeBefore||c.nodeAfter)===null||e===void 0)&&e.marks.find(u=>u.type.spec.code))return!1;let f=!1;const d=oc(c)+s;return o.forEach(u=>{if(f)return;const p=lc(d,u.find);if(!p)return;const h=a.state.tr,m=_t({state:a.state,transaction:h}),g={from:n-(p[0].length-s.length),to:i},{commands:b,chain:T,can:E}=new Xt({editor:t,state:m});u.handler({state:m,range:g,match:p,commands:b,chain:T,can:E})===null||!h.steps.length||(h.setMeta(l,{transform:h,from:n,to:i,text:s}),a.dispatch(h),f=!0)}),f}function ac(r){const{editor:e,rules:t}=r,n=new Oe({state:{init(){return null},apply(i,s){const o=i.getMeta(n);return o||(i.selectionSet||i.docChanged?null:s)}},props:{handleTextInput(i,s,o,l){return bn({editor:e,from:s,to:o,text:l,rules:t,plugin:n})},handleDOMEvents:{compositionend:i=>(setTimeout(()=>{const{$cursor:s}=i.state.selection;s&&bn({editor:e,from:s.pos,to:s.pos,text:"",rules:t,plugin:n})}),!1)},handleKeyDown(i,s){if(s.key!=="Enter")return!1;const{$cursor:o}=i.state.selection;return o?bn({editor:e,from:o.pos,to:o.pos,text:` `,rules:t,plugin:n}):!1}},isInputRules:!0});return n}function cc(r){return typeof r=="number"}class fc{constructor(e){this.find=e.find,this.handler=e.handler}}const dc=(r,e)=>{if(Qn(e))return[...r.matchAll(e)];const t=e(r);return t?t.map(n=>{const i=[];return i.push(n.text),i.index=n.index,i.input=r,i.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),i.push(n.replaceWith)),i}):[]};function uc(r){const{editor:e,state:t,from:n,to:i,rule:s}=r,{commands:o,chain:l,can:a}=new Xt({editor:e,state:t}),c=[];return t.doc.nodesBetween(n,i,(d,u)=>{if(!d.isTextblock||d.type.spec.code)return;const p=Math.max(n,u),h=Math.min(i,u+d.content.size),m=d.textBetween(p-u,h-u,void 0,"");dc(m,s.find).forEach(b=>{if(b.index===void 0)return;const T=p+b.index+1,E=T+b[0].length,W={from:t.tr.mapping.map(T),to:t.tr.mapping.map(E)},U=s.handler({state:t,range:W,match:b,commands:o,chain:l,can:a});c.push(U)})}),c.every(d=>d!==null)}function hc(r){const{editor:e,rules:t}=r;let n=null,i=!1,s=!1;return t.map(l=>new Oe({view(a){const c=f=>{var d;n=!((d=a.dom.parentElement)===null||d===void 0)&&d.contains(f.target)?a.dom.parentElement:null};return window.addEventListener("dragstart",c),{destroy(){window.removeEventListener("dragstart",c)}}},props:{handleDOMEvents:{drop:a=>(s=n===a.dom.parentElement,!1),paste:(a,c)=>{var f;const d=(f=c.clipboardData)===null||f===void 0?void 0:f.getData("text/html");return i=!!(d!=null&&d.includes("data-pm-slice")),!1}}},appendTransaction:(a,c,f)=>{const d=a[0],u=d.getMeta("uiEvent")==="paste"&&!i,p=d.getMeta("uiEvent")==="drop"&&!s;if(!u&&!p)return;const h=c.doc.content.findDiffStart(f.doc.content),m=c.doc.content.findDiffEnd(f.doc.content);if(!cc(h)||!m||h===m.b)return;const g=f.tr,b=_t({state:f,transaction:g});if(!(!uc({editor:e,state:b,from:Math.max(h-1,0),to:m.b-1,rule:l})||!g.steps.length))return g}}))}function pc(r){const e=r.filter((t,n)=>r.indexOf(t)!==n);return[...new Set(e)]}class Re{constructor(e,t){this.splittableMarks=[],this.editor=t,this.extensions=Re.resolve(e),this.schema=vs(this.extensions),this.extensions.forEach(n=>{var i;this.editor.extensionStorage[n.name]=n.storage;const s={name:n.name,options:n.options,storage:n.storage,editor:this.editor,type:yn(n.name,this.schema)};n.type==="mark"&&(!((i=M(S(n,"keepOnSplit",s)))!==null&&i!==void 0)||i)&&this.splittableMarks.push(n.name);const o=S(n,"onBeforeCreate",s);o&&this.editor.on("beforeCreate",o);const l=S(n,"onCreate",s);l&&this.editor.on("create",l);const a=S(n,"onUpdate",s);a&&this.editor.on("update",a);const c=S(n,"onSelectionUpdate",s);c&&this.editor.on("selectionUpdate",c);const f=S(n,"onTransaction",s);f&&this.editor.on("transaction",f);const d=S(n,"onFocus",s);d&&this.editor.on("focus",d);const u=S(n,"onBlur",s);u&&this.editor.on("blur",u);const p=S(n,"onDestroy",s);p&&this.editor.on("destroy",p)})}static resolve(e){const t=Re.sort(Re.flatten(e)),n=pc(t.map(i=>i.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(i=>`'${i}'`).join(", ")}]. This can lead to issues.`),t}static flatten(e){return e.map(t=>{const n={name:t.name,options:t.options,storage:t.storage},i=S(t,"addExtensions",n);return i?[t,...this.flatten(i())]:t}).flat(10)}static sort(e){return e.sort((n,i)=>{const s=S(n,"priority")||100,o=S(i,"priority")||100;return s>o?-1:s{const n={name:t.name,options:t.options,storage:t.storage,editor:this.editor,type:yn(t.name,this.schema)},i=S(t,"addCommands",n);return i?{...e,...i()}:e},{})}get plugins(){const{editor:e}=this,t=Re.sort([...this.extensions].reverse()),n=[],i=[],s=t.map(o=>{const l={name:o.name,options:o.options,storage:o.storage,editor:e,type:yn(o.name,this.schema)},a=[],c=S(o,"addKeyboardShortcuts",l);let f={};if(o.type==="mark"&&o.config.exitable&&(f.ArrowRight=()=>Ce.handleExit({editor:e,mark:o})),c){const m=Object.fromEntries(Object.entries(c()).map(([g,b])=>[g,()=>b({editor:e})]));f={...f,...m}}const d=Aa(f);a.push(d);const u=S(o,"addInputRules",l);oi(o,e.options.enableInputRules)&&u&&n.push(...u());const p=S(o,"addPasteRules",l);oi(o,e.options.enablePasteRules)&&p&&i.push(...p());const h=S(o,"addProseMirrorPlugins",l);if(h){const m=h();a.push(...m)}return a}).flat();return[ac({editor:e,rules:n}),...hc({editor:e,rules:i}),...s]}get attributes(){return Bs(this.extensions)}get nodeViews(){const{editor:e}=this,{nodeExtensions:t}=Zt(this.extensions);return Object.fromEntries(t.filter(n=>!!S(n,"addNodeView")).map(n=>{const i=this.attributes.filter(a=>a.type===n.name),s={name:n.name,options:n.options,storage:n.storage,editor:e,type:P(n.name,this.schema)},o=S(n,"addNodeView",s);if(!o)return[];const l=(a,c,f,d)=>{const u=vn(a,i);return o()({editor:e,node:a,getPos:f,decorations:d,HTMLAttributes:u,extension:n})};return[n.name,l]}))}}function mc(r){return Object.prototype.toString.call(r).slice(8,-1)}function kn(r){return mc(r)!=="Object"?!1:r.constructor===Object&&Object.getPrototypeOf(r)===Object.prototype}function Qt(r,e){const t={...r};return kn(r)&&kn(e)&&Object.keys(e).forEach(n=>{kn(e[n])?n in r?t[n]=Qt(r[n],e[n]):Object.assign(t,{[n]:e[n]}):Object.assign(t,{[n]:e[n]})}),t}class de{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=M(S(this,"addOptions",{name:this.name}))),this.storage=M(S(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new de(e)}configure(e={}){const t=this.extend();return t.options=Qt(this.options,e),t.storage=M(S(t,"addStorage",{name:t.name,options:t.options})),t}extend(e={}){const t=new de(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=M(S(t,"addOptions",{name:t.name})),t.storage=M(S(t,"addStorage",{name:t.name,options:t.options})),t}}function Fs(r,e,t){const{from:n,to:i}=e,{blockSeparator:s=` `,textSerializers:o={}}=t||{};let l="",a=!0;return r.nodesBetween(n,i,(c,f,d,u)=>{var p;const h=o==null?void 0:o[c.type.name];h?(c.isBlock&&!a&&(l+=s,a=!0),d&&(l+=h({node:c,pos:f,parent:d,index:u,range:e}))):c.isText?(l+=(p=c==null?void 0:c.text)===null||p===void 0?void 0:p.slice(Math.max(n,f)-f,i-f),a=!1):c.isBlock&&!a&&(l+=s,a=!0)}),l}function Ls(r){return Object.fromEntries(Object.entries(r.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}const gc=de.create({name:"clipboardTextSerializer",addProseMirrorPlugins(){return[new Oe({key:new kt("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:r}=this,{state:e,schema:t}=r,{doc:n,selection:i}=e,{ranges:s}=i,o=Math.min(...s.map(f=>f.$from.pos)),l=Math.max(...s.map(f=>f.$to.pos)),a=Ls(t);return Fs(n,{from:o,to:l},{textSerializers:a})}}})]}}),yc=()=>({editor:r,view:e})=>(requestAnimationFrame(()=>{var t;r.isDestroyed||(e.dom.blur(),(t=window==null?void 0:window.getSelection())===null||t===void 0||t.removeAllRanges())}),!0),bc=(r=!1)=>({commands:e})=>e.setContent("",r),kc=()=>({state:r,tr:e,dispatch:t})=>{const{selection:n}=e,{ranges:i}=n;return t&&i.forEach(({$from:s,$to:o})=>{r.doc.nodesBetween(s.pos,o.pos,(l,a)=>{if(l.type.isText)return;const{doc:c,mapping:f}=e,d=c.resolve(f.map(a)),u=c.resolve(f.map(a+l.nodeSize)),p=d.blockRange(u);if(!p)return;const h=tt(p);if(l.type.isTextblock){const{defaultType:m}=d.parent.contentMatchAt(d.index());e.setNodeMarkup(p.start,m)}(h||h===0)&&e.lift(p,h)})}),!0},Sc=r=>e=>r(e),xc=()=>({state:r,dispatch:e})=>Ha(r,e),Mc=()=>({tr:r,dispatch:e})=>{const{selection:t}=r,n=t.$anchor.node();if(n.content.size>0)return!1;const i=r.selection.$anchor;for(let s=i.depth;s>0;s-=1)if(i.node(s).type===n.type){if(e){const l=i.before(s),a=i.after(s);r.delete(l,a).scrollIntoView()}return!0}return!1},Cc=r=>({tr:e,state:t,dispatch:n})=>{const i=P(r,t.schema),s=e.selection.$anchor;for(let o=s.depth;o>0;o-=1)if(s.node(o).type===i){if(n){const a=s.before(o),c=s.after(o);e.delete(a,c).scrollIntoView()}return!0}return!1},wc=r=>({tr:e,dispatch:t})=>{const{from:n,to:i}=r;return t&&e.delete(n,i),!0},Oc=()=>({state:r,dispatch:e})=>Ra(r,e),Tc=()=>({commands:r})=>r.keyboardShortcut("Enter"),Nc=()=>({state:r,dispatch:e})=>Ja(r,e);function Wt(r,e,t={strict:!0}){const n=Object.keys(e);return n.length?n.every(i=>t.strict?e[i]===r[i]:Qn(e[i])?e[i].test(r[i]):e[i]===r[i]):!0}function Fn(r,e,t={}){return r.find(n=>n.type===e&&Wt(n.attrs,t))}function Ec(r,e,t={}){return!!Fn(r,e,t)}function tr(r,e,t={}){if(!r||!e)return;let n=r.parent.childAfter(r.parentOffset);if(r.parentOffset===n.offset&&n.offset!==0&&(n=r.parent.childBefore(r.parentOffset)),!n.node)return;const i=Fn([...n.node.marks],e,t);if(!i)return;let s=n.index,o=r.start()+n.offset,l=s+1,a=o+n.node.nodeSize;for(Fn([...n.node.marks],e,t);s>0&&i.isInSet(r.parent.child(s-1).marks);)s-=1,o-=r.parent.child(s).nodeSize;for(;l({tr:t,state:n,dispatch:i})=>{const s=Ne(r,n.schema),{doc:o,selection:l}=t,{$from:a,from:c,to:f}=l;if(i){const d=tr(a,s,e);if(d&&d.from<=c&&d.to>=f){const u=w.create(o,d.from,d.to);t.setSelection(u)}}return!0},Dc=r=>e=>{const t=typeof r=="function"?r(e):r;for(let n=0;n({editor:t,view:n,tr:i,dispatch:s})=>{e={scrollIntoView:!0,...e};const o=()=>{nr()&&n.dom.focus(),requestAnimationFrame(()=>{t.isDestroyed||(n.focus(),e!=null&&e.scrollIntoView&&t.commands.scrollIntoView())})};if(n.hasFocus()&&r===null||r===!1)return!0;if(s&&r===null&&!Vs(t.state.selection))return o(),!0;const l=$s(i.doc,r)||t.state.selection,a=t.state.selection.eq(l);return s&&(a||i.setSelection(l),a&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},Ic=(r,e)=>t=>r.every((n,i)=>e(n,{...t,index:i})),Pc=(r,e)=>({tr:t,commands:n})=>n.insertContentAt({from:t.selection.from,to:t.selection.to},r,e);function li(r){const e=`${r}`;return new window.DOMParser().parseFromString(e,"text/html").body}function Jt(r,e,t){if(t={slice:!0,parseOptions:{},...t},typeof r=="object"&&r!==null)try{return Array.isArray(r)?y.fromArray(r.map(n=>e.nodeFromJSON(n))):e.nodeFromJSON(r)}catch(n){return console.warn("[tiptap warn]: Invalid content.","Passed value:",r,"Error:",n),Jt("",e,t)}if(typeof r=="string"){const n=_e.fromSchema(e);return t.slice?n.parseSlice(li(r),t.parseOptions).content:n.parse(li(r),t.parseOptions)}return Jt("",e,t)}function Bc(r,e,t){const n=r.steps.length-1;if(n{o===0&&(o=f)}),r.setSelection(C.near(r.doc.resolve(o),t))}const zc=r=>r.toString().startsWith("<"),vc=(r,e,t)=>({tr:n,dispatch:i,editor:s})=>{if(i){t={parseOptions:{},updateSelection:!0,...t};const o=Jt(e,s.schema,{parseOptions:{preserveWhitespace:"full",...t.parseOptions}});if(o.toString()==="<>")return!0;let{from:l,to:a}=typeof r=="number"?{from:r,to:r}:r,c=!0,f=!0;if((zc(o)?o:[o]).forEach(u=>{u.check(),c=c?u.isText&&u.marks.length===0:!1,f=f?u.isBlock:!1}),l===a&&f){const{parent:u}=n.doc.resolve(l);u.isTextblock&&!u.type.spec.code&&!u.childCount&&(l-=1,a+=1)}c?n.insertText(e,l,a):n.replaceWith(l,a,o),t.updateSelection&&Bc(n,n.steps.length-1,-1)}return!0},Fc=()=>({state:r,dispatch:e})=>La(r,e),Lc=()=>({state:r,dispatch:e})=>Va(r,e),Vc=()=>({state:r,dispatch:e})=>Pa(r,e),$c=()=>({state:r,dispatch:e})=>va(r,e);function Ws(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Wc(r){const e=r.split(/-(?!$)/);let t=e[e.length-1];t==="Space"&&(t=" ");let n,i,s,o;for(let l=0;l({editor:e,view:t,tr:n,dispatch:i})=>{const s=Wc(r).split(/-(?!$)/),o=s.find(c=>!["Alt","Ctrl","Meta","Shift"].includes(c)),l=new KeyboardEvent("keydown",{key:o==="Space"?" ":o,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),a=e.captureTransaction(()=>{t.someProp("handleKeyDown",c=>c(t,l))});return a==null||a.steps.forEach(c=>{const f=c.map(n.mapping);f&&i&&n.maybeStep(f)}),!0};function bt(r,e,t={}){const{from:n,to:i,empty:s}=r.selection,o=e?P(e,r.schema):null,l=[];r.doc.nodesBetween(n,i,(d,u)=>{if(d.isText)return;const p=Math.max(n,u),h=Math.min(i,u+d.nodeSize);l.push({node:d,from:p,to:h})});const a=i-n,c=l.filter(d=>o?o.name===d.node.type.name:!0).filter(d=>Wt(d.node.attrs,t,{strict:!1}));return s?!!c.length:c.reduce((d,u)=>d+u.to-u.from,0)>=a}const Hc=(r,e={})=>({state:t,dispatch:n})=>{const i=P(r,t.schema);return bt(t,i,e)?$a(t,n):!1},qc=()=>({state:r,dispatch:e})=>qa(r,e),Kc=r=>({state:e,dispatch:t})=>{const n=P(r,e.schema);return Qa(n)(e,t)},jc=()=>({state:r,dispatch:e})=>Wa(r,e);function en(r,e){return e.nodes[r]?"node":e.marks[r]?"mark":null}function ai(r,e){const t=typeof e=="string"?[e]:e;return Object.keys(r).reduce((n,i)=>(t.includes(i)||(n[i]=r[i]),n),{})}const Uc=(r,e)=>({tr:t,state:n,dispatch:i})=>{let s=null,o=null;const l=en(typeof r=="string"?r:r.name,n.schema);return l?(l==="node"&&(s=P(r,n.schema)),l==="mark"&&(o=Ne(r,n.schema)),i&&t.selection.ranges.forEach(a=>{n.doc.nodesBetween(a.$from.pos,a.$to.pos,(c,f)=>{s&&s===c.type&&t.setNodeMarkup(f,void 0,ai(c.attrs,e)),o&&c.marks.length&&c.marks.forEach(d=>{o===d.type&&t.addMark(f,f+c.nodeSize,o.create(ai(d.attrs,e)))})})}),!0):!1},Gc=()=>({tr:r,dispatch:e})=>(e&&r.scrollIntoView(),!0),Yc=()=>({tr:r,commands:e})=>e.setTextSelection({from:0,to:r.doc.content.size}),_c=()=>({state:r,dispatch:e})=>Ba(r,e),Xc=()=>({state:r,dispatch:e})=>Fa(r,e),Zc=()=>({state:r,dispatch:e})=>Ka(r,e),Qc=()=>({state:r,dispatch:e})=>Ga(r,e),ef=()=>({state:r,dispatch:e})=>Ua(r,e);function Js(r,e,t={}){return Jt(r,e,{slice:!1,parseOptions:t})}const tf=(r,e=!1,t={})=>({tr:n,editor:i,dispatch:s})=>{const{doc:o}=n,l=Js(r,i.schema,t);return s&&n.replaceWith(0,o.content.size,l).setMeta("preventUpdate",!e),!0};function Xf(r,e){const t=new Ki(r);return e.forEach(n=>{n.steps.forEach(i=>{t.step(i)})}),t}function nf(r){for(let e=0;e{t(i)&&n.push({node:i,pos:s})}),n}function rf(r,e){for(let t=r.depth;t>0;t-=1){const n=r.node(t);if(e(n))return{pos:t>0?r.before(t):0,start:r.start(t),depth:t,node:n}}}function rr(r){return e=>rf(e.$from,r)}function sf(r,e){const t=$e.fromSchema(e).serializeFragment(r),i=document.implementation.createHTMLDocument().createElement("div");return i.appendChild(t),i.innerHTML}function Qf(r){const e=Re.resolve(r);return vs(e)}function of(r,e){const t={from:0,to:r.content.size};return Fs(r,t,e)}function ir(r,e){const t=Ne(e,r.schema),{from:n,to:i,empty:s}=r.selection,o=[];s?(r.storedMarks&&o.push(...r.storedMarks),o.push(...r.selection.$head.marks())):r.doc.nodesBetween(n,i,a=>{o.push(...a.marks)});const l=o.find(a=>a.type.name===t.name);return l?{...l.attrs}:{}}function lf(r,e){const t=P(e,r.schema),{from:n,to:i}=r.selection,s=[];r.doc.nodesBetween(n,i,l=>{s.push(l)});const o=s.reverse().find(l=>l.type.name===t.name);return o?{...o.attrs}:{}}function af(r,e){const t=en(typeof e=="string"?e:e.name,r.schema);return t==="node"?lf(r,e):t==="mark"?ir(r,e):{}}function cf(r,e=JSON.stringify){const t={};return r.filter(n=>{const i=e(n);return Object.prototype.hasOwnProperty.call(t,i)?!1:t[i]=!0})}function ff(r){const e=cf(r);return e.length===1?e:e.filter((t,n)=>!e.filter((s,o)=>o!==n).some(s=>t.oldRange.from>=s.oldRange.from&&t.oldRange.to<=s.oldRange.to&&t.newRange.from>=s.newRange.from&&t.newRange.to<=s.newRange.to))}function ed(r){const{mapping:e,steps:t}=r,n=[];return e.maps.forEach((i,s)=>{const o=[];if(i.ranges.length)i.forEach((l,a)=>{o.push({from:l,to:a})});else{const{from:l,to:a}=t[s];if(l===void 0||a===void 0)return;o.push({from:l,to:a})}o.forEach(({from:l,to:a})=>{const c=e.slice(s).map(l,-1),f=e.slice(s).map(a),d=e.invert().map(c,-1),u=e.invert().map(f);n.push({oldRange:{from:d,to:u},newRange:{from:c,to:f}})})}),ff(n)}function Hs(r,e,t){const n=[];return r===e?t.resolve(r).marks().forEach(i=>{const s=t.resolve(r-1),o=tr(s,i.type);o&&n.push({mark:i,...o})}):t.nodesBetween(r,e,(i,s)=>{n.push(...i.marks.map(o=>({from:s,to:s+i.nodeSize,mark:o})))}),n}function Ln(r,e,t={}){const{empty:n,ranges:i}=r.selection,s=e?Ne(e,r.schema):null;if(n)return!!(r.storedMarks||r.selection.$from.marks()).filter(d=>s?s.name===d.type.name:!0).find(d=>Wt(d.attrs,t,{strict:!1}));let o=0;const l=[];if(i.forEach(({$from:d,$to:u})=>{const p=d.pos,h=u.pos;r.doc.nodesBetween(p,h,(m,g)=>{if(!m.isText&&!m.marks.length)return;const b=Math.max(p,g),T=Math.min(h,g+m.nodeSize),E=T-b;o+=E,l.push(...m.marks.map(W=>({mark:W,from:b,to:T})))})}),o===0)return!1;const a=l.filter(d=>s?s.name===d.mark.type.name:!0).filter(d=>Wt(d.mark.attrs,t,{strict:!1})).reduce((d,u)=>d+u.to-u.from,0),c=l.filter(d=>s?d.mark.type!==s&&d.mark.type.excludes(s):!0).reduce((d,u)=>d+u.to-u.from,0);return(a>0?a+c:a)>=o}function df(r,e,t={}){if(!e)return bt(r,null,t)||Ln(r,null,t);const n=en(e,r.schema);return n==="node"?bt(r,e,t):n==="mark"?Ln(r,e,t):!1}function ci(r,e){const{nodeExtensions:t}=Zt(e),n=t.find(o=>o.name===r);if(!n)return!1;const i={name:n.name,options:n.options,storage:n.storage},s=M(S(n,"group",i));return typeof s!="string"?!1:s.split(" ").includes("list")}function uf(r){var e;const t=(e=r.type.createAndFill())===null||e===void 0?void 0:e.toJSON(),n=r.toJSON();return JSON.stringify(t)===JSON.stringify(n)}function td(r){return r instanceof x}function nd(r,e,t){const i=r.state.doc.content.size,s=ce(e,0,i),o=ce(t,0,i),l=r.coordsAtPos(s),a=r.coordsAtPos(o,-1),c=Math.min(l.top,a.top),f=Math.max(l.bottom,a.bottom),d=Math.min(l.left,a.left),u=Math.max(l.right,a.right),p=u-d,h=f-c,b={top:c,bottom:f,left:d,right:u,width:p,height:h,x:d,y:c};return{...b,toJSON:()=>b}}function hf(r,e,t){var n;const{selection:i}=e;let s=null;if(Vs(i)&&(s=i.$cursor),s){const l=(n=r.storedMarks)!==null&&n!==void 0?n:s.marks();return!!t.isInSet(l)||!l.some(a=>a.type.excludes(t))}const{ranges:o}=i;return o.some(({$from:l,$to:a})=>{let c=l.depth===0?r.doc.inlineContent&&r.doc.type.allowsMarkType(t):!1;return r.doc.nodesBetween(l.pos,a.pos,(f,d,u)=>{if(c)return!1;if(f.isInline){const p=!u||u.type.allowsMarkType(t),h=!!t.isInSet(f.marks)||!f.marks.some(m=>m.type.excludes(t));c=p&&h}return!c}),c})}const pf=(r,e={})=>({tr:t,state:n,dispatch:i})=>{const{selection:s}=t,{empty:o,ranges:l}=s,a=Ne(r,n.schema);if(i)if(o){const c=ir(n,a);t.addStoredMark(a.create({...c,...e}))}else l.forEach(c=>{const f=c.$from.pos,d=c.$to.pos;n.doc.nodesBetween(f,d,(u,p)=>{const h=Math.max(p,f),m=Math.min(p+u.nodeSize,d);u.marks.find(b=>b.type===a)?u.marks.forEach(b=>{a===b.type&&t.addMark(h,m,a.create({...b.attrs,...e}))}):t.addMark(h,m,a.create(e))})});return hf(n,t,a)},mf=(r,e)=>({tr:t})=>(t.setMeta(r,e),!0),gf=(r,e={})=>({state:t,dispatch:n,chain:i})=>{const s=P(r,t.schema);return s.isTextblock?i().command(({commands:o})=>ri(s,e)(t)?!0:o.clearNodes()).command(({state:o})=>ri(s,e)(o,n)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},yf=r=>({tr:e,dispatch:t})=>{if(t){const{doc:n}=e,i=ce(r,0,n.content.size),s=x.create(n,i);e.setSelection(s)}return!0},bf=r=>({tr:e,dispatch:t})=>{if(t){const{doc:n}=e,{from:i,to:s}=typeof r=="number"?{from:r,to:r}:r,o=w.atStart(n).from,l=w.atEnd(n).to,a=ce(i,o,l),c=ce(s,o,l),f=w.create(n,a,c);e.setSelection(f)}return!0},kf=r=>({state:e,dispatch:t})=>{const n=P(r,e.schema);return nc(n)(e,t)};function At(r,e,t){return Object.fromEntries(Object.entries(t).filter(([n])=>{const i=r.find(s=>s.type===e&&s.name===n);return i?i.attribute.keepOnSplit:!1}))}function fi(r,e){const t=r.storedMarks||r.selection.$to.parentOffset&&r.selection.$from.marks();if(t){const n=t.filter(i=>e==null?void 0:e.includes(i.type.name));r.tr.ensureMarks(n)}}const Sf=({keepMarks:r=!0}={})=>({tr:e,state:t,dispatch:n,editor:i})=>{const{selection:s,doc:o}=e,{$from:l,$to:a}=s,c=i.extensionManager.attributes,f=At(c,l.node().type.name,l.node().attrs);if(s instanceof x&&s.node.isBlock)return!l.parentOffset||!Ue(o,l.pos)?!1:(n&&(r&&fi(t,i.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;if(n){const d=a.parentOffset===a.parent.content.size;s instanceof w&&e.deleteSelection();const u=l.depth===0?void 0:nf(l.node(-1).contentMatchAt(l.indexAfter(-1)));let p=d&&u?[{type:u,attrs:f}]:void 0,h=Ue(e.doc,e.mapping.map(l.pos),1,p);if(!p&&!h&&Ue(e.doc,e.mapping.map(l.pos),1,u?[{type:u}]:void 0)&&(h=!0,p=u?[{type:u,attrs:f}]:void 0),h&&(e.split(e.mapping.map(l.pos),1,p),u&&!d&&!l.parentOffset&&l.parent.type!==u)){const m=e.mapping.map(l.before()),g=e.doc.resolve(m);l.node(-1).canReplaceWith(g.index(),g.index()+1,u)&&e.setNodeMarkup(e.mapping.map(l.before()),u)}r&&fi(t,i.extensionManager.splittableMarks),e.scrollIntoView()}return!0},xf=r=>({tr:e,state:t,dispatch:n,editor:i})=>{var s;const o=P(r,t.schema),{$from:l,$to:a}=t.selection,c=t.selection.node;if(c&&c.isBlock||l.depth<2||!l.sameParent(a))return!1;const f=l.node(-1);if(f.type!==o)return!1;const d=i.extensionManager.attributes;if(l.parent.content.size===0&&l.node(-1).childCount===l.indexAfter(-1)){if(l.depth===2||l.node(-3).type!==o||l.index(-2)!==l.node(-2).childCount-1)return!1;if(n){let g=y.empty;const b=l.index(-1)?1:l.index(-2)?2:3;for(let te=l.depth-b;te>=l.depth-3;te-=1)g=y.from(l.node(te).copy(g));const T=l.indexAfter(-1){if(D>-1)return!1;te.isTextblock&&te.content.size===0&&(D=We+1)}),D>-1&&e.setSelection(w.near(e.doc.resolve(D))),e.scrollIntoView()}return!0}const u=a.pos===l.end()?f.contentMatchAt(0).defaultType:null,p=At(d,f.type.name,f.attrs),h=At(d,l.node().type.name,l.node().attrs);e.delete(l.pos,a.pos);const m=u?[{type:o,attrs:p},{type:u,attrs:h}]:[{type:o,attrs:p}];return Ue(e.doc,l.pos,2)?(n&&e.split(l.pos,2,m).scrollIntoView(),!0):!1},di=(r,e)=>{const t=rr(o=>o.type===e)(r.selection);if(!t)return!0;const n=r.doc.resolve(Math.max(0,t.pos-1)).before(t.depth);if(n===void 0)return!0;const i=r.doc.nodeAt(n);return t.node.type===(i==null?void 0:i.type)&&we(r.doc,t.pos)&&r.join(t.pos),!0},ui=(r,e)=>{const t=rr(o=>o.type===e)(r.selection);if(!t)return!0;const n=r.doc.resolve(t.start).after(t.depth);if(n===void 0)return!0;const i=r.doc.nodeAt(n);return t.node.type===(i==null?void 0:i.type)&&we(r.doc,n)&&r.join(n),!0},Mf=(r,e)=>({editor:t,tr:n,state:i,dispatch:s,chain:o,commands:l,can:a})=>{const{extensions:c}=t.extensionManager,f=P(r,i.schema),d=P(e,i.schema),{selection:u}=i,{$from:p,$to:h}=u,m=p.blockRange(h);if(!m)return!1;const g=rr(b=>ci(b.type.name,c))(u);if(m.depth>=1&&g&&m.depth-g.depth<=1){if(g.node.type===f)return l.liftListItem(d);if(ci(g.node.type.name,c)&&f.validContent(g.node.content)&&s)return o().command(()=>(n.setNodeMarkup(g.pos,f),!0)).command(()=>di(n,f)).command(()=>ui(n,f)).run()}return o().command(()=>a().wrapInList(f)?!0:l.clearNodes()).wrapInList(f).command(()=>di(n,f)).command(()=>ui(n,f)).run()},Cf=(r,e={},t={})=>({state:n,commands:i})=>{const{extendEmptyMarkRange:s=!1}=t,o=Ne(r,n.schema);return Ln(n,o,e)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,e)},wf=(r,e,t={})=>({state:n,commands:i})=>{const s=P(r,n.schema),o=P(e,n.schema);return bt(n,s,t)?i.setNode(o):i.setNode(s,t)},Of=(r,e={})=>({state:t,commands:n})=>{const i=P(r,t.schema);return bt(t,i,e)?n.lift(i):n.wrapIn(i,e)},Tf=()=>({state:r,dispatch:e})=>{const t=r.plugins;for(let n=0;n=0;a-=1)o.step(l.steps[a].invert(l.docs[a]));if(s.text){const 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)}return!0}}return!1},Nf=()=>({tr:r,dispatch:e})=>{const{selection:t}=r,{empty:n,ranges:i}=t;return n||e&&i.forEach(s=>{r.removeMark(s.$from.pos,s.$to.pos)}),!0},Ef=(r,e={})=>({tr:t,state:n,dispatch:i})=>{var s;const{extendEmptyMarkRange:o=!1}=e,{selection:l}=t,a=Ne(r,n.schema),{$from:c,empty:f,ranges:d}=l;if(!i)return!0;if(f&&o){let{from:u,to:p}=l;const h=(s=c.marks().find(g=>g.type===a))===null||s===void 0?void 0:s.attrs,m=tr(c,a,h);m&&(u=m.from,p=m.to),t.removeMark(u,p,a)}else d.forEach(u=>{t.removeMark(u.$from.pos,u.$to.pos,a)});return t.removeStoredMark(a),!0},Af=(r,e={})=>({tr:t,state:n,dispatch:i})=>{let s=null,o=null;const l=en(typeof r=="string"?r:r.name,n.schema);return l?(l==="node"&&(s=P(r,n.schema)),l==="mark"&&(o=Ne(r,n.schema)),i&&t.selection.ranges.forEach(a=>{const c=a.$from.pos,f=a.$to.pos;n.doc.nodesBetween(c,f,(d,u)=>{s&&s===d.type&&t.setNodeMarkup(u,void 0,{...d.attrs,...e}),o&&d.marks.length&&d.marks.forEach(p=>{if(o===p.type){const h=Math.max(u,c),m=Math.min(u+d.nodeSize,f);t.addMark(h,m,o.create({...p.attrs,...e}))}})})}),!0):!1},Df=(r,e={})=>({state:t,dispatch:n})=>{const i=P(r,t.schema);return Ya(i,e)(t,n)},Rf=(r,e={})=>({state:t,dispatch:n})=>{const i=P(r,t.schema);return _a(i,e)(t,n)};var If=Object.freeze({__proto__:null,blur:yc,clearContent:bc,clearNodes:kc,command:Sc,createParagraphNear:xc,deleteCurrentNode:Mc,deleteNode:Cc,deleteRange:wc,deleteSelection:Oc,enter:Tc,exitCode:Nc,extendMarkRange:Ac,first:Dc,focus:Rc,forEach:Ic,insertContent:Pc,insertContentAt:vc,joinUp:Fc,joinDown:Lc,joinBackward:Vc,joinForward:$c,keyboardShortcut:Jc,lift:Hc,liftEmptyBlock:qc,liftListItem:Kc,newlineInCode:jc,resetAttributes:Uc,scrollIntoView:Gc,selectAll:Yc,selectNodeBackward:_c,selectNodeForward:Xc,selectParentNode:Zc,selectTextblockEnd:Qc,selectTextblockStart:ef,setContent:tf,setMark:pf,setMeta:mf,setNode:gf,setNodeSelection:yf,setTextSelection:bf,sinkListItem:kf,splitBlock:Sf,splitListItem:xf,toggleList:Mf,toggleMark:Cf,toggleNode:wf,toggleWrap:Of,undoInputRule:Tf,unsetAllMarks:Nf,unsetMark:Ef,updateAttributes:Af,wrapIn:Df,wrapInList:Rf});const Pf=de.create({name:"commands",addCommands(){return{...If}}}),Bf=de.create({name:"editable",addProseMirrorPlugins(){return[new Oe({key:new kt("editable"),props:{editable:()=>this.editor.options.editable}})]}}),zf=de.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:r}=this;return[new Oe({key:new kt("focusEvents"),props:{handleDOMEvents:{focus:(e,t)=>{r.isFocused=!0;const n=r.state.tr.setMeta("focus",{event:t}).setMeta("addToHistory",!1);return e.dispatch(n),!1},blur:(e,t)=>{r.isFocused=!1;const n=r.state.tr.setMeta("blur",{event:t}).setMeta("addToHistory",!1);return e.dispatch(n),!1}}}})]}}),vf=de.create({name:"keymap",addKeyboardShortcuts(){const r=()=>this.editor.commands.first(({commands:o})=>[()=>o.undoInputRule(),()=>o.command(({tr:l})=>{const{selection:a,doc:c}=l,{empty:f,$anchor:d}=a,{pos:u,parent:p}=d,h=C.atStart(c).from===u;return!f||!h||!p.type.isTextblock||p.textContent.length?!1:o.clearNodes()}),()=>o.deleteSelection(),()=>o.joinBackward(),()=>o.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.deleteCurrentNode(),()=>o.joinForward(),()=>o.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.newlineInCode(),()=>o.createParagraphNear(),()=>o.liftEmptyBlock(),()=>o.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:r,"Mod-Backspace":r,"Shift-Backspace":r,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},i={...n},s={...n,"Ctrl-h":r,"Alt-Backspace":r,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return nr()||Ws()?s:i},addProseMirrorPlugins(){return[new Oe({key:new kt("clearDocument"),appendTransaction:(r,e,t)=>{if(!(r.some(h=>h.docChanged)&&!e.doc.eq(t.doc)))return;const{empty:i,from:s,to:o}=e.selection,l=C.atStart(e.doc).from,a=C.atEnd(e.doc).to,c=s===l&&o===a,f=t.doc.textBetween(0,t.doc.content.size," "," ").length===0;if(i||!c||!f)return;const d=t.tr,u=_t({state:t,transaction:d}),{commands:p}=new Xt({editor:this.editor,state:u});if(p.clearNodes(),!!d.steps.length)return d}})]}}),Ff=de.create({name:"tabindex",addProseMirrorPlugins(){return[new Oe({key:new kt("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});var Lf=Object.freeze({__proto__:null,ClipboardTextSerializer:gc,Commands:Pf,Editable:Bf,FocusEvents:zf,Keymap:vf,Tabindex:Ff});const Vf=`.ProseMirror { position: relative; } .ProseMirror { word-wrap: break-word; white-space: pre-wrap; white-space: break-spaces; -webkit-font-variant-ligatures: none; font-variant-ligatures: none; font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */ } .ProseMirror [contenteditable="false"] { white-space: normal; } .ProseMirror [contenteditable="false"] [contenteditable="true"] { white-space: pre-wrap; } .ProseMirror pre { white-space: pre-wrap; } img.ProseMirror-separator { display: inline !important; border: none !important; margin: 0 !important; width: 1px !important; height: 1px !important; } .ProseMirror-gapcursor { display: none; pointer-events: none; position: absolute; margin: 0; } .ProseMirror-gapcursor:after { content: ""; display: block; position: absolute; top: -2px; width: 20px; border-top: 1px solid black; animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite; } @keyframes ProseMirror-cursor-blink { to { visibility: hidden; } } .ProseMirror-hideselection *::selection { background: transparent; } .ProseMirror-hideselection *::-moz-selection { background: transparent; } .ProseMirror-hideselection * { caret-color: transparent; } .ProseMirror-focused .ProseMirror-gapcursor { display: block; } .tippy-box[data-animation=fade][data-state=hidden] { opacity: 0 }`;function $f(r,e){const t=document.querySelector("style[data-tiptap-style]");if(t!==null)return t;const n=document.createElement("style");return e&&n.setAttribute("nonce",e),n.setAttribute("data-tiptap-style",""),n.innerHTML=r,document.getElementsByTagName("head")[0].appendChild(n),n}let rd=class extends rc{constructor(e={}){super(),this.isFocused=!1,this.extensionStorage={},this.options={element:document.createElement("div"),content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,editorProps:{},parseOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,onBeforeCreate:()=>null,onCreate:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.createView(),this.injectCSS(),this.on("create",this.options.onCreate),this.on("update",this.options.onUpdate),this.on("selectionUpdate",this.options.onSelectionUpdate),this.on("transaction",this.options.onTransaction),this.on("focus",this.options.onFocus),this.on("blur",this.options.onBlur),this.on("destroy",this.options.onDestroy),window.setTimeout(()=>{this.isDestroyed||(this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}))},0)}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&document&&(this.css=$f(Vf,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.view||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e){this.setOptions({editable:e}),this.emit("update",{editor:this,transaction:this.state.tr})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get state(){return this.view.state}registerPlugin(e,t){const n=zs(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],i=this.state.reconfigure({plugins:n});this.view.updateState(i)}unregisterPlugin(e){if(this.isDestroyed)return;const t=typeof e=="string"?`${e}$`:e.key,n=this.state.reconfigure({plugins:this.state.plugins.filter(i=>!i.key.startsWith(t))});this.view.updateState(n)}createExtensionManager(){const t=[...this.options.enableCoreExtensions?Object.values(Lf):[],...this.options.extensions].filter(n=>["extension","node","mark"].includes(n==null?void 0:n.type));this.extensionManager=new Re(t,this)}createCommandManager(){this.commandManager=new Xt({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createView(){const e=Js(this.options.content,this.schema,this.options.parseOptions),t=$s(e,this.options.autofocus);this.view=new Sa(this.options.element,{...this.options.editorProps,dispatchTransaction:this.dispatchTransaction.bind(this),state:je.create({doc:e,selection:t||void 0})});const n=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(n),this.createNodeViews();const i=this.view.dom;i.editor=this}createNodeViews(){this.view.setProps({nodeViews:this.extensionManager.nodeViews})}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;const t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(o=>{var l;return(l=this.capturedTransaction)===null||l===void 0?void 0:l.step(o)});return}const t=this.state.apply(e),n=!this.state.selection.eq(t.selection);this.view.updateState(t),this.emit("transaction",{editor:this,transaction:e}),n&&this.emit("selectionUpdate",{editor:this,transaction:e});const i=e.getMeta("focus"),s=e.getMeta("blur");i&&this.emit("focus",{editor:this,event:i.event,transaction:e}),s&&this.emit("blur",{editor:this,event:s.event,transaction:e}),!(!e.docChanged||e.getMeta("preventUpdate"))&&this.emit("update",{editor:this,transaction:e})}getAttributes(e){return af(this.state,e)}isActive(e,t){const n=typeof e=="string"?e:null,i=typeof e=="string"?t:e;return df(this.state,n,i)}getJSON(){return this.state.doc.toJSON()}getHTML(){return sf(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t=` `,textSerializers:n={}}=e||{};return of(this.state.doc,{blockSeparator:t,textSerializers:{...n,...Ls(this.schema)}})}get isEmpty(){return uf(this.state.doc)}getCharacterCount(){return console.warn('[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.'),this.state.doc.content.size-2}destroy(){this.emit("destroy"),this.view&&this.view.destroy(),this.removeAllListeners()}get isDestroyed(){var e;return!(!((e=this.view)===null||e===void 0)&&e.docView)}};function Ht(r){return new er({find:r.find,handler:({state:e,range:t,match:n})=>{const i=M(r.getAttributes,void 0,n);if(i===!1||i===null)return null;const{tr:s}=e,o=n[n.length-1],l=n[0];let a=t.to;if(o){const c=l.search(/\S/),f=t.from+l.indexOf(o),d=f+o.length;if(Hs(t.from,t.to,e.doc).filter(p=>p.mark.type.excluded.find(m=>m===r.type&&m!==p.mark.type)).filter(p=>p.to>f).length)return null;dt.from&&s.delete(t.from+c,f),a=t.from+c+o.length,s.addMark(t.from+c,a,r.type.create(i||{})),s.removeStoredMark(r.type)}}})}function sd(r){return new er({find:r.find,handler:({state:e,range:t,match:n})=>{const i=e.doc.resolve(t.from),s=M(r.getAttributes,void 0,n)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),r.type))return null;e.tr.delete(t.from,t.to).setBlockType(t.from,t.from,r.type,s)}})}function Vn(r){return new er({find:r.find,handler:({state:e,range:t,match:n})=>{const i=M(r.getAttributes,void 0,n)||{},s=e.tr.delete(t.from,t.to),l=s.doc.resolve(t.from).blockRange(),a=l&&Jn(l,r.type,i);if(!a)return null;s.wrap(l,a);const c=s.doc.resolve(t.from-1).nodeBefore;c&&c.type===r.type&&we(s.doc,t.from-1)&&(!r.joinPredicate||r.joinPredicate(n,c))&&s.join(t.from-1)}})}class Ce{constructor(e={}){this.type="mark",this.name="mark",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=M(S(this,"addOptions",{name:this.name}))),this.storage=M(S(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Ce(e)}configure(e={}){const t=this.extend();return t.options=Qt(this.options,e),t.storage=M(S(t,"addStorage",{name:t.name,options:t.options})),t}extend(e={}){const t=new Ce(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=M(S(t,"addOptions",{name:t.name})),t.storage=M(S(t,"addStorage",{name:t.name,options:t.options})),t}static handleExit({editor:e,mark:t}){const{tr:n}=e.state,i=e.state.selection.$from;if(i.pos===i.end()){const o=i.marks();if(!!!o.find(c=>(c==null?void 0:c.type.name)===t.name))return!1;const a=o.find(c=>(c==null?void 0:c.type.name)===t.name);return a&&n.removeStoredMark(a),n.insertText(" ",i.pos),e.view.dispatch(n),!0}return!1}}class se{constructor(e={}){this.type="node",this.name="node",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=M(S(this,"addOptions",{name:this.name}))),this.storage=M(S(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new se(e)}configure(e={}){const t=this.extend();return t.options=Qt(this.options,e),t.storage=M(S(t,"addStorage",{name:t.name,options:t.options})),t}extend(e={}){const t=new se(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=M(S(t,"addOptions",{name:t.name})),t.storage=M(S(t,"addStorage",{name:t.name,options:t.options})),t}}function qt(r){return new fc({find:r.find,handler:({state:e,range:t,match:n})=>{const i=M(r.getAttributes,void 0,n);if(i===!1||i===null)return null;const{tr:s}=e,o=n[n.length-1],l=n[0];let a=t.to;if(o){const c=l.search(/\S/),f=t.from+l.indexOf(o),d=f+o.length;if(Hs(t.from,t.to,e.doc).filter(p=>p.mark.type.excluded.find(m=>m===r.type&&m!==p.mark.type)).filter(p=>p.to>f).length)return null;dt.from&&s.delete(t.from+c,f),a=t.from+c+o.length,s.addMark(t.from+c,a,r.type.create(i||{})),s.removeStoredMark(r.type)}}})}const Wf=/(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))$/,Jf=/(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))/g,Hf=/(?:^|\s)((?:__)((?:[^__]+))(?:__))$/,qf=/(?:^|\s)((?:__)((?:[^__]+))(?:__))/g,od=Ce.create({name:"bold",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:r=>r.style.fontWeight!=="normal"&&null},{style:"font-weight",getAttrs:r=>/^(bold(er)?|[5-9]\d{2,})$/.test(r)&&null}]},renderHTML({HTMLAttributes:r}){return["strong",ee(this.options.HTMLAttributes,r),0]},addCommands(){return{setBold:()=>({commands:r})=>r.setMark(this.name),toggleBold:()=>({commands:r})=>r.toggleMark(this.name),unsetBold:()=>({commands:r})=>r.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[Ht({find:Wf,type:this.type}),Ht({find:Hf,type:this.type})]},addPasteRules(){return[qt({find:Jf,type:this.type}),qt({find:qf,type:this.type})]}}),Kf=se.create({name:"listItem",addOptions(){return{HTMLAttributes:{}}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:r}){return["li",ee(this.options.HTMLAttributes,r),0]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),hi=Ce.create({name:"textStyle",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"span",getAttrs:r=>r.hasAttribute("style")?{}:!1}]},renderHTML({HTMLAttributes:r}){return["span",ee(this.options.HTMLAttributes,r),0]},addCommands(){return{removeEmptyTextStyle:()=>({state:r,commands:e})=>{const t=ir(r,this.type);return Object.entries(t).some(([,i])=>!!i)?!0:e.unsetMark(this.name)}}}}),pi=/^\s*([-+*])\s$/,ld=se.create({name:"bulletList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:"ul"}]},renderHTML({HTMLAttributes:r}){return["ul",ee(this.options.HTMLAttributes,r),0]},addCommands(){return{toggleBulletList:()=>({commands:r,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(Kf.name,this.editor.getAttributes(hi.name)).run():r.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let r=Vn({find:pi,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(r=Vn({find:pi,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(hi.name),editor:this.editor})),[r]}}),ad=se.create({name:"doc",topNode:!0,content:"block+"}),jf=/(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/,Uf=/(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/g,Gf=/(?:^|\s)((?:_)((?:[^_]+))(?:_))$/,Yf=/(?:^|\s)((?:_)((?:[^_]+))(?:_))/g,cd=Ce.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:r=>r.style.fontStyle!=="normal"&&null},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:r}){return["em",ee(this.options.HTMLAttributes,r),0]},addCommands(){return{setItalic:()=>({commands:r})=>r.setMark(this.name),toggleItalic:()=>({commands:r})=>r.toggleMark(this.name),unsetItalic:()=>({commands:r})=>r.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[Ht({find:jf,type:this.type}),Ht({find:Gf,type:this.type})]},addPasteRules(){return[qt({find:Uf,type:this.type}),qt({find:Yf,type:this.type})]}}),fd=se.create({name:"listItem",addOptions(){return{HTMLAttributes:{}}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:r}){return["li",ee(this.options.HTMLAttributes,r),0]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),_f=/^(\d+)\.\s$/,dd=se.create({name:"orderedList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{}}},group:"block list",content(){return`${this.options.itemTypeName}+`},addAttributes(){return{start:{default:1,parseHTML:r=>r.hasAttribute("start")?parseInt(r.getAttribute("start")||"",10):1}}},parseHTML(){return[{tag:"ol"}]},renderHTML({HTMLAttributes:r}){const{start:e,...t}=r;return e===1?["ol",ee(this.options.HTMLAttributes,t),0]:["ol",ee(this.options.HTMLAttributes,r),0]},addCommands(){return{toggleOrderedList:()=>({commands:r})=>r.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){return[Vn({find:_f,type:this.type,getAttributes:r=>({start:+r[1]}),joinPredicate:(r,e)=>e.childCount+e.attrs.start===+r[1]})]}}),ud=se.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:r}){return["p",ee(this.options.HTMLAttributes,r),0]},addCommands(){return{setParagraph:()=>({commands:r})=>r.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),hd=se.create({name:"text",group:"inline"}),pd=Ce.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:r=>r.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:r}){return["u",ee(this.options.HTMLAttributes,r),0]},addCommands(){return{setUnderline:()=>({commands:r})=>r.setMark(this.name),toggleUnderline:()=>({commands:r})=>r.toggleMark(this.name),unsetUnderline:()=>({commands:r})=>r.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}});export{od as B,X as D,de as E,cd as I,fd as L,Ce as M,se as N,dd as O,Oe as P,hd as T,pd as U,R as a,qt as b,kt as c,Xf as d,Hs as e,Zf as f,ed as g,af as h,Qf as i,Be as j,$e as k,ad as l,ee as m,ud as n,ld as o,Vs as p,td as q,nd as r,rd as s,sd as t,Ht as u,at as v}; //# sourceMappingURL=tiptap-extension-underline.esm-1c1a172c.js.map